m (→Kontact integration) |
m (→Kontact integration) |
||
Line 140: | Line 140: | ||
$ find /home/kde-devel/kde/lib/ -iname "karmpart*" | $ find /home/kde-devel/kde/lib/ -iname "karmpart*" | ||
/home/kde-devel/kde/lib/kde4/karmpart.so | /home/kde-devel/kde/lib/kde4/karmpart.so | ||
− | So, write | + | So, write the following file. |
== hello_part.desktop == | == hello_part.desktop == |
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 are KParts that get loaded at runtime. So, this is a good time to learn how to write a kPart... Read on.
We will write a "hello world"-KPart here. And we will write a MainWindow to hold this KPart. 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 pushbutton because it is the easiest viewable thing to create. It does not trigger an action on your click. The following is what you do
We will use 4 files to do this:
Create a directory hello in a fresh checkout of kdepim. In it, add the following files:
project(hello) find_package (KDE4 REQUIRED) INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} . ) include_directories( ${KDE4_INCLUDE_DIR}/kcal ${CMAKE_SOURCE_DIR}/kresources/remote ) set(hello_shared_SRCS hello_part.cpp ) set(hellopart_PART_SRCS hello_part.cpp) kde4_add_plugin(hellopart ${hellopart_PART_SRCS}) target_link_libraries(hellopart ${KDE4_KPARTS_LIBS} ${KDE4_KCAL_LIBS} ${KDE4_KIO_LIBS} kdepim kcal_resourceremote) if(X11_Xscreensaver_LIB) target_link_libraries(hellopart ${X11_Xscreensaver_LIB} ) endif(X11_Xscreensaver_LIB) install(TARGETS hellopart DESTINATION ${PLUGIN_INSTALL_DIR}) install( FILES hello_part.desktop DESTINATION ${SERVICES_INSTALL_DIR})
/**
* This is a "Part". It that does all the real work in a KPart * application. */
class helloPart : public KParts::ReadWritePart {
Q_OBJECT
private: QLabel *mMainWidget;
public:
helloPart(QWidget *parentWidget, QObject *parent, const QVariantList&);
QLabel* MainWidget() { return mMainWidget; };
virtual ~helloPart(); bool openFile(){}; bool saveFile(){};
};
K_PLUGIN_FACTORY(helloPartFactory, registerPlugin<helloPart>();) // produce a factory K_EXPORT_PLUGIN(helloPartFactory("hello","hello") )
helloPart::helloPart( QWidget *parentWidget, QObject *parent, const QVariantList& )
: KParts::ReadWritePart(parent)
{
KGlobal::locale()->insertCatalog("hello"); // we need an instance setComponentData( helloPartFactory::componentData() );
mMainWidget = new QLabel(); mMainWidget->setText("hello"); setWidget( mMainWidget );
}
helloPart::~helloPart() { }
To compile and link the code above, use
cmake . && make
Now you can find your kpart in the lib folder:
tweedleburg:~/svn/kdepim/hello # ll lib total 468 -rwxr-xr-x 1 root root 471554 May 28 22:42 hellopart.so
To integrate your KPart into kontact, you will need to have a .desktop file. This can be e.g. here:
$ ls /home/kde-devel/kde/share/kde4/services/kontact/ akregatorplugin.desktop knotesplugin.desktop akregatorplugin3.2.desktop korganizerplugin.desktop journalplugin.desktop newstickerplugin.desktop kaddressbookplugin.desktop plannerplugin.desktop karmplugin.desktop specialdatesplugin.desktop kmailplugin.desktop summaryplugin.desktop kmobiletools.desktop todoplugin.desktop knodeplugin.desktop weatherplugin.desktop
You will also need your plugin, maybe here:
$ find /home/kde-devel/kde/lib/ -iname "karmpart*" /home/kde-devel/kde/lib/kde4/karmpart.so
So, write the following file.
[Desktop Entry] Name=Friendly Component MimeType=text/calendar; X-KDE-ServiceTypes=KParts/ReadOnlyPart,KParts/ReadWritePart X-KDE-Library=hellopart Type=Service
You will also need to make your KPart a subclass of Kontact::Plugin