summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Uwe Broulik <[email protected]>2017-03-17 12:13:41 +0100
committerKai Uwe Broulik <[email protected]>2017-03-17 12:13:41 +0100
commit412f19df9cbb80b2f2b10cea8948bbe6885c45b0 (patch)
treefdc11463355b60810fb5d9dcfcb70e37e4e1a02d
parent8068537eeab0332b421dc1c2afd8183ac6698616 (diff)
Port Kate Sessions Runner
This brings back the ability to find and launch Kate sessions through KRunner, e.g. "kate foo" will show the "foo" Kate session if there is one. BUG: 377284 FIXED-IN: 5.10.0 Differential Revision: https://phabricator.kde.org/D5077
-rw-r--r--runners/CMakeLists.txt2
-rw-r--r--runners/katesessions/CMakeLists.txt12
-rw-r--r--runners/katesessions/katesessions.cpp76
-rw-r--r--runners/katesessions/katesessions.h10
-rw-r--r--runners/katesessions/plasma-runner-katesessions.desktop (renamed from runners/katesessions/katesessions.desktop)2
5 files changed, 49 insertions, 53 deletions
diff --git a/runners/CMakeLists.txt b/runners/CMakeLists.txt
index fecb3d5..abe2946 100644
--- a/runners/CMakeLists.txt
+++ b/runners/CMakeLists.txt
@@ -1,7 +1,7 @@
# add_subdirectory(browserhistory)
add_subdirectory(converter)
add_subdirectory(datetime)
-# add_subdirectory(katesessions)
+add_subdirectory(katesessions)
# add_subdirectory(konquerorsessions)
# add_subdirectory(kopete)
# add_subdirectory(mediawiki)
diff --git a/runners/katesessions/CMakeLists.txt b/runners/katesessions/CMakeLists.txt
index 2ecaa1b..5fd3425 100644
--- a/runners/katesessions/CMakeLists.txt
+++ b/runners/katesessions/CMakeLists.txt
@@ -1,11 +1,11 @@
+add_definitions(-DTRANSLATION_DOMAIN=\"plasma_runner_katesessions\")
+
set(krunner_katesessions_SRCS
katesessions.cpp
)
-kde4_add_plugin(krunner_katesessions ${krunner_katesessions_SRCS})
-target_link_libraries(krunner_katesessions ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS})
-
-install(TARGETS krunner_katesessions DESTINATION ${PLUGIN_INSTALL_DIR} )
-
-install(FILES katesessions.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+add_library(krunner_katesessions MODULE ${krunner_katesessions_SRCS})
+target_link_libraries(krunner_katesessions KF5::KIOCore KF5::I18n KF5::Runner)
+install(TARGETS krunner_katesessions DESTINATION ${PLUGIN_INSTALL_DIR})
+install(FILES plasma-runner-katesessions.desktop DESTINATION ${SERVICES_INSTALL_DIR})
diff --git a/runners/katesessions/katesessions.cpp b/runners/katesessions/katesessions.cpp
index c709625..fe4ebdc 100644
--- a/runners/katesessions/katesessions.cpp
+++ b/runners/katesessions/katesessions.cpp
@@ -1,5 +1,6 @@
/*
* Copyright 2008 Sebastian Kügler <[email protected]>
+ * Copyright 2017 Kai Uwe Broulik <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@@ -19,25 +20,20 @@
#include "katesessions.h"
+#include <QCollator>
+#include <QDir>
+#include <QFileInfo>
+#include <QStandardPaths>
-#include <KDebug>
#include <KDirWatch>
-#include <KStandardDirs>
+#include <KLocalizedString>
#include <KToolInvocation>
-#include <KIcon>
-#include <KConfig>
-#include <KConfigGroup>
-#include <KUrl>
-#include <KStringHandler>
-#include <QFile>
-
-bool katesessions_runner_compare_sessions(const QString &s1, const QString &s2) {
- return KStringHandler::naturalCompare(s1,s2)==-1;
-}
+
+K_EXPORT_PLASMA_RUNNER(katesessionsrunner, KateSessions)
KateSessions::KateSessions(QObject *parent, const QVariantList& args)
: Plasma::AbstractRunner(parent, args),
- m_sessionWatch(0)
+ m_sessionWatch(nullptr)
{
setObjectName(QLatin1String("Kate Sessions"));
setIgnoredTypes(Plasma::RunnerContext::File | Plasma::RunnerContext::Directory | Plasma::RunnerContext::NetworkLocation);
@@ -48,6 +44,9 @@ KateSessions::KateSessions(QObject *parent, const QVariantList& args)
setDefaultSyntax(Plasma::RunnerSyntax(QLatin1String("kate"), i18n("Lists all the Kate editor sessions in your account.")));
+ m_sessionsFolderPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ + QLatin1String("/kate/sessions");
+
connect(this, SIGNAL(prepare()), SLOT(slotPrepare()));
connect(this, SIGNAL(teardown()), SLOT(slotTeardown()));
}
@@ -63,42 +62,39 @@ void KateSessions::slotPrepare()
// listen for changes to the list of kate sessions
if (!m_sessionWatch) {
KDirWatch *m_sessionWatch = new KDirWatch(this);
- const QStringList sessiondirs = KGlobal::dirs()->findDirs("data", QLatin1String("kate/sessions/"));
- foreach (const QString &dir, sessiondirs) {
- m_sessionWatch->addDir(dir);
- }
- connect(m_sessionWatch,SIGNAL(dirty(QString)),this,SLOT(loadSessions()));
- connect(m_sessionWatch,SIGNAL(created(QString)),this,SLOT(loadSessions()));
- connect(m_sessionWatch,SIGNAL(deleted(QString)),this,SLOT(loadSessions()));
+ m_sessionWatch->addDir(m_sessionsFolderPath);
+ connect(m_sessionWatch, &KDirWatch::dirty, this, &KateSessions::loadSessions);
+ connect(m_sessionWatch, &KDirWatch::created, this, &KateSessions::loadSessions);
+ connect(m_sessionWatch, &KDirWatch::deleted, this, &KateSessions::loadSessions);
}
}
void KateSessions::slotTeardown()
{
delete m_sessionWatch;
- m_sessionWatch = 0;
+ m_sessionWatch = nullptr;
m_sessions.clear();
}
void KateSessions::loadSessions()
{
- // Switch kate session: -u
- // Should we add a match for this option or would that clutter the matches too much?
- QStringList sessions = QStringList();
- const QStringList list = KGlobal::dirs()->findAllResources( "data", QLatin1String("kate/sessions/*.katesession"), KStandardDirs::NoDuplicates );
- KUrl url;
- for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it)
- {
-/* KConfig _config( *it, KConfig::SimpleConfig );
- KConfigGroup config(&_config, "General" );
- QString name = config.readEntry( "Name" );*/
- url.setPath(*it);
- QString name=url.fileName();
- name = QUrl::fromPercentEncoding(QFile::encodeName(url.fileName()));
- name.chop(12);///.katesession==12
- sessions.append( name );
+ QStringList sessions;
+
+ QDir sessionsDir(m_sessionsFolderPath);
+
+ const auto &sessionFiles = sessionsDir.entryInfoList({QStringLiteral("*.katesession")}, QDir::Files);
+
+ for (const QFileInfo &sessionFile : sessionFiles) {
+ const QString name = QUrl::fromPercentEncoding(sessionFile.baseName().toLocal8Bit()); // is this the right encoding?
+ sessions.append(name);
}
- qSort(sessions.begin(),sessions.end(),katesessions_runner_compare_sessions);
+
+ QCollator collator;
+ collator.setCaseSensitivity(Qt::CaseInsensitive);
+ std::sort(sessions.begin(), sessions.end(), [&collator](const QString &a, const QString &b) {
+ return collator.compare(a, b) < 0;
+ });
+
m_sessions = sessions;
}
@@ -153,11 +149,11 @@ void KateSessions::match(Plasma::RunnerContext &context)
match.setRelevance(0.8);
}
}
- match.setIcon(KIcon(QLatin1String("kate")));
+ match.setIconName(QStringLiteral("kate"));
match.setData(session);
match.setText(session);
match.setSubtext(i18n("Open Kate Session"));
- context.addMatch(term, match);
+ context.addMatch(match);
}
}
}
@@ -166,7 +162,6 @@ void KateSessions::run(const Plasma::RunnerContext &context, const Plasma::Query
{
Q_UNUSED(context)
QString session = match.data().toString();
- kDebug() << "Open Kate Session " << session;
if (!session.isEmpty()) {
QStringList args;
@@ -175,3 +170,4 @@ void KateSessions::run(const Plasma::RunnerContext &context, const Plasma::Query
}
}
+#include "katesessions.moc"
diff --git a/runners/katesessions/katesessions.h b/runners/katesessions/katesessions.h
index 6efc971..86c53e5 100644
--- a/runners/katesessions/katesessions.h
+++ b/runners/katesessions/katesessions.h
@@ -1,5 +1,6 @@
/*
* Copyright 2008 Sebastian Kügler <[email protected]>
+ * Copyright 2017 Kai Uwe Broulik <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@@ -20,7 +21,7 @@
#ifndef KATESESSIONS_H
#define KATESESSIONS_H
-#include <plasma/abstractrunner.h>
+#include <krunner/abstractrunner.h>
class KDirWatch;
@@ -31,8 +32,8 @@ class KateSessions : public Plasma::AbstractRunner {
KateSessions( QObject *parent, const QVariantList& args );
~KateSessions();
- void match(Plasma::RunnerContext &context);
- void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match);
+ void match(Plasma::RunnerContext &context) override;
+ void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) override;
private Q_SLOTS:
void loadSessions();
@@ -41,9 +42,8 @@ class KateSessions : public Plasma::AbstractRunner {
private:
KDirWatch* m_sessionWatch;
+ QString m_sessionsFolderPath;
QStringList m_sessions;
};
-K_EXPORT_PLASMA_RUNNER(katesessions, KateSessions)
-
#endif
diff --git a/runners/katesessions/katesessions.desktop b/runners/katesessions/plasma-runner-katesessions.desktop
index 000be97..f5d5d7f 100644
--- a/runners/katesessions/katesessions.desktop
+++ b/runners/katesessions/plasma-runner-katesessions.desktop
@@ -117,7 +117,7 @@ X-KDE-Library=krunner_katesessions
X-KDE-PluginInfo-Author=Sebastian Kügler
X-KDE-PluginInfo-Name=katesessions
-X-KDE-PluginInfo-Version=1.0
+X-KDE-PluginInfo-Version=1.1
X-KDE-PluginInfo-License=LGPL
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-AdvertiseSingleRunnerQueryMode=true