Home · API Reference · Modules
Plugin Tutorial

Introduction

This page is a short tutorial about creating your own input method plugin. MeeGo Touch Input Method provides a framework which developers can extend the functionality of the input method by providing a new input method user interface. The new input method is implemented as a plugin.

This page shows some excerpts from MeeGo Keyboard source code.

Skeleton

There are two important parts in the plugin making: the user interface of the input method, which is the part that user interact with while inputting text; and the settings, which is the part that enables user to set preferences on the input method.

User interface

The UI is loaded and controlled by a MAbstractInputMethod class.

class MKeyboardHost: public MAbstractInputMethod
{
Q_OBJECT
public:
MKeyboardHost(MAbstractInputMethodHost *host, QWidget *mainWindow);
virtual ~MKeyboardHost();
.....

The MAbstractInputMethod itself needs to be loaded by the plugin class, which is a MInputMethodPlugin class. For the plugin system to work, class must declare proper interface using Q_INTERFACES (in the header file) and export the plugin with Q_EXPORT_PLUGIN2 (in the .cpp file):

// The header file:
class MKeyboardPlugin : public QObject, public MInputMethodPlugin
{
Q_OBJECT
Q_INTERFACES(MInputMethodPlugin)
public:
MKeyboardPlugin();
virtual ~MKeyboardPlugin();
.....
// At the end of the .cpp file:
Q_EXPORT_PLUGIN2(meego-keyboard, MKeyboardPlugin)

The UI class is created in the createInputMethod method:

MKeyboardPlugin::createInputMethod(MAbstractInputMethodHost *host, QWidget *mainWindow)
{
MAbstractInputMethod *inputMethod = new MKeyboardHost(host, mainWindow);
return inputMethod;
}

The plugin is given a main window that should be used as a parent widget for plugin visualization. Plugin is then free to create a QWidget or QGraphicsView or similar.

The interaction between the UI and the application is done by employing functions provided by MAbstractInputMethod and MAbstractInputMethodHost.

Settings

Settings is basically a QGraphicsWidget which holds items to provide user to set some preferences or behaviour of the input method. It is displayed in the control panel of the system.

The settings is created by subclassing MAbstractInputMethodSettings.

class MKeyboardSettings: public QObject, public MAbstractInputMethodSettings
{
Q_OBJECT
public:
MKeyboardSettings();
.....

The actual widget shown is created in MKeyboardSettings::createContentWidget:

QGraphicsWidget *MKeyboardSettings::createContentWidget(QGraphicsWidget *parent)
{
// the pointer of returned QGraphicsWidget is owned by the caller,
// so we just always create a new containerWidget.
return new MKeyboardSettingsWidget(this, parent);
}

Compilation

To use the framework you need to add plugin and meegoimframework to CONFIG variable in your project file.

CONFIG += plugin meegoimframework

Installation

The plugin is installed to /usr/lib/meego-im-plugins directory. Depending on the user interface type, the plugin can be activated programmaticaly by setting the handler GConf key to the name of the plugin. The GConf parent key is /meegotouch/inputmethods/plugins/handler.

During runtime the plugin can be selected from control panel on the system.


Copyright © 2011 Nokia Corporation
Maliit