diff --git a/runners/CMakeLists.txt b/runners/CMakeLists.txt index 6015c7ddc..5a5f32bf9 100644 --- a/runners/CMakeLists.txt +++ b/runners/CMakeLists.txt @@ -1,23 +1,23 @@ # add_subdirectory(browserhistory) add_subdirectory(converter) add_subdirectory(datetime) add_subdirectory(katesessions) # add_subdirectory(konquerorsessions) # add_subdirectory(kopete) # add_subdirectory(mediawiki) add_subdirectory(spellchecker) add_subdirectory(characters) add_subdirectory(dictionary) # # 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) # endif(QJSON_FOUND) diff --git a/runners/konsolesessions/CMakeLists.txt b/runners/konsolesessions/CMakeLists.txt index c1d5cea98..8617db863 100644 --- 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.cpp b/runners/konsolesessions/konsolesessions.cpp index bf6a6f6f3..33848f565 100644 --- a/runners/konsolesessions/konsolesessions.cpp +++ b/runners/konsolesessions/konsolesessions.cpp @@ -1,156 +1,184 @@ /* * Copyright 2008 Montel Laurent * based on kate session from sebas * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program 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 General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #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 :"< i(m_sessions); while (i.hasNext()) { i.next(); Plasma::QueryMatch match(this); match.setType(Plasma::QueryMatch::PossibleMatch); match.setRelevance(1.0); - match.setIcon(m_icon); + match.setIconName(QStringLiteral("utilities-terminal")); match.setData(i.key()); match.setText(QLatin1String( "Konsole: " ) + i.value()); - context.addMatch(term, match); + context.addMatch(match); } } else { if (term.startsWith(QLatin1String("konsole "), Qt::CaseInsensitive)) { term.remove(0, 8); } QHashIterator i(m_sessions); while (i.hasNext()) { if (!context.isValid()) { return; } i.next(); - kDebug() << "checking" << term << i.value(); + if (i.value().contains(term, Qt::CaseInsensitive)) { Plasma::QueryMatch match(this); match.setType(Plasma::QueryMatch::PossibleMatch); - match.setIcon(m_icon); + match.setIconName(QStringLiteral("utilities-terminal")); match.setData(i.key()); match.setText(QLatin1String( "Konsole: " ) + i.value()); if (i.value().compare(term, Qt::CaseInsensitive) == 0) { match.setRelevance(1.0); } else { match.setRelevance(0.6); } - context.addMatch(term, match); + context.addMatch(match); } } } } void KonsoleSessions::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context) const QString session = match.data().toString(); - kDebug() << "Open Konsole Session " << session; if (!session.isEmpty()) { - QStringList args; - args << QLatin1String( "--profile" ); - args << session; - kDebug() << "=== START: konsole" << args; - KToolInvocation::kdeinitExec(QLatin1String( "konsole" ), args); + return; } + + const QStringList args { + QStringLiteral("--profile"), + session + }; + KToolInvocation::kdeinitExec(QStringLiteral("konsole"), args); } + +K_EXPORT_PLASMA_RUNNER(konsolesessions, KonsoleSessions) + +#include "konsolesessions.moc" diff --git a/runners/konsolesessions/konsolesessions.h b/runners/konsolesessions/konsolesessions.h index a98c253f9..e23b4339f 100644 --- a/runners/konsolesessions/konsolesessions.h +++ b/runners/konsolesessions/konsolesessions.h @@ -1,47 +1,49 @@ /* * Copyright 2008 Montel Laurent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program 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 General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #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