File indexing completed on 2024-05-05 05:37:09

0001 /*
0002  *   SPDX-FileCopyrightText: 2006 Aaron Seigo <aseigo@kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include <iostream>
0008 
0009 #include <KAboutData>
0010 #include <KLocalizedString>
0011 #include <KPluginMetaData>
0012 #include <QApplication>
0013 
0014 #include <Plasma5Support/PluginLoader>
0015 #include <qcommandlineoption.h>
0016 #include <qcommandlineparser.h>
0017 
0018 #include "engineexplorer.h"
0019 
0020 void listEngines()
0021 {
0022     int maxLen = 0;
0023     QMap<QString, QString> engines;
0024     const auto plugins = Plasma5Support::PluginLoader::listDataEngineMetaData();
0025     for (const KPluginMetaData &info : plugins) {
0026         int len = info.pluginId().length();
0027         if (len > maxLen) {
0028             maxLen = len;
0029         }
0030 
0031         QString name = info.pluginId();
0032         QString comment = info.description();
0033 
0034         if (comment.isEmpty()) {
0035             comment = i18n("No description available");
0036         }
0037 
0038         engines.insert(name, comment);
0039     }
0040 
0041     QMap<QString, QString>::const_iterator it;
0042     for (it = engines.constBegin(); it != engines.constEnd(); ++it) {
0043         QString engine("%1 - %2");
0044         engine = engine.arg(it.key().leftJustified(maxLen, ' ')).arg(it.value());
0045         std::cout << engine.toLocal8Bit().data() << std::endl;
0046     }
0047 }
0048 
0049 int main(int argc, char **argv)
0050 {
0051     QApplication app(argc, argv);
0052 
0053     KLocalizedString::setApplicationDomain("plasmaengineexplorer");
0054 
0055     KAboutData aboutData("plasmaengineexplorer",
0056                          i18n("Plasma Engine Explorer"),
0057                          PROJECT_VERSION,
0058                          i18n("Explore the data published by Plasma DataEngines"),
0059                          KAboutLicense::GPL,
0060                          i18n("(c) 2006, The KDE Team"));
0061     aboutData.addAuthor(i18n("Aaron J. Seigo"), i18n("Author and maintainer"), "aseigo@kde.org");
0062     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("plasma"), app.windowIcon()));
0063 
0064     KAboutData::setApplicationData(aboutData);
0065 
0066     QCommandLineParser parser;
0067     aboutData.setupCommandLine(&parser);
0068     parser.addOption(QCommandLineOption(QStringList() << "list", i18n("Displays a list of known engines and their descriptions")));
0069     parser.addOption(QCommandLineOption(QStringList() << "height", i18n("The desired height in pixels"), "pixels"));
0070     parser.addOption(QCommandLineOption(QStringList() << "width", i18n("The desired width in pixels"), "pixels"));
0071     parser.addOption(QCommandLineOption(QStringList() << "x", i18n("The desired x position in pixels"), "pixels"));
0072     parser.addOption(QCommandLineOption(QStringList() << "y", i18n("The desired y position in pixels"), "pixels"));
0073     parser.addOption(QCommandLineOption(QStringList() << "engine", i18n("The data engine to use"), "data engine"));
0074     parser.addOption(QCommandLineOption(QStringList() << "source", i18n("The source to request"), "data engine"));
0075     parser.addOption(QCommandLineOption(QStringList() << "interval", i18n("Update interval in milliseconds"), "ms"));
0076     parser.addOption(QCommandLineOption(QStringList() << "app",
0077                                         i18n("Only show engines associated with the parent application; "
0078                                              "maps to the X-KDE-ParentApp entry in the DataEngine's .desktop file."),
0079                                         "application"));
0080 
0081     parser.process(app);
0082     aboutData.processCommandLine(&parser);
0083 
0084     if (parser.isSet("list")) {
0085         listEngines();
0086         return 0;
0087     }
0088 
0089     EngineExplorer *w = new EngineExplorer;
0090 
0091     bool ok1, ok2 = false;
0092     // get size
0093     int x = parser.value("height").toInt(&ok1);
0094     int y = parser.value("width").toInt(&ok2);
0095     if (ok1 && ok2) {
0096         w->resize(x, y);
0097     }
0098 
0099     // get pos if available
0100     x = parser.value("x").toInt(&ok1);
0101     y = parser.value("y").toInt(&ok2);
0102     if (ok1 && ok2) {
0103         w->move(x, y);
0104     }
0105 
0106     // set interval
0107     int interval = parser.value("interval").toInt(&ok1);
0108     if (ok1) {
0109         w->setInterval(interval);
0110     }
0111 
0112     // set engine
0113     QString engine = parser.value("engine");
0114     if (!engine.isEmpty()) {
0115         w->setEngine(engine);
0116 
0117         QString source = parser.value("source");
0118         if (!source.isEmpty()) {
0119             w->requestSource(source);
0120         }
0121     }
0122 
0123     if (parser.isSet("app")) {
0124         w->setApp(parser.value("app"));
0125     }
0126 
0127     w->show();
0128     return app.exec();
0129 }