Difference between revisions of "Development/Tutorials/Collaboration/HotNewStuff/Introduction"

Jump to: navigation, search
(The Code)
Line 41: Line 41:
 
</code>  
 
</code>  
  
 +
 +
==== The Configuration File (.knsrc)  ====
 
For this to work, a file that sets up KNewStuff ''khotnewstuff_example.knsrc'' is needed. The file has to be in ''kde/share/config/khotnewstuff_example.knsrc''. (The name of the file is taken from the about data).  
 
For this to work, a file that sets up KNewStuff ''khotnewstuff_example.knsrc'' is needed. The file has to be in ''kde/share/config/khotnewstuff_example.knsrc''. (The name of the file is taken from the about data).  
  
Line 48: Line 50:
 
Categories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200
 
Categories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200
 
TargetDir=wallpapers
 
TargetDir=wallpapers
 +
Uncompress=archive
 
</code>  
 
</code>  
  
 +
Uncompress can be one of: always, never or archive:
 +
* always: assume all downloaded files are archives and need to be extracted
 +
* never: never try to extract the file
 +
* archive: if the file is an archive, uncompress it, otherwise just pass it on
 +
 +
You have different options to set the target install directory:
 +
 +
* StandardResource: standard ressouce dir, such as .kde/share/wallpapers. This is what KStandardDirs::locateLocal(name) will return.
 +
* TargetDir: a directory in the share/apps section, such as .kde/share/apps/wallpapers. This is what KStandardDirs::locateLocal("data", name) will return.
 +
 +
==== Linking in CMakeLists.txt ====
 
To link against KNS3, just link against ''${KDE4_KNEWSTUFF3_LIBS}''. Example:
 
To link against KNS3, just link against ''${KDE4_KNEWSTUFF3_LIBS}''. Example:
  
 
<code>
 
<code>
 
target_link_libraries(ktexteditor_codesnippets_core
 
target_link_libraries(ktexteditor_codesnippets_core
${KDE4_KDEUI_LIBS} ${KDE4_KTEXTEDITOR_LIBS} ${KDE4_KNEWSTUFF3_LIBS})
+
${KDE4_KDEUI_LIBS} ${KDE4_KTEXTEDITOR_LIBS} '''${KDE4_KNEWSTUFF3_LIBS}''')
 
</code>
 
</code>

Revision as of 17:42, 10 January 2010


Contents

Development/Tutorials/Collaboration/HotNewStuff/Introduction


Get Hot New Stuff 3 Introduction
Tutorial Series   HotNewStuff
Previous   Getting started with KDE development
What's Next   n/a
Further Reading   n/a

Overview

Here is a small example of an application that asks openDesktop.org for wallpapers. It lets the user install them into the system wallpaper directory.

The Code

The example consists of just one c++ source file. //khotnewstuff.cpp

  1. include <kapplication.h>
  2. include <kdebug.h>
  3. include <klocale.h>
  4. include <kcmdlineargs.h>
  5. include <kaboutdata.h>
  1. include <knewstuff3/downloaddialog.h>

int main(int argc, char **argv) {

   KAboutData about("khotnewstuff_example", 0, ki18n("KHotNewStuff"), "0.4");
   about.setProgramIconName("get-hot-new-stuff");
   
   KApplication i;
   KNS3::DownloadDialog dialog(args->arg(0));
   dialog.exec();
   foreach (const KNS3::Entry& e, dialog.changedEntries()) {
       kDebug() << "Changed Entry: " << e.name();
   }

   return 0;

}


The Configuration File (.knsrc)

For this to work, a file that sets up KNewStuff khotnewstuff_example.knsrc is needed. The file has to be in kde/share/config/khotnewstuff_example.knsrc. (The name of the file is taken from the about data).

[KNewStuff3] ProvidersUrl=http://download.kde.org/ocs/providers.xml Categories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200 TargetDir=wallpapers Uncompress=archive

Uncompress can be one of: always, never or archive:

  • always: assume all downloaded files are archives and need to be extracted
  • never: never try to extract the file
  • archive: if the file is an archive, uncompress it, otherwise just pass it on

You have different options to set the target install directory:

  • StandardResource: standard ressouce dir, such as .kde/share/wallpapers. This is what KStandardDirs::locateLocal(name) will return.
  • TargetDir: a directory in the share/apps section, such as .kde/share/apps/wallpapers. This is what KStandardDirs::locateLocal("data", name) will return.

Linking in CMakeLists.txt

To link against KNS3, just link against ${KDE4_KNEWSTUFF3_LIBS}. Example:

target_link_libraries(ktexteditor_codesnippets_core ${KDE4_KDEUI_LIBS} ${KDE4_KTEXTEDITOR_LIBS} ${KDE4_KNEWSTUFF3_LIBS})


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal