* Name, Comment and Type fields, which are required for all desktop files.

* Name, Comment and Type fields, which are required for all desktop files.

* X-KDE-ServiceTypes field which tells plasma that this is a PackageStructure

* X-KDE-ServiceTypes field which tells plasma that this is a PackageStructure

−

* X-KDE-PluginInfo-Name field which should be identical to the name used in your code (discussed later). This name must also be globally unique to all other PackageStructure plugins, and so using a reverse-domain style name is recommended to avoid naming collisions with other plugins.

+

* X-KDE-PluginInfo-Name field which should be identical to the name used in your code (discussed later). This name must also be globally unique to all other PackageStructure plugins, and so using a name that includes unique components such as your project or organization's name is recommended to avoid naming collisions with other plugins.

* X-KDE-Library field which tells plasma how to load/install the packages with this package structure.

* X-KDE-Library field which tells plasma how to load/install the packages with this package structure.

* X-KDE-PluginInfo-Name field which should be identical to the name of dataengine/plasmoid that uses this PackageStructure.

* X-KDE-PluginInfo-Name field which should be identical to the name of dataengine/plasmoid that uses this PackageStructure.

Revision as of 09:49, 17 March 2011

Contents

Abstract

A Plasma Package is a set of files, usually shipped in a single compressed archive, that together provide one particular data or functionality addon, such as Plasmoid or a Wallpaper set. Packages may be defined for any kind of custom data (e.g. non-compiled) addons. Packages can be installed, removed, listed and updated.

Plasma::PackageStructure defines what is in a Package. This information is used to create packages and provides a way to programmatically refer to the contents. It's also used to provide an installation profile for your Packages.

plasmapkg

The plasmapkg command line tool is used to get information about Packages and install, remove or upgrade them. Run
plasmapkg --help
to get a list of available options. The most commonly used options are
-i for installing and -r for removing a package.

Name, Comment and Type fields, which are required for all desktop files.

X-KDE-ServiceTypes field which tells plasma that this is a PackageStructure

X-KDE-PluginInfo-Name field which should be identical to the name used in your code (discussed later). This name must also be globally unique to all other PackageStructure plugins, and so using a name that includes unique components such as your project or organization's name is recommended to avoid naming collisions with other plugins.

X-KDE-Library field which tells plasma how to load/install the packages with this package structure.

X-KDE-PluginInfo-Name field which should be identical to the name of dataengine/plasmoid that uses this PackageStructure.

The Header File

testpackage.h

ifndef TESTPACKAGE_H

define TESTPACKAGE_H

// We need this header since we are inheriting it

include <plasma/packagestructure.h>

/**

This PackageStructure provides an structure for packages used by the test
DataEngine.

// This declares the plugin so it can be loaded at runtime from its shared library.
// The plugin name and class name are the two parameters used, respectively.
K_EXPORT_PLASMA_PACKAGESTRUCTURE(org.myproject.test, TestPackage)

endif // TESTPACKAGE_H

The Main Code

testpackage.cpp

include "testpackage.h"

include "plasma/applet.h"

include "plasma/package.h"

/**

We pass Plasma/Test as the type to the Plasma::PackageStructure. this string
should be identical to the "X-KDE-PluginInfo-Name" in the desktop file,
otherwise plasmapkg won't recognize your package and you'll get an this error
when trying to install your packages:
Could not find a suitable installer for package of type Plasma/Test

// tell plasma where to install your package.
// normally this would be prepended with ~/.kde4/share/apps/
// so the final path to your package after installation is ~/.kde4/share/apps/plasma/test/
setDefaultPackageRoot( QLatin1String( "plasma/test/" ) );
// You'll need to use this service prefix when you want to access "test" packages.
setServicePrefix( QLatin1String( "plasma-test-" ) );

}

File Definition

in this Example, For simplicity's sake, I've added code/main.js file definition. This way your packages support only js scripts. But if you want to support a larger set of scripting languages, you should leave this to code/main, and then in your dataengine/plasmoid, when trying to use the installed packages, set the extension of the script file like this:
// get path to your installed packages
const QString path = KStandardDirs::locate( "data", QLatin1String( "plasma/test/" ) + pluginName + QLatin1Char( '/' ) );
if (!path.isEmpty()) {