Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117750647
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
23 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/file/cleaner/main.cpp b/src/file/cleaner/main.cpp
index be1b2791..4689f56e 100644
--- a/src/file/cleaner/main.cpp
+++ b/src/file/cleaner/main.cpp
@@ -1,67 +1,68 @@
/*
This file is part of the KDE Baloo project.
Copyright (C) 2014 Vishesh Handa <me@vhanda.in>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cleaner.h"
#include "../database.h"
#include "../priority.h"
#include <k4aboutdata.h>
#include <KCmdLineArgs>
#include <KLocale>
+#include <KGlobal>
#include <KComponentData>
#include <QApplication>
#include <QDBusConnection>
#include <KDebug>
#include <KStandardDirs>
int main(int argc, char* argv[])
{
lowerIOPriority();
lowerSchedulingPriority();
lowerPriority();
K4AboutData aboutData("baloo_file_cleaner", 0, ki18n("Baloo File Cleaner"),
"0.1",
ki18n("Cleans up stale file index information"),
K4AboutData::License_LGPL_V2,
ki18n("(C) 2014, Vishesh Handa"));
aboutData.addAuthor(ki18n("Vishesh Handa"), ki18n("Maintainer"), "me@vhanda.in");
KCmdLineArgs::init(argc, argv, &aboutData);
QApplication app(argc, argv);
KComponentData data(aboutData, KComponentData::RegisterAsMainComponent);
if (!QDBusConnection::sessionBus().registerService("org.kde.baloo.file.cleaner")) {
kError() << "Failed to register via dbus. Another instance is running";
return 1;
}
const QString path = KGlobal::dirs()->localxdgdatadir() + "baloo/file/";
Database db;
db.setPath(path);
db.init();
Baloo::Cleaner cleaner(&db);
return app.exec();
}
diff --git a/src/file/extractor/app.cpp b/src/file/extractor/app.cpp
index 42c6bb97..16b4296f 100644
--- a/src/file/extractor/app.cpp
+++ b/src/file/extractor/app.cpp
@@ -1,239 +1,240 @@
/*
* This file is part of the KDE Baloo Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "app.h"
#include "../basicindexingjob.h"
#include "../database.h"
#include <KCmdLineArgs>
#include <KMimeType>
#include <KStandardDirs>
#include <KDebug>
#include <KUrl>
+#include <KGlobal>
#include <QTimer>
#include <QtCore/QFileInfo>
#include <QDBusMessage>
#include <QSqlQuery>
#include <QSqlError>
#include <QDBusConnection>
#include <KApplication>
#include <kfilemetadata/propertyinfo.h>
#include <iostream>
using namespace Baloo;
App::App(QObject* parent)
: QObject(parent)
, m_termCount(0)
{
m_path = KGlobal::dirs()->localxdgdatadir() + "baloo/file";
m_db.setPath(m_path);
m_db.init();
const KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
m_bData = args->isSet("bdata");
m_results.reserve(args->count());
for (int i=0; i<args->count(); i++) {
FileMapping mapping = FileMapping(args->arg(i).toUInt());
QString url;
if (mapping.fetch(m_db.sqlDatabase())) {
// arg is an id
url = mapping.url();
// If this url no longer exists, remove it from the mapping db.
if (!QFile::exists(url)) {
QSqlQuery query(m_db.sqlDatabase());
query.prepare("delete from files where url = ?");
query.addBindValue(url);
if (!query.exec()) {
kError() << query.lastError().text();
}
}
} else {
// arg is a url
url = args->url(i).toLocalFile();
}
if (QFile::exists(url)) {
m_urls << url;
} else {
// id or url was looked up, but file deleted
kDebug() << url << "does not exist";
// Try to delete it as an id:
// it may have been deleted from the FileMapping db as well.
// The worst that can happen is deleting nothing.
deleteDocument(mapping.id());
}
}
connect(this, SIGNAL(saved()), this, SLOT(processNextUrl()), Qt::QueuedConnection);
QTimer::singleShot(0, this, SLOT(processNextUrl()));
}
App::~App()
{
}
void App::processNextUrl()
{
if (m_urls.isEmpty()) {
if (m_results.isEmpty()) {
QCoreApplication::instance()->exit(0);
}
else {
saveChanges();
}
return;
}
const QString url = m_urls.takeFirst();
const QString mimetype = KMimeType::findByUrl(KUrl::fromLocalFile(url))->name();
FileMapping file(url);
if (!m_bData) {
if (!file.fetch(m_db.sqlDatabase())) {
file.create(m_db.sqlDatabase());
}
}
Xapian::Document doc;
if (file.fetched()) {
try {
doc = m_db.xapianDatabase()->get_document(file.id());
}
catch (const Xapian::DocNotFoundError&) {
BasicIndexingJob basicIndexer(&m_db.sqlDatabase(), file, mimetype);
basicIndexer.index();
file.setId(basicIndexer.id());
doc = basicIndexer.document();
}
}
Result result(url, mimetype);
result.setId(file.id());
result.setDocument(doc);
QList<KFileMetaData::ExtractorPlugin*> exList = m_manager.fetchExtractors(mimetype);
Q_FOREACH (KFileMetaData::ExtractorPlugin* plugin, exList) {
plugin->extract(&result);
}
m_results << result;
m_termCount += result.document().termlist_count();
// Documents with these many terms occupy about 10 mb
if (m_termCount >= 10000) {
saveChanges();
return;
}
if (m_urls.isEmpty()) {
if (m_bData) {
QByteArray arr;
QDataStream s(&arr, QIODevice::WriteOnly);
Q_FOREACH (const Result& res, m_results) {
QVariantMap map;
QMapIterator<QString, QVariant> it(res.map());
while (it.hasNext()) {
it.next();
int propNum = it.key().toInt();
using namespace KFileMetaData::Property;
Property prop = static_cast<Property>(propNum);
KFileMetaData::PropertyInfo pi(prop);
map.insert(pi.name(), it.value());
}
s << map;
}
std::cout << arr.toBase64().constData();
m_results.clear();
}
else {
saveChanges();
}
}
QTimer::singleShot(0, this, SLOT(processNextUrl()));
}
void App::saveChanges()
{
if (m_results.isEmpty())
return;
QList<QString> updatedFiles;
try {
Xapian::WritableDatabase db(m_path.toUtf8().constData(), Xapian::DB_CREATE_OR_OPEN);
for (int i = 0; i<m_results.size(); i++) {
Result& res = m_results[i];
res.save(db);
updatedFiles << res.inputUrl();
}
Q_FOREACH (Xapian::docid id, m_docsToRemove) {
try {
db.delete_document(id);
}
catch (const Xapian::DocNotFoundError&) {
}
}
db.commit();
m_db.xapianDatabase()->reopen();
m_results.clear();
m_docsToRemove.clear();
m_termCount = 0;
Q_EMIT saved();
}
catch (const Xapian::DatabaseLockError& err) {
kError() << "Cannot open database in write mode:" << err.get_msg().c_str();
QTimer::singleShot(100, this, SLOT(saveChanges()));
return;
}
QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/files"),
QLatin1String("org.kde"),
QLatin1String("changed"));
QVariantList vl;
vl.reserve(1);
vl << QVariant(updatedFiles);
message.setArguments(vl);
QDBusConnection::sessionBus().send(message);
}
void App::deleteDocument(unsigned docid)
{
m_docsToRemove << docid;
}
diff --git a/src/file/lib/db.cpp b/src/file/lib/db.cpp
index 15bd62b8..2d651b52 100644
--- a/src/file/lib/db.cpp
+++ b/src/file/lib/db.cpp
@@ -1,117 +1,118 @@
/*
* This file is part of the KDE Baloo Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "db.h"
#include <KDebug>
#include <KStandardDirs>
+#include <KGlobal>
#include <QSqlQuery>
#include <QSqlError>
std::string fileIndexDbPath()
{
return (KGlobal::dirs()->localxdgdatadir() + "baloo/file").toUtf8().constData();
}
QSqlDatabase fileMappingDb() {
const QString path = KGlobal::dirs()->localxdgdatadir() + "baloo/file/fileMap.sqlite3";
return fileMappingDb(path);
}
QSqlDatabase fileMappingDb(const QString& path)
{
QSqlDatabase sqlDb = QSqlDatabase::database("fileMappingDb");
if (!sqlDb.isValid()) {
sqlDb = QSqlDatabase::addDatabase("QSQLITE", "fileMappingDb");
sqlDb.setDatabaseName(path);
}
if (!sqlDb.open()) {
kDebug() << "Failed to open db" << sqlDb.lastError().text();
return sqlDb;
}
const QStringList tables = sqlDb.tables();
if (tables.contains("files")) {
return sqlDb;
}
QSqlQuery query(sqlDb);
bool ret = query.exec("CREATE TABLE files("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"url TEXT NOT NULL UNIQUE)");
if (!ret) {
kDebug() << "Could not create tags table" << query.lastError().text();
return sqlDb;
}
ret = query.exec("CREATE INDEX fileUrl_index ON files (url)");
if (!ret) {
kDebug() << "Could not create tags index" << query.lastError().text();
return sqlDb;
}
return sqlDb;
}
QSqlDatabase fileMetadataDb()
{
const QString path = KGlobal::dirs()->localxdgdatadir() + "baloo/file/fileMetaData.sqlite3";
QSqlDatabase sqlDb = QSqlDatabase::database("fileMetadataDb");
if (!sqlDb.isValid()) {
sqlDb = QSqlDatabase::addDatabase("QSQLITE", "fileMetadataDb");
sqlDb.setDatabaseName(path);
}
if (!sqlDb.open()) {
kDebug() << "Failed to open db" << sqlDb.lastError().text();
return sqlDb;
}
const QStringList tables = sqlDb.tables();
if (tables.contains("files")) {
return sqlDb;
}
QSqlQuery query(sqlDb);
bool ret = query.exec("CREATE TABLE files("
"id INTEGER NOT NULL, "
"property TEXT NOT NULL, "
"value TEXT NOT NULL, "
"UNIQUE(id, property) ON CONFLICT REPLACE)");
if (!ret) {
kDebug() << "Could not create tags table" << query.lastError().text();
return sqlDb;
}
ret = query.exec("CREATE INDEX fileprop_index ON files (property)");
if (!ret) {
kDebug() << "Could not create tags index" << query.lastError().text();
return sqlDb;
}
return sqlDb;
}
diff --git a/src/file/main.cpp b/src/file/main.cpp
index a1b6ef26..1783b4e2 100644
--- a/src/file/main.cpp
+++ b/src/file/main.cpp
@@ -1,91 +1,92 @@
/*
* This file is part of the KDE Baloo Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <QApplication>
#include <KComponentData>
#include <k4aboutdata.h>
#include <KStandardDirs>
#include <KConfig>
#include <KConfigGroup>
#include <KDebug>
+#include <KGlobal>
#include <iostream>
#include "filewatch.h"
#include "fileindexer.h"
#include "database.h"
#include "fileindexerconfig.h"
#include "priority.h"
#include <QDBusConnection>
int main(int argc, char** argv)
{
lowerIOPriority();
lowerSchedulingPriority();
lowerPriority();
QApplication app(argc, argv);
K4AboutData aboutData("baloo_file", "baloo_file", ki18n("Baloo File"), "0.1",
ki18n("An application to handle file metadata"),
K4AboutData::License_GPL_V2);
KComponentData data(aboutData, KComponentData::RegisterAsMainComponent);
KConfig config("baloofilerc");
KConfigGroup group = config.group("Basic Settings");
bool indexingEnabled = group.readEntry("Indexing-Enabled", true);
if (!indexingEnabled) {
std::cout << "Baloo File Indexing has been disabled" << std::endl;
return 0;
}
if (!QDBusConnection::sessionBus().registerService("org.kde.baloo.file")) {
kError() << "Failed to register via dbus. Another instance is running";
return 1;
}
const QString path = KGlobal::dirs()->localxdgdatadir() + "baloo/file/";
Database db;
db.setPath(path);
db.init();
db.sqlDatabase().transaction();
Baloo::FileIndexerConfig indexerConfig;
Baloo::FileWatch filewatcher(&db, &indexerConfig, &app);
Baloo::FileIndexer fileIndexer(&db, &indexerConfig, &app);
QObject::connect(&filewatcher, SIGNAL(indexFile(QString)),
&fileIndexer, SLOT(indexFile(QString)));
QObject::connect(&filewatcher, SIGNAL(installedWatches()),
&fileIndexer, SLOT(update()));
QObject::connect(&filewatcher, SIGNAL(fileRemoved(int)),
&fileIndexer, SLOT(removeFileData(int)));
return app.exec();
}
diff --git a/src/file/search/filesearchstore.cpp b/src/file/search/filesearchstore.cpp
index c82b62fa..8bf98529 100644
--- a/src/file/search/filesearchstore.cpp
+++ b/src/file/search/filesearchstore.cpp
@@ -1,207 +1,208 @@
/*
* This file is part of the KDE Baloo Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "filesearchstore.h"
#include "term.h"
#include "query.h"
#include "filemapping.h"
#include "pathfilterpostingsource.h"
#include <xapian.h>
#include <QVector>
#include <KStandardDirs>
#include <KDebug>
#include <KUrl>
#include <KMimeType>
+#include <KGlobal>
#include <kfilemetadata/propertyinfo.h>
using namespace Baloo;
FileSearchStore::FileSearchStore(QObject* parent)
: XapianSearchStore(parent)
, m_sqlDb(0)
, m_sqlMutex(QMutex::Recursive)
{
const QString path = KGlobal::dirs()->localxdgdatadir() + "baloo/file/";
setDbPath(path);
m_prefixes.insert("filename", "F");
m_prefixes.insert("mimetype", "M");
m_prefixes.insert("rating", "R");
m_prefixes.insert("tag", "TA");
m_prefixes.insert("tags", "TA");
m_prefixes.insert("usercomment", "C");
}
FileSearchStore::~FileSearchStore()
{
const QString conName = m_sqlDb->connectionName();
delete m_sqlDb;
QSqlDatabase::removeDatabase(conName);
}
void FileSearchStore::setDbPath(const QString& path)
{
XapianSearchStore::setDbPath(path);
const QString conName = "filesearchstore" + QString::number(qrand());
delete m_sqlDb;
m_sqlDb = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", conName));
m_sqlDb->setDatabaseName(dbPath() + "/fileMap.sqlite3");
m_sqlDb->open();
}
QStringList FileSearchStore::types()
{
return QStringList() << "File" << "Audio" << "Video" << "Document" << "Image" << "Archive" << "Folder";
}
Xapian::Query FileSearchStore::convertTypes(const QStringList& types)
{
Xapian::Query xapQ;
Q_FOREACH (const QString& type, types) {
QString t = 'T' + type.toLower();
if (t == "Tfile")
continue;
const QByteArray arr = t.toUtf8();
xapQ = andQuery(xapQ, Xapian::Query(arr.constData()));
}
return xapQ;
}
Xapian::Query FileSearchStore::constructQuery(const QString& property, const QVariant& value,
Term::Comparator com)
{
// FIXME: Handle cases where only the property is specified
if (value.isNull())
return Xapian::Query();
if (property.compare(QLatin1String("rating"), Qt::CaseInsensitive) == 0) {
int val = value.toInt();
if (val == 0)
return Xapian::Query();
QVector<std::string> terms;
if (com == Term::Greater || com == Term::GreaterEqual) {
if (com == Term::Greater)
val++;
for (int i=val; i<=10; i++) {
QByteArray arr = 'R' + QByteArray::number(i);
terms << arr.constData();
}
}
else if (com == Term::Less || com == Term::LessEqual) {
if (com == Term::Less)
val--;
for (int i=1; i<=val; i++) {
QByteArray arr = 'R' + QByteArray::number(i);
terms << arr.constData();
}
}
else if (com == Term::Equal) {
QByteArray arr = 'R' + QByteArray::number(val);
terms << arr.constData();
}
return Xapian::Query(Xapian::Query::OP_OR, terms.begin(), terms.end());
}
if (com == Term::Contains) {
Xapian::QueryParser parser;
parser.set_database(*xapianDb());
std::string p;
QHash<QString, std::string>::const_iterator it = m_prefixes.constFind(property.toLower());
if (it != m_prefixes.constEnd()) {
p = it.value();
}
else {
KFileMetaData::PropertyInfo pi = KFileMetaData::PropertyInfo::fromName(property);
int propPrefix = static_cast<int>(pi.property());
p = ('X' + QString::number(propPrefix)).toUtf8().constData();
}
const QByteArray arr = value.toString().toUtf8();
int flags = Xapian::QueryParser::FLAG_DEFAULT | Xapian::QueryParser::FLAG_PARTIAL;
return parser.parse_query(arr.constData(), flags, p);
}
const QByteArray arr = value.toString().toUtf8();
return Xapian::Query(arr.constData());
}
Xapian::Query FileSearchStore::constructFilterQuery(int year, int month, int day)
{
QVector<std::string> vector;
vector.reserve(3);
if (year != -1)
vector << QString::fromLatin1("DT_MY%1").arg(year).toUtf8().constData();
if (month != -1)
vector << QString::fromLatin1("DT_MM%1").arg(month).toUtf8().constData();
if (day != -1)
vector << QString::fromLatin1("DT_MD%1").arg(day).toUtf8().constData();
return Xapian::Query(Xapian::Query::OP_AND, vector.begin(), vector.end());
}
QUrl FileSearchStore::constructUrl(const Xapian::docid& docid)
{
QMutexLocker lock(&m_sqlMutex);
FileMapping file(docid);
file.fetch(*m_sqlDb);
return QUrl::fromLocalFile(file.url());
}
QString FileSearchStore::text(int queryId)
{
return KUrl(url(queryId)).fileName();
}
QString FileSearchStore::icon(int queryId)
{
KMimeType::Ptr mime = KMimeType::findByUrl(url(queryId));
return mime->iconName();
}
Xapian::Query FileSearchStore::applyCustomOptions(const Xapian::Query& q, const QVariantMap& options)
{
QMap<QString, QVariant>::const_iterator it = options.constFind("includeFolder");
if (it == options.constEnd()) {
return q;
}
QString includeDir = it.value().toString();
PathFilterPostingSource ps(m_sqlDb, includeDir);
return andQuery(q, Xapian::Query(&ps));
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 4, 2:34 AM (1 w, 14 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18822153
Default Alt Text
(23 KB)
Attached To
Mode
rKB baloo
Attached
Detach File
Event Timeline