diff --git a/runners/CMakeLists.txt b/runners/CMakeLists.txt --- a/runners/CMakeLists.txt +++ b/runners/CMakeLists.txt @@ -12,11 +12,11 @@ # if(KDEPIMLIBS_FOUND) # add_subdirectory(events) # endif(KDEPIMLIBS_FOUND) -# -# if(NOT WIN32) -# add_subdirectory(konsolesessions) -# endif(NOT WIN32) -# + +if(NOT WIN32) + add_subdirectory(konsolesessions) +endif(NOT WIN32) + # if(QJSON_FOUND) # add_subdirectory(youtube) # add_subdirectory(translator) diff --git a/runners/konsolesessions/CMakeLists.txt b/runners/konsolesessions/CMakeLists.txt --- a/runners/konsolesessions/CMakeLists.txt +++ b/runners/konsolesessions/CMakeLists.txt @@ -1,11 +1,15 @@ +add_definitions(-DTRANSLATION_DOMAIN="plasma_runner_konsolesessions") + set(krunner_konsolesessions_SRCS konsolesessions.cpp ) -kde4_add_plugin(krunner_konsolesessions ${krunner_konsolesessions_SRCS}) -target_link_libraries(krunner_konsolesessions ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS}) - -install(TARGETS krunner_konsolesessions DESTINATION ${PLUGIN_INSTALL_DIR} ) +add_library(krunner_konsolesessions MODULE ${krunner_konsolesessions_SRCS}) +target_link_libraries(krunner_konsolesessions + KF5::Runner + KF5::I18n +) -install(FILES konsolesessions.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +install(TARGETS krunner_konsolesessions DESTINATION ${KDE_INSTALL_PLUGINDIR}) +install(FILES konsolesessions.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) diff --git a/runners/konsolesessions/konsolesessions.h b/runners/konsolesessions/konsolesessions.h --- a/runners/konsolesessions/konsolesessions.h +++ b/runners/konsolesessions/konsolesessions.h @@ -20,28 +20,30 @@ #ifndef KONSOLESESSIONS_H #define KONSOLESESSIONS_H -#include +#include + +class KDirWatch; -#include class KonsoleSessions : public Plasma::AbstractRunner { Q_OBJECT public: KonsoleSessions( QObject *parent, const QVariantList& args ); - ~KonsoleSessions(); + ~KonsoleSessions() override; - 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; -protected slots: +private Q_SLOTS: void loadSessions(); + void slotPrepare(); + void slotTeardown(); + private: - KIcon m_icon; + KDirWatch* m_sessionWatch = nullptr; + QHash m_sessions; - QTime m_time; }; -K_EXPORT_PLASMA_RUNNER(konsolesessions, KonsoleSessions) - #endif diff --git a/runners/konsolesessions/konsolesessions.cpp b/runners/konsolesessions/konsolesessions.cpp --- a/runners/konsolesessions/konsolesessions.cpp +++ b/runners/konsolesessions/konsolesessions.cpp @@ -20,67 +20,90 @@ #include "konsolesessions.h" -#include +// KF #include -#include -#include #include -#include +#include #include -#include -#include +// Qt +#include +#include +#include KonsoleSessions::KonsoleSessions(QObject *parent, const QVariantList& args) : Plasma::AbstractRunner(parent, args) { - Q_UNUSED(args); - setObjectName(QLatin1String( "Konsole Sessions" )); - m_icon = KIcon(QLatin1String( "utilities-terminal" )); - setIgnoredTypes(Plasma::RunnerContext::File | Plasma::RunnerContext::Directory | Plasma::RunnerContext::NetworkLocation); - loadSessions(); + setObjectName(QStringLiteral("Konsole Sessions")); - KDirWatch *historyWatch = new KDirWatch(this); - const QStringList sessiondirs = KGlobal::dirs()->findDirs("data", QLatin1String( "konsole/" )); - foreach (const QString &dir, sessiondirs) { - historyWatch->addDir(dir); - } - - connect(historyWatch, SIGNAL(dirty(QString)), this,SLOT(loadSessions())); - connect(historyWatch, SIGNAL(created(QString)), this,SLOT(loadSessions())); - connect(historyWatch, SIGNAL(deleted(QString)), this,SLOT(loadSessions())); + setIgnoredTypes(Plasma::RunnerContext::File | Plasma::RunnerContext::Directory | Plasma::RunnerContext::NetworkLocation); - Plasma::RunnerSyntax s(QLatin1String( ":q:" ), i18n("Finds Konsole sessions matching :q:.")); - s.addExampleQuery(QLatin1String( "konsole :q:" )); + Plasma::RunnerSyntax s(QStringLiteral( ":q:" ), i18n("Finds Konsole sessions matching :q:.")); + s.addExampleQuery(QStringLiteral( "konsole :q:" )); addSyntax(s); - addSyntax(Plasma::RunnerSyntax(QLatin1String( "konsole" ), i18n("Lists all the Konsole sessions in your account."))); + setDefaultSyntax(Plasma::RunnerSyntax(QStringLiteral( "konsole" ), i18n("Lists all the Konsole sessions in your account."))); + + connect(this, &Plasma::AbstractRunner::prepare, this, &KonsoleSessions::slotPrepare); + connect(this, &Plasma::AbstractRunner::teardown, this, &KonsoleSessions::slotTeardown); } KonsoleSessions::~KonsoleSessions() { } +void KonsoleSessions::slotPrepare() +{ + loadSessions(); + + if (!m_sessionWatch) { + m_sessionWatch = new KDirWatch(this); + const QStringList sessiondirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("konsole"), QStandardPaths::LocateDirectory); + foreach (const QString &dir, sessiondirs) { + m_sessionWatch->addDir(dir); + } + + connect(m_sessionWatch, &KDirWatch::dirty, this, &KonsoleSessions::loadSessions); + connect(m_sessionWatch, &KDirWatch::created, this, &KonsoleSessions::loadSessions); + connect(m_sessionWatch, &KDirWatch::deleted, this, &KonsoleSessions::loadSessions); + } +} + +void KonsoleSessions::slotTeardown() +{ + delete m_sessionWatch; + m_sessionWatch = nullptr; + m_sessions.clear(); +} + void KonsoleSessions::loadSessions() { - const QStringList list = KGlobal::dirs()->findAllResources("data", QLatin1String( "konsole/*.profile" ), KStandardDirs::NoDuplicates); - QStringList::ConstIterator end = list.constEnd(); - for (QStringList::ConstIterator it = list.constBegin(); it != end; ++it) { - QFileInfo info(*it); - const QString profileName = KIO::decodeFileName(info.baseName()); + m_sessions.clear(); + + QStringList profilesPaths; + const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("konsole"), QStandardPaths::LocateDirectory); + + for (const auto& dir : dirs) { + const QStringList fileNames = QDir(dir).entryList({QStringLiteral("*.profile")}); + for (const QString& fileName : fileNames) { + profilesPaths.append(dir + QLatin1Char('/') + fileName); + } + } + + for (const auto& profilePath : qAsConst(profilesPaths)) { + QFileInfo info(profilePath); + const QString profileName = info.baseName(); QString niceName=profileName; - //kDebug()<<" loadSessions :"; - KConfig _config(*it, KConfig::SimpleConfig); + KConfig _config(profilePath, KConfig::SimpleConfig); if (_config.hasGroup("General")) { KConfigGroup cfg(&_config, "General"); if (cfg.hasKey("Name")) { niceName = cfg.readEntry("Name"); } m_sessions.insert(profileName, niceName); - //kDebug()<<" profileName :"<