From 8a7381114f7e210ed128974d7796c7a751a559f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Sat, 7 Jul 2018 11:25:05 +0200 Subject: [PATCH] fix broken bookmarks data --- fm/src/bookmarks.cpp | 31 +++++++++++++++++-------------- fm/src/mainwindow.cpp | 12 ++++++------ fm/src/propertiesdlg.cpp | 3 ++- libfm/common.h | 4 ++++ 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/fm/src/bookmarks.cpp b/fm/src/bookmarks.cpp index 3e759e0..b2dc61f 100644 --- a/fm/src/bookmarks.cpp +++ b/fm/src/bookmarks.cpp @@ -28,6 +28,7 @@ #include "bookmarkmodel.h" #include "icondlg.h" #include "mainwindow.h" +#include "common.h" //--------------------------------------------------------------------------- void MainWindow::addBookmarkAction() @@ -66,13 +67,15 @@ void bookmarkmodel::addBookmark(QString name, QString path, QString isAuto, QStr QIcon theIcon; theIcon = QIcon::fromTheme(icon,QApplication::style()->standardIcon(QStyle::SP_DirIcon)); - if(icon.isEmpty()) if(folderIcons->contains(name)) theIcon = folderIcons->value(name); + if(icon.isEmpty()) { + if(folderIcons->contains(name)) { theIcon = folderIcons->value(name); } + } if(name.isEmpty()) name = "/"; QStandardItem *item = new QStandardItem(theIcon,name); - item->setData(path,32); - item->setData(icon,33); - item->setData(isAuto,34); + item->setData(path, BOOKMARK_PATH); + item->setData(icon, BOOKMARK_ICON); + item->setData(isAuto, BOOKMARKS_AUTO); item->setData(isMedia, MEDIA_MODEL); if (isMedia) { item->setData(mediaPath, MEDIA_PATH); } this->appendRow(item); @@ -141,10 +144,10 @@ void MainWindow::delBookmark() while(!list.isEmpty()) { - if(list.first().data(34).toString() == "1") //automount, add to dontShowList + if(list.first().data(BOOKMARKS_AUTO).toString() == "1") //automount, add to dontShowList { QStringList temp = settings->value("hideBookmarks",0).toStringList(); - temp.append(list.first().data(32).toString()); + temp.append(list.first().data(BOOKMARK_PATH).toString()); settings->setValue("hideBookmarks",temp); } modelBookmarks->removeRow(list.first().row()); @@ -160,7 +163,7 @@ void MainWindow::editBookmark() if(themeIcons->exec() == 1) { QStandardItem * item = modelBookmarks->itemFromIndex(bookmarksList->currentIndex()); - item->setData(themeIcons->result,33); + item->setData(themeIcons->result, BOOKMARK_ICON); item->setIcon(QIcon::fromTheme(themeIcons->result)); handleBookmarksChanged(); } @@ -178,30 +181,30 @@ void MainWindow::toggleWrapBookmarks() void MainWindow::bookmarkPressed(QModelIndex current) { if (current.data(MEDIA_MODEL).toBool() && !current.data(MEDIA_PATH).toString().isEmpty()) { - if (current.data(32).toString().isEmpty()) { + if (current.data(BOOKMARK_PATH).toString().isEmpty()) { disks->devices[current.data(MEDIA_PATH).toString()]->mount(); } } if(QApplication::mouseButtons() == Qt::MidButton) - tabs->setCurrentIndex(addTab(current.data(32).toString())); + tabs->setCurrentIndex(addTab(current.data(BOOKMARK_PATH).toString())); } //--------------------------------------------------------------------------- void MainWindow::bookmarkClicked(QModelIndex item) { - if(item.data(32).toString() == pathEdit->currentText()) return; + if(item.data(BOOKMARK_PATH).toString() == pathEdit->currentText()) return; if (item.data(MEDIA_MODEL).toBool() && !item.data(MEDIA_PATH).toString().isEmpty()) { - if (item.data(32).toString().isEmpty()) { + if (item.data(BOOKMARK_PATH).toString().isEmpty()) { disks->devices[item.data(MEDIA_PATH).toString()]->mount(); } } - QString info(item.data(32).toString()); + QString info(item.data(BOOKMARK_PATH).toString()); if(info.isEmpty()) return; //separator if(info.contains("/.")) modelList->setRootPath(info); //hidden folders - tree->setCurrentIndex(modelTree->mapFromSource(modelList->index(item.data(32).toString()))); + tree->setCurrentIndex(modelTree->mapFromSource(modelList->index(item.data(BOOKMARK_PATH).toString()))); status->showMessage(getDriveInfo(curIndex.filePath())); } @@ -238,7 +241,7 @@ bool bookmarkmodel::dropMimeData(const QMimeData * data,Qt::DropAction action,in cutList.append(file.filePath()); } - emit bookmarkPaste(data, parent.data(32).toString(), cutList); + emit bookmarkPaste(data, parent.data(BOOKMARK_PATH).toString(), cutList); return false; } diff --git a/fm/src/mainwindow.cpp b/fm/src/mainwindow.cpp index c567ca1..551f66c 100644 --- a/fm/src/mainwindow.cpp +++ b/fm/src/mainwindow.cpp @@ -531,9 +531,9 @@ void MainWindow::writeBookmarks() if (modelBookmarks->item(i)->data(MEDIA_MODEL).toBool()) { continue; } // ignore media devices QStringList temp; temp << modelBookmarks->item(i)->text() - << modelBookmarks->item(i)->data(32).toString() - << modelBookmarks->item(i)->data(34).toString() - << modelBookmarks->item(i)->data(33).toString(); + << modelBookmarks->item(i)->data(BOOKMARK_PATH).toString() + << modelBookmarks->item(i)->data(BOOKMARKS_AUTO).toString() + << modelBookmarks->item(i)->data(BOOKMARK_ICON).toString(); settings->setValue(QString(i),temp); } settings->endGroup(); @@ -1153,7 +1153,7 @@ void MainWindow::folderPropertiesLauncher() { QModelIndexList selList; if(focusWidget() == bookmarksList) { - selList.append(modelView->mapFromSource(modelList->index(bookmarksList->currentIndex().data(32).toString()))); + selList.append(modelView->mapFromSource(modelList->index(bookmarksList->currentIndex().data(BOOKMARK_PATH).toString()))); } else if(focusWidget() == list || focusWidget() == detailTree) { if (listSelectionModel->selectedRows(0).count()) { selList = listSelectionModel->selectedRows(0); } else { selList = listSelectionModel->selectedIndexes(); } @@ -1383,7 +1383,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent * event) { if (focusWidget() == bookmarksList) { listSelectionModel->clearSelection(); if (bookmarksList->indexAt(bookmarksList->mapFromGlobal(event->globalPos())).isValid()) { - curIndex = bookmarksList->currentIndex().data(32).toString(); + curIndex = bookmarksList->currentIndex().data(BOOKMARK_PATH).toString(); isMedia = bookmarksList->currentIndex().data(MEDIA_MODEL).toBool(); if (!isMedia) { popup->addAction(delBookmarkAct); @@ -1563,7 +1563,7 @@ void MainWindow::handleMediaMountpointChanged(QString path, QString mountpoint) if (path.isEmpty()) { return; } for (int i = 0; i < modelBookmarks->rowCount(); i++) { if (modelBookmarks->item(i)->data(MEDIA_MODEL).toBool() && modelBookmarks->item(i)->data(MEDIA_PATH).toString() == path) { - modelBookmarks->item(i)->setData(disks->devices[path]->mountpoint, 32); + modelBookmarks->item(i)->setData(disks->devices[path]->mountpoint, BOOKMARK_PATH); } } } diff --git a/fm/src/propertiesdlg.cpp b/fm/src/propertiesdlg.cpp index cf5f9e9..4a3be0f 100644 --- a/fm/src/propertiesdlg.cpp +++ b/fm/src/propertiesdlg.cpp @@ -28,6 +28,7 @@ #else #endif +#include "common.h" #include "propertiesdlg.h" #include "icondlg.h" #include "mainwindow.h" @@ -279,7 +280,7 @@ void PropertiesDialog::recurseProperties(QString path) if(it.fileInfo().isDir()) { folders++; - if(folders % 32 == 0) emit updateSignal(); + if(folders % BOOKMARK_PATH == 0) emit updateSignal(); } else { diff --git a/libfm/common.h b/libfm/common.h index 79f6412..f01f46a 100644 --- a/libfm/common.h +++ b/libfm/common.h @@ -16,6 +16,10 @@ #define FM_MAJOR 6 +#define BOOKMARK_PATH Qt::UserRole+1 +#define BOOKMARK_ICON Qt::UserRole+2 +#define BOOKMARKS_AUTO Qt::UserRole+3 + class Common { public: