Skip to content

Commit

Permalink
Merge pull request #30 from rodlie/6.0-fix2
Browse files Browse the repository at this point in the history
fix broken bookmarks data
  • Loading branch information
rodlie authored Jul 7, 2018
2 parents 39c32ab + 8a73811 commit e2a82b7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
31 changes: 17 additions & 14 deletions fm/src/bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "bookmarkmodel.h"
#include "icondlg.h"
#include "mainwindow.h"
#include "common.h"

//---------------------------------------------------------------------------
void MainWindow::addBookmarkAction()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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();
}
Expand All @@ -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()));
}

Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions fm/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(); }
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion fm/src/propertiesdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#else
#endif

#include "common.h"
#include "propertiesdlg.h"
#include "icondlg.h"
#include "mainwindow.h"
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions libfm/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e2a82b7

Please sign in to comment.