Plasma
depextractor.cpp
Go to the documentation of this file.
00001 /* Plasma Data Engine dependency extractor 00002 Copyright (C) 2011 Kevin Kofler <kevin.kofler@chello.at> 00003 00004 This program is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00016 00017 #include <QCoreApplication> 00018 #include <QTextStream> 00019 #include <QFileInfo> 00020 #include <QDir> 00021 00022 #include <cstdio> 00023 00024 #include <kaboutdata.h> 00025 #include <kcmdlineargs.h> 00026 #include <kdesktopfile.h> 00027 #include <kconfiggroup.h> 00028 00029 #include "private/componentinstaller_p.h" 00030 00031 static QString scriptingApi(const QString &desktopFile) 00032 { 00033 KDesktopFile desktop(desktopFile); 00034 KConfigGroup desktopGroup = desktop.desktopGroup(); 00035 if (desktopGroup.readEntry("X-KDE-ServiceTypes", QStringList()) 00036 .contains("Plasma/ScriptEngine") 00037 || desktopGroup.readEntry("ServiceTypes", QStringList()) 00038 .contains("Plasma/ScriptEngine")) { 00039 /* Script engines are always written in C++. Their X-Plasma-API is the 00040 API they export, not the language they're written in. */ 00041 return QString(); 00042 } 00043 return desktopGroup.readEntry("X-Plasma-API", QString()); 00044 } 00045 00046 static void writeDataEngineDependencies(const QStringList &deps, 00047 const QString &desktopFile) 00048 { 00049 if (!deps.isEmpty()) { 00050 KDesktopFile desktop(desktopFile); 00051 desktop.desktopGroup().writeEntry("X-Plasma-RequiredDataEngines", deps); 00052 } 00053 } 00054 00055 int main(int argc, char **argv) 00056 { 00057 KAboutData aboutData("plasma-dataengine-depextractor", QByteArray(), 00058 ki18n("Plasma Data Engine dependency extractor"), 00059 "2", 00060 ki18n("Plasma Data Engine dependency extractor")); 00061 aboutData.addAuthor(ki18n("Kevin Kofler"), ki18n("Author"), 00062 "kevin.kofler@chello.at"); 00063 00064 KCmdLineArgs::init(argc, argv, &aboutData); 00065 KCmdLineOptions options; 00066 options.add("+[path]", 00067 ki18n("Source path (default: .)")); 00068 options.add("+[file]", 00069 ki18n(".desktop rel. to path (default: metadata.desktop)") 00070 ); 00071 KCmdLineArgs::addCmdLineOptions(options); 00072 00073 QCoreApplication *app = new QCoreApplication(KCmdLineArgs::qtArgc(), 00074 KCmdLineArgs::qtArgv()); 00075 00076 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 00077 00078 int exitCode = 0; 00079 00080 QString path, desktopFile; 00081 int argCount = args->count(); 00082 switch (argCount) { 00083 case 0: 00084 path = "."; 00085 desktopFile = "metadata.desktop"; 00086 break; 00087 case 1: 00088 path = args->arg(0); 00089 desktopFile = "metadata.desktop"; 00090 break; 00091 case 2: 00092 path = args->arg(0); 00093 desktopFile = args->arg(1); 00094 break; 00095 default: 00096 { 00097 QTextStream err(stderr, QIODevice::WriteOnly | QIODevice::Text); 00098 err << i18n("Expected at most 2 arguments, but %1 given", argCount) 00099 << endl; 00100 exitCode = 1; 00101 break; 00102 } 00103 } 00104 00105 if (!exitCode) { 00106 if (QFileInfo(desktopFile).isRelative()) 00107 desktopFile = QDir(path).absoluteFilePath(desktopFile); 00108 00109 if (QFileInfo(desktopFile).exists()) { 00110 writeDataEngineDependencies(Plasma::ComponentInstaller::self() 00111 ->extractDataEngineDependencies( 00112 path, 00113 scriptingApi(desktopFile)), 00114 desktopFile); 00115 } else { 00116 QTextStream err(stderr, QIODevice::WriteOnly | QIODevice::Text); 00117 err << i18n("Desktop file \"%1\" not found", desktopFile) << endl; 00118 exitCode = 1; 00119 } 00120 } 00121 00122 args->clear(); 00123 delete app; 00124 return exitCode; 00125 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:51:36 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:51:36 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.