• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.8 API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • plasma
  • depextractor
depextractor.cpp
Go to the documentation of this file.
1 /* Plasma Data Engine dependency extractor
2  Copyright (C) 2011 Kevin Kofler <kevin.kofler@chello.at>
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 published by
6  the Free Software Foundation, either version 2 of the License, or
7  (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 General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 
17 #include <QCoreApplication>
18 #include <QTextStream>
19 #include <QFileInfo>
20 #include <QDir>
21 
22 #include <cstdio>
23 
24 #include <kaboutdata.h>
25 #include <kcmdlineargs.h>
26 #include <kdesktopfile.h>
27 #include <kconfiggroup.h>
28 
29 #include "private/componentinstaller_p.h"
30 
31 static QString scriptingApi(const QString &desktopFile)
32 {
33  KDesktopFile desktop(desktopFile);
34  KConfigGroup desktopGroup = desktop.desktopGroup();
35  if (desktopGroup.readEntry("X-KDE-ServiceTypes", QStringList())
36  .contains("Plasma/ScriptEngine")
37  || desktopGroup.readEntry("ServiceTypes", QStringList())
38  .contains("Plasma/ScriptEngine")) {
39  /* Script engines are always written in C++. Their X-Plasma-API is the
40  API they export, not the language they're written in. */
41  return QString();
42  }
43  return desktopGroup.readEntry("X-Plasma-API", QString());
44 }
45 
46 static void writeDataEngineDependencies(const QStringList &deps,
47  const QString &desktopFile)
48 {
49  if (!deps.isEmpty()) {
50  KDesktopFile desktop(desktopFile);
51  desktop.desktopGroup().writeEntry("X-Plasma-RequiredDataEngines", deps);
52  }
53 }
54 
55 int main(int argc, char **argv)
56 {
57  KAboutData aboutData("plasma-dataengine-depextractor", QByteArray(),
58  ki18n("Plasma Data Engine dependency extractor"),
59  "2",
60  ki18n("Plasma Data Engine dependency extractor"));
61  aboutData.addAuthor(ki18n("Kevin Kofler"), ki18n("Author"),
62  "kevin.kofler@chello.at");
63 
64  KCmdLineArgs::init(argc, argv, &aboutData);
65  KCmdLineOptions options;
66  options.add("+[path]",
67  ki18n("Source path (default: .)"));
68  options.add("+[file]",
69  ki18n(".desktop rel. to path (default: metadata.desktop)")
70  );
71  KCmdLineArgs::addCmdLineOptions(options);
72 
73  QCoreApplication *app = new QCoreApplication(KCmdLineArgs::qtArgc(),
74  KCmdLineArgs::qtArgv());
75 
76  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
77 
78  int exitCode = 0;
79 
80  QString path, desktopFile;
81  int argCount = args->count();
82  switch (argCount) {
83  case 0:
84  path = ".";
85  desktopFile = "metadata.desktop";
86  break;
87  case 1:
88  path = args->arg(0);
89  desktopFile = "metadata.desktop";
90  break;
91  case 2:
92  path = args->arg(0);
93  desktopFile = args->arg(1);
94  break;
95  default:
96  {
97  QTextStream err(stderr, QIODevice::WriteOnly | QIODevice::Text);
98  err << i18n("Expected at most 2 arguments, but %1 given", argCount)
99  << endl;
100  exitCode = 1;
101  break;
102  }
103  }
104 
105  if (!exitCode) {
106  if (QFileInfo(desktopFile).isRelative())
107  desktopFile = QDir(path).absoluteFilePath(desktopFile);
108 
109  if (QFileInfo(desktopFile).exists()) {
110  writeDataEngineDependencies(Plasma::ComponentInstaller::self()
111  ->extractDataEngineDependencies(
112  path,
113  scriptingApi(desktopFile)),
114  desktopFile);
115  } else {
116  QTextStream err(stderr, QIODevice::WriteOnly | QIODevice::Text);
117  err << i18n("Desktop file \"%1\" not found", desktopFile) << endl;
118  exitCode = 1;
119  }
120  }
121 
122  args->clear();
123  delete app;
124  return exitCode;
125 }
writeDataEngineDependencies
static void writeDataEngineDependencies(const QStringList &deps, const QString &desktopFile)
Definition: depextractor.cpp:46
main
int main(int argc, char **argv)
Definition: depextractor.cpp:55
scriptingApi
static QString scriptingApi(const QString &desktopFile)
Definition: depextractor.cpp:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Fri Nov 20 2015 11:52:42 by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

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

kdelibs-4.14.8 API Reference

Skip menu "kdelibs-4.14.8 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal