the rest of the fallout from the package changes

This commit is contained in:
Aaron Seigo 2011-07-15 13:35:58 +02:00
parent 2e51a57701
commit c16dffd1e7
4 changed files with 1 additions and 2172 deletions

View File

@ -1,84 +1,3 @@
[Desktop Entry]
Type=ServiceType
X-KDE-ServiceType=Plasma/PackageStructure
Comment=Plasma package structure definition
Comment[ar]=تعريف بنية حزمة بلازما
Comment[as]=Plasma
Comment[ast]=Definición d'estructura de paquete Plasma
Comment[be@latin]=Aznačeńnie struktury pakunka Plasma
Comment[bg]=Структурно определение на пакет на Plasma
Comment[bs]=Definicija strukture plazma paketa
Comment[ca]=Definició de l'estructura d'un paquet Plasma
Comment[ca@valencia]=Definició de l'estructura d'un paquet Plasma
Comment[cs]=Definice struktury Plasma balíčku
Comment[da]=Definition af pakkestruktur til Plasma
Comment[de]=Plasma-Paket-Struktur-Definition
Comment[el]=Ορισμός δομής πακέτου του Plasma
Comment[en_GB]=Plasma package structure definition
Comment[es]=Definición de estructura de paquete para Plasma
Comment[et]=Plasma paketi struktuuri definitsioon
Comment[eu]=Plasma paketearen egituraren definizioa
Comment[fi]=Plasma-pakettirakenteen määritelmä
Comment[fr]=Définition de la structure des paquetages Plasma
Comment[fy]=Plasma pakket sstruktuer defenysje
Comment[ga]=Sainmhíniú ar struchtúr pacáiste Plasma
Comment[gl]=Definición da estrutura do paquete de Plasma
Comment[gu]=
Comment[he]=הגדרת מבנה של חבילת Plasma
Comment[hne]= ि
Comment[hr]=Plasmina definicija strukture paketa
Comment[hsb]=Strukturna definicija Plasma-pakćika
Comment[hu]=Struktúraleíró Plasma-csomagokhoz
Comment[ia]=Definition del structura de pacchetto de Plasma
Comment[id]=Definisi struktur paket Plasma
Comment[is]=Skilgreiningar Plasma pakkauppbyggingar
Comment[it]=Definizione struttura pacchetto Plasma
Comment[ja]=Plasma
Comment[kk]=Plasma дестесінің құрамынын анықтауы
Comment[km]=
Comment[kn]= () (ಿ)
Comment[ko]=Plasma
Comment[ku]=Daxuyaniya çêbûna pakêta Plasma
Comment[lt]=Plasma paketo struktūros aprašymas
Comment[lv]=Plasma pakotņu struktūras definīcija
Comment[mai]= ि
Comment[ml]= ി
Comment[nb]=Definisjon av Plasma pakkestruktur
Comment[nds]=Paketstruktuur-Fastleggen vun Plasma
Comment[nl]=Structuurdefinitie van plasmapakket
Comment[nn]=Pakkestrukturdefinisjon for Plasma
Comment[pa]= ਿ
Comment[pl]=Definicja struktury pakietu Plazmy
Comment[pt]=Definição da estrutura de pacotes do Plasma
Comment[pt_BR]=Definição de estrutura de pacote do Plasma
Comment[ro]=Definiție de structură a pachetului Plasma
Comment[ru]=Определение структуры пакета Plasma
Comment[se]=Plasma-páhkkaráhkadusdefinišuvdna
Comment[sk]=Definícia štruktúry Plasma balíčkov
Comment[sl]=Definicija strukture paketa za Plasmo
Comment[sr]=Дефиниција структуре плазма пакета
Comment[sr@ijekavian]=Дефиниција структуре плазма пакета
Comment[sr@ijekavianlatin]=Definicija strukture plasma paketa
Comment[sr@latin]=Definicija strukture plasma paketa
Comment[sv]=Strukturdefinition av Plasma-paket
Comment[ta]=ி ி ி
Comment[tg]=Барномаи муайянкунии сохтори Plasma
Comment[th]=
Comment[tr]=Plasma paketi yapı tanımlaması
Comment[ug]=Plasma بوغچا قۇرۇلما ئېنىقلىمىسى
Comment[uk]=Опис структури пакунка плазми
Comment[wa]=Definixha del sitructeure do pacaedje di Plasma
Comment[x-test]=xxPlasma package structure definitionxx
Comment[zh_CN]=Plasma
Comment[zh_TW]=Plasma
[PropertyDef::X-Plasma-PackageFileFilter]
Type=QString
[PropertyDef::X-Plasma-PackageFileMimetypes]
Type=QStringList
[PropertyDef::X-Plasma-ProvidesWidgetBrowser]
Type=bool
X-KDE-ServiceType=Plasma/Package

View File

