Kontact plugins are [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1Part.html KParts] that get loaded at runtime. To integrate your KPart into kontact, you will need to have a .desktop file like this:

[http://kontact.kde.org/ Kontact] is a KDE [http://pim.kde.org/ PIM] (personal information management) framework that allows embedding several pim applications like kmail and korganizer as plugins into one window. Kontact plugins use [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1Part.html KParts] that get loaded at runtime. So, this is a good time to learn how to write a kPart. The "hello world" kontact plugin we will be writing here will look like this:

−

journalplugin.desktop newstickerplugin.desktop

+

−

kaddressbookplugin.desktop plannerplugin.desktop

+

[[Image:Kontact-helloplugin.png]]

−

karmplugin.desktop specialdatesplugin.desktop

+

−

kmailplugin.desktop summaryplugin.desktop

+

−

kmobiletools.desktop todoplugin.desktop

+

−

knodeplugin.desktop weatherplugin.desktop

+

−

</pre>

+

= Writing a KPart =

= Writing a KPart =

−

The following is what you do

+

We will write a "hello world"-KPart here. And you will learn how to hold it in a [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1MainWindow.html MainWindow]. A KPart also gives you the flexibility to be integrated into kontact or konqueror, but we will do this later. So, the "hello world"-KPart only consists of a label "hello world". We chose a label because it is the easiest viewable thing to create. It does not trigger any action. The following is what you do

* write a subclass mypart of KParts::Part

* write a subclass mypart of KParts::Part

** because [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1Part.html#399fea8c8f8d4ee321118d1ec85775db setWidget] is protected

** because [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1Part.html#399fea8c8f8d4ee321118d1ec85775db setWidget] is protected

** use a Widget in it and use setWidget to get your widget into the KPart

** use a Widget in it and use setWidget to get your widget into the KPart

* write a subclass mypartmainwindow of KParts::MainWindow

* write a subclass mypartmainwindow of KParts::MainWindow

−

** because [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1MainWindow.html#f96742c32da821dd7350deebc0a65382 createGUI] is protected

+

** because [http://api.kde.org/4.x-api/kdelibs-apidocs/kparts/html/classKParts_1_1MainWindow.html#f96742c32da821dd7350deebc0a65382 createGUI] is protected (and you may want createGUI later)

* write main.cpp

* write main.cpp

** use new mypart(mw) to get your part into your main window

** use new mypart(mw) to get your part into your main window

+

+

We will use 4 files to do this:

+

* CMakeLists.txt to ease building work

+

* mypart.h to declare our classes

+

* mypart.cpp to implement our classes

+

+

'''Create a directory ''hello'' in a fresh checkout of kdepim. In it, add the following files:'''

To integrate your KPart into kontact, you will need to create a subclass of [http://api.kde.org/4.x-api/kdepim-apidocs/kontact/html/classKontact_1_1Plugin.html Kontact::Plugin]

+

+

So, go to your checkout of kdepim, create a folder kdepim/kontact/plugins/hello. Continue there. We will make a shared object file kontact_helloplugin.so and a file hello_plugin.desktop. Those files will be the kontact plugin and tell kontact at runtime ''which'' kPart to load (hello_plugin.desktop) and ''how'' (kontact_helloplugin.so).

Somehow, your kontact plugin must be able to communicate with your application. For example, if you have a mail application, there will be a need for a button "new mail" in kontact. If this button is clicked, the plugin needs to call a function in the mail application (for corba fans: "needs to send a message to the application"). This is done via dbus. The kontact plugin gets an auto-generated dbus interface provided with the following addition to CMakeLists.txt:

If you want your plugin to be configurable from within kontact (this is needed e.g. to deselect it), have a look into svn how other made this, e.g. [http://websvn.kde.org/?view=rev&revision=815080 here]

+

+

= Beyond hello world =

+

+

== An application around your kpart ==

+

+

To write an application that only contains your kpart, see [[Development/Tutorials/Using_KParts]].

Kontact is a KDE PIM (personal information management) framework that allows embedding several pim applications like kmail and korganizer as plugins into one window. Kontact plugins use KParts that get loaded at runtime. So, this is a good time to learn how to write a kPart. The "hello world" kontact plugin we will be writing here will look like this:

We will write a "hello world"-KPart here. And you will learn how to hold it in a MainWindow. A KPart also gives you the flexibility to be integrated into kontact or konqueror, but we will do this later. So, the "hello world"-KPart only consists of a label "hello world". We chose a label because it is the easiest viewable thing to create. It does not trigger any action. The following is what you do

To integrate your KPart into kontact, you will need to create a subclass of Kontact::Plugin

So, go to your checkout of kdepim, create a folder kdepim/kontact/plugins/hello. Continue there. We will make a shared object file kontact_helloplugin.so and a file hello_plugin.desktop. Those files will be the kontact plugin and tell kontact at runtime which kPart to load (hello_plugin.desktop) and how (kontact_helloplugin.so).

Somehow, your kontact plugin must be able to communicate with your application. For example, if you have a mail application, there will be a need for a button "new mail" in kontact. If this button is clicked, the plugin needs to call a function in the mail application (for corba fans: "needs to send a message to the application"). This is done via dbus. The kontact plugin gets an auto-generated dbus interface provided with the following addition to CMakeLists.txt: