Changeset View
Changeset View
Standalone View
Standalone View
wallpapers/image/backgroundlistmodel.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 82 | { | |||
---|---|---|---|---|---|
90 | { PackageNameRole, "packageName" }, | 90 | { PackageNameRole, "packageName" }, | ||
91 | { RemovableRole, "removable" }, | 91 | { RemovableRole, "removable" }, | ||
92 | { PendingDeletionRole, "pendingDeletion" }, | 92 | { PendingDeletionRole, "pendingDeletion" }, | ||
93 | }; | 93 | }; | ||
94 | } | 94 | } | ||
95 | 95 | | |||
96 | void BackgroundListModel::removeBackground(const QString &path) | 96 | void BackgroundListModel::removeBackground(const QString &path) | ||
97 | { | 97 | { | ||
98 | QModelIndex index; | 98 | int index = -1; | ||
99 | while ((index = indexOf(path)).isValid()) { | 99 | while ((index = indexOf(path)) >= 0) { | ||
100 | beginRemoveRows(QModelIndex(), index.row(), index.row()); | 100 | beginRemoveRows(QModelIndex(), index, index); | ||
101 | m_packages.removeAt(index.row()); | 101 | m_packages.removeAt(index); | ||
102 | endRemoveRows(); | 102 | endRemoveRows(); | ||
103 | emit countChanged(); | 103 | emit countChanged(); | ||
104 | } | 104 | } | ||
105 | } | 105 | } | ||
106 | 106 | | |||
107 | void BackgroundListModel::reload() | 107 | void BackgroundListModel::reload() | ||
108 | { | 108 | { | ||
109 | reload(QStringList()); | 109 | reload(QStringList()); | ||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 214 | if (!m_wallpaper || !contains(path)) { | |||
223 | m_wallpaper->findPreferedImageInPackage(package); | 223 | m_wallpaper->findPreferedImageInPackage(package); | ||
224 | qDebug() << "WP Bckground added " << path << package.isValid(); | 224 | qDebug() << "WP Bckground added " << path << package.isValid(); | ||
225 | m_packages.prepend(package); | 225 | m_packages.prepend(package); | ||
226 | endInsertRows(); | 226 | endInsertRows(); | ||
227 | emit countChanged(); | 227 | emit countChanged(); | ||
228 | } | 228 | } | ||
229 | } | 229 | } | ||
230 | 230 | | |||
231 | QModelIndex BackgroundListModel::indexOf(const QString &path) const | 231 | int BackgroundListModel::indexOf(const QString &path) const | ||
232 | { | 232 | { | ||
233 | for (int i = 0; i < m_packages.size(); i++) { | 233 | for (int i = 0; i < m_packages.size(); i++) { | ||
234 | // packages will end with a '/', but the path passed in may not | 234 | // packages will end with a '/', but the path passed in may not | ||
235 | QString package = m_packages[i].path(); | 235 | QString package = m_packages[i].path(); | ||
236 | if (package.at(package.length() - 1) == QChar::fromLatin1('/')) { | 236 | if (package.at(package.length() - 1) == QChar::fromLatin1('/')) { | ||
237 | package.truncate(package.length() - 1); | 237 | package.truncate(package.length() - 1); | ||
238 | } | 238 | } | ||
239 | //remove eventual file:/// | ||||
240 | const QString filteredPath = QUrl(path).path(); | ||||
239 | 241 | | |||
240 | if (path.startsWith(package)) { | 242 | if (filteredPath.startsWith(package)) { | ||
241 | // FIXME: ugly hack to make a difference between local files in the same dir | 243 | // FIXME: ugly hack to make a difference between local files in the same dir | ||
242 | // package->path does not contain the actual file name | 244 | // package->path does not contain the actual file name | ||
243 | qDebug() << "WP prefix" << m_packages[i].contentsPrefixPaths() << m_packages[i].filePath("preferred") << package << path; | 245 | qDebug() << "WP prefix" << m_packages[i].contentsPrefixPaths() << m_packages[i].filePath("preferred") << package << filteredPath; | ||
244 | QStringList ps = m_packages[i].contentsPrefixPaths(); | 246 | QStringList ps = m_packages[i].contentsPrefixPaths(); | ||
245 | bool prefixempty = ps.count() == 0; | 247 | bool prefixempty = ps.count() == 0; | ||
246 | if (!prefixempty) { | 248 | if (!prefixempty) { | ||
247 | prefixempty = ps[0].isEmpty(); | 249 | prefixempty = ps[0].isEmpty(); | ||
248 | } | 250 | } | ||
249 | 251 | | |||
250 | 252 | //For local files (user wallpapers) filteredPath == m_packages[i].filePath("preferred") | |||
251 | //For local files (user wallpapers) path == m_packages[i].filePath("preferred") | 253 | //E.X. filteredPath = "/home/kde/next.png" | ||
252 | //E.X. path = "/home/kde/next.png" | | |||
253 | //m_packages[i].filePath("preferred") = "/home/kde/next.png" | 254 | //m_packages[i].filePath("preferred") = "/home/kde/next.png" | ||
254 | // | 255 | // | ||
255 | //But for the system wallpapers this is not the case. path != m_packages[i].filePath("preferred") | 256 | //But for the system wallpapers this is not the case. filteredPath != m_packages[i].filePath("preferred") | ||
256 | //E.X. path = /usr/share/wallpapers/Next/" | 257 | //E.X. filteredPath = /usr/share/wallpapers/Next/" | ||
257 | //m_packages[i].filePath("preferred") = "/usr/share/wallpapers/Next/contents/images/1920x1080.png" | 258 | //m_packages[i].filePath("preferred") = "/usr/share/wallpapers/Next/contents/images/1920x1080.png" | ||
258 | if ((path == m_packages[i].filePath("preferred")) || m_packages[i].filePath("preferred").contains(path)) { | 259 | if ((filteredPath == m_packages[i].filePath("preferred")) || m_packages[i].filePath("preferred").contains(filteredPath)) { | ||
259 | qDebug() << "WP TRUE" << (!m_packages[i].contentsPrefixPaths().isEmpty()) << (path == m_packages[i].filePath("preferred")); | 260 | qDebug() << "WP TRUE" << (!m_packages[i].contentsPrefixPaths().isEmpty()) << (filteredPath == m_packages[i].filePath("preferred")); | ||
260 | return index(i, 0); | 261 | return i; | ||
261 | } | 262 | } | ||
262 | } | 263 | } | ||
263 | } | 264 | } | ||
264 | return QModelIndex(); | 265 | return -1; | ||
265 | } | 266 | } | ||
266 | 267 | | |||
267 | bool BackgroundListModel::contains(const QString &path) const | 268 | bool BackgroundListModel::contains(const QString &path) const | ||
268 | { | 269 | { | ||
269 | //qDebug() << "WP contains: " << path << indexOf(path).isValid(); | 270 | //qDebug() << "WP contains: " << path << indexOf(path).isValid(); | ||
270 | return indexOf(path).isValid(); | 271 | return indexOf(path) >= 0; | ||
271 | } | 272 | } | ||
272 | 273 | | |||
273 | int BackgroundListModel::rowCount(const QModelIndex &) const | 274 | int BackgroundListModel::rowCount(const QModelIndex &) const | ||
274 | { | 275 | { | ||
275 | return m_packages.size(); | 276 | return m_packages.size(); | ||
276 | } | 277 | } | ||
277 | 278 | | |||
278 | QSize BackgroundListModel::bestSize(const KPackage::Package &package) const | 279 | QSize BackgroundListModel::bestSize(const KPackage::Package &package) const | ||
Show All 18 Lines | |||||
297 | } | 298 | } | ||
298 | 299 | | |||
299 | void BackgroundListModel::sizeFound(const QString &path, const QSize &s) | 300 | void BackgroundListModel::sizeFound(const QString &path, const QSize &s) | ||
300 | { | 301 | { | ||
301 | if (!m_wallpaper) { | 302 | if (!m_wallpaper) { | ||
302 | return; | 303 | return; | ||
303 | } | 304 | } | ||
304 | 305 | | |||
305 | QModelIndex index = indexOf(path); | 306 | int idx = indexOf(path); | ||
306 | if (index.isValid()) { | 307 | if (idx >= 0) { | ||
307 | KPackage::Package package = m_packages.at(index.row()); | 308 | KPackage::Package package = m_packages.at(idx); | ||
308 | m_sizeCache.insert(package.path(), s); | 309 | m_sizeCache.insert(package.path(), s); | ||
309 | emit dataChanged(index, index); | 310 | emit dataChanged(index(idx, 0), index(idx, 0)); | ||
310 | } | 311 | } | ||
311 | } | 312 | } | ||
312 | 313 | | |||
313 | QVariant BackgroundListModel::data(const QModelIndex &index, int role) const | 314 | QVariant BackgroundListModel::data(const QModelIndex &index, int role) const | ||
314 | { | 315 | { | ||
315 | if (!index.isValid()) { | 316 | if (!index.isValid()) { | ||
316 | return QVariant(); | 317 | return QVariant(); | ||
317 | } | 318 | } | ||
▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines |