diff --git a/klipper/CMakeLists.txt b/klipper/CMakeLists.txt
index daf4890a0..660b0d174 100644
--- a/klipper/CMakeLists.txt
+++ b/klipper/CMakeLists.txt
@@ -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)
diff --git a/klipper/clipboardengine.cpp b/klipper/clipboardengine.cpp
index ec27dff27..3d98b8d18 100644
--- a/klipper/clipboardengine.cpp
+++ b/klipper/clipboardengine.cpp
@@ -17,22 +17,38 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*********************************************************************/
#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"
diff --git a/klipper/clipboardengine.h b/klipper/clipboardengine.h
index 3c7aa933b..76e5b6693 100644
--- a/klipper/clipboardengine.h
+++ b/klipper/clipboardengine.h
@@ -21,12 +21,19 @@ along with this program. If not, see .
#include
+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
diff --git a/klipper/clipboardjob.cpp b/klipper/clipboardjob.cpp
new file mode 100644
index 000000000..1aa728939
--- /dev/null
+++ b/klipper/clipboardjob.cpp
@@ -0,0 +1,72 @@
+/********************************************************************
+This file is part of the KDE project.
+
+Copyright (C) 2014 Martin Gräßlin
+
+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 .
+*********************************************************************/
+#include "clipboardjob.h"
+#include "klipper.h"
+#include "history.h"
+#include "historyitem.h"
+
+ClipboardJob::ClipboardJob(Klipper *klipper, const QString &destination, const QString &operation, const QVariantMap ¶meters, 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);
+ }
+}
diff --git a/klipper/clipboardjob.h b/klipper/clipboardjob.h
new file mode 100644
index 000000000..b4f5284cf
--- /dev/null
+++ b/klipper/clipboardjob.h
@@ -0,0 +1,39 @@
+/********************************************************************
+This file is part of the KDE project.
+
+Copyright (C) 2014 Martin Gräßlin
+
+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 .
+*********************************************************************/
+#ifndef KLIPPER_CLIPBOARDJOB_H
+#define KLIPPER_CLIPBOARDJOB_H
+
+#include
+
+class Klipper;
+
+class ClipboardJob : public Plasma::ServiceJob
+{
+ Q_OBJECT
+public:
+ ClipboardJob(Klipper *klipper, const QString &destination, const QString &operation, const QVariantMap ¶meters, QObject *parent=0);
+ ~ClipboardJob() = default;
+
+ void start() override;
+
+private:
+ Klipper *m_klipper;
+};
+
+#endif
diff --git a/klipper/clipboardservice.cpp b/klipper/clipboardservice.cpp
new file mode 100644
index 000000000..5cc94864c
--- /dev/null
+++ b/klipper/clipboardservice.cpp
@@ -0,0 +1,33 @@
+/********************************************************************
+This file is part of the KDE project.
+
+Copyright (C) 2014 Martin Gräßlin
+
+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 .
+*********************************************************************/
+#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 ¶meters)
+{
+ return new ClipboardJob(m_klipper, m_uuid, operation, parameters, this);
+}
diff --git a/klipper/clipboardservice.h b/klipper/clipboardservice.h
new file mode 100644
index 000000000..91888e730
--- /dev/null
+++ b/klipper/clipboardservice.h
@@ -0,0 +1,41 @@
+/********************************************************************
+This file is part of the KDE project.
+
+Copyright (C) 2014 Martin Gräßlin
+
+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 .
+*********************************************************************/
+#ifndef KLIPPER_CLIPBOARDSERVICE_H
+#define KLIPPER_CLIPBOARDSERVICE_H
+
+#include
+
+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 ¶meters) override;
+
+private:
+ Klipper *m_klipper;
+ QString m_uuid;
+};
+
+#endif
diff --git a/klipper/org.kde.plasma.clipboard.operations b/klipper/org.kde.plasma.clipboard.operations
new file mode 100644
index 000000000..813aafa96
--- /dev/null
+++ b/klipper/org.kde.plasma.clipboard.operations
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+