diff --git a/wallpapers/image/backgroundlistmodel.h b/wallpapers/image/backgroundlistmodel.h --- a/wallpapers/image/backgroundlistmodel.h +++ b/wallpapers/image/backgroundlistmodel.h @@ -85,7 +85,7 @@ void reload(); void reload(const QStringList &selected); void addBackground(const QString &path); - QModelIndex indexOf(const QString &path) const; + Q_INVOKABLE int indexOf(const QString &path) const; virtual bool contains(const QString &bg) const; int count() const {return m_packages.size();}; diff --git a/wallpapers/image/backgroundlistmodel.cpp b/wallpapers/image/backgroundlistmodel.cpp --- a/wallpapers/image/backgroundlistmodel.cpp +++ b/wallpapers/image/backgroundlistmodel.cpp @@ -95,10 +95,10 @@ void BackgroundListModel::removeBackground(const QString &path) { - QModelIndex index; - while ((index = indexOf(path)).isValid()) { - beginRemoveRows(QModelIndex(), index.row(), index.row()); - m_packages.removeAt(index.row()); + int index = -1; + while ((index = indexOf(path)) >= 0) { + beginRemoveRows(QModelIndex(), index, index); + m_packages.removeAt(index); endRemoveRows(); emit countChanged(); } @@ -228,46 +228,47 @@ } } -QModelIndex BackgroundListModel::indexOf(const QString &path) const +int BackgroundListModel::indexOf(const QString &path) const { for (int i = 0; i < m_packages.size(); i++) { // packages will end with a '/', but the path passed in may not QString package = m_packages[i].path(); if (package.at(package.length() - 1) == QChar::fromLatin1('/')) { package.truncate(package.length() - 1); } + //remove eventual file:/// + const QString filteredPath = QUrl(path).path(); - if (path.startsWith(package)) { + if (filteredPath.startsWith(package)) { // FIXME: ugly hack to make a difference between local files in the same dir // package->path does not contain the actual file name - qDebug() << "WP prefix" << m_packages[i].contentsPrefixPaths() << m_packages[i].filePath("preferred") << package << path; + qDebug() << "WP prefix" << m_packages[i].contentsPrefixPaths() << m_packages[i].filePath("preferred") << package << filteredPath; QStringList ps = m_packages[i].contentsPrefixPaths(); bool prefixempty = ps.count() == 0; if (!prefixempty) { prefixempty = ps[0].isEmpty(); } - - //For local files (user wallpapers) path == m_packages[i].filePath("preferred") - //E.X. path = "/home/kde/next.png" + //For local files (user wallpapers) filteredPath == m_packages[i].filePath("preferred") + //E.X. filteredPath = "/home/kde/next.png" //m_packages[i].filePath("preferred") = "/home/kde/next.png" // - //But for the system wallpapers this is not the case. path != m_packages[i].filePath("preferred") - //E.X. path = /usr/share/wallpapers/Next/" + //But for the system wallpapers this is not the case. filteredPath != m_packages[i].filePath("preferred") + //E.X. filteredPath = /usr/share/wallpapers/Next/" //m_packages[i].filePath("preferred") = "/usr/share/wallpapers/Next/contents/images/1920x1080.png" - if ((path == m_packages[i].filePath("preferred")) || m_packages[i].filePath("preferred").contains(path)) { - qDebug() << "WP TRUE" << (!m_packages[i].contentsPrefixPaths().isEmpty()) << (path == m_packages[i].filePath("preferred")); - return index(i, 0); + if ((filteredPath == m_packages[i].filePath("preferred")) || m_packages[i].filePath("preferred").contains(filteredPath)) { + qDebug() << "WP TRUE" << (!m_packages[i].contentsPrefixPaths().isEmpty()) << (filteredPath == m_packages[i].filePath("preferred")); + return i; } } } - return QModelIndex(); + return -1; } bool BackgroundListModel::contains(const QString &path) const { //qDebug() << "WP contains: " << path << indexOf(path).isValid(); - return indexOf(path).isValid(); + return indexOf(path) >= 0; } int BackgroundListModel::rowCount(const QModelIndex &) const @@ -302,11 +303,11 @@ return; } - QModelIndex index = indexOf(path); - if (index.isValid()) { - KPackage::Package package = m_packages.at(index.row()); + int idx = indexOf(path); + if (idx >= 0) { + KPackage::Package package = m_packages.at(idx); m_sizeCache.insert(package.path(), s); - emit dataChanged(index, index); + emit dataChanged(index(idx, 0), index(idx, 0)); } } diff --git a/wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml b/wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml --- a/wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml +++ b/wallpapers/image/imagepackage/contents/ui/WallpaperDelegate.qml @@ -32,12 +32,6 @@ property bool selected: (wallpapersGrid.currentIndex == index) opacity: model.pendingDeletion ? 0.5 : 1 - onSelectedChanged: { - if (selected) { - cfg_Image = model.path - } - } - hoverEnabled: true @@ -173,11 +167,4 @@ } onExited: Tooltip.hideText() - - Component.onCompleted: { - if (cfg_Image == model.path) { - makeCurrentTimer.pendingIndex = model.index - makeCurrentTimer.restart() - } - } } diff --git a/wallpapers/image/imagepackage/contents/ui/config.qml b/wallpapers/image/imagepackage/contents/ui/config.qml --- a/wallpapers/image/imagepackage/contents/ui/config.qml +++ b/wallpapers/image/imagepackage/contents/ui/config.qml @@ -288,24 +288,18 @@ color: cfg_Color } + onCountChanged: { + wallpapersGrid.currentIndex = imageWallpaper.wallpaperModel.indexOf(cfg_Image); + wallpapersGrid.positionViewAtIndex(wallpapersGrid.currentIndex, GridView.Visible) + } + Connections { target: root onRestoreIndex: { wallpapersGrid.currentIndex = wallpapersGrid.currentIndex - count } } - Timer { - id: makeCurrentTimer - interval: 100 - repeat: false - property string pendingIndex - onTriggered: { - wallpapersGrid.currentIndex = pendingIndex - wallpapersGrid.forceActiveFocus(); - } - } - Keys.onPressed: { if (count < 1) { return; @@ -325,7 +319,9 @@ Connections { target: imageWallpaper - onCustomWallpaperPicked: wallpapersGrid.currentIndex = 0 + onCustomWallpaperPicked: { + wallpapersGrid.currentIndex = 0 + } } } diff --git a/wallpapers/image/imagepackage/platformcontents/phone/ui/WallpaperDelegate.qml b/wallpapers/image/imagepackage/platformcontents/phone/ui/WallpaperDelegate.qml --- a/wallpapers/image/imagepackage/platformcontents/phone/ui/WallpaperDelegate.qml +++ b/wallpapers/image/imagepackage/platformcontents/phone/ui/WallpaperDelegate.qml @@ -30,10 +30,6 @@ property bool selected: (wallpapersGrid.currentIndex == index) - onSelectedChanged: { - cfg_Image = model.path - } - hoverEnabled: true @@ -130,11 +126,4 @@ } onExited: Tooltip.hideText() - - Component.onCompleted: { - if (cfg_Image == model.path) { - makeCurrentTimer.pendingIndex = model.index - makeCurrentTimer.restart() - } - } } diff --git a/wallpapers/image/imagepackage/platformcontents/phone/ui/config.qml b/wallpapers/image/imagepackage/platformcontents/phone/ui/config.qml --- a/wallpapers/image/imagepackage/platformcontents/phone/ui/config.qml +++ b/wallpapers/image/imagepackage/platformcontents/phone/ui/config.qml @@ -59,14 +59,10 @@ boundsBehavior: Flickable.DragAndOvershootBounds delegate: WallpaperDelegate {} - Timer { - id: makeCurrentTimer - interval: 100 - repeat: false - property string pendingIndex - onTriggered: { - wallpapersGrid.currentIndex = pendingIndex - } + + onCountChanged: { + wallpapersGrid.currentIndex = imageWallpaper.wallpaperModel.indexOf(cfg_Image); + wallpapersGrid.positionViewAtIndex(wallpapersGrid.currentIndex, GridView.Visible) } Connections { diff --git a/wallpapers/image/imagepackage/platformcontents/touch/ui/WallpaperDelegate.qml b/wallpapers/image/imagepackage/platformcontents/touch/ui/WallpaperDelegate.qml --- a/wallpapers/image/imagepackage/platformcontents/touch/ui/WallpaperDelegate.qml +++ b/wallpapers/image/imagepackage/platformcontents/touch/ui/WallpaperDelegate.qml @@ -30,10 +30,6 @@ property bool selected: (wallpapersGrid.currentIndex == index) - onSelectedChanged: { - cfg_Image = model.path - } - hoverEnabled: true PlasmaCore.FrameSvgItem { @@ -80,11 +76,4 @@ wallpapersGrid.currentIndex = (wallpapersGrid.currentPage*wallpapersGrid.pageSize) + index cfg_Image = model.path } - - Component.onCompleted: { - if (cfg_Image == model.path) { - makeCurrentTimer.pendingIndex = model.index - makeCurrentTimer.restart() - } - } } diff --git a/wallpapers/image/imagepackage/platformcontents/touch/ui/config.qml b/wallpapers/image/imagepackage/platformcontents/touch/ui/config.qml --- a/wallpapers/image/imagepackage/platformcontents/touch/ui/config.qml +++ b/wallpapers/image/imagepackage/platformcontents/touch/ui/config.qml @@ -62,20 +62,15 @@ delegateHeight: delegateWidth / 1.6 delegate: WallpaperDelegate {} - Timer { - id: makeCurrentTimer - interval: 100 - repeat: false - property string pendingIndex - onTriggered: { - wallpapersGrid.currentIndex = pendingIndex - wallpapersGrid.positionViewAtIndex(pendingIndex, ListView.Beginning) - } + + onCountChanged: { + wallpapersGrid.currentIndex = imageWallpaper.wallpaperModel.indexOf(cfg_Image); + wallpapersGrid.positionViewAtIndex(wallpapersGrid.currentIndex, GridView.Visible) } Connections { target: imageWallpaper - onCustomWallpaperPicked: wallpapersGrid.currentIndex = 0 - } + onCustomWallpaperPicked: wallpapersGrid.currentIndex = 0 + } } }