[klipper] Add ClipboardService and ClipboardJob

The ClipboardEngine provides a service which in turn starts a
ClipboardJob. The following operations are globally supported:
* configureKlipper
* clearHistory

And the following operations are supported on uuid (base64):
* select
* remove
* edit
* barcode
* action

barcode is only supported if klipper gets compiled with prison support,
this is announced as data element "supportsBarcodes" in the "clipboard"
source of the DataEngine.
wilder-5.14
Martin Gräßlin 12 years ago
parent 4555ed3ffb
commit 1b7c7dd2fe
  1. 3
      klipper/CMakeLists.txt
  2. 20
      klipper/clipboardengine.cpp
  3. 7
      klipper/clipboardengine.h
  4. 72
      klipper/clipboardjob.cpp
  5. 39
      klipper/clipboardjob.h
  6. 33
      klipper/clipboardservice.cpp
  7. 41
      klipper/clipboardservice.h
  8. 19
      klipper/org.kde.plasma.clipboard.operations

@ -69,7 +69,7 @@ install(PROGRAMS org.kde.klipper.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
install(PROGRAMS org.kde.klipper.desktop DESTINATION ${AUTOSTART_INSTALL_DIR})
# Plasma Data Engine
set(plasma_engine_clipboard_SRCS ${libklipper_common_SRCS} clipboardengine.cpp)
set(plasma_engine_clipboard_SRCS ${libklipper_common_SRCS} clipboardengine.cpp clipboardservice.cpp clipboardjob.cpp)
add_library(plasma_engine_clipboard MODULE ${plasma_engine_clipboard_SRCS})
kservice_desktop_to_json(plasma_engine_clipboard plasma-dataengine-clipboard.desktop)
target_link_libraries(plasma_engine_clipboard
@ -96,5 +96,6 @@ if (PRISON_FOUND)
endif ()
install(TARGETS plasma_engine_clipboard DESTINATION ${PLUGIN_INSTALL_DIR}/plasma/dataengine)
install(FILES plasma-dataengine-clipboard.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install(FILES org.kde.plasma.clipboard.operations DESTINATION ${PLASMA_DATA_INSTALL_DIR}/services)
add_subdirectory(autotests)

@ -17,22 +17,38 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "clipboardengine.h"
#include "clipboardservice.h"
#include "history.h"
#include "historymodel.h"
#include "klipper.h"
static const QString s_clipboardSourceName = QStringLiteral("clipboard");
static const QString s_barcodeKey = QStringLiteral("supportsBarcodes");
ClipboardEngine::ClipboardEngine(QObject *parent, const QVariantList &args)
: Plasma::DataEngine(parent, args)
, m_klipper(new Klipper(this, KSharedConfig::openConfig("klipperrc")))
{
Klipper *klipper = new Klipper(this, KSharedConfig::openConfig("klipperrc"));
// TODO: use a filterproxymodel
setModel(QStringLiteral("clipboard"), klipper->history()->model());
setModel(s_clipboardSourceName, m_klipper->history()->model());
#ifdef HAVE_PRISON
setData(s_clipboardSourceName, s_barcodeKey, true);
#else
setData(s_clipboardSourceName, s_barcodeKey, false);
#endif
}
ClipboardEngine::~ClipboardEngine()
{
}
Plasma::Service *ClipboardEngine::serviceForSource(const QString &source)
{
Plasma::Service *service = new ClipboardService(m_klipper, source);
service->setParent(this);
return service;
}
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(org.kde.plasma.clipboard, ClipboardEngine, "plasma-dataengine-clipboard.json")
#include "clipboardengine.moc"

@ -21,12 +21,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <Plasma/DataEngine>
class Klipper;
class ClipboardEngine : public Plasma::DataEngine
{
Q_OBJECT
public:
ClipboardEngine(QObject *parent, const QVariantList &args);
~ClipboardEngine();
Plasma::Service *serviceForSource (const QString &source) override;
private:
Klipper *m_klipper;
};
#endif

@ -0,0 +1,72 @@
/********************************************************************
This file is part of the KDE project.
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, 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 General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "clipboardjob.h"
#include "klipper.h"
#include "history.h"
#include "historyitem.h"
ClipboardJob::ClipboardJob(Klipper *klipper, const QString &destination, const QString &operation, const QVariantMap &parameters, QObject *parent)
: Plasma::ServiceJob(destination, operation, parameters, parent)
, m_klipper(klipper)
{
}
void ClipboardJob::start()
{
const QString operation = operationName();
// first check for operations not needing an item
if (operation == QLatin1String("clearHistory")) {
m_klipper->slotAskClearHistory();
setResult(true);
return;
} else if (operation == QLatin1String("configureKlipper")) {
m_klipper->slotConfigure();
setResult(true);
return;
}
// other operations need the item
HistoryItemConstPtr item = m_klipper->history()->find(QByteArray::fromBase64(destination().toUtf8()));
if (item.isNull()) {
setResult(false);
return;
}
if (operation == QLatin1String("select")) {
m_klipper->history()->slotMoveToTop(item->uuid());
setResult(true);
} else if (operation == QLatin1String("remove")) {
m_klipper->history()->remove(item);
setResult(true);
} else if (operation == QLatin1String("edit")) {
m_klipper->editData(item);
setResult(true);
} else if (operation == QLatin1String("barcode")) {
#ifdef HAVE_PRISON
m_klipper->showBarcode(item);
setResult(true);
#else
setResult(false);
#endif
} else if (operation == QLatin1String("action")) {
m_klipper->urlGrabber()->invokeAction(item);
setResult(true);
} else {
setResult(false);
}
}

@ -0,0 +1,39 @@
/********************************************************************
This file is part of the KDE project.
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, 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 General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KLIPPER_CLIPBOARDJOB_H
#define KLIPPER_CLIPBOARDJOB_H
#include <Plasma/ServiceJob>
class Klipper;
class ClipboardJob : public Plasma::ServiceJob
{
Q_OBJECT
public:
ClipboardJob(Klipper *klipper, const QString &destination, const QString &operation, const QVariantMap &parameters, QObject *parent=0);
~ClipboardJob() = default;
void start() override;
private:
Klipper *m_klipper;
};
#endif

@ -0,0 +1,33 @@
/********************************************************************
This file is part of the KDE project.
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, 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 General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "clipboardservice.h"
#include "clipboardjob.h"
ClipboardService::ClipboardService(Klipper *klipper, const QString &uuid)
: Plasma::Service()
, m_klipper(klipper)
, m_uuid(uuid)
{
setName(QStringLiteral("org.kde.plasma.clipboard"));
}
Plasma::ServiceJob *ClipboardService::createJob(const QString &operation, QVariantMap &parameters)
{
return new ClipboardJob(m_klipper, m_uuid, operation, parameters, this);
}

@ -0,0 +1,41 @@
/********************************************************************
This file is part of the KDE project.
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, 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 General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KLIPPER_CLIPBOARDSERVICE_H
#define KLIPPER_CLIPBOARDSERVICE_H
#include <Plasma/Service>
class Klipper;
class ClipboardService : public Plasma::Service
{
Q_OBJECT
public:
ClipboardService(Klipper *klipper, const QString &uuid);
~ClipboardService() = default;
protected:
Plasma::ServiceJob *createJob(const QString &operation, QVariantMap &parameters) override;
private:
Klipper *m_klipper;
QString m_uuid;
};
#endif

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kcfg SYSTEM
"http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfg>
<group name="select">
</group>
<group name="remove">
</group>
<group name="edit">
</group>
<group name="barcode">
</group>
<group name="action">
</group>
<group name="configureKlipper">
</group>
<group name="clearHistory">
</group>
</kcfg>
Loading…
Cancel
Save