Commit 2f3bcfa8 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Port konsolesessions runner to Plasma5/Qt5

Summary: Ported following changes in katesessions runner and konsole.

Test Plan:
Konsole profiles are shown as matches when entering "konsole"
and "konsole <lettersofprofiles>"

Reviewers: broulik, jriddell, davidedmundson

Reviewed By: davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D10110
parent 6e4a9baa
......@@ -12,11 +12,11 @@ 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)
......
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})
......@@ -20,58 +20,82 @@
#include "konsolesessions.h"
#include <QFileInfo>
// KF
#include <KDirWatch>
#include <KDebug>
#include <KStandardDirs>
#include <KToolInvocation>
#include <KIcon>
#include <KLocalizedString>
#include <KConfig>
#include <KConfigGroup>
#include <kio/global.h>
// Qt
#include <QFileInfo>
#include <QDir>
#include <QStandardPaths>
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");
......@@ -80,7 +104,6 @@ void KonsoleSessions::loadSessions()
}
m_sessions.insert(profileName, niceName);
//kDebug()<<" profileName :"<<profileName<<" niceName :"<<niceName;
}
}
}
......@@ -103,10 +126,10 @@ void KonsoleSessions::match(Plasma::RunnerContext &context)
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)) {
......@@ -119,11 +142,11 @@ void KonsoleSessions::match(Plasma::RunnerContext &context)
}
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());
......@@ -133,7 +156,7 @@ void KonsoleSessions::match(Plasma::RunnerContext &context)
match.setRelevance(0.6);
}
context.addMatch(term, match);
context.addMatch(match);
}
}
}
......@@ -143,14 +166,19 @@ void KonsoleSessions::run(const Plasma::RunnerContext &context, const Plasma::Qu
{
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"
......@@ -20,28 +20,30 @@
#ifndef KONSOLESESSIONS_H
#define KONSOLESESSIONS_H
#include <plasma/abstractrunner.h>
#include <KRunner/AbstractRunner>
class KDirWatch;
#include <KIcon>
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<QString, QString> m_sessions;
QTime m_time;
};
K_EXPORT_PLASMA_RUNNER(konsolesessions, KonsoleSessions)
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment