Plasma
qedje_package.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 <qedje_package.h>
00021 #include <qedje.h>
00022
00023 #include <QtCore/QDir>
00024 #include <QtCore/QFile>
00025 #include <QDir>
00026 #include <QFile>
00027
00028 #include <Plasma/Package>
00029 #include <Plasma/PackageStructure>
00030 #include <Plasma/PackageMetadata>
00031
00032 K_EXPORT_PLASMA_PACKAGESTRUCTURE(qedjescripts, QEdjePackage)
00033
00034 QEdjePackage::QEdjePackage(QObject *parent, const QVariantList &args)
00035 : Plasma::PackageStructure(parent) {
00036 Q_UNUSED(args);
00037 addFileDefinition("edje_file", "file.edj", i18n("Main Edje File"));
00038 setRequired("edje_file", true);
00039 }
00040
00041 QEdjePackage::~QEdjePackage() {
00042 }
00043
00044
00045 bool QEdjePackage::installPackage(const QString &archive_path,
00046 const QString &package_root) {
00047
00048 kDebug() << "QEdjePackage::installPackage archivePath="
00049 << archive_path
00050 << "packageRoot=" << package_root;
00051
00052
00053 QStringList groups = groupNamesFromFile(archive_path);
00054 if (groups.isEmpty()) {
00055 kDebug() << "Invalid file format";
00056 return false;
00057 }
00058
00059 QString file = archive_path.split("/", QString::SkipEmptyParts).last();
00060 QString package_name = file.split(".", QString::SkipEmptyParts).first();
00061
00062 QString dir_name = QString("qedje_%1").arg(package_name);
00063 QString dest_dir = QString("%1/%2/contents/").arg(package_root).arg(dir_name);
00064
00065
00066 QDir contents(dest_dir);
00067 if (!contents.exists() && !contents.mkpath(dest_dir)) {
00068 kDebug() << "It was not possible to create the destination directory";
00069 return false;
00070 }
00071
00072
00073 if (!QFile::copy(archive_path, QString(dest_dir + "file.edj"))) {
00074 kDebug() << "It was not possible to copy " << archive_path << "to " << dest_dir;
00075 return false;
00076 }
00077
00078 setPath(dest_dir);
00079
00080
00081 Plasma::PackageMetadata data;
00082 data.setName(package_name);
00083 data.setType("Service");
00084 data.setPluginName(dir_name);
00085 data.setImplementationApi("qedjescript");
00086 data.setDescription(i18n("An Edje Object to be loaded using QEdje"));
00087 Plasma::Package::registerPackage(data, QString(""));
00088
00089 return true;
00090 }