Wednesday, May 12, 2010

Plasma Applet Development Walk-through

 

Episode 2: Qt Creator Steps In

Preface

This article opens (yes, with episode 2) a series of mini-howtos describing various actions related to the development of custom plasma (KDE4 desktop) components (applets/data engines) in C++. Some of the information presented could be found elsewhere; other bits are almost trivial. If you are a programmer new to KDE4 development as I am, these articles may be of some help. The main idea is to show how purely technical stuff could be accomplished in some reasonable way without heavy thinking and head-scratching. Developer should focus on the stuff that is essential for his/her project: architecture, code structure, usability, documentation etc.

I am currently using Ubuntu Lucid (10.04) distribution with KDE 4.4 and Qt Creator 1.3.1; I believe my description should need only minor modifications if any at all for other distros.

Choosing the destination

We have our plasmoid project initialized and populated with .desktop, .cpp, and CmakeLists.txt files. Now is the time for compile-run-modify interactive development cycle. But before setting up development tools, we should determine where the applet should be installed. There are two principal choices:

· system-based or

· home-based installation.

Each type of installation could have either the default or customized destination specified. For development and testing purposes system-based installation is not very convenient, because we must use sudo (or even kdesudo) each time we rebuild the project. Custom home-based installation may have some advantages over default home-based installation, but they are very subtle. We shall stick with simple home-based installation of the plasma software we compile.

To build our plasmoid and install it in the default home directory based destination we may issue following commands from the shell:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=~/.kde ..
make
make install


Qt Creator

But IDE-based development is much more fun. Qt creator is my choice for KDE4 development. It's interface is mostly intuitive, functional, fast and pleasant to the eye. It also features a good support for cmake projects


To open a CMake project, select Open from the File menu and select the CmakeLists.txt file from your Cmake project. A wizard guides you with the rest of the process.









Qt Creator: Open File or Project ...

Like this








Open File


On the first page the wizard suggests a name for build directory. During development and testing phase we will use Debug build type. Change the suggested name to qtcreator-debug-build and hit Next >:









Qt Creator: CMake Wizard (1 of 2)


Here we specify build type (Debug) and the default home-based installation destination (~/.kde) for our project. Debug build type allows use of kDebug output stream, among other features. Look here for an official description of Cmake build types.









Qt Creator: CMake Wizard (2 of 2)

Press Run Cmake button, then dismiss the dialog with Finish button and the qt creator project is ready to work with!


Fine-tuning build and run steps

Click on the Projects Icon in Mode Selector Pane or press Ctrl+4 to switch the projects mode. We will modify build (I) and run (II) settings to have our plasmoid installed automagically from the IDE.









Qt Creator: Projects Mode

We may optionally add an uninstallation step to the clean procedure (III) as well.


Build modification is trivial: we just supply install argument for make command:


IModify build step


Run settings are more complex. We would like to test our plasmoid behaviour with plasmoidviewer utility. The illustration below is self-descriptive. Important: уou should change the text of Arguments field (marked as 6 in the picture) to contain the name of your applet (gioco1 in the example).


IIRun settings for plasmoid


Working directory in this example is not relevant. We may leave it as is. By the way, $BUILDDIR is the only macro accepted in projects mode input fields for Qt Creator 1.3.1 – I had to peruse the source of the software to figure this out.


Optional uninstall step

Occasionally you may need to remove your plasmoid and all related files from the installation destination. The command make uninstall invoked from the build directory at the shell prompt would also do the trick.  Alternatively you may add that command as a clean step for the project.


The picture below is self-descriptive


IIIAdd make uninstall as a clean step


Development

Now the project is ready for the development cycle. Press Ctrl+B to (re)compile and (re)install the plasmoid. Press Ctrl+R to test it with plasmoidviewer. And choose Build → Clean Project from the Qt Creator menu to uninstall the plasmoid (if you had enabled the uninstall step) and/or delete all the binaries from the build directory.


Now use the IDE to edit the source, recompile, reinstall and test your applet as it suits your development style. Happy hacking!


To be continued ...


(from both ends :-)

1 comment:

  1. 888 Casino Review India 2021 - jtmhub.com
    888 Casino is a reliable 전라북도 출장샵 online 남원 출장안마 gambling website, available to Indian players. 제주도 출장안마 We 삼척 출장샵 have also provided a list of 영천 출장마사지 various payment methods available.

    ReplyDelete