This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to enable own krunner plugin

Tags: None
(comma "," separated)
lima2
Registered Member
Posts
3
Karma
0
OS

How to enable own krunner plugin

Mon Feb 07, 2011 9:31 am
Hi there,

I am trying to implement an own runner for the krunner.
To do this I am following the tutorial on techbase: http://techbase.kde.org/Development/Tut ... ractRunner

I have successfully built the .so file.
I tried to enable the krunner doing the following:

1.) copied the .desktop file to /usr/share/kde4/services
2.) copied the .so file to /usr/lib/kde4
3.) ran kbuildsycoca4
4.) logged out of kde4
5.) logged in again
6.) summoned the krunner dialog (ALT+F2)
7.) clicked the settings button
8.) searched the list of available plugins
9.) realized that my runner is not in the list

This leads me to several questions:

Is there anything wrong in the steps I did to enable the new runner?

How can I enable this new krunner?
Where do I have to put the lib?
Where do I have to put the .desktop file?
Is there anything left to do to enable this new krunner?

Regards,
Markus
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: How to enable own krunner plugin

Tue Feb 08, 2011 12:22 am
Can you post your source code please? It is possible that the X-KDE-Library field of your *.desktop file does not match the library you placed in /usr/lib/kde4/


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
lima2
Registered Member
Posts
3
Karma
0
OS
Hi. I checked the X-KDE-Library field of the desktop file: It matches the lib in /usr/lib/kde4

Here is the requested code. It is essentially the code of the mentioned tutorial:

homefilesrunner.h:
Code: Select all
#ifndef HOMEFILERUNNER_H
#define HOMEFILERUNNER_H

#include <Plasma/AbstractRunner>

#include <QHash>
#include <QtCore>

#include <KIcon>
#include <KRun>
#include <KMimeType>
#include <QtGui>

class HomeFilesRunner : public Plasma::AbstractRunner
{
    Q_OBJECT

    public:
        HomeFilesRunner(QObject *parent, const QVariantList &args);

        void match(Plasma::RunnerContext &context);
        void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match);
        void createRunOptions(QWidget *widget);
        void reloadConfiguration();

    protected Q_SLOTS:
        void init();
        void prepareForMatchSession();
        void matchSessionFinished();

    private:
        QHash<QString, KIcon> m_iconCache;
        QString m_path;
        QString m_triggerWord;
};


#endif



homefilesrunner.cpp:
Code: Select all
#include "homefilesrunner.h"

HomeFilesRunner::HomeFilesRunner(QObject *parent, const QVariantList &args)
    : AbstractRunner(parent, args)
{
    setIgnoredTypes(Plasma::RunnerContext::NetworkLocation |
                    Plasma::RunnerContext::Executable |
                    Plasma::RunnerContext::ShellCommand);
    setSpeed(SlowSpeed);
    setPriority(LowPriority);
    setHasRunOptions(true);
}

void HomeFilesRunner::init()
{
    reloadConfiguration();
    connect(this, SIGNAL(prepare()),this,SLOT(prepareForMatchSession()));
    connect(this, SIGNAL(teardown()),this,SLOT(matchSessionFinished()));
}

void HomeFilesRunner::matchSessionFinished()
{
    m_iconCache.clear();
}

void HomeFilesRunner::match(Plasma::RunnerContext &context)
{
    QString query = context.query();
    if (query == QChar('.') || query == "..") {
        return;
    }

    if (!m_triggerWord.isEmpty()) {
        if (!query.startsWith(m_triggerWord)) {
            return;
        }

        query.remove(0, m_triggerWord.length());
    }

    if (query.length() > 2) {
        query.prepend('*').append('*');
    }

    QDir dir(m_path);
    QList<Plasma::QueryMatch> matches;

    foreach( const QString &file, dir.entryList(QStringList(query))) {
        const QString path = dir.absoluteFilePath(file);
        if (!path.startsWith(m_path)) {
            continue;
        }

        if (!context.isValid()) {
            return;
        }

        Plasma::QueryMatch match(this);
        match.setText(i18n("Open %1",path));
        match.setData(path);
        match.setId(path);
        if (m_iconCache.contains(path)) {
            match.setIcon(m_iconCache.value(path));
        } else {
            KIcon icon(KMimeType::iconNameForUrl(path));
            m_iconCache.insert(path, icon);
            match.setIcon(icon);
        }

        if (file.compare(query, Qt::CaseInsensitive)) {
            match.setRelevance(1.0);
            match.setType(Plasma::QueryMatch::ExactMatch);
        } else {
            match.setRelevance(0.8);
        }

        matches.append(match);
    }
    context.addMatches(context.query(),matches);
}

void HomeFilesRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
{
    Q_UNUSED(context)
    KRun *opener = new KRun(match.data().toString(), 0);
    opener->setRunExecutables(false);
}

void HomeFilesRunner::reloadConfiguration()
{
    KConfigGroup c = config();
    m_triggerWord = c.readEntry("trigger", QString());
    if (!m_triggerWord.isEmpty()) {
        m_triggerWord.append(' ');
    }

    m_path = c.readPathEntry("path", QDir::homePath());
    QFileInfo pathInfo(m_path);
    if (!pathInfo.isDir()) {
        m_path = QDir::homePath();
    }

    QList<Plasma::RunnerSyntax> syntaxes;
    Plasma::RunnerSyntax syntax(QString("%1:q:").arg(m_triggerWord),
        i18n("Finds files matching :q: in the %1 folder"));
    syntaxes.append(syntax);
    setSyntaxes(syntaxes);
}

void HomeFilesRunner::createRunOptions(QWidget *widget)
{
    QVBoxLayout *layout = new QVBoxLayout(widget);
    QCheckBox *cb = new QCheckBox(widget);
    cb->setText(i18n("This is just for show"));
    layout->addWidget(cb);
}

void HomeFilesRunner::prepareForMatchSession()
{

}

K_EXPORT_PLASMA_RUNNER(example-homefiles, HomeFilesRunner)

#include "homefilesrunner.moc"


CMakeLists.txt:
Code: Select all
project(runnerexample)

set(KDE_MIN_VERSION "4.3.60")
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include (MacroLibrary)

add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINTITIONS})
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})

set(example_SRCS homefilesrunner.cpp)

kde4_add_plugin(plasma_runner_example_homefiles ${example_SRCS})
target_link_libraries(plasma_runner_example_homefiles ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS})

install(TARGETS plasma_runner_example_homefiles DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES plasma_runner_example_homefiles.desktop DESTINATION ${SERVICES_INSTALL_DIR})

User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Please try changing the following line:
Code: Select all
K_EXPORT_PLASMA_RUNNER(example-homefiles, HomeFilesRunner)

to:
Code: Select all
K_EXPORT_PLASMA_RUNNER(example_homefiles, HomeFilesRunner)


Without the *.desktop file I was unable to test.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
lima2
Registered Member
Posts
3
Karma
0
OS
Hi. I tried your change, but it did not help...

here is the .desktop file for reference.

plasma-runner-example-homefiles.desktop:

[Desktop Entry]
Name=Home Files
Comment=Part of a tutorial
Type=Service
X-KDE-ServiceTypes=Plasma/Runner

X-KDE-Library=plasma_runner_example_homefiles
X-KDE-PluginInfo-Author=fooAuthor
X-KDE-PluginInfo-Email=foo@bar.com
X-KDE-PluginInfo-Name=example-homefiles
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://foobar
X-KDE-PluginInfo-Category=Examples
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true

User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: How to enable own krunner plugin

Thu Feb 10, 2011 10:35 am
I suggest contacting the Plasma developers on their mailing list: plasma-devel@kde.org

Unfortunately I wasn't able to get it to function either...


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
JanGerrit
Moderator
Posts
647
Karma
3
OS
I did some experiments and it seems to be displayed when removing the line:
Code: Select all
X-KDE-PluginInfo-Category=Examples

in the desktop file.


Image


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft