~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/tools/engineexplorer/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2006 Aaron Seigo <aseigo@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU General Public License as
 
6
 *   published by the Free Software Foundation; either version 2,
 
7
 *   or (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include <iostream>
 
21
 
 
22
#include <KApplication>
 
23
#include <KAboutData>
 
24
#include <KCmdLineArgs>
 
25
#include <KLocale>
 
26
 
 
27
#include <Plasma/DataEngineManager>
 
28
 
 
29
#include "engineexplorer.h"
 
30
 
 
31
static const char description[] = I18N_NOOP("Explore the data published by Plasma DataEngines");
 
32
static const char version[] = "0.2";
 
33
 
 
34
void listEngines()
 
35
{
 
36
    int maxLen = 0;
 
37
    QMap<QString, QString> engines;
 
38
    foreach (const KPluginInfo &info, Plasma::DataEngineManager::listEngineInfo()) {
 
39
        if (info.property("NoDisplay").toBool()) {
 
40
            continue;
 
41
        }
 
42
 
 
43
        int len = info.pluginName().length();
 
44
        if (len > maxLen) {
 
45
            maxLen = len;
 
46
        }
 
47
 
 
48
        QString name = info.pluginName();
 
49
        QString comment = info.comment();
 
50
 
 
51
        if (comment.isEmpty()) {
 
52
            comment = i18n("No description available");
 
53
        }
 
54
 
 
55
        engines.insert(name, comment);
 
56
    }
 
57
 
 
58
    QMap<QString, QString>::const_iterator it;
 
59
    for (it = engines.constBegin(); it != engines.constEnd(); it++) {
 
60
        QString engine("%1 - %2");
 
61
        engine = engine.arg(it.key().leftJustified(maxLen, ' ')).arg(it.value());
 
62
        std::cout << engine.toLocal8Bit().data() << std::endl;
 
63
    }
 
64
}
 
65
 
 
66
int main(int argc, char **argv)
 
67
{
 
68
    KAboutData aboutData("plasmaengineexplorer", 0, ki18n("Plasma Engine Explorer"),
 
69
                         version, ki18n(description), KAboutData::License_GPL,
 
70
                         ki18n("(c) 2006, The KDE Team"));
 
71
    aboutData.addAuthor(ki18n("Aaron J. Seigo"),
 
72
                        ki18n( "Author and maintainer" ),
 
73
                        "aseigo@kde.org");
 
74
    aboutData.setProgramIconName("plasma");
 
75
 
 
76
    KCmdLineArgs::init(argc, argv, &aboutData);
 
77
 
 
78
    KCmdLineOptions options;
 
79
    options.add("list", ki18n("Displays a list of known engines and their descriptions"));
 
80
    options.add("height <pixels>", ki18n("The desired height in pixels"));
 
81
    options.add("width <pixels>", ki18n("The desired width in pixels"));
 
82
    options.add("x <pixels>", ki18n("The desired x position in pixels"));
 
83
    options.add("y <pixels>", ki18n("The desired y position in pixels"));
 
84
    options.add("engine <data engine>", ki18n("The data engine to use"));
 
85
    options.add("source <data engine>", ki18n("The source to request"));
 
86
    options.add("interval <ms>", ki18n("Update interval in milliseconds"));
 
87
    options.add("app <application>", ki18n("Only show engines associated with the parent application; "
 
88
                                           "maps to the X-KDE-ParentApp entry in the DataEngine's .desktop file."));
 
89
 
 
90
    KCmdLineArgs::addCmdLineOptions(options);
 
91
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
92
 
 
93
    if (args->isSet("list")) {
 
94
        listEngines();
 
95
        return 0;
 
96
    }
 
97
 
 
98
    KApplication app;
 
99
    EngineExplorer* w = new EngineExplorer;
 
100
 
 
101
    bool ok1, ok2 = false;
 
102
    //get size
 
103
    int x = args->getOption("height").toInt(&ok1);
 
104
    int y = args->getOption("width").toInt(&ok2);
 
105
    if (ok1 && ok2) {
 
106
        w->resize(x,y);
 
107
    }
 
108
 
 
109
    //get pos if available
 
110
    x = args->getOption("x").toInt(&ok1);
 
111
    y = args->getOption("y").toInt(&ok2);
 
112
    if (ok1 && ok2) {
 
113
        w->move(x,y);
 
114
    }
 
115
 
 
116
    //set interval
 
117
    int interval = args->getOption("interval").toInt(&ok1);
 
118
    if (ok1) {
 
119
        w->setInterval(interval);
 
120
    }
 
121
 
 
122
    //set engine
 
123
    QString engine = args->getOption("engine");
 
124
    if (!engine.isEmpty()) {
 
125
        w->setEngine(engine);
 
126
 
 
127
        QString source = args->getOption("source");
 
128
        if (!source.isEmpty()) {
 
129
            w->requestSource(source);
 
130
        }
 
131
    }
 
132
 
 
133
    if (args->isSet("app")) {
 
134
        w->setApp(args->getOption("app"));
 
135
    }
 
136
 
 
137
    args->clear();
 
138
 
 
139
    w->show();
 
140
    return app.exec();
 
141
}