User:Mxttie: Difference between revisions

From KDE Community Wiki
(→‎Adding configuration: emit configNeedsSaving())
Line 44: Line 44:
</code>
</code>


Writing settings is as easy as:
Writing settings:
<code cppqt>
<code cppqt>
KConfigGroup config = this->config();
KConfigGroup config = config();
config.writeEntry("login", m_login);
config.writeEntry("login", m_login);
</code>
</code>
Don't forget to
<code cppqt>
emit configNeedsSaving()
</code>
as it hints to the corona to persist your settings. This may not happen immediately but definitely at destruction time. It can also compress config changed events to minimize disk I/O hence battery drain. Never call <tt>sync()</tt> yourself!


Reading:
Reading settings:
<code cppqt>
<code cppqt>
KConfigGroup config = this->config();
KConfigGroup config = config();
m_login = config.readEntry("login", "");
m_login = config.readEntry("login", "");
</code>
</code>

Revision as of 21:41, 5 August 2010

Developing my first plasmoid

These are my personal findings in creating my first plasmoid. I plan on integrating these bits in the appropiate pages.

Learn by example

Existing plasmoids can be found in the following places:

Plasma widgets which you can use to build your plasmoid UI:

Other intesting plasma sources:

When using OpenSSL

You have to remove the FindOpenSSL cmake module supplied by KDE libs which is superseded now by the Cmake provided one. The KDE one does not link against the crypto lib.

Adding custom SVG content to your plasmoid

Normally, relative paths are used to point to items from the current desktop theme. When you have custom content that's not part of any theme yet, you can supply it with your plasmoid by installing it in the default desktop theme.

In Cmake language this translates to: install(FILES "analog_telemeter.svgz"

  DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/ )

I discovered this by looking at the cmake files of desktop themes. Desktop themes are found in KDE/kdeartwork/desktopthemes , except for oxygen, which can be found at KDE/kdebase/runtime/desktoptheme/oxygen. DATA_INSTALL_DIR translates for example to /usr/share/kde4/apps.

A desktop theme can support your plasmoid by supplying a file with the same name. If it is not found, there is a fallback to the default theme.

Adding configuration

The Applet class has a config() method which returns a KConfigGroup. There is a tutorial explaining the KConfig basics but here we'll explain the basics needed to persist your plasmoid settings.

The easiest thing to do, is create your gui using the gui designer. Add this form to your build file: kde4_add_ui_files(telemeter_SRCS telemeterConfig.ui)

Override the createConfigurationInterface(KConfigDialog *parent) method where you initialise your gui fields with the in-memory values (normally previously read from disk). You'll also want to map the accepted() signal from the KConfigDialog parent to some local slot which persists the new settings. In the end, add your form to the KConfigDialog: parent->addPage(uiConfig, i18n("General"), icon());

Writing settings: KConfigGroup config = config(); config.writeEntry("login", m_login); Don't forget to emit configNeedsSaving() as it hints to the corona to persist your settings. This may not happen immediately but definitely at destruction time. It can also compress config changed events to minimize disk I/O hence battery drain. Never call sync() yourself!

Reading settings: KConfigGroup config = config(); m_login = config.readEntry("login", "");

Enable your plasma config gui by setHasConfigurationInterface(true) during construction.

Taking security constraints into account

Excerpt from KDE/kdebase/workspace/plasma/design/security:

Each plasmoid's .desktop file must list what features the plasmoid requires, and be kept up to date with the code. X-Plasma-Requires-<feature> can be set to Required, Unused, or Optional. Example: X-Plasma-Requires-FileDialog=Required

Internationalization

You can read anything your heart desires to know about i18n in this section

Packaging and deploying

[02:09] <aseigo> look in kdesdk/scripts/createtarball .. it has everythign you need :)