diff --git a/runners/CMakeLists.txt b/runners/CMakeLists.txt --- 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 --- 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.h b/runners/katesessions/katesessions.h --- a/runners/katesessions/katesessions.h +++ b/runners/katesessions/katesessions.h @@ -1,5 +1,6 @@ /* * Copyright 2008 Sebastian Kügler + * Copyright 2017 Kai Uwe Broulik * * 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 +#include class KDirWatch; @@ -31,19 +32,18 @@ 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(); void slotPrepare(); void slotTeardown(); private: KDirWatch* m_sessionWatch; + QString m_sessionsFolderPath; QStringList m_sessions; }; -K_EXPORT_PLASMA_RUNNER(katesessions, KateSessions) - #endif diff --git a/runners/katesessions/katesessions.cpp b/runners/katesessions/katesessions.cpp --- a/runners/katesessions/katesessions.cpp +++ b/runners/katesessions/katesessions.cpp @@ -1,5 +1,6 @@ /* * Copyright 2008 Sebastian Kügler + * Copyright 2017 Kai Uwe Broulik * * 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 +#include +#include +#include -#include #include -#include +#include #include -#include -#include -#include -#include -#include -#include - -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 @@ 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 @@ // 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,25 +149,25 @@ 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); } } } void KateSessions::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context) QString session = match.data().toString(); - kDebug() << "Open Kate Session " << session; if (!session.isEmpty()) { QStringList args; args << QLatin1String("--start") << session << QLatin1String("-n"); KToolInvocation::kdeinitExec(QLatin1String("kate"), args); } } +#include "katesessions.moc" diff --git a/runners/katesessions/katesessions.desktop b/runners/katesessions/plasma-runner-katesessions.desktop rename from runners/katesessions/katesessions.desktop rename to runners/katesessions/plasma-runner-katesessions.desktop --- a/runners/katesessions/katesessions.desktop +++ b/runners/katesessions/plasma-runner-katesessions.desktop @@ -117,7 +117,7 @@ X-KDE-PluginInfo-Author=Sebastian Kügler X-KDE-PluginInfo-Email=sebas@kde.org 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