Verified Commit 42678889 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Run astyle to correct indentation to 4 spaces

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent d7d03e89
......@@ -52,6 +52,10 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMMarkNonGuiExecutable)
include(KDEClangFormat)
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
include(ECMMarkAsTest)
include(ECMOptionalAddSubdirectory)
include(ECMQtDeclareLoggingCategory)
......
......@@ -37,7 +37,7 @@ AboutProtocol::~AboutProtocol()
void AboutProtocol::get( const QUrl& )
{
QByteArray output;
QTextStream os( &output, QIODevice::WriteOnly );
os.setCodec( "ISO-8859-1" ); // In fact ASCII
......
......@@ -86,8 +86,8 @@ public:
}
return path.length() == 0 ? RootItem
: path.contains("/") ? ActivityPathItem
: ActivityRootItem;
: path.contains("/") ? ActivityPathItem
: ActivityRootItem;
}
void syncActivities(KActivities::Consumer &activities)
......@@ -142,14 +142,14 @@ public:
{
// return QString::fromUtf8(QUrl::toPercentEncoding(path));
return QString::fromLatin1(path.toUtf8().toBase64(
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals));
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals));
}
QString demangledPath(const QString &mangled) const
{
// return QUrl::fromPercentEncoding(mangled.toUtf8());
return QString::fromUtf8(QByteArray::fromBase64(mangled.toLatin1(),
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals));
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals));
}
// KActivities::Consumer activities;
......@@ -186,30 +186,30 @@ bool ActivitiesProtocol::rewriteUrl(const QUrl &url, QUrl &newUrl)
{
QString activity, path;
switch (d->pathType(url, &activity, &path)) {
case Private::RootItem:
case Private::ActivityRootItem:
if (activity == "current") {
KActivities::Consumer activities;
d->syncActivities(activities);
newUrl = QUrl(QStringLiteral("activities:/")
+ activities.currentActivity());
return true;
}
return false;
case Private::ActivityPathItem:
{
// auto demangled = d->demangledPath(path);
// QProcess::execute("kdialog",
// { "--passivepopup",
// path.midRef(1).toString() + "\n" + demangled });
newUrl = QUrl::fromLocalFile(path);
case Private::RootItem:
case Private::ActivityRootItem:
if (activity == "current") {
KActivities::Consumer activities;
d->syncActivities(activities);
newUrl = QUrl(QStringLiteral("activities:/")
+ activities.currentActivity());
return true;
}
return false;
default:
return true;
case Private::ActivityPathItem:
{
// auto demangled = d->demangledPath(path);
// QProcess::execute("kdialog",
// { "--passivepopup",
// path.midRef(1).toString() + "\n" + demangled });
newUrl = QUrl::fromLocalFile(path);
return true;
}
default:
return true;
}
}
......@@ -220,76 +220,76 @@ void ActivitiesProtocol::listDir(const QUrl &url)
QString activity, path;
switch (d->pathType(url, &activity, &path)) {
case Private::RootItem:
{
KIO::UDSEntryList udslist;
case Private::RootItem:
{
KIO::UDSEntryList udslist;
KIO::UDSEntry uds;
uds.reserve(9);
uds.fastInsert(KIO::UDSEntry::UDS_NAME, QStringLiteral("current"));
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, i18n("Current activity"));
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, i18n("Activity"));
uds.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("activities"));
uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory"));
uds.fastInsert(KIO::UDSEntry::UDS_ACCESS, 0500);
uds.fastInsert(KIO::UDSEntry::UDS_USER, KUser().loginName());
uds.fastInsert(KIO::UDSEntry::UDS_TARGET_URL, QStringLiteral("activities:/") + activities.currentActivity());
udslist << uds;
for (const auto& activity: activities.activities()) {
udslist << d->activityEntry(activity);
}
KIO::UDSEntry uds;
uds.reserve(9);
uds.fastInsert(KIO::UDSEntry::UDS_NAME, QStringLiteral("current"));
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, i18n("Current activity"));
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, i18n("Activity"));
uds.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("activities"));
uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory"));
uds.fastInsert(KIO::UDSEntry::UDS_ACCESS, 0500);
uds.fastInsert(KIO::UDSEntry::UDS_USER, KUser().loginName());
uds.fastInsert(KIO::UDSEntry::UDS_TARGET_URL, QStringLiteral("activities:/") + activities.currentActivity());
udslist << uds;
listEntries(udslist);
finished();
break;
for (const auto& activity: activities.activities()) {
udslist << d->activityEntry(activity);
}
case Private::ActivityRootItem:
{
KIO::UDSEntryList udslist;
listEntries(udslist);
finished();
break;
}
auto database = Common::Database::instance(
Common::Database::ResourcesDatabase,
Common::Database::ReadOnly);
case Private::ActivityRootItem:
{
KIO::UDSEntryList udslist;
if (!database) {
finished();
break;
}
auto database = Common::Database::instance(
Common::Database::ResourcesDatabase,
Common::Database::ReadOnly);
if (activity == "current") {
activity = activities.currentActivity();
}
if (!database) {
finished();
break;
}
static const auto queryString = QStringLiteral(
"SELECT targettedResource "
"FROM ResourceLink "
"WHERE usedActivity = '%1' "
"AND initiatingAgent = \":global\" "
);
if (activity == "current") {
activity = activities.currentActivity();
}
auto query = database->execQuery(queryString.arg(activity));
static const auto queryString = QStringLiteral(
"SELECT targettedResource "
"FROM ResourceLink "
"WHERE usedActivity = '%1' "
"AND initiatingAgent = \":global\" "
);
for (const auto& result: query) {
auto path = result[0].toString();
auto query = database->execQuery(queryString.arg(activity));
if (!QFile(path).exists()) continue;
for (const auto& result: query) {
auto path = result[0].toString();
KIO::UDSEntry uds;
if (!QFile(path).exists()) continue;
udslist << d->filesystemEntry(path);
}
KIO::UDSEntry uds;
listEntries(udslist);
finished();
break;
udslist << d->filesystemEntry(path);
}
case Private::ActivityPathItem:
ForwardingSlaveBase::listDir(QUrl::fromLocalFile(path));
break;
listEntries(udslist);
finished();
break;
}
case Private::ActivityPathItem:
ForwardingSlaveBase::listDir(QUrl::fromLocalFile(path));
break;
}
}
......@@ -303,55 +303,55 @@ void ActivitiesProtocol::stat(const QUrl& url)
QString activity;
switch (d->pathType(url, &activity)) {
case Private::RootItem:
{
QString dirName = i18n("Activities");
KIO::UDSEntry uds;
uds.reserve(6);
uds.fastInsert(KIO::UDSEntry::UDS_NAME, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("activities"));
uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory"));
statEntry(uds);
finished();
break;
}
case Private::RootItem:
{
QString dirName = i18n("Activities");
KIO::UDSEntry uds;
uds.reserve(6);
uds.fastInsert(KIO::UDSEntry::UDS_NAME, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("activities"));
uds.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
uds.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/directory"));
case Private::ActivityRootItem:
{
KActivities::Consumer activities;
d->syncActivities(activities);
statEntry(uds);
finished();
break;
}
if (activity == "current") {
activity = activities.currentActivity();
}
case Private::ActivityRootItem:
{
KActivities::Consumer activities;
d->syncActivities(activities);
statEntry(d->activityEntry(activity));
finished();
break;
if (activity == "current") {
activity = activities.currentActivity();
}
case Private::ActivityPathItem:
ForwardingSlaveBase::stat(url);
break;
statEntry(d->activityEntry(activity));
finished();
break;
}
case Private::ActivityPathItem:
ForwardingSlaveBase::stat(url);
break;
}
}
void ActivitiesProtocol::mimetype(const QUrl& url)
{
switch (d->pathType(url)) {
case Private::RootItem:
case Private::ActivityRootItem:
mimeType(QStringLiteral("inode/directory"));
finished();
break;
case Private::ActivityPathItem:
ForwardingSlaveBase::mimetype(url);
break;
case Private::RootItem:
case Private::ActivityRootItem:
mimeType(QStringLiteral("inode/directory"));
finished();
break;
case Private::ActivityPathItem:
ForwardingSlaveBase::mimetype(url);
break;
}
}
......
......@@ -39,25 +39,25 @@ namespace Common {
namespace {
#ifdef QT_DEBUG
QString lastExecutedQuery;
QString lastExecutedQuery;
#endif
std::mutex databases_mutex;
std::mutex databases_mutex;
struct DatabaseInfo {
Qt::HANDLE thread;
Database::OpenMode openMode;
};
struct DatabaseInfo {
Qt::HANDLE thread;
Database::OpenMode openMode;
};
bool operator<(const DatabaseInfo &left, const DatabaseInfo &right)
{
return
left.thread < right.thread ? true :
left.thread > right.thread ? false :
left.openMode < right.openMode;
}
bool operator<(const DatabaseInfo &left, const DatabaseInfo &right)
{
return
left.thread < right.thread ? true :
left.thread > right.thread ? false :
left.openMode < right.openMode;
}
std::map<DatabaseInfo, std::weak_ptr<Database>> databases;
std::map<DatabaseInfo, std::weak_ptr<Database>> databases;
};
class QSqlDatabaseWrapper {
......@@ -71,16 +71,16 @@ public:
: m_open(false)
{
m_connectionName =
"kactivities_db_resources_"
// Adding the thread number to the database name
+ QString::number((quintptr)info.thread)
// And whether it is read-only or read-write
+ (info.openMode == Database::ReadOnly ? "_readonly" : "_readwrite");
"kactivities_db_resources_"
// Adding the thread number to the database name
+ QString::number((quintptr)info.thread)
// And whether it is read-only or read-write
+ (info.openMode == Database::ReadOnly ? "_readonly" : "_readwrite");
m_database =
QSqlDatabase::contains(m_connectionName)
? QSqlDatabase::database(m_connectionName)
: QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), m_connectionName);
? QSqlDatabase::database(m_connectionName)
: QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), m_connectionName);
if (info.openMode == Database::ReadOnly) {
m_database.setConnectOptions(QStringLiteral("QSQLITE_OPEN_READONLY"));
......@@ -212,11 +212,11 @@ Database::Ptr Database::instance(Source source, OpenMode openMode)
ptr->setPragma(QStringLiteral("wal_autocheckpoint = 100"));
qDebug() << "KActivities: Database connection: " << ptr->d->database->connectionName()
<< "\n query_only: " << ptr->pragma(QStringLiteral("query_only"))
<< "\n journal_mode: " << ptr->pragma(QStringLiteral("journal_mode"))
<< "\n wal_autocheckpoint: " << ptr->pragma(QStringLiteral("wal_autocheckpoint"))
<< "\n synchronous: " << ptr->pragma(QStringLiteral("synchronous"))
;
<< "\n query_only: " << ptr->pragma(QStringLiteral("query_only"))
<< "\n journal_mode: " << ptr->pragma(QStringLiteral("journal_mode"))
<< "\n wal_autocheckpoint: " << ptr->pragma(QStringLiteral("wal_autocheckpoint"))
<< "\n synchronous: " << ptr->pragma(QStringLiteral("synchronous"))
;
return ptr;
}
......
......@@ -67,7 +67,7 @@ public:
QSqlDatabase &m_database;
};
#define DATABASE_TRANSACTION(A) \
#define DATABASE_TRANSACTION(A) \
/* enable this for debugging only: qDebug() << "Location:" << __FILE__ << __LINE__; */ \
Common::Database::Locker lock(A)
......@@ -77,7 +77,7 @@ private:
template <typename EscapeFunction>
QString parseStarPattern(const QString &pattern, const QString &joker,
EscapeFunction escape)
EscapeFunction escape)
{
const auto begin = pattern.constBegin();
const auto end = pattern.constEnd();
......@@ -89,10 +89,10 @@ QString parseStarPattern(const QString &pattern, const QString &joker,
// This should be available in the QString class...
auto stringFromIterators = [&](const QString::const_iterator &currentStart,
const QString::const_iterator &currentPosition) {
const QString::const_iterator &currentPosition) {
return pattern.mid(
std::distance(begin, currentStart),
std::distance(currentStart, currentPosition));
std::distance(begin, currentStart),
std::distance(currentStart, currentPosition));
};
// Escaping % and _ for sql like
......@@ -115,7 +115,7 @@ QString parseStarPattern(const QString &pattern, const QString &joker,
} else if (*currentPosition == '*') {
// Replacing the star with the sql like joker - %
resultPattern.append(escape(stringFromIterators(
currentStart, currentPosition)) + joker);
currentStart, currentPosition)) + joker);
currentStart = currentPosition + 1;
} else {
......@@ -125,7 +125,7 @@ QString parseStarPattern(const QString &pattern, const QString &joker,
if (currentStart != currentPosition) {
resultPattern.append(escape(stringFromIterators(
currentStart, currentPosition)));
currentStart, currentPosition)));
}
return resultPattern;
......
......@@ -40,55 +40,55 @@ QStringList schema()
return QStringList()
<< // Schema information table, used for versioning
<< // Schema information table, used for versioning
QStringLiteral("CREATE TABLE IF NOT EXISTS SchemaInfo ("
"key text PRIMARY KEY, value text"
")")
"key text PRIMARY KEY, value text"
")")
<< QStringLiteral("INSERT OR IGNORE INTO schemaInfo VALUES ('version', '%1')").arg(version())
<< QStringLiteral("UPDATE schemaInfo SET value = '%1' WHERE key = 'version'").arg(version())
<< QStringLiteral("INSERT OR IGNORE INTO schemaInfo VALUES ('version', '%1')").arg(version())
<< QStringLiteral("UPDATE schemaInfo SET value = '%1' WHERE key = 'version'").arg(version())
<< // The ResourceEvent table saves the Opened/Closed event pairs for
<< // The ResourceEvent table saves the Opened/Closed event pairs for
// a resource. The Accessed event is mapped to those.
// Focusing events are not stored in order not to get a
// huge database file and to lessen writes to the disk.
QStringLiteral("CREATE TABLE IF NOT EXISTS ResourceEvent ("
"usedActivity TEXT, "
"initiatingAgent TEXT, "
"targettedResource TEXT, "
"start INTEGER, "
"end INTEGER "
")")
<< // The ResourceScoreCache table stores the calculated scores
"usedActivity TEXT, "
"initiatingAgent TEXT, "
"targettedResource TEXT, "
"start INTEGER, "
"end INTEGER "
")")
<< // The ResourceScoreCache table stores the calculated scores
// for resources based on the recorded events.
QStringLiteral("CREATE TABLE IF NOT EXISTS ResourceScoreCache ("
"usedActivity TEXT, "
"initiatingAgent TEXT, "
"targettedResource TEXT, "
"scoreType INTEGER, "
"cachedScore FLOAT, "
"firstUpdate INTEGER, "
"lastUpdate INTEGER, "
"PRIMARY KEY(usedActivity, initiatingAgent, targettedResource)"
")")
<< // @since 2014.05.05
"usedActivity TEXT, "
"initiatingAgent TEXT, "
"targettedResource TEXT, "
"scoreType INTEGER, "
"cachedScore FLOAT, "
"firstUpdate INTEGER, "
"lastUpdate INTEGER, "
"PRIMARY KEY(usedActivity, initiatingAgent, targettedResource)"
")")
<< // @since 2014.05.05
// The ResourceLink table stores the information, formerly kept by
// Nepomuk, of which resources are linked to which activities.
// The additional features compared to the old days are
// the ability to limit the link to specific applications, and
// to create global links.
QStringLiteral("CREATE TABLE IF NOT EXISTS ResourceLink ("
"usedActivity TEXT, "
"initiatingAgent TEXT, "
"targettedResource TEXT, "
"PRIMARY KEY(usedActivity, initiatingAgent, targettedResource)"
")")
"usedActivity TEXT, "
"initiatingAgent TEXT, "
"targettedResource TEXT, "
"PRIMARY KEY(usedActivity, initiatingAgent, targettedResource)"
")")
<< // @since 2015.01.18
<< // @since 2015.01.18
// The ResourceInfo table stores the collected information about a
// resource that is not agent nor activity related like the
// title and the mime type.
......@@ -96,15 +96,15 @@ QStringList schema()
// flag is set to true. This is done for the agents to be able to
// override these.
QStringLiteral("CREATE TABLE IF NOT EXISTS ResourceInfo ("
"targettedResource TEXT, "
"title TEXT, "
"mimetype TEXT, "
"autoTitle INTEGER, "
"autoMimetype INTEGER, "
"PRIMARY KEY(targettedResource)"
")")
;
"targettedResource TEXT, "
"title TEXT, "
"mimetype TEXT, "
"autoTitle INTEGER, "
"autoMimetype INTEGER, "
"PRIMARY KEY(targettedResource)"
")")
;
}
// TODO: This will require some refactoring after we introduce more databases
......@@ -124,8 +124,8 @@ QString path()
return
(app->property(overrideFlagProperty).toBool()) ?
app->property(overrideFileProperty).toString() :
defaultPath();
app->property(overrideFileProperty).toString() :
defaultPath();
}
void overridePath(const QString &path)
......@@ -141,8 +141,8 @@ void initSchema(Database &database)
QString dbSchemaVersion;
auto query = database.execQuery(
QStringLiteral("SELECT value FROM SchemaInfo WHERE key = 'version'"),
/* ignore error */ true);
QStringLiteral("SELECT value FROM SchemaInfo WHERE key = 'version'"),
/* ignore error */ true);
if (query.next()) {
dbSchemaVersion = query.value(0).toString();
......@@ -176,11 +176,11 @@ void initSchema(Database &database)
if (dbSchemaVersion < QStringLiteral("2015.02.09")) {
const QString updateActivity =
QStringLiteral("SET usedActivity=':global' "
"WHERE usedActivity IS NULL OR usedActivity = ''");
"WHERE usedActivity IS NULL OR usedActivity = ''");
const QString updateAgent =
QStringLiteral("SET initiatingAgent=':global' "
"WHERE initiatingAgent IS NULL OR initiatingAgent = ''");
"WHERE initiatingAgent IS NULL OR initiatingAgent = ''");
// When the activity field was empty, it meant the file was
// linked to all activities (aka :global)
......