Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/simplefavoritesmodel.cpp
- This file was moved from applets/kicker/plugin/favoritesmodel.cpp.
Context not available. | |||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||
---|---|---|---|---|---|
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "favoritesmodel.h" | 20 | #include "simplefavoritesmodel.h" | ||
21 | #include "appentry.h" | 21 | #include "appentry.h" | ||
22 | #include "contactentry.h" | 22 | #include "contactentry.h" | ||
23 | #include "fileentry.h" | 23 | #include "fileentry.h" | ||
Context not available. | |||||
26 | 26 | | |||
27 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
28 | 28 | | |||
29 | FavoritesModel::FavoritesModel(QObject *parent) : AbstractModel(parent) | 29 | SimpleFavoritesModel::SimpleFavoritesModel(QObject *parent) : AbstractModel(parent) | ||
30 | , m_enabled(true) | 30 | , m_enabled(true) | ||
31 | , m_maxFavorites(-1) | 31 | , m_maxFavorites(-1) | ||
32 | , m_dropPlaceholderIndex(-1) | 32 | , m_dropPlaceholderIndex(-1) | ||
33 | { | 33 | { | ||
34 | } | 34 | } | ||
35 | 35 | | |||
36 | FavoritesModel::~FavoritesModel() | 36 | SimpleFavoritesModel::~SimpleFavoritesModel() | ||
37 | { | 37 | { | ||
38 | qDeleteAll(m_entryList); | 38 | qDeleteAll(m_entryList); | ||
39 | } | 39 | } | ||
40 | 40 | | |||
41 | QString FavoritesModel::description() const | 41 | QString SimpleFavoritesModel::description() const | ||
42 | { | 42 | { | ||
43 | return i18n("Favorites"); | 43 | return i18n("Favorites"); | ||
44 | } | 44 | } | ||
45 | 45 | | |||
46 | QVariant FavoritesModel::data(const QModelIndex& index, int role) const | 46 | QVariant SimpleFavoritesModel::data(const QModelIndex& index, int role) const | ||
47 | { | 47 | { | ||
48 | if (!index.isValid() || index.row() >= rowCount()) { | 48 | if (!index.isValid() || index.row() >= rowCount()) { | ||
49 | return QVariant(); | 49 | return QVariant(); | ||
Context not available. | |||||
84 | return QVariant(); | 84 | return QVariant(); | ||
85 | } | 85 | } | ||
86 | 86 | | |||
87 | int FavoritesModel::rowCount(const QModelIndex& parent) const | 87 | int SimpleFavoritesModel::rowCount(const QModelIndex& parent) const | ||
88 | { | 88 | { | ||
89 | return parent.isValid() ? 0 : m_entryList.count() + (m_dropPlaceholderIndex != -1 ? 1 : 0); | 89 | return parent.isValid() ? 0 : m_entryList.count() + (m_dropPlaceholderIndex != -1 ? 1 : 0); | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | bool FavoritesModel::trigger(int row, const QString &actionId, const QVariant &argument) | 92 | bool SimpleFavoritesModel::trigger(int row, const QString &actionId, const QVariant &argument) | ||
93 | { | 93 | { | ||
94 | if (row < 0 || row >= m_entryList.count()) { | 94 | if (row < 0 || row >= m_entryList.count()) { | ||
95 | return false; | 95 | return false; | ||
Context not available. | |||||
98 | return m_entryList.at(row)->run(actionId, argument); | 98 | return m_entryList.at(row)->run(actionId, argument); | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | bool FavoritesModel::enabled() const | 101 | bool SimpleFavoritesModel::enabled() const | ||
102 | { | 102 | { | ||
103 | return m_enabled; | 103 | return m_enabled; | ||
104 | } | 104 | } | ||
105 | 105 | | |||
106 | void FavoritesModel::setEnabled(bool enable) | 106 | void SimpleFavoritesModel::setEnabled(bool enable) | ||
107 | { | 107 | { | ||
108 | if (m_enabled != enable) { | 108 | if (m_enabled != enable) { | ||
109 | m_enabled = enable; | 109 | m_enabled = enable; | ||
Context not available. | |||||
112 | } | 112 | } | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | QStringList FavoritesModel::favorites() const | 115 | QStringList SimpleFavoritesModel::favorites() const | ||
116 | { | 116 | { | ||
117 | return m_favorites; | 117 | return m_favorites; | ||
118 | } | 118 | } | ||
119 | 119 | | |||
120 | void FavoritesModel::setFavorites(const QStringList& favorites) | 120 | void SimpleFavoritesModel::setFavorites(const QStringList& favorites) | ||
121 | { | 121 | { | ||
122 | QStringList _favorites(favorites); | 122 | QStringList _favorites(favorites); | ||
123 | _favorites.removeDuplicates(); | 123 | _favorites.removeDuplicates(); | ||
Context not available. | |||||
128 | } | 128 | } | ||
129 | } | 129 | } | ||
130 | 130 | | |||
131 | int FavoritesModel::maxFavorites() const | 131 | int SimpleFavoritesModel::maxFavorites() const | ||
132 | { | 132 | { | ||
133 | return m_maxFavorites; | 133 | return m_maxFavorites; | ||
134 | } | 134 | } | ||
135 | 135 | | |||
136 | void FavoritesModel::setMaxFavorites(int max) | 136 | void SimpleFavoritesModel::setMaxFavorites(int max) | ||
137 | { | 137 | { | ||
138 | if (m_maxFavorites != max) | 138 | if (m_maxFavorites != max) | ||
139 | { | 139 | { | ||
Context not available. | |||||
147 | } | 147 | } | ||
148 | } | 148 | } | ||
149 | 149 | | |||
150 | bool FavoritesModel::isFavorite(const QString &id) const | 150 | bool SimpleFavoritesModel::isFavorite(const QString &id) const | ||
151 | { | 151 | { | ||
152 | return m_favorites.contains(id); | 152 | return m_favorites.contains(id); | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | void FavoritesModel::addFavorite(const QString &id, int index) | 155 | void SimpleFavoritesModel::addFavorite(const QString &id, int index) | ||
156 | { | 156 | { | ||
157 | if (!m_enabled || id.isEmpty()) { | 157 | if (!m_enabled || id.isEmpty()) { | ||
158 | return; | 158 | return; | ||
Context not available. | |||||
184 | emit favoritesChanged(); | 184 | emit favoritesChanged(); | ||
185 | } | 185 | } | ||
186 | 186 | | |||
187 | void FavoritesModel::removeFavorite(const QString &id) | 187 | void SimpleFavoritesModel::removeFavorite(const QString &id) | ||
188 | { | 188 | { | ||
189 | if (!m_enabled || id.isEmpty()) { | 189 | if (!m_enabled || id.isEmpty()) { | ||
190 | return; | 190 | return; | ||
Context not available. | |||||
208 | } | 208 | } | ||
209 | } | 209 | } | ||
210 | 210 | | |||
211 | void FavoritesModel::moveRow(int from, int to) | 211 | void SimpleFavoritesModel::moveRow(int from, int to) | ||
212 | { | 212 | { | ||
213 | if (from >= m_favorites.count() || to >= m_favorites.count()) { | 213 | if (from >= m_favorites.count() || to >= m_favorites.count()) { | ||
214 | return; | 214 | return; | ||
Context not available. | |||||
234 | } | 234 | } | ||
235 | } | 235 | } | ||
236 | 236 | | |||
237 | int FavoritesModel::dropPlaceholderIndex() const | 237 | int SimpleFavoritesModel::dropPlaceholderIndex() const | ||
238 | { | 238 | { | ||
239 | return m_dropPlaceholderIndex; | 239 | return m_dropPlaceholderIndex; | ||
240 | } | 240 | } | ||
241 | 241 | | |||
242 | void FavoritesModel::setDropPlaceholderIndex(int index) | 242 | void SimpleFavoritesModel::setDropPlaceholderIndex(int index) | ||
243 | { | 243 | { | ||
244 | if (index == -1 && m_dropPlaceholderIndex != -1) { | 244 | if (index == -1 && m_dropPlaceholderIndex != -1) { | ||
245 | beginRemoveRows(QModelIndex(), m_dropPlaceholderIndex, m_dropPlaceholderIndex); | 245 | beginRemoveRows(QModelIndex(), m_dropPlaceholderIndex, m_dropPlaceholderIndex); | ||
Context not available. | |||||
270 | } | 270 | } | ||
271 | } | 271 | } | ||
272 | 272 | | |||
273 | AbstractModel *FavoritesModel::favoritesModel() | 273 | AbstractModel *SimpleFavoritesModel::favoritesModel() | ||
274 | { | 274 | { | ||
275 | return this; | 275 | return this; | ||
276 | } | 276 | } | ||
277 | 277 | | |||
278 | void FavoritesModel::refresh() | 278 | void SimpleFavoritesModel::refresh() | ||
279 | { | 279 | { | ||
280 | beginResetModel(); | 280 | beginResetModel(); | ||
281 | 281 | | |||
Context not available. | |||||
314 | emit favoritesChanged(); | 314 | emit favoritesChanged(); | ||
315 | } | 315 | } | ||
316 | 316 | | |||
317 | AbstractEntry *FavoritesModel::favoriteFromId(const QString &id) | 317 | AbstractEntry *SimpleFavoritesModel::favoriteFromId(const QString &id) | ||
318 | { | 318 | { | ||
319 | const QUrl url(id); | 319 | const QUrl url(id); | ||
320 | const QString &s = url.scheme(); | 320 | const QString &s = url.scheme(); | ||
Context not available. |