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.
This commit is contained in:
parent
97bfbf07a5
commit
bc53043064
@ -1 +1,2 @@
|
|||||||
add_subdirectory(plasmapkg)
|
add_subdirectory(plasmapkg)
|
||||||
|
add_subdirectory(plasma-remote-helper)
|
||||||
|
10
tools/plasma-remote-helper/CMakeLists.txt
Normal file
10
tools/plasma-remote-helper/CMakeLists.txt
Normal file
@ -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})
|
||||||
|
|
2
tools/plasma-remote-helper/Messages.sh
Executable file
2
tools/plasma-remote-helper/Messages.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
$XGETTEXT *.cpp -o $podir/plasma-remote-helper.pot
|
81
tools/plasma-remote-helper/main.cpp
Normal file
81
tools/plasma-remote-helper/main.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/* Copyright 2011 Kevin Ottens <ervin@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,
|
||||||
|
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 <iostream>
|
||||||
|
|
||||||
|
#include <QtDBus/QDBusInterface>
|
||||||
|
#include <QtDBus/QDBusReply>
|
||||||
|
|
||||||
|
#include <KDE/KApplication>
|
||||||
|
#include <KDE/KAboutData>
|
||||||
|
#include <KDE/KCmdLineArgs>
|
||||||
|
|
||||||
|
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<void> 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("+<url>", 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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user