Neverendingo (Talk | contribs) m (Text replace - "<code>" to "<syntaxhighlight lang="text">") |
Neverendingo (Talk | contribs) m (Text replace - "</code>" to "</syntaxhighlight>") |
||
| Line 16: | Line 16: | ||
InstallationCommand= | InstallationCommand= | ||
Uncompress= | Uncompress= | ||
| − | </ | + | </syntaxhighlight> |
::'''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. | ||
| Line 32: | Line 32: | ||
StandardResource= | StandardResource= | ||
AbsoluteInstallPath= | AbsoluteInstallPath= | ||
| − | </ | + | </syntaxhighlight> |
:* TargetDir installs to KStandardDirs::locateLocal("data") + TargetDir + "/" | :* TargetDir installs to KStandardDirs::locateLocal("data") + TargetDir + "/" | ||
| Line 47: | Line 47: | ||
SignaturePolicy= | SignaturePolicy= | ||
Scope= | Scope= | ||
| − | </ | + | </syntaxhighlight> |
:install the file using CMake install macro like this | :install the file using CMake install macro like this | ||
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
install( FILES yourdata.knsrc DESTINATION ${CONFIG_INSTALL_DIR} ) | install( FILES yourdata.knsrc DESTINATION ${CONFIG_INSTALL_DIR} ) | ||
| − | </ | + | </syntaxhighlight> |
: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: | ||
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
khotnewstuff4 yourdata.knsrc | khotnewstuff4 yourdata.knsrc | ||
| − | </ | + | </syntaxhighlight> |
: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). | ||
| Line 65: | Line 65: | ||
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
static KNS::Entry::List download(); | static KNS::Entry::List download(); | ||
| − | </ | + | </syntaxhighlight> |
:if you use this method, your knsrc file must have the same name as your KGlobal::activeComponent().componentName(), it will create an Engine object, initialize it with the knsrc file, and call downloadDialogModal, then before returning it will copy the list of modified (installed, uninstalled, etc.) entries. Use is like this: | :if you use this method, your knsrc file must have the same name as your KGlobal::activeComponent().componentName(), it will create an Engine object, initialize it with the knsrc file, and call downloadDialogModal, then before returning it will copy the list of modified (installed, uninstalled, etc.) entries. Use is like this: | ||
| Line 80: | Line 80: | ||
} | } | ||
qDeleteAll(entries); | qDeleteAll(entries); | ||
| − | </ | + | </syntaxhighlight> |
:Taken from kdeedu/parley/src/parleydocument.cpp | :Taken from kdeedu/parley/src/parleydocument.cpp | ||
| Line 100: | Line 100: | ||
} | } | ||
} | } | ||
| − | </ | + | </syntaxhighlight> |
:Taken from plasma/containments/desktop/backgrounddialog.cpp | :Taken from plasma/containments/desktop/backgrounddialog.cpp | ||
This tutorial informs about how to use Get Hot New Stuff collaborative data sharing features in your KDE application. Complementary to this tutorial, there is a porting guide for KDE 3 developers and another tutorial in SVN. The KNS2-enabled application list is also a good reference to find similar applications.
Contents |
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)
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.
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=
TargetDir= InstallPath= StandardResource= AbsoluteInstallPath=
CustomName= CachePolicy= ChecksumPolicy= SignaturePolicy= Scope=
install( FILES yourdata.knsrc DESTINATION ${CONFIG_INSTALL_DIR} )khotnewstuff4 yourdata.knsrc
static KNS::Entry::List download();
KNS::Entry::List entries = KNS::Engine::download();
// list of changed entries
foreach(KNS::Entry* entry, entries) {
// care only about installed ones
if (entry->status() == KNS::Entry::Installed) {
// do something with the installed entries
}
}
}
qDeleteAll(entries);
KNS::Engine engine(0);
if (engine.init("wallpaper.knsrc")) {
KNS::Entry::List entries = engine.downloadDialogModal(this);
if (entries.size() > 0) {
// do something with the modified entries here if you want
// such as rescaning your data folder or whatnot
m_model->reload();
}
}