KDevelop API Documentation

How to add application templates to the application wizard part

Project templates provide the developer with a basic application framework. This is necessary for rapid application development (RAD) and makes it even possible for an inexperienced 3rd party developer to create standard conforming applications like kedit as well as plugins for example for kdevelop or noatun.

I. Example: How To Create a Simple KDE Application Template "KHello"
II. Registration/Installation Of The Application Template
III. How To Add The Template To KDevelop CVS HEAD


I. Example: How To Create a Simple KDE Application Template "KHello"

You can find this template in $KDEDIR/share/apps/kdevappwizard/template-khello.

I.1. Step 1: Basic Skeleton

Create a directory template-khello with the files
  • template-khello/app.cpp
  • template-khello/app.h
  • template-khello/app.desktop
  • template-khello/app.kdevelop
  • template-khello/appui.rc
  • template-khello/khello
  • template-khello/main.cpp
  • template-khello/preview.png
  • template-khello/script
  • template-khello/src-Makefile.am
  • template-khello/subdirs
Note:
The directory name must begin with "template-".

I.2. Step 2: The Files in Detail

Have a look into the files! There are some variables which the application wizard will replace:
  • $AUTHOR$ ...... by the author
  • $EMAIL$ ....... by the e-mail address
  • $VERSION$ ..... by the version
  • $APPNAME$ ..... by the project name (KHello)
  • $APPNAMELC$ ... by the project name in lowercase (khello)
  • $APPNAMEUC$ ... by the project name in uppercase (KHELLO)
  • $LICENSE$ ..... by the license (GPL, BSD, QPL, LGPL, ...)
  • $LICENSEFILE$ . by the licensefile
  • $YEAR$ ........ by the year
All this can be found in $KDEDIR/share/apps/kdevappwizard/template-common/kdevelop.pm.

I.2.1. The Source Files

The files template-khello/app.cpp, template-khello/app.h and template-khello/main.cpp contain the source code that should not be too special so that the user can implement his own ideas.
(There may be variables included - see Step 2: The Files in Detail).

I.2.2. The File template-khello/khello

It may look like this:

The application wizard looks into this file to get

Further information could be (not required):
Attention:
The file template-khello/khello must have the same name as the right half of the directory! If the directory is template-foobar the file must be template-foobar/foobar.
See also:
AppWizardPart for more information.

I.2.3. Some Additional Files

The file

I.2.4. The File template-khello/src-Makefile.am

This file will be copied to the $PROJECTDIR/src/.
# set the include path for X, qt and KDE
INCLUDES = $(all_includes)

# these are the headers for your project
noinst_HEADERS = %{APPNAMELC}.h

# let automoc handle all of the meta source files (moc)
METASOURCES = AUTO

messages: rc.cpp
	$(XGETTEXT) *.cpp -o $(podir)/%{APPNAMELC}.pot

KDE_ICON = %{APPNAMELC}

#########################################################################
# APPLICATION SECTION
#########################################################################
# this is the program that gets installed.  it's name is used for all
# of the other Makefile.am variables
bin_PROGRAMS = %{APPNAMELC}

# the application source, library search path, and link libraries
%{APPNAMELC}_SOURCES = main.cpp %{APPNAMELC}.cpp
%{APPNAMELC}_LDFLAGS = $(KDE_RPATH) $(all_libraries)
%{APPNAMELC}_LDADD = $(LIB_KDEUI)

# this is where the desktop file will go 
shelldesktopdir   = $(kde_appsdir)/Utilities
shelldesktop_DATA = %{APPNAMELC}.desktop

# this is where the shell's XML-GUI resource file goes
shellrcdir   = $(kde_datadir)/%{APPNAMELC}
shellrc_DATA = %{APPNAMELC}ui.rc

I.2.5. The File template-khello/script

The following script is used to install the template and replaces all variables by the corresponding value. The result is a hopefully working kdevelop project!

Note:
There are several application templates which use some identical files - that's why some files are taken from the "template-common"-directory.

II. Registration/Installation Of The Application Template

The easiest way to install your template is to provide an "install.sh" shell script.
Example:
#!/bin/sh

kde_prefix=`kde-config --prefix`
if  [ `id -u` = 0 ]; then
  # we are root so install the template into the global kde directory
  kde_dir=`kde-config --prefix`
else
  # we are a user so install it into $HOME/.kde/share/apps/kdevappwizard directory
  kde_dir=`kde-config --localprefix`
  echo "Note: It would be better to install as root. Press CTRL+C to abort"
fi

# use usual path or another one?
echo "Install dir [${kde_dir}/share/apps/kdevappwizard]:"
read newdir

if [ "$newdir"a = a ]; then newdir="${kde_dir}/share/apps/kdevappwizard/"; fi

# make sure the directories exist
if [ ! -e "${newdir}/template-khello" ]; then mkdir -p "${newdir}/template-khello" ; fi;
if [ ! -e "${newdir}/templates" ]; then mkdir -p "${newdir}/templates" ; fi;
if [ ! -e "${newdir}" ]; then mkdir -p "$newdir" ; fi;
if [ ! -e "${newdir}/template-common" ]; then ln -s "${kde_prefix}/share/apps/kdevappwizard/template-common" "${newdir}/template-common" ; fi;

# install now
cp -R --target-directory "$newdir" template-khello
# the file template-khello/khello must go to the "templates" directory that
# kdevelop knows that it exists
mv "$newdir/template-khello/khello" "$newdir/templates/"
echo "done"

Attention:
Please test your template whether it installs and behaves correctly! Test, test and test again! ;)

III. How To Add The Template To KDevelop CVS HEAD

This section is for kdevelop developers only. Most probably you don't have to read this!.
Move the directory "template-khello" to kdevelop/languages/cpp/app_templates/ and then add the following files in kdevelop/languages/cpp/app_templates/template-khello/ (in this example the language is c++ if you use other language replace cpp with the language name): Finally add "template-khello" to "SUBDIRS = " in kdevelop/languages/cpp/app_templates/Makefile.am.
Attention:
Please test your template whether it installs and behaves correctly! Test, test and test again! It works? Well - now talk to the kdevelop guys so that they know what's going on and probably you may commit. ;)
That's all! :)
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:50:04 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003