@ -1,855 +0,0 @@
/******************************************************************************
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public License *
* along with this library; see the file COPYING.LIB. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
*******************************************************************************/
#include "packagestructure.h"
#include "config-plasma.h"
#include <QDir>
#include <QMap>
#include <QFileInfo>
#include <kconfiggroup.h>
#include <kdebug.h>
#include <kdesktopfile.h>
#ifndef PLASMA_NO_KIO
#include <kio/copyjob.h>
#include <kio/deletejob.h>
#include <kio/jobclasses.h>
#include <kio/job.h>
#endif
#include <kmimetype.h>
#include <kstandarddirs.h>
#include <kservicetypetrader.h>
#include <ktar.h>
#include <ktemporaryfile.h>
#include <ktempdir.h>
#include <kurl.h>
#include <kzip.h>
#include "package.h"
#include "private/packages_p.h"
#include "theme.h"
namespace Plasma
{
class ContentStructure
{
public:
ContentStructure()
: directory(false),
required(false)
{
}
ContentStructure(const ContentStructure &other)
{
paths = other.paths;
name = other.name;
mimeTypes = other.mimeTypes;
directory = other.directory;
required = other.required;
}
QStringList paths;
QString name;
QStringList mimeTypes;
bool directory : 1;
bool required : 1;
};
class PackageStructurePrivate
{
public:
PackageStructurePrivate(const QString &t)
: type(t),
packageRoot("plasma/plasmoids"),
servicePrefix("plasma-applet-"),
metadata(0),
externalPaths(false)
{
contentsPrefixPaths << "contents/";
}
~PackageStructurePrivate()
{
delete metadata;
}
void createPackageMetadata(const QString &path);
QStringList entryList(const QString &prefix, const QString &requestedPath);
static QHash<QString, PackageStructure::Ptr> structures;
QString type;
QString path;
QStringList contentsPrefixPaths;
QString packageRoot;
QString servicePrefix;
QMap<QByteArray, ContentStructure> contents;
QStringList mimeTypes;
KPluginInfo *metadata;
bool externalPaths;
};
QHash<QString, PackageStructure::Ptr> PackageStructurePrivate::structures;
PackageStructure::PackageStructure(QObject *parent, const QString &type)
: QObject(parent),
d(new PackageStructurePrivate(type))
{
}
PackageStructure::~PackageStructure()
{
delete d;
}
PackageStructure::Ptr PackageStructure::load(const QString &packageFormat)
{
if (packageFormat.isEmpty()) {
return Ptr(new PackageStructure());
}
PackageStructure::Ptr structure = PackageStructurePrivate::structures[packageFormat];
if (structure) {
return structure;
}
if (packageFormat == "Plasma/Applet") {
structure = defaultPackageStructure(AppletComponent);
structure->d->type = "Plasma/Applet";
} else if (packageFormat == "Plasma/DataEngine") {
structure = defaultPackageStructure(DataEngineComponent);
structure->d->type = "Plasma/DataEngine";
} else if (packageFormat == "Plasma/Runner") {
structure = defaultPackageStructure(RunnerComponent);
structure->d->type = "Plasma/Runner";
} else if (packageFormat == "Plasma/Wallpaper") {
structure = defaultPackageStructure(WallpaperComponent);
structure->d->type = "Plasma/Wallpaper";
} else if (packageFormat == "Plasma/Theme") {
structure = Theme::packageStructure();
structure->d->type = "Plasma/Theme";
} else if (packageFormat == "Plasma/Generic") {
structure = defaultPackageStructure(GenericComponent);
structure->d->type = "Plasma/Generic";
structure->setDefaultPackageRoot(KStandardDirs::locate("data", "plasmapackages"));
}
if (structure) {
PackageStructurePrivate::structures[packageFormat] = structure;
return structure;
}
// first we check for plugins in sycoca
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(packageFormat);
KService::List offers =
KServiceTypeTrader::self()->query("Plasma/PackageStructure", constraint);
QVariantList args;
QString error;
foreach (const KService::Ptr &offer, offers) {
PackageStructure::Ptr structure(
offer->createInstance<Plasma::PackageStructure>(0, args, &error));
if (structure) {
return structure;
}
kDebug() << "Couldn't load PackageStructure for" << packageFormat
<< "! reason given: " << error;
}
// if that didn't give us any love, then we try to load from a config file
structure = new PackageStructure();
QString configPath("plasma/packageformats/%1rc");
configPath = KStandardDirs::locate("data", configPath.arg(packageFormat));
if (!configPath.isEmpty()) {
KConfig config(configPath);
structure->read(&config);
PackageStructurePrivate::structures[packageFormat] = structure;
return structure;
}
// try to load from absolute file path
KUrl url(packageFormat);
if (url.isLocalFile()) {
KConfig config(url.toLocalFile(), KConfig::SimpleConfig);
structure->read(&config);
PackageStructurePrivate::structures[structure->type()] = structure;
}
#ifndef PLASMA_NO_KIO
else {
KTemporaryFile tmp;
if (tmp.open()) {
KIO::Job *job = KIO::file_copy(url, KUrl(tmp.fileName()),
-1, KIO::Overwrite | KIO::HideProgressInfo);
if (job->exec()) {
KConfig config(tmp.fileName(), KConfig::SimpleConfig);
structure->read(&config);
PackageStructurePrivate::structures[structure->type()] = structure;
}
}
}
#endif
return structure;
}
PackageStructure &PackageStructure::operator=(const PackageStructure &rhs)
{
if (this == &rhs) {
return *this;
}
*d = *rhs.d;
return *this;
}
QString PackageStructure::type() const
{
return d->type;
}
QList<const char*> PackageStructure::directories() const
{
QList<const char*> dirs;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
if (it.value().directory) {
dirs << it.key();
}
++it;
}
return dirs;
}
QList<const char*> PackageStructure::requiredDirectories() const
{
QList<const char*> dirs;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
if (it.value().directory &&
it.value().required) {
dirs << it.key();
}
++it;
}
return dirs;
}
QList<const char*> PackageStructure::files() const
{
QList<const char*> files;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
if (!it.value().directory) {
files << it.key();
}
++it;
}
return files;
}
QList<const char*> PackageStructure::requiredFiles() const
{
QList<const char*> files;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
if (!it.value().directory && it.value().required) {
files << it.key();
}
++it;
}
return files;
}
QStringList PackageStructure::entryList(const char *key)
{
QString p = path(key);
if (p.isEmpty()) {
return QStringList();
}
QStringList list;
if (d->contentsPrefixPaths.isEmpty()) {
// no prefixes is the same as d->contentsPrefixPths with QStringList() << QString()
list << d->entryList(QString(), p);
} else {
foreach (QString prefix, d->contentsPrefixPaths) {
list << d->entryList(prefix, p);
}
}
return list;
}
QStringList PackageStructurePrivate::entryList(const QString &prefix, const QString &requestedPath)
{
QDir dir(path + prefix + requestedPath);
if (externalPaths) {
return dir.entryList(QDir::Files | QDir::Readable);
}
// ensure that we don't return files outside of our base path
// due to symlink or ../ games
QString canonicalized = dir.canonicalPath();
if (canonicalized.startsWith(path)) {
return dir.entryList(QDir::Files | QDir::Readable);
}
return QStringList();
}
void PackageStructure::addDirectoryDefinition(const char *key,
const QString &path, const QString &name)
{
ContentStructure s;
if (d->contents.contains(key)) {
s = d->contents[key];
}
if (!name.isEmpty()) {
s.name = name;
}
s.paths.append(path);
s.directory = true;
d->contents[key] = s;
}
void PackageStructure::addFileDefinition(const char *key, const QString &path, const QString &name)
{
ContentStructure s;
if (d->contents.contains(key)) {
s = d->contents[key];
}
if (!name.isEmpty()) {
s.name = name;
}
s.paths.append(path);
s.directory = false;
d->contents[key] = s;
}
void PackageStructure::removeDefinition(const char *key)
{
d->contents.remove(key);
}
QString PackageStructure::path(const char *key) const
{
//kDebug() << "looking for" << key;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return QString();
}
//kDebug() << "found" << key << "and the value is" << it.value().paths.first();
return it.value().paths.first();
}
QStringList PackageStructure::searchPath(const char *key) const
{
//kDebug() << "looking for" << key;
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return QStringList();
}
//kDebug() << "found" << key << "and the value is" << it.value().paths;
return it.value().paths;
}
QString PackageStructure::name(const char *key) const
{
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return QString();
}
return it.value().name;
}
void PackageStructure::setRequired(const char *key, bool required)
{
QMap<QByteArray, ContentStructure>::iterator it = d->contents.find(key);
if (it == d->contents.end()) {
return;
}
it.value().required = required;
}
bool PackageStructure::isRequired(const char *key) const
{
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return false;
}
return it.value().required;
}
void PackageStructure::setDefaultMimeTypes(QStringList mimeTypes)
{
d->mimeTypes = mimeTypes;
}
void PackageStructure::setMimeTypes(const char *key, QStringList mimeTypes)
{
QMap<QByteArray, ContentStructure>::iterator it = d->contents.find(key);
if (it == d->contents.end()) {
return;
}
it.value().mimeTypes = mimeTypes;
}
QStringList PackageStructure::mimeTypes(const char *key) const
{
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constFind(key);
if (it == d->contents.constEnd()) {
return QStringList();
}
if (it.value().mimeTypes.isEmpty()) {
return d->mimeTypes;
}
return it.value().mimeTypes;
}
void PackageStructure::setPath(const QString &path)
{
KUrl url(path);
QDir dir(url.toLocalFile());
QString basePath = dir.canonicalPath();
bool valid = QFile::exists(basePath);
if (valid) {
QFileInfo info(basePath);
if (info.isDir() && !basePath.endsWith('/')) {
basePath.append('/');
}
//kDebug() << "basePath is" << basePath;
} else {
kDebug() << path << "invalid, basePath is" << basePath;
return;
}
if (d->path == basePath) {
return;
}
d->path = basePath;
delete d->metadata;
d->metadata = 0;
pathChanged();
}
QString PackageStructure::path() const
{
return d->path;
}
void PackageStructure::pathChanged()
{
// default impl does nothing, this is a hook for subclasses.
}
void PackageStructure::read(const KConfigBase *config)
{
d->contents.clear();
d->mimeTypes.clear();
KConfigGroup general(config, QString());
d->type = general.readEntry("Type", QString());
d->contentsPrefixPaths = general.readEntry("ContentsPrefixPaths", d->contentsPrefixPaths);
d->packageRoot = general.readEntry("DefaultPackageRoot", d->packageRoot);
d->externalPaths = general.readEntry("AllowExternalPaths", d->externalPaths);
QStringList groups = config->groupList();
foreach (const QString &group, groups) {
KConfigGroup entry(config, group);
QByteArray key = group.toAscii();
QString path = entry.readEntry("Path", QString());
QString name = entry.readEntry("Name", QString());
QStringList mimeTypes = entry.readEntry("Mimetypes", QStringList());
bool directory = entry.readEntry("Directory", false);
bool required = entry.readEntry("Required", false);
if (directory) {
addDirectoryDefinition(key, path, name);
} else {
addFileDefinition(key, path, name);
}
setMimeTypes(key, mimeTypes);
setRequired(key, required);
}
}
void PackageStructure::write(KConfigBase *config) const
{
KConfigGroup general = KConfigGroup(config, "");
general.writeEntry("Type", type());
general.writeEntry("ContentsPrefixPaths", d->contentsPrefixPaths);
general.writeEntry("DefaultPackageRoot", d->packageRoot);
general.writeEntry("AllowExternalPaths", d->externalPaths);
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
while (it != d->contents.constEnd()) {
KConfigGroup group = config->group(it.key());
group.writeEntry("Path", it.value().paths);
group.writeEntry("Name", it.value().name);
if (!it.value().mimeTypes.isEmpty()) {
group.writeEntry("Mimetypes", it.value().mimeTypes);
}
if (it.value().directory) {
group.writeEntry("Directory", true);
}
if (it.value().required) {
group.writeEntry("Required", true);
}
++it;
}
}
QStringList PackageStructure::contentsPrefixPaths() const
{
return d->contentsPrefixPaths;
}
void PackageStructure::setContentsPrefixPaths(const QStringList &prefixPaths)
{
d->contentsPrefixPaths = prefixPaths;
}
bool PackageStructure::installPackage(const QString &package, const QString &packageRoot)
{
//TODO: report *what* failed if something does fail
QDir root(packageRoot);
if (!root.exists()) {
KStandardDirs::makeDir(packageRoot);
if (!root.exists()) {
kWarning() << "Could not create package root directory:" << packageRoot;
return false;
}
}
QFileInfo fileInfo(package);
if (!fileInfo.exists()) {
kWarning() << "No such file:" << package;
return false;
}
QString path;
KTempDir tempdir;
bool archivedPackage = false;
if (fileInfo.isDir()) {
// we have a directory, so let's just install what is in there
path = package;
// make sure we end in a slash!
if (path[path.size() - 1] != '/') {
path.append('/');
}
} else {
KArchive *archive = 0;
KMimeType::Ptr mimetype = KMimeType::findByPath(package);
if (mimetype->is("application/zip")) {
archive = new KZip(package);
} else if (mimetype->is("application/x-compressed-tar") ||
mimetype->is("application/x-tar")|| mimetype->is("application/x-bzip-compressed-tar")) {
archive = new KTar(package);
} else {
kWarning() << "Could not open package file, unsupported archive format:" << package << mimetype->name();
return false;
}
if (!archive->open(QIODevice::ReadOnly)) {
kWarning() << "Could not open package file:" << package;
delete archive;
return false;
}
archivedPackage = true;
path = tempdir.name();
const KArchiveDirectory *source = archive->directory();
source->copyTo(path);
QStringList entries = source->entries();
if (entries.count() == 1) {
const KArchiveEntry *entry = source->entry(entries[0]);
if (entry->isDirectory()) {
path.append(entry->name()).append("/");
}
}
delete archive;
}
QString metadataPath = path + "metadata.desktop";
if (!QFile::exists(metadataPath)) {
kWarning() << "No metadata file in package" << package << metadataPath;
return false;
}
KPluginInfo meta(metadataPath);
QString targetName = meta.pluginName();
if (targetName.isEmpty()) {
kWarning() << "Package plugin name not specified";
return false;
}
// Ensure that package names are safe so package uninstall can't inject
// bad characters into the paths used for removal.
QRegExp validatePluginName("^[\\w-\\.]+$"); // Only allow letters, numbers, underscore and period.
if (!validatePluginName.exactMatch(targetName)) {
kWarning() << "Package plugin name " << targetName << "contains invalid characters";
return false;
}
targetName = packageRoot + '/' + targetName;
if (QFile::exists(targetName)) {
kWarning() << targetName << "already exists";
return false;
}
if (archivedPackage) {
// it's in a temp dir, so just move it over.
#ifndef PLASMA_NO_KIO
KIO::CopyJob *job = KIO::move(KUrl(path), KUrl(targetName), KIO::HideProgressInfo);
const bool ok = job->exec();
const QString errorString = job->errorString();
#else
const bool ok = copyFolder(path, targetName);
removeFolder(path);
const QString errorString("unknown");
#endif
if (!ok) {
kWarning() << "Could not move package to destination:" << targetName << " : " << errorString;
return false;
}
} else {
// it's a directory containing the stuff, so copy the contents rather
// than move them
#ifndef PLASMA_NO_KIO
KIO::CopyJob *job = KIO::copy(KUrl(path), KUrl(targetName), KIO::HideProgressInfo);
const bool ok = job->exec();
const QString errorString = job->errorString();
#else
const bool ok = copyFolder(path, targetName);
const QString errorString("unknown");
#endif
if (!ok) {
kWarning() << "Could not copy package to destination:" << targetName << " : " << errorString;
return false;
}
}
if (archivedPackage) {
// no need to remove the temp dir (which has been successfully moved if it's an archive)
tempdir.setAutoRemove(false);
}
if (!d->servicePrefix.isEmpty()) {
// and now we register it as a service =)
QString metaPath = targetName + "/metadata.desktop";
KDesktopFile df(metaPath);
KConfigGroup cg = df.desktopGroup();
// Q: should not installing it as a service disqualify it?
// Q: i don't think so since KServiceTypeTrader may not be
// used by the installing app in any case, and the
// package is properly installed - aseigo
//TODO: reduce code duplication with registerPackage below
QString serviceName = d->servicePrefix + meta.pluginName();
QString service = KStandardDirs::locateLocal("services", serviceName + ".desktop");
#ifndef PLASMA_NO_KIO
KIO::FileCopyJob *job = KIO::file_copy(metaPath, service, -1, KIO::HideProgressInfo);
const bool ok = job->exec();
const QString errorString = job->errorString();
#else
const bool ok = QFile::copy(metaPath, service);
const QString errorString("unknown");
#endif
if (ok) {
// the icon in the installed file needs to point to the icon in the
// installation dir!
QString iconPath = targetName + '/' + cg.readEntry("Icon");
QFile icon(iconPath);
if (icon.exists()) {
KDesktopFile df(service);
KConfigGroup cg = df.desktopGroup();
cg.writeEntry("Icon", iconPath);
}
} else {
kWarning() << "Could not register package as service (this is not necessarily fatal):" << serviceName << " : " << errorString;
}
}
return true;
}
bool PackageStructure::uninstallPackage(const QString &packageName, const QString &packageRoot)
{
// We need to remove the package directory and its metadata file.
const QString targetName = packageRoot + '/' + packageName;
if (!QFile::exists(targetName)) {
kWarning() << targetName << "does not exist";
return false;
}
QString serviceName = d->servicePrefix + packageName;
QString service = KStandardDirs::locateLocal("services", serviceName + ".desktop");
kDebug() << "Removing service file " << service;
bool ok = QFile::remove(service);
if (!ok) {
kWarning() << "Unable to remove " << service;
}
#ifndef PLASMA_NO_KIO
KIO::DeleteJob *job = KIO::del(KUrl(targetName));
ok = job->exec();
const QString errorString = job->errorString();
#else
ok = removeFolder(targetName);
const QString errorString("unknown");
#endif
if (!ok) {
kWarning() << "Could not delete package from:" << targetName << " : " << errorString;
return false;
}
return true;
}
QString PackageStructure::defaultPackageRoot() const
{
return d->packageRoot;
}
QString PackageStructure::servicePrefix() const
{
return d->servicePrefix;
}
void PackageStructure::setDefaultPackageRoot(const QString &packageRoot)
{
d->packageRoot = packageRoot;
}
void PackageStructure::setServicePrefix(const QString &servicePrefix)
{
d->servicePrefix = servicePrefix;
}
void PackageStructurePrivate::createPackageMetadata(const QString &path)
{
delete metadata;
QString metadataPath(path + "/metadata.desktop");
if (!QFile::exists(metadataPath)) {
kWarning() << "No metadata file in the package, expected it at:" << metadataPath;
metadataPath.clear();
}
metadata = new KPluginInfo(metadataPath);
}
KPluginInfo PackageStructure::metadata() const
{
if (!d->metadata && !d->path.isEmpty()) {
QFileInfo fileInfo(d->path);
if (fileInfo.isDir()) {
d->createPackageMetadata(d->path);
} else if (fileInfo.exists()) {
KArchive *archive = 0;
KMimeType::Ptr mimeType = KMimeType::findByPath(d->path);
if (mimeType->is("application/zip")) {
archive = new KZip(d->path);
} else if (mimeType->is("application/x-compressed-tar") ||
mimeType->is("application/x-tar")|| mimeType->is("application/x-bzip-compressed-tar")) {
archive = new KTar(d->path);
} else {
kWarning() << "Could not open package file, unsupported archive format:" << d->path << mimeType->name();
}
if (archive && archive->open(QIODevice::ReadOnly)) {
const KArchiveDirectory *source = archive->directory();
KTempDir tempdir;
source->copyTo(tempdir.name());
d->createPackageMetadata(tempdir.name());
} else {
kWarning() << "Could not open package file:" << d->path;
}
delete archive;
}
}
if (!d->metadata) {
d->metadata = new KPluginInfo();
}
return *d->metadata;
}
bool PackageStructure::allowExternalPaths() const
{
return d->externalPaths;
}
void PackageStructure::setAllowExternalPaths(bool allow)
{
d->externalPaths = allow;
}
} // Plasma namespace
#include "packagestructure.moc"

View File

@ -1,351 +0,0 @@
/******************************************************************************
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public License *
* along with this library; see the file COPYING.LIB. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
*******************************************************************************/
#ifndef PLASMA_PACKAGESTRUCTURE_H
#define PLASMA_PACKAGESTRUCTURE_H
#include <QtCore/QStringList>
#include <QtCore/QSharedData>
#include <kgenericfactory.h>
#include <klocale.h>
#include <kplugininfo.h>
#include <ksharedptr.h>
#include <plasma/version.h>
class KConfigBase;
namespace Plasma
{
class PackageStructurePrivate;
/**
* @class PackageStructure plasma/packagestructure.h <Plasma/PackageStructure>
*
* @short A description of the expected file structure of a given package type
*
* PackageStructure defines what is in a package. This information is used
* to create packages and provides a way to programatically refer to contents.
*
* An example usage of this class might be:
*
@code
PackageStructure structure;
structure.addDirectoryDefinition("images", "pics/", i18n("Images"));
QStringList mimeTypes;
mimeTypes << "image/svg" << "image/png" << "image/jpeg";
structure.setMimeTypes("images", mimeTypes);
structure.addDirectoryDefinition("scripts", "code/", i18n("Executable Scripts"));
mimeTypes.clear();
mimeTypes << "text/\*";
structure.setMimeTypes("scripts", mimeTypes);
structure.addFileDefinition("mainscript", "code/main.js", i18n("Main Script File"));
structure.setRequired("mainscript", true);
@endcode
* One may also choose to create a subclass of PackageStructure and include the setup
* in the constructor.
*
* Either way, PackageStructure creates a sort of "contract" between the packager and
* the application which is also self-documenting.
**/
class PLASMA_EXPORT PackageStructure : public QObject, public QSharedData
{
Q_OBJECT
public:
typedef KSharedPtr<PackageStructure> Ptr;
/**
* Default constructor for a package structure definition
*
* @param type the type of package. This is often application specific.
**/
explicit PackageStructure(QObject *parent = 0,
const QString &type = i18nc("A non-functional package", "Invalid"));
/**
* Destructor
**/
virtual ~PackageStructure();
/**
* Assignment operator
**/
PackageStructure &operator=(const PackageStructure &rhs);
/**
* Loads a package format by name.
*
* @param format If not empty, attempts to locate the given format, either
* from built-ins or via plugins.
* @return a package that matches the format, if available. The caller
* is responsible for deleting the object.
*/
static PackageStructure::Ptr load(const QString &packageFormat);
/**
* Type of package this structure describes
**/
QString type() const;
/**
* The directories defined for this package
**/
QList<const char*> directories() const;
/**
* The required directories defined for this package
**/
QList<const char*> requiredDirectories() const;
/**
* The individual files, by key, that are defined for this package
**/
QList<const char*> files() const;
/**
* The individual required files, by key, that are defined for this package
**/
QList<const char*> requiredFiles() const;
/**
* Adds a directory to the structure of the package. It is added as
* a not-required element with no associated mimeTypes.
*
* Starting in 4.6, if an entry with the given key
* already exists, the path is added to it as a search alternative.
*
* @param key used as an internal label for this directory
* @param path the path within the package for this directory
* @param name the user visible (translated) name for the directory
**/
void addDirectoryDefinition(const char *key, const QString &path, const QString &name);
/**
* Adds a file to the structure of the package. It is added as
* a not-required element with no associated mimeTypes.
*
* Starting in 4.6, if an entry with the given key
* already exists, the path is added to it as a search alternative.
*
* @param key used as an internal label for this file
* @param path the path within the package for this file
* @param name the user visible (translated) name for the file
**/
void addFileDefinition(const char *key, const QString &path, const QString &name);
/**
* Removes a definition from the structure of the package.
* @since 4.6
* @param key the internal label of the file or directory to remove
*/
void removeDefinition(const char *key);
/**
* @return path relative to the package root for the given entry
* @deprecatd use searchPaths instead
**/
QString path(const char *key) const;
/**
* @return a list of paths relative to the package root for the given entry.
* They are orted by importance: when searching for a file the paths
* will be searched in order
* @since 4.6
**/
QStringList searchPath(const char *key) const;
/**
* Get the list of files of a given type.
*
* @param key the type of file to look for
* @return list of files by name
* @since 4.3
*/
QStringList entryList(const char *key);
/**
* @return user visible name for the given entry
**/
QString name(const char *key) const;
/**
* Sets whether or not a given part of the structure is required or not.
* The path must already have been added using addDirectoryDefinition
* or addFileDefinition.
*
* @param key the entry within the package
* @param required true if this entry is required, false if not
*/
void setRequired(const char *key, bool required);
/**
* @return true if the item at path exists and is required
**/
bool isRequired(const char *key) const;
/**
* Defines the default mimeTypes for any definitions that do not have
* associated mimeTypes. Handy for packages with only one or predominantly
* one file type.
*
* @param mimeTypes a list of mimeTypes
**/
void setDefaultMimeTypes(QStringList mimeTypes);
/**
* Define mimeTypes for a given part of the structure
* The path must already have been added using addDirectoryDefinition
* or addFileDefinition.
*
* @param key the entry within the package
* @param mimeTypes a list of mimeTypes
**/
void setMimeTypes(const char *key, QStringList mimeTypes);
/**
* @return the mimeTypes associated with the path, if any
**/
QStringList mimeTypes(const char *key) const;
/**
* Sets the path to the package. Useful for package formats
* which do not have well defined contents prior to installation.
*/
void setPath(const QString &path);
/**
* @return the path to the package, or QString() if none
*/
QString path() const;
/**
* Read a package structure from a config file.
*/
void read(const KConfigBase *config);
/**
* Write this package structure to a config file.
*/
void write(KConfigBase *config) const;
/**
* Installs a package matching this package structure. By default installs a
* native Plasma::Package.
*
* @param archivePath path to the package archive file
* @param packageRoot path to the directory where the package should be
* installed to
* @return true on successful installation, false otherwise
**/
virtual bool installPackage(const QString &archivePath, const QString &packageRoot);
/**
* Uninstalls a package matching this package structure.
*
* @param packageName the name of the package to remove
* @param packageRoot path to the directory where the package should be installed to
* @return true on successful removal of the package, false otherwise
*/
virtual bool uninstallPackage(const QString &packageName, const QString &packageRoot);
/**
* @return the prefix paths inserted between the base path and content entries, in order of priority.
* When searching for a file, all paths will be tried in order.
* @since 4.6
*/
QStringList contentsPrefixPaths() const;
/**
* @return preferred package root. This defaults to plasma/plasmoids/
*/
QString defaultPackageRoot() const;
/**
* @return service prefix used in desktop files. This defaults to plasma-applet-
*/
QString servicePrefix() const;
/**
* Sets service prefix.
*/
void setServicePrefix(const QString &servicePrefix);
/**
* @return the package metadata object.
*/
virtual KPluginInfo metadata() const;
/**
* @return true if paths/symlinks outside the package itself should be followed.
* By default this is set to false for security reasons.
*/
bool allowExternalPaths() const;
protected:
/**
* Sets whether or not external paths/symlinks can be followed by a package
* @param allow true if paths/symlinks outside of the package should be followed,
* false if they should be rejected.
*/
void setAllowExternalPaths(bool allow);
/**
* Sets the prefixes that all the contents in this package should
* appear under. This defaults to "contents/" and is added automatically
* between the base path and the entries as defined by the package
* structure. Multiple entries can be added.
* In this case each file request will be searched in all prefixes in order,
* and the first found will be returned.
*
* @param prefix paths the directory prefix to use
* @since 4.6
*/
void setContentsPrefixPaths(const QStringList &prefixPaths);
/**
* Sets preferred package root.
*/
void setDefaultPackageRoot(const QString &packageRoot);
/**
* Called whenever the path changes so that subclasses may take
* package specific actions.
*/
virtual void pathChanged();
private:
PackageStructurePrivate * const d;
};
/**
* Register an applet when it is contained in a loadable module
*/
#define K_EXPORT_PLASMA_PACKAGESTRUCTURE(libname, classname) \
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
K_EXPORT_PLUGIN(factory("plasma_packagestructure_" #libname)) \
K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
} // Plasma namespace
#endif

View File

@ -1,884 +0,0 @@
/*
* Copyright 2006-2007 by Aaron Seigo <aseigo@kde.org>
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_PLASMOID_H
#define PLASMA_PLASMOID_H
<QObject>
namespace Plasma
{
class PlasmoidPrivate;
class Containment;
class Context;
class DataEngine;
class Extender;
class ExtenderItem;
class Package;
/**
* @class Plasmoid plasma/applet.h <Plasma/Plasmoid>
*
* @short The base Plasmoid class
*
* Plasmoid provides several important roles for add-ons widgets in Plasma.
*
* First, it is the base class for the plugin system and therefore is the
* interface to applets for host applications. It also handles the life time
* management of data engines (e.g. all data engines accessed via
* Plasmoid::dataEngine(const QString&) are properly deref'd on Plasmoid
* destruction), background painting (allowing for consistent and complex
* look and feel in just one line of code for applets), loading and starting
* of scripting support for each applet, providing access to the associated
* plasmoid package (if any) and access to configuration data.
*
* See techbase.kde.org for tutorials on writing Plasmoids using this class.
*/
class PLASMA_EXPORT Plasmoid : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
Q_PROPERTY(QString name READ name)
Q_PROPERTY(QString pluginName READ pluginName)
Q_PROPERTY(QString category READ category)
Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability)
Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
Q_PROPERTY(bool busy READ isBusy WRITE setBusy)
Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
Q_PROPERTY(uint id READ id)
Q_PROPERTY(bool userConfiguring READ isUserConfiguring)
public:
typedef QList<Plasmoid*> List;
typedef QHash<QString, Plasmoid*> Dict;
/**
* Description on how draw a background for the applet
*/
enum BackgroundHint {
NoBackground = 0, /**< Not drawing a background under the
applet, the applet has its own implementation */
StandardBackground = 1, /**< The standard background from the theme is drawn */
TranslucentBackground = 2, /**< An alternate version of the background is drawn,
usually more translucent */
DefaultBackground = StandardBackground /**< Default settings:
both standard background */
};
Q_DECLARE_FLAGS(BackgroundHints, BackgroundHint)
~Plasmoid();
/**
* @return a package structure representing a Plasmoid
*/
static PackageStructure::Ptr packageStructure();
/**
* @return the id of this applet
*/
uint id() const;
/**
* Returns the KConfigGroup to access the applets configuration.
*
* This config object will write to an instance
* specific config file named \<appletname\>\<instanceid\>rc
* in the Plasma appdata directory.
**/
KConfigGroup config() const;
/**
* Returns a config group with the name provided. This ensures
* that the group name is properly namespaced to avoid collision
* with other applets that may be sharing this config file
*
* @param group the name of the group to access
**/
KConfigGroup config(const QString &group) const;
/**
* Saves state information about this applet that will
* be accessed when next instantiated in the restore(KConfigGroup&) method.
*
* This method does not need to be reimplmented by Plasmoid
* subclasses, but can be useful for Plasmoid specializations
* (such as Containment) to do so.
*
* Plasmoid subclasses may instead want to reimplement saveState().
**/
virtual void save(KConfigGroup &group) const;
/**
* Restores state information about this applet saved previously
* in save(KConfigGroup&).
*
* This method does not need to be reimplmented by Plasmoid
* subclasses, but can be useful for Plasmoid specializations
* (such as Containment) to do so.
**/
virtual void restore(KConfigGroup &group);
/**
* Returns a KConfigGroup object to be shared by all applets of this
* type.
*
* This config object will write to an applet-specific config object
* named plasma_\<appletname\>rc in the local config directory.
*/
KConfigGroup globalConfig() const;
/**
* Returns the config skeleton object from this applet's package,
* if any.
* TODO: still keep both kconfiggroup and kconfigskeleton?
* @return config skeleton object, or 0 if none
**/
ConfigLoader *configScheme() const;
/**
* Accessor for the associated Package object if any.
* Generally, only Plasmoids come in a Package.
*
* @return the Package object, or 0 if none
**/
const Package *package() const;
/**
* Called when any of the geometry constraints have been updated.
* This method calls constraintsEvent, which may be reimplemented,
* once the Plasmoid has been prepared for updating the constraints.
* TODO: KEEP?
* @param constraints the type of constraints that were updated
*/
void updateConstraints(Plasma::Constraints constraints = Plasma::AllConstraints);
/**
* Returns the current form factor the applet is being displayed in.
* TODO: qproperty with notify?
* @see Plasma::FormFactor
*/
virtual FormFactor formFactor() const;
/**
* Returns the location of the scene which is displaying applet.
* TODO: qproperty with notify?
* @see Plasma::Location
*/
virtual Location location() const;
/**
* Returns the workspace context which the applet is operating in
*/
Context *context() const;
/**
* @return the preferred aspect ratio mode for placement and resizing
* TODO: should still be there since this shouldn't be graphical?
*/
Plasma::AspectRatioMode aspectRatioMode() const;
/**
* Sets the preferred aspect ratio mode for placement and resizing
*/
void setAspectRatioMode(Plasma::AspectRatioMode);
/**
* Returns the user-visible name for the applet, as specified in the
* .desktop file.
*
* @return the user-visible name for the applet.
**/
QString name() const;
/**
* Returns the plugin name for the applet
*/
QString pluginName() const;
/**
* Whether the applet should conserve resources. If true, try to avoid doing stuff which
* is computationally heavy. Try to conserve power and resources.
*
* @return true if it should conserve resources, false if it does not.
*/
bool shouldConserveResources() const;
/**
* Returns the icon related to this applet
**/
QString icon() const;
/**
* @return The type of immutability of this applet
*/
ImmutabilityType immutability() const;
/**
* If for some reason, the applet fails to get up on its feet (the
* library couldn't be loaded, necessary hardware support wasn't found,
* etc..) this method returns true
**/
bool hasFailedToLaunch() const;
/**
* @return true if the applet is busy and is showing an indicator widget for that
*/
bool isBusy() const;
/**
* @return true if the applet currently needs to be configured,
* otherwise, false
*/
bool configurationRequired() const;
/**
* @return true if this plasmoid provides a GUI configuration
**/
bool hasConfigurationInterface() const;
/**
* Returns a list of context-related QAction instances.
*
* This is used e.g. within the \a DesktopView to display a
* contextmenu.
*
* @return A list of actions. The default implementation returns an
* empty list.
**/
virtual QList<QAction*> contextualActions();
/**
* Returns the QAction with the given name from our collection
*/
Q_INVOKABLE QAction *action(QString name) const;
/**
* Adds the action to our collection under the given name
* TODO: QList or QHash of QActions instead?
*/
void addAction(QString name, QAction *action);
/**
* Sets the BackgroundHints for this applet @see BackgroundHint
*
* @param hints the BackgroundHint combination for this applet
*/
void setBackgroundHints(const BackgroundHints hints);
/**
* @return BackgroundHints flags combination telling if the standard background is shown
* and if it has a drop shadow
*/
BackgroundHints backgroundHints() const;
/**
* @return true if this Plasmoid is currently being used as a Containment, false otherwise
*/
bool isContainment() const;
/**
* @return the Containment, if any, this applet belongs to
**/
Containment *containment() const;
/**
* Sets the global shorcut to associate with this widget.
* TODO: globalActions instead?
*/
void setGlobalShortcut(const KShortcut &shortcut);
/**
* @return the global shortcut associated with this wiget, or
* an empty shortcut if no global shortcut is associated.
*/
KShortcut globalShortcut() const;
/**
* associate actions with this widget, including ones added after this call.
* needed to make keyboard shortcuts work.
* TODO: can this be internal/private?
*/
virtual void addAssociatedWidget(QWidget *widget);
/**
* un-associate actions from this widget, including ones added after this call.
* needed to make keyboard shortcuts work.
*/
virtual void removeAssociatedWidget(QWidget *widget);
/**
* @param parent the QGraphicsItem this applet is parented to
* @param serviceId the name of the .desktop file containing the
* information about the widget
* @param appletId a unique id used to differentiate between multiple
* instances of the same Plasmoid type
*/
explicit Plasmoid(QGraphicsItem *parent = 0,
const QString &serviceId = QString(),
uint appletId = 0);
/**
* @param parent the QGraphicsItem this applet is parented to
* @param info the plugin information object for this Plasmoid
* @param appletId a unique id used to differentiate between multiple
* instances of the same Plasmoid type
* @since 4.6
*/
explicit Plasmoid(const KPluginInfo &info, QGraphicsItem *parent = 0, uint appletId = 0);
/**
* @param parent the QGraphicsItem this applet is parented to
* @param serviceId the name of the .desktop file containing the
* information about the widget
* @param appletId a unique id used to differentiate between multiple
* instances of the same Plasmoid type
* @param args a list of strings containing two entries: the service id
* and the applet id
* @since 4.3
*/
explicit Plasmoid(QGraphicsItem *parent,
const QString &serviceId,
uint appletId,
const QVariantList &args);
/**
* @return true if destroy() was called; useful for Plasmoids which should avoid
* certain tasks if they are about to be deleted permanently
*/
bool destroyed() const;
/**
* Reimplement this method so provide a configuration interface,
* parented to the supplied widget. Ownership of the widgets is passed
* to the parent widget.
*
* Typically one would add custom pages to the config dialog @p parent
* and then connect to the applyClicked() and okClicked() signals
* or @p parent to react on config changes:
*
* @code
* connect(parent, SIGNAL(applyClicked()), this, SLOT(myConfigAccepted()));
* connect(parent, SIGNAL(okClicked()), this, SLOT(myConfigAccepted()));
* @endcode
*
* With this approach it makes sense to store the custom pages in member
* variables to make their fields accessible from the myConfigAccepted()
* slot.
*
* Use config() to store your configuration.
*
* @param parent the dialog which is the parent of the configuration
* widgets
*/
virtual void createConfigurationInterface(KConfigDialog *parent);
/**
* Returns true if the applet is allowed to perform functions covered by the given constraint
* eg. hasAuthorization("FileDialog") returns true if applets are allowed to show filedialogs.
* @since 4.3
*/
bool hasAuthorization(const QString &constraint) const;
/**
* Sets an application associated to this applet, that will be
* regarded as a full view of what is represented in the applet
*
* @param string the name of the application. it can be
* \li a name understood by KService::serviceByDesktopName
* (e.g. "konqueror")
* \li a command in $PATH
* \li or an absolute path to an executable
* @since 4.4
*/
void setAssociatedApplication(const QString &string);
/**
* Sets a list of urls associated to this application,
* they will be used as parameters for the associated application
* @see setAssociatedApplication()
*
* @param urls
*/
void setAssociatedApplicationUrls(const KUrl::List &urls);
/**
* @return the application associated to this applet
* @since 4.4
*/
QString associatedApplication() const;
/**
* @return the urls associated to this applet
* @since 4.4
*/
KUrl::List associatedApplicationUrls() const;
/**
* @return true if the applet has a valid associated application or urls
* @since 4.4
*/
bool hasValidAssociatedApplication() const;
Q_SIGNALS:
/**
* This signal indicates that an application launch, window
* creation or window focus event was triggered. This is used, for instance,
* to ensure that the Dashboard view in Plasma Desktop hides when such an event is
* triggered by an item it is displaying.
*/
void releaseVisualFocus();
Q_SIGNALS:
/**
* Emitted when the user completes a transformation of the applet.
*/
void appletTransformedByUser();
/**
* Emitted when the applet changes its own geometry or transform.
*/
void appletTransformedItself();
/**
* Emitted by Plasmoid subclasses when they change a sizeHint and wants to announce the change
*/
void sizeHintChanged(Qt::SizeHint which);
/**
* Emitted when an applet has changed values in its configuration
* and wishes for them to be saved at the next save point. As this implies
* disk activity, this signal should be used with care.
*
* @note This does not need to be emitted from saveState by individual
* applets.
*/
void configNeedsSaving();
/**
* Emitted when activation is requested due to, for example, a global
* keyboard shortcut. By default the wiget is given focus.
*/
void activate();
/**
* Emitted when the user clicked on a button of the message overlay
*
* @see showMessage
* @see Plasma::MessageButton
* @since 4.3
*/
void messageButtonPressed(const Plasma::MessageButton button);
/**
* Emitted when the applet is deleted
*/
void appletDestroyed(Plasma::Plasmoid *applet);
/**
* Emitted when the applet status changes
* @since 4.4
*/
void newStatus(Plasma::ItemStatus status);
/**
* Emitted when an ExtenderItem in a scripting applet needs to be initialized
*/
void extenderItemRestored(Plasma::ExtenderItem *item);
/**
* Emitted when the immutability changes
* @since 4.4
*/
void immutabilityChanged(Plasma::ImmutabilityType immutable);
public Q_SLOTS:
/**
* Sets the immutability type for this applet (not immutable,
* user immutable or system immutable)
* @arg immutable the new immutability type of this applet
*/
void setImmutability(const ImmutabilityType immutable);
/**
* Destroys the applet; it will be removed nicely and deleted.
* Its configuration will also be deleted.
*/
virtual void destroy();
/**
* Lets the user interact with the plasmoid options.
* Called when the user selects the configure entry
* from the context menu.
*
* Unless there is good reason for overriding this method,
* Plasmoid subclasses should actually override createConfigurationInterface
* instead. A good example of when this isn't plausible is
* when using a dialog prepared by another library, such
* as KPropertiesDialog from libkfile.
* You probably want to call showConfigurationInterface(QWidget*)
* with the custom widget you created to actually show your interface
*/
virtual void showConfigurationInterface();
/**
* Actually show your custom configuration interface
* Use this only if you reimplemented showConfigurationInterface()
*
* @arg widget the widget representing your configuration interface
*
* @since 4.5
*/
void showConfigurationInterface(QWidget *widget);
/**
* @return true when the configuration interface is being shown
* @since 4.5
*/
bool isUserConfiguring() const;
/**
* Causes this applet to raise above all other applets.
*/
void raise();
/**
* Causes this applet to lower below all the other applets.
*/
void lower();
/**
* Sends all pending contraints updates to the applet. Will usually
* be called automatically, but can also be called manually if needed.
*/
void flushPendingConstraintsEvents();
/**
* This method is called once the applet is loaded and added to a Corona.
* If the applet requires a QGraphicsScene or has an particularly intensive
* set of initialization routines to go through, consider implementing it
* in this method instead of the constructor.
*
* Note: paintInterface may get called before init() depending on initialization
* order. Painting is managed by the canvas (QGraphisScene), and may schedule a
* paint event prior to init() being called.
**/
virtual void init();
/**
* Called when applet configuration values have changed.
*/
virtual void configChanged();
/**
* Shows a busy indicator that overlays the applet
* @param busy show or hide the busy indicator
*/
void setBusy(bool busy);
/**
* @return the list of arguments which the applet was called with
* @since KDE4.3
*/
QVariantList startupArguments() const;
/**
* @return the status of the applet
* @since 4.4
*/
ItemStatus status() const;
/**
* sets the status for this applet
* @since 4.4
*/
void setStatus(const ItemStatus stat);
/**
* Publishes and optionally announces this applet on the network for remote access.
* @param methods the methods to use for announcing this applet.
* @param resourceName the name under which this applet will be published (has to be unique
* for each machine)
*/
void publish(Plasma::AnnouncementMethods methods, const QString &resourceName);
void unpublish();
bool isPublished() const;
/**
* Open the application associated to this applet, if it's not set
* but some urls are, open those urls with the proper application
* for their mimetype
* @see setAssociatedApplication()
* @see setAssociatedApplicationUrls()
* @since 4.4
*/
void runAssociatedApplication();
protected:
/**
* This constructor is to be used with the plugin loading systems
* found in KPluginInfo and KService. The argument list is expected
* to have two elements: the KService service ID for the desktop entry
* and an applet ID which must be a base 10 number.
*
* @param parent a QObject parent; you probably want to pass in 0
* @param args a list of strings containing two entries: the service id
* and the applet id
*/
Plasmoid(QObject *parent, const QVariantList &args);
/**
* Call this method when the applet fails to launch properly. An
* optional reason can be provided.
*
* Not that all children items will be deleted when this method is
* called. If you have pointers to these items, you will need to
* reset them after calling this method.
*
* @param failed true when the applet failed, false when it succeeded
* @param reason an optional reason to show the user why the applet
* failed to launch
**/
void setFailedToLaunch(bool failed, const QString &reason = QString());
/**
* When called, the Plasmoid should write any information needed as part
* of the Plasmoid's running state to the configuration object in config()
* and/or globalConfig().
*
* Plasmoids that always sync their settings/state with the config
* objects when these settings/states change do not need to reimplement
* this method.
**/
virtual void saveState(KConfigGroup &config) const;
/**
* Sets whether or not this applet provides a user interface for
* configuring the applet.
*
* It defaults to false, and if true is passed in you should
* also reimplement createConfigurationInterface()
*
* @param hasInterface whether or not there is a user interface available
**/
void setHasConfigurationInterface(bool hasInterface);
/**
* When the applet needs to be configured before being usable, this
* method can be called to show a standard interface prompting the user
* to configure the applet
*
* @param needsConfiguring true if the applet needs to be configured,
* or false if it doesn't
* @param reason a translated message for the user explaining that the
* applet needs configuring; this should note what needs
* to be configured
*/
void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
/**
* Shows a message as an overlay of the applet: the message has an
* icon, text and (optional) buttons
*
* @param icon the icon that will be shown
* @param message the message string that will be shown.
* If the message is empty nothng will be shown
* and if there was a message already it will be hidden
* @param buttons an OR combination of all the buttons needed
*
* @see Plasma::MessageButtons
* @see messageButtonPressed
* @since 4.3
*/
void showMessage(const QIcon &icon, const QString &message, const Plasma::MessageButtons buttons);
/**
* Called when any of the geometry constraints have been updated.
*
* This is always called prior to painting and should be used as an
* opportunity to layout the widget, calculate sizings, etc.
*
* Do not call update() from this method; an update() will be triggered
* at the appropriate time for the applet.
*
* @param constraints the type of constraints that were updated
* @property constraint
*/
virtual void constraintsEvent(Plasma::Constraints constraints);
/**
* Register the widgets that manage mouse clicks but you still want
* to be able to drag the applet around when holding the mouse pointer
* on that widget.
*
* Calling this results in an eventFilter being places on the widget.
*
* @param item the item to watch for mouse move
*/
void registerAsDragHandle(QGraphicsItem *item);
/**
* Unregister a widget registered with registerAsDragHandle.
*
* @param item the item to unregister
*/
void unregisterAsDragHandle(QGraphicsItem *item);
/**
* @param item the item to look for if it is registered or not
* @return true if it is registered, false otherwise
*/
bool isRegisteredAsDragHandle(QGraphicsItem *item);
/**
* @return the extender of this applet.
*/
Extender *extender() const;
/**
* @internal event filter; used for focus watching
**/
bool eventFilter(QObject *o, QEvent *e);
/**
* @internal scene event filter; used to manage applet dragging
*/
bool sceneEventFilter (QGraphicsItem *watched, QEvent *event);
/**
* @internal manage the mouse movement to drag the applet around
*/
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
/**
* Reimplemented from QGraphicsItem
*/
void focusInEvent(QFocusEvent *event);
/**
* Reimplemented from QGraphicsItem
*/
void resizeEvent(QGraphicsSceneResizeEvent *event);
/**
* Reimplemented from QGraphicsItem
*/
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* Reimplemented from QGraphicsItem
*/
QPainterPath shape() const;
/**
* Reimplemented from QGraphicsLayoutItem
*/
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
/**
* Reimplemented from QGraphicsLayoutItem
*/
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
/**
* Reimplemented from QGraphicsLayoutItem
*/
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
/**
* Reimplemented from QObject
*/
void timerEvent (QTimerEvent *event);
private:
/**
* @internal This constructor is to be used with the Package loading system.
*
* @param parent a QObject parent; you probably want to pass in 0
* @param args a list of strings containing two entries: the service id
* and the applet id
* @since 4.3
*/
Plasmoid(const QString &packagePath, uint appletId, const QVariantList &args);
Q_PRIVATE_SLOT(d, void setFocus())
Q_PRIVATE_SLOT(d, void themeChanged())
Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
Q_PRIVATE_SLOT(d, void selectItemToDestroy())
Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
Q_PRIVATE_SLOT(d, void destroyMessageOverlay())
Q_PRIVATE_SLOT(d, void clearShortcutEditorPtr())
Q_PRIVATE_SLOT(d, void configDialogFinished())
Q_PRIVATE_SLOT(d, void updateShortcuts())
Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state))
Q_PRIVATE_SLOT(d, void globalShortcutChanged())
Q_PRIVATE_SLOT(d, void propagateConfigChanged())
/**
* Reimplemented from QGraphicsItem
**/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
PlasmoidPrivate *const d;
//Corona needs to access setFailedToLaunch and init
friend class Corona;
friend class CoronaPrivate;
friend class Containment;
friend class ContainmentPrivate;
friend class PlasmoidScript;
friend class PlasmoidHandle;
friend class PlasmoidPrivate;
friend class AccessPlasmoidJobPrivate;
friend class PluginLoader;
friend class PopupPlasmoid;
friend class PopupPlasmoidPrivate;
friend class AssociatedApplicationManager;
friend class Extender;
friend class ExtenderGroup;
friend class ExtenderGroupPrivate;
friend class ExtenderPrivate;
friend class ExtenderItem;
};
} // Plasma namespace
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Plasmoid::BackgroundHints)
/**
* Register an applet when it is contained in a loadable module
*/
#define K_EXPORT_PLASMA_APPLET(libname, classname) \
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
K_EXPORT_PLUGIN(factory("plasma_applet_" #libname)) \
K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
#endif // multiple inclusion guard