1 /***************************************************************************
2 * Copyright (C) 2008 by Artur Duque de Souza <morpheuz@gmail.com> *
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. *
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. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
20 #include <qedje_package.h>
23 #include <QtCore/QDir>
24 #include <QtCore/QFile>
28 #include <Plasma/Package>
29 #include <Plasma/PackageStructure>
30 #include <Plasma/PackageMetadata>
32 K_EXPORT_PLASMA_PACKAGESTRUCTURE(qedjescripts
, QEdjePackage
)
34 QEdjePackage::QEdjePackage(QObject
*parent
, const QVariantList
&args
)
35 : Plasma::PackageStructure(parent
) {
37 addFileDefinition("edje_file", "file.edj", i18n("Main Edje File"));
38 setRequired("edje_file", true);
41 QEdjePackage::~QEdjePackage() {
45 bool QEdjePackage::installPackage(const QString
&archive_path
,
46 const QString
&package_root
) {
48 kDebug() << "QEdjePackage::installPackage archivePath="
50 << "packageRoot=" << package_root
;
52 // check if it's a valid file by trying to load it's groups
53 QStringList groups
= groupNamesFromFile(archive_path
);
54 if (groups
.isEmpty()) {
55 kDebug() << "Invalid file format";
59 QString file
= archive_path
.split("/", QString::SkipEmptyParts
).last();
60 QString package_name
= file
.split(".", QString::SkipEmptyParts
).first();
62 QString dir_name
= QString("qedje_%1").arg(package_name
);
63 QString dest_dir
= QString("%1/%2/contents/").arg(package_root
).arg(dir_name
);
65 // Create the directory so we can copy the edje file inside it
66 QDir
contents(dest_dir
);
67 if (!contents
.exists() && !contents
.mkpath(dest_dir
)) {
68 kDebug() << "It was not possible to create the destination directory";
72 // Copy the edje file to the package's directory
73 if (!QFile::copy(archive_path
, QString(dest_dir
+ "file.edj"))) {
74 kDebug() << "It was not possible to copy " << archive_path
<< "to " << dest_dir
;
80 // Setup the metadata for this package
81 Plasma::PackageMetadata data
;
82 data
.setName(package_name
);
83 data
.setType("Service");
84 data
.setPluginName(dir_name
);
85 data
.setImplementationApi("qedjescript");
86 data
.setDescription(i18n("An Edje Object to be loaded using QEdje"));
87 Plasma::Package::registerPackage(data
, QString(""));