kdeplasma-addons: adjust to runners changes

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-18 18:19:52 +03:00
parent e686f4bb8a
commit 1b2019d884
2 changed files with 15 additions and 62 deletions

View file

@ -31,13 +31,13 @@
#include <KStringHandler>
#include <QFile>
bool katesessions_runner_compare_sessions(const QString &s1, const QString &s2) {
return KStringHandler::naturalCompare(s1,s2)==-1;
bool katesessions_runner_compare_sessions(const QString &s1, const QString &s2)
{
return KStringHandler::naturalCompare(s1,s2) == -1;
}
KateSessions::KateSessions(QObject *parent, const QVariantList& args)
: Plasma::AbstractRunner(parent, args),
m_sessionWatch(0)
: Plasma::AbstractRunner(parent, args)
{
setObjectName(QLatin1String("Kate Sessions"));
setIgnoredTypes(Plasma::RunnerContext::File | Plasma::RunnerContext::Directory | Plasma::RunnerContext::NetworkLocation);
@ -47,39 +47,15 @@ KateSessions::KateSessions(QObject *parent, const QVariantList& args)
addSyntax(s);
addSyntax(Plasma::RunnerSyntax(QLatin1String("kate"), i18n("Lists all the Kate editor sessions in your account.")));
connect(this, SIGNAL(prepare()), SLOT(slotPrepare()));
connect(this, SIGNAL(teardown()), SLOT(slotTeardown()));
}
KateSessions::~KateSessions()
void KateSessions::match(Plasma::RunnerContext &context)
{
}
void KateSessions::slotPrepare()
{
loadSessions();
// 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()));
QString term = context.query();
if (term.length() < 3) {
return;
}
}
void KateSessions::slotTeardown()
{
delete m_sessionWatch;
m_sessionWatch = 0;
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();
@ -99,19 +75,6 @@ void KateSessions::loadSessions()
sessions.append( name );
}
qSort(sessions.begin(),sessions.end(),katesessions_runner_compare_sessions);
m_sessions = sessions;
}
void KateSessions::match(Plasma::RunnerContext &context)
{
if (m_sessions.isEmpty()) {
return;
}
QString term = context.query();
if (term.length() < 3) {
return;
}
bool listAll = false;
@ -131,7 +94,7 @@ void KateSessions::match(Plasma::RunnerContext &context)
return;
}
foreach (const QString &session, m_sessions) {
foreach (const QString &session, sessions) {
if (!context.isValid()) {
return;
}

View file

@ -24,24 +24,14 @@
class KDirWatch;
class KateSessions : public Plasma::AbstractRunner {
class KateSessions : public Plasma::AbstractRunner
{
Q_OBJECT
public:
KateSessions( QObject *parent, const QVariantList& args );
public:
KateSessions( QObject *parent, const QVariantList& args );
~KateSessions();
void match(Plasma::RunnerContext &context);
void run(const Plasma::QueryMatch &match);
private Q_SLOTS:
void loadSessions();
void slotPrepare();
void slotTeardown();
private:
KDirWatch* m_sessionWatch;
QStringList m_sessions;
void match(Plasma::RunnerContext &context);
void run(const Plasma::QueryMatch &match);
};
K_EXPORT_PLASMA_RUNNER(katesessions, KateSessions)