Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/quickitemsmodel.h
Show All 29 Lines | |||||
30 | * Use an instance of this model to show the content items represented by the configuration | 30 | * Use an instance of this model to show the content items represented by the configuration | ||
31 | * file passed to an engine. The following sample assumes you are using the Engine component, | 31 | * file passed to an engine. The following sample assumes you are using the Engine component, | ||
32 | * however it is also possible to pass a KNSCore::Engine instance created from C++ to this | 32 | * however it is also possible to pass a KNSCore::Engine instance created from C++ to this | ||
33 | * property, if you have specific requirements not covered by the convenience component. | 33 | * property, if you have specific requirements not covered by the convenience component. | ||
34 | * | 34 | * | ||
35 | * Most data in the model is simple, but the DownloadLinks role will return a list of | 35 | * Most data in the model is simple, but the DownloadLinks role will return a list of | ||
36 | * DownloadLinkInfo entries, which you will need to manage in some way. | 36 | * DownloadLinkInfo entries, which you will need to manage in some way. | ||
37 | * | 37 | * | ||
38 | * You might also look at NewStuffList and NewStuffItem to see some more detail on what can be | 38 | * You might also look at NewStuffList, NewStuffItem, and the other items, to see some more | ||
39 | * done with the data. | 39 | * detail on what can be done with the data. | ||
40 | * | 40 | * | ||
41 | * @see NewStuffList | 41 | * @see NewStuffList | ||
42 | * @see NewStuffItem | 42 | * @see NewStuffItem | ||
43 | * @see NewStuffPage | ||||
44 | * @see NewStuffEntryDetails | ||||
45 | * @see NewStuffEntryComments | ||||
43 | * | 46 | * | ||
44 | * \code | 47 | * \code | ||
45 | import org.kde.newstuff 1.0 as NewStuff | 48 | import org.kde.newstuff 1.0 as NewStuff | ||
46 | Item { | 49 | Item { | ||
47 | NewStuff.ItemsModel { | 50 | NewStuff.ItemsModel { | ||
48 | id: newStuffModel; | 51 | id: newStuffModel; | ||
49 | engine: newStuffEngine.engine; | 52 | engine: newStuffEngine.engine; | ||
50 | } | 53 | } | ||
51 | NewStuff.Engine { | 54 | NewStuff.Engine { | ||
52 | id: newStuffEngine; | 55 | id: newStuffEngine; | ||
53 | configFile: "/some/filesystem/location/wallpaper.knsrc"; | 56 | configFile: "/some/filesystem/location/wallpaper.knsrc"; | ||
54 | onMessage: console.log("KNS Message: " + message); | 57 | onMessage: console.log("KNS Message: " + message); | ||
55 | onIdleMessage: console.log("KNS Idle: " + message); | 58 | onIdleMessage: console.log("KNS Idle: " + message); | ||
56 | onBusyMessage: console.log("KNS Busy: " + message); | 59 | onBusyMessage: console.log("KNS Busy: " + message); | ||
57 | onErrorMessage: console.log("KNS Error: " + message); | 60 | onErrorMessage: console.log("KNS Error: " + message); | ||
58 | } | 61 | } | ||
59 | } | 62 | } | ||
60 | \endcode | 63 | \endcode | ||
61 | */ | 64 | */ | ||
62 | class ItemsModel : public QAbstractListModel | 65 | class ItemsModel : public QAbstractListModel | ||
63 | { | 66 | { | ||
64 | Q_OBJECT | 67 | Q_OBJECT | ||
68 | /** | ||||
69 | * The NewStuffQuickEngine to show items from | ||||
70 | */ | ||||
65 | Q_PROPERTY(QObject* engine READ engine WRITE setEngine NOTIFY engineChanged) | 71 | Q_PROPERTY(QObject* engine READ engine WRITE setEngine NOTIFY engineChanged) | ||
66 | public: | 72 | public: | ||
67 | explicit ItemsModel(QObject* parent = nullptr); | 73 | explicit ItemsModel(QObject* parent = nullptr); | ||
68 | virtual ~ItemsModel(); | 74 | virtual ~ItemsModel(); | ||
69 | 75 | | |||
70 | enum Roles { | 76 | enum Roles { | ||
71 | NameRole = Qt::UserRole + 1, | 77 | NameRole = Qt::UserRole + 1, | ||
72 | UniqueIdRole, | 78 | UniqueIdRole, | ||
Show All 18 Lines | |||||
91 | DownloadCountRole, | 97 | DownloadCountRole, | ||
92 | NumberFansRole, | 98 | NumberFansRole, | ||
93 | NumberKnowledgebaseEntriesRole, | 99 | NumberKnowledgebaseEntriesRole, | ||
94 | KnowledgebaseLinkRole, | 100 | KnowledgebaseLinkRole, | ||
95 | DownloadLinksRole, | 101 | DownloadLinksRole, | ||
96 | DonationLinkRole, | 102 | DonationLinkRole, | ||
97 | ProviderIdRole, | 103 | ProviderIdRole, | ||
98 | SourceRole, | 104 | SourceRole, | ||
99 | StatusRole | 105 | StatusRole, | ||
106 | CommentsModelRole | ||||
100 | }; | 107 | }; | ||
108 | Q_ENUM(Roles) | ||||
101 | enum ItemStatus { | 109 | enum ItemStatus { | ||
102 | InvalidStatus, | 110 | InvalidStatus, | ||
103 | DownloadableStatus, | 111 | DownloadableStatus, | ||
104 | InstalledStatus, | 112 | InstalledStatus, | ||
105 | UpdateableStatus, | 113 | UpdateableStatus, | ||
106 | DeletedStatus, | 114 | DeletedStatus, | ||
107 | InstallingStatus, | 115 | InstallingStatus, | ||
108 | UpdatingStatus | 116 | UpdatingStatus | ||
109 | }; | 117 | }; | ||
110 | Q_ENUM(ItemStatus) | 118 | Q_ENUM(ItemStatus) | ||
111 | 119 | | |||
112 | QHash< int, QByteArray > roleNames() const override; | 120 | QHash< int, QByteArray > roleNames() const override; | ||
113 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | 121 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
122 | Q_INVOKABLE QVariant data(int index, int role = Qt::DisplayRole) const; | ||||
114 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | 123 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
115 | bool canFetchMore(const QModelIndex & parent) const override; | 124 | bool canFetchMore(const QModelIndex & parent) const override; | ||
116 | void fetchMore(const QModelIndex & parent) override; | 125 | void fetchMore(const QModelIndex & parent) override; | ||
117 | 126 | | |||
118 | QObject* engine() const; | 127 | QObject* engine() const; | ||
119 | void setEngine(QObject* newEngine); | 128 | void setEngine(QObject* newEngine); | ||
120 | Q_SIGNAL void engineChanged(); | 129 | Q_SIGNAL void engineChanged(); | ||
121 | 130 | | |||
122 | /** | 131 | /** | ||
123 | * @brief This will install (or update, if already installed) the item at the given index | 132 | * @brief This will install (or update, if already installed) the item at the given index | ||
124 | * | 133 | * | ||
125 | * There are no side effects of this function if it is called on an item which cannot be | 134 | * There are no side effects of this function if it is called on an item which cannot be | ||
126 | * installed or updated (that is, if the status is not one such that these are possible, | 135 | * installed or updated (that is, if the status is not one such that these are possible, | ||
127 | * the function will simply return without performing any actions) | 136 | * the function will simply return without performing any actions) | ||
128 | * | 137 | * | ||
129 | * @param index The index of the item to install or update | 138 | * @param index The index of the item to install or update | ||
130 | */ | 139 | */ | ||
131 | Q_INVOKABLE void installItem(int index); | 140 | Q_INVOKABLE void installItem(int index, int linkId); | ||
132 | /** | 141 | /** | ||
133 | * @brief Uninstall an already installed item | 142 | * @brief Uninstall an already installed item | ||
134 | * | 143 | * | ||
135 | * There are no side effects of this function if it is called on an item which cannot be | 144 | * There are no side effects of this function if it is called on an item which cannot be | ||
136 | * uninstalled (that is, if the status is not one such that this is possible, | 145 | * uninstalled (that is, if the status is not one such that this is possible, | ||
137 | * the function will simply return without performing any actions) | 146 | * the function will simply return without performing any actions) | ||
138 | * | 147 | * | ||
139 | * @param index The index of the item to be uninstalled | 148 | * @param index The index of the item to be uninstalled | ||
140 | */ | 149 | */ | ||
141 | Q_INVOKABLE void uninstallItem(int index); | 150 | Q_INVOKABLE void uninstallItem(int index); | ||
151 | | ||||
152 | /** | ||||
153 | * @brief Run the adoption command on an already installed item | ||||
154 | * | ||||
155 | * @note This will simply fail quietly if the item is not installed | ||||
156 | * | ||||
157 | * @param index The intex of the item to be adopted | ||||
158 | */ | ||||
159 | Q_INVOKABLE void adoptItem(int index); | ||||
160 | | ||||
161 | /** | ||||
162 | * @brief Fired when an entry's data changes | ||||
163 | * | ||||
164 | * @param index The index of the item which has changed | ||||
165 | */ | ||||
166 | Q_SIGNAL void entryChanged(int index); | ||||
142 | private: | 167 | private: | ||
143 | class Private; | 168 | class Private; | ||
144 | Private* d; | 169 | Private* d; | ||
145 | }; | 170 | }; | ||
146 | Q_DECLARE_METATYPE(ItemsModel::ItemStatus) | 171 | Q_DECLARE_METATYPE(ItemsModel::ItemStatus) | ||
147 | 172 | | |||
148 | #endif//ITEMSMODEL_H | 173 | #endif//ITEMSMODEL_H |