• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.reuse/H04-Dec-2021-107

LICENSES/H03-May-2022-

autotests/H03-May-2022-1,3281,090

data/kmoretools-desktopfiles/H03-May-2022-5,3655,234

docs/H03-May-2022-2213

po/H04-Dec-2021-164,165140,945

src/H03-May-2022-26,51818,553

tests/H03-May-2022-889696

.git-blame-ignore-revsH A D04-Dec-2021210 86

.gitignoreH A D04-Dec-2021370 3130

.gitlab-ci.ymlH A D04-Dec-2021284 75

.kde-ci.ymlH A D04-Dec-2021698 2421

KF5NewStuffConfig.cmake.inH A D04-Dec-2021966 3022

KF5NewStuffCoreConfig.cmake.inH A D04-Dec-2021735 2618

KF5NewStuffQuickConfig.cmake.inH A D04-Dec-2021182 85

README.mdH A D04-Dec-202114 KiB249181

TODOH A D04-Dec-2021613 1710

metainfo.yamlH A D04-Dec-2021452 2421

README.md

1# KNewStuff
2
3Framework for downloading and sharing additional application data
4
5## Introduction
6
7The KNewStuff library implements collaborative data sharing for
8applications. It uses libattica to support the Open Collaboration Services
9specification.
10
11
12## Usage
13
14There are three parts to KNewStuff:
15
16* *KNewStuffCore* - The core functionality, which takes care of the actual work
17  (downloading data and interacting with the remote services). Importantly, this
18  library has no dependencies past Tier 1, and so while the entire framework is
19  to be considered Tier 3, the KNewStuffCore library can be considered Tier 2
20  for integration purposes.
21* *KNewStuff* - A Qt Widget based UI library, designed for ease of implementation of
22  various UI patterns found through KDE applications (such as the Get New Stuff buttons,
23  as well as generic download and upload dialogues)
24* *KNewStuffQuick* - A set of Qt Quick based components designed to provide similar
25  pattern support as KNewStuff, except for Qt Quick based applications, and specifically
26  in Kirigami based applications.
27
28If you are using CMake, you need to find the modules, which can be done by doing one of
29the following in your CMakeLists.txt:
30
31Either use the more modern (and compact) component based method (only actually add the
32component you need, since both NewStuff and NewStuffQuick depend on NewStuffCore):
33
34    find_package(KF5 COMPONENTS NewStuffCore NewStuff NewStuffQuick)
35
36Or use the old-fashioned syntax
37
38    find_package(KF5NewStuffCore CONFIG) # for the KNewStuffCore library only
39    find_package(KF5NewStuff CONFIG) # for the KNewStuff UI library, will pull in KNewStuffCore for you
40    find_package(KF5NewStuffQuick CONFIG) # for the KNewStuffQuick UI library, will pull in KNewStuffCore for you
41
42Also remember to link to the library you are using (either KF5::NewStuff or
43KF5::NewStuffCore), and for the Qt Quick NewStuffQuick module, add the following
44to the QML files where you wish to use the components:
45
46    import org.kde.newstuff 1.0
47
48Finally, because KNewStuffQuick is not a link time requirement, it would be good form
49to mark it as a runtime requirement (and describing why you need them), which is done
50by adding the following in your CMakeLists.txt sometime after the find statement:
51
52    set_package_properties(KF5NewStuffQuick PROPERTIES
53        DESCRIPTION "Qt Quick components used for interacting with remote data services"
54        URL "https://api.kde.org/frameworks/knewstuff/html/index.html"
55        PURPOSE "Required to Get Hot New Stuff for my application"
56        TYPE RUNTIME)
57
58When installing your knsrc configuration file, you should install it into the location
59where KNewStuffCore expects it to be found. Do this by using the CMake variable
60`KDE_INSTALL_KNSRCDIR` as provided by the KNewStuffCore module, since 5.57.0.
61To support older versions you can use the CMake variable `KDE_INSTALL_CONFDIR` from
62[Extra-CMake-Modules' KDEInstallDirs](https://api.kde.org/ecm/kde-module/KDEInstallDirs.html).
63You can also handle this yourself, which means you will need to feed `Engine::init()`
64the full path to the knsrc file.
65
66## Which module should you use?
67
68When building applications designed to fit in with other classic, widget based
69applications, the application authors should use KNS3::DownloadDialog for
70downloading application content. For uploading KNS3::UploadDialog is used.
71
72When building Qt Quick (and in particular Kirigami) based applications, you can
73use the NewStuffList item from the org.kde.newstuff import to achieve a similar
74functionality to KNS3::DownloadDialog. You can also use the ItemsModel directly,
75if this is not featureful enough. Uploading is currently not exposed in KNewStuffQuick.
76
77If neither of these options are powerful enough for your needs, you can access
78the functionality directly through the classes in the KNSCore namespace.
79
80If you are looking for some tutorials, Techbase has a couple of those here:
81[Get Hot New Stuff tutorials](https://techbase.kde.org/Development/Tutorials#Get_Hot_New_Stuff).
82
83## Configuration Files
84
85The Engine (and consequently all the various abstracted options like Page and Dialog) is configured by a KNewStuff
86Resource and Configuration, or .knsrc file for short, containing the details of how the engine should be set up.
87
88Your application should install a file into the systemwide configuration location defined by the KNSCore CMake module,
89which provides the variable `KDE_INSTALL_KNSRCDIR`, which will put the file into something equivalent to
90`/usr/share/knsrcfiles/appname.knsrc` (that is, the systemwide data directory, the subdirectory knsrcfiles, and then
91appname, which can technically be anything but which should commonly be your application's binary name for consistency
92purposes).
93
94As an example, the file might look like this for wallpapers found on the KDE Store:
95
96    [KNewStuff3]
97    Name=Wallpapers
98    ProvidersUrl=https://autoconfig.kde.org/ocs/providers.xml
99    Categories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200
100    XdgTargetDir=wallpapers
101    Uncompress=archive
102
103### Name
104
105This sets a human-readable name that KNewStuff can use to tell the user what type of content this knsrc file
106provides access to. It will usually be considerably different in nature to the appname of the file itself.
107For example, the book store in [Peruse](https://peruse.kde.org) (an electronic reading app by KDE) has the knsrc
108filename `peruse.knsrc` for ease of packaging and distribution, whereas this entry in that file is `Name=Books`.
109
110If there is no name set for the file, the UI might end up looking slightly weird (as this results in exposing
111the knsrc filename to the end user, which likely will not be what you are intending).
112
113### ProvidersUrl
114
115To use a local providers file instead of a remote one, you can set `UseLocalProvidersFile=true` instead of
116ProvidersUrl. An example of where this would be useful is if you wish to use an
117[OPDS feed](https://wiki.mobileread.com/wiki/OPDS). These are likely to not have a providers file, and if you
118lack a server on which to host one of your own, being able to simply put it beside the knsrc file becomes useful.
119This will make the engine attempt to load a file located next to your knsrc file, with the same name as that
120file, with .providers appended. For example, if your configuration file is called `appname.knsrc`, then your
121providers file should be named `appname.providers`.
122
123### Categories
124
125The comma-separated list in the entry Categories defines which subsections of the service should be used to fetch content,
126and is further shown in a dropdown list on NewStuff.Page and in KNS3::Dialog. They exist in a three-layer format, where the
127usual human-readable ID in the knsrc file corresponds to a UID in the service, which has a number of pieces of metadata
128(such as translated human-readable titles). See also KNSCore::Engine::categoriesMetadata().
129
130To see which categories are available on a particular Attica provider, you can fetch the list by performing a GET call to the
131content/categories object (by, for example, opening it in a browser). For example, for an OCS service with the server address
132ocs.server.org, you would fetch `https://ocs.server.org/v1/content/categories`, which will give you an XML file, with
133all categories available on that service, and their metadata.
134
135### XdgTargetDir
136
137This defines the location where the downloaded items will be put. This is the name of a directory in your $XDG_DATA_HOME
138directory, such as `~/.local/share/wallpapers`, which is what you would get by setting `XdgTargetDir=wallpapers` as in the
139example above.
140
141This is what `QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + name` will return.
142
143The two following options are deprecated and should not be used in new code (and are only listed here to allow you
144to understand older knsrc files should you come across them):
145
146* `StandardResource`: Not available in KF5, use XdgTargetDir instead.
147* `TargetDir`: Since KF5, this is equivalent to XdgTargetDir.
148
149#### InstallPath
150
151Alternatively to using an XDG data directory, you can bypass this and just have a named location in the user's home directory.
152To do this, set `InstallPath` instead of `XdgTargetDir`. For example, setting `InstallPath=Applications` will put downloaded
153items into `~/Applications`.
154
155### Uncompress
156
157Uncompress can be one of: `always`, `never`, `archive`, `surdir`, or `kpackage`:
158
159* `always`: Assume all downloaded files are archives that need to be extracted
160* `never`: Never try to extract the file
161* `archive`: If the file is an archive, uncompress it, otherwise just pass it on
162* `subdir`: Logic as archive, but decompress into a subdirectory named after the payload filename
163* `kpackage`: Require that the downloaded file is a kpackage, and use the KPackage framework for handling installation and removal (since 5.70).
164  See also the note on [KPackage Support below](#kpackage-support) below.
165
166### Entry and Download Item Tag Filter
167
168Use the `TagFilter` and `DownloadTagFilter` options to set filters based on the abstract tags which can be present
169on both entries and the download items they contain. To see the full documentation on this, read further in
170KNSCore::Engine::setTagFilter(const QStringList &filter), but the following is an example of its use in a knsrc file:
171
172    TagFilter=ghns_excluded!=1,data##mimetype==application/cbr+zip,data##mimetype==application/cbr+rar
173
174This will honor the ghns_exclusion tag (the default value if you do not set one, and generally you should include
175this entry). It then further filters out anything that does not include a comic book archive in either ZIP or RAR
176format in one or more of the download items. Notice in particular that there are two `data##mimetype` entries. Use this
177for when a tag may have multiple values.
178
179### Automatic Dead Entry Removal
180
181If you set `RemoveDeadEntries=true`, entries whose installed files have all been deleted without going through
182KNewStuff will be removed from the cache. The removal will happen only after all listed files have been removed, which
183means that if, for example, an entry was installed from archive, which was decompressed to yield multiple installed files,
184if even one of those files remains, the entry will remain marked as installed.
185
186**Note** In KDE Frameworks 6, this option will default to `true`, and you should consider switching it on at this point,
187and rework your code to support this functionality, or explicitly set it to `false` now, if you need this to retain its
188current functionality.
189
190### Adoption Command
191
192Set the `AdoptionCommand` option to add a supplementary action to the places where entries are displayed which allows the
193user to "adopt" the entry (that is, use it in some way, which will depend on the specific type of entry). In NewStuff.Page,
194the delegates all get a new button shown on them, and on detail pages, a new action will be shown in either the toolbar
195on desktops, or in the context drawer on mobile.
196
197#### Use Label
198
199Usually, once installed, an item will have some canonical way of being used (for example, using a wallpaper will set it
200as the wallpaper on the primary desktop, using a color scheme will switch the environment to that scheme), but in some
201cases the word "Use" usually used as the label for the action which activates the Adoption Command does not quite fit.
202To change this label, you can add an entry like the following to your knsrc file: `UseLabel=Read`, which in this case
203will show the word "Read" for that action instead of "Use".
204
205### Upload Assistance
206
207While KNewStuff does not currently handle content uploading, the UI will attempt to guide users in how to upload new entries
208on whatever provider their content is currently coming from. If you as an application developer want to explicitly not
209suggest that users should do this, add an `UploadEnabled=false` entry to your configuration file.
210
211Not adding this entry to your configuration will cause KNewStuff to add an entry to NewStuff.Page's contextual actions
212with the label "Upload...", which pushes a NewStuff.UploadPage to the stack. At this current time, this page simply
213gives instructions on how uploading can be done (with specific attention paid to identifying the KDE Store and giving
214more specific instructions for that).
215
216### Installation Control
217
218The `InstallationCommand` and `UninstallCommand` entries can be used to handle items once they have been put into their
219installation location. For example, you might need to register an item with some service, and unregister it before removing
220it, and using these two entries will allow that to happen.
221
222You can also handle the output from the installation process, by returning a non-zero value on exiting, and writing
223to standard output. If the return value is non-zero, KNewStuff will report this to the user through various ways,
224primarily through the error displayer in NewStuff.Page (and associated components), and the KNS3::DownloadDialog.
225
226An example of this is how Plymouth graphical boot themes are handled, by running the `kplymouththemeinstaller` tool with the
227appropriate flags set. You can see the file here: [https://invent.kde.org/plasma/plymouth-kcm/-/blob/master/src/plymouth.knsrc]
228
229### <a id="kpackage-support" />KPackage Support
230
231To make use of the KPackage option described above, in addition to the Uncompress setting above, you should also specify
232the type of archive expected by KPackage. While it is possible to deduce this from the package metadata in many situations,
233it is not a requirement of the format that this information exists, and we need to have a fallback in the case it is not
234available there. As such, you will want to add a `KPackageType` entry to your knsrc file. The following example shows how this
235is done for Plasma themes:
236
237    [KNewStuff3]
238    ProvidersUrl=https://autoconfig.kde.org/ocs/providers.xml
239    Categories=Plasma Theme
240    StandardResource=tmp
241    TagFilter=ghns_excluded!=1,plasma##version==5
242    DownloadTagFilter=plasma##version==5
243    Uncompress=kpackage
244    KPackageType=Plasma/Theme
245
246Using KPackage support will automatically enable the removal of dead entries option. You can override this if you
247want to, by explicitly adding `RemoveDeadEntries=false` to your knsrc file, though this would likely result in your
248knewstuff cache to end up out of sync at some point.
249