KNewStuff

quickitemsmodel.h
1/*
2 SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <admin@leinir.dk>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef ITEMSMODEL_H
8#define ITEMSMODEL_H
9
10#include <QAbstractListModel>
11
12#include "entry.h"
13
14#include <memory>
15
16class ItemsModelPrivate;
17
18/**
19 * @short A model which shows the contents found in an Engine
20 *
21 * Use an instance of this model to show the content items represented by the configuration
22 * file passed to an engine. The following sample assumes you are using the Engine component,
23 * however it is also possible to pass a KNSCore::EngineBase instance created from C++ to this
24 * property, if you have specific requirements not covered by the convenience component.
25 *
26 * Most data in the model is simple, but the DownloadLinks role will return a list of
27 * DownloadLinkInfo entries, which you will need to manage in some way.
28 *
29 * You might also look at NewStuffList, NewStuffItem, and the other items, to see some more
30 * detail on what can be done with the data.
31 *
32 * @see NewStuffList
33 * @see NewStuffItem
34 * @see NewStuffPage
35 * @see NewStuffEntryDetails
36 * @see NewStuffEntryComments
37 *
38 * \code
39 import org.kde.newstuff 1.0 as NewStuff
40 Item {
41 NewStuff.ItemsModel {
42 id: newStuffModel;
43 engine: newStuffEngine
44 }
45 NewStuff.Engine {
46 id: newStuffEngine
47 configFile: "/some/filesystem/location/wallpaper.knsrc"
48 onBusyMessageChanged: () => console.log("KNS Message: " + newStuffEngine.busyMessage);
49 onErrorCode: (code, message, metadata) => console.log("KNS Error: " + message);
50 }
51 }
52 \endcode
53 */
55{
57 /**
58 * The NewStuffQuickEngine to show items from
59 */
61public:
62 explicit ItemsModel(QObject *parent = nullptr);
63 ~ItemsModel() override;
64
65 enum Roles {
66 NameRole = Qt::UserRole + 1,
67 UniqueIdRole,
68 CategoryRole,
69 HomepageRole,
70 AuthorRole,
71 LicenseRole,
72 ShortSummaryRole,
73 SummaryRole,
74 ChangelogRole,
75 VersionRole,
76 ReleaseDateRole,
77 UpdateVersionRole,
78 UpdateReleaseDateRole,
79 PayloadRole,
80 PreviewsSmallRole, ///@< this will return a list here, rather than be tied so tightly to the remote api
81 PreviewsRole, ///@< this will return a list here, rather than be tied so tightly to the remote api
83 UnInstalledFilesRole,
84 RatingRole,
85 NumberOfCommentsRole,
86 DownloadCountRole,
87 NumberFansRole,
88 NumberKnowledgebaseEntriesRole,
89 KnowledgebaseLinkRole,
90 DownloadLinksRole,
91 DonationLinkRole,
92 ProviderIdRole,
93 SourceRole,
94 CommentsModelRole,
95 EntryRole,
96 };
98
99 // The lists in OCS are one-indexed, and that isn't how one usually does things in C++.
100 // Consequently, this enum removes what would seem like magic numbers from the code, and
101 // makes their meaning more explicit.
102 enum LinkId { // TODO KF6 reuse this enum in the transaction, we currently use magic numbers there
103 AutoDetectLinkId = -1,
104 FirstLinkId = 1,
105 };
106 Q_ENUM(LinkId)
107
108 QHash<int, QByteArray> roleNames() const override;
109 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
110 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
111 bool canFetchMore(const QModelIndex &parent) const override;
112 void fetchMore(const QModelIndex &parent) override;
113
114 QObject *engine() const;
115 void setEngine(QObject *newEngine);
116 Q_SIGNAL void engineChanged();
117
118 /**
119 * Get the index of an entry based on that entry's unique ID
120 * @param providerId The provider inside of which you wish to search for an entry
121 * @param entryId The unique ID within the given provider of the entry you want to know the index of
122 * @return The index of the entry. In case the entry is not found, -1 is returned
123 * @see KNSCore::Entry::uniqueId()
124 * @since 5.79
125 */
126 Q_INVOKABLE int indexOfEntryId(const QString &providerId, const QString &entryId);
127 Q_INVOKABLE int indexOfEntry(const KNSCore::Entry &e)
128 {
129 return indexOfEntryId(e.providerId(), e.uniqueId());
130 }
131
132 /**
133 * @brief Fired when an entry's data changes
134 *
135 * @param index The index of the item which has changed
136 */
138
139private:
140 const std::unique_ptr<ItemsModelPrivate> d;
141};
142
143#endif // ITEMSMODEL_H
A model which shows the contents found in an Engine.
Q_INVOKABLE int indexOfEntryId(const QString &providerId, const QString &entryId)
Get the index of an entry based on that entry's unique ID.
QObject * engine
The NewStuffQuickEngine to show items from.
@ PreviewsRole
< this will return a list here, rather than be tied so tightly to the remote api
@ InstalledFilesRole
< this will return a list here, rather than be tied so tightly to the remote api
Q_SIGNAL void entryChanged(const KNSCore::Entry &entry)
Fired when an entry's data changes.
KNewStuff data entry container.
Definition entry.h:48
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
Q_ENUM(...)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALQ_SIGNAL
QObject * parent() const const
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.