location bar 显示

This commit is contained in:
yangling 2022-11-18 14:45:23 +08:00
parent be42976eca
commit 349b10b62c
6 changed files with 40 additions and 8 deletions

View File

@ -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:"<<info->uri();
// 避免上一次的取消操作影响此次的结果,这个通常发生在极短时间内进行连续跳转的情况下
// 从peony的交互来看基本不会触发但是文件对话框的流程可能会触发这种情况

View File

@ -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();
}

View File

@ -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<QString> 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);

View File

@ -81,6 +81,9 @@ public:
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
QSet<QString> getFileUrisFromLabelId(int labelId);
QString getLabelNameFromLabelId(int id);
int getLabelIdFromLabelName(const QString &colorName);
Q_SIGNALS:
void fileLabelChanged(const QString &uri);

View File

@ -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<QString> uriSet = FileLabelModel::getGlobalModel()->getFileUrisFromLabelId(labelId);
for(const QString &str: uriSet){
QUrl url = QUrl(str);

View File

@ -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);
}