Difference between revisions of "Development/Tutorials/K Hot New Stuff2"

Jump to: navigation, search
(add Uncompress details)
(formatting update)
Line 7: Line 7:
 
There are a many good examples for how to use khotnewstuff2 in the KDE-Edu module.  Look at their source code for examples if needed, but it's basically a 2-part process to get download into your app.
 
There are a many good examples for how to use khotnewstuff2 in the KDE-Edu module.  Look at their source code for examples if needed, but it's basically a 2-part process to get download into your app.
  
:1. First write a .knsrc file. A .knsrc file is just a file telling the library which options to use for a given application.  It also lists where providers can be found, where uploads should be sent, etc. Anyway, the format of the file is an ini file with one group:
+
=== 1. First write a .knsrc file. ===
 +
A .knsrc file is just a file telling the library which options to use for a given application.  It also lists where providers can be found, where uploads should be sent, etc. Anyway, the format of the file is an ini file with one group:
 
<code>
 
<code>
 
[KNewStuff2]
 
[KNewStuff2]
Line 15: Line 16:
 
</code>
 
</code>
  
:'''NOTE''': InstallationCommand is optional, and if included will be invoked after each item is downloaded.
+
::'''NOTE''': InstallationCommand is optional, and if included will be invoked after each item is downloaded.
:'''NOTE''': Uncompress is optional, and if included will try to uncompress all downloads into the target folder according to the mime-type of the file.
+
::'''NOTE''': Uncompress is optional, and if included will try to uncompress all downloads into the target folder according to the mime-type of the file.
* Uncompress possible values as of r794016 are
+
:* Uncompress possible values as of r794016 are
* "always" - always attempt to uncompress (old values of "true" are seen as "always"
+
:* "always" - always attempt to uncompress (old values of "true" are seen as "always"
* "archive" - uncompress if it's an archive but copy otherwise
+
:* "archive" - uncompress if it's an archive but copy otherwise
* "never" - (default) never attempt to uncompress
+
:* "never" - (default) never attempt to uncompress
  
  
One of the following is required to tell where downloads should go:
+
:One of the following is required to tell where downloads should go:
 
<code>
 
<code>
 
TargetDir=
 
TargetDir=
Line 31: Line 32:
 
</code>
 
</code>
  
* TargetDir installs to KStandardDirs::locateLocal("data") + TargetDir + "/"
+
:* TargetDir installs to KStandardDirs::locateLocal("data") + TargetDir + "/"
* StandardResource installs to KStandardDirs::locateLocal(StandardResource)
+
:* StandardResource installs to KStandardDirs::locateLocal(StandardResource)
* InstallPath installs to QDir::home().path() + "/" + InstallPath
+
:* InstallPath installs to QDir::home().path() + "/" + InstallPath
* AbsoluteInstallPath installs to AbsoluteInstallPath + "/"
+
:* AbsoluteInstallPath installs to AbsoluteInstallPath + "/"
:'''NOTE''': AbsoluteInstallPath is not portable (/boot/grub is probably not a valid path except on linux), so should not be used in anything that is meant to run on all our platforms.
+
::'''NOTE''': AbsoluteInstallPath is not portable (/boot/grub is probably not a valid path except on linux), so should not be used in anything that is meant to run on all our platforms.
  
And the following values are currently read, though not used yet:
+
:And the following values are currently read, though not used yet:
 
<code>
 
<code>
 
CustomName=
 
CustomName=
Line 45: Line 46:
 
Scope=
 
Scope=
 
</code>
 
</code>
install the file using CMake install macro like this
+
:install the file using CMake install macro like this
 
<code>
 
<code>
 
install( FILES yourdata.knsrc  DESTINATION  ${CONFIG_INSTALL_DIR} )
 
install( FILES yourdata.knsrc  DESTINATION  ${CONFIG_INSTALL_DIR} )
 
</code>
 
</code>
at this point, you can test your knsrc file with khotnewstuff4 like so:
+
:at this point, you can test your knsrc file with khotnewstuff4 like so:
 
<code>
 
<code>
 
khotnewstuff4 yourdata.knsrc
 
khotnewstuff4 yourdata.knsrc
 
</code>
 
</code>
it should show you a download dialog of the data available on your provider(s).
+
:it should show you a download dialog of the data available on your provider(s).
  
:2. Make your application launch the KNS ui with your knsrc file.
+
=== 2. Make your application launch the KNS ui with your knsrc file. ===

Revision as of 18:43, 6 April 2008

The page that used to be here was all KDE3 specific information, so I figured it was about time to start a new one.

Contents

Terminology

First some basic terminology just to get us all on the same page. KHotNewStuff2 is the new library that implements the GHNS freedesktop.org specification for downloading and uploading user data. It will also support DXS (Desktop Exchange Service)

Use it in your application

There are a many good examples for how to use khotnewstuff2 in the KDE-Edu module. Look at their source code for examples if needed, but it's basically a 2-part process to get download into your app.

1. First write a .knsrc file.

A .knsrc file is just a file telling the library which options to use for a given application. It also lists where providers can be found, where uploads should be sent, etc. Anyway, the format of the file is an ini file with one group: [KNewStuff2] ProvidersUrl= InstallationCommand= Uncompress=

NOTE: InstallationCommand is optional, and if included will be invoked after each item is downloaded.
NOTE: Uncompress is optional, and if included will try to uncompress all downloads into the target folder according to the mime-type of the file.
  • Uncompress possible values as of r794016 are
  • "always" - always attempt to uncompress (old values of "true" are seen as "always"
  • "archive" - uncompress if it's an archive but copy otherwise
  • "never" - (default) never attempt to uncompress


One of the following is required to tell where downloads should go:

TargetDir= InstallPath= StandardResource= AbsoluteInstallPath=

  • TargetDir installs to KStandardDirs::locateLocal("data") + TargetDir + "/"
  • StandardResource installs to KStandardDirs::locateLocal(StandardResource)
  • InstallPath installs to QDir::home().path() + "/" + InstallPath
  • AbsoluteInstallPath installs to AbsoluteInstallPath + "/"
NOTE: AbsoluteInstallPath is not portable (/boot/grub is probably not a valid path except on linux), so should not be used in anything that is meant to run on all our platforms.
And the following values are currently read, though not used yet:

CustomName= CachePolicy= ChecksumPolicy= SignaturePolicy= Scope=

install the file using CMake install macro like this

install( FILES yourdata.knsrc DESTINATION ${CONFIG_INSTALL_DIR} )

at this point, you can test your knsrc file with khotnewstuff4 like so:

khotnewstuff4 yourdata.knsrc

it should show you a download dialog of the data available on your provider(s).

2. Make your application launch the KNS ui with your knsrc file.


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