Make KDE applets with KDevelop
17 november 2010 Plaats een reactie
In previous tutorial I gave a short introduction how you create an KDE applet. Of course I explained how you do it manually. Because you develop Java programs with Eclipse or Netbeans, it’s obviously to have some sort of IDE to create KDE applets. I suggest you use KDevelop, it’s a powerfull IDE for C++ coding. Okej let’s start creating an small KDE applet.
You have to install two things to start with KDevelop:
- G++ (compiler)
With a package manager this job should be easy.
Open KDevelop. In the menu “Project” select “New from template”. Then you get a window like this.
Choose “Plasma Applate Template” from the category “C++ | KDE”. Give it a name and a location. Press “Next”. If you want a CVS system managing your files, you should select one. Press “Finish”.
It will ask where the “cmake” executable is located, normally it’s in /usr/bin/cmake. When you build your code, it needs a build directory where it can dump all make files, the executable and some log files. The other two fields are optional, so I leave them blank.
Under the “Projects” window you find your project. Is the “Projects” window not visible, activate it by clicking on the “Window” menu and then select “Tool views | Projects”. Under the project you find a lot of files like README, Messages.sh, … There are four important files for you KDE widget:
- CMakeLists.txt: the make file to make the binairy
- plasma-applet-tutorial.desktop: the widget desktop file
- tutorial.cpp: source code
- tutorial.h: header file
If you open “tutorial.cpp” you find some C++ code. This is you main file for your widget. You can see this because it extends from the class “Plasma::Applet”. In the CMakeLists.txt you find what files you need to compile, what libraries the code depends on, what it requires. If you get an build error and your code is fine, it’s because somethings wrong in this file. The desktop file is needed to find you widget and to put the widget on your desktop. It contains various information of the widget (name, author, category, …).
Build and install
Now we’re going to build the project. If you press F8 or right click on the project and choose “Build”, it starts building. It create some files in the “build” sub-directory of your project. When you don’t have red text in your build console and only green (you get a warning about an unused parameter option, ignore it), your build is successful.
In KDevelop you can “Install” the project by right click on the project and choose “Install”. In my case it fails because you need to be root. So the installation part should be done manually. Just execute the follow shell lines:
sudo make install
Run your applet
Keep your console open and type the follow command:
plasmoidviewer -c desktop tutorial
Congratz, you created your first KDE widget trough KDevelop.