[FEATURE] #13156 回收站增加原始路径支持

This commit is contained in:
Yue-Lan 2022-05-19 14:31:38 +08:00
parent b0e9e157f9
commit 1dd0f98cbe
8 changed files with 44 additions and 0 deletions

View File

@ -614,6 +614,11 @@ const QList<QAction *> DirectoryViewMenu::constructViewOpActions()
tmp<<sortTypeMenu->addAction(tr("Modified Date"));
tmp<<sortTypeMenu->addAction(tr("File Type"));
tmp<<sortTypeMenu->addAction(tr("File Size"));
tmp<<sortTypeMenu->addAction(tr("Orignal Path"));
if (m_top_window->getCurrentUri() != "trash:///") {
tmp.last()->setVisible(false);
}
int sortType = m_view->getSortType();
if (sortType >= 0) {
tmp.at(sortType)->setCheckable(true);

View File

@ -418,6 +418,10 @@ void FileInfoJob::refreshInfoContents(GFileInfo *new_info)
info->m_deletion_date_uint64 = dateTime.toMSecsSinceEpoch ();
}
if (g_file_info_has_attribute(new_info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH)) {
auto origPath = g_file_info_get_attribute_byte_string(new_info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH);
info->setProperty("orig-path", origPath);
}
m_info->m_meta_info = FileMetaInfo::fromGFileInfo(m_info->uri(), new_info);
// update peony qt color list after meta info updated.

View File

@ -199,6 +199,9 @@ QModelIndex FileItemModel::parent(const QModelIndex &child) const
int FileItemModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
if (m_root_uri == "trash:///") {
return FileSize + 2;
}
return FileSize+1;
}
@ -312,6 +315,17 @@ QVariant FileItemModel::data(const QModelIndex &index, int role) const
return QVariant();
}
}
case TrashOriginPath: {
switch (role) {
case Qt::DisplayRole:
case Qt::ToolTipRole: {
return item->m_info->property("orig-path");
break;
}
default:
break;
}
}
default:
return QVariant();
}
@ -335,6 +349,8 @@ QVariant FileItemModel::headerData(int section, Qt::Orientation orientation, int
return tr("File Type");
case FileSize:
return tr("File Size");
case TrashOriginPath:
return tr("Original Path");
default:
return QVariant();
}

View File

@ -57,6 +57,7 @@ public:
ModifiedDate,
FileType,
FileSize,
TrashOriginPath,
Owner,
Other
};

View File

@ -417,6 +417,8 @@ void HeaderBar::addMenuButtons()
m_window->setCurrentSortOrder(order);
});
connect(sortTypeMenu, &QMenu::aboutToShow, sortTypeMenu, [=]() {
bool originPathVisible = m_window->getCurrentUri() == "trash:///";
sortTypeMenu->setOriginPathVisible(originPathVisible);
sortTypeMenu->setSortType(m_window->getCurrentSortColumn());
sortTypeMenu->setSortOrder(m_window->getCurrentSortOrder());
});

View File

@ -47,6 +47,11 @@ SortTypeMenu::SortTypeMenu(QWidget *parent) : QMenu(parent)
fileSize->setCheckable(true);
sortTypeGroup->addAction(fileSize);
auto originalPath = addAction(tr("Original Path"));
m_origin_path = originalPath;
originalPath->setCheckable(true);
sortTypeGroup->addAction(originalPath);
connect(sortTypeGroup, &QActionGroup::triggered, this, [=](QAction *action) {
int index = sortTypeGroup->actions().indexOf(action);
switchSortTypeRequest(index);
@ -84,6 +89,11 @@ SortTypeMenu::SortTypeMenu(QWidget *parent) : QMenu(parent)
addAction(useGlobalSortAction);
}
void SortTypeMenu::setOriginPathVisible(bool visible)
{
m_origin_path->setVisible(visible);
}
void SortTypeMenu::setSortType(int type)
{
m_sort_types->actions().at(type)->setChecked(true);

View File

@ -31,6 +31,8 @@ class SortTypeMenu : public QMenu
public:
explicit SortTypeMenu(QWidget *parent = nullptr);
void setOriginPathVisible(bool visible);
Q_SIGNALS:
void switchSortTypeRequest(int type);
void switchSortOrderRequest(Qt::SortOrder order);
@ -43,6 +45,7 @@ private:
int m_sort_type = 0;
Qt::SortOrder m_sort_order = Qt::AscendingOrder;
QAction *m_origin_path = nullptr;
QActionGroup *m_sort_types;
QActionGroup *m_sort_orders;
};

View File

@ -1158,6 +1158,9 @@ int TabWidget::getSortType()
//fix switch to computer view and back change to default sort issue, link to bug#92261
auto settings = Peony::GlobalSettings::getInstance();
auto sortType = settings->isExist(SORT_COLUMN)? settings->getValue(SORT_COLUMN).toInt() : 0;
if (getCurrentUri() != "trash:///" && sortType == 4) {
sortType = 0;
}
return sortType;