Migrated clipboard plugin to new format

This commit is contained in:
Albert Vaca 2013-08-13 15:48:02 +02:00
parent 049c708743
commit 8481a91057
6 changed files with 62 additions and 20 deletions

View file

@ -4,4 +4,4 @@ install(FILES kdeconnect_plugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR})
add_subdirectory(ping) add_subdirectory(ping)
add_subdirectory(pausemusic) add_subdirectory(pausemusic)
add_subdirectory(mpriscontrol) add_subdirectory(mpriscontrol)
add_subdirectory(clipboard)

View file

@ -0,0 +1,23 @@
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories(${KDE4_INCLUDES})
set(kdeconnect_clipboard_SRCS
clipboardplugin.cpp
../kdeconnectplugin.cpp
../pluginloader.cpp
../../networkpackage.cpp
../../device.cpp
)
kde4_add_plugin(kdeconnect_clipboard ${kdeconnect_clipboard_SRCS})
target_link_libraries(kdeconnect_clipboard
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
${QT_QTNETWORK_LIBRARY}
qjson
)
install(TARGETS kdeconnect_clipboard DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_clipboard.desktop DESTINATION ${SERVICES_INSTALL_DIR} )

View file

@ -18,20 +18,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "clipboardpackageinterface.h" #include "clipboardplugin.h"
#include <QClipboard> #include <QClipboard>
#include <KDebug> #include <KDebug>
#include <QApplication> #include <QApplication>
ClipboardPackageInterface::ClipboardPackageInterface() K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< ClipboardPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_clipboard", "kdeconnect_clipboard") )
ClipboardPlugin::ClipboardPlugin(QObject *parent, const QVariantList &args)
: KdeConnectPlugin(parent, args)
{ {
clipboard = QApplication::clipboard(); clipboard = QApplication::clipboard();
ignore_next_clipboard_change = false; ignore_next_clipboard_change = false;
connect(clipboard,SIGNAL(changed(QClipboard::Mode)),this,SLOT(clipboardChanged(QClipboard::Mode))); connect(clipboard,SIGNAL(changed(QClipboard::Mode)),this,SLOT(clipboardChanged(QClipboard::Mode)));
} }
void ClipboardPackageInterface::clipboardChanged(QClipboard::Mode mode) void ClipboardPlugin::clipboardChanged(QClipboard::Mode mode)
{ {
if (mode != QClipboard::QClipboard::Clipboard) return; if (mode != QClipboard::QClipboard::Clipboard) return;
@ -42,12 +46,12 @@ void ClipboardPackageInterface::clipboardChanged(QClipboard::Mode mode)
//qDebug() << "ClipboardChanged"; //qDebug() << "ClipboardChanged";
NetworkPackage np(PACKAGE_TYPE_CLIPBOARD); NetworkPackage np(PACKAGE_TYPE_CLIPBOARD);
np.set("content",clipboard->text()); np.set("content",clipboard->text());
emit sendPackage(np); device()->sendPackage(np);
} }
bool ClipboardPackageInterface::receivePackage(const Device& device, const NetworkPackage& np) bool ClipboardPlugin::receivePackage(const NetworkPackage& np)
{ {
Q_UNUSED(device); qDebug() << "AAAAAAAAAAAAAAAAAA";
if (np.type() == PACKAGE_TYPE_CLIPBOARD) { if (np.type() == PACKAGE_TYPE_CLIPBOARD) {
ignore_next_clipboard_change = true; ignore_next_clipboard_change = true;
clipboard->setText(np.get<QString>("content")); clipboard->setText(np.get<QString>("content"));

View file

@ -18,27 +18,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CLIPBOARDPACKAGEINTERFACE_H #ifndef CLIPBOARDPLUGIN_H
#define CLIPBOARDPACKAGEINTERFACE_H #define CLIPBOARDPLUGIN_H
#include <QObject> #include <QObject>
#include <QClipboard> #include <QClipboard>
#include "networkpackage.h" #include "../kdeconnectplugin.h"
#include "device.h" #include "../../networkpackage.h"
#include "packageinterface.h" #include "../../device.h"
class ClipboardPackageInterface class ClipboardPlugin
: public PackageInterface : public KdeConnectPlugin
{ {
Q_OBJECT Q_OBJECT
public: public:
ClipboardPackageInterface(); explicit ClipboardPlugin(QObject *parent, const QVariantList &args);
virtual ~ClipboardPackageInterface() { }
public Q_SLOTS: public Q_SLOTS:
virtual bool receivePackage(const Device& device, const NetworkPackage& np); virtual bool receivePackage(const NetworkPackage& np);
private Q_SLOTS: private Q_SLOTS:
void clipboardChanged(QClipboard::Mode mode); void clipboardChanged(QClipboard::Mode mode);

View file

@ -0,0 +1,15 @@
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=KdeConnect/Plugin
X-KDE-Library=kdeconnect_clipboard
X-KDE-PluginInfo-Author=Albert Vaca
X-KDE-PluginInfo-Email=albertvaka@gmail.com
X-KDE-PluginInfo-Name=kdeconnect_clipboard
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://albertvaka.wordpress.com
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=edit-paste
Name=Clipboard
Comment=Share the clipboard between devices

View file

@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef MPRISCONTROLPACKAGEINTERFACE_H #ifndef MPRISCONTROLPLUGIN_H
#define MPRISCONTROLPACKAGEINTERFACE_H #define MPRISCONTROLPLUGIN_H
#include <QSet> #include <QSet>
#include <QString> #include <QString>
@ -45,10 +45,11 @@ private Q_SLOTS:
void propertiesChanged(const QString& interface, const QVariantMap& properties); void propertiesChanged(const QString& interface, const QVariantMap& properties);
private: private:
QHash<QString, QString> playerList;
void addPlayer(const QString& ifaceName); void addPlayer(const QString& ifaceName);
void removePlayer(const QString& ifaceName); void removePlayer(const QString& ifaceName);
void sendPlayerList(); void sendPlayerList();
QHash<QString, QString> playerList;
int prevVolume; int prevVolume;
}; };