From bc5304306491a5267ec9d5e9484d1df076882292 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Fri, 29 Apr 2011 16:52:53 +0200 Subject: [PATCH] Implement a CLI tool allowing to add remote plasmoids Use the D-Bus call on the Plasma Desktop shell to create a cli helper tool allowing you to add a remote widgets based on its URL. So something like "plasma-remote-helper plasma://host:port/name" will add the plasmoid "name" exported from "host" to your current activity. --- tools/CMakeLists.txt | 1 + tools/plasma-remote-helper/CMakeLists.txt | 10 +++ tools/plasma-remote-helper/Messages.sh | 2 + tools/plasma-remote-helper/main.cpp | 81 +++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 tools/plasma-remote-helper/CMakeLists.txt create mode 100755 tools/plasma-remote-helper/Messages.sh create mode 100644 tools/plasma-remote-helper/main.cpp diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 575dea7b8..555096d88 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(plasmapkg) +add_subdirectory(plasma-remote-helper) diff --git a/tools/plasma-remote-helper/CMakeLists.txt b/tools/plasma-remote-helper/CMakeLists.txt new file mode 100644 index 000000000..c2eddb20a --- /dev/null +++ b/tools/plasma-remote-helper/CMakeLists.txt @@ -0,0 +1,10 @@ +set(plasma_remote_helper_SRCS + main.cpp +) + +kde4_add_executable(plasma-remote-helper ${plasma_remote_helper_SRCS}) + +target_link_libraries(plasma-remote-helper ${KDE4_KDEUI_LIBS}) + +install(TARGETS plasma-remote-helper ${INSTALL_TARGETS_DEFAULT_ARGS}) + diff --git a/tools/plasma-remote-helper/Messages.sh b/tools/plasma-remote-helper/Messages.sh new file mode 100755 index 000000000..7b98af468 --- /dev/null +++ b/tools/plasma-remote-helper/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT *.cpp -o $podir/plasma-remote-helper.pot diff --git a/tools/plasma-remote-helper/main.cpp b/tools/plasma-remote-helper/main.cpp new file mode 100644 index 000000000..a1d3d0cc0 --- /dev/null +++ b/tools/plasma-remote-helper/main.cpp @@ -0,0 +1,81 @@ +/* Copyright 2011 Kevin Ottens + + 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, + 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 Library General Public + License along with this program; if not, write to the + Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include + +#include +#include + +#include +#include +#include + +static const char description[] = I18N_NOOP("Trigger the installation of a remove Plasma Widget"); +static const char version[] = "0.1"; + +int addRemotePlasmoidToShell(const QString &shellName, const QString &url) +{ + QString serviceName = "org.kde." + shellName; + QDBusInterface iface(serviceName, "/App"); + + if (!iface.isValid()) { + std::cerr << "Error: Couldn't contact " + << shellName.toLocal8Bit().constData() << std::endl; + return 1; + } else { + QDBusReply reply = iface.call("addRemotePlasmoid", url); + if (!reply.isValid()) { + std::cerr << "Error: Couldn't call addRemotePlasmoid on " + << shellName.toLocal8Bit().constData() << std::endl; + return 1; + } + } + + return 0; +} + +int main(int argc, char **argv) +{ + KAboutData aboutData("plasma-remote-helper", 0, ki18n("Plasma Remote Widget Helper"), + version, ki18n(description), KAboutData::License_GPL, + ki18n("(C) 2011 Kevin Ottens")); + aboutData.addAuthor( ki18n("Kevin Ottens"), + ki18n("Original author"), + "ervin@kde.org" ); + + KComponentData componentData(aboutData); + + KCmdLineArgs::init( argc, argv, &aboutData ); + + KCmdLineOptions options; + options.add("+", ki18n("URL to the Plasma Remote Widget.")); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if (args->count()<1) { + KCmdLineArgs::usageError(i18n("Syntax Error: Not enough arguments")); + } else if (args->count()>1) { + KCmdLineArgs::usageError(i18n("Syntax Error: Too many arguments")); + } + + QString url = args->arg(0); + return addRemotePlasmoidToShell("plasma-desktop", url); +} +