simplify down to one constructor and try harder to have all information at all times with clearer code
This commit is contained in:
parent
a386f40f73
commit
e4be1cecf5
@ -31,7 +31,9 @@
|
||||
#include <kdebug.h>
|
||||
#include <ktemporaryfile.h>
|
||||
#include <kzip.h>
|
||||
#include <kservicetypetrader.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QHostInfo>
|
||||
@ -53,6 +55,10 @@ void PlasmoidServiceJob::start()
|
||||
{
|
||||
if (operationName() == "GetPackage") {
|
||||
kDebug() << "sending " << m_service->m_packagePath;
|
||||
if (m_service->m_packagePath.isEmpty()) {
|
||||
// just return the plugin name in this case
|
||||
setResult(m_service->m_pluginName);
|
||||
} else {
|
||||
QFileInfo fileInfo(m_service->m_packagePath);
|
||||
|
||||
if (fileInfo.exists() && fileInfo.isAbsolute()) {
|
||||
@ -61,8 +67,8 @@ void PlasmoidServiceJob::start()
|
||||
file.open(QIODevice::ReadOnly);
|
||||
setResult(file.readAll());
|
||||
} else {
|
||||
kDebug() << "file doesn't exists, we're sending the plugin name";
|
||||
setResult(m_service->m_packagePath);
|
||||
setResult(QString());
|
||||
}
|
||||
}
|
||||
} else if (operationName() == "GetMetaData") {
|
||||
QFile file(m_service->m_metadata);
|
||||
@ -78,27 +84,19 @@ void PlasmoidServiceJob::start()
|
||||
}
|
||||
setResult(serviceName);
|
||||
}
|
||||
|
||||
setResult(false);
|
||||
}
|
||||
|
||||
|
||||
PlasmoidService::PlasmoidService(const QString &packageLocation)
|
||||
: Plasma::Service(0)
|
||||
PlasmoidService::PlasmoidService(Applet *applet)
|
||||
: Plasma::Service(applet),
|
||||
m_pluginName(applet->pluginName())
|
||||
{
|
||||
setName("plasmoidservice");
|
||||
|
||||
QString location;
|
||||
location = packageLocation;
|
||||
if (!location.endsWith('/')) {
|
||||
location.append('/');
|
||||
}
|
||||
|
||||
m_metadata = location + "metadata.desktop";
|
||||
|
||||
/*FIXME: either do something useful on error or don't waste time with them
|
||||
if (!QFile::exists(m_metadata)) {
|
||||
kDebug() << "not a valid package";
|
||||
}
|
||||
*/
|
||||
if (applet->package() && !applet->package()->isValid()) {
|
||||
const QString root = applet->package()->path();
|
||||
m_metadata = root + "metadata.desktop";
|
||||
|
||||
m_tempFile.open();
|
||||
m_packagePath = m_tempFile.fileName();
|
||||
@ -107,23 +105,27 @@ PlasmoidService::PlasmoidService(const QString &packageLocation)
|
||||
// put everything into a zip archive
|
||||
KZip creation(m_packagePath);
|
||||
creation.setCompression(KZip::NoCompression);
|
||||
if (!creation.open(QIODevice::WriteOnly)) {
|
||||
/*FIXME: either do something useful on error or don't waste time with it */
|
||||
if (creation.open(QIODevice::WriteOnly)) {
|
||||
QDir dir(root);
|
||||
foreach (const QString &entry, dir.entryList(QDir::Files)) {
|
||||
creation.addLocalFile(root + entry, entry);
|
||||
}
|
||||
|
||||
foreach (const QString &entry, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||
creation.addLocalDirectory(root + entry, entry);
|
||||
}
|
||||
|
||||
creation.close();
|
||||
} else {
|
||||
kDebug() << "could not open archive";
|
||||
}
|
||||
|
||||
creation.addLocalFile(location + "metadata.desktop", "metadata.desktop");
|
||||
location.append("contents/");
|
||||
creation.addLocalDirectory(location, "contents");
|
||||
creation.close();
|
||||
} else {
|
||||
kDebug() << "applet lacks a valid package";
|
||||
const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(applet->pluginName());
|
||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
||||
if (!offers.isEmpty()) {
|
||||
m_metadata = offers.first()->entryPath();
|
||||
}
|
||||
|
||||
PlasmoidService::PlasmoidService(Applet *applet)
|
||||
{
|
||||
setName("plasmoidservice");
|
||||
if (!applet->package() || !applet->package()->isValid()) {
|
||||
kDebug() << "not a valid package";
|
||||
m_packagePath = applet->pluginName();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,6 @@ class PlasmoidService : public Service, DataEngineConsumer
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlasmoidService(const QString &plasmoidLocation);
|
||||
PlasmoidService(Applet *applet);
|
||||
|
||||
protected:
|
||||
@ -66,6 +65,7 @@ class PlasmoidService : public Service, DataEngineConsumer
|
||||
private:
|
||||
QString m_packagePath;
|
||||
QString m_metadata;
|
||||
QString m_pluginName;
|
||||
KTemporaryFile m_tempFile;
|
||||
|
||||
friend class PlasmoidServiceJob;
|
||||
|
Loading…
x
Reference in New Issue
Block a user