diff --git a/libpeony-qt/controls/navigation-bar/location-bar/location-bar.cpp b/libpeony-qt/controls/navigation-bar/location-bar/location-bar.cpp index 8302337c..b21ddc3c 100644 --- a/libpeony-qt/controls/navigation-bar/location-bar/location-bar.cpp +++ b/libpeony-qt/controls/navigation-bar/location-bar/location-bar.cpp @@ -199,7 +199,7 @@ void LocationBar::setRootUri(const QString &uri) infoJob->cancel(); }); connect(infoJob, &FileInfoJob::queryAsyncFinished, this, [=](bool successed){ - if (!successed) { + if (!successed && !info.get()->uri().startsWith("label://")) { qWarning()<<"can not query file:"<uri(); // 避免上一次的取消操作影响此次的结果,这个通常发生在极短时间内进行连续跳转的情况下 // 从peony的交互来看基本不会触发,但是文件对话框的流程可能会触发这种情况 diff --git a/libpeony-qt/file-utils.cpp b/libpeony-qt/file-utils.cpp index 1365fb07..67211bfa 100644 --- a/libpeony-qt/file-utils.cpp +++ b/libpeony-qt/file-utils.cpp @@ -343,6 +343,7 @@ QString FileUtils::getNonSuffixedBaseNameFromUri(const QString &uri) } } +#include "file-label-model.h" QString FileUtils::getFileDisplayName(const QString &uri) { auto fileInfo = FileInfo::fromUri(uri); @@ -363,6 +364,15 @@ QString FileUtils::getFileDisplayName(const QString &uri) return showName; } } + if(uri.startsWith("label://")){/* 标记模式uri的displayName */ + if("label:///" == uri){ + showName = "label"; + }else{ + showName = uri.section("/", -1,-1).replace("?schema=file",""); + } + return showName; + } + return fileInfo.get()->displayName(); } diff --git a/libpeony-qt/model/file-label-model.cpp b/libpeony-qt/model/file-label-model.cpp index 7064978e..9a1ad10c 100644 --- a/libpeony-qt/model/file-label-model.cpp +++ b/libpeony-qt/model/file-label-model.cpp @@ -305,7 +305,7 @@ void FileLabelModel::addLabelToFile(const QString &uri, int labelId) /* 同步全局标记 */ QUrl url(uri); - QString labelUri = QString("label:///").append(QString::number(labelId)) + url.path() + "?schema=" + url.scheme(); + QString labelUri = QString("label:///").append(getLabelNameFromLabelId(labelId)) + url.path() + "?schema=" + url.scheme(); Q_EMIT fileLabelAdded(labelUri, true);//end auto metaInfo = Peony::FileMetaInfo::fromUri(uri); @@ -360,7 +360,7 @@ void FileLabelModel::removeFileLabel(const QString &uri, int labelId) } /* 同步全局标记 */ QUrl url(uri); - QString labelUri = QString("label:///").append(QString::number(id)) + url.path() + "?schema=" + url.scheme(); + QString labelUri = QString("label:///").append(getLabelNameFromLabelId(id)) + url.path() + "?schema=" + url.scheme(); Q_EMIT fileLabelRemoved(labelUri, true); } m_label_settings->endGroup(); @@ -445,6 +445,26 @@ QSet FileLabelModel::getFileUrisFromLabelId(int labelId) return uriSet; } +int FileLabelModel::getLabelIdFromLabelName(const QString &colorName) +{ + for (auto item : m_labels) { + if (item->name() == colorName) { + return item->id(); + } + } + return 0; +} + +QString FileLabelModel::getLabelNameFromLabelId(int id) +{ + for (auto item : m_labels) { + if (item->id() == id) { + return item->name(); + } + } + return QString(); +} + void FileLabelModel::setName(FileLabelItem *item, const QString &name) { m_label_settings->beginWriteArray("labels", lastLabelId() + 1); diff --git a/libpeony-qt/model/file-label-model.h b/libpeony-qt/model/file-label-model.h index 2b065400..fa74c2c4 100644 --- a/libpeony-qt/model/file-label-model.h +++ b/libpeony-qt/model/file-label-model.h @@ -81,6 +81,9 @@ public: bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; QSet getFileUrisFromLabelId(int labelId); + QString getLabelNameFromLabelId(int id); + int getLabelIdFromLabelName(const QString &colorName); + Q_SIGNALS: void fileLabelChanged(const QString &uri); diff --git a/libpeony-qt/vfs/label-vfs-file.cpp b/libpeony-qt/vfs/label-vfs-file.cpp index ef20dcdf..11c44334 100644 --- a/libpeony-qt/vfs/label-vfs-file.cpp +++ b/libpeony-qt/vfs/label-vfs-file.cpp @@ -236,7 +236,8 @@ gboolean vfs_label_file_delete (GFile* file, GCancellable* cancellable, GError** QUrl url(uri); QString realUri = QString("file:///").append(url.path().section("/", 2,-1)); QString encodeUri = Peony::FileUtils::getEncodedUri(realUri); - FileLabelModel::getGlobalModel()->removeFileLabel(encodeUri); + int labelId = FileLabelModel::getGlobalModel()->getLabelIdFromLabelName(url.path().section("/", 1, 1)); + FileLabelModel::getGlobalModel()->removeFileLabel(encodeUri, labelId); return TRUE; } @@ -309,8 +310,6 @@ GFileInfo* vfs_label_file_query_info(GFile *file, const char *attributes, GFileQ if ("label" == scheam) { trueUri = QString("%1://%2").arg("file").arg(url.path()); } else { - QString s =url.path(); - QString s1 = url.path().section("/",2,-1); trueUri = QString("%1:///%2").arg(scheam).arg(url.path().section("/",2,-1)); } break; @@ -440,7 +439,7 @@ void label_vfs_file_enumerator_parse_uri(LabelVFSFileEnumerator *enumerator, con LabelVFSFileEnumeratorPrivate *priv = enumerator->priv; *priv->label_vfs_directory_uri = uri; auto tmp = priv->label_vfs_directory_uri->section("/", -1,-1); - int labelId = tmp.toInt(); + int labelId = FileLabelModel::getGlobalModel()->getLabelIdFromLabelName(tmp); QSet uriSet = FileLabelModel::getGlobalModel()->getFileUrisFromLabelId(labelId); for(const QString &str: uriSet){ QUrl url = QUrl(str); diff --git a/src/control/tab-widget.cpp b/src/control/tab-widget.cpp index 9e34eb09..3dfb51b2 100644 --- a/src/control/tab-widget.cpp +++ b/src/control/tab-widget.cpp @@ -1287,7 +1287,7 @@ void TabWidget::addPage(const QString &uri, bool jumpTo) auto realUri = uri; if (info->isSymbolLink() && info->symlinkTarget().length() >0 && uri.startsWith("file://")) { realUri = "file://" + info->symlinkTarget(); - } else if (!info->isDir() && !realUri.startsWith("smb://") ) { + } else if (!info->isDir() && !realUri.startsWith("smb://") && !realUri.startsWith("label://") ) { realUri = Peony::FileUtils::getParentUri(uri); }