| Line 6: | Line 6: | ||
pre=[[Getting_Started|Getting started with KDE development]]| | pre=[[Getting_Started|Getting started with KDE development]]| | ||
next=[[Development/Tutorials/Collaboration/HotNewStuff/Updates|Get Hot New Stuff 3 - Updates]]| | next=[[Development/Tutorials/Collaboration/HotNewStuff/Updates|Get Hot New Stuff 3 - Updates]]| | ||
| + | reading=[http://api.kde.org/4.x-api/kdelibs-apidocs/knewstuff/html/classKNS3_1_1DownloadDialog.html API Documentation] | ||
}} | }} | ||
Contents |
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 |
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 example consists of just one c++ source file.
//khotnewstuff.cpp
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;
}
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:
You have different options to set the target install directory:
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
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})
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.