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.
29 #include <QPixmapCache>
31 #include <KApplication>
34 #include <KCmdLineArgs>
36 #include <KStandardAction>
39 #include <Plasma/Applet>
42 using namespace Plasma
;
44 static const char description
[] = I18N_NOOP("Run Plasma widgets in their own window");
46 int main(int argc
, char **argv
)
48 KAboutData
aboutData("plasmoidviewer", 0, ki18n("Plasma Widget Viewer"),
49 "1.0", ki18n(description
), KAboutData::License_BSD
,
50 ki18n("2007-2008, Frerich Raabe"));
51 aboutData
.setProgramIconName("plasma");
52 aboutData
.addAuthor(ki18n("Frerich Raabe"),
53 ki18n("Original author"),
56 KCmdLineArgs::init(argc
, argv
, &aboutData
);
58 KCmdLineOptions options
;
59 options
.add("list", ki18n("Displays a list of known applets"));
61 options
.add("formfactor <name>", ki18nc("Do not translate horizontal, vertical, mediacenter nor planar", "The formfactor to use (horizontal, vertical, mediacenter or planar)"), "planar");
63 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");
65 options
.add("containment <name>", ki18n("Name of the containment plugin"), "null");
67 options
.add("wallpaper <name>", ki18n("Name of the wallpaper plugin"), QByteArray());
69 options
.add("pixmapcache <size>", ki18n("The size in KB to set the pixmap cache to"));
70 options
.add("+applet", ki18n("Name of applet to add (required)"));
71 options
.add("+[args]", ki18n("Optional arguments of the applet to add"));
72 KCmdLineArgs::addCmdLineOptions(options
);
76 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs() ;
78 if (args
->isSet("list")) {
80 QMap
<QString
, QString
> applets
;
81 foreach (const KPluginInfo
&info
, Plasma::Applet::listAppletInfo()) {
82 if (info
.property("NoDisplay").toBool())
85 int len
= info
.pluginName().length();
89 QString name
= info
.pluginName();
90 QString comment
= info
.comment();
93 comment
= i18n("No description available");
95 applets
.insert(name
, comment
);
98 QMap
<QString
, QString
>::const_iterator it
;
99 for(it
= applets
.constBegin(); it
!= applets
.constEnd(); it
++) {
100 QString
applet("%1 - %2");
102 applet
= applet
.arg(it
.key().leftJustified(maxLen
, ' ')).arg(it
.value());
103 std::cout
<< applet
.toLocal8Bit().data() << std::endl
;
109 if (args
->count() == 0) {
110 KCmdLineArgs::usageError(i18n("No applet name specified"));
113 //At this point arg(0) is always set
114 QString pluginName
= args
->arg(0);
116 QString formfactor
= args
->getOption("formfactor");
117 kDebug() << "setting FormFactor to" << args
->getOption("formfactor");
119 QString location
= args
->getOption("location");
120 kDebug() << "setting Location to" << args
->getOption("location");
122 QString containment
= args
->getOption("containment");
123 kDebug() << "setting containment to" << containment
;
126 if (args
->isSet("wallpaper")) {
127 wallpaper
= args
->getOption("wallpaper");
128 kDebug() << "setting wallpaper to" << wallpaper
;
131 QVariantList appletArgs
;
132 for (int i
= 1; i
< args
->count(); ++i
) {
133 appletArgs
<< args
->arg(i
);
136 FullView
view(formfactor
, location
);
137 view
.addApplet(pluginName
, containment
, wallpaper
, appletArgs
);
140 QAction
*action
= KStandardAction::quit(&app
, SLOT(quit()), &view
);
141 view
.addAction(action
);
143 if (args
->isSet("pixmapcache")) {
144 kDebug() << "setting pixmap cache to" << args
->getOption("pixmapcache").toInt();
145 QPixmapCache::setCacheLimit(args
->getOption("pixmapcache").toInt());