Plasma
main.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <iostream>
00021
00022 #include <QDir>
00023
00024 #include <KApplication>
00025 #include <KAboutData>
00026 #include <KAction>
00027 #include <KCmdLineArgs>
00028 #include <KLocale>
00029 #include <KService>
00030 #include <KServiceTypeTrader>
00031 #include <KShell>
00032 #include <KStandardDirs>
00033
00034 #include <plasma/packagestructure.h>
00035
00036 static const char description[] = I18N_NOOP("Install, list, remove Plasma packages");
00037 static const char version[] = "0.1";
00038
00039 void output(const QString &msg)
00040 {
00041 std::cout << msg.toLocal8Bit().constData() << std::endl;
00042 }
00043
00044 void listPackages()
00045 {
00046
00047 output(i18n("Listing is not yet implemented."));
00048 }
00049
00050 int main(int argc, char **argv)
00051 {
00052 KAboutData aboutData("plasmapkg", 0, ki18n("Plasma Package Manager"),
00053 version, ki18n(description), KAboutData::License_GPL,
00054 ki18n("(C) 2008, Aaron Seigo"));
00055 aboutData.addAuthor( ki18n("Aaron Seigo"),
00056 ki18n("Original author"),
00057 "aseigo@kde.org" );
00058
00059 KComponentData componentData(aboutData);
00060
00061 KCmdLineArgs::init( argc, argv, &aboutData );
00062
00063 KCmdLineOptions options;
00064 options.add("g");
00065 options.add("global", ki18n("For install or remove, operates on packages installed for all users."));
00066 options.add("t");
00067 options.add("type <type>",
00068 ki18n("The type of package, e.g. theme, wallpaper, plasmoid, DataEngine, Runner, etc."),
00069 "plasmoid");
00070 options.add("s");
00071 options.add("i");
00072 options.add("install <path>", ki18n("Install the package at <path>"));
00073 options.add("l");
00074 options.add("list", ki18n("List installed packages"));
00075 options.add("r");
00076 options.add("remove <name>", ki18n("Remove the package named <name>"));
00077 options.add("p");
00078 options.add("packageroot <path>", ki18n("Absolute path to the package root. If not supplied, then the standard data directories for this KDE session will be searched instead."));
00079 KCmdLineArgs::addCmdLineOptions( options );
00080
00081 KApplication app;
00082
00083
00084
00085
00086
00087 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00088 if (args->isSet("list")) {
00089 listPackages();
00090 } else {
00091
00092 const QString type = args->getOption("type").toLower();
00093 QString packageRoot = args->getOption("type").toLower();
00094 QString servicePrefix;
00095
00096 Plasma::PackageStructure *installer = new Plasma::PackageStructure();
00097 if (type == i18n("plasmoid") || type == "plasmoid") {
00098 packageRoot = "plasma/plasmoids/";
00099 servicePrefix = "plasma-applet-";
00100 } else if (type == i18n("theme") || type == "theme") {
00101 packageRoot = "desktoptheme/";
00102 } else if (type == i18n("wallpaper") || type == "wallpaper") {
00103 packageRoot = "wallpapers/";
00104 } else if (type == i18n("dataengine") || type == "dataengine") {
00105 packageRoot = "plasma/dataengines/";
00106 servicePrefix = "plasma-dataengine-";
00107 } else if (type == i18n("runner") || type == "runner") {
00108 packageRoot = "plasma/runners/";
00109 servicePrefix = "plasma-abstractrunner-";
00110 } else {
00111
00112 delete installer;
00113 installer = 0;
00114
00115 QString constraint = QString("'%1' == [X-KDE-PluginInfo-Name]").arg(packageRoot);
00116 KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure", constraint);
00117 if (offers.isEmpty()) {
00118 output(i18n("Could not find a suitable installer for package of type %1", type));
00119 return 1;
00120 }
00121
00122 KService::Ptr offer = offers.first();
00123 QString error;
00124 installer = offer->createInstance<Plasma::PackageStructure>(0, QVariantList(), &error);
00125
00126 if (!installer) {
00127 output(i18n("Could not load installer for package of type %1. Error reported was: %2",
00128 type, error));
00129 return 1;
00130 }
00131
00132 packageRoot = "plasma/plasmoids";
00133 }
00134
00135 if (args->isSet("packageroot")) {
00136 packageRoot = args->getOption("packageroot");
00137 } else if (args->isSet("global")) {
00138 packageRoot = KStandardDirs::locate("data", packageRoot);
00139 } else {
00140 packageRoot = KStandardDirs::locateLocal("data", packageRoot);
00141 }
00142
00143 if (args->isSet("install")) {
00144 QString package = KShell::tildeExpand(args->getOption("install"));
00145 if (!QDir::isAbsolutePath(package)) {
00146 package = QDir(QDir::currentPath() + "/" + package).absolutePath();
00147 }
00148
00149 if (installer->installPackage(package, packageRoot)) {
00150 QString msg = i18n("Successfully installed %1", package);
00151 } else {
00152 output(i18n("Installation of %1 failed.", package));
00153 return 1;
00154 }
00155 } else if (args->isSet("remove")) {
00156 QString package = args->getOption("remove");
00157 if (installer->uninstallPackage(package, packageRoot)) {
00158 output(i18n("Successfully removed %1", package));
00159 } else {
00160 output(i18n("Removal of %1 failed.", package));
00161 return 1;
00162 }
00163 } else {
00164 KCmdLineArgs::usageError(i18n("One of install, remove or list is required."));
00165 }
00166 }
00167
00168 return 0;
00169 }
00170