00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "fullview.h"
00028
00029 #include <QPixmapCache>
00030
00031 #include <KApplication>
00032 #include <KAboutData>
00033 #include <KAction>
00034 #include <KCmdLineArgs>
00035 #include <KLocale>
00036 #include <KStandardAction>
00037
00038
00039 #include <Plasma/Applet>
00040 #include <iostream>
00041
00042 using namespace Plasma;
00043
00044 static const char description[] = I18N_NOOP("Run Plasma widgets in their own window");
00045
00046 int main(int argc, char **argv)
00047 {
00048 KAboutData aboutData("plasmoidviewer", 0, ki18n("Plasma Widget Viewer"),
00049 "1.0", ki18n(description), KAboutData::License_BSD,
00050 ki18n("2007-2008, Frerich Raabe"));
00051 aboutData.setProgramIconName("plasma");
00052 aboutData.addAuthor(ki18n("Frerich Raabe"),
00053 ki18n("Original author"),
00054 "raabe@kde.org");
00055
00056 KCmdLineArgs::init(argc, argv, &aboutData);
00057
00058 KCmdLineOptions options;
00059 options.add("list", ki18n("Displays a list of known applets"));
00060 options.add("f");
00061 options.add("formfactor <name>", ki18nc("Do not translate horizontal, vertical, mediacenter nor planar", "The formfactor to use (horizontal, vertical, mediacenter or planar)"), "planar");
00062 options.add("l");
00063 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");
00064 options.add("c");
00065 options.add("containment <name>", ki18n("Name of the containment plugin"), "null");
00066 options.add("w");
00067 options.add("wallpaper <name>", ki18n("Name of the wallpaper plugin"), QByteArray());
00068 options.add("p");
00069 options.add("pixmapcache <size>", ki18n("The size in KB to set the pixmap cache to"));
00070 options.add("+applet", ki18n("Name of applet to add (required)"));
00071 options.add("+[args]", ki18n("Optional arguments of the applet to add"));
00072 KCmdLineArgs::addCmdLineOptions(options);
00073
00074 KApplication app;
00075
00076 KCmdLineArgs *args = KCmdLineArgs::parsedArgs() ;
00077
00078 if (args->isSet("list")) {
00079 int maxLen = 0;
00080 QMap<QString, QString> applets;
00081 foreach (const KPluginInfo &info, Plasma::Applet::listAppletInfo()) {
00082 if (info.property("NoDisplay").toBool())
00083 continue;
00084
00085 int len = info.pluginName().length();
00086 if (len > maxLen)
00087 maxLen = len;
00088
00089 QString name = info.pluginName();
00090 QString comment = info.comment();
00091
00092 if(comment.isEmpty())
00093 comment = i18n("No description available");
00094
00095 applets.insert(name, comment);
00096 }
00097
00098 QMap<QString, QString>::const_iterator it;
00099 for(it = applets.constBegin(); it != applets.constEnd(); it++) {
00100 QString applet("%1 - %2");
00101
00102 applet = applet.arg(it.key().leftJustified(maxLen, ' ')).arg(it.value());
00103 std::cout << applet.toLocal8Bit().data() << std::endl;
00104 }
00105
00106 return 0;
00107 }
00108
00109 if (args->count() == 0) {
00110 KCmdLineArgs::usageError(i18n("No applet name specified"));
00111 }
00112
00113
00114 QString pluginName = args->arg(0);
00115
00116 QString formfactor = args->getOption("formfactor");
00117 kDebug() << "setting FormFactor to" << args->getOption("formfactor");
00118
00119 QString location = args->getOption("location");
00120 kDebug() << "setting Location to" << args->getOption("location");
00121
00122 QString containment = args->getOption("containment");
00123 kDebug() << "setting containment to" << containment;
00124
00125 QString wallpaper;
00126 if (args->isSet("wallpaper")) {
00127 wallpaper = args->getOption("wallpaper");
00128 kDebug() << "setting wallpaper to" << wallpaper;
00129 }
00130
00131 QVariantList appletArgs;
00132 for (int i = 1; i < args->count(); ++i) {
00133 appletArgs << args->arg(i);
00134 }
00135
00136 FullView view(formfactor, location);
00137 view.addApplet(pluginName, containment, wallpaper, appletArgs);
00138 view.show();
00139
00140 QAction *action = KStandardAction::quit(&app, SLOT(quit()), &view);
00141 view.addAction(action);
00142
00143 if (args->isSet("pixmapcache")) {
00144 kDebug() << "setting pixmap cache to" << args->getOption("pixmapcache").toInt();
00145 QPixmapCache::setCacheLimit(args->getOption("pixmapcache").toInt());
00146 }
00147 args->clear();
00148
00149 return app.exec();
00150 }
00151