• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

main.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2007 Frerich Raabe <raabe@kde.org>
00003  * Copyright 2007-2008 Aaron Seigo <aseigo@kde.org>
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00016  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00017  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00018  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00019  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00020  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00021  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00022  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00024  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 // for --list
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     //At this point arg(0) is always set
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 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal