Development/Tutorials/Collaboration/HotNewStuff/Introduction: Difference between revisions
Neverendingo (talk | contribs) m (Text replace - "<code>" to "<syntaxhighlight lang="text">") |
Neverendingo (talk | contribs) m (Text replace - "</code>" to "</syntaxhighlight>") |
||
Line 41: | Line 41: | ||
return 0; | return 0; | ||
} | } | ||
</ | </syntaxhighlight> | ||
Line 55: | Line 55: | ||
TargetDir=wallpapers | TargetDir=wallpapers | ||
Uncompress=archive | Uncompress=archive | ||
</ | </syntaxhighlight> | ||
'''Uncompress''' can be one of: | '''Uncompress''' can be one of: | ||
Line 74: | Line 74: | ||
A new option has been added for KDE 4.5. | A new option has been added for KDE 4.5. | ||
By default KNewStuff will ask if the user wants to open ''downloaded HTML'' files with a browser instead of trying to install them. This is so since most of the time HTML means a broken link or a link to a page from which the item can be downloaded. If you want to accept html (because your app actually uses KNewStuff to get html files, you should explicitly allow this: | By default KNewStuff will ask if the user wants to open ''downloaded HTML'' files with a browser instead of trying to install them. This is so since most of the time HTML means a broken link or a link to a page from which the item can be downloaded. If you want to accept html (because your app actually uses KNewStuff to get html files, you should explicitly allow this: | ||
<syntaxhighlight lang="text">AcceptHtmlDownloads=true</ | <syntaxhighlight lang="text">AcceptHtmlDownloads=true</syntaxhighlight> | ||
'''ProvidersUrl''' | '''ProvidersUrl''' | ||
Line 80: | Line 80: | ||
Starting with KDE 4.5 this is optional, and if you just want to use what KDE provides as default (http://download.kde.org/ocs/providers.xml, currently openDesktop.org), leave this out. The advantage of not specifying this field is that users can add more providers using the attica kcm (kcmshell4 kcm_attica). | Starting with KDE 4.5 this is optional, and if you just want to use what KDE provides as default (http://download.kde.org/ocs/providers.xml, currently openDesktop.org), leave this out. The advantage of not specifying this field is that users can add more providers using the attica kcm (kcmshell4 kcm_attica). | ||
Only if you have to (because you need a different provider) use: | Only if you have to (because you need a different provider) use: | ||
<syntaxhighlight lang="text">ProvidersUrl=http://download.kde.org/ocs/providers.xml</ | <syntaxhighlight lang="text">ProvidersUrl=http://download.kde.org/ocs/providers.xml</syntaxhighlight> | ||
==== Linking in CMakeLists.txt ==== | ==== Linking in CMakeLists.txt ==== | ||
Line 89: | Line 89: | ||
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}) | ||
</ | </syntaxhighlight> | ||
==== Using a Widget instead of the Dialog ==== | ==== Using a Widget instead of the Dialog ==== | ||
If you don't like to use an external dialog, you can also use a widget instead. Just replace '''DownloadDialog''' with '''DownloadWidget''' and you're good to go. This is especially nice as additional page in existing config dialogs.<br> | If you don't like to use an external dialog, you can also use a widget instead. Just replace '''DownloadDialog''' with '''DownloadWidget''' and you're good to go. This is especially nice as additional page in existing config dialogs.<br> |
Revision as of 20:50, 29 June 2011
Development/Tutorials/Collaboration/HotNewStuff/Introduction
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
Tutorial Series | HotNewStuff |
Previous | Getting started with KDE development |
What's Next | Get Hot New Stuff 3 - Updates |
Further Reading | API Documentation |
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
- include <kapplication.h>
- include <kdebug.h>
- include <klocale.h>
- include <kcmdlineargs.h>
- include <kaboutdata.h>
- 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;
}
</syntaxhighlight>
The Configuration File (.knsrc)
For this to work, a file that sets up KNewStuff khotnewstuff_example.knsrc is needed.
If you don't pass a file name to the dialog, the name of the file is taken from the about data (application name). If you want to use different dialogs in one application, just create multiple .knsrc files, such as krita_brushes.knsrc and krita_palettes.knsrc for example.
The file has to be in kde/share/config/khotnewstuff_example.knsrc.
[KNewStuff3]
Categories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200
TargetDir=wallpapers
Uncompress=archive
Uncompress can be one of:
- 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.
- XdgTargetDir: a directory in the $XDG_DATA_HOME directory such as .local/share/wallpapers (since KDE 4.5)
Downloaded HTML:
A new option has been added for KDE 4.5.
By default KNewStuff will ask if the user wants to open downloaded HTML files with a browser instead of trying to install them. This is so since most of the time HTML means a broken link or a link to a page from which the item can be downloaded. If you want to accept html (because your app actually uses KNewStuff to get html files, you should explicitly allow this:
AcceptHtmlDownloads=true
ProvidersUrl
The data has to come from somewhere, right? Up until KDE SC 4.5 you must specify ProvidersUrl with an url to the providers.xml file.
Starting with KDE 4.5 this is optional, and if you just want to use what KDE provides as default (http://download.kde.org/ocs/providers.xml, currently openDesktop.org), leave this out. The advantage of not specifying this field is that users can add more providers using the attica kcm (kcmshell4 kcm_attica).
Only if you have to (because you need a different provider) use:
ProvidersUrl=http://download.kde.org/ocs/providers.xml
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})
Using a Widget instead of the Dialog
If you don't like to use an external dialog, you can also use a widget instead. Just replace DownloadDialog with DownloadWidget and you're good to go. This is especially nice as additional page in existing config dialogs.