2
* Copyright 2007 Frerich Raabe <raabe@kde.org>
3
* Copyright 2007-2008 Aaron Seigo <aseigo@kde.org>
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
#include <QPixmapCache>
33
#include <KApplication>
36
#include <KCmdLineArgs>
38
#include <KStandardAction>
41
#include <Plasma/Applet>
42
#include <Plasma/Theme>
43
#include <Plasma/AccessManager>
44
#include <Plasma/AuthorizationManager>
45
#include <Plasma/Wallpaper>
47
using namespace Plasma;
49
static const char description[] = I18N_NOOP("Run Plasma widgets in their own window");
51
class RemotePlasmoidWatcher : public QObject
56
RemotePlasmoidWatcher(AccessManager *manager)
60
connect(manager, SIGNAL(remoteAppletAnnounced(Plasma::PackageMetadata)),
61
this, SLOT(slotServiceAdded(Plasma::PackageMetadata)));
62
connect(manager, SIGNAL(remoteAppletUnannounced(Plasma::PackageMetadata)),
63
this, SLOT(slotServiceRemoved(Plasma::PackageMetadata)));
66
~RemotePlasmoidWatcher() {}
69
void slotServiceAdded(Plasma::PackageMetadata metadata) {
70
std::cout << "New service published:" << std::endl;
71
std::cout << metadata.remoteLocation().prettyUrl().toLocal8Bit().data() << std::endl;
72
std::cout << metadata.name().toLocal8Bit().data() << " - "
73
<< metadata.description().toLocal8Bit().data() << std::endl;
76
void slotServiceRemoved(Plasma::PackageMetadata metadata) {
77
std::cout << "Service removed:" << std::endl;
78
std::cout << metadata.remoteLocation().prettyUrl().toLocal8Bit().data() << std::endl;
82
void listPlugins(const KPluginInfo::List & plugins)
85
QMap<QString, QString> applets;
86
foreach (const KPluginInfo &info, plugins) {
87
if (info.property("NoDisplay").toBool()) {
91
int len = info.pluginName().length();
96
QString name = info.pluginName();
97
QString comment = info.comment();
99
if (comment.isEmpty()) {
100
comment = i18n("No description available");
103
applets.insert(name, comment);
106
QMap<QString, QString>::const_iterator it;
107
for (it = applets.constBegin(); it != applets.constEnd(); it++) {
108
QString applet("%1 - %2");
110
applet = applet.arg(it.key().leftJustified(maxLen, ' ')).arg(it.value());
111
std::cout << applet.toLocal8Bit().data() << std::endl;
115
int main(int argc, char **argv)
117
KAboutData aboutData("plasmoidviewer", 0, ki18n("Plasma Widget Viewer"),
118
"1.0", ki18n(description), KAboutData::License_BSD,
119
ki18n("2007-2008, Frerich Raabe"));
120
aboutData.setProgramIconName("plasma");
121
aboutData.addAuthor(ki18n("Frerich Raabe"),
122
ki18n("Original author"),
125
KCmdLineArgs::init(argc, argv, &aboutData);
127
KCmdLineOptions options;
129
options.add("containment <name>", ki18n("Name of the containment plugin"), "null");
131
options.add("formfactor <name>", ki18nc("Do not translate horizontal, vertical, mediacenter nor planar", "The formfactor to use (horizontal, vertical, mediacenter or planar)"), "planar");
132
options.add("list", ki18n("Displays a list of known applets"));
133
options.add("list-wallpapers", ki18n("Displays a list of known wallpapers"));
134
options.add("list-containments", ki18n("Displays a list of known containments"));
136
options.add("location <name>", ki18nc("Do not translate floating, desktop, fullscreen, top, bottom, left nor right", "The location constraint to start the Containment with (floating, desktop, fullscreen, top, bottom, left, right)"), "floating");
138
options.add("pixmapcache <size>", ki18n("The size in KB to set the pixmap cache to"));
140
options.add("screenshot", ki18n("Takes a screenshot of the widget and saves it the working directory as <pluginname>.png"));
141
options.add("screenshot-all", ki18n("Takes a screenshot of each widget and saves it the working directory as <pluginname>.png"));
143
options.add("theme <name>", ki18n("Desktop SVG theme to use"));
145
options.add("wallpaper <name>", ki18n("Name of the wallpaper plugin. Requires a containment plugin to be specified."), QByteArray());
146
options.add("+applet", ki18n("Name of applet to view; may refer to the plugin name or be a path "
147
"(absolute or relative) to a package. If not provided, then an "
148
"attempt is made to load a package from the current directory."));
149
options.add("+[args]", ki18n("Optional arguments of the applet to add"));
150
options.add("list-remote", ki18n("List zeroconf announced remote widgets"));
151
KCmdLineArgs::addCmdLineOptions(options);
155
KCmdLineArgs *args = KCmdLineArgs::parsedArgs() ;
157
if (args->isSet("list")) {
158
listPlugins(Plasma::Applet::listAppletInfo());
162
if (args->isSet("list-wallpapers")) {
163
listPlugins(Plasma::Wallpaper::listWallpaperInfo());
167
if (args->isSet("list-containments")) {
168
listPlugins(Plasma::Containment::listContainments());
173
if (args->count() > 0) {
174
pluginName = args->arg(0);
177
QString formfactor = args->getOption("formfactor");
178
kDebug() << "setting FormFactor to" << args->getOption("formfactor");
180
QString location = args->getOption("location");
181
kDebug() << "setting Location to" << args->getOption("location");
183
QString containment = args->getOption("containment");
184
kDebug() << "setting containment to" << containment;
186
if (args->isSet("theme")) {
187
QString theme = args->getOption("theme");
188
Plasma::Theme::defaultTheme()->setUseGlobalSettings(false);
189
Plasma::Theme::defaultTheme()->setThemeName(theme);
190
kDebug() << "setting theme to" << theme;
194
if (args->isSet("wallpaper")) {
195
wallpaper = args->getOption("wallpaper");
196
kDebug() << "setting wallpaper to" << wallpaper;
199
if (args->isSet("pixmapcache")) {
200
kDebug() << "setting pixmap cache to" << args->getOption("pixmapcache").toInt();
201
QPixmapCache::setCacheLimit(args->getOption("pixmapcache").toInt());
204
QVariantList appletArgs;
205
for (int i = 1; i < args->count(); ++i) {
206
appletArgs << args->arg(i);
208
kDebug() << "setting auth policy";
209
Plasma::AuthorizationManager::self()->setAuthorizationPolicy(Plasma::AuthorizationManager::PinPairing);
211
FullView view(formfactor, location);
213
if (args->isSet("list-remote")) {
214
kDebug() << "list remote...";
216
QList<KUrl> list = AccessManager::self()->remotePlasmoids();
217
foreach (const KUrl &url, list) {
218
std::cout << url.prettyUrl().toLocal8Bit().data() << std::endl;
221
new RemotePlasmoidWatcher(AccessManager::self());
222
} else if (args->isSet("screenshot-all")) {
224
view.screenshotAll();
226
kDebug() << "just load applet";
227
view.addApplet(pluginName, containment, wallpaper, appletArgs);
232
QAction *action = KStandardAction::quit(&app, SLOT(quit()), &view);
233
view.addAction(action);