mirror of https://gitee.com/openkylin/peony.git
Update openkylin/yangtze
This commit is contained in:
parent
0b0ba4e278
commit
5d4351c8ae
18
common.pri
18
common.pri
|
@ -36,21 +36,3 @@ exists(/usr/include/kysdk/applications/ukuistylehelper/ukuistylehelper.h) {
|
|||
exists("/usr/include/libkyudfburn/udfburn_global.h") {
|
||||
DEFINES += KY_UDF_BURN
|
||||
}
|
||||
|
||||
exists("/usr/include/ukui-search/libsearch_global.h") {
|
||||
DEFINES += KY_UKUI_SEARCH
|
||||
}
|
||||
|
||||
exists("/usr/include/kysdk/desktop/kysdk-soundeffects_global.h") {
|
||||
DEFINES += KY_SDK_SOUND_EFFECTS
|
||||
PKGCONFIG += kysdk-soundeffects
|
||||
}
|
||||
|
||||
exists("/usr/include/kysdk/kysdk-system/libkydate.h") {
|
||||
DEFINES += KY_SDK_DATE
|
||||
}
|
||||
|
||||
exists(/usr/include/kysdk/kysdk-system/libkysysinfo.h) {
|
||||
message("kysysinfo find")
|
||||
DEFINES += KY_SDK_SYSINFO
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@ GenericName=Home
|
|||
GenericName[tr]=Giriş
|
||||
GenericName[zh_CN]=打开个人目录
|
||||
GenericName[bo_CN]=སྒེར་གྱི་དཀར་ཆག
|
||||
GenericName[mn]=ᠬᠤᠪᠢ ᠬᠦᠮᠦᠨ
|
||||
Name[tr]=Giriş
|
||||
Name[zh_CN]=个人目录
|
||||
Name[bo_CN]=སྒེར་གྱི་དཀར་ཆག
|
||||
Name[mn]=ᠬᠤᠪᠢ ᠬᠦᠮᠦᠨ
|
||||
Exec=/usr/bin/peony
|
||||
Icon=user-home
|
||||
Terminal=false
|
||||
|
|
|
@ -4,11 +4,9 @@ GenericName=Trash
|
|||
GenericName[tr]=Çöp
|
||||
GenericName[zh_CN]=打开回收站
|
||||
GenericName[bo_CN]=སྙིགས་སྒམ།
|
||||
GenericName[mn]=ᠬᠤᠭᠯᠠᠭᠤᠷ
|
||||
Name[tr]=Çöp
|
||||
Name[zh_CN]=回收站
|
||||
Name[bo_CN]=སྙིགས་སྒམ།
|
||||
Name[mn]=ᠬᠤᠭᠯᠠᠭᠤᠷ
|
||||
Exec=/usr/bin/peony trash:///
|
||||
Icon=user-trash
|
||||
Terminal=false
|
||||
|
|
|
@ -4,11 +4,9 @@ GenericName=UKUI File Manager
|
|||
GenericName[tr]=UKUI Dosya Yöneticisi
|
||||
GenericName[zh_CN]=文件管理器
|
||||
GenericName[bo_CN]=ཡིག་ཆ་དོ་དམ་ཆས།
|
||||
GenericName[mn]=ᠹᠠᠢᠯ ᠤ᠋ᠨ ᠬᠠᠮᠢᠶᠠᠷᠤᠭᠤᠷ
|
||||
Name[tr]=Peony
|
||||
Name[zh_CN]=文件管理器
|
||||
Name[bo_CN]=ཡིག་ཆ་དོ་དམ་ཆས།
|
||||
Name[mn]=ᠹᠠᠢᠯ ᠤ᠋ᠨ ᠬᠠᠮᠢᠶᠠᠷᠤᠭᠤᠷ
|
||||
Exec=/usr/bin/peony %U
|
||||
MimeType=inode/directory
|
||||
Icon=system-file-manager
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 130 KiB |
|
@ -140,7 +140,7 @@ ConnectServerDialog::ConnectServerDialog(QWidget *parent) : QDialog(parent)
|
|||
}
|
||||
setFixedSize(m_widget_size);
|
||||
setWindowIcon(QIcon::fromTheme("network-server"));
|
||||
setWindowTitle(tr("Connect to server"));
|
||||
setWindowTitle(tr("connect to server"));
|
||||
setBackgroundRole(QPalette::Base);
|
||||
setAutoFillBackground(true);
|
||||
|
||||
|
@ -165,10 +165,10 @@ ConnectServerDialog::ConnectServerDialog(QWidget *parent) : QDialog(parent)
|
|||
m_remote_port->append(ftpDefaultPortStr);
|
||||
m_remote_port->append(sftpDefaultPortStr);
|
||||
m_remote_port->append(sambaDefaultPortStr);
|
||||
m_ip_label->setText(tr("Ip"));
|
||||
m_ip_label->setText(tr("ip"));
|
||||
m_port_editor->setEditable(true);
|
||||
m_port_label->setText(tr("Port"));
|
||||
m_remote_type_label->setText(tr("Type"));
|
||||
m_port_label->setText(tr("port"));
|
||||
m_remote_type_label->setText(tr("type"));
|
||||
m_main_layout->setMargin(m_widget_margin);
|
||||
m_remote_type_edit->setAutoCompletion(true);
|
||||
m_ip_label->setFixedHeight(36);
|
||||
|
@ -212,9 +212,9 @@ ConnectServerDialog::ConnectServerDialog(QWidget *parent) : QDialog(parent)
|
|||
|
||||
m_main_layout->addSpacing(12);
|
||||
|
||||
m_btn_add->setText(tr("Add"));
|
||||
m_btn_del->setText(tr("Delete"));
|
||||
m_btn_conn->setText(tr("Connect"));
|
||||
m_btn_add->setText(tr("add"));
|
||||
m_btn_del->setText(tr("delete"));
|
||||
m_btn_conn->setText(tr("connect"));
|
||||
m_btn_layout->addWidget(m_btn_add);
|
||||
m_btn_layout->addWidget(m_btn_del);
|
||||
m_btn_layout->addSpacing(72);
|
||||
|
@ -267,7 +267,7 @@ ConnectServerDialog::ConnectServerDialog(QWidget *parent) : QDialog(parent)
|
|||
|
||||
connect(m_btn_del, &QPushButton::clicked, this, [=] (bool checked) {
|
||||
QString delUri = uri();
|
||||
if (m_favorite_list && m_favorite_list->currentItem() && delUri != m_favorite_list->currentItem()->text()) {
|
||||
if (!m_favorite_list && !m_favorite_list->currentItem() && delUri != m_favorite_list->currentItem()->text()) {
|
||||
delUri = m_favorite_list->currentItem()->text();
|
||||
}
|
||||
removeUri(delUri);
|
||||
|
@ -291,11 +291,11 @@ ConnectServerDialog::ConnectServerDialog(QWidget *parent) : QDialog(parent)
|
|||
|
||||
if (m_checkIp) {
|
||||
m_checkIp = false;
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("Ip input error, please re-enter!"), QMessageBox::Ok);
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("ip input error, please re-enter!"), QMessageBox::Ok);
|
||||
return;
|
||||
} else if (m_checkPort) {
|
||||
m_checkPort = false;
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("Port input error, please re-enter!"), QMessageBox::Ok);
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("port input error, please re-enter!"), QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
accept();
|
||||
|
@ -363,11 +363,11 @@ void ConnectServerDialog::addUri(QString uri)
|
|||
|
||||
if (m_checkIp) {
|
||||
m_checkIp = false;
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("Ip input error, please re-enter!"), QMessageBox::Ok);
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("ip input error, please re-enter!"), QMessageBox::Ok);
|
||||
return;
|
||||
} else if (m_checkPort) {
|
||||
m_checkPort = false;
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("Port input error, please re-enter!"), QMessageBox::Ok);
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("port input error, please re-enter!"), QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -456,7 +456,6 @@ ConnectServerLogin::ConnectServerLogin(QString uri, QWidget *parent)
|
|||
{
|
||||
if("bo_CN" == QLocale::system().name()){
|
||||
m_widget_size.setHeight(m_widget_size.height() + 61);
|
||||
m_widget_size.setWidth(m_widget_size.width() + 30);
|
||||
}
|
||||
setFixedSize(m_widget_size);
|
||||
if("bo_CN" == QLocale::system().name()){
|
||||
|
@ -480,7 +479,7 @@ ConnectServerLogin::ConnectServerLogin(QString uri, QWidget *parent)
|
|||
m_usr_btn_usr = new QRadioButton;
|
||||
|
||||
m_usr_label->setText(tr("User's identity"));
|
||||
m_usr_btn_guest->setText(tr("Guest"));
|
||||
m_usr_btn_guest->setText(tr("guest"));
|
||||
m_usr_btn_usr->setText(tr("Registered users"));
|
||||
m_usr_layout->addWidget(m_usr_label, 0, 0);
|
||||
m_usr_layout->addWidget(m_usr_btn_guest, 0, 1);
|
||||
|
@ -496,8 +495,8 @@ ConnectServerLogin::ConnectServerLogin(QString uri, QWidget *parent)
|
|||
m_reg_usr_layout = new QGridLayout;
|
||||
|
||||
m_reg_usr_name_editor->setEditable (true);
|
||||
m_reg_usr_name_label->setText(tr("Name"));
|
||||
m_reg_usr_passwd_label->setText(tr("Password"));
|
||||
m_reg_usr_name_label->setText(tr("name"));
|
||||
m_reg_usr_passwd_label->setText(tr("password"));
|
||||
m_reg_usr_combox->setText(tr("Remember the password"));
|
||||
m_reg_usr_name_label->setFixedHeight(36);
|
||||
m_reg_usr_passwd_label->setFixedHeight(36);
|
||||
|
@ -518,8 +517,8 @@ ConnectServerLogin::ConnectServerLogin(QString uri, QWidget *parent)
|
|||
m_btn_ok = new QPushButton;
|
||||
m_btn_layout = new QHBoxLayout;
|
||||
m_btn_layout->addSpacing(192);
|
||||
m_btn_cancel->setText(tr("Cancel"));
|
||||
m_btn_ok->setText(tr("OK"));
|
||||
m_btn_cancel->setText(tr("cancel"));
|
||||
m_btn_ok->setText(tr("ok"));
|
||||
m_btn_layout->addWidget(m_btn_cancel);
|
||||
m_btn_layout->addWidget(m_btn_ok);
|
||||
m_main_layout->addStretch();
|
||||
|
@ -637,16 +636,6 @@ bool ConnectServerLogin::savePassword()
|
|||
return m_reg_usr_combox->isChecked();
|
||||
}
|
||||
|
||||
void ConnectServerLogin::setCurrentUserName(QString &name)
|
||||
{
|
||||
m_reg_usr_name_editor->setCurrentText(name);
|
||||
}
|
||||
|
||||
void ConnectServerLogin::setCurrentPasswd(QString &passwd)
|
||||
{
|
||||
m_reg_usr_passwd_editor->setText(passwd);
|
||||
}
|
||||
|
||||
void ConnectServerLogin::syncRemoteServer(const QUrl& url)
|
||||
{
|
||||
if (GlobalSettings::getInstance()->isExist(REMOTE_SERVER_REMOTE_IP)) {
|
||||
|
|
|
@ -103,8 +103,6 @@ public:
|
|||
QString password();
|
||||
bool anonymous();
|
||||
bool savePassword();
|
||||
void setCurrentUserName(QString &name);
|
||||
void setCurrentPasswd(QString &passwd);
|
||||
|
||||
void syncRemoteServer(const QUrl& url);
|
||||
QString getPassWordProperty();
|
||||
|
|
|
@ -11,10 +11,8 @@ include(tool-bar/tool-bar.pri)
|
|||
include(tab-page/tab-page.pri)
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/icon-container.h \
|
||||
$$PWD/tag-management.h
|
||||
$$PWD/icon-container.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/icon-container.cpp \
|
||||
$$PWD/tag-management.cpp
|
||||
$$PWD/icon-container.cpp
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
|
||||
#include "file-operation-manager.h"
|
||||
#include "file-rename-operation.h"
|
||||
#include "file-batch-rename-operation.h"
|
||||
|
||||
#include "emblem-provider.h"
|
||||
|
||||
|
@ -46,7 +45,6 @@
|
|||
#include <QStyle>
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QDBusReply>
|
||||
|
||||
#include "icon-view-editor.h"
|
||||
#include "icon-view-index-widget.h"
|
||||
|
@ -421,9 +419,7 @@ QWidget *IconViewDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
|
|||
auto edit = new IconViewEditor(parent);
|
||||
edit->setContentsMargins(0, 0, 0, 0);
|
||||
edit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
auto size = sizeHint(option, index);
|
||||
edit->setMinimumWidth(size.width());
|
||||
edit->setMinimumHeight(size.height() - getView()->iconSize().height() - 5);
|
||||
edit->setMinimumSize(sizeHint(option, index).width(), 54);
|
||||
|
||||
edit->blockSignals(true);
|
||||
auto displayString = index.data(Qt::DisplayRole).toString();
|
||||
|
@ -431,27 +427,10 @@ QWidget *IconViewDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
|
|||
auto uri = index.data(Qt::UserRole).toString();
|
||||
auto suffix = displayName.remove(displayString);
|
||||
auto fsType = FileUtils::getFsTypeFromFile(uri);
|
||||
auto info = FileInfo::fromUri(uri);
|
||||
if (info->isDesktopFile()) {
|
||||
suffix = ".desktop";
|
||||
}
|
||||
if (FileUtils::isFuseFileSystem(uri)) {
|
||||
fsType = "fuse.kyfs";
|
||||
}
|
||||
if (fsType.contains("ext")) {
|
||||
edit->setMaxLengthLimit(255 - suffix.toLocal8Bit().length());
|
||||
} else if (fsType.contains("ntfs")) {
|
||||
edit->setLimitBytes(false);
|
||||
edit->setMaxLengthLimit(255 - suffix.length());
|
||||
} else if (fsType.contains("fuse.kyfs")) {
|
||||
int32_t maxLength = 255;
|
||||
edit->setLimitBytes(false);
|
||||
QDBusInterface iface ("com.kylin.file.system.fuse","/com/kylin/file/system/fuse","com.kylin.file.system.fuse",QDBusConnection::systemBus());
|
||||
QDBusReply<int32_t> reply = iface.call("GetFilenameLength");
|
||||
if (reply.isValid()) {
|
||||
maxLength = reply.value();
|
||||
}
|
||||
edit->setMaxLengthLimit(maxLength - suffix.length());
|
||||
}
|
||||
edit->setText(displayString);
|
||||
edit->blockSignals(false);
|
||||
|
@ -515,7 +494,8 @@ void IconViewDelegate::setEditorData(QWidget *editor, const QModelIndex &index)
|
|||
|
||||
void IconViewDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QStyledItemDelegate::updateEditorGeometry(editor, option, index);
|
||||
//fix I7GW9E 选中时候拉动边框文本会缩略导致闪
|
||||
//QStyledItemDelegate::updateEditorGeometry(editor, option, index);
|
||||
auto edit = qobject_cast<IconViewEditor*>(editor);
|
||||
if (!edit)
|
||||
return;
|
||||
|
@ -544,48 +524,21 @@ void IconViewDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
|||
newName = "";
|
||||
//comment new name != suffix check to fix feedback issue
|
||||
if (newName.length() >0 && newName != oldName/* && newName != suffix*/) {
|
||||
if (getView()->getSelections().count() > 1) {
|
||||
auto fileOpMgr = FileOperationManager::getInstance();
|
||||
QStringList uris = getView()->getSelections();
|
||||
auto renameOp = new FileBatchRenameOperation(uris, newName);
|
||||
connect(renameOp, &FileBatchRenameOperation::operationFinished, getView(), [=](){
|
||||
auto info = renameOp->getOperationInfo().get();
|
||||
auto uri = info->target();
|
||||
QTimer::singleShot(100, getView(), [=](){
|
||||
auto infoJob = new Peony::FileInfoJob(Peony::FileInfo::fromUri(uri));
|
||||
infoJob->setAutoDelete();
|
||||
connect(infoJob, &Peony::FileInfoJob::queryAsyncFinished, this, [=]() {
|
||||
getView()->setSelections(QStringList()<<uri);
|
||||
getView()->scrollToSelection(uri);
|
||||
//set focus to fix bug#54061
|
||||
getView()->setFocus();
|
||||
});
|
||||
infoJob->queryAsync();
|
||||
});
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
auto fileOpMgr = FileOperationManager::getInstance();
|
||||
auto renameOp = new FileRenameOperation(index.data(FileItemModel::UriRole).toString(), newName);
|
||||
|
||||
fileOpMgr->startOperation(renameOp, true);
|
||||
} else {
|
||||
auto fileOpMgr = FileOperationManager::getInstance();
|
||||
auto renameOp = new FileRenameOperation(index.data(FileItemModel::UriRole).toString(), newName);
|
||||
connect(renameOp, &FileRenameOperation::operationFinished, getView(), [=](){
|
||||
auto info = renameOp->getOperationInfo().get();
|
||||
auto uri = info->target();
|
||||
QTimer::singleShot(100, getView(), [=](){
|
||||
auto infoJob = new Peony::FileInfoJob(Peony::FileInfo::fromUri(uri));
|
||||
infoJob->setAutoDelete();
|
||||
connect(infoJob, &Peony::FileInfoJob::queryAsyncFinished, this, [=]() {
|
||||
getView()->setSelections(QStringList()<<uri);
|
||||
getView()->scrollToSelection(uri);
|
||||
//set focus to fix bug#54061
|
||||
getView()->setFocus();
|
||||
});
|
||||
infoJob->queryAsync();
|
||||
});
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
connect(renameOp, &FileRenameOperation::operationFinished, getView(), [=](){
|
||||
auto info = renameOp->getOperationInfo().get();
|
||||
auto uri = info->target();
|
||||
QTimer::singleShot(100, getView(), [=](){
|
||||
getView()->setSelections(QStringList()<<uri);
|
||||
getView()->scrollToSelection(uri);
|
||||
//set focus to fix bug#54061
|
||||
getView()->setFocus();
|
||||
});
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
|
||||
fileOpMgr->startOperation(renameOp, true);
|
||||
}
|
||||
fileOpMgr->startOperation(renameOp, true);
|
||||
}
|
||||
else if (newName == oldName)
|
||||
{
|
||||
|
@ -669,7 +622,6 @@ void IconViewTextHelper::paintText(QPainter *painter, const QStyleOptionViewItem
|
|||
document.setIndentWidth(0);
|
||||
document.setDocumentMargin(0);
|
||||
|
||||
bool isElided= false;
|
||||
//计算text的长度
|
||||
while (true) {
|
||||
QTextLine line = textLayout.createLine();
|
||||
|
@ -678,18 +630,14 @@ void IconViewTextHelper::paintText(QPainter *painter, const QStyleOptionViewItem
|
|||
|
||||
int nextLineY = y + lineSpacing;
|
||||
lineCount++;
|
||||
y = nextLineY;
|
||||
if (1 == lineCount) {
|
||||
line.setLineWidth(width-xOffset);
|
||||
|
||||
if (textMaxHeight >= nextLineY + lineSpacing && lineCount != maxLineCount) {
|
||||
line.setLineWidth(width-xOffset);
|
||||
y = nextLineY;
|
||||
} else {
|
||||
line.setLineWidth(width);
|
||||
}
|
||||
if (textMaxHeight < nextLineY + lineSpacing || lineCount == maxLineCount) {
|
||||
QString lastLine = option.text.mid(line.textStart());
|
||||
QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width);
|
||||
if (elidedLastLine != lastLine) {
|
||||
isElided = true;
|
||||
}
|
||||
elidedText = option.text.left(line.textStart()) + elidedLastLine;
|
||||
textOpt.setWrapMode(QTextOption::NoWrap);
|
||||
line = textLayout.createLine();
|
||||
|
@ -705,6 +653,7 @@ void IconViewTextHelper::paintText(QPainter *painter, const QStyleOptionViewItem
|
|||
QTextCursor cursor(&document);
|
||||
|
||||
cursor.beginEditBlock();
|
||||
|
||||
QTextBlock textStyleBlock = cursor.block();
|
||||
QTextBlockFormat textStyleFormat = textStyleBlock.blockFormat();
|
||||
textStyleFormat.setLineHeight(lineSpacing, QTextBlockFormat::FixedHeight);
|
||||
|
@ -720,154 +669,20 @@ void IconViewTextHelper::paintText(QPainter *painter, const QStyleOptionViewItem
|
|||
cursor.mergeCharFormat(selectColorFormat);
|
||||
}
|
||||
|
||||
if (!regFindKeyWords.isEmpty()) {
|
||||
//对特殊字符进行处理
|
||||
QString escapedKeywords = QRegularExpression::escape(regFindKeyWords);
|
||||
QRegularExpression regex(escapedKeywords);
|
||||
QRegularExpressionMatchIterator matchIterator = regex.globalMatch(option.text);
|
||||
|
||||
while (matchIterator.hasNext()) {
|
||||
QRegularExpressionMatch match = matchIterator.next();
|
||||
int startPos = match.capturedStart();
|
||||
int endPos = match.capturedEnd();
|
||||
int oo = elidedText.size();
|
||||
// 判断是否关键字被省略
|
||||
if (isElided && startPos >= elidedText.size() - 1) {
|
||||
break; // 关键字被完全省略,退出循环
|
||||
}
|
||||
|
||||
// 调整关键字的结束位置
|
||||
if (endPos > elidedText.size()) {
|
||||
endPos = elidedText.size() ; // 关键字的一部分被省略,将结束位置调整为最后一个字符的位置
|
||||
}
|
||||
|
||||
// 执行关键字高亮
|
||||
highlightCursor.setPosition(startPos);
|
||||
highlightCursor.setPosition(endPos, QTextCursor::KeepAnchor);
|
||||
while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
|
||||
highlightCursor = document.find(regFindKeyWords, highlightCursor);
|
||||
if (!highlightCursor.isNull()) {
|
||||
highlightCursor.mergeCharFormat(colorFormat);
|
||||
}
|
||||
|
||||
}
|
||||
cursor.endEditBlock();
|
||||
document.drawContents(painter);
|
||||
document.drawContents(painter/*, rect*/);
|
||||
|
||||
textLayout.endLayout();
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
qreal IconViewTextHelper::drawText(QPainter *painter, const QStyleOptionViewItem &option, int textMaxHeight, int xOffset, const QString ®FindKeyWords, int horizalMargin, int maxLineCount)
|
||||
{
|
||||
painter->save();
|
||||
QFont font = option.font;
|
||||
QTextLayout textLayout(option.text, font);
|
||||
QTextOption textOpt;
|
||||
textOpt.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||
textLayout.setTextOption(textOpt);
|
||||
textLayout.beginLayout();
|
||||
|
||||
auto fontMetrics = option.fontMetrics;
|
||||
auto lineSpacing = fontMetrics.lineSpacing();
|
||||
int width = option.rect.width() - 2*horizalMargin;
|
||||
int y = 0;
|
||||
int lineCount = 0;
|
||||
QString elidedText = option.text;
|
||||
|
||||
QTextDocument document;
|
||||
textOpt.setAlignment(Qt::AlignHCenter);
|
||||
document.setDefaultTextOption(textOpt);
|
||||
document.setTextWidth(width);
|
||||
document.setDefaultFont(option.font);
|
||||
document.setIndentWidth(0);
|
||||
document.setDocumentMargin(0);
|
||||
|
||||
bool isElided= false;
|
||||
//计算text的长度
|
||||
while (true) {
|
||||
QTextLine line = textLayout.createLine();
|
||||
if (!line.isValid())
|
||||
break;
|
||||
|
||||
int nextLineY = y + lineSpacing;
|
||||
lineCount++;
|
||||
y = nextLineY;
|
||||
if (1 == lineCount) {
|
||||
line.setLineWidth(width-xOffset);
|
||||
} else {
|
||||
line.setLineWidth(width);
|
||||
}
|
||||
if (textMaxHeight < nextLineY + lineSpacing || lineCount == maxLineCount) {
|
||||
QString lastLine = option.text.mid(line.textStart());
|
||||
QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width);
|
||||
if (elidedLastLine != lastLine) {
|
||||
isElided = true;
|
||||
}
|
||||
elidedText = option.text.left(line.textStart()) + elidedLastLine;
|
||||
textOpt.setWrapMode(QTextOption::NoWrap);
|
||||
line = textLayout.createLine();
|
||||
break;
|
||||
}
|
||||
}
|
||||
document.setPlainText(elidedText);
|
||||
|
||||
painter->translate(horizalMargin, 0);
|
||||
|
||||
//设置关键字高亮
|
||||
QTextCursor highlightCursor(&document);
|
||||
QTextCursor cursor(&document);
|
||||
|
||||
cursor.beginEditBlock();
|
||||
QTextBlock textStyleBlock = cursor.block();
|
||||
QTextBlockFormat textStyleFormat = textStyleBlock.blockFormat();
|
||||
textStyleFormat.setLineHeight(lineSpacing, QTextBlockFormat::FixedHeight);
|
||||
textStyleFormat.setTextIndent(xOffset);
|
||||
cursor.setBlockFormat(textStyleFormat);
|
||||
QTextCharFormat plainFormat(highlightCursor.charFormat());
|
||||
QTextCharFormat colorFormat = plainFormat;
|
||||
colorFormat.setBackground(Qt::green);
|
||||
if (option.state.testFlag(QStyle::State_Selected)) {
|
||||
QTextCharFormat selectColorFormat(cursor.charFormat());
|
||||
selectColorFormat.setForeground(Qt::white);
|
||||
cursor.select(QTextCursor::Document);
|
||||
cursor.mergeCharFormat(selectColorFormat);
|
||||
}
|
||||
|
||||
if (!regFindKeyWords.isEmpty()) {
|
||||
//对特殊字符进行处理
|
||||
QString escapedKeywords = QRegularExpression::escape(regFindKeyWords);
|
||||
QRegularExpression regex(escapedKeywords);
|
||||
QRegularExpressionMatchIterator matchIterator = regex.globalMatch(option.text);
|
||||
|
||||
while (matchIterator.hasNext()) {
|
||||
QRegularExpressionMatch match = matchIterator.next();
|
||||
int startPos = match.capturedStart();
|
||||
int endPos = match.capturedEnd();
|
||||
int oo = elidedText.size();
|
||||
// 判断是否关键字被省略
|
||||
if (isElided && startPos >= elidedText.size() - 1) {
|
||||
break; // 关键字被完全省略,退出循环
|
||||
}
|
||||
|
||||
// 调整关键字的结束位置
|
||||
if (endPos > elidedText.size()) {
|
||||
endPos = elidedText.size() ; // 关键字的一部分被省略,将结束位置调整为最后一个字符的位置
|
||||
}
|
||||
|
||||
// 执行关键字高亮
|
||||
highlightCursor.setPosition(startPos);
|
||||
highlightCursor.setPosition(endPos, QTextCursor::KeepAnchor);
|
||||
highlightCursor.mergeCharFormat(colorFormat);
|
||||
}
|
||||
}
|
||||
cursor.endEditBlock();
|
||||
document.drawContents(painter);
|
||||
|
||||
textLayout.endLayout();
|
||||
painter->restore();
|
||||
|
||||
QSizeF docSize = document.size();
|
||||
qreal docHeight = docSize.height(); // 获取文档的高度
|
||||
return docHeight;
|
||||
}
|
||||
|
||||
QSize IconViewTextHelper::getTextSizeForIndex(const QStyleOptionViewItem &option, const QModelIndex &index, int horizalMargin, int maxLineCount)
|
||||
{
|
||||
int fixedWidth = option.rect.width() - horizalMargin*2;
|
||||
|
|
|
@ -125,14 +125,6 @@ class PEONYCORESHARED_EXPORT IconViewTextHelper
|
|||
const QString ®FindKeyWords,
|
||||
int horizalMargin = 0,
|
||||
int maxLineCount = 4) ;
|
||||
|
||||
static qreal drawText(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
int textMaxHeight,
|
||||
int xOffset,
|
||||
const QString ®FindKeyWords,
|
||||
int horizalMargin = 0,
|
||||
int maxLineCount = 4) ;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -38,10 +38,6 @@ IconViewEditor::IconViewEditor(QWidget *parent) : QTextEdit(parent)
|
|||
m_styled_edit = new QLineEdit;
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
setAlignment(Qt::AlignCenter);
|
||||
// fix #164278, icon view text editor doesn't cover view item.
|
||||
// note on ukui platform theme, style panel frame is not visible,
|
||||
// we have to draw a frame by ourselves.
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
|
||||
// setStyleSheet("padding: 0px;"
|
||||
// "background-color: white;");
|
||||
|
@ -57,18 +53,13 @@ IconViewEditor::~IconViewEditor()
|
|||
void IconViewEditor::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPainter p(this->viewport());
|
||||
qreal padding = 1.0;
|
||||
QRectF rectF = viewport()->rect();
|
||||
p.save();
|
||||
if (devicePixelRatioF() < 2.0) {
|
||||
if (devicePixelRatioF() > 1.0) {
|
||||
padding = qMin(devicePixelRatioF(), 1.5);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
}
|
||||
}
|
||||
p.fillRect(rectF, palette().highlight());
|
||||
p.fillRect(rectF.adjusted(padding, padding, -padding, -padding), palette().base());
|
||||
p.restore();
|
||||
p.fillRect(this->viewport()->rect(), m_styled_edit->palette().base());
|
||||
QPen pen;
|
||||
pen.setWidth(2);
|
||||
pen.setColor(this->palette().highlight().color());
|
||||
QPolygon polygon = this->viewport()->rect();
|
||||
p.setPen(pen);
|
||||
p.drawPolygon(polygon);
|
||||
QTextEdit::paintEvent(e);
|
||||
}
|
||||
|
||||
|
@ -86,27 +77,35 @@ void IconViewEditor::minimalAdjust()
|
|||
if (m_max_length_limit) {
|
||||
//fix #154584
|
||||
blockSignals(true);
|
||||
auto privousText = toPlainText();
|
||||
auto currentText = privousText;
|
||||
auto position = textCursor().position();
|
||||
bool needReset = false;
|
||||
while (true) {
|
||||
if (m_limit_bytes) {
|
||||
auto local8Bit = toPlainText().toLocal8Bit();
|
||||
auto local8Bit = currentText.toLocal8Bit();
|
||||
if (local8Bit.length() <= m_max_length_limit) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (toPlainText().length() <= m_max_length_limit) {
|
||||
if (currentText.length() <= m_max_length_limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (position > 0) {
|
||||
position--;
|
||||
textCursor().beginEditBlock();
|
||||
textCursor().setPosition(position);
|
||||
textCursor().deletePreviousChar();
|
||||
textCursor().endEditBlock();
|
||||
currentText.remove(position, 1);
|
||||
} else {
|
||||
break;
|
||||
currentText.remove(0, 1);
|
||||
}
|
||||
needReset = true;
|
||||
}
|
||||
if (needReset) {
|
||||
setText(currentText);
|
||||
auto currentTextCursor = textCursor();
|
||||
currentTextCursor.setPosition(position);
|
||||
setTextCursor(currentTextCursor);
|
||||
}
|
||||
blockSignals(false);
|
||||
}
|
||||
|
|
|
@ -109,6 +109,7 @@ IconViewIndexWidget::IconViewIndexWidget(const IconViewDelegate *delegate, const
|
|||
|
||||
auto textSize = IconViewTextHelper::getTextSizeForIndex(opt, index, 2);
|
||||
int fixedHeight = 5 + iconExpectedSize.height() + 5 + textSize.height() + 5;
|
||||
|
||||
int y_bottom = option.rect.y() + fixedHeight + 20;
|
||||
//qDebug() << "Y:" <<option.rect.y() <<fixedHeight <<m_delegate->getView()->height();
|
||||
b_elide_text = false;
|
||||
|
@ -195,12 +196,7 @@ void IconViewIndexWidget::paintEvent(QPaintEvent *e)
|
|||
// p.fillRect(0, 0, 999, 999, qApp->palette().base());
|
||||
|
||||
//adjustPos();
|
||||
auto bgColor = QApplication::palette().base().color();
|
||||
p.save();
|
||||
p.setPen(Qt::transparent);
|
||||
p.setBrush(bgColor);
|
||||
p.drawRoundedRect(this->rect(), 6, 6);
|
||||
p.restore();
|
||||
|
||||
//qDebug()<<m_option.backgroundBrush;
|
||||
//qDebug()<<this->size() << m_delegate->getView()->iconSize();
|
||||
|
||||
|
@ -221,6 +217,12 @@ void IconViewIndexWidget::paintEvent(QPaintEvent *e)
|
|||
auto opt = m_option;
|
||||
auto rawRect = m_option.rect;
|
||||
opt.rect = this->rect();
|
||||
auto widgetRect = this->rect();
|
||||
if (qApp->devicePixelRatio() != 1.0) {
|
||||
opt.rect.adjust(1, 1, -1, -1);
|
||||
rawRect.adjust(1, 1, -1, -1);
|
||||
widgetRect.adjust(1, 1, -1, -1);
|
||||
}
|
||||
|
||||
int horizalMargin = 2;
|
||||
auto fontMetrics = opt.fontMetrics;
|
||||
|
@ -263,6 +265,9 @@ void IconViewIndexWidget::paintEvent(QPaintEvent *e)
|
|||
opt.text = std::move(tmp);
|
||||
|
||||
//extra emblems
|
||||
if (!m_info.lock()) {
|
||||
return;
|
||||
}
|
||||
auto info = m_info.lock();
|
||||
|
||||
// draw color symbols
|
||||
|
@ -316,6 +321,7 @@ void IconViewIndexWidget::paintEvent(QPaintEvent *e)
|
|||
p.save();
|
||||
//fix bug#147348
|
||||
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
p.translate(widgetRect.topLeft());
|
||||
p.translate(0, m_delegate->getView()->iconSize().height() + 5);
|
||||
|
||||
// p.translate(2, 2);
|
||||
|
@ -331,22 +337,16 @@ void IconViewIndexWidget::paintEvent(QPaintEvent *e)
|
|||
}
|
||||
QString regFindKeyWords = m_delegate->getRegFindKeyWords();
|
||||
p.save();
|
||||
p.translate(widgetRect.topLeft());
|
||||
p.translate(0, m_delegate->getView()->iconSize().height() + 5 + yoffset);
|
||||
p.setPen(opt.palette.highlightedText().color());
|
||||
|
||||
qreal textHeight = IconViewTextHelper::drawText(&p,
|
||||
opt,
|
||||
9999,
|
||||
xoffset,
|
||||
regFindKeyWords,
|
||||
2,
|
||||
4);
|
||||
|
||||
//fix#bug182191 【文件管理器】文件添加标记后选中状态名称显示不全
|
||||
int fixedHeight = 5 + m_delegate->getView()->iconSize().height() + 5 + textHeight + 5;
|
||||
if (fixedHeight > this->height())
|
||||
setFixedHeight(fixedHeight);
|
||||
|
||||
IconViewTextHelper::paintText(&p,
|
||||
opt,
|
||||
9999,
|
||||
xoffset,
|
||||
regFindKeyWords,
|
||||
2,
|
||||
4);
|
||||
p.restore();
|
||||
|
||||
QList<int> emblemPoses = {4, 3, 2, 1}; //bottom right, bottom left, top right, top left
|
||||
|
@ -360,7 +360,7 @@ void IconViewIndexWidget::paintEvent(QPaintEvent *e)
|
|||
//Adjust link emblem to topLeft.link story#8354
|
||||
p.save();
|
||||
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
icon.paint(&p, this->rect().x() + 10, m_delegate->getView()->iconSize().height() - 10, 20, 20, Qt::AlignCenter);
|
||||
icon.paint(&p, this->rect().x() + 10, widgetRect.y()+m_delegate->getView()->iconSize().height() - 10, 20, 20, Qt::AlignCenter);
|
||||
p.restore();
|
||||
}
|
||||
if(view->isEnableMultiSelect())
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "list-view-delegate.h"
|
||||
#include "file-operation-manager.h"
|
||||
#include "file-rename-operation.h"
|
||||
#include "file-batch-rename-operation.h"
|
||||
#include "file-item-model.h"
|
||||
#include "file-item-proxy-filter-sort-model.h"
|
||||
#include "file-item.h"
|
||||
|
@ -39,7 +38,6 @@
|
|||
#include <QPushButton>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDBusReply>
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QItemDelegate>
|
||||
|
@ -365,27 +363,10 @@ QWidget *ListViewDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
|
|||
auto uri = index.data(Qt::UserRole).toString();
|
||||
auto suffix = displayName.remove(displayString);
|
||||
auto fsType = FileUtils::getFsTypeFromFile(uri);
|
||||
auto info = FileInfo::fromUri(uri);
|
||||
if (info->isDesktopFile()) {
|
||||
suffix = ".desktop";
|
||||
}
|
||||
if (FileUtils::isFuseFileSystem(uri)) {
|
||||
fsType = "fuse.kyfs";
|
||||
}
|
||||
if (fsType.contains("ext")) {
|
||||
edit->setMaxLengthLimit(255 - suffix.toLocal8Bit().length());
|
||||
} else if (fsType.contains("ntfs")) {
|
||||
edit->setLimitBytes(false);
|
||||
edit->setMaxLengthLimit(255 - suffix.length());
|
||||
} else if (fsType.contains("fuse.kyfs")) {
|
||||
int32_t maxLength = 255;
|
||||
edit->setLimitBytes(false);
|
||||
QDBusInterface iface ("com.kylin.file.system.fuse","/com/kylin/file/system/fuse","com.kylin.file.system.fuse",QDBusConnection::systemBus());
|
||||
QDBusReply<int32_t> reply = iface.call("GetFilenameLength");
|
||||
if (reply.isValid()) {
|
||||
maxLength = reply.value();
|
||||
}
|
||||
edit->setMaxLengthLimit(maxLength - suffix.length());
|
||||
}
|
||||
edit->blockSignals(false);
|
||||
|
||||
|
@ -476,40 +457,21 @@ void ListViewDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
|||
return;
|
||||
}
|
||||
|
||||
if (view->getSelections().count() > 1) {
|
||||
auto fileOpMgr = FileOperationManager::getInstance();
|
||||
QStringList lists = view->getSelections();
|
||||
auto renameOp = new FileBatchRenameOperation(lists, text);
|
||||
auto fileOpMgr = FileOperationManager::getInstance();
|
||||
auto renameOp = new FileRenameOperation(index.data(FileItemModel::UriRole).toString(), text);
|
||||
|
||||
connect(renameOp, &FileBatchRenameOperation::operationFinished, view, [=](){
|
||||
auto info = renameOp->getOperationInfo().get();
|
||||
auto uri = info->target();
|
||||
QTimer::singleShot(100, view, [=](){
|
||||
view->setSelections(QStringList()<<uri);
|
||||
//after rename will nor sort immediately, comment to fix bug#60482
|
||||
//view->scrollToSelection(uri);
|
||||
view->setFocus();
|
||||
});
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
connect(renameOp, &FileRenameOperation::operationFinished, view, [=](){
|
||||
auto info = renameOp->getOperationInfo().get();
|
||||
auto uri = info->target();
|
||||
QTimer::singleShot(100, view, [=](){
|
||||
view->setSelections(QStringList()<<uri);
|
||||
//after rename will nor sort immediately, comment to fix bug#60482
|
||||
//view->scrollToSelection(uri);
|
||||
view->setFocus();
|
||||
});
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
|
||||
fileOpMgr->startOperation(renameOp, true);
|
||||
} else {
|
||||
auto fileOpMgr = FileOperationManager::getInstance();
|
||||
auto renameOp = new FileRenameOperation(index.data(FileItemModel::UriRole).toString(), text);
|
||||
|
||||
connect(renameOp, &FileRenameOperation::operationFinished, view, [=](){
|
||||
auto info = renameOp->getOperationInfo().get();
|
||||
auto uri = info->target();
|
||||
QTimer::singleShot(100, view, [=](){
|
||||
view->setSelections(QStringList()<<uri);
|
||||
//after rename will nor sort immediately, comment to fix bug#60482
|
||||
//view->scrollToSelection(uri);
|
||||
view->setFocus();
|
||||
});
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
|
||||
fileOpMgr->startOperation(renameOp, true);
|
||||
}
|
||||
fileOpMgr->startOperation(renameOp, true);
|
||||
}
|
||||
|
||||
//not comment this bug to fix bug#93314
|
||||
|
@ -541,11 +503,7 @@ void ListViewDelegate::setSearchKeyword(QString regFindKeyWords)
|
|||
//TextEdit
|
||||
TextEdit::TextEdit(QWidget *parent) : QTextEdit (parent)
|
||||
{
|
||||
// fix #164278, icon view text editor doesn't cover view item.
|
||||
// note on ukui platform theme, style panel frame is not visible.
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
|
||||
setViewportMargins(1, 2, 1, 2);
|
||||
this->setContentsMargins(0,0,0,0);
|
||||
}
|
||||
|
||||
void TextEdit::adjustText()
|
||||
|
@ -553,27 +511,35 @@ void TextEdit::adjustText()
|
|||
if (m_max_length_limit) {
|
||||
//fix #154584
|
||||
blockSignals(true);
|
||||
auto privousText = toPlainText();
|
||||
auto currentText = privousText;
|
||||
auto position = textCursor().position();
|
||||
bool needReset = false;
|
||||
while (true) {
|
||||
if (m_limit_bytes) {
|
||||
auto local8Bit = toPlainText().toLocal8Bit();
|
||||
auto local8Bit = currentText.toLocal8Bit();
|
||||
if (local8Bit.length() <= m_max_length_limit) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (toPlainText().length() <= m_max_length_limit) {
|
||||
if (currentText.length() <= m_max_length_limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (position > 0) {
|
||||
position--;
|
||||
textCursor().beginEditBlock();
|
||||
textCursor().setPosition(position);
|
||||
textCursor().deletePreviousChar();
|
||||
textCursor().endEditBlock();
|
||||
currentText.remove(position, 1);
|
||||
} else {
|
||||
break;
|
||||
currentText.remove(0, 1);
|
||||
}
|
||||
needReset = true;
|
||||
}
|
||||
if (needReset) {
|
||||
setText(currentText);
|
||||
auto currentTextCursor = textCursor();
|
||||
currentTextCursor.setPosition(position);
|
||||
setTextCursor(currentTextCursor);
|
||||
}
|
||||
blockSignals(false);
|
||||
}
|
||||
|
|
|
@ -164,10 +164,6 @@ bool DirectoryViewContainer::canCdUp()
|
|||
{
|
||||
if (!m_view)
|
||||
return false;
|
||||
|
||||
if("label:///" == FileUtils::getParentUri(m_view->getDirectoryUri()))/* 全局标记页面‘上一级’菜单置灰 */
|
||||
return false;
|
||||
|
||||
return !FileUtils::getParentUri(m_view->getDirectoryUri()).isNull();
|
||||
}
|
||||
|
||||
|
@ -262,12 +258,8 @@ update:
|
|||
//fix bug 41094, avoid go back to same path issue
|
||||
if (! curUri.startsWith("search://")
|
||||
&& !FileUtils::isSamePath(curUri, uri)) {
|
||||
if(getCurrentUri().startsWith("label:///") && FileUtils::getTargetUri(getCurrentUri()) == uri){
|
||||
m_back_list.append(FileUtils::getTargetUri(getCurrentUri()));/* 解决标记路径进入文件夹内,后退不了问题 */
|
||||
}else{
|
||||
qDebug() << "m_back_list.append first:"<<curUri;
|
||||
m_back_list.append(getCurrentUri());
|
||||
}
|
||||
qDebug() << "m_back_list.append first:"<<curUri;
|
||||
m_back_list.append(curUri);
|
||||
}else if(curUri.startsWith("search://")){
|
||||
//process remeber search record,only remeber the last search history,relate to bug#94229
|
||||
if (m_back_list.length() > 0 ){
|
||||
|
@ -366,7 +358,7 @@ void DirectoryViewContainer::switchViewType(const QString &viewId)
|
|||
connect(m_view, &DirectoryViewWidget::viewDirectoryChanged, this, [=](){
|
||||
if (DirectoryViewFactoryManager2::getInstance()->internalViews().contains(m_view->viewId())) {
|
||||
auto dirInfo = FileInfo::fromUri(m_current_uri);
|
||||
if (dirInfo.get()->isEmptyInfo() && !dirInfo.get()->uri().startsWith("search://") && !dirInfo.get()->uri().startsWith("label://")) {
|
||||
if (dirInfo.get()->isEmptyInfo() && !dirInfo.get()->uri().startsWith("search://")) {
|
||||
goBack();
|
||||
if (!m_forward_list.isEmpty())
|
||||
m_forward_list.takeFirst();
|
||||
|
@ -435,20 +427,12 @@ void DirectoryViewContainer::switchViewType(const QString &viewId)
|
|||
bool hasStandardPath = FileUtils::containsStandardPath(selections);
|
||||
if (selections.count() == 1 && !hasStandardPath) {
|
||||
QString one = selections.first();
|
||||
if(one.startsWith("filesafe:///") && one.remove("filesafe:///").indexOf("/") == -1 || one.startsWith("label://")) {
|
||||
if(one.startsWith("filesafe:///") && one.remove("filesafe:///").indexOf("/") == -1) {
|
||||
return ;
|
||||
}
|
||||
//修复在选中文件不可见时,重命名操作不会跳转显示重命名文件问题,link to bug#160799
|
||||
m_view->scrollToSelection(selections.first());
|
||||
m_view->editUri(selections.first());
|
||||
} else if (selections.count() > 1 && !hasStandardPath) {
|
||||
for (auto uri : selections) {
|
||||
QString one = uri;
|
||||
if(one.startsWith("filesafe:///") && one.remove("filesafe:///").indexOf("/") == -1) {
|
||||
return ;
|
||||
}
|
||||
}
|
||||
m_view->editUris(selections);
|
||||
}
|
||||
});
|
||||
this->addAction(editAction);
|
||||
|
|
|
@ -636,8 +636,7 @@ void IconView::slotRename()
|
|||
|| getDirectoryUri().startsWith("recent://")
|
||||
|| getDirectoryUri().startsWith("favorite://")
|
||||
|| getDirectoryUri().startsWith("search://")
|
||||
|| getDirectoryUri().startsWith("network://")
|
||||
|| getDirectoryUri().startsWith("label://"))
|
||||
|| getDirectoryUri().startsWith("network://"))
|
||||
return;
|
||||
|
||||
//standardPaths not allow rename
|
||||
|
@ -848,15 +847,6 @@ void IconView::editUris(const QStringList uris)
|
|||
{
|
||||
//FIXME:
|
||||
//implement batch rename.
|
||||
setState(QListView::NoState);
|
||||
auto origin = FileUtils::getOriginalUri(uris.first());
|
||||
if(uris.first().startsWith("mtp://"))/* Fixbug#82649:在手机内部存储里新建文件/文件夹时,名称不是可编辑状态,都是默认文件名/文件夹名 */
|
||||
origin = uris.first();
|
||||
QModelIndex index = m_sort_filter_proxy_model->indexFromUri(origin);
|
||||
setIndexWidget(index, nullptr);
|
||||
qDebug() << "editUris:" << uris << origin;
|
||||
QListView::scrollTo(index);
|
||||
edit(index);
|
||||
}
|
||||
|
||||
void IconView::selectAll()
|
||||
|
|
|
@ -108,8 +108,7 @@ ListView::ListView(QWidget *parent) : QTreeView(parent)
|
|||
header()->setSectionResizeMode(QHeaderView::Interactive);
|
||||
header()->setSectionsMovable(true);
|
||||
header()->setStretchLastSection(false);
|
||||
header()->setMinimumSectionSize(130);
|
||||
header()->setTextElideMode(Qt::ElideRight);
|
||||
|
||||
if (this->topLevelWidget()->objectName() == "_peony_mainwindow") {
|
||||
connect(header(), &QHeaderView::sectionClicked, this, [=](){
|
||||
//update sort policy
|
||||
|
@ -151,7 +150,7 @@ ListView::ListView(QWidget *parent) : QTreeView(parent)
|
|||
setIconSize(QSize(40, 40));
|
||||
setMouseTracking(true);//追踪鼠标
|
||||
|
||||
m_rubberBand = new QRubberBand(QRubberBand::Shape::Rectangle, this->viewport());
|
||||
m_rubberBand = new QRubberBand(QRubberBand::Shape::Rectangle, this);
|
||||
|
||||
//FIXME: do not create proxy in view itself.
|
||||
ListViewDelegate *delegate = new ListViewDelegate(this);
|
||||
|
@ -441,7 +440,7 @@ void ListView::mouseMoveEvent(QMouseEvent *e)
|
|||
m_logicRect = logicRect.normalized();
|
||||
|
||||
int dx = -horizontalOffset();
|
||||
int dy = -verticalOffset();
|
||||
int dy = -verticalOffset() + this->header()->height();
|
||||
auto realRect = m_logicRect.adjusted(dx, dy, dx ,dy);
|
||||
|
||||
if (!m_rubberBand->isVisible())
|
||||
|
@ -586,13 +585,6 @@ void ListView::dropEvent(QDropEvent *e)
|
|||
return;
|
||||
}
|
||||
|
||||
auto sizeHint = itemDelegate()->sizeHint(viewOptions(), index);
|
||||
auto validRect = QRect(visualRect(proxy_index).topLeft(), sizeHint);
|
||||
if (!validRect.contains(e->pos())) {
|
||||
//拖拽到在空白处,就移动到当前目录下
|
||||
m_model->dropMimeData(e->mimeData(), action, 0, 0, QModelIndex());
|
||||
return;
|
||||
}
|
||||
m_model->dropMimeData(e->mimeData(), action, 0, 0, index);
|
||||
}
|
||||
|
||||
|
@ -767,9 +759,7 @@ void ListView::slotRename()
|
|||
|| getDirectoryUri().startsWith("recent://")
|
||||
|| getDirectoryUri().startsWith("favorite://")
|
||||
|| getDirectoryUri().startsWith("search://")
|
||||
|| getDirectoryUri().startsWith("network://")
|
||||
|| getDirectoryUri().startsWith("label://"))
|
||||
|
||||
|| getDirectoryUri().startsWith("network://"))
|
||||
return;
|
||||
|
||||
//standardPaths not allow rename
|
||||
|
@ -1050,7 +1040,7 @@ void ListView::editUri(const QString &uri)
|
|||
auto origin = FileUtils::getOriginalUri(uri);
|
||||
if(uri.startsWith("mtp://"))/* Fixbug#82649:在手机内部存储里新建文件/文件夹时,名称不是可编辑状态,都是默认文件名/文件夹名 */
|
||||
origin = uri;
|
||||
QModelIndex index = m_proxy_model->indexFromUri(origin);
|
||||
QModelIndex index =m_proxy_model->indexFromUri(origin);
|
||||
setIndexWidget(index, nullptr);
|
||||
//注释该行以修复bug:#60474
|
||||
// QTreeView::scrollTo(m_proxy_model->indexFromUri(origin));
|
||||
|
@ -1073,19 +1063,6 @@ void ListView::editUris(const QStringList uris)
|
|||
{
|
||||
//FIXME:
|
||||
//implement batch rename.
|
||||
setState(QTreeView::NoState);
|
||||
auto origin = FileUtils::getOriginalUri(uris.first());
|
||||
if(uris.first().startsWith("mtp://"))/* Fixbug#82649:在手机内部存储里新建文件/文件夹时,名称不是可编辑状态,都是默认文件名/文件夹名 */
|
||||
origin = uris.first();
|
||||
QModelIndex index = m_proxy_model->indexFromUri(origin);
|
||||
setIndexWidget(index, nullptr);
|
||||
//fix bug#70769, edit box overlapped with status bar issue
|
||||
//qDebug() <<"editUri row"<<m_proxy_model->rowCount()<<index.row();
|
||||
if(index.row() >= m_proxy_model->rowCount()-1)
|
||||
QTreeView::scrollToBottom();
|
||||
//注释该行以修复bug:#60474
|
||||
// QTreeView::scrollTo(m_proxy_model->indexFromUri(origin));
|
||||
edit(index);
|
||||
}
|
||||
|
||||
bool ListView::isEnableMultiSelect()
|
||||
|
|
|
@ -27,19 +27,18 @@
|
|||
|
||||
#include <QPainterPath>
|
||||
|
||||
#define BIG_LABEL_WIDTH 20
|
||||
#define SMALL_LABEL_WIDTH 14
|
||||
|
||||
ColorPushButton::ColorPushButton(QColor color,QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
m_color = color;
|
||||
setProperty("isRoundButton",true);
|
||||
setFixedSize(BIG_LABEL_WIDTH, BIG_LABEL_WIDTH);
|
||||
setFixedSize(12,12);
|
||||
QRectF rect = this->rect();
|
||||
m_bigpathrect = rect.adjusted(1, 1, -1, -1);
|
||||
m_pathrect = rect.adjusted(4, 4, -4, -4);
|
||||
m_pathrectwidth = m_pathrect.width();
|
||||
m_pathrect = rect.adjusted(1, 1, -1, -1);
|
||||
m_pathrectwidth =m_pathrect.width();
|
||||
m_pathrectheigth = m_pathrect.height();
|
||||
QSizeF size(18,18);
|
||||
rect.setSize(size);
|
||||
m_bigpathrect = rect.adjusted(1,1,-1,-1);
|
||||
m_bigpathrectwidth = m_bigpathrect.width();
|
||||
m_bigpathrectheigth = m_bigpathrect.height();
|
||||
|
||||
|
@ -47,15 +46,11 @@ ColorPushButton::ColorPushButton(QColor color,QWidget *parent) : QPushButton(par
|
|||
|
||||
void ColorPushButton::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
m_pathrect = this->rect().adjusted(1, 1, -1, -1);
|
||||
m_bigpathrect = m_pathrect;
|
||||
QString manager = tr("label management ...");
|
||||
|
||||
if(this->underMouse()){
|
||||
if(this->isChecked() && m_checkInMultiSelect){
|
||||
if(this->isChecked()){
|
||||
if(this->underMouse()){
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::Active,QPalette::Highlight, m_color);
|
||||
setFixedSize(BIG_LABEL_WIDTH, BIG_LABEL_WIDTH);
|
||||
setFixedSize(18,18);
|
||||
this->setPalette(pal);
|
||||
QPushButton::paintEvent(e);
|
||||
|
||||
|
@ -69,37 +64,12 @@ void ColorPushButton::paintEvent(QPaintEvent *e)
|
|||
path.lineTo(m_bigpathrect.left() + m_bigpathrectwidth * 0.75, m_bigpathrect.top() + m_bigpathrectheigth / 4);
|
||||
painter.drawPath(path);
|
||||
painter.restore();
|
||||
manager = QString(tr("delete \"%1\"")).arg(m_name);
|
||||
Q_EMIT changeText(manager);
|
||||
}else{
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::Active,QPalette::Highlight, m_color);
|
||||
this->setPalette(pal);
|
||||
setFixedSize(BIG_LABEL_WIDTH, BIG_LABEL_WIDTH);
|
||||
setFixedSize(12,12);
|
||||
QPushButton::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
|
||||
painter.setPen(Qt::white);
|
||||
QPainterPath path;
|
||||
path.moveTo(m_bigpathrect.left() + m_bigpathrectwidth / 4, m_bigpathrect.top() + m_bigpathrectheigth / 2);
|
||||
path.lineTo(m_bigpathrect.left() + m_bigpathrectwidth * 0.80, m_bigpathrect.top() + m_bigpathrectheigth / 2);
|
||||
path.moveTo(m_bigpathrect.left() + m_bigpathrectwidth / 2, m_bigpathrect.top() + m_bigpathrectheigth / 4);
|
||||
path.lineTo(m_bigpathrect.left() + m_bigpathrectwidth / 2, m_bigpathrect.top() + m_bigpathrectheigth * 0.80);
|
||||
painter.drawPath(path);
|
||||
painter.restore();
|
||||
manager = QString(tr("add \"%1\"")).arg(m_name);
|
||||
Q_EMIT changeText(manager);
|
||||
}
|
||||
}else{
|
||||
if(this->isChecked()){
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::Active,QPalette::Highlight, m_color);
|
||||
this->setPalette(pal);
|
||||
setFixedSize(SMALL_LABEL_WIDTH, SMALL_LABEL_WIDTH);
|
||||
QPushButton::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
|
||||
|
@ -110,18 +80,32 @@ void ColorPushButton::paintEvent(QPaintEvent *e)
|
|||
path.lineTo(m_pathrect.right() - m_pathrectwidth / 4, m_pathrect.top() + m_pathrectheigth / 3);
|
||||
painter.drawPath(path);
|
||||
painter.restore();
|
||||
}else {
|
||||
}
|
||||
}else{
|
||||
if(this->underMouse()){
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::Active,QPalette::Highlight, m_color);
|
||||
this->setPalette(pal);
|
||||
setFixedSize(18,18);
|
||||
QPushButton::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setPen(Qt::white);
|
||||
QPainterPath path;
|
||||
path.moveTo(m_bigpathrect.left() + m_bigpathrectwidth / 4, m_bigpathrect.top() + m_bigpathrectheigth / 2);
|
||||
path.lineTo(m_bigpathrect.left() + m_bigpathrectwidth * 0.80, m_bigpathrect.top() + m_bigpathrectheigth / 2);
|
||||
path.moveTo(m_bigpathrect.left() + m_bigpathrectwidth / 2, m_bigpathrect.top() + m_bigpathrectheigth / 4);
|
||||
path.lineTo(m_bigpathrect.left() + m_bigpathrectwidth / 2, m_bigpathrect.top() + m_bigpathrectheigth * 0.80);
|
||||
painter.drawPath(path);
|
||||
painter.restore();
|
||||
}else if(!this->underMouse()){
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::Button, m_color);
|
||||
this->setPalette(pal);
|
||||
setFixedSize(SMALL_LABEL_WIDTH, SMALL_LABEL_WIDTH);
|
||||
setFixedSize(12,12);
|
||||
QPushButton::paintEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ColorPushButton::setName(const QString& name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
|
|
@ -35,17 +35,11 @@ class ColorPushButton : public QPushButton
|
|||
public:
|
||||
explicit ColorPushButton(QColor color,QWidget *parent = nullptr);
|
||||
|
||||
void setName(const QString& name);
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeText(const QString &colorName);
|
||||
|
||||
//Q_SIGNALS:
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
public:
|
||||
bool m_checkInMultiSelect = true;
|
||||
|
||||
private:
|
||||
QColor m_color = nullptr;
|
||||
QRectF m_pathrect;
|
||||
|
@ -54,7 +48,6 @@ private:
|
|||
QRectF m_bigpathrect;
|
||||
double m_bigpathrectwidth;
|
||||
double m_bigpathrectheigth;
|
||||
QString m_name;
|
||||
};
|
||||
|
||||
#endif // COLORPUSHBUTTON_H
|
||||
|
|
|
@ -42,9 +42,6 @@
|
|||
#include "file-untrash-operation.h"
|
||||
#include "file-delete-operation.h"
|
||||
#include "sound-effect.h"
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
#include "ksoundeffects.h"
|
||||
#endif
|
||||
|
||||
#include "file-utils.h"
|
||||
#include "bookmark-manager.h"
|
||||
|
@ -60,7 +57,6 @@
|
|||
#include "file-operation-error-dialog.h"
|
||||
#include "file-enumerator.h"
|
||||
#include "gerror-wrapper.h"
|
||||
#include "format-dlg-create-delegate.h"
|
||||
|
||||
#include "global-settings.h"
|
||||
#include "sound-effect.h"
|
||||
|
@ -80,9 +76,6 @@
|
|||
#include <QDebug>
|
||||
|
||||
using namespace Peony;
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
using namespace kdk;
|
||||
#endif
|
||||
|
||||
DirectoryViewMenu::DirectoryViewMenu(DirectoryViewWidget *directoryView, QWidget *parent) : QMenu(parent)
|
||||
{
|
||||
|
@ -118,11 +111,6 @@ void DirectoryViewMenu::setHiddenActionsByObjectName(const QStringList &actionNa
|
|||
|
||||
void DirectoryViewMenu::fillActions()
|
||||
{
|
||||
QString tmpUri;
|
||||
g_autoptr (GFile) tmp_file = g_file_new_for_uri(m_directory.toUtf8().constData());
|
||||
g_autofree gchar* tmp_uri = g_file_get_uri(tmp_file);
|
||||
tmpUri = tmp_uri;
|
||||
|
||||
if (m_directory == "computer:///") {
|
||||
m_is_computer = true;
|
||||
}
|
||||
|
@ -156,7 +144,7 @@ void DirectoryViewMenu::fillActions()
|
|||
}
|
||||
|
||||
if (m_directory.startsWith("ftp://")
|
||||
|| m_directory.startsWith("sftp://") || tmpUri.startsWith("ftp://") || tmpUri.startsWith("sftp://")) {
|
||||
|| m_directory.startsWith("sftp://")) {
|
||||
m_is_ftp = true;
|
||||
}
|
||||
|
||||
|
@ -168,7 +156,7 @@ void DirectoryViewMenu::fillActions()
|
|||
m_is_filesafe = true;
|
||||
}
|
||||
|
||||
if(m_directory.startsWith("smb://") || tmpUri.startsWith("smb://")){
|
||||
if(m_directory.startsWith("smb://")){
|
||||
m_is_smb_file = true;
|
||||
}
|
||||
|
||||
|
@ -177,14 +165,6 @@ void DirectoryViewMenu::fillActions()
|
|||
m_is_boxpath = true;
|
||||
}
|
||||
|
||||
if (m_directory.startsWith("label://")){
|
||||
m_is_label_model = true;
|
||||
}
|
||||
|
||||
if (m_directory.startsWith("mtp://") || m_directory.startsWith("gphoto2://")){
|
||||
m_is_mtp_ptp = true;
|
||||
}
|
||||
|
||||
auto dev = VolumeManager::getDriveFromUri(m_directory);
|
||||
if(dev != nullptr){
|
||||
bool canEject = g_drive_can_eject(dev.get()->getGDrive());
|
||||
|
@ -195,12 +175,6 @@ void DirectoryViewMenu::fillActions()
|
|||
qDebug() << "canEject :" << canEject;
|
||||
}
|
||||
|
||||
//task#147972 【删除回收站】选项需求
|
||||
//如果是长城的机器并且带了9215控制器,不再区分移动设备,统一右键删除到回收站
|
||||
bool trashSettings = GlobalSettings::getInstance()->getValue(TRASH_MOBILE_FILES).toBool();
|
||||
if (trashSettings)
|
||||
m_is_mobile_file = false;
|
||||
|
||||
QString homeUri = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
||||
QString musicUri = QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
|
||||
QString desktop = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||
|
@ -422,7 +396,6 @@ const QList<QAction *> DirectoryViewMenu::constructOpenOpActions()
|
|||
});
|
||||
}
|
||||
} else if (!info->isVolume()) {
|
||||
bool needDisable = isMultVideoOrAudio(info);
|
||||
l<<addAction(QIcon::fromTheme("document-open-symbolic"), tr("Open"));
|
||||
l.last()->setObjectName(OPEN_ACTION);
|
||||
connect(l.last(), &QAction::triggered, [=]() {
|
||||
|
@ -433,10 +406,6 @@ const QList<QAction *> DirectoryViewMenu::constructOpenOpActions()
|
|||
FileLaunchManager::openAsync(uri, false, false);
|
||||
});
|
||||
|
||||
if (needDisable) {
|
||||
l.last()->setEnabled(false);
|
||||
}
|
||||
|
||||
if (m_is_network)
|
||||
return l;
|
||||
auto openWithAction = addAction(tr("Open with..."));
|
||||
|
@ -481,9 +450,6 @@ const QList<QAction *> DirectoryViewMenu::constructOpenOpActions()
|
|||
d.exec();
|
||||
});
|
||||
openWithAction->setMenu(openWithMenu);
|
||||
if (needDisable) {
|
||||
openWithAction->setEnabled(false);
|
||||
}
|
||||
} else {
|
||||
l<<addAction(tr("Open"));
|
||||
l.last()->setObjectName(OPEN_ACTION);
|
||||
|
@ -541,7 +507,7 @@ const QList<QAction *> DirectoryViewMenu::constructOpenOpActions()
|
|||
const QList<QAction *> DirectoryViewMenu::constructCreateTemplateActions()
|
||||
{
|
||||
QList<QAction *> l;
|
||||
if (!m_is_favorite && m_selections.isEmpty() && !m_is_filesafe && !m_is_trash && !m_is_label_model) {
|
||||
if (!m_is_favorite && m_selections.isEmpty() && !m_is_filesafe && !m_is_trash) {
|
||||
auto createAction = new QAction(tr("New"), this);
|
||||
createAction->setObjectName(CREATE_ACTION);
|
||||
if (m_is_cd) {
|
||||
|
@ -550,10 +516,6 @@ const QList<QAction *> DirectoryViewMenu::constructCreateTemplateActions()
|
|||
if (m_is_boxpath) {
|
||||
createAction->setEnabled(false);
|
||||
}
|
||||
//related bug#191108, huawei/android phone can paste file success,also can create
|
||||
// if (m_is_mtp_ptp) {
|
||||
// createAction->setEnabled(false);
|
||||
// }
|
||||
//fix create folder fail issue in special path
|
||||
auto info = FileInfo::fromUri(m_directory);
|
||||
if (info.get()->isEmptyInfo()) {
|
||||
|
@ -715,7 +677,7 @@ 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("Original Path"));
|
||||
tmp<<sortTypeMenu->addAction(tr("Orignal Path"));
|
||||
|
||||
if (m_top_window->getCurrentUri() != "trash:///") {
|
||||
tmp.last()->setVisible(false);
|
||||
|
@ -839,7 +801,7 @@ const QList<QAction *> DirectoryViewMenu::constructFileOpActions()
|
|||
if (m_is_kydroid)
|
||||
return l;
|
||||
|
||||
if (!hasStandardPath && !m_is_recent && !m_is_favorite && !m_is_filesafe && !m_is_label_model)
|
||||
if (!hasStandardPath && !m_is_recent && !m_is_favorite && !m_is_filesafe)
|
||||
{
|
||||
bool canCut = true;
|
||||
auto info = FileInfo::fromUri(m_directory);
|
||||
|
@ -857,7 +819,7 @@ const QList<QAction *> DirectoryViewMenu::constructFileOpActions()
|
|||
}
|
||||
|
||||
bool hasDeleteForever = false;
|
||||
if (!m_is_recent && !m_is_favorite && !hasStandardPath && !m_is_filesafe && !m_is_label_model) {
|
||||
if (!m_is_recent && !m_is_favorite && !hasStandardPath && !m_is_filesafe) {
|
||||
bool canTrash = true;
|
||||
bool canDelete = true;
|
||||
for (auto uri : m_selections) {
|
||||
|
@ -867,11 +829,6 @@ const QList<QAction *> DirectoryViewMenu::constructFileOpActions()
|
|||
|
||||
if (! info->canDelete() && (!uri.startsWith("ftp://")))/* 由于gio info 的can_delete=false,hotfix bug#98208【用例 100365】匿名访问ftp服务器,右键没有删除选项 */
|
||||
canDelete = false;
|
||||
|
||||
if(FileUtils::isLongNameFileOfNotDel2Trash(uri)){/* 在家目录/下载/扩展目录下存放的长文件名文件使用永久删除,link bug#188864 */
|
||||
canTrash = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//fix unencrypted box file can delete to trash issue, link to bug#72948
|
||||
|
@ -902,7 +859,7 @@ const QList<QAction *> DirectoryViewMenu::constructFileOpActions()
|
|||
}
|
||||
}
|
||||
|
||||
if ((m_is_favorite || m_is_label_model) && m_can_delete && !m_is_filesafe && !hasDeleteForever ) {
|
||||
if (m_is_favorite && m_can_delete && !m_is_filesafe && !hasDeleteForever) {
|
||||
l<<addAction(QIcon::fromTheme("edit-clear-symbolic"), tr("Delete forever"));
|
||||
l.last()->setObjectName(DELETE_ACTION);
|
||||
connect(l.last(), &QAction::triggered, [=]() {
|
||||
|
@ -918,38 +875,20 @@ const QList<QAction *> DirectoryViewMenu::constructFileOpActions()
|
|||
});
|
||||
}
|
||||
|
||||
if (m_selections.count() > 0 && ! hasStandardPath && !m_is_recent && !m_is_favorite && !m_is_filesafe && !m_is_label_model) {
|
||||
if (m_selections.count() == 1 && ! hasStandardPath && !m_is_recent && !m_is_favorite && !m_is_filesafe) {
|
||||
l<<addAction(QIcon::fromTheme("document-edit-symbolic"), tr("Rename"));
|
||||
l.last()->setObjectName(RENAME_ACTION);
|
||||
connect(l.last(), &QAction::triggered, [=]() {
|
||||
if (m_selections.count() == 1) {
|
||||
m_view->editUri(m_selections.first());
|
||||
} else if (m_selections.count() > 1) {
|
||||
m_view->editUris(m_selections);
|
||||
}
|
||||
m_view->editUri(m_selections.first());
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!m_is_recent && !m_is_favorite && !m_is_kydroid && !m_is_filesafe && !m_is_cd && !m_is_label_model)
|
||||
if (!m_is_recent && !m_is_favorite && !m_is_kydroid && !m_is_filesafe && !m_is_cd)
|
||||
{
|
||||
auto pasteAction = addAction(QIcon::fromTheme("edit-paste-symbolic"), tr("Paste"));
|
||||
l<<pasteAction;
|
||||
l.last()->setObjectName(PASTE_ACTION);
|
||||
ClipboardUtils::getInstance()->updateClipboardManually();
|
||||
|
||||
//fix bug#183268, not allow paste in mtp, gphoto2 path or can not write path
|
||||
auto info = FileInfo::fromUri(m_directory);
|
||||
bool isDirectoryCanWrite = true;
|
||||
if (!info->isEmptyInfo()) {
|
||||
isDirectoryCanWrite = info->canWrite();
|
||||
}
|
||||
//comment to fix bug#191108, huawei phone can paste file success
|
||||
// if (m_directory.startsWith("mtp://") || m_directory.startsWith("gphoto2://")){
|
||||
// isDirectoryCanWrite = false;
|
||||
// }
|
||||
|
||||
pasteAction->setEnabled(ClipboardUtils::isClipboardHasFiles() && isDirectoryCanWrite);
|
||||
pasteAction->setEnabled(ClipboardUtils::isClipboardHasFiles());
|
||||
connect(l.last(), &QAction::triggered, [=]() {
|
||||
auto op = ClipboardUtils::pasteClipboardFiles(m_directory);
|
||||
if (op) {
|
||||
|
@ -1078,14 +1017,6 @@ const QList<QAction *> DirectoryViewMenu::constructFilePropertiesActions()
|
|||
selectUriList<< m_selections.at(uriIndex);
|
||||
}
|
||||
}
|
||||
}else if(m_selections.first().startsWith("label:///")){
|
||||
for(auto &labelUri : m_selections){/* 标记模式页面为不同目录下的文件(夹),所以每个都需要一个属性对话框 */
|
||||
QStringList urisList;
|
||||
urisList.append(labelUri);
|
||||
PropertiesWindow *p = new PropertiesWindow(urisList);
|
||||
p->setAttribute(Qt::WA_DeleteOnClose);
|
||||
p->show();
|
||||
}
|
||||
}else {
|
||||
selectUriList = m_selections;
|
||||
}
|
||||
|
@ -1140,8 +1071,6 @@ const QList<QAction *> DirectoryViewMenu::constructComputerActions()
|
|||
// FIXME:// refactory Format_Dialog
|
||||
Format_Dialog* fd = new Format_Dialog(info->uri(), nullptr, m_view);
|
||||
fd->show();
|
||||
// Format_Dialog *fd = format_dlg_create_delegate::getInstance()->createDlg(info->uri(), nullptr);
|
||||
// fd->show();
|
||||
});
|
||||
l.last()->setObjectName(FORMAT_ACTION);
|
||||
|
||||
|
@ -1196,23 +1125,15 @@ const QList<QAction *> DirectoryViewMenu::constructTrashActions()
|
|||
if (m_selections.count() == 1) {
|
||||
auto untrashop = FileOperationUtils::restore(m_selections.first());
|
||||
if(untrashop){
|
||||
untrashop->connect(untrashop,&Peony::FileUntrashOperation::operationFinished,[=](){
|
||||
//Peony::SoundEffect::getInstance()->copyOrMoveSucceedMusic();
|
||||
//Task#152997, use sdk play sound
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
kdk::KSoundEffects::playSound(SoundType::OPERATION_FILE);
|
||||
#endif
|
||||
connect(untrashop,&Peony::FileUntrashOperation::operationFinished,[=](){
|
||||
Peony::SoundEffect::getInstance()->copyOrMoveSucceedMusic();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
auto untrashop = FileOperationUtils::restore(m_selections);
|
||||
if(untrashop){
|
||||
untrashop->connect(untrashop,&Peony::FileUntrashOperation::operationFinished,[=](){
|
||||
//Peony::SoundEffect::getInstance()->copyOrMoveSucceedMusic();
|
||||
//Task#152997, use sdk play sound
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
kdk::KSoundEffects::playSound(SoundType::OPERATION_FILE);
|
||||
#endif
|
||||
connect(untrashop,&Peony::FileUntrashOperation::operationFinished,[=](){
|
||||
Peony::SoundEffect::getInstance()->copyOrMoveSucceedMusic();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1222,17 +1143,10 @@ const QList<QAction *> DirectoryViewMenu::constructTrashActions()
|
|||
l.last()->setObjectName(DELETE_ACTION);
|
||||
connect(l.last(), &QAction::triggered, [=]() {
|
||||
AudioPlayManager::getInstance()->playWarningAudio();
|
||||
int result = 0;
|
||||
QString message = QObject::tr("Are you sure you want to permanently delete this file?"
|
||||
" Once deletion begins, "
|
||||
"the file will not be recoverable.");
|
||||
if (m_selections.count() > 1) {
|
||||
message = QObject::tr("Are you sure you want to permanently delete these %1 files?"
|
||||
" Once deletion begins, "
|
||||
"these file will not be recoverable.").arg(m_selections.count());
|
||||
}
|
||||
|
||||
result = QMessageBox::question(nullptr, "", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||
auto result = QMessageBox::question(nullptr, tr("Delete Permanently"), tr("Are you sure that you want to delete these files? "
|
||||
"Once you start a deletion, the files deleting will never be "
|
||||
"restored again."),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
|
||||
if (result == QMessageBox::Yes) {
|
||||
// SoundEffect::getInstance()->recycleBinClearMusic();
|
||||
FileOperationUtils::remove(m_selections);
|
||||
|
@ -1306,25 +1220,10 @@ const QList<QAction *> DirectoryViewMenu::constructSearchActions()
|
|||
return l;
|
||||
}
|
||||
|
||||
bool DirectoryViewMenu::isMultVideoOrAudio(std::shared_ptr<FileInfo> info)
|
||||
{
|
||||
if (!info) {
|
||||
qDebug() << "file info not valid";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString uri = info->uri();
|
||||
if (uri.startsWith("mult:///") && (info->isAudioFile() || info->isVideoFile())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const QList<QAction *> DirectoryViewMenu::constructMenuPluginActions()
|
||||
{
|
||||
QList<QAction *> l;
|
||||
if (!m_is_favorite && !m_is_label_model) {
|
||||
if (!m_is_favorite) {
|
||||
auto pluginIds = MenuPluginManager::getInstance()->getPluginIds();
|
||||
//sort plugiins by name, so the menu option orders is relatively fixed
|
||||
std::sort(pluginIds.begin(), pluginIds.end());
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define DIRECTORYVIEWMENU_H
|
||||
|
||||
#include <QMenu>
|
||||
#include <memory>
|
||||
#include "peony-core_global.h"
|
||||
|
||||
#include "directory-view-plugin-iface2.h"
|
||||
|
@ -32,7 +31,6 @@
|
|||
namespace Peony {
|
||||
|
||||
class FMWindowIface;
|
||||
class FileInfo;
|
||||
|
||||
/*!
|
||||
* \brief The DirectoryViewMenu class
|
||||
|
@ -72,9 +70,6 @@ protected:
|
|||
const QList<QAction *> constructSearchActions();
|
||||
const QList<QAction *> constructMultiSelectActions();
|
||||
|
||||
private:
|
||||
bool isMultVideoOrAudio(std::shared_ptr<FileInfo> info);
|
||||
|
||||
private:
|
||||
FMWindowIface *m_top_window;
|
||||
|
||||
|
@ -97,8 +92,6 @@ private:
|
|||
bool m_is_smb_file = false;
|
||||
bool m_is_mobile_file = false;
|
||||
bool m_is_boxpath = false;
|
||||
bool m_is_mtp_ptp = false;
|
||||
bool m_is_label_model = false;
|
||||
|
||||
const int ELIDE_TEXT_LENGTH = 16;
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
//tag file
|
||||
#include "file-label-model.h"
|
||||
#include "tag-management.h"
|
||||
#include <QMenu>
|
||||
|
||||
#include <QAction>
|
||||
|
@ -193,17 +192,6 @@ QList<QAction *> FileLabelInternalMenuPlugin::menuActions(MenuPluginInterface::T
|
|||
m_label = labelWidget;
|
||||
labelWidgetContainer->setDefaultWidget(labelWidget);
|
||||
l<<labelWidgetContainer;
|
||||
|
||||
QAction *tagAction = new QAction(tr("label management ..."), this);
|
||||
connect(tagAction, &QAction::triggered, this, [=]() {
|
||||
TagManagement *managent = TagManagement::getInstance();
|
||||
managent->show();
|
||||
});
|
||||
l<<tagAction;
|
||||
|
||||
connect(labelWidget, &FileLabelWidget::changeText, this, [=](const QString &text) {
|
||||
tagAction->setText(text);
|
||||
});
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
@ -259,7 +247,6 @@ QList<QAction *> CreateSharedFileLinkMenuPlugin::menuActions(MenuPluginInterface
|
|||
void FileLabelWidget::clickItem(int index)
|
||||
{
|
||||
m_colorgroup->button(index)->setFocus();
|
||||
static_cast<ColorPushButton*>(m_colorgroup->button(index))->m_checkInMultiSelect = true;
|
||||
QList<int> updateids;
|
||||
updateids = m_ids;
|
||||
if(m_selectionUris->count() == 1){
|
||||
|
@ -315,10 +302,8 @@ void FileLabelWidget::clickItem(int index)
|
|||
|
||||
FileLabelWidget::FileLabelWidget(const QStringList &selectionUris)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
m_selectionUris = const_cast<QStringList*>(&selectionUris);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
auto hbox = new QHBoxLayout;
|
||||
auto items = FileLabelModel::getGlobalModel()->getAllFileLabelItems();
|
||||
|
||||
|
@ -328,22 +313,17 @@ FileLabelWidget::FileLabelWidget(const QStringList &selectionUris)
|
|||
|
||||
int btnid = 1;
|
||||
for (auto item : items) {
|
||||
if (!item->isValidInMenu()) {
|
||||
continue;
|
||||
}
|
||||
ColorPushButton *colorButton=new ColorPushButton(item->color(),this);
|
||||
colorButton->setName(item->name());
|
||||
|
||||
colorButton->palette().window();
|
||||
colorButton->setCheckable(true);
|
||||
colorButton->setEnabled(true);
|
||||
QList<int> ids;
|
||||
bool checkInMultiSelect = true;
|
||||
|
||||
for (auto selectionUri : selectionUris) {
|
||||
auto id = FileLabelModel::getGlobalModel()->getFileLabelIds(selectionUri);
|
||||
checkInMultiSelect = checkInMultiSelect ? id.contains(item->id()) : false ;
|
||||
ids.append(id);
|
||||
}
|
||||
colorButton->m_checkInMultiSelect = checkInMultiSelect;
|
||||
ids = ids.toSet().toList();
|
||||
m_ids = ids;
|
||||
bool checked = ids.contains(item->id());
|
||||
|
@ -351,33 +331,16 @@ FileLabelWidget::FileLabelWidget(const QStringList &selectionUris)
|
|||
colorButton->setChecked(checked);
|
||||
colorgroup->button(btnid)->setChecked(checked);
|
||||
|
||||
connect(colorButton, &ColorPushButton::changeText, this, &FileLabelWidget::changeText);
|
||||
|
||||
btnid++;
|
||||
}
|
||||
|
||||
for (QWidget * item : m_colorgroup->buttons()) {
|
||||
hbox->addWidget(item,0);
|
||||
item->installEventFilter(this);
|
||||
}
|
||||
hbox->setAlignment(Qt::AlignLeft);
|
||||
mainLayout->addLayout(hbox);
|
||||
this->setLayout(mainLayout);
|
||||
}
|
||||
|
||||
this->setLayout(hbox);
|
||||
|
||||
connect(m_colorgroup,SIGNAL(buttonClicked(int)),this,SLOT(clickItem(int)));
|
||||
}
|
||||
|
||||
void FileLabelWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
bool isUnderMouse = false;
|
||||
QString manager;
|
||||
for (QWidget * item : m_colorgroup->buttons()) {
|
||||
if(item->underMouse()) {
|
||||
isUnderMouse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isUnderMouse){
|
||||
Q_EMIT changeText(tr("label management ..."));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,15 +131,9 @@ public:
|
|||
friend class FileLabelInternalMenuPlugin;
|
||||
Q_OBJECT
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeText(const QString &text);
|
||||
|
||||
public Q_SLOTS:
|
||||
void clickItem(int index);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
private:
|
||||
explicit FileLabelWidget(const QStringList &selectionUris);
|
||||
QStringList *m_selectionUris;
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include <QAction>
|
||||
#include <QModelIndex>
|
||||
#include "format_dialog.h"
|
||||
#include "format-dlg-create-delegate.h"
|
||||
|
||||
#ifndef KY_UDF_BURN
|
||||
#include "disccontrol.h"
|
||||
|
@ -140,23 +139,22 @@ const QList<QAction *> SideBarMenu::constructFileSystemItemActions()
|
|||
QList<QAction *> l;
|
||||
/* 卸载 */
|
||||
bool isWayland = qApp->property("isWayland").toBool(); // related to #105070
|
||||
//fix bug#175330, wayland should be the same with mainline version
|
||||
// if (isWayland) {
|
||||
// if (m_item->isUnmountable()) {
|
||||
// l<<addAction(QIcon::fromTheme("media-eject-symbolic"), tr("Unmount"), [=]() {
|
||||
// m_item->unmount();
|
||||
// });
|
||||
// l.last()->setEnabled(m_item->isMounted());
|
||||
// }
|
||||
// } else {
|
||||
/* 可用的U盘、外接移动硬盘、外接移动光盘, 右键菜单里不允许有“卸载”选项,bug#83206 */
|
||||
if (!(m_item->isEjectable() || m_item->isStopable()) && m_item->isUnmountable()) {
|
||||
l<<addAction(QIcon::fromTheme("media-eject-symbolic"), tr("Unmount"), [=]() {
|
||||
m_item->unmount();
|
||||
});
|
||||
l.last()->setEnabled(m_item->isMounted());
|
||||
if (isWayland) {
|
||||
if (m_item->isUnmountable()) {
|
||||
l<<addAction(QIcon::fromTheme("media-eject-symbolic"), tr("Unmount"), [=]() {
|
||||
m_item->unmount();
|
||||
});
|
||||
l.last()->setEnabled(m_item->isMounted());
|
||||
}
|
||||
} else {
|
||||
/* 可用的U盘、外接移动硬盘、外接移动光盘, 右键菜单里不允许有“卸载”选项,bug#83206 */
|
||||
if (!(m_item->isEjectable() || m_item->isStopable()) && m_item->isUnmountable()) {
|
||||
l<<addAction(QIcon::fromTheme("media-eject-symbolic"), tr("Unmount"), [=]() {
|
||||
m_item->unmount();
|
||||
});
|
||||
l.last()->setEnabled(m_item->isMounted());
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
/* 弹出 */
|
||||
if (m_item->isEjectable()||m_item->isStopable()) {
|
||||
|
@ -215,7 +213,7 @@ const QList<QAction *> SideBarMenu::constructFileSystemItemActions()
|
|||
if(discControl->work()){
|
||||
connect(discControl, &DiscControl::workFinished, [=](DiscControl *discCtrl){
|
||||
connect(action, &QAction::triggered, [=](){
|
||||
UdfFormatDialog *udfFormatDlg = FormatDlgCreateDelegate::getInstance()->createUdfDlg(uri, discCtrl);
|
||||
UdfFormatDialog *udfFormatDlg = new UdfFormatDialog(uri, discCtrl);
|
||||
udfFormatDlg->show();
|
||||
});
|
||||
qDebug()<<unixDevice<<" supported Udf values are:"<<discCtrl->supportUdf();
|
||||
|
@ -229,7 +227,7 @@ const QList<QAction *> SideBarMenu::constructFileSystemItemActions()
|
|||
if(discControl->work()){
|
||||
connect(discControl, &UdfBurn::DiscControl::workFinished, [=](UdfBurn::DiscControl *discCtrl){
|
||||
connect(action, &QAction::triggered, [=](){
|
||||
UdfBurn::UdfFormatDialogWrapper *udfFormatDlg = FormatDlgCreateDelegate::getInstance()->createUdfDlgWrapper(uri, discCtrl);
|
||||
UdfBurn::UdfFormatDialog *udfFormatDlg = new UdfFormatDialog(uri, discCtrl);
|
||||
udfFormatDlg->show();
|
||||
});
|
||||
qDebug()<<unixDevice<<" supported Udf values are:"<<discCtrl->supportUdf();
|
||||
|
@ -245,7 +243,7 @@ const QList<QAction *> SideBarMenu::constructFileSystemItemActions()
|
|||
FileInfoJob job (uri, this);
|
||||
job.querySync ();
|
||||
}
|
||||
Format_Dialog *fd = FormatDlgCreateDelegate::getInstance()->createUDiskDlg(uri, m_item);
|
||||
Format_Dialog *fd = new Format_Dialog(uri, m_item);
|
||||
fd->show();
|
||||
});
|
||||
}
|
||||
|
@ -324,13 +322,13 @@ const QList<QAction *> SideBarMenu::constructFileSystemItemActions()
|
|||
void SideBarMenu::gotoAboutComputer()
|
||||
{
|
||||
QProcess p;
|
||||
p.setProgram("/usr/bin/ukui-control-center");
|
||||
p.setProgram("ukui-control-center");
|
||||
//-m About para to show about computer infos, related to bug#88258
|
||||
p.setArguments(QStringList()<<"-m" << "About");
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
p.startDetached();
|
||||
#else
|
||||
p.startDetached("/usr/bin/ukui-control-center", QStringList()<<"-m" << "About");
|
||||
p.startDetached("ukui-control-center", QStringList()<<"-m" << "About");
|
||||
#endif
|
||||
p.waitForFinished(-1);
|
||||
}
|
||||
|
|
|
@ -96,11 +96,6 @@ AdvancedLocationBar::AdvancedLocationBar(QWidget *parent) : QWidget(parent)
|
|||
{
|
||||
Q_EMIT searchRequest(m_last_non_search_path, key);
|
||||
m_last_key = key;
|
||||
if (key == "") {
|
||||
m_search_bar->updateSearchProgress(false);
|
||||
} else {
|
||||
m_search_bar->updateSearchProgress(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -109,8 +104,6 @@ AdvancedLocationBar::AdvancedLocationBar(QWidget *parent) : QWidget(parent)
|
|||
Q_EMIT this->updateFileTypeFilter(index);
|
||||
});
|
||||
|
||||
connect(this, &Peony::AdvancedLocationBar::updateSearchProgress, m_search_bar, &Peony::SearchBarContainer::updateSearchProgress);
|
||||
|
||||
bool is_intel = (QString::compare("V10SP1-edu", GlobalSettings::getInstance()->getProjectName(), Qt::CaseInsensitive) == 0);
|
||||
if (is_intel) {
|
||||
QToolButton* indicator = m_bar->findChild<QToolButton*>("peony_location_bar_indicator");
|
||||
|
|
|
@ -48,7 +48,6 @@ Q_SIGNALS:
|
|||
void searchRequest(const QString &path, const QString &key);
|
||||
void updateFileTypeFilter(const int &index);
|
||||
void clearTrash();
|
||||
void updateSearchProgress(bool searching);
|
||||
|
||||
public Q_SLOTS:
|
||||
void updateLocation(const QString &uri);
|
||||
|
|
|
@ -155,8 +155,6 @@ LocationBar::~LocationBar()
|
|||
|
||||
void LocationBar::setRootUri(const QString &uri)
|
||||
{
|
||||
m_indicator->setFixedSize(this->height() - 2, this->height() - 2);
|
||||
|
||||
Q_EMIT aboutToSetRootUri();
|
||||
|
||||
//when is the same uri and has buttons return
|
||||
|
@ -167,7 +165,7 @@ void LocationBar::setRootUri(const QString &uri)
|
|||
|
||||
//clear buttons
|
||||
clearButtons();
|
||||
if (m_current_uri.startsWith("search://") ) {
|
||||
if (m_current_uri.startsWith("search://")) {
|
||||
//m_indicator->setArrowType(Qt::NoArrow);
|
||||
addButton(m_current_uri, false, false);
|
||||
//fix bug 94229, show button
|
||||
|
@ -175,12 +173,6 @@ void LocationBar::setRootUri(const QString &uri)
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_current_uri.startsWith("label://")) {
|
||||
addButton(m_current_uri);
|
||||
doLayout();
|
||||
return;
|
||||
}
|
||||
|
||||
m_current_info = FileInfo::fromUri(uri);
|
||||
m_buttons_info.clear();
|
||||
auto tmpUri = uri;
|
||||
|
@ -199,32 +191,37 @@ void LocationBar::setRootUri(const QString &uri)
|
|||
|
||||
for (auto info : m_buttons_info) {
|
||||
auto infoJob = new FileInfoJob(info);
|
||||
//infoJob->setAutoDelete();
|
||||
// enumerate buttons info directory
|
||||
auto enumerator = new FileEnumerator;
|
||||
//comment to fix kydroid path show abnormal issue
|
||||
//enumerator->setEnumerateWithInfoJob();
|
||||
connect(this, &LocationBar::aboutToSetRootUri, enumerator, [=]{
|
||||
enumerator->setProperty("isCancelled", true);
|
||||
enumerator->cancel();
|
||||
infoJob->setAutoDelete();
|
||||
connect(this, &LocationBar::aboutToSetRootUri, infoJob, [=]{
|
||||
infoJob->setProperty("isCancelled", true);
|
||||
infoJob->cancel();
|
||||
});
|
||||
connect(enumerator, &FileEnumerator::enumerateFinished, this, [=](bool successed){
|
||||
m_querying_buttons_info.removeOne(info);
|
||||
if (successed) {
|
||||
auto infos = enumerator->getChildren();
|
||||
m_infos_hash.insert(info.get()->uri(), infos);
|
||||
if (m_querying_buttons_info.isEmpty()) {
|
||||
// add buttons
|
||||
clearButtons();
|
||||
for (auto info : m_buttons_info) {
|
||||
addButton(info.get()->uri().toLocal8Bit(), true, true);
|
||||
}
|
||||
doLayout();
|
||||
}
|
||||
} else {
|
||||
connect(infoJob, &FileInfoJob::queryAsyncFinished, this, [=](bool successed){
|
||||
if (!successed) {
|
||||
qWarning()<<"can not query file:"<<info->uri();
|
||||
// 避免上一次的取消操作影响此次的结果,这个通常发生在极短时间内进行连续跳转的情况下
|
||||
// 从peony的交互来看基本不会触发,但是文件对话框的流程可能会触发这种情况
|
||||
if (!enumerator->property("isCancelled").toBool()) {
|
||||
if (!infoJob->property("isCancelled").toBool()) {
|
||||
m_querying_buttons_info.removeOne(info);
|
||||
m_buttons_info.removeOne(info);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// enumerate buttons info directory
|
||||
auto enumerator = new FileEnumerator;
|
||||
enumerator->setEnumerateDirectory(info.get()->uri());
|
||||
//comment to fix kydroid path show abnormal issue
|
||||
//enumerator->setEnumerateWithInfoJob();
|
||||
|
||||
connect(this, &LocationBar::aboutToSetRootUri, enumerator, [=]{
|
||||
enumerator->setProperty("isCancelled", true);
|
||||
enumerator->cancel();
|
||||
});
|
||||
connect(enumerator, &FileEnumerator::enumerateFinished, this, [=](bool successed){
|
||||
m_querying_buttons_info.removeOne(info);
|
||||
if (successed) {
|
||||
auto infos = enumerator->getChildren();
|
||||
m_infos_hash.insert(info.get()->uri(), infos);
|
||||
if (m_querying_buttons_info.isEmpty()) {
|
||||
// add buttons
|
||||
clearButtons();
|
||||
|
@ -233,36 +230,25 @@ void LocationBar::setRootUri(const QString &uri)
|
|||
}
|
||||
doLayout();
|
||||
}
|
||||
} else {
|
||||
// 避免上一次的取消操作影响此次的结果,这个通常发生在极短时间内进行连续跳转的情况下
|
||||
// 从peony的交互来看基本不会触发,但是文件对话框的流程可能会触发这种情况
|
||||
if (!enumerator->property("isCancelled").toBool()) {
|
||||
if (m_querying_buttons_info.isEmpty()) {
|
||||
// add buttons
|
||||
clearButtons();
|
||||
for (auto info : m_buttons_info) {
|
||||
addButton(info.get()->uri().toLocal8Bit(), true, true);
|
||||
}
|
||||
doLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enumerator->deleteLater();
|
||||
});
|
||||
connect(this, &LocationBar::aboutToSetRootUri, infoJob, [=]{
|
||||
infoJob->setProperty("isCancelled", true);
|
||||
infoJob->cancel();
|
||||
});
|
||||
connect(this, &LocationBar::destroyed, infoJob, [=]{
|
||||
infoJob->setProperty("isCancelled", true);
|
||||
infoJob->cancel();
|
||||
});
|
||||
connect(infoJob, &FileInfoJob::queryAsyncFinished, this, [=](bool successed){
|
||||
if (!successed && !info.get()->uri().startsWith("label://")) {
|
||||
qWarning()<<"can not query file:"<<info->uri();
|
||||
// 避免上一次的取消操作影响此次的结果,这个通常发生在极短时间内进行连续跳转的情况下
|
||||
// 从peony的交互来看基本不会触发,但是文件对话框的流程可能会触发这种情况
|
||||
if (!infoJob->property("isCancelled").toBool()) {
|
||||
m_querying_buttons_info.removeOne(info);
|
||||
m_buttons_info.removeOne(info);
|
||||
}
|
||||
enumerator->deleteLater();
|
||||
infoJob->deleteLater();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
enumerator->setEnumerateDirectory(info.get()->uri());
|
||||
enumerator->enumerateAsync();
|
||||
infoJob->deleteLater();
|
||||
});
|
||||
infoJob->queryAsync();
|
||||
}
|
||||
|
@ -308,7 +294,7 @@ void LocationBar::updateButtons()
|
|||
|
||||
for (auto info : m_buttons_info) {
|
||||
auto infoJob = new FileInfoJob(info);
|
||||
//infoJob->setAutoDelete();
|
||||
infoJob->setAutoDelete();
|
||||
connect(infoJob, &FileInfoJob::queryAsyncFinished, this, [=](){
|
||||
// enumerate buttons info directory
|
||||
auto enumerator = new FileEnumerator;
|
||||
|
@ -343,7 +329,6 @@ void LocationBar::updateButtons()
|
|||
});
|
||||
|
||||
enumerator->enumerateAsync();
|
||||
infoJob->deleteLater();
|
||||
});
|
||||
infoJob->queryAsync();
|
||||
}
|
||||
|
@ -559,36 +544,16 @@ void LocationBar::doLayout()
|
|||
|
||||
m_indicator_menu->clear();
|
||||
|
||||
int iconWidth = 0;
|
||||
if (!m_buttons.isEmpty()) {
|
||||
auto button = m_buttons.first();
|
||||
button->setVisible(true);
|
||||
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
iconWidth = button->sizeHint().width();
|
||||
button->setToolButtonStyle(Qt::ToolButtonTextOnly);
|
||||
iconWidth = iconWidth - button->sizeHint().width();
|
||||
button->setVisible(false);
|
||||
}
|
||||
int exceptTotalwidth = 0;
|
||||
for (auto button : m_buttons) {
|
||||
button->setVisible(true);
|
||||
// 默认不做自动文字缩略
|
||||
button->setProperty("elideText", QVariant());
|
||||
button->resize(button->sizeHint().width(), button->height());
|
||||
button->setFixedHeight(this->height()); //fixme
|
||||
button->setFixedHeight(this->height());
|
||||
button->setToolButtonStyle(Qt::ToolButtonTextOnly);
|
||||
button->adjustSize();
|
||||
int sizeHintWidth = button->sizeHint().width();
|
||||
exceptTotalwidth += sizeHintWidth;
|
||||
sizeHints<<sizeHintWidth;
|
||||
sizeHints<<button->sizeHint().width();
|
||||
button->setVisible(false);
|
||||
}
|
||||
|
||||
int totalWidth = this->width() - iconWidth;
|
||||
if (totalWidth < exceptTotalwidth) {
|
||||
totalWidth = totalWidth - m_indicator->width() - 2;
|
||||
}
|
||||
|
||||
int totalWidth = this->width();
|
||||
int currentWidth = 0;
|
||||
int visibleButtonCount = 0;
|
||||
for (int index = sizeHints.count() - 1; index >= 0; index--) {
|
||||
|
@ -625,11 +590,8 @@ void LocationBar::doLayout()
|
|||
if (visibleButtonCount == 0 && !m_buttons.isEmpty()) {
|
||||
auto button = m_buttons.values().at(sizeHints.count() - 1);
|
||||
button->setVisible(true);
|
||||
// 设置自动文字缩略
|
||||
button->setProperty("elideText", true);
|
||||
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
button->move(offset, 0);
|
||||
button->resize(totalWidth, button->height());
|
||||
button->resize(totalWidth - 20, this->height());
|
||||
}
|
||||
|
||||
int spaceCount = 0;
|
||||
|
@ -688,15 +650,7 @@ void LocationBarButtonStyle::drawComplexControl(QStyle::ComplexControl control,
|
|||
opt.features.setFlag(QStyleOptionToolButton::HasMenu, false);
|
||||
return qApp->style()->drawComplexControl(control, &opt, painter);
|
||||
} else {
|
||||
opt.rect.adjust(0, 1, 0, -1); //bug#165286 地址栏中“计算机”文字显示不完整,高度减小2,宽度不变
|
||||
}
|
||||
if (widget) {
|
||||
if (widget->property("elideText").toBool()) {
|
||||
// 设置文字缩略
|
||||
int textWidth = opt.rect.width() - opt.iconSize.width() - (opt.features.testFlag(QStyleOptionToolButton::HasMenu)? 44: 20);
|
||||
auto text = opt.text;
|
||||
opt.text = opt.fontMetrics.elidedText(text, Qt::ElideRight, textWidth);
|
||||
}
|
||||
opt.rect.adjust(1, 1, -1, -1);
|
||||
}
|
||||
return qApp->style()->drawComplexControl(control, &opt, painter, widget);
|
||||
}
|
||||
|
|
|
@ -47,8 +47,6 @@
|
|||
|
||||
#include <QPainter>
|
||||
#include <QGSettings>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusReply>
|
||||
|
||||
#include "icon-container.h"
|
||||
|
||||
|
@ -107,7 +105,7 @@ DefaultPreviewPage::DefaultPreviewPage(QWidget *parent) : QStackedWidget (parent
|
|||
if (QGSettings::isSchemaInstalled("org.ukui.control-center.panel.plugins")) {
|
||||
QGSettings* settings = new QGSettings("org.ukui.control-center.panel.plugins", QByteArray(), this);
|
||||
connect(settings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
if ("hoursystem" == key) {
|
||||
if ("hoursystem" == key || "date" == key) {
|
||||
if (m_support && m_preview_tab_widget) {
|
||||
if (m_info) {
|
||||
FileInfoJob* infoJob = new FileInfoJob(m_info, this);
|
||||
|
@ -121,13 +119,6 @@ DefaultPreviewPage::DefaultPreviewPage(QWidget *parent) : QStackedWidget (parent
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
connect(GlobalSettings::getInstance(),
|
||||
&GlobalSettings::updateLongDataFormat,
|
||||
this,
|
||||
&DefaultPreviewPage::updateDateFormat);
|
||||
#endif
|
||||
}
|
||||
|
||||
DefaultPreviewPage::~DefaultPreviewPage()
|
||||
|
@ -135,35 +126,16 @@ DefaultPreviewPage::~DefaultPreviewPage()
|
|||
cancel();
|
||||
}
|
||||
|
||||
void DefaultPreviewPage::updateDateFormat(QString dateFormat)
|
||||
{
|
||||
//update date and time show format, task #101605
|
||||
qDebug() << "sdk format signal:"<<dateFormat;
|
||||
if (m_date_format != dateFormat){
|
||||
if (m_support && m_preview_tab_widget) {
|
||||
if (m_info) {
|
||||
FileInfoJob* infoJob = new FileInfoJob(m_info, this);
|
||||
infoJob->setAutoDelete(true);
|
||||
connect(infoJob, &FileInfoJob::queryAsyncFinished, this, [=] {
|
||||
m_preview_tab_widget->updateInfo(m_info.get());
|
||||
});
|
||||
infoJob->queryAsync();
|
||||
}
|
||||
}
|
||||
m_date_format = dateFormat;
|
||||
}
|
||||
}
|
||||
|
||||
bool DefaultPreviewPage::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
if (obj == m_preview_tab_widget) {
|
||||
if (ev->type() == QEvent::Resize) {
|
||||
auto e = static_cast<QResizeEvent*>(ev);
|
||||
auto page = qobject_cast<FilePreviewPage*>(m_preview_tab_widget);
|
||||
int width = e->size().width();
|
||||
int width = e->size().width() - 50;
|
||||
width = qMax(width, 96);
|
||||
width = qMin(width, 256);
|
||||
page->resizeIcon(QSize(width* 2/3, width* 3/4));
|
||||
page->resizeIcon(QSize(width, width * 2/3));
|
||||
page->updateForm(e->size());
|
||||
}
|
||||
}
|
||||
|
@ -337,14 +309,11 @@ void FilePreviewPage::wrapData(QLabel *p_label, const QString &text)
|
|||
int width = p_label->width()==0?LABEL_MAX_WIDTH:p_label->width();
|
||||
if(textSize > width){
|
||||
int lastIndex = 0;
|
||||
for(int i = lastIndex+1; i <= wrapText.length(); i++) {
|
||||
QString line = wrapText.mid(lastIndex, i - lastIndex);
|
||||
if(fontMetrics.width(line) == width) {
|
||||
for(int i = lastIndex; i < wrapText.length(); i++) {
|
||||
if(fontMetrics.width(wrapText.mid(lastIndex, i - lastIndex)) == width) {
|
||||
lastIndex = i;
|
||||
if (i != wrapText.length()) {
|
||||
wrapText.insert(i, '\n');
|
||||
}
|
||||
} else if(fontMetrics.width(line) > width) {
|
||||
wrapText.insert(i, '\n');
|
||||
} else if(fontMetrics.width(wrapText.mid(lastIndex, i - lastIndex)) > width) {
|
||||
lastIndex = i;
|
||||
wrapText.insert(i - 1, '\n');
|
||||
} else {
|
||||
|
@ -377,14 +346,6 @@ void FilePreviewPage::updateInfo(FileInfo *info)
|
|||
if (QRegExp("^file:///data/usershare(/{,1})$").exactMatch(info->uri())) {
|
||||
displayName = tr("usershare");
|
||||
}
|
||||
|
||||
QString accessDate = info->accessDate();
|
||||
QString modifyDate = info->modifiedDate();
|
||||
#ifdef KY_SDK_DATE
|
||||
accessDate = GlobalSettings::getInstance()->transToSystemTimeFormat(info->accessTime(), true);
|
||||
modifyDate = GlobalSettings::getInstance()->transToSystemTimeFormat(info->modifiedTime(), true);
|
||||
#endif
|
||||
|
||||
wrapData(m_display_name_label, displayName);
|
||||
m_form_label_map[m_display_name_label] = displayName;
|
||||
|
||||
|
@ -404,11 +365,11 @@ void FilePreviewPage::updateInfo(FileInfo *info)
|
|||
wrapData(m_time_create_label, createTime);
|
||||
m_form_label_map[m_time_create_label] = createTime;
|
||||
|
||||
wrapData(m_time_access_label, accessDate);
|
||||
m_form_label_map[m_time_access_label] = accessDate;
|
||||
wrapData(m_time_access_label, info->accessDate());
|
||||
m_form_label_map[m_time_access_label] = info->accessDate();
|
||||
|
||||
wrapData(m_time_modified_label, modifyDate);
|
||||
m_form_label_map[m_time_modified_label] = modifyDate;
|
||||
wrapData(m_time_modified_label, info->modifiedDate());
|
||||
m_form_label_map[m_time_modified_label] = info->modifiedDate();
|
||||
|
||||
m_file_count_label->setText(tr(""));
|
||||
m_form_label_map[m_file_count_label] = "";
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <memory>
|
||||
#include <QLabel>
|
||||
#include <QMap>
|
||||
#include <QDBusInterface>
|
||||
|
||||
class QVBoxLayout;
|
||||
class QPushButton;
|
||||
class QFormLayout;
|
||||
|
@ -60,9 +60,6 @@ public:
|
|||
void cancel() override;
|
||||
void closePreviewPage() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void updateDateFormat(QString dateFormat);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *ev) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
@ -78,8 +75,6 @@ private:
|
|||
std::shared_ptr<FileWatcher> m_watcher;
|
||||
|
||||
bool m_support = true;
|
||||
QString m_date_format = "";
|
||||
QDBusInterface *mDbusDateServer;
|
||||
};
|
||||
|
||||
class FileCountOperation;
|
||||
|
|
|
@ -395,7 +395,6 @@ void BasicPropertiesPage::loadPartOne()
|
|||
m_displayNameEdit->setToolTip(fileName);
|
||||
fileName = BasicPropertiesPage::elideText(m_displayNameEdit->font(),260,fileName);
|
||||
m_displayNameEdit->setText(fileName);
|
||||
m_displayNameEdit->setToolTip(fileName);
|
||||
delete getNameThread;
|
||||
});
|
||||
getNameThread->start();
|
||||
|
@ -437,8 +436,6 @@ void BasicPropertiesPage::loadPartOne()
|
|||
|
||||
if (fileUri == ("file://" + QStandardPaths::writableLocation(QStandardPaths::HomeLocation))) {
|
||||
disconnect(m_iconButton, &QPushButton::clicked, this, &BasicPropertiesPage::chooseFileIcon);
|
||||
m_iconButton->setFocusPolicy(Qt::NoFocus);
|
||||
m_iconButton->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -489,20 +486,13 @@ void BasicPropertiesPage::loadOptionalData()
|
|||
if (QGSettings::isSchemaInstalled("org.ukui.control-center.panel.plugins")) {
|
||||
QGSettings* settings = new QGSettings("org.ukui.control-center.panel.plugins", QByteArray(), this);
|
||||
connect(settings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
if ("hoursystem" == key) {
|
||||
if ("hoursystem" == key || "date" == key) {
|
||||
setSysTimeFormat();
|
||||
updateInfo(m_info->uri());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
connect(GlobalSettings::getInstance(),
|
||||
&GlobalSettings::updateLongDataFormat,
|
||||
this,
|
||||
&BasicPropertiesPage::updateDateFormat);
|
||||
#endif
|
||||
|
||||
updateInfo(m_info.get()->uri());
|
||||
connect(m_watcher.get(), &FileWatcher::locationChanged, [=](const QString&, const QString &uri) {
|
||||
this->updateInfo(uri);
|
||||
|
@ -615,7 +605,6 @@ void BasicPropertiesPage::onSingleFileChanged(const QString &oldUri, const QStri
|
|||
}
|
||||
|
||||
m_displayNameEdit->setText(fileName);
|
||||
m_displayNameEdit->setToolTip(fileName);
|
||||
|
||||
if (thumbnail.isNull()) {
|
||||
ThumbnailManager::getInstance()->createThumbnail(m_info.get()->uri(), m_thumbnail_watcher);
|
||||
|
@ -658,21 +647,7 @@ void BasicPropertiesPage::countFilesAsync(const QStringList &uris)
|
|||
m_countOp = new FileCountOperation(realUris.isEmpty() ? uris : realUris);
|
||||
DEBUG << "symlinkTarget:" << info.get()->symlinkTarget();
|
||||
} else {
|
||||
QStringList lists;
|
||||
for (auto uri : uris) {
|
||||
auto info = FileInfo::fromUri(uri);
|
||||
if (info->isSymbolLink()) {
|
||||
if (!info.get()->symlinkTarget().isEmpty()) {
|
||||
QString temp = "file://" + info.get()->symlinkTarget();
|
||||
lists.append(temp);
|
||||
} else {
|
||||
lists.append(uri);
|
||||
}
|
||||
} else {
|
||||
lists.append(uri);
|
||||
}
|
||||
}
|
||||
m_countOp = new FileCountOperation(lists);
|
||||
m_countOp = new FileCountOperation(uris);
|
||||
}
|
||||
|
||||
m_countOp->setAutoDelete(true);
|
||||
|
@ -697,37 +672,27 @@ void BasicPropertiesPage::countFilesAsync(const QStringList &uris)
|
|||
return;
|
||||
}
|
||||
QUrl url(uri);
|
||||
if (url.isLocalFile()) {
|
||||
std::shared_ptr<FileInfo> fileInfo = FileInfo::fromUri(uri);
|
||||
FileInfoJob *fileInfoJob = new FileInfoJob(fileInfo);
|
||||
fileInfoJob->setAutoDelete();
|
||||
fileInfoJob->querySync();
|
||||
//某些带空格的文件名称会导致命令错误,加上引号解决此问题。
|
||||
QString path;
|
||||
if(uri == "filesafe:///") {
|
||||
path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.box";
|
||||
bool isLocalFile = url.isLocalFile();
|
||||
//某些带空格的文件名称会导致命令错误,加上引号解决此问题。
|
||||
QString path;
|
||||
if(uri == "filesafe:///") {
|
||||
path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.box";
|
||||
} else {
|
||||
g_autoptr (GFile) gfile = g_file_new_for_uri(uri.toUtf8().constData());
|
||||
g_autofree gchar *gpath = g_file_get_path(gfile);
|
||||
if (gpath) {
|
||||
path = gpath;
|
||||
} else {
|
||||
// g_autoptr (GFile) gfile = g_file_new_for_uri(uri.toUtf8().constData());
|
||||
// g_autofree gchar *gpath = g_file_get_path(gfile);
|
||||
// if (gpath) {
|
||||
// path = gpath;
|
||||
// } else {
|
||||
path = QString("%1%2%3").arg("\"").arg(url.path()).arg("\"");
|
||||
// }
|
||||
path = QString("%1%2%3").arg("\"").arg(url.path()).arg("\"");
|
||||
}
|
||||
|
||||
|
||||
QProcess process;
|
||||
if (fileInfo->isSymbolLink()) {
|
||||
process.start("/usr/bin/du -L " + path);
|
||||
} else {
|
||||
process.start("/usr/bin/du -s " + path);
|
||||
}
|
||||
process.waitForFinished();
|
||||
QString result = process.readAllStandardOutput();
|
||||
//du -s xxx 输出格式:4 xxx (大小单位为KB)
|
||||
m_fileTotalSizeCount += result.split(QRegExp("\\s+")).first().toLong();
|
||||
}
|
||||
|
||||
QProcess process;
|
||||
process.start("du -s " + path);
|
||||
process.waitForFinished();
|
||||
QString result = process.readAllStandardOutput();
|
||||
//du -s xxx 输出格式:4 xxx (大小单位为KB)
|
||||
m_fileTotalSizeCount += result.split(QRegExp("\\s+")).first().toLong();
|
||||
}
|
||||
//转换为 xx Bytes
|
||||
m_fileTotalSizeCount *= CELL1K;
|
||||
|
@ -904,12 +869,12 @@ void BasicPropertiesPage::saveAllChange()
|
|||
QString desktopUri = Peony::FileUtils::getEncodedUri(desktopPath);
|
||||
//if (m_info.get()->uri().contains(desktopUri) && m_info.get()->isSymbolLink()) {
|
||||
QProcess p;
|
||||
p.setProgram("/usr/bin/touch");
|
||||
p.setProgram("touch");
|
||||
p.setArguments(QStringList()<<"-h"<<m_info->filePath());
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
p.startDetached();
|
||||
#else
|
||||
p.startDetached("/usr/bin/touch", QStringList()<<"-h"<<m_info->filePath());
|
||||
p.startDetached("touch", QStringList()<<"-h"<<m_info->filePath());
|
||||
#endif
|
||||
p.waitForFinished(-1);
|
||||
//}
|
||||
|
@ -921,19 +886,6 @@ void BasicPropertiesPage::chooseFileIcon()
|
|||
iconPathUrl.setPath("/usr/share/icons");
|
||||
auto picture = QFileDialog::getOpenFileName(nullptr, tr("Choose a custom icon"), "/usr/share/icons", "*.png *.jpg *.jpeg *.svg");
|
||||
|
||||
QFileInfo fileInfo(picture);
|
||||
if (fileInfo.exists()) {
|
||||
qint64 fileSize = fileInfo.size();
|
||||
double fileSizeMB = fileSize / (1024.0 * 1024.0);
|
||||
qDebug() << "fileSize is :" << fileSizeMB << "MB";
|
||||
if (fileSizeMB > 1.0) {
|
||||
QMessageBox::warning(nullptr, "", tr("Please select a image that is smaller than 1MB."));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "file does not exist :" << picture;
|
||||
}
|
||||
|
||||
if (!picture.isEmpty()) {
|
||||
qDebug()<<"chose new file icon:"<< picture;
|
||||
m_iconButton->setIcon(QIcon(picture));
|
||||
|
@ -990,16 +942,6 @@ void BasicPropertiesPage::updateCountInfo(bool isDone)
|
|||
}
|
||||
}
|
||||
|
||||
void BasicPropertiesPage::updateDateFormat(QString dateFormat)
|
||||
{
|
||||
//update date and time show format, task #101605
|
||||
qDebug() << "sdk format signal:"<<dateFormat;
|
||||
if (m_date_format != dateFormat){
|
||||
updateInfo(m_info->uri());
|
||||
m_date_format = dateFormat;
|
||||
}
|
||||
}
|
||||
|
||||
void BasicPropertiesPage::updateInfo(const QString &uri)
|
||||
{
|
||||
//QT获取文件相关时间 ,
|
||||
|
@ -1033,17 +975,15 @@ void BasicPropertiesPage::updateInfo(const QString &uri)
|
|||
|
||||
m_timeModified = g_file_info_get_attribute_uint64(info,"time::modified");
|
||||
if(m_timeModifiedLabel) {
|
||||
// QDateTime date2 = QDateTime::fromMSecsSinceEpoch(m_timeModified*1000);
|
||||
// QString time2 = date2.toString(m_systemTimeFormat);
|
||||
QString time2 = GlobalSettings::getInstance()->transToSystemTimeFormat(m_timeModified, true);
|
||||
QDateTime date2 = QDateTime::fromMSecsSinceEpoch(m_timeModified*1000);
|
||||
QString time2 = date2.toString(m_systemTimeFormat);
|
||||
m_timeModifiedLabel->setText(time2);
|
||||
}
|
||||
|
||||
if(m_timeAccessLabel) {
|
||||
m_timeAccess = g_file_info_get_attribute_uint64(info,"time::access");
|
||||
// QDateTime date3 = QDateTime::fromMSecsSinceEpoch(m_timeAccess*1000);
|
||||
// QString time3 = date3.toString(m_systemTimeFormat);
|
||||
QString time3 = GlobalSettings::getInstance()->transToSystemTimeFormat(m_timeAccess, true);
|
||||
QDateTime date3 = QDateTime::fromMSecsSinceEpoch(m_timeAccess*1000);
|
||||
QString time3 = date3.toString(m_systemTimeFormat);
|
||||
m_timeAccessLabel->setText(time3);
|
||||
}
|
||||
|
||||
|
@ -1059,9 +999,8 @@ void BasicPropertiesPage::updateInfo(const QString &uri)
|
|||
// minTime = qMin (minTime, m_timeAccess);
|
||||
// m_timeCreated = minTime;
|
||||
if (m_timeCreated) {
|
||||
// QDateTime createDate = QDateTime::fromMSecsSinceEpoch(m_timeCreated*1000);
|
||||
// QString createTime = createDate.toString(m_systemTimeFormat);
|
||||
QString createTime = GlobalSettings::getInstance()->transToSystemTimeFormat(m_timeCreated, true);
|
||||
QDateTime createDate = QDateTime::fromMSecsSinceEpoch(m_timeCreated*1000);
|
||||
QString createTime = createDate.toString(m_systemTimeFormat);
|
||||
m_timeCreatedLabel->setText(createTime);
|
||||
} else {
|
||||
QFormLayout *layout = this->findChild<QFormLayout*>("floorTwoBaseLayout");
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include <QtConcurrent>
|
||||
#include <QProxyStyle>
|
||||
#include <QComboBox>
|
||||
#include <QDBusInterface>
|
||||
|
||||
#include "properties-window-tab-iface.h"
|
||||
#include "open-with-properties-page.h"
|
||||
|
@ -145,7 +144,6 @@ protected Q_SLOTS:
|
|||
void onFileCountOne(const QString &uri, quint64 size);
|
||||
void cancelCount();
|
||||
void updateInfo(const QString &uri);
|
||||
void updateDateFormat(QString dateFormat);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
|
@ -205,9 +203,6 @@ private:
|
|||
|
||||
QTimer *m_timer = nullptr;
|
||||
bool m_isReadOnly = false;
|
||||
|
||||
QString m_date_format = "";
|
||||
QDBusInterface *mDbusDateServer;
|
||||
};
|
||||
|
||||
class PushButtonStyle : public QProxyStyle
|
||||
|
|
|
@ -53,12 +53,9 @@ ComputerPropertiesPage::ComputerPropertiesPage(const QString &uri, QWidget *pare
|
|||
{
|
||||
m_uri = uri;
|
||||
m_layout = new QFormLayout(this);
|
||||
m_layout->setContentsMargins(24, 16, 24, 16);
|
||||
m_layout->setRowWrapPolicy(QFormLayout::WrapLongRows);
|
||||
m_layout->setFormAlignment(Qt::AlignLeft);
|
||||
m_layout->setVerticalSpacing(8);
|
||||
m_layout->setHorizontalSpacing(24);
|
||||
//m_layout->setLabelAlignment(Qt::AlignRight);
|
||||
m_layout->setLabelAlignment(Qt::AlignRight);
|
||||
setLayout(m_layout);
|
||||
|
||||
if (uri == "computer:///") {
|
||||
|
@ -262,7 +259,7 @@ ComputerPropertiesPage::ComputerPropertiesPage(const QString &uri, QWidget *pare
|
|||
auto pushbutton = new QPushButton(tr("Kylin Burner"));
|
||||
connect(pushbutton, &QPushButton::clicked, pushbutton, [=](){
|
||||
QProcess p;
|
||||
p.startDetached("/usr/bin/kylin-burner");
|
||||
p.startDetached("kylin-burner");
|
||||
p.waitForStarted();
|
||||
});
|
||||
m_layout->addRow(new QLabel(tr("Open with: \t")), pushbutton);
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include "linux-pwd-helper.h"
|
||||
#include "global-settings.h"
|
||||
#include "file-watcher.h"
|
||||
#include "global-settings.h"
|
||||
|
||||
using namespace Peony;
|
||||
|
||||
|
@ -94,8 +93,6 @@ QWidget *DetailsPropertiesPage::createTableRow(QString labelText, QLabel *conten
|
|||
QLabel *label1 = this->createFixedLabel(FIXED_LABEL_WIDTH,0,labelText,row);
|
||||
label1->setContentsMargins(22,0,0,0);
|
||||
|
||||
contentLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||
contentLabel->setCursor(Qt::IBeamCursor);
|
||||
boxLayout->addWidget(label1);
|
||||
boxLayout->addWidget(contentLabel);
|
||||
boxLayout->addStretch(1);
|
||||
|
@ -113,11 +110,8 @@ QWidget *DetailsPropertiesPage::createTableRow(QString labelText, QString conten
|
|||
QLabel *label1 = this->createFixedLabel(FIXED_LABEL_WIDTH,0,labelText,row);
|
||||
label1->setContentsMargins(22,0,0,0);
|
||||
|
||||
QLabel *labelContent = this->createFixedLabel(0,0,content,row);
|
||||
labelContent->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||
labelContent->setCursor(Qt::IBeamCursor);
|
||||
boxLayout->addWidget(label1);
|
||||
boxLayout->addWidget(labelContent);
|
||||
boxLayout->addWidget(this->createFixedLabel(0,0,content,row));
|
||||
boxLayout->addStretch(1);
|
||||
|
||||
return row;
|
||||
|
@ -212,22 +206,15 @@ void DetailsPropertiesPage::initDetailsPropertiesPage()
|
|||
// set time
|
||||
connect(GlobalSettings::getInstance(), &GlobalSettings::valueChanged, this, [=] (const QString& key) {
|
||||
if (UKUI_CONTROL_CENTER_PANEL_PLUGIN_TIME == key) {
|
||||
// if ("12" == GlobalSettings::getInstance()->getValue(key)) {
|
||||
// setSystemTimeFormat(tr("yyyy-MM-dd, hh:mm:ss AP"));
|
||||
// } else if ("24" == GlobalSettings::getInstance()->getValue(key)) {
|
||||
// setSystemTimeFormat(tr("yyyy-MM-dd, HH:mm:ss"));
|
||||
// }
|
||||
if ("12" == GlobalSettings::getInstance()->getValue(key)) {
|
||||
setSystemTimeFormat(tr("yyyy-MM-dd, hh:mm:ss AP"));
|
||||
} else if ("24" == GlobalSettings::getInstance()->getValue(key)) {
|
||||
setSystemTimeFormat(tr("yyyy-MM-dd, HH:mm:ss"));
|
||||
}
|
||||
updateFileInfo(m_fileInfo.get()->uri());
|
||||
}
|
||||
});
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
connect(GlobalSettings::getInstance(),
|
||||
&GlobalSettings::updateLongDataFormat,
|
||||
this,
|
||||
&DetailsPropertiesPage::updateDateFormat);
|
||||
#endif
|
||||
|
||||
//size
|
||||
this->addRow(tr("File size:"),m_fileInfo->fileSize());
|
||||
|
||||
|
@ -278,16 +265,6 @@ void DetailsPropertiesPage::setSystemTimeFormat(QString format)
|
|||
this->m_systemTimeFormat = format;
|
||||
}
|
||||
|
||||
void DetailsPropertiesPage::updateDateFormat(QString dateFormat)
|
||||
{
|
||||
//update date and time show format, task #101605
|
||||
qDebug() << "sdk format signal:"<<dateFormat;
|
||||
if (m_date_format != dateFormat){
|
||||
updateFileInfo(m_fileInfo.get()->uri());
|
||||
m_date_format = dateFormat;
|
||||
}
|
||||
}
|
||||
|
||||
void DetailsPropertiesPage::updateFileInfo(const QString &uri)
|
||||
{
|
||||
this->getFIleInfo();
|
||||
|
@ -334,9 +311,8 @@ void DetailsPropertiesPage::updateFileInfo(const QString &uri)
|
|||
g_object_unref(file);
|
||||
|
||||
quint64 timeNum2 = g_file_info_get_attribute_uint64(info,"time::modified");
|
||||
// QDateTime date2 = QDateTime::fromMSecsSinceEpoch(timeNum2*1000);
|
||||
// QString time2 = date2.toString(m_systemTimeFormat);
|
||||
QString time2 = GlobalSettings::getInstance()->transToSystemTimeFormat(timeNum2, true);
|
||||
QDateTime date2 = QDateTime::fromMSecsSinceEpoch(timeNum2*1000);
|
||||
QString time2 = date2.toString(m_systemTimeFormat);
|
||||
m_modifyDateLabel->setText(time2);
|
||||
|
||||
g_object_unref(info);
|
||||
|
|
|
@ -62,9 +62,6 @@ public:
|
|||
Q_SIGNALS:
|
||||
void fileInfoReady();
|
||||
|
||||
public Q_SLOTS:
|
||||
void updateDateFormat(QString dateFormat);
|
||||
|
||||
private:
|
||||
QString m_uri = nullptr;
|
||||
std::shared_ptr<FileInfo> m_fileInfo = nullptr;
|
||||
|
@ -87,8 +84,6 @@ private:
|
|||
QLabel *m_localLabel = nullptr;
|
||||
QLabel *m_nameLabel = nullptr;
|
||||
|
||||
QString m_date_format = "";
|
||||
|
||||
QWidget *createTableRow(QString labelText, QString content);
|
||||
QWidget *createTableRow(QString labelText, QLabel *contentLabel);
|
||||
|
||||
|
|
|
@ -31,11 +31,6 @@
|
|||
#include <QDebug>
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
|
||||
#ifdef KY_SDK_QT_WIDGETS
|
||||
#include "kborderlessbutton.h"
|
||||
using namespace kdk;
|
||||
#endif
|
||||
|
||||
using namespace Peony;
|
||||
OpenWithGlobalData *OpenWithPropertiesPage::openWithGlobalData = nullptr;
|
||||
|
||||
|
@ -108,7 +103,7 @@ void OpenWithPropertiesPage::initFloorOne()
|
|||
QLabel *targetTypeMsgLabel = new QLabel(floor1);
|
||||
targetTypeMsgLabel->setMinimumHeight(60);
|
||||
qDebug() << "targetTypeMsgLabel :" << targetTypeMsgLabel->height();
|
||||
targetTypeMsgLabel->setText(tr("How do you want to open \"%1%2\" files ?").arg(".").arg(m_fileInfo.get()->displayName().split(".").last()));
|
||||
targetTypeMsgLabel->setText(tr("How do you want to open %1%2 files ?").arg(".").arg(m_fileInfo.get()->displayName().split(".").last()));
|
||||
layout1->addWidget(targetTypeMsgLabel);
|
||||
|
||||
QLabel *defaultOpenLabel = new QLabel(floor1);
|
||||
|
@ -170,12 +165,7 @@ void OpenWithPropertiesPage::initFloorThree()
|
|||
floor3->setLayout(layout3);
|
||||
floor3->setMaximumHeight(122);
|
||||
layout3->setContentsMargins(22, 0, 0, 0);
|
||||
#ifdef KY_SDK_QT_WIDGETS
|
||||
KBorderlessButton *allOpenLabel = new KBorderlessButton(tr("Choose other application"), floor3);
|
||||
KBorderlessButton *otherOpenLabel = new KBorderlessButton(tr("Go to application center"), floor3);
|
||||
connect(allOpenLabel, &KBorderlessButton::clicked, this, &OpenWithPropertiesPage::chooseOtherApp);
|
||||
connect(otherOpenLabel, &KBorderlessButton::clicked, this, &OpenWithPropertiesPage::openAppCenter);
|
||||
#else
|
||||
|
||||
QString str1;
|
||||
str1 = "<a href=\"ukui-software-center\" style=\"color: #3D6BE5;text-underline: none;\">"
|
||||
+ tr("Choose other application")
|
||||
|
@ -183,16 +173,41 @@ void OpenWithPropertiesPage::initFloorThree()
|
|||
QLabel *allOpenLabel = new QLabel(str1, floor3);
|
||||
allOpenLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
connect(allOpenLabel, &QLabel::linkActivated, this, [=]() {
|
||||
AllFileLaunchDialog dialog(m_fileInfo.get()->uri());
|
||||
if (QDialog::Accepted == dialog.exec()) {
|
||||
m_defaultOpenWithWidget->setLaunchAction(FileLaunchManager::getDefaultAction(m_fileInfo->uri()));
|
||||
}
|
||||
});
|
||||
|
||||
layout3->addWidget(allOpenLabel);
|
||||
|
||||
QString str2;
|
||||
str2 = "<a href=\"ukui-software-center\" style=\"color: #3D6BE5;text-underline: none;\">"
|
||||
+ tr("Go to application center")
|
||||
+ "</a>";
|
||||
|
||||
QLabel *otherOpenLabel = new QLabel(str2, floor3);
|
||||
otherOpenLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
connect(allOpenLabel, &QLabel::linkActivated, this, &OpenWithPropertiesPage::chooseOtherApp);
|
||||
connect(otherOpenLabel, &QLabel::linkActivated, this, &OpenWithPropertiesPage::openAppCenter);
|
||||
|
||||
connect(otherOpenLabel, &QLabel::linkActivated, this, [=]() {
|
||||
QtConcurrent::run([=]() {
|
||||
QProcess p;
|
||||
if (COMMERCIAL_VERSION || (GlobalSettings::getInstance()->getProjectName() == V10_SP1_EDU))
|
||||
p.setProgram("kylin-software-center");
|
||||
else
|
||||
p.setProgram("ubuntu-kylin-software-center");
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
p.startDetached();
|
||||
#else
|
||||
if (COMMERCIAL_VERSION)
|
||||
p.startDetached("kylin-software-center");
|
||||
else
|
||||
p.startDetached("ubuntu-kylin-software-center");
|
||||
|
||||
#endif
|
||||
});
|
||||
});
|
||||
|
||||
bool isVisible = false;
|
||||
if(QFileInfo::exists("/usr/bin/kylin-software-center")
|
||||
|
@ -201,43 +216,12 @@ void OpenWithPropertiesPage::initFloorThree()
|
|||
}
|
||||
|
||||
otherOpenLabel->setVisible(isVisible);
|
||||
|
||||
layout3->addWidget(allOpenLabel);
|
||||
layout3->addWidget(otherOpenLabel);
|
||||
layout3->addStretch(1);
|
||||
|
||||
this->m_layout->addWidget(floor3);
|
||||
}
|
||||
|
||||
void OpenWithPropertiesPage::chooseOtherApp()
|
||||
{
|
||||
AllFileLaunchDialog dialog(m_fileInfo.get()->uri());
|
||||
if (QDialog::Accepted == dialog.exec()) {
|
||||
m_defaultOpenWithWidget->setLaunchAction(FileLaunchManager::getDefaultAction(m_fileInfo->uri()));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenWithPropertiesPage::openAppCenter()
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
QProcess p;
|
||||
if (COMMERCIAL_VERSION)
|
||||
p.setProgram("/usr/bin/kylin-software-center");
|
||||
else
|
||||
p.setProgram("/usr/bin/ubuntu-kylin-software-center");
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
p.startDetached();
|
||||
#else
|
||||
if (COMMERCIAL_VERSION)
|
||||
p.startDetached("/usr/bin/kylin-software-center");
|
||||
else
|
||||
p.startDetached("/usr/bin/ubuntu-kylin-software-center");
|
||||
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
NewFileLaunchDialog::NewFileLaunchDialog(const QString &uri, QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
m_launchHashList = new LaunchHashList(uri, this);
|
||||
|
|
|
@ -169,10 +169,6 @@ public:
|
|||
void init();
|
||||
void saveAllChange() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void chooseOtherApp();
|
||||
void openAppCenter();
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include <QButtonGroup>
|
||||
#include <QProcess>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
|
||||
#include <QUrl>
|
||||
#include <QStandardPaths>
|
||||
|
@ -107,8 +106,6 @@ PermissionsPropertiesPage::PermissionsPropertiesPage(const QStringList &uris, QW
|
|||
connect(this, &PermissionsPropertiesPage::checkBoxChanged, this, &PermissionsPropertiesPage::changePermission);
|
||||
|
||||
queryPermissionsAsync(nullptr, m_uri);
|
||||
|
||||
this->addAdvancedLayout();
|
||||
}
|
||||
|
||||
PermissionsPropertiesPage::~PermissionsPropertiesPage()
|
||||
|
@ -274,7 +271,7 @@ GAsyncReadyCallback PermissionsPropertiesPage::async_query_permisson_callback(GO
|
|||
QFileInfo file("/usr/sbin/security-switch");
|
||||
if(file.exists() == true) {
|
||||
QProcess shProcess;
|
||||
shProcess.start("/usr/sbin/security-switch --get");
|
||||
shProcess.start("security-switch --get");
|
||||
if (!shProcess.waitForStarted()) {
|
||||
qDebug()<<"wait get security state start timeout";
|
||||
} else {
|
||||
|
@ -473,7 +470,6 @@ void PermissionsPropertiesPage::saveAllChange()
|
|||
{
|
||||
if(this->m_thisPageChanged)
|
||||
this->savePermissions();
|
||||
|
||||
qDebug() << "PermissionsPropertiesPage::saveAllChange()" << this->m_thisPageChanged;
|
||||
}
|
||||
|
||||
|
@ -537,73 +533,11 @@ void PermissionsPropertiesPage::updateCheckBox()
|
|||
}
|
||||
connect(permissionsBtGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
|
||||
[=](int id){
|
||||
if (i == 1) {
|
||||
auto info = FileInfo::fromUri(m_uri);
|
||||
QStringList args;
|
||||
bool ret;
|
||||
args << "getfacl" << "-p" << QString("\"%1\"").arg(info->filePath());
|
||||
QString acl = UserShareInfoManager::getInstance()->exectueSetAclCommand(args, &ret);
|
||||
if (!ret && !acl.isEmpty()) {
|
||||
this->close();
|
||||
return;
|
||||
}
|
||||
if (acl.count("user:") >= 2 && !m_isShow) {
|
||||
m_isShow = true;
|
||||
auto res = QMessageBox::question(nullptr, tr("Permissions modify tip"), tr("The current file or folder has already set ACL permissions. Modifying user group permissions may cause the permissions set in ACL to be unusable. Do you want to continue modifying user group permissions?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||
if (QMessageBox::No == res) {
|
||||
// FIXME:
|
||||
//checkbox->setChecked(!checkbox->isChecked());
|
||||
updateCheckBox();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->checkBoxChanged(i, id, permissionsBtGroup->button(id)->isChecked());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void PermissionsPropertiesPage::addAdvancedLayout()
|
||||
{
|
||||
QHBoxLayout *hboxLayout = new QHBoxLayout();
|
||||
hboxLayout->setContentsMargins(16, 16, 16, 16);
|
||||
m_advancedBtn = new QPushButton(tr("Permission refinement settings"));
|
||||
m_layout->addWidget(m_advancedBtn);
|
||||
|
||||
if (m_uri.startsWith("filesafe://")
|
||||
|| m_uri.startsWith("smb://")
|
||||
|| m_uri.startsWith("sftp://")
|
||||
|| m_uri.startsWith("ftp://")
|
||||
|| m_uri.startsWith("kmre://")) {
|
||||
m_advancedBtn->setVisible(false);
|
||||
}
|
||||
|
||||
connect(m_advancedBtn, &QPushButton::clicked, this, [=](){
|
||||
|
||||
auto info = FileInfo::fromUri(m_uri);
|
||||
auto displayname = info->displayName();
|
||||
bool isAdvancedShare = UserShareInfoManager::getInstance()->checkDirAdvancedShare(displayname);
|
||||
AdvancedPermissionsPage *page = new AdvancedPermissionsPage(m_uri);
|
||||
connect(page, &AdvancedPermissionsPage::updatePermissions, this, [=](){
|
||||
queryPermissionsAsync(nullptr, m_uri);
|
||||
});
|
||||
if (isAdvancedShare) {
|
||||
auto result = QMessageBox::question(nullptr, tr("Permission refinement settings"),
|
||||
tr("The current user has set advanced sharing. If you still need to modify permissions, advanced sharing may not be available. Do you want to continue setting?"),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
|
||||
if (QMessageBox::Yes == result) {
|
||||
page->show();
|
||||
}
|
||||
} else {
|
||||
page->show();
|
||||
}
|
||||
|
||||
});
|
||||
hboxLayout->addWidget(m_advancedBtn);
|
||||
hboxLayout->addStretch(2);
|
||||
m_layout->addLayout(hboxLayout);
|
||||
}
|
||||
|
||||
QWidget *PermissionsPropertiesPage::createCellWidget(QWidget *parent, QIcon icon, QString text)
|
||||
{
|
||||
QWidget *widget = new QWidget(parent);
|
||||
|
@ -647,473 +581,3 @@ QWidget *PermissionsPropertiesPage::createCellWidget(QWidget *parent, QIcon icon
|
|||
|
||||
return widget;
|
||||
}
|
||||
|
||||
AdvancedPermissionsPage::AdvancedPermissionsPage(const QString &uri, QWidget *parent)
|
||||
{
|
||||
m_uri = uri;
|
||||
this->init();
|
||||
}
|
||||
|
||||
AdvancedPermissionsPage::~AdvancedPermissionsPage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::init()
|
||||
{
|
||||
this->setWindowTitle(tr("Permission refinement settings"));
|
||||
this->setWindowIcon(QIcon::fromTheme("system-file-manager"));
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
this->setAttribute(Qt::WA_DeleteOnClose);
|
||||
this->setFixedSize(460, 600);
|
||||
this->setContentsMargins(0, 10, 0, 0);
|
||||
this->setWindowFlags(this->windowFlags() & ~Qt::WindowMinMaxButtonsHint & ~Qt::WindowSystemMenuHint);
|
||||
this->setWindowModality(Qt::ApplicationModal);
|
||||
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setMargin(0);
|
||||
m_layout->setSpacing(0);
|
||||
|
||||
this->getUserInfo();
|
||||
|
||||
this->initFloorOne();
|
||||
this->initFloorTwo();
|
||||
this->addSeparate();
|
||||
this->initFloorThree();
|
||||
this->addSeparate();
|
||||
this->initFloorFour();
|
||||
this->initCheckState();
|
||||
|
||||
connect(m_tabWidget, &QTableWidget::cellEntered, this, &AdvancedPermissionsPage::updateDelAclBtn);
|
||||
connect(m_tabWidget, &QTableWidget::cellClicked, this, &AdvancedPermissionsPage::updateDelAclBtn);
|
||||
|
||||
connect(m_listWidget, &QListWidget::currentTextChanged, this, [=](QString currentIndex){
|
||||
if (!m_userInfo.contains(currentIndex)) {
|
||||
m_addUserBtn->setEnabled(true);
|
||||
} else {
|
||||
m_addUserBtn->setEnabled(false);
|
||||
}
|
||||
QFontMetrics fontWidth(m_listLabel->font());
|
||||
QString elideNote = fontWidth.elidedText(currentIndex, Qt::ElideMiddle, 300);
|
||||
m_listLabel->setText(elideNote);
|
||||
m_listLabel->setToolTip(currentIndex);
|
||||
});
|
||||
|
||||
connect(m_addUserBtn, &QPushButton::clicked, this, [=](){
|
||||
QListWidgetItem *item = m_listWidget->currentItem();
|
||||
if (nullptr != item) {
|
||||
QString name = item->text();
|
||||
//增加用户默认acl
|
||||
m_mutex.lock();
|
||||
m_userInfo.insert(name, "rwx");
|
||||
m_mutex.unlock();
|
||||
|
||||
m_addUserBtn->setEnabled(false);
|
||||
m_inheritsBox->setEnabled(true);
|
||||
|
||||
int rowCount = m_tabWidget->rowCount();
|
||||
m_tabWidget->insertRow(rowCount);
|
||||
QTableWidgetItem* itemC = new QTableWidgetItem(name);
|
||||
itemC->setFlags(itemC->flags() | Qt::ItemIsSelectable);
|
||||
itemC->setToolTip(name);
|
||||
m_tabWidget->setItem(rowCount, 0, itemC);
|
||||
for (int i = 1; i < 4; ++i) {
|
||||
m_tabWidget->setCellWidget(rowCount, i, nullptr);
|
||||
QWidget *w = new QWidget(m_tabWidget);
|
||||
QHBoxLayout *l = new QHBoxLayout(w);
|
||||
l->setMargin(0);
|
||||
w->setLayout(l);
|
||||
l->setAlignment(Qt::AlignCenter);
|
||||
auto checkbox = new QCheckBox(w);
|
||||
bool check = updateCheckBox(i, name);
|
||||
checkbox->setChecked(check);
|
||||
l->addWidget(checkbox);
|
||||
m_tabWidget->setCellWidget(rowCount, i, w);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_delUserBtn, &QPushButton::clicked, this, [=](){
|
||||
QTableWidgetItem *item = m_tabWidget->currentItem();
|
||||
if (nullptr != item) {
|
||||
QString name = item->text();
|
||||
|
||||
if (m_userInfo.contains(name)) {
|
||||
m_mutex.lock();
|
||||
m_userInfo.remove(name);
|
||||
m_mutex.unlock();
|
||||
|
||||
int currentRow = m_tabWidget->currentRow();
|
||||
m_tabWidget->removeRow(currentRow);
|
||||
if (m_tabWidget->rowCount() <= 0) {
|
||||
m_delUserBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_tabWidget->rowCount() == 0) {
|
||||
m_inheritsBox->setEnabled(false);
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_cancelBtn, &QPushButton::clicked, this, [=](){
|
||||
m_userInfo.clear();
|
||||
m_defaultAcl.clear();
|
||||
this->close();
|
||||
});
|
||||
|
||||
connect(m_saveBtn, &QPushButton::clicked, this, [=](){
|
||||
for (int row = 0; row < m_tabWidget->rowCount(); ++row) {
|
||||
for (int col = 0; col < m_tabWidget->columnCount(); ++col) {
|
||||
if (col == 0) {
|
||||
continue;
|
||||
}
|
||||
QWidget *w = m_tabWidget->cellWidget(row, col);
|
||||
QCheckBox *box = w->findChild<QCheckBox*>();
|
||||
updateUserInfo(row, col, box->isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
auto result = QMessageBox::question(nullptr, tr("Permission refinement settings tip"), tr("Setting ACL permissions will result in a change in the user group permissions for basic permissions. Do you need to continue setting ACL permissions?"),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
|
||||
if (result == QMessageBox::Yes) {
|
||||
this->checkInheritsBoxInfo();
|
||||
this->saveAclPermissions();
|
||||
qDebug() << __func__ << "userInfo" << m_userInfo;
|
||||
Q_EMIT this->updatePermissions();
|
||||
this->close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::initTableWidget()
|
||||
{
|
||||
m_tabWidget = new QTableWidget(this);
|
||||
m_tabWidget->setColumnCount(4);
|
||||
m_tabWidget->verticalHeader()->setVisible(false);
|
||||
m_tabWidget->verticalHeader()->setMinimumSectionSize(12);
|
||||
m_tabWidget->horizontalHeader()->setFrameShape(QFrame::NoFrame);
|
||||
m_tabWidget->setFrameShape(QFrame::NoFrame);
|
||||
m_tabWidget->horizontalHeader()->setSelectionMode(QTableWidget::NoSelection);
|
||||
m_tabWidget->verticalHeader()->setSelectionMode(QTableWidget::NoSelection);
|
||||
m_tabWidget->setSelectionMode(QTableWidget::SingleSelection);
|
||||
m_tabWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||
m_tabWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
m_tabWidget->setShowGrid(false);
|
||||
|
||||
m_tabWidget->horizontalHeader()->setMinimumHeight(34);
|
||||
m_tabWidget->rowHeight(34);
|
||||
|
||||
m_tabWidget->setAlternatingRowColors(true);
|
||||
auto l = QStringList();
|
||||
l<<tr("User")<<tr("Read")<<tr("Write")<<tr("Executable");
|
||||
m_tabWidget->setHorizontalHeaderLabels(l);
|
||||
m_tabWidget->setEditTriggers(QTableWidget::NoEditTriggers);
|
||||
m_tabWidget->horizontalHeader()->setMinimumSectionSize(30);
|
||||
m_tabWidget->horizontalHeader()->setMaximumSectionSize(400);
|
||||
|
||||
m_tabWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Interactive);
|
||||
m_tabWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
m_tabWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
|
||||
m_tabWidget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed);
|
||||
m_tabWidget->horizontalHeaderItem(0)->setTextAlignment(Qt::AlignLeft);
|
||||
|
||||
m_tabWidget->setColumnWidth(0, 100);
|
||||
m_tabWidget->setColumnWidth(1, 75);
|
||||
m_tabWidget->setColumnWidth(3, 120);
|
||||
|
||||
m_layout->addWidget(m_tabWidget);
|
||||
|
||||
int rowCount = m_userInfo.count();
|
||||
m_tabWidget->setRowCount(rowCount);
|
||||
|
||||
//Add all user acl
|
||||
QMap<QString, QString>::iterator iter;
|
||||
int row = 0;
|
||||
for (iter = m_userInfo.begin(); iter != m_userInfo.end(); iter++) {
|
||||
QString key = iter.key();
|
||||
QTableWidgetItem* itemC0 = new QTableWidgetItem(key);
|
||||
itemC0->setFlags(itemC0->flags() | Qt::ItemIsSelectable);
|
||||
itemC0->setToolTip(key);
|
||||
m_tabWidget->setItem(row, 0, itemC0);
|
||||
for (int j = 1; j < 4; j++) {
|
||||
m_tabWidget->setCellWidget(row, j, nullptr);
|
||||
QWidget *w = new QWidget(m_tabWidget);
|
||||
QHBoxLayout *l = new QHBoxLayout(w);
|
||||
l->setMargin(0);
|
||||
w->setLayout(l);
|
||||
l->setAlignment(Qt::AlignCenter);
|
||||
auto checkbox = new QCheckBox(w);
|
||||
bool check = updateCheckBox(j, key);
|
||||
checkbox->setChecked(check);
|
||||
l->addWidget(checkbox);
|
||||
m_tabWidget->setCellWidget(row, j, w);
|
||||
}
|
||||
++row;
|
||||
}
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::initListWidget()
|
||||
{
|
||||
QVBoxLayout *vBoxLayout = new QVBoxLayout;
|
||||
vBoxLayout->setContentsMargins(22, 0, 22, 0);
|
||||
m_listWidget = new QListWidget(this);
|
||||
m_listWidget->setUniformItemSizes(true);
|
||||
m_listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
m_sysAccounts = new SystemDbusAccounts(this);
|
||||
QStringList m_userNames = m_sysAccounts->getAllUserNames();
|
||||
QString loginName = qgetenv("USER");
|
||||
if (!m_userNames.isEmpty()) {
|
||||
for (QString user : m_userNames) {
|
||||
if (0 != user.compare(loginName)) {
|
||||
auto item = new QListWidgetItem(user, m_listWidget);
|
||||
item->setToolTip(user);
|
||||
m_listWidget->addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
vBoxLayout->addWidget(m_listWidget);
|
||||
m_layout->addLayout(vBoxLayout);
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::initFloorOne()
|
||||
{
|
||||
m_label = new QLabel(tr("Permission refinement settings"), this);
|
||||
m_label->setContentsMargins(22, 0, 22, 0);
|
||||
m_layout->addWidget(m_label);
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::initFloorTwo()
|
||||
{
|
||||
this->initTableWidget();
|
||||
m_layout->addSpacing(10);
|
||||
QHBoxLayout *hBoxLayout = new QHBoxLayout;
|
||||
hBoxLayout->setContentsMargins(22, 0, 22, 0);
|
||||
hBoxLayout->setSpacing(0);
|
||||
m_delUserBtn = new QPushButton(tr("delete"));
|
||||
m_delUserBtn->setEnabled(false);
|
||||
m_inheritsBox = new QCheckBox(tr("Inherit permission"));
|
||||
hBoxLayout->addWidget(m_inheritsBox, 2);
|
||||
hBoxLayout->addStretch(1);
|
||||
hBoxLayout->addWidget(m_delUserBtn, 1);
|
||||
m_layout->addLayout(hBoxLayout);
|
||||
m_layout->addSpacing(10);
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::initFloorThree()
|
||||
{
|
||||
m_layout->addSpacing(10);
|
||||
this->initListWidget();
|
||||
QHBoxLayout *hBoxLayout = new QHBoxLayout;
|
||||
hBoxLayout->setContentsMargins(22, 0, 22, 0);
|
||||
hBoxLayout->setSpacing(0);
|
||||
m_addUserBtn = new QPushButton(tr("Add"));
|
||||
m_listLabel = new QLabel;
|
||||
m_addUserBtn->setEnabled(false);
|
||||
hBoxLayout->addWidget(m_listLabel, 3);
|
||||
hBoxLayout->addSpacing(10);
|
||||
hBoxLayout->addWidget(m_addUserBtn, 1);
|
||||
m_layout->addSpacing(10);
|
||||
m_layout->addLayout(hBoxLayout);
|
||||
m_layout->addSpacing(10);
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::initFloorFour()
|
||||
{
|
||||
m_layout->addSpacing(10);
|
||||
QHBoxLayout *hBoxLayout2 = new QHBoxLayout;
|
||||
hBoxLayout2->setContentsMargins(22, 0, 22, 0);
|
||||
hBoxLayout2->setSpacing(0);
|
||||
m_saveBtn = new QPushButton(tr("Apply"));
|
||||
m_cancelBtn = new QPushButton(tr("Cancel"));
|
||||
hBoxLayout2->addStretch(1);
|
||||
hBoxLayout2->addWidget(m_saveBtn);
|
||||
hBoxLayout2->addSpacing(10);
|
||||
hBoxLayout2->addWidget(m_cancelBtn);
|
||||
m_layout->addLayout(hBoxLayout2);
|
||||
m_layout->addSpacing(16);
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::addSeparate()
|
||||
{
|
||||
QPushButton *separate = new QPushButton;
|
||||
separate->setFixedHeight(1);
|
||||
separate->setFocusPolicy(Qt::NoFocus);
|
||||
separate->setEnabled(false);
|
||||
m_layout->addWidget(separate);
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::getUserInfo()
|
||||
{
|
||||
if (m_userInfo.isEmpty()) {
|
||||
auto info = FileInfo::fromUri(m_uri);
|
||||
QStringList args;
|
||||
bool ret;
|
||||
args << "getfacl" << "-p" << QString("\"%1\"").arg(info->filePath());
|
||||
QString acl = UserShareInfoManager::getInstance()->exectueSetAclCommand(args, &ret);
|
||||
if (!ret && !acl.isEmpty()) {
|
||||
this->close();
|
||||
return;
|
||||
}
|
||||
parseUserInfoAcl(acl);
|
||||
}
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::parseUserInfoAcl(QString strAcl)
|
||||
{
|
||||
if (!strAcl.isEmpty()) {
|
||||
QStringList lists = strAcl.split('\n');
|
||||
for (int i = 0; i < lists.size();) {
|
||||
QString list = lists.at(i);
|
||||
if (list.startsWith("#")
|
||||
|| list.isEmpty()
|
||||
|| list.contains("user::")
|
||||
|| list.contains("group::")
|
||||
|| list.contains("mask::")
|
||||
|| list.contains("other::")
|
||||
|| list.startsWith("default:")) {
|
||||
if (list.startsWith("default:user:") && !list.contains("user::")) {
|
||||
QString tmp = list;
|
||||
tmp = tmp.remove(1, 6);
|
||||
m_defaultAcl.append(tmp);
|
||||
m_defaultAcl.append(",");
|
||||
}
|
||||
lists.removeOne(list);
|
||||
} else if (list.contains("#effective:")) {
|
||||
int ind = lists.indexOf(list);
|
||||
int index = list.indexOf("\t");
|
||||
int size = list.size();
|
||||
QString tmp = list.remove(index, size);
|
||||
lists.replace(ind, tmp);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
for (QString l : lists) {
|
||||
//当前格式为:user:kylin:rwx,user:kylin2:r-x
|
||||
QStringList tmpLists = l.split(":");
|
||||
QString name = tmpLists.at(1);
|
||||
QString per = tmpLists.at(2);
|
||||
m_mutex.lock();
|
||||
m_userInfo.insert(name, per);
|
||||
m_mutex.unlock();
|
||||
}
|
||||
qDebug() << __func__ << "init userInfo" << m_userInfo << m_defaultAcl;
|
||||
}
|
||||
}
|
||||
|
||||
bool AdvancedPermissionsPage::updateCheckBox(int col, QString &name)
|
||||
{
|
||||
bool ret = false;
|
||||
if (name.isEmpty() || col < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (col == 1 && m_userInfo.value(name).contains("r")) {
|
||||
ret = true;
|
||||
} else if (col == 2 && m_userInfo.value(name).contains("w")) {
|
||||
ret = true;
|
||||
} else if (col == 3 && m_userInfo.value(name).contains("x")) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::updateUserInfo(int row, int col, bool checked)
|
||||
{
|
||||
if (checked && col >= 1 && col <= 3) {
|
||||
QTableWidgetItem *item = m_tabWidget->item(row, 0);
|
||||
if (nullptr != item && m_userInfo.contains(item->text())) {
|
||||
QString name = item->text();
|
||||
QString perm = m_userInfo.value(name);
|
||||
if (col == 1) {
|
||||
perm = perm.replace(col - 1, 1, "r");
|
||||
} else if (col == 2) {
|
||||
perm = perm.replace(col - 1, 1, "w");
|
||||
} else if (col == 3) {
|
||||
perm = perm.replace(col - 1, 1, "x");
|
||||
}
|
||||
|
||||
m_userInfo.remove(name);
|
||||
m_userInfo.insert(name, perm);
|
||||
}
|
||||
} else if (!checked && col >= 1 && col <= 3) {
|
||||
QTableWidgetItem *item = m_tabWidget->item(row, 0);
|
||||
if (nullptr != item && m_userInfo.contains(item->text())) {
|
||||
QString name = item->text();
|
||||
QString perm = m_userInfo.value(name);
|
||||
perm = perm.replace(col - 1, 1, "-");
|
||||
m_userInfo.remove(name);
|
||||
m_userInfo.insert(name, perm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::checkInheritsBoxInfo()
|
||||
{
|
||||
if (m_inheritsBox->isChecked()) {
|
||||
m_defaultAcl.clear();
|
||||
QMap<QString, QString>::iterator iter;
|
||||
for (iter = m_userInfo.begin(); iter != m_userInfo.end(); ++iter) {
|
||||
QString tmp = "d:u:" + iter.key() + ":" + iter.value() + ",";
|
||||
m_defaultAcl.append(tmp);
|
||||
}
|
||||
} else {
|
||||
m_defaultAcl.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::initCheckState()
|
||||
{
|
||||
if (m_tabWidget->rowCount() == 0) {
|
||||
m_inheritsBox->setEnabled(false);
|
||||
m_inheritsBox->setChecked(false);
|
||||
} else if (m_defaultAcl.isEmpty() && m_tabWidget->rowCount() > 0) {
|
||||
m_inheritsBox->setEnabled(true);
|
||||
m_inheritsBox->setChecked(false);
|
||||
} else {
|
||||
m_inheritsBox->setEnabled(true);
|
||||
m_inheritsBox->setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::saveAclPermissions()
|
||||
{
|
||||
bool retb;
|
||||
QStringList args;
|
||||
auto info = FileInfo::fromUri(m_uri);
|
||||
args << "setfacl" << "-b" << QString("\"%1\"").arg(info->filePath());
|
||||
QString result = UserShareInfoManager::exectueSetAclCommand(args, &retb);
|
||||
if (!retb && !result.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_userInfo.isEmpty()) {
|
||||
QString tmpUserInfo = m_defaultAcl;
|
||||
QMap<QString, QString>::iterator iter;
|
||||
for (iter = m_userInfo.begin(); iter != m_userInfo.end(); ++iter) {
|
||||
QString tmp = QString("u:%1:%2,").arg(iter.key()).arg(iter.value());
|
||||
tmpUserInfo.append(tmp);
|
||||
}
|
||||
|
||||
bool retm;
|
||||
args.clear();
|
||||
args << "setfacl" << "-m" << tmpUserInfo << QString("\"%1\"").arg(info->filePath());
|
||||
qDebug() << __func__ << tmpUserInfo;
|
||||
result = UserShareInfoManager::getInstance()->exectueSetAclCommand(args, &retm);
|
||||
if (!retm && !result.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AdvancedPermissionsPage::updateDelAclBtn(int row, int col)
|
||||
{
|
||||
if (col >= 1) {
|
||||
m_delUserBtn->setEnabled(false);
|
||||
} else if (col == 0) {
|
||||
m_delUserBtn->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,15 +25,9 @@
|
|||
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QListWidget>
|
||||
#include <QMutex>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "properties-window-tab-iface.h"
|
||||
#include "peony-core_global.h"
|
||||
#include "systemd-bus-accounts.h"
|
||||
#include "usershare-manager.h"
|
||||
|
||||
#include <memory>
|
||||
#include <gio/gio.h>
|
||||
|
@ -72,8 +66,6 @@ public:
|
|||
|
||||
void updateCheckBox();
|
||||
|
||||
void addAdvancedLayout();
|
||||
|
||||
protected:
|
||||
static GAsyncReadyCallback async_query_permisson_callback(GObject *obj,
|
||||
GAsyncResult *res,
|
||||
|
@ -96,7 +88,6 @@ private:
|
|||
QLabel *m_label = nullptr;
|
||||
QLabel *m_message = nullptr;
|
||||
QTableWidget *m_table = nullptr;
|
||||
QPushButton *m_advancedBtn = nullptr;
|
||||
|
||||
//防止错误修改权限
|
||||
bool m_enable = false;
|
||||
|
@ -106,8 +97,6 @@ private:
|
|||
//unixmode能力,标识修改权限是否可使用gio接口
|
||||
bool m_has_unix_mode = false;
|
||||
|
||||
bool m_isShow = false;
|
||||
|
||||
public:
|
||||
void thisPageChanged() override;
|
||||
|
||||
|
@ -116,55 +105,6 @@ public:
|
|||
void saveAllChange();
|
||||
};
|
||||
|
||||
class AdvancedPermissionsPage : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AdvancedPermissionsPage(const QString &uri, QWidget *parent = nullptr);
|
||||
~AdvancedPermissionsPage();
|
||||
|
||||
void init();
|
||||
void initTableWidget();
|
||||
void initListWidget();
|
||||
void initFloorOne();
|
||||
void initFloorTwo();
|
||||
void initFloorThree();
|
||||
void initFloorFour();
|
||||
void addSeparate();
|
||||
|
||||
void getUserInfo();
|
||||
void parseUserInfoAcl(QString strAcl);
|
||||
bool updateCheckBox(int col, QString &name);
|
||||
void updateUserInfo(int row, int col, bool checked);
|
||||
void checkInheritsBoxInfo();
|
||||
void initCheckState();
|
||||
void saveAclPermissions();
|
||||
|
||||
Q_SIGNALS:
|
||||
void updatePermissions();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void updateDelAclBtn(int row, int col);
|
||||
|
||||
private:
|
||||
QString m_uri;
|
||||
QString m_defaultAcl;
|
||||
SystemDbusAccounts *m_sysAccounts = nullptr;
|
||||
QMap<QString, QString> m_userInfo;
|
||||
QMutex m_mutex;
|
||||
bool m_thisPageChanged = false;
|
||||
|
||||
QLabel *m_label = nullptr;
|
||||
QLabel *m_listLabel = nullptr;
|
||||
QTableWidget *m_tabWidget = nullptr;
|
||||
QListWidget *m_listWidget = nullptr;
|
||||
QPushButton *m_saveBtn = nullptr;
|
||||
QPushButton *m_cancelBtn = nullptr;
|
||||
QPushButton *m_addUserBtn = nullptr;
|
||||
QPushButton *m_delUserBtn = nullptr;
|
||||
QCheckBox *m_inheritsBox = nullptr;
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PERMISSIONSPROPERTIESPAGE_H
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "global-settings.h"
|
||||
#include "file-count-operation.h"
|
||||
#include "file-operation-utils.h"
|
||||
#include "file-meta-info.h"
|
||||
|
||||
#include <QGSettings>
|
||||
#include <QFormLayout>
|
||||
|
@ -93,8 +92,6 @@ void RecentAndTrashPropertiesPage::init()
|
|||
iconName = getIconName();
|
||||
}
|
||||
auto icon = new QPushButton(QIcon::fromTheme(iconName), nullptr, this);
|
||||
icon->setFocusPolicy(Qt::NoFocus);
|
||||
icon->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
icon->setIconSize(QSize(48, 48));
|
||||
icon->setProperty("isIcon", true);
|
||||
|
||||
|
@ -139,14 +136,6 @@ void RecentAndTrashPropertiesPage::init()
|
|||
nullptr);
|
||||
auto origin_path = g_file_info_get_attribute_byte_string(info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH);
|
||||
|
||||
if (!origin_path) {
|
||||
auto targetInfo = FileInfo::fromUri(m_uri);
|
||||
QString path = targetInfo.get()->property("orig-path").toString();
|
||||
if (!path.isEmpty()) {
|
||||
origin_path = path.toUtf8().constData();
|
||||
}
|
||||
}
|
||||
|
||||
QUrl url(FileUtils::getParentUri("file://" + QString(origin_path)));
|
||||
|
||||
quint64 width = FIXED_ROW_WIDTH - label->fontMetrics().width(tr("Origin Path: "));
|
||||
|
@ -185,42 +174,24 @@ void RecentAndTrashPropertiesPage::init()
|
|||
nullptr,
|
||||
nullptr);
|
||||
|
||||
//use sdk interface to get time format
|
||||
QString deletion_date = m_fileInfo->deletionDate();
|
||||
if (deletion_date.isEmpty()) {
|
||||
deletion_date = m_fileInfo->modifiedDate();
|
||||
}
|
||||
quint64 delete_width = FIXED_ROW_WIDTH - delete_label->fontMetrics().width(tr("Deletion Date: "));
|
||||
delete_label->setText(label->fontMetrics().elidedText(deletion_date, Qt::ElideMiddle, delete_width));
|
||||
delete_label->setWordWrap(true);
|
||||
|
||||
//no need of old way
|
||||
// if (QGSettings::isSchemaInstalled("org.ukui.control-center.panel.plugins")) {
|
||||
// QGSettings *settings = new QGSettings("org.ukui.control-center.panel.plugins", "", this);
|
||||
// connect(settings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
// if(key == "date") {
|
||||
// QString current_text = delete_label->text();
|
||||
// QString new_date_type = settings->get("date").toString();
|
||||
// //cn : 1999/11/11
|
||||
// //en : 1999-11-11
|
||||
// if ((new_date_type == "cn") && current_text.contains("-")) {
|
||||
// delete_label->setText(current_text.replace("-", "/"));
|
||||
|
||||
// } else if ((new_date_type == "en") && current_text.contains("/")) {
|
||||
// delete_label->setText(current_text.replace("/", "-"));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// QString current_text = delete_label->text();
|
||||
// QString new_date_type = settings->get("date").toString();
|
||||
// if ((new_date_type == "cn") && current_text.contains("-")) {
|
||||
// delete_label->setText(current_text.replace("-", "/"));
|
||||
|
||||
// } else if ((new_date_type == "en") && current_text.contains("/")) {
|
||||
// delete_label->setText(current_text.replace("/", "-"));
|
||||
// }
|
||||
// }
|
||||
if (QGSettings::isSchemaInstalled("org.ukui.control-center.panel.plugins")) {
|
||||
QGSettings *settings = new QGSettings("org.ukui.control-center.panel.plugins", "", this);
|
||||
connect(settings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
if(key == "date" || "hoursystem" == key) {
|
||||
QDateTime deleteTime = QDateTime::fromMSecsSinceEpoch(m_fileInfo->deletionTime (), Qt::LocalTime);
|
||||
QString format = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
QString deletion_date = deleteTime.toString(format);
|
||||
quint64 delete_width = FIXED_ROW_WIDTH - delete_label->fontMetrics().width(tr("Deletion Date: "));
|
||||
delete_label->setText(label->fontMetrics().elidedText(deletion_date, Qt::ElideMiddle, delete_width));
|
||||
delete_label->setWordWrap(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
g_object_unref(info);
|
||||
g_object_unref(file);
|
||||
|
|
|
@ -1,466 +0,0 @@
|
|||
/*
|
||||
* Peony-Qt's Library
|
||||
*
|
||||
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: yangyanwei <yangyanwei@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tag-management.h"
|
||||
#include "xatom-helper.h"
|
||||
#include "file-label-model.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTableWidget>
|
||||
#include <QWidget>
|
||||
#include <QCheckBox>
|
||||
#include <QPainter>
|
||||
#include <QLineEdit>
|
||||
#include <QColorDialog>
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
|
||||
#include <QPainterPath>
|
||||
|
||||
using namespace Peony;
|
||||
static TagManagement *global_instance = nullptr;
|
||||
|
||||
FileLabelEdit::FileLabelEdit(QColor color,QString name, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
m_colorButton = new QPushButton(this);
|
||||
m_colorButton->setProperty("isRoundButton",true);
|
||||
m_colorButton->setFixedSize(12,12);
|
||||
QPalette pal = m_colorButton->palette();
|
||||
pal.setColor(QPalette::Button, color);
|
||||
pal.setColor(QPalette::Active,QPalette::Highlight, color);
|
||||
m_colorButton->setPalette(pal);
|
||||
|
||||
QHBoxLayout *nameLayout = new QHBoxLayout(this);
|
||||
nameLayout->setMargin(0);
|
||||
nameLayout->setAlignment(Qt::AlignLeft);
|
||||
nameLayout->addWidget(m_colorButton);
|
||||
m_text = new QLabel(this);
|
||||
m_text->setText(name);
|
||||
nameLayout->addWidget(m_text);
|
||||
m_edit = new QLineEdit(this);
|
||||
nameLayout->addWidget(m_edit);
|
||||
m_edit->hide();
|
||||
setLayout(nameLayout);
|
||||
connect(m_edit, &QLineEdit::editingFinished, this, [=]() {
|
||||
m_edit->hide();
|
||||
m_text->show();
|
||||
m_text->setText(m_edit->text());
|
||||
Q_EMIT changeName(m_edit->text());
|
||||
});
|
||||
}
|
||||
|
||||
void FileLabelEdit::setColor(QColor color)
|
||||
{
|
||||
QPalette pal = m_colorButton->palette();
|
||||
pal.setColor(QPalette::Button, color);
|
||||
pal.setColor(QPalette::Active,QPalette::Highlight, color);
|
||||
m_colorButton->setPalette(pal);
|
||||
}
|
||||
|
||||
void FileLabelEdit::setName(const QString& name)
|
||||
{
|
||||
m_text->setText(name);
|
||||
}
|
||||
|
||||
void FileLabelEdit::startEdit()
|
||||
{
|
||||
m_text->hide();
|
||||
m_edit->show();
|
||||
m_edit->setFocus();
|
||||
m_edit->setText(m_text->text());
|
||||
}
|
||||
|
||||
LabelSettings::LabelSettings(QWidget *parent)
|
||||
{
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
m_fileLabel = new QTableWidget(this);
|
||||
m_fileLabel->setColumnCount(3);
|
||||
FileLabelModel *model = FileLabelModel::getGlobalModel();
|
||||
auto items = model->getAllFileLabelItems();
|
||||
m_fileLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
m_fileLabel->setRowCount(items.size());
|
||||
m_fileLabel->setContentsMargins(0, 0, 0, 0);
|
||||
m_fileLabel->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
//m_fileLabel->setSelectionMode(QAbstractItemView::NoSelection);
|
||||
m_fileLabel->setAlternatingRowColors(true);
|
||||
m_fileLabel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_fileLabel->verticalHeader()->setVisible(false);
|
||||
m_fileLabel->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
m_fileLabel->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
m_fileLabel->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||
m_fileLabel->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||
m_fileLabel->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
|
||||
m_fileLabel->setShowGrid(false);
|
||||
|
||||
QStringList titles;
|
||||
titles.append(tr("Name"));
|
||||
titles.append(tr("SideBar"));
|
||||
titles.append(tr("Menu"));
|
||||
m_fileLabel->setHorizontalHeaderLabels(titles);
|
||||
|
||||
loadAllFileLabels();
|
||||
mainLayout->addWidget(m_fileLabel);
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
QPushButton *add = new QPushButton(QIcon::fromTheme("list-add-symbolic"), tr("Create New Label"), this);
|
||||
connect(add, &QPushButton::clicked, this, &LabelSettings::addFileLabel);
|
||||
QPushButton *del = new QPushButton(QIcon::fromTheme("list-remove-symbolic"), tr("Delete Label"), this);
|
||||
connect(del, &QPushButton::clicked, this, &LabelSettings::delFileLabel);
|
||||
|
||||
layout->setContentsMargins(0, 26, 18, 0);
|
||||
layout->addStretch();
|
||||
layout->addWidget(add);
|
||||
layout->addWidget(del);
|
||||
|
||||
QLabel *instruction = new QLabel(this);
|
||||
instruction->setWordWrap(true);
|
||||
instruction->setText(tr("Display the following items in the identification area: (maximum of 6)"));
|
||||
mainLayout->setContentsMargins(8, 18, 8, 26);
|
||||
mainLayout->addWidget(instruction);
|
||||
mainLayout->addSpacing(18);
|
||||
mainLayout->addWidget(m_fileLabel);
|
||||
mainLayout->addLayout(layout);
|
||||
setLayout(mainLayout);
|
||||
connect(m_fileLabel, &QTableWidget::cellClicked, this, [=](int row, int col) {
|
||||
if (0 == col) {
|
||||
FileLabelEdit *item = static_cast<FileLabelEdit*>(m_fileLabel->cellWidget(row,col));
|
||||
item->startEdit();
|
||||
}
|
||||
});
|
||||
connect(m_fileLabel, &QWidget::customContextMenuRequested, this, [=](const QPoint &pos) {
|
||||
auto index = m_fileLabel->indexAt(pos);
|
||||
QMenu menu(this);
|
||||
if (index.isValid()) {
|
||||
menu.addAction(tr("Rename"), [=]() {
|
||||
//FIXME: edit
|
||||
int row = m_fileLabel->currentRow();
|
||||
FileLabelEdit *item = static_cast<FileLabelEdit*>(m_fileLabel->cellWidget(row,0));
|
||||
item->startEdit();
|
||||
});
|
||||
|
||||
menu.addAction(tr("Edit Color"), [=]() {
|
||||
QColorDialog d;
|
||||
d.setStyleSheet("QSpinBox{"
|
||||
"min-width: 2em;"
|
||||
"}");
|
||||
if (d.exec()) {
|
||||
auto color = d.selectedColor();
|
||||
auto item = FileLabelModel::getGlobalModel()->itemFormIndex(index);
|
||||
FileLabelModel::getGlobalModel()->setLabelColor(item->id(), color);
|
||||
int row = m_fileLabel->currentRow();
|
||||
FileLabelEdit *edit = static_cast<FileLabelEdit*>(m_fileLabel->cellWidget(row,0));
|
||||
edit->setColor(color);
|
||||
}
|
||||
});
|
||||
|
||||
auto a = menu.addAction(tr("Delete This Label"));
|
||||
connect(a, &QAction::triggered, this, &LabelSettings::delFileLabel);
|
||||
} else {
|
||||
auto a = menu.addAction(tr("Create New Label"));
|
||||
connect(a, &QAction::triggered, this, &LabelSettings::addFileLabel);
|
||||
}
|
||||
menu.exec(mapToGlobal(pos));
|
||||
});
|
||||
}
|
||||
|
||||
void LabelSettings::loadAllFileLabels()
|
||||
{
|
||||
FileLabelModel *model = FileLabelModel::getGlobalModel();
|
||||
auto items = model->getAllFileLabelItems();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
bool valids[2] = {0};
|
||||
valids[0] = items[i]->isValidInSidebar();
|
||||
valids[1] = items[i]->isValidInMenu();
|
||||
for(int j = 0 ; j < 2; j++) {
|
||||
m_fileLabel->setCellWidget(i, j + 1, nullptr);
|
||||
QWidget *w = new QWidget(m_fileLabel);
|
||||
QHBoxLayout *l = new QHBoxLayout(w);
|
||||
l->setMargin(0);
|
||||
w->setLayout(l);
|
||||
l->setAlignment(Qt::AlignCenter);
|
||||
QCheckBox *box = new QCheckBox(w);
|
||||
box->setChecked(valids[j]);
|
||||
connect(box, &QCheckBox::clicked, this, [=](bool status) {
|
||||
if(0 == j) {
|
||||
items[i]->setValidInSidebar(status);
|
||||
} else {
|
||||
items[i]->setValidInMenu(status);
|
||||
}
|
||||
});
|
||||
|
||||
l->addWidget(box);
|
||||
m_fileLabel->setCellWidget(i, j + 1, w);
|
||||
}
|
||||
FileLabelEdit *labelName = new FileLabelEdit(items[i]->color(), items[i]->name(), this);
|
||||
m_fileLabel->setCellWidget(i, 0, labelName);
|
||||
connect(labelName, &FileLabelEdit::changeName, model, [=](const QString &name){
|
||||
model->setLabelName(items[i]->id(), name);
|
||||
});
|
||||
connect(items[i], &FileLabelItem::nameChanged, labelName, &FileLabelEdit::setName);
|
||||
connect(items[i], &FileLabelItem::colorChanged, labelName, &FileLabelEdit::setColor);
|
||||
}
|
||||
}
|
||||
|
||||
void LabelSettings::addFileLabel()
|
||||
{
|
||||
QColorDialog dialog;
|
||||
dialog.setStyleSheet("QSpinBox{"
|
||||
"min-width: 2em;"
|
||||
"}");
|
||||
if (dialog.exec()) {
|
||||
auto color = dialog.selectedColor();
|
||||
auto name = color.name();
|
||||
FileLabelModel *model = FileLabelModel::getGlobalModel();
|
||||
if (!model->addLabel(name, color))
|
||||
return;
|
||||
int row = m_fileLabel->rowCount();
|
||||
m_fileLabel->insertRow(row);
|
||||
|
||||
FileLabelItem *item = model->getItemByRow(row);
|
||||
|
||||
FileLabelEdit *labelName = new FileLabelEdit(color, name, this);
|
||||
m_fileLabel->setCellWidget(row, 0, labelName);
|
||||
connect(labelName, &FileLabelEdit::changeName, model, [=](const QString &name){
|
||||
model->setLabelName(item->id(), name);
|
||||
});
|
||||
connect(item, &FileLabelItem::nameChanged, labelName, &FileLabelEdit::setName);
|
||||
connect(item, &FileLabelItem::colorChanged, labelName, &FileLabelEdit::setColor);
|
||||
|
||||
for(int j = 0 ; j < 2; j++) {
|
||||
m_fileLabel->setCellWidget(row, j + 1, nullptr);
|
||||
QWidget *w = new QWidget(m_fileLabel);
|
||||
QHBoxLayout *l = new QHBoxLayout(w);
|
||||
l->setMargin(0);
|
||||
w->setLayout(l);
|
||||
l->setAlignment(Qt::AlignCenter);
|
||||
QCheckBox *box = new QCheckBox(w);
|
||||
connect(box, &QCheckBox::clicked, this, [=](bool status) {
|
||||
if(0 == j) {
|
||||
item->setValidInSidebar(status);
|
||||
} else {
|
||||
item->setValidInMenu(status);
|
||||
}
|
||||
});
|
||||
if (0 == j) {
|
||||
box->setChecked(true);
|
||||
model->getItemByRow(row)->setValidInSidebar(true);
|
||||
}
|
||||
l->addWidget(box);
|
||||
m_fileLabel->setCellWidget(row, j + 1, w);
|
||||
}
|
||||
}
|
||||
}
|
||||
void LabelSettings::delFileLabel()
|
||||
{
|
||||
int row = m_fileLabel->currentRow();
|
||||
m_fileLabel->removeRow(row);
|
||||
auto item = FileLabelModel::getGlobalModel()->getItemByRow(row);
|
||||
int index = item->id();
|
||||
FileLabelModel::getGlobalModel()->removeLabel(index);
|
||||
}
|
||||
|
||||
TagManagement *TagManagement::getInstance()
|
||||
{
|
||||
if (!global_instance) {
|
||||
global_instance = new TagManagement;
|
||||
}
|
||||
return global_instance;
|
||||
}
|
||||
|
||||
TagManagement::TagManagement(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
//this->setAttribute(Qt::WA_DeleteOnClose);
|
||||
this->setContentsMargins(0, 25, 0, 0);
|
||||
this->setFixedSize(440, 568);
|
||||
|
||||
MotifWmHints hints;
|
||||
hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
|
||||
hints.functions = MWM_FUNC_ALL;
|
||||
hints.decorations = MWM_DECOR_BORDER;
|
||||
XAtomHelper::getInstance()->setWindowMotifHint(window()->winId(), hints);
|
||||
setWindowFlags(Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
|
||||
|
||||
QTabWidget *management = new QTabWidget(this);
|
||||
management->setStyle(new tabWidgetStyle);
|
||||
management->tabBar()->setStyle(new tabStyle);
|
||||
setCentralWidget(management);
|
||||
QWidget *general = new QWidget(this);
|
||||
LabelSettings *tag = new LabelSettings(this);
|
||||
|
||||
QWidget *sidebar = new QWidget(this);
|
||||
QWidget *Advanced = new QWidget(this);
|
||||
|
||||
//management->addTab(general, tr("General"));
|
||||
management->addTab(tag, tr("Mark"));
|
||||
//management->addTab(sidebar, tr("Sidebar"));
|
||||
//management->addTab(Advanced, tr("Advanced"));
|
||||
}
|
||||
|
||||
//TagManagement* TagManagement::getInstance()
|
||||
//{
|
||||
// if (!global_instance) {
|
||||
// global_instance = new TagManagement();
|
||||
// }
|
||||
// return global_instance;
|
||||
//}
|
||||
|
||||
void tabStyle::drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter,
|
||||
const QWidget *widget) const
|
||||
{
|
||||
/**
|
||||
* FIX:需要修复颜色不能跟随主题的问题
|
||||
* \brief
|
||||
*/
|
||||
if (element == CE_TabBarTab) {
|
||||
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
|
||||
//设置按钮的左右上下偏移
|
||||
QRect rect = tab->rect;
|
||||
//左侧移动1px
|
||||
rect.setLeft(rect.x() + 1);
|
||||
//右侧移动1px
|
||||
rect.setRight((rect.x() + rect.width())-2);
|
||||
QPainterPath path;
|
||||
const qreal radius = 6;
|
||||
if(tab->position == QStyleOptionTab::Beginning)
|
||||
{
|
||||
path.moveTo(rect.topRight());
|
||||
path.lineTo(rect.topLeft() + QPointF(radius, 0));
|
||||
path.quadTo(rect.topLeft(), rect.topLeft() + QPointF(0, radius));
|
||||
path.lineTo(rect.bottomLeft() - QPointF(0, radius));
|
||||
path.quadTo(rect.bottomLeft(), rect.bottomLeft() + QPointF(radius, 0));
|
||||
path.lineTo(rect.bottomRight());
|
||||
path.lineTo(rect.topRight());
|
||||
|
||||
}
|
||||
else if(tab->position == QStyleOptionTab::End)
|
||||
{
|
||||
path.moveTo(rect.topRight() - QPointF(radius, 0));
|
||||
path.lineTo(rect.topLeft());
|
||||
path.lineTo(rect.bottomLeft() );
|
||||
path.lineTo(rect.bottomRight() - QPointF(radius, 0));
|
||||
path.quadTo(rect.bottomRight(), rect.bottomRight() + QPointF(0, -radius));
|
||||
path.lineTo(rect.topRight() + QPointF(0, radius));
|
||||
path.quadTo(rect.topRight(), rect.topRight() + QPointF(-radius, -0));
|
||||
|
||||
}
|
||||
else if(tab->position == QStyleOptionTab::OnlyOneTab)
|
||||
{
|
||||
path.addRoundedRect(rect, radius, radius);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.addRect(rect);
|
||||
}
|
||||
const QPalette &palette = widget->palette();
|
||||
|
||||
//未选中时文字颜色 - Text color when not selected
|
||||
painter->setPen(palette.color(QPalette::ButtonText));
|
||||
|
||||
if (tab->state & QStyle::State_Selected) {
|
||||
painter->save();
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(palette.brush(QPalette::Highlight));
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
||||
painter->drawPath(path);
|
||||
painter->restore();
|
||||
|
||||
//选中时文字颜色 - Text color when selected
|
||||
painter->setPen(palette.color(QPalette::HighlightedText));
|
||||
} else if (tab->state & QStyle::State_MouseOver) {
|
||||
painter->save();
|
||||
QColor color = palette.color(QPalette::Highlight).lighter(140);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(color);
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
||||
painter->drawPath(path);
|
||||
painter->restore();
|
||||
//选中时文字颜色 - Text color when selected
|
||||
painter->setPen(palette.color(QPalette::HighlightedText));
|
||||
} else {
|
||||
painter->save();
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(palette.color(QPalette::Button));
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
||||
painter->drawPath(path);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
painter->drawText(rect, tab->text, QTextOption(Qt::AlignCenter));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (element == CE_TabBarTabLabel) {
|
||||
QProxyStyle::drawControl(element, option, painter, widget);
|
||||
}
|
||||
}
|
||||
|
||||
QSize tabStyle::sizeFromContents(QStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize,
|
||||
const QWidget *widget) const
|
||||
{
|
||||
QSize barSize = QProxyStyle::sizeFromContents(ct, opt, contentsSize, widget);
|
||||
|
||||
if (ct == QStyle::CT_TabBarTab) {
|
||||
barSize.transpose();
|
||||
const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt);
|
||||
//解决按钮不能自适应的问题
|
||||
int fontWidth = tab->fontMetrics.width(tab->text);
|
||||
//宽度统一加上30px
|
||||
barSize.setWidth(fontWidth + 30);
|
||||
|
||||
//46 - 8 - 8 = 30;
|
||||
barSize.setHeight(36);
|
||||
}
|
||||
|
||||
return barSize;
|
||||
}
|
||||
|
||||
QRect tabWidgetStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
switch(element)
|
||||
{
|
||||
case SE_TabWidgetTabBar:
|
||||
{
|
||||
//解决QTabBar设置为居中
|
||||
if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option))
|
||||
{
|
||||
QRect rect = QRect(QPoint(0, 0), twf->tabBarSize);
|
||||
if (twf->rect.size().width() > twf->tabBarSize.width()) {
|
||||
rect.moveLeft((twf->rect.size() - twf->leftCornerWidgetSize - twf->rightCornerWidgetSize - twf->tabBarSize).width() / 2);
|
||||
} else {
|
||||
rect.setWidth(twf->rect.size().width());
|
||||
rect.moveLeft(0);
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
return QProxyStyle::subElementRect(element, option, widget);
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* Peony-Qt's Library
|
||||
*
|
||||
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: yangyanwei <yangyanwei@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TAGMANAGEMENT_H
|
||||
#define TAGMANAGEMENT_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QTabWidget>
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QPainter>
|
||||
#include <QColor>
|
||||
#include <QEnterEvent>
|
||||
#include <QTableWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QProxyStyle>
|
||||
#include "peony-core_global.h"
|
||||
|
||||
namespace Peony {
|
||||
class PEONYCORESHARED_EXPORT TagManagement : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TagManagement *getInstance();
|
||||
explicit TagManagement(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void init();
|
||||
};
|
||||
|
||||
class FileLabelEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FileLabelEdit(QColor color, QString name, QWidget *parent = nullptr);
|
||||
void startEdit();
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeName(const QString &name);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setColor(QColor color);
|
||||
void setName(const QString& name);
|
||||
|
||||
private:
|
||||
QPushButton *m_colorButton = nullptr;
|
||||
QLabel *m_text = nullptr;
|
||||
QLineEdit *m_edit = nullptr;
|
||||
|
||||
};
|
||||
|
||||
class LabelSettings : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LabelSettings(QWidget *parent = nullptr);
|
||||
void loadAllFileLabels();
|
||||
|
||||
public Q_SLOTS:
|
||||
void addFileLabel();
|
||||
void delFileLabel();
|
||||
|
||||
private:
|
||||
QTableWidget *m_fileLabel = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
class tabStyle : public QProxyStyle
|
||||
{
|
||||
public:
|
||||
void drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter,
|
||||
const QWidget *widget) const;
|
||||
|
||||
QSize sizeFromContents(QStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize,
|
||||
const QWidget *w) const;
|
||||
};
|
||||
|
||||
class tabWidgetStyle : public QProxyStyle
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* QTabBar设置居中
|
||||
* @brief subElementRect
|
||||
* @param element
|
||||
* @return 返回QTabBar的矩形
|
||||
*/
|
||||
QRect subElementRect(SubElement element,
|
||||
const QStyleOption *option,
|
||||
const QWidget *widget = nullptr) const;
|
||||
};
|
||||
|
||||
#endif // TAGMANAGEMENT_H
|
|
@ -37,60 +37,6 @@
|
|||
|
||||
using namespace Peony;
|
||||
static ToolButtonStyle *global_instance = nullptr;
|
||||
|
||||
ProgressLineEdit::ProgressLineEdit(QWidget *parent)
|
||||
: QLineEdit(parent),
|
||||
m_value(0)
|
||||
{
|
||||
m_animation = new QVariantAnimation(this);
|
||||
m_animation->setDuration(1000);
|
||||
m_animation->setEasingCurve(QEasingCurve::InQuad);
|
||||
|
||||
connect(m_animation, &QVariantAnimation::valueChanged, this, [=](){
|
||||
if (m_animation->state() == QVariantAnimation::Running) {
|
||||
m_value = m_animation->currentValue().toReal();
|
||||
if (m_searching && 0.7 < m_value/m_animation->endValue().toReal()*1.0)
|
||||
m_animation->pause();
|
||||
update();
|
||||
}
|
||||
});
|
||||
connect(m_animation, &QVariantAnimation::finished, this, [=](){
|
||||
m_value = 0;
|
||||
});
|
||||
}
|
||||
|
||||
void ProgressLineEdit::updateSearchProgress(bool searching)
|
||||
{
|
||||
bool tmp = m_searching;
|
||||
m_searching = searching;
|
||||
if(searching) {
|
||||
if((m_animation->state() == QVariantAnimation::Stopped)) {
|
||||
m_animation->setStartValue(qreal(0));
|
||||
m_animation->setEndValue(qreal(this->width()));
|
||||
m_animation->start();
|
||||
m_value = 0;
|
||||
}
|
||||
} else if(tmp && !searching) {
|
||||
m_animation->resume();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void ProgressLineEdit::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QLineEdit::paintEvent(e);
|
||||
if (0 == m_value)
|
||||
return;
|
||||
|
||||
QPainter p(this);
|
||||
p.setOpacity(0.25);
|
||||
QBrush b;
|
||||
QRect backgroundRect = this->rect();
|
||||
backgroundRect.setWidth(m_value);
|
||||
backgroundRect.adjust(2, 2,-2, -2);
|
||||
p.fillRect(backgroundRect, this->palette().highlight().color());
|
||||
}
|
||||
|
||||
SearchBarContainer::SearchBarContainer(QWidget *parent): QWidget(parent)
|
||||
{
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
|
@ -108,14 +54,12 @@ SearchBarContainer::SearchBarContainer(QWidget *parent): QWidget(parent)
|
|||
// filter->setFixedHeight(parent->height());
|
||||
// AdvancedLocationBar * a = qobject_cast<AdvancedLocationBar *>(parent);
|
||||
|
||||
ProgressLineEdit *edit = new ProgressLineEdit(this);
|
||||
QLineEdit *edit = new QLineEdit(this);
|
||||
m_search_box = edit;
|
||||
|
||||
QAction *searchAction = new QAction(m_search_box);
|
||||
searchAction->setIcon(QIcon::fromTheme("edit-find-symbolic"));
|
||||
m_search_box->addAction(searchAction,QLineEdit::LeadingPosition);
|
||||
//fix bug#180920, contents and icon overlap issue
|
||||
edit->setTextMargins(0, 0, 20, 0);
|
||||
|
||||
// layout->addWidget(filter, Qt::AlignLeft);
|
||||
layout->addWidget(edit, Qt::AlignLeft);
|
||||
|
@ -235,7 +179,7 @@ SearchBarContainer::SearchBarContainer(QWidget *parent): QWidget(parent)
|
|||
searchButton->hide();
|
||||
}
|
||||
});
|
||||
connect(this, &Peony::SearchBarContainer::updateSearchProgress, edit, &ProgressLineEdit::updateSearchProgress);
|
||||
|
||||
connect(m_list_view, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableClicked(const QModelIndex &)));
|
||||
}
|
||||
|
||||
|
|
|
@ -32,29 +32,8 @@
|
|||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
#include <QProxyStyle>
|
||||
#include <QPaintEvent>
|
||||
#include <QVariantAnimation>
|
||||
namespace Peony {
|
||||
|
||||
class ProgressLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProgressLineEdit(QWidget *parent = nullptr);
|
||||
|
||||
public Q_SLOTS:
|
||||
void updateSearchProgress(bool searching);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
private:
|
||||
QVariantAnimation *m_animation = nullptr;
|
||||
bool m_searching = false;
|
||||
int m_value = 0;
|
||||
};
|
||||
|
||||
class SearchBarContainer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -97,7 +76,6 @@ public:
|
|||
Q_SIGNALS:
|
||||
void returnPressed();
|
||||
void filterUpdate(const int &index);
|
||||
void updateSearchProgress(bool searching);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onTableClicked(const QModelIndex &index);
|
||||
|
@ -107,7 +85,7 @@ public Q_SLOTS:
|
|||
private:
|
||||
QHBoxLayout *m_layout = nullptr;
|
||||
|
||||
ProgressLineEdit *m_search_box;
|
||||
QLineEdit *m_search_box;
|
||||
QComboBox *m_filter_box;
|
||||
|
||||
QStringListModel *m_model = nullptr;
|
||||
|
|
|
@ -250,7 +250,6 @@ void ToolBar::init()
|
|||
});
|
||||
|
||||
connect(pasteAction, &QAction::triggered, [=]() {
|
||||
ClipboardUtils::getInstance()->updateClipboardManually();
|
||||
if (ClipboardUtils::isClipboardHasFiles()) {
|
||||
//FIXME: how about duplicated copy?
|
||||
//FIXME: how to deal with a failed move?
|
||||
|
|
|
@ -65,11 +65,6 @@ static bool m_is_peony_cut = false;
|
|||
|
||||
static QList<QString> m_target_directory_uri;
|
||||
|
||||
static const QMimeData *clipboardData = nullptr;
|
||||
static bool is_clipboard_has_files = false;
|
||||
static bool is_clipboard_files_be_cut = false;
|
||||
static QStringList clipboard_file_uris;
|
||||
|
||||
ClipboardUtils *ClipboardUtils::getInstance()
|
||||
{
|
||||
if (!global_instance) {
|
||||
|
@ -80,14 +75,13 @@ ClipboardUtils *ClipboardUtils::getInstance()
|
|||
|
||||
ClipboardUtils::ClipboardUtils(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//connect(QApplication::clipboard(), &QClipboard::dataChanged, this, &ClipboardUtils::clipboardChanged);
|
||||
connect(QApplication::clipboard(), &QClipboard::dataChanged, this, &ClipboardUtils::clipboardChanged);
|
||||
connect(QApplication::clipboard(), &QClipboard::dataChanged, [=]() {
|
||||
// 更新缓存数据
|
||||
updateClipboardManually(true);
|
||||
Q_EMIT clipboardChanged();
|
||||
auto data = QApplication::clipboard()->mimeData();
|
||||
if (!data->hasFormat("peony-qt/is-cut")) {
|
||||
m_clipboard_parent_uri = nullptr;
|
||||
}
|
||||
});
|
||||
// 初始化缓存数据
|
||||
updateClipboardManually(true);
|
||||
|
||||
connect (ClipboardThread::getInstance (), &ClipboardThread::startOp, this, [=] (QStringList& str, bool mIsMove) {
|
||||
qDebug() << "start 云桌面 uri 获取成功!!!" << str;
|
||||
|
@ -116,69 +110,6 @@ ClipboardUtils::~ClipboardUtils()
|
|||
m_target_directory_uri.clear();
|
||||
}
|
||||
|
||||
void ClipboardUtils::updateClipboardManually(bool force)
|
||||
{
|
||||
if (!force) {
|
||||
// 如果当前应用持有剪切板则没有必要更新,使用缓存数据即可
|
||||
if (QApplication::clipboard()->ownsClipboard()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto data = QApplication::clipboard()->mimeData();
|
||||
if (!data->hasFormat("peony-qt/is-cut")) {
|
||||
m_clipboard_parent_uri = nullptr;
|
||||
}
|
||||
|
||||
clipboardData = data;
|
||||
if (clipboardData) {
|
||||
is_clipboard_has_files = clipboardData->hasUrls() || clipboardData->hasFormat("uos/remote-copy");
|
||||
if (is_clipboard_has_files) {
|
||||
if (clipboardData->hasFormat("peony-qt/is-cut")) {
|
||||
is_clipboard_files_be_cut = QVariant(clipboardData->data("peony-qt/is-cut")).toBool();
|
||||
} else {
|
||||
is_clipboard_files_be_cut = false;
|
||||
}
|
||||
|
||||
QStringList l;
|
||||
auto mimeData = clipboardData;
|
||||
//auto text = mimeData->text();
|
||||
auto peonyText = mimeData->data("peony-qt/encoded-uris");
|
||||
if (!peonyText.isEmpty()) {
|
||||
qDebug() << "peony text:" << peonyText;
|
||||
auto byteArrays = peonyText.split(' ');
|
||||
for (auto byteArray : byteArrays) {
|
||||
l<<byteArray;
|
||||
}
|
||||
} else {
|
||||
auto urls = mimeData->urls();
|
||||
for (auto url : urls) {
|
||||
// fix #144280, shenxinfu virual machine copy failed
|
||||
if (url.toString().count() < 5) {
|
||||
qWarning()<<url<<"is not standard uri, skip...";
|
||||
continue;
|
||||
}
|
||||
g_autofree gchar* uri = g_uri_unescape_string(url.toString().toUtf8().constData(), nullptr);
|
||||
if (uri) {
|
||||
l<<QString(uri);
|
||||
} else {
|
||||
qWarning()<<"can not unescape uri:"<<url.toString().toUtf8().constData();
|
||||
l<<url.toString().toUtf8().constData();
|
||||
}
|
||||
}
|
||||
}
|
||||
clipboard_file_uris = l;
|
||||
} else {
|
||||
is_clipboard_files_be_cut = false;
|
||||
clipboard_file_uris = QStringList();
|
||||
}
|
||||
} else {
|
||||
is_clipboard_files_be_cut = false;
|
||||
is_clipboard_has_files = false;
|
||||
clipboard_file_uris = QStringList();
|
||||
}
|
||||
}
|
||||
|
||||
void ClipboardUtils::release()
|
||||
{
|
||||
delete global_instance;
|
||||
|
@ -204,7 +135,6 @@ void ClipboardUtils::onClipboardDataChanged()
|
|||
gClipboardFileUrls.clear();
|
||||
|
||||
const QMimeData *mimeData = qApp->clipboard()->mimeData();
|
||||
clipboardData = mimeData;
|
||||
if (!mimeData || mimeData->formats().isEmpty()) {
|
||||
qWarning() << "get null mimeData from QClipBoard or remote formats is null!";
|
||||
return;
|
||||
|
@ -269,7 +199,7 @@ void ClipboardUtils::setClipboardFiles(const QStringList &uris, bool isCut)
|
|||
|
||||
bool ClipboardUtils::isClipboardHasFiles()
|
||||
{
|
||||
return is_clipboard_has_files;
|
||||
return QApplication::clipboard()->mimeData()->hasUrls()|| qApp->clipboard()->mimeData()->hasFormat ("uos/remote-copy");
|
||||
}
|
||||
|
||||
bool ClipboardUtils::isDesktopFilesBeCut()
|
||||
|
@ -284,12 +214,53 @@ bool ClipboardUtils::isPeonyFilesBeCut()
|
|||
|
||||
bool ClipboardUtils::isClipboardFilesBeCut()
|
||||
{
|
||||
return is_clipboard_files_be_cut;
|
||||
if (isClipboardHasFiles()) {
|
||||
auto data = QApplication::clipboard()->mimeData();
|
||||
if (data->hasFormat("peony-qt/is-cut")) {
|
||||
QVariant var(data->data("peony-qt/is-cut"));
|
||||
return var.toBool();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList ClipboardUtils::getClipboardFilesUris()
|
||||
{
|
||||
return clipboard_file_uris;
|
||||
QStringList l;
|
||||
|
||||
if (!isClipboardHasFiles()) {
|
||||
return l;
|
||||
}
|
||||
|
||||
auto mimeData = QApplication::clipboard()->mimeData();
|
||||
//auto text = mimeData->text();
|
||||
auto peonyText = mimeData->data("peony-qt/encoded-uris");
|
||||
|
||||
if (!peonyText.isEmpty()) {
|
||||
qDebug() << "peony text:" << peonyText;
|
||||
auto byteArrays = peonyText.split(' ');
|
||||
for (auto byteArray : byteArrays) {
|
||||
l<<byteArray;
|
||||
}
|
||||
} else {
|
||||
auto urls = mimeData->urls();
|
||||
for (auto url : urls) {
|
||||
// fix #144280, shenxinfu virual machine copy failed
|
||||
if (url.toString().count() < 5) {
|
||||
qWarning()<<url<<"is not standard uri, skip...";
|
||||
continue;
|
||||
}
|
||||
g_autofree gchar* uri = g_uri_unescape_string(url.toString().toUtf8().constData(), nullptr);
|
||||
if (uri) {
|
||||
l<<QString(uri);
|
||||
} else {
|
||||
qWarning()<<"can not unescape uri:"<<url.toString().toUtf8().constData();
|
||||
l<<url.toString().toUtf8().constData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
FileOperation *ClipboardUtils::pasteClipboardFiles(const QString &targetDirUri)
|
||||
|
@ -388,7 +359,7 @@ ClipboardThread::~ClipboardThread()
|
|||
QStringList ClipboardThread::getUrlsByX11()
|
||||
{
|
||||
QAtomicInt currentCount = gRemoteCurrentCount;
|
||||
const QMimeData *mimedata = clipboardData;
|
||||
const QMimeData *mimedata = qApp->clipboard()->mimeData();
|
||||
if (!mimedata) {
|
||||
qWarning() << "the clipboard mimedata is invalid!";
|
||||
return QStringList ();
|
||||
|
|
|
@ -76,7 +76,6 @@ public:
|
|||
static const QString getClipedFilesParentUri();
|
||||
|
||||
const QString getLastTargetDirectoryUri();
|
||||
void updateClipboardManually(bool force = false);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onClipboardDataChanged ();
|
||||
|
|
|
@ -7,14 +7,10 @@ HEADERS += \
|
|||
$$PWD/audio-play-manager.h \
|
||||
$$PWD/clipboard-utils.h \
|
||||
$$PWD/datacdrom.h \
|
||||
$$PWD/file-operation-utils.h \
|
||||
$$PWD/systemd-bus-accounts.h \
|
||||
$$PWD/xdg-portal-helper.h
|
||||
$$PWD/file-operation-utils.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/audio-play-manager.cpp \
|
||||
$$PWD/clipboard-utils.cpp \
|
||||
$$PWD/datacdrom.cpp \
|
||||
$$PWD/file-operation-utils.cpp \
|
||||
$$PWD/systemd-bus-accounts.cpp \
|
||||
$$PWD/xdg-portal-helper.cpp
|
||||
$$PWD/file-operation-utils.cpp
|
||||
|
|
|
@ -238,7 +238,7 @@ int DataCDROM::checkRWSupport()
|
|||
qDebug()<< "Removable CDROM.";
|
||||
break;
|
||||
default:
|
||||
qDebug()<<"Unknown medium type" << ((result[i + 12] << 8) | result[i + 13]);
|
||||
qDebug()<<"Unkown medium type" << ((result[i + 12] << 8) | result[i + 13]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ void DataCDROM::DVDRWCapacity()
|
|||
QStringList deviceName;
|
||||
deviceName<<m_oBlockName;
|
||||
|
||||
process.start("/usr/bin/dvd+rw-mediainfo", deviceName);
|
||||
process.start("dvd+rw-mediainfo", deviceName);
|
||||
process.waitForFinished(10000);
|
||||
QString result = process.readAllStandardOutput();
|
||||
QStringList ss = result.split("\n");
|
||||
|
|
|
@ -603,7 +603,7 @@ bool DiscControl::xorrisoBlankFullSync()
|
|||
|
||||
arg << "-dev" << mDevice << "-blank" << "full";
|
||||
formatUdf.setProcessChannelMode(QProcess::MergedChannels);
|
||||
formatUdf.start("/usr/bin/xorriso", arg);
|
||||
formatUdf.start("xorriso", arg);
|
||||
formatUdf.waitForFinished(-1);
|
||||
output = formatUdf.readAll();
|
||||
formatUdf.close();
|
||||
|
@ -627,7 +627,7 @@ bool DiscControl::xorrisoFormatFullSync()
|
|||
|
||||
arg << "-dev" << mDevice << "-format" << "full";
|
||||
formatUdf.setProcessChannelMode(QProcess::MergedChannels);
|
||||
formatUdf.start("/usr/bin/xorriso", arg);
|
||||
formatUdf.start("xorriso", arg);
|
||||
formatUdf.waitForFinished(-1);
|
||||
output = formatUdf.readAll();
|
||||
formatUdf.close();
|
||||
|
@ -656,7 +656,7 @@ bool DiscControl::formatUdfByUdfclientSync(const QString &dvdRwLabel)
|
|||
|
||||
arg << "-P" << dvdRwLabel << "-L" << dvdRwLabel << mDevice;
|
||||
formatUdf.setProcessChannelMode(QProcess::MergedChannels);
|
||||
formatUdf.start("/usr/bin/newfs_udf", arg);
|
||||
formatUdf.start("newfs_udf", arg);
|
||||
formatUdf.waitForFinished(-1);
|
||||
output = formatUdf.readAll();
|
||||
formatErr = formatUdf.error();
|
||||
|
@ -745,7 +745,7 @@ bool DiscControl::formatUdfDvdRw(const QString& dvdRwLabel){
|
|||
//2. 进行udf格式化
|
||||
arg2<<"-P"<<dvdRwLabel<<"-L"<<dvdRwLabel<<mDevice;
|
||||
formatUdf2.setProcessChannelMode(QProcess::MergedChannels);
|
||||
formatUdf2.start("/usr/bin/newfs_udf", arg2);
|
||||
formatUdf2.start("newfs_udf", arg2);
|
||||
formatUdf2.waitForFinished(-1);
|
||||
output2 = formatUdf2.readAll();
|
||||
formatUdf2.close();
|
||||
|
@ -838,7 +838,7 @@ bool DiscControl::discBurnSync2(){
|
|||
|
||||
//3. 刻录操作:将空盘变为非空盘
|
||||
tmpBurnArg<<"-dev"<<mDevice<<"-map"<<tmpDirPath<<"/"<<"-close"<<"off"<<"-commit";
|
||||
tmpBurn.start("/usr/bin/xorriso", tmpBurnArg);
|
||||
tmpBurn.start("xorriso", tmpBurnArg);
|
||||
tmpBurn.waitForFinished(-1);
|
||||
//tmpBurnOutput = tmpBurn.readAll();
|
||||
|
||||
|
@ -868,7 +868,7 @@ void DiscControl::discBurn(QString srcFile, QString destDir, const QString& disc
|
|||
asyncBurnParameters << "-close" << "off" << "-commit" << "-eject";
|
||||
|
||||
mDeleteDirAfterBurn << srcFile << willBurnDir;
|
||||
asyncBurnOperation->setCmd("/usr/bin/xorriso", asyncBurnParameters);
|
||||
asyncBurnOperation->setCmd("xorriso", asyncBurnParameters);
|
||||
connect(asyncBurnOperation, &DiscCommand::cmdFinished, this, &DiscControl::burnSlot);
|
||||
asyncBurnOperation->startCmd();
|
||||
|
||||
|
@ -929,13 +929,13 @@ QString DiscControl::prepareFileBeforeBurn(const QString& srcFile){
|
|||
dirObject.setPath(hardLinkParentDir);
|
||||
if(!dirObject.exists()){
|
||||
if(!dirObject.mkpath(hardLinkParentDir)){
|
||||
qInfo()<<"failed for mkdir:" + hardLinkParentDir;
|
||||
qInfo()<<"faild for mkdir:" + hardLinkParentDir;
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
//阻塞式创建文件的硬链接
|
||||
hardLinkFileName = hardLinkParentDir+hardLinkFileName;
|
||||
createHardlink->setProgram("/usr/bin/ln");
|
||||
createHardlink->setProgram("ln");
|
||||
hardLinkArgs.append(srcFileAttr.absoluteFilePath());//ln第一个参数
|
||||
hardLinkArgs.append(hardLinkFileName); //ln第二个参数
|
||||
createHardlink->setArguments(hardLinkArgs);
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "file-copy-operation.h"
|
||||
#include "file-trash-operation.h"
|
||||
#include "file-rename-operation.h"
|
||||
#include "file-batch-rename-operation.h"
|
||||
#include "file-delete-operation.h"
|
||||
#include "file-link-operation.h"
|
||||
|
||||
|
@ -41,7 +40,6 @@
|
|||
|
||||
#include "file-operation-internal-dialog.h"
|
||||
#include "sound-effect.h"
|
||||
#include "global-settings.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QFileInfo>
|
||||
|
@ -77,8 +75,7 @@ FileOperation *FileOperationUtils::move(const QStringList &srcUris, const QStrin
|
|||
}
|
||||
|
||||
auto moveOp = new FileMoveOperation(srcUris, destDir);
|
||||
moveOp->setAction(copyMove? Qt::MoveAction: Qt::TargetMoveAction);
|
||||
//moveOp->setCopyMove(copyMove);
|
||||
moveOp->setCopyMove(copyMove);
|
||||
op = moveOp;
|
||||
fileOpMgr->startOperation(moveOp, addHistory);
|
||||
} else {
|
||||
|
@ -156,12 +153,6 @@ FileOperation *FileOperationUtils::trash(const QStringList &uris, bool addHistor
|
|||
// }
|
||||
// qDebug() <<"total_size:" <<total_size<<ONE_GIB_SIZE<<canNotTrash<<isBigFile;
|
||||
|
||||
//task#147972 【删除回收站】选项需求
|
||||
//如果是长城的机器并且带了9215控制器,不再区分移动设备,统一右键删除到回收站
|
||||
bool trashSettings = GlobalSettings::getInstance()->getValue(TRASH_MOBILE_FILES).toBool();
|
||||
if (trashSettings)
|
||||
break;
|
||||
|
||||
//file total size more than 10G, not trash but delete, task#56444
|
||||
//FIXME 判断是否是移动设备文件,可能不准确, 目前暂未找到好的判断方法
|
||||
bool isMobileDeviece = FileUtils::isMobileDeviceFile(uri);
|
||||
|
@ -184,27 +175,13 @@ FileOperation *FileOperationUtils::trash(const QStringList &uris, bool addHistor
|
|||
|
||||
if (canNotTrash) {
|
||||
Peony::AudioPlayManager::getInstance()->playWarningAudio();
|
||||
//task #155670,155671 improve delete file permanently message
|
||||
QString message;
|
||||
if (isBigFile){
|
||||
message = QObject::tr("The file is too large to be moved to the recycle bin. "
|
||||
"Do you want to permanently delete it?");
|
||||
|
||||
if (uris.length() > 1)
|
||||
message = QObject::tr("These files are too large to be moved to the recycle bin. "
|
||||
"Do you want to permanently delete these %1 files?").arg(uris.length());
|
||||
}
|
||||
else if (uris.length() == 1){
|
||||
message = QObject::tr("Are you sure you want to permanently delete this file?"
|
||||
" Once deletion begins, "
|
||||
"the file will not be recoverable.");
|
||||
}else{
|
||||
message = QObject::tr("Are you sure you want to permanently delete these %1 files?"
|
||||
" Once deletion begins, "
|
||||
"these file will not be recoverable.").arg(uris.length());
|
||||
}
|
||||
|
||||
auto result = QMessageBox::question(nullptr, "", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||
QString message = QObject::tr("Can not trash these files. "
|
||||
"You can delete them permanently. "
|
||||
"Are you sure doing that?");
|
||||
if (isBigFile)
|
||||
message = QObject::tr("Can not trash files more than 10GB, would you like to delete it permanently?");
|
||||
auto result = QMessageBox::question(nullptr, QObject::tr("Can not trash"), message,
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||
if (result == QMessageBox::Yes) {
|
||||
op = FileOperationUtils::remove(uris);
|
||||
}
|
||||
|
@ -294,7 +271,7 @@ FileOperation *FileOperationUtils::clearRecycleBinWithDialog(const QStringList &
|
|||
FileOperation *FileOperationUtils::clearRecycleBinWithDialog(const QStringList &list, QWidget *parent)
|
||||
{
|
||||
FileOperationInternalDialog questionbox((QDialog*)parent);
|
||||
auto okButton = questionbox.addButton(QObject::tr("Clean the Trash"));
|
||||
auto okButton = questionbox.addButton(QObject::tr("OK"));
|
||||
questionbox.connect(okButton, &QPushButton::clicked, &questionbox, [&]{
|
||||
questionbox.accept();
|
||||
});
|
||||
|
@ -358,17 +335,15 @@ void FileOperationUtils::executeRemoveActionWithDialog(const QStringList &uris)
|
|||
|
||||
Peony::AudioPlayManager::getInstance()->playWarningAudio();
|
||||
int result = 0;
|
||||
QString message = QObject::tr("Are you sure you want to permanently delete this file?"
|
||||
" Once deletion begins, "
|
||||
"the file will not be recoverable.");
|
||||
if (uris.count() > 1) {
|
||||
message = QObject::tr("Are you sure you want to permanently delete these %1 files?"
|
||||
" Once deletion begins, "
|
||||
"these file will not be recoverable.").arg(uris.length());
|
||||
if (uris.count() == 1) {
|
||||
QUrl url = uris.first();
|
||||
result = QMessageBox::question(nullptr, QObject::tr("Delete Permanently"), QObject::tr("Are you sure that you want to delete these files? Once you start a deletion, the files deleting will never be restored again."),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
|
||||
} else {
|
||||
result = QMessageBox::question(nullptr, QObject::tr("Delete Permanently"), QObject::tr("Are you sure that you want to delete these files? Once you start a deletion, the files deleting will never be restored again."),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
|
||||
}
|
||||
|
||||
result = QMessageBox::question(nullptr, "", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||
|
||||
if (result == QMessageBox::Yes) {
|
||||
FileOperationUtils::remove(uris);
|
||||
}
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* Peony-Qt's Library
|
||||
*
|
||||
* Copyright (C) 2022, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Wenjie Xiang <xiangwenjie@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "systemd-bus-accounts.h"
|
||||
#include <QDebug>
|
||||
|
||||
Peony::SystemDbusAccounts::SystemDbusAccounts(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_systemInterface = new QDBusInterface("org.freedesktop.Accounts",
|
||||
"/org/freedesktop/Accounts",
|
||||
"org.freedesktop.Accounts",
|
||||
QDBusConnection::systemBus());
|
||||
// connect(m_systemInterface, SIGNAL(UserAdded(QDBusObjectPath)), this, SLOT(create_user_success(QDBusObjectPath)));
|
||||
// connect(m_systemInterface, SIGNAL(UserDeleted(QDBusObjectPath)), this, SLOT(delete_user_success(QDBusObjectPath)));
|
||||
}
|
||||
|
||||
Peony::SystemDbusAccounts::~SystemDbusAccounts()
|
||||
{
|
||||
delete m_systemInterface;
|
||||
m_systemInterface = NULL;
|
||||
}
|
||||
|
||||
QStringList Peony::SystemDbusAccounts::getListCachedUsers()
|
||||
{
|
||||
QStringList userLists;
|
||||
QDBusReply<QList<QDBusObjectPath>> reply = m_systemInterface->call("ListCachedUsers");
|
||||
if (reply.isValid()) {
|
||||
for (QDBusObjectPath op : reply.value()) {
|
||||
userLists << op.path();
|
||||
}
|
||||
}
|
||||
return userLists;
|
||||
}
|
||||
|
||||
QStringList Peony::SystemDbusAccounts::getAllUserNames()
|
||||
{
|
||||
QStringList userNames;
|
||||
QStringList objectPaths = getListCachedUsers();
|
||||
if (!objectPaths.isEmpty()) {
|
||||
for (auto objectPath : objectPaths) {
|
||||
userNames << getUserName(objectPath);
|
||||
}
|
||||
}
|
||||
return userNames;
|
||||
}
|
||||
|
||||
QString Peony::SystemDbusAccounts::getUserName(QString objectPath)
|
||||
{
|
||||
QString userName;
|
||||
QDBusInterface *interFace = new QDBusInterface("org.freedesktop.Accounts",
|
||||
objectPath,
|
||||
"org.freedesktop.DBus.Properties",
|
||||
QDBusConnection::systemBus());
|
||||
QDBusReply<QDBusVariant> reply = interFace->call("Get", "org.freedesktop.Accounts.User", "UserName");
|
||||
if (reply.isValid()) {
|
||||
userName = reply.value().variant().toString();
|
||||
} else {
|
||||
qDebug() << __func__ << "reply failed!";
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
|
||||
void Peony::SystemDbusAccounts::createUserSuccess(QDBusObjectPath objectPath)
|
||||
{
|
||||
Q_EMIT createUserDone(objectPath.path());
|
||||
}
|
||||
|
||||
void Peony::SystemDbusAccounts::deleteUserSuccess(QDBusObjectPath objectPath)
|
||||
{
|
||||
Q_EMIT deleteUserDone(objectPath.path());
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Peony-Qt's Library
|
||||
*
|
||||
* Copyright (C) 2022, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Wenjie Xiang <xiangwenjie@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMDBUSACCOUNTS_H
|
||||
#define SYSTEMDBUSACCOUNTS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusReply>
|
||||
|
||||
#include "peony-core_global.h"
|
||||
|
||||
namespace Peony {
|
||||
|
||||
class PEONYCORESHARED_EXPORT SystemDbusAccounts : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SystemDbusAccounts(QObject *parent = nullptr);
|
||||
~SystemDbusAccounts();
|
||||
|
||||
QStringList getListCachedUsers();
|
||||
QStringList getAllUserNames();
|
||||
QString getUserName(QString objectPath);
|
||||
|
||||
public Q_SLOTS:
|
||||
void createUserSuccess(QDBusObjectPath objectPath);
|
||||
void deleteUserSuccess(QDBusObjectPath objectPath);
|
||||
|
||||
Q_SIGNALS:
|
||||
void createUserDone(QString path);
|
||||
void deleteUserDone(QString path);
|
||||
|
||||
private:
|
||||
QDBusInterface *m_systemInterface = nullptr;
|
||||
|
||||
};
|
||||
}
|
||||
#endif // SYSTEMDBUSACCOUNTS_H
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Peony-Qt's Library
|
||||
*
|
||||
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Yue Lan <lanyue@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xdg-portal-helper.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Peony;
|
||||
|
||||
static XdgPortalHelper *global_instance = nullptr;
|
||||
static bool is_flatpak_context = false;
|
||||
static bool is_init_with_gtk_use_portal_env = false;
|
||||
|
||||
static QMutex portal_mutex;
|
||||
|
||||
XdgPortalHelper *XdgPortalHelper::getInstance()
|
||||
{
|
||||
if (!global_instance)
|
||||
global_instance = new XdgPortalHelper;
|
||||
return global_instance;
|
||||
}
|
||||
|
||||
bool XdgPortalHelper::tryUnusePortal()
|
||||
{
|
||||
if (is_flatpak_context)
|
||||
return false;
|
||||
if (!is_init_with_gtk_use_portal_env)
|
||||
return true;
|
||||
|
||||
if (!portal_mutex.tryLock()) {
|
||||
qWarning()<<__FUNCTION__<<"can not get portal mutex control";
|
||||
return false;
|
||||
}
|
||||
g_unsetenv("GTK_USE_PORTAL");
|
||||
portal_mutex.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool XdgPortalHelper::tryResetPortal()
|
||||
{
|
||||
if (is_flatpak_context)
|
||||
return true;
|
||||
if (!is_init_with_gtk_use_portal_env)
|
||||
return true;
|
||||
if (!portal_mutex.tryLock()) {
|
||||
qWarning()<<__FUNCTION__<<"can not get portal mutex control";
|
||||
return false;
|
||||
}
|
||||
g_setenv("GTK_USE_PORTAL", "1", true);
|
||||
portal_mutex.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
XdgPortalHelper::XdgPortalHelper(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
is_flatpak_context = g_file_test("/.flatpak-info", G_FILE_TEST_EXISTS);
|
||||
auto env = g_getenv("GTK_USE_PORTAL");
|
||||
is_init_with_gtk_use_portal_env = (env && env[0] == '1');
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Peony-Qt's Library
|
||||
*
|
||||
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Yue Lan <lanyue@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XDGPORTALHELPER_H
|
||||
#define XDGPORTALHELPER_H
|
||||
|
||||
#include "peony-core_global.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace Peony {
|
||||
|
||||
class PEONYCORESHARED_EXPORT XdgPortalHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static XdgPortalHelper *getInstance();
|
||||
bool tryUnusePortal();
|
||||
bool tryResetPortal();
|
||||
|
||||
private:
|
||||
explicit XdgPortalHelper(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // XDGPORTALHELPER_H
|
|
@ -70,7 +70,6 @@ void EmblemProviderManager::registerProvider(EmblemProvider *provider)
|
|||
connect(provider, &EmblemProvider::visibleChanged, this, [=](bool visible){
|
||||
this->visibleChanged(provider->emblemKey().toUtf8().constData(), visible);
|
||||
});
|
||||
connect(this, &EmblemProviderManager::queueQueryFinished, this, &EmblemProviderManager::requestUpdateAllFiles);
|
||||
}
|
||||
|
||||
QStringList EmblemProviderManager::getAllEmblemsForUri(const QString &uri)
|
||||
|
|
|
@ -19,16 +19,11 @@
|
|||
* Authors: Ding Jing <dingjing@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/mman.h>
|
||||
#include "file-copy.h"
|
||||
#include "file-utils.h"
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstring>
|
||||
#include <QString>
|
||||
#include <mutex>
|
||||
#include <mntent.h>
|
||||
#include <QProcess>
|
||||
#include "file-info.h"
|
||||
|
@ -36,9 +31,6 @@
|
|||
|
||||
#define BUF_SIZE 1024000
|
||||
#define SYNC_INTERVAL 10
|
||||
#define BIG_FILE_SIZE 300 * 1024 * 1024
|
||||
const size_t BUFFER_SIZE = 4096;
|
||||
std::mutex fileMutex;
|
||||
|
||||
using namespace Peony;
|
||||
|
||||
|
@ -83,11 +75,6 @@ void FileCopy::cancel()
|
|||
mPause.unlock();
|
||||
}
|
||||
|
||||
FileCopy::Status FileCopy::getStatus()
|
||||
{
|
||||
return mStatus;
|
||||
}
|
||||
|
||||
void FileCopy::detailError (GError** error)
|
||||
{
|
||||
if (nullptr == error || nullptr == *error || nullptr == mError) {
|
||||
|
@ -95,7 +82,9 @@ void FileCopy::detailError (GError** error)
|
|||
}
|
||||
|
||||
g_set_error(mError, (*error)->domain, (*error)->code, "%s", (*error)->message);
|
||||
g_clear_error(error);
|
||||
g_error_free(*error);
|
||||
|
||||
*error = nullptr;
|
||||
}
|
||||
|
||||
void FileCopy::sync(const GFile* destFile)
|
||||
|
@ -112,21 +101,12 @@ void FileCopy::sync(const GFile* destFile)
|
|||
return;
|
||||
}
|
||||
|
||||
if(mTotalSize < BUF_SIZE * SYNC_INTERVAL || mIsDestFileLocal) {
|
||||
return;
|
||||
}
|
||||
|
||||
// execute sync
|
||||
int fromfd = open(path, O_SYNC);
|
||||
if (-1 != fromfd) {
|
||||
fsync(fromfd);
|
||||
close(fromfd);
|
||||
} else {
|
||||
auto lastError = strerror(errno);
|
||||
qWarning() << "Failed to open the source file, path:" << path
|
||||
<< "error code:" << errno
|
||||
<< "error msg:" << lastError;
|
||||
}
|
||||
QProcess p;
|
||||
p.setProgram("sync");
|
||||
p.setArguments(QStringList() << "-f" << path);
|
||||
p.start();
|
||||
p.waitForFinished(-1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -178,15 +158,6 @@ void FileCopy::run ()
|
|||
goto out;
|
||||
}
|
||||
|
||||
//fix copy special file stuck issue, will skip these type files: socket, fifo, blockdev, chardev
|
||||
//fix bug#162130, 参照nautilus提示修改
|
||||
if (G_FILE_TYPE_SPECIAL == srcFileType) {
|
||||
//qWarning() << "skip G_FILE_TYPE_SPECIAL type file copy srcFile: " << mSrcUri;
|
||||
error = g_error_new(1, G_IO_ERROR_NOT_REGULAR_FILE, "%s", tr("Error when copy file: %1, can not copy special files, skip this file and continue?").arg(mSrcUri.replace("file://", "")).toUtf8().constData());
|
||||
detailError(&error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
destFileType = g_file_query_file_type(destFile, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr);
|
||||
if (G_FILE_TYPE_DIRECTORY == destFileType) {
|
||||
mDestUri = mDestUri + "/" + mSrcUri.split("/").last();
|
||||
|
@ -201,14 +172,6 @@ void FileCopy::run ()
|
|||
|
||||
// check file status
|
||||
if (FileUtils::isFileExsit(mDestUri)) {
|
||||
bool src_file_exists = g_file_query_exists(srcFile, mCancel);
|
||||
if (!src_file_exists) {
|
||||
qWarning()<<__FUNCTION__<<"query src file doesn't exist"<<mSrcUri;
|
||||
g_clear_error(&error);
|
||||
error = g_error_new_literal(g_io_error_quark(), G_IO_ERROR_NOT_FOUND, tr("Can not copy %1, file doesn't exist. Has the file been renamed or moved?").arg(mSrcUri).toUtf8().constData());
|
||||
detailError(&error);
|
||||
return;
|
||||
}
|
||||
if (mCopyFlags & G_FILE_COPY_OVERWRITE) {
|
||||
g_file_delete(destFile, nullptr, &error);
|
||||
if (nullptr != error) {
|
||||
|
@ -244,7 +207,6 @@ void FileCopy::run ()
|
|||
|
||||
// check dest filesystem
|
||||
destDir = g_file_get_parent (destFile);
|
||||
mIsDestFileLocal = isFileOnLocal(destDir);
|
||||
if (destDir) {
|
||||
g_autoptr (GMount) destMount = g_file_find_enclosing_mount (destDir, NULL, NULL);
|
||||
if (destMount) {
|
||||
|
@ -265,30 +227,6 @@ void FileCopy::run ()
|
|||
}
|
||||
}
|
||||
|
||||
if (mTotalSize > BIG_FILE_SIZE) {
|
||||
if (!mSrcUri.startsWith("ftp://") && !mSrcUri.startsWith("sftp://")) {
|
||||
auto SrcPath = g_file_get_path(srcFile);
|
||||
auto destPath = g_file_get_path(destFile);
|
||||
|
||||
if(-1 != doCopyBigFile(SrcPath, destPath)){
|
||||
if (CANCEL == mStatus) {
|
||||
error = g_error_new(1, G_IO_ERROR_CANCELLED, "%s", tr("operation cancel").toUtf8().constData());
|
||||
detailError(&error);
|
||||
g_file_delete(destFile, nullptr, nullptr);
|
||||
} else {
|
||||
mStatus = FINISHED;
|
||||
}
|
||||
goto out;
|
||||
} else {
|
||||
if (ERROR == mStatus) {
|
||||
error = g_error_new(1, G_IO_ERROR_FAILED, "%s", tr("Error writing to file: Input/output error").toUtf8().constData());
|
||||
detailError(&error);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// read io stream
|
||||
readIO = g_file_read(srcFile, mCancel ? mCancel : nullptr, &error);
|
||||
if (nullptr != error) {
|
||||
|
@ -320,7 +258,7 @@ void FileCopy::run ()
|
|||
|
||||
if (notSupportInputStream || notSupportOutputStream) {
|
||||
qInfo()<<"stream io not supported, use g_file_copy instead";
|
||||
g_file_copy(srcFile, destFile, (writeIO? GFileCopyFlags(mCopyFlags|G_FILE_COPY_OVERWRITE): mCopyFlags), mCancel, mProgress, mProgressData, &error);
|
||||
g_file_copy(srcFile, destFile, mCopyFlags, mCancel, mProgress, mProgressData, &error);
|
||||
sync(destFile);
|
||||
if (error) {
|
||||
qWarning() << "g_file_copy error:" << error->code << " -- " << error->message;
|
||||
|
@ -352,11 +290,9 @@ void FileCopy::run ()
|
|||
if (0 == readSize && nullptr == error) {
|
||||
mStatus = FINISHED;
|
||||
mPause.unlock();
|
||||
if (mTotalSize == 0) {
|
||||
mTotalSize = 1024;
|
||||
mOffset = mTotalSize;
|
||||
updateProgress ();
|
||||
}
|
||||
mTotalSize = 1024;
|
||||
mOffset = mTotalSize;
|
||||
updateProgress ();
|
||||
continue;
|
||||
} else if (nullptr != error) {
|
||||
detailError(&error);
|
||||
|
@ -385,7 +321,7 @@ void FileCopy::run ()
|
|||
if (!existed) {
|
||||
error = g_error_new (1, G_IO_ERROR_FAILED, "%s", tr("Please check whether the device has been removed!").toUtf8().constData());
|
||||
} else {
|
||||
error = g_error_new(1, G_IO_ERROR_FAILED, "%s", tr("Write file error: There is no available disk space for device!").toUtf8().constData());
|
||||
error = g_error_new(1, G_IO_ERROR_FAILED, "%s", tr("Write file error: There is no avaliable disk space for device!").toUtf8().constData());
|
||||
}
|
||||
|
||||
detailError(&error);
|
||||
|
@ -405,8 +341,7 @@ void FileCopy::run ()
|
|||
g_file_delete (destFile, nullptr, nullptr);
|
||||
break;
|
||||
} else if (ERROR == mStatus) {
|
||||
// 在一些特殊场景下可能会导致数据丢失问题,所以屏蔽
|
||||
//g_file_delete (destFile, nullptr, nullptr);
|
||||
g_file_delete (destFile, nullptr, nullptr);
|
||||
break;
|
||||
} else if (FINISHED == mStatus) {
|
||||
break;
|
||||
|
@ -456,24 +391,12 @@ out:
|
|||
}
|
||||
sync(destFile);
|
||||
} else {
|
||||
// some special detail for mtp, gphoto2, or other cases.
|
||||
if (mSrcUri.startsWith("mtp://") || mDestUri.startsWith("mtp://")) {
|
||||
// some special detail for mtp
|
||||
if (mSrcUri.startsWith("mtp:///") || mDestUri.startsWith("mtp:///")) {
|
||||
if (mError) {
|
||||
g_error_free(*mError);
|
||||
*mError = nullptr;
|
||||
g_set_error(mError, 1, G_IO_ERROR_FAILED, "%s", tr("File opening failure").toUtf8().constData());
|
||||
}else if (mDestUri.startsWith("gphoto2://")) {
|
||||
if (mError) {
|
||||
g_error_free(*mError);
|
||||
*mError = nullptr;
|
||||
g_set_error(mError, 1, G_IO_ERROR_FAILED, "%s", tr("Failed to create %1. Please ensure if it is in root directory, or if the device supports gphoto2 protocol correctly.").arg(mDestUri).toUtf8().constData());
|
||||
}
|
||||
} else {
|
||||
if (mError) {
|
||||
g_error_free(*mError);
|
||||
*mError = nullptr;
|
||||
g_set_error(mError, 1, G_IO_ERROR_FAILED, "%s", tr("Failed to create %1.").arg(mDestUri).toUtf8().constData());
|
||||
}
|
||||
g_set_error(mError, 1, G_IO_ERROR_NOT_SUPPORTED, "%s", tr("File opening failure").toUtf8().constData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -509,86 +432,6 @@ out:
|
|||
}
|
||||
}
|
||||
|
||||
int FileCopy::doCopyBigFile(const char *srcPath, const char *destPath)
|
||||
{
|
||||
mStatus = RUNNING;
|
||||
int in_fd, out_fd, ret(-1);
|
||||
struct stat stat_buf;
|
||||
off_t offset = 0;
|
||||
int syncCount = 0;
|
||||
|
||||
std::unique_lock<std::mutex> lock(fileMutex, std::defer_lock);
|
||||
lock.lock();
|
||||
in_fd = open(srcPath, O_RDONLY);
|
||||
if (in_fd == -1) {
|
||||
qDebug() << "Failed to open the source file";
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (fstat(in_fd, &stat_buf) == -1) {
|
||||
qDebug() << "Failed to get the source file status";
|
||||
return ret;
|
||||
}
|
||||
lock.unlock();
|
||||
out_fd = open(destPath, O_WRONLY | O_CREAT, stat_buf.st_mode);
|
||||
if (out_fd == -1) {
|
||||
qDebug() << "Failed to open the destination file";
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t buf = 10 * 1024 * 1024;
|
||||
ssize_t sendSize = 0;
|
||||
ssize_t size = 0;
|
||||
while(size < stat_buf.st_size) {
|
||||
if (nullptr != mCancel && g_cancellable_is_cancelled(mCancel)) {
|
||||
mStatus = CANCEL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (RUNNING == mStatus) {
|
||||
sendSize = sendfile(out_fd, in_fd, &offset, buf);
|
||||
if (sendSize == -1) {
|
||||
size = sendSize;
|
||||
if (0 != offset) {
|
||||
mStatus = ERROR;
|
||||
}
|
||||
qWarning() << "send file error";
|
||||
break;
|
||||
}
|
||||
size += sendSize;
|
||||
if (mOffset <= mTotalSize) {
|
||||
mOffset = size;
|
||||
}
|
||||
if (!mIsDestFileLocal) {
|
||||
if (++syncCount > SYNC_INTERVAL) {
|
||||
syncCount = 0;
|
||||
fsync(out_fd);
|
||||
}
|
||||
}
|
||||
updateProgress ();
|
||||
} else if (PAUSE == mStatus) {
|
||||
if (mPause.tryLock(3000)) {
|
||||
if (RESUME == mStatus) {
|
||||
mPause.unlock();
|
||||
}
|
||||
mStatus = RUNNING;
|
||||
}
|
||||
}
|
||||
}
|
||||
close(in_fd);
|
||||
close(out_fd);
|
||||
return size;
|
||||
}
|
||||
|
||||
bool FileCopy::isFileOnLocal(const GFile* destFile)
|
||||
{
|
||||
GMount* mount = g_file_find_enclosing_mount(const_cast<GFile*>(destFile), NULL, NULL);
|
||||
if (mount) {
|
||||
return !g_mount_can_unmount(mount);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @note
|
||||
* 同步了 glib 针对vfat/fat32 单文件大于4g,提前提醒用户的补丁,
|
||||
|
|
|
@ -73,16 +73,13 @@ public Q_SLOTS:
|
|||
*/
|
||||
void cancel();
|
||||
|
||||
Status getStatus();
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
private:
|
||||
void updateProgress () const;
|
||||
void detailError (GError** error);
|
||||
void sync(const GFile* destFile);
|
||||
int doCopyBigFile(const char *srcPath, const char *destPath);
|
||||
bool isFileOnLocal(const GFile* destFile);
|
||||
|
||||
private:
|
||||
QMutex mPause;
|
||||
QString mSrcUri = nullptr;
|
||||
|
@ -98,7 +95,6 @@ private:
|
|||
goffset mOffset = 0; // 记录当前进度
|
||||
goffset mTotalSize = 0; // 记录当前进度
|
||||
enum Status mStatus = INVALID; // 记录运行状态
|
||||
bool mIsDestFileLocal = false;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -428,13 +428,8 @@ void FileEnumerator::enumerateAsync()
|
|||
|
||||
// query directory info first
|
||||
auto infoJob = new FileInfoJob(m_uri);
|
||||
//infoJob->setAutoDelete(true);
|
||||
connect(infoJob, &FileInfoJob::queryAsyncFinished, this, [=](bool successed){
|
||||
if (!successed) {
|
||||
Q_EMIT enumerateFinished(false);
|
||||
infoJob->deleteLater();
|
||||
return;
|
||||
}
|
||||
infoJob->setAutoDelete(true);
|
||||
connect(infoJob, &FileInfoJob::queryAsyncFinished, this, [=](){
|
||||
//auto uri = g_file_get_uri(m_root_file);
|
||||
//auto path = g_file_get_path(m_root_file);
|
||||
g_file_enumerate_children_async(m_root_file,
|
||||
|
@ -445,9 +440,8 @@ void FileEnumerator::enumerateAsync()
|
|||
m_cancellable,
|
||||
GAsyncReadyCallback(find_children_async_ready_callback),
|
||||
this);
|
||||
infoJob->deleteLater();
|
||||
|
||||
});
|
||||
connect(this, &FileEnumerator::cancelled, infoJob, &FileInfoJob::cancel);
|
||||
infoJob->queryAsync();
|
||||
}
|
||||
|
||||
|
@ -564,15 +558,12 @@ GAsyncReadyCallback FileEnumerator::mount_enclosing_volume_callback(GFile *file,
|
|||
if (finished_err) {
|
||||
qDebug()<<"finished err:"<<finished_err->code()<<finished_err->message();
|
||||
if (finished_err->code() == G_IO_ERROR_PERMISSION_DENIED
|
||||
|| finished_err->code() == G_IO_ERROR_FAILED_HANDLED
|
||||
|| finished_err->code() == G_IO_ERROR_NOT_DIRECTORY) {
|
||||
|| finished_err->code() == G_IO_ERROR_FAILED_HANDLED) {
|
||||
p_this->enumerateFinished(false);
|
||||
Peony::AudioPlayManager::getInstance()->playWarningAudio();
|
||||
QString strErr = finished_err->message();
|
||||
if (finished_err->code() == G_IO_ERROR_FAILED_HANDLED) {
|
||||
strErr = tr("The password dialog box is canceled");
|
||||
} else if (finished_err->code() == G_IO_ERROR_NOT_DIRECTORY) {
|
||||
strErr = tr("Message recipient disconnected from message bus without replying!");
|
||||
}
|
||||
QMessageBox::critical(nullptr, tr("Error"), strErr);
|
||||
return;
|
||||
|
@ -602,7 +593,7 @@ GAsyncReadyCallback FileEnumerator::find_children_async_ready_callback(GFile *fi
|
|||
qDebug()<<"find children async err:"<<err->code<<err->message;
|
||||
//NOTE: if the enumerator file has target uri, but target uri is not mounted,
|
||||
//it should be handled.
|
||||
//This nearly won't happened in local, but in a network server it might.
|
||||
//This nearly won't happend in local, but in a network server it might.
|
||||
if (err->code == G_IO_ERROR_NOT_MOUNTED) {
|
||||
g_object_unref(p_this->m_root_file);
|
||||
p_this->m_root_file = g_file_dup(file);
|
||||
|
|
|
@ -309,7 +309,7 @@ void FileInfoJob::refreshInfoContents(GFileInfo *new_info)
|
|||
if (g_file_info_has_attribute(new_info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) {
|
||||
info->m_can_read = g_file_info_get_attribute_boolean(new_info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
|
||||
} else {
|
||||
// we assume an Unknown access file is readable.
|
||||
// we assume an unknow access file is readable.
|
||||
info->m_can_read = true;
|
||||
}
|
||||
|
||||
|
@ -339,9 +339,6 @@ void FileInfoJob::refreshInfoContents(GFileInfo *new_info)
|
|||
if(g_file_info_has_attribute(new_info,G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE_FILE))
|
||||
info->m_unix_device_file = g_file_info_get_attribute_string(new_info,G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE_FILE);
|
||||
|
||||
info->m_target_uri = g_file_info_get_attribute_string(new_info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
|
||||
info->m_symlink_target = g_file_info_get_symlink_target(new_info);
|
||||
|
||||
GIcon *g_icon = g_file_info_get_icon (new_info);
|
||||
if (G_IS_THEMED_ICON(g_icon)) {
|
||||
const gchar* const* icon_names = g_themed_icon_get_names(G_THEMED_ICON (g_icon));
|
||||
|
@ -360,19 +357,7 @@ void FileInfoJob::refreshInfoContents(GFileInfo *new_info)
|
|||
//g_object_unref(g_icon);
|
||||
}
|
||||
|
||||
//fix bug#163449, trash desktop file icon issue
|
||||
auto uri = m_info.get()->uri();
|
||||
QUrl targetUrl = info->m_target_uri;
|
||||
if (uri.startsWith("trash:///") && uri != "trash:///" && QFile::exists(targetUrl.path())){
|
||||
if (info->m_icon_name == "application-x-desktop"){
|
||||
auto _desktop_file = g_desktop_app_info_new_from_filename(QUrl(targetUrl).path().toUtf8().constData());
|
||||
if (_desktop_file) {
|
||||
info->m_icon_name = g_desktop_app_info_get_string(_desktop_file, "Icon");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//qDebug()<<"refreshInfoContents:"<<info->m_uri <<info->m_icon_name;
|
||||
//qDebug()<<m_display_name<<m_icon_name;
|
||||
GIcon *g_symbolic_icon = g_file_info_get_symbolic_icon (new_info);
|
||||
if (G_IS_THEMED_ICON(g_symbolic_icon)) {
|
||||
const gchar* const* symbolic_icon_names = g_themed_icon_get_names(G_THEMED_ICON (g_symbolic_icon));
|
||||
|
@ -421,31 +406,29 @@ void FileInfoJob::refreshInfoContents(GFileInfo *new_info)
|
|||
info->m_file_size = nullptr;
|
||||
}
|
||||
|
||||
// auto systemTimeFormat = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
// QDateTime date = QDateTime::fromMSecsSinceEpoch(info->m_modified_time*1000);
|
||||
auto systemTimeFormat = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
QDateTime date = QDateTime::fromMSecsSinceEpoch(info->m_modified_time*1000);
|
||||
if (info->m_modified_time) {
|
||||
//info->m_modified_date = date.toString(systemTimeFormat);
|
||||
info->m_modified_date = GlobalSettings::getInstance()->transToSystemTimeFormat(info->m_modified_time);
|
||||
info->m_modified_date = date.toString(systemTimeFormat);
|
||||
} else {
|
||||
info->m_modified_date = nullptr;
|
||||
}
|
||||
|
||||
if (info->m_access_time) {
|
||||
// date = QDateTime::fromMSecsSinceEpoch(info->m_access_time*1000);
|
||||
// info->m_access_date = date.toString(systemTimeFormat);
|
||||
info->m_access_date = GlobalSettings::getInstance()->transToSystemTimeFormat(info->m_access_time);
|
||||
date = QDateTime::fromMSecsSinceEpoch(info->m_access_time*1000);
|
||||
info->m_access_date = date.toString(systemTimeFormat);
|
||||
} else {
|
||||
info->m_access_date = nullptr;
|
||||
}
|
||||
|
||||
if (g_file_info_has_attribute(new_info, "trash::deletion-date"))
|
||||
{
|
||||
QString deletionDate = g_file_info_get_attribute_as_string(new_info, G_FILE_ATTRIBUTE_TRASH_DELETION_DATE);
|
||||
info->m_deletion_date = deletionDate.replace("T", " ");
|
||||
QDateTime dateTime = QDateTime::fromString (deletionDate, "yyyy-MM-dd HH:mm:ss");
|
||||
info->m_deletion_date_uint64 = dateTime.toMSecsSinceEpoch ();
|
||||
//time already processed, need /1000 to origin state
|
||||
info->m_deletion_date = GlobalSettings::getInstance()->transToSystemTimeFormat(info->m_deletion_date_uint64/1000);
|
||||
QString deletionDate = g_file_info_get_attribute_as_string(new_info, G_FILE_ATTRIBUTE_TRASH_DELETION_DATE);
|
||||
info->m_deletion_date = deletionDate.replace("T", " ");
|
||||
QDateTime dateTime = QDateTime::fromString (deletionDate, "yyyy-MM-dd HH:mm:ss");
|
||||
info->m_deletion_date_uint64 = dateTime.toMSecsSinceEpoch ();
|
||||
date = QDateTime::fromMSecsSinceEpoch(info->m_deletion_date_uint64);
|
||||
info->m_deletion_date = date.toString(systemTimeFormat);
|
||||
}
|
||||
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);
|
||||
|
@ -463,7 +446,12 @@ void FileInfoJob::refreshInfoContents(GFileInfo *new_info)
|
|||
|
||||
queryFileDisplayName(new_info);
|
||||
|
||||
info->m_target_uri = g_file_info_get_attribute_string(new_info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
|
||||
info->m_symlink_target = g_file_info_get_symlink_target(new_info);
|
||||
|
||||
// fix #81862
|
||||
auto uri = m_info.get()->uri();
|
||||
QUrl targetUrl = info->m_target_uri;
|
||||
//fix bug#126974, related to trash link files, use this code when target exists
|
||||
if (uri.startsWith("trash:///") && uri != "trash:///" && QFile::exists(targetUrl.path())) {
|
||||
auto targetInfo = FileInfo::fromUri(info->m_target_uri);
|
||||
|
|
|
@ -82,8 +82,8 @@ Q_SIGNALS:
|
|||
/*!
|
||||
* \brief queryAsyncFinished
|
||||
* \param successed
|
||||
* \retval true if no error happened in queryAsync() and callback
|
||||
* \retval false if error happened, it might be cancelled, or others.
|
||||
* \retval true if no error happend in queryAsync() and callback
|
||||
* \retval false if error happend, it might be cancelled, or others.
|
||||
* \note If you just want to get the info states, I recommend you connect to
|
||||
* Peony::FileInfo::updated signal, every query job of a info will send this signal
|
||||
* if query successfully.
|
||||
|
|
|
@ -199,21 +199,6 @@ bool FileInfo::isExecDisable()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool FileInfo::isAudioFile()
|
||||
{
|
||||
if (nullptr != m_mime_type_string) {
|
||||
if (m_mime_type_string.startsWith("audio")
|
||||
|| m_mime_type_string.startsWith("application/x-smaf")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isOfficeFile()
|
||||
{
|
||||
int idx = 0;
|
||||
|
|
|
@ -285,9 +285,6 @@ public:
|
|||
}
|
||||
|
||||
bool isVideoFile();
|
||||
|
||||
bool isAudioFile();
|
||||
|
||||
bool isOfficeFile();
|
||||
|
||||
bool isEmptyInfo() {
|
||||
|
|
|
@ -40,11 +40,6 @@
|
|||
#include "global-settings.h"
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
|
||||
#ifdef KY_SDK_QT_WIDGETS
|
||||
#include "kborderlessbutton.h"
|
||||
using namespace kdk;
|
||||
#endif
|
||||
|
||||
#define DESKTOPPATH "/usr/share/applications/"
|
||||
|
||||
using namespace Peony;
|
||||
|
@ -258,12 +253,7 @@ void FileLauchDialog::initFloorThree()
|
|||
floor3->setLayout(layout3);
|
||||
floor3->setMaximumHeight(60);
|
||||
layout3->setContentsMargins(10,0,0,0);
|
||||
#ifdef KY_SDK_QT_WIDGETS
|
||||
KBorderlessButton *allOpenLabel = new KBorderlessButton(tr("Choose other application"), floor3);
|
||||
KBorderlessButton *otherOpenLabel = new KBorderlessButton(tr("Go to application center"), floor3);
|
||||
connect(allOpenLabel, &KBorderlessButton::clicked, this, &FileLauchDialog::chooseOtherApp);
|
||||
connect(otherOpenLabel, &KBorderlessButton::clicked, this, &FileLauchDialog::openAppCenter);
|
||||
#else
|
||||
|
||||
QString str1;
|
||||
str1 = "<a href=\"ukui-software-center\" style=\"color: #3D6BE5;text-decoration: none;\">"
|
||||
+ tr("Choose other application")
|
||||
|
@ -271,6 +261,12 @@ void FileLauchDialog::initFloorThree()
|
|||
QLabel *allOpenLabel = new QLabel(str1, floor3);
|
||||
allOpenLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
connect(allOpenLabel, &QLabel::linkActivated, this, [=]() {
|
||||
FileLauchDialog::moreAction();
|
||||
});
|
||||
|
||||
layout3->addWidget(allOpenLabel);
|
||||
|
||||
QString str2;
|
||||
str2 = "<a href=\"ukui-software-center\" style=\"color: #3D6BE5;text-decoration: none;\">"
|
||||
+ tr("Go to application center")
|
||||
|
@ -278,9 +274,26 @@ void FileLauchDialog::initFloorThree()
|
|||
QLabel *otherOpenLabel = new QLabel(str2, floor3);
|
||||
otherOpenLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
connect(allOpenLabel, &QLabel::linkActivated, this, &FileLauchDialog::chooseOtherApp);
|
||||
connect(otherOpenLabel, &QLabel::linkActivated, this, &FileLauchDialog::openAppCenter);
|
||||
connect(otherOpenLabel, &QLabel::linkActivated, this, [=]() {
|
||||
QtConcurrent::run([=]() {
|
||||
QProcess p;
|
||||
if (COMMERCIAL_VERSION || (GlobalSettings::getInstance()->getProjectName() == V10_SP1_EDU))
|
||||
p.setProgram("kylin-software-center");
|
||||
else
|
||||
p.setProgram("ubuntu-kylin-software-center");
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
p.startDetached();
|
||||
#else
|
||||
if (COMMERCIAL_VERSION)
|
||||
p.startDetached("kylin-software-center");
|
||||
else
|
||||
p.startDetached("ubuntu-kylin-software-center");
|
||||
|
||||
#endif
|
||||
});
|
||||
});
|
||||
|
||||
bool isVisible = false;
|
||||
if(QFileInfo::exists("/usr/bin/kylin-software-center")
|
||||
|| QFileInfo::exists("/usr/bin/ubuntu-kylin-software-center")){
|
||||
|
@ -288,38 +301,12 @@ void FileLauchDialog::initFloorThree()
|
|||
}
|
||||
|
||||
otherOpenLabel->setVisible(isVisible);
|
||||
layout3->addWidget(allOpenLabel);
|
||||
layout3->addWidget(otherOpenLabel);
|
||||
layout3->addStretch(1);
|
||||
|
||||
this->m_layout->addWidget(floor3);
|
||||
}
|
||||
|
||||
void FileLauchDialog::chooseOtherApp()
|
||||
{
|
||||
FileLauchDialog::moreAction();
|
||||
}
|
||||
|
||||
void FileLauchDialog::openAppCenter()
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
QProcess p;
|
||||
if (COMMERCIAL_VERSION || (GlobalSettings::getInstance()->getProjectName() == V10_SP1_EDU))
|
||||
p.setProgram("kylin-software-center");
|
||||
else
|
||||
p.setProgram("ubuntu-kylin-software-center");
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
p.startDetached();
|
||||
#else
|
||||
if (COMMERCIAL_VERSION)
|
||||
p.startDetached("kylin-software-center");
|
||||
else
|
||||
p.startDetached("ubuntu-kylin-software-center");
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
void FileLauchDialog::initFloorFour()
|
||||
{
|
||||
QWidget *container = new QWidget();
|
||||
|
@ -371,13 +358,12 @@ void FileLauchDialog::paintEvent(QPaintEvent *event)
|
|||
bool FileLauchDialog::event(QEvent *event)
|
||||
{
|
||||
//失去焦点即关闭窗口
|
||||
//comment this code, fix bug#164644, open other app auto close issue
|
||||
// if (event->type() == QEvent::ActivationChange) {
|
||||
// if (QApplication::activeWindow() != this) {
|
||||
// this->close();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
if (event->type() == QEvent::ActivationChange) {
|
||||
if (QApplication::activeWindow() != this) {
|
||||
this->close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
|
|
|
@ -122,11 +122,6 @@ public:
|
|||
}
|
||||
Q_SIGNALS:
|
||||
void open(FileLaunchAction *action);
|
||||
|
||||
public Q_SLOTS:
|
||||
void chooseOtherApp();
|
||||
void openAppCenter();
|
||||
|
||||
protected:
|
||||
void init(const QString &uri);
|
||||
void initFloorOne();
|
||||
|
|
|
@ -126,6 +126,7 @@ bool FileLaunchAction::isExcuteableFile(QString fileType)
|
|||
|
||||
void FileLaunchAction::lauchFileSync(bool forceWithArg, bool skipDialog)
|
||||
{
|
||||
m_force_with_arg = forceWithArg;
|
||||
if(checkAppDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ void FileLaunchAction::lauchFileSync(bool forceWithArg, bool skipDialog)
|
|||
}
|
||||
|
||||
if (launchAppWithDBus()) {
|
||||
qDebug() << "[FileLaunchAction::lauchFileSync] launchAppWithDBus success name:" << fileInfo->displayName();
|
||||
qDebug() << "[FileLaunchAction::lauchFileSync] launchAppWithDBus sucess name:" << fileInfo->displayName();
|
||||
//fix bug#143664, use launchAppWithDBus not show in recent issue
|
||||
RecentVFSManager::getInstance()->insert(fileInfo.get()->uri(), fileInfo.get()->mimeType(), fileInfo.get()->displayName(), g_app_info_get_name(m_app_info));
|
||||
return;
|
||||
|
@ -248,6 +249,7 @@ void pid_callback(GDesktopAppInfo *appinfo, GPid pid, gpointer user_data) {
|
|||
|
||||
void FileLaunchAction::lauchFileAsync(bool forceWithArg, bool skipDialog)
|
||||
{
|
||||
m_force_with_arg = forceWithArg;
|
||||
if(checkAppDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
@ -395,7 +397,7 @@ void FileLaunchAction::lauchFileAsync(bool forceWithArg, bool skipDialog)
|
|||
#endif
|
||||
|
||||
if (launchAppWithDBus()) {
|
||||
qDebug() << "[FileLaunchAction::lauchFileAsync] launchAppWithDBus success name:" << fileInfo->displayName();
|
||||
qDebug() << "[FileLaunchAction::lauchFileAsync] launchAppWithDBus sucess name:" << fileInfo->displayName();
|
||||
//fix bug#143664, use launchAppWithDBus not show in recent issue
|
||||
RecentVFSManager::getInstance()->insert(fileInfo.get()->uri(), fileInfo.get()->mimeType(), fileInfo.get()->displayName(), g_app_info_get_name(m_app_info));
|
||||
return;
|
||||
|
@ -467,6 +469,7 @@ void FileLaunchAction::lauchFileAsync(bool forceWithArg, bool skipDialog)
|
|||
|
||||
void FileLaunchAction::lauchFilesAsync(const QStringList files, bool forceWithArg, bool skipDialog)
|
||||
{
|
||||
m_force_with_arg = forceWithArg;
|
||||
if(files.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -552,8 +555,7 @@ void FileLaunchAction::lauchFilesAsync(const QStringList files, bool forceWithAr
|
|||
}
|
||||
else
|
||||
QMessageBox::critical(nullptr, tr("Open Failed"),
|
||||
tr("Can not open %1, Please confirm you have the right authority.").arg(m_uri),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
|
||||
tr("Can not open %1, Please confirm you have the right authority.").arg(m_uri));
|
||||
}
|
||||
else if (fileInfo->isDesktopFile() && GlobalSettings::getInstance()->getProjectName() != V10_SP1_EDU)
|
||||
{
|
||||
|
@ -592,7 +594,7 @@ void FileLaunchAction::lauchFilesAsync(const QStringList files, bool forceWithAr
|
|||
}
|
||||
|
||||
if (launchAppWithDBus()) {
|
||||
qDebug() << "[FileLaunchAction::lauchFilesAsync] launchAppWithDBus success name:" << fileInfo->displayName();
|
||||
qDebug() << "[FileLaunchAction::lauchFilesAsync] launchAppWithDBus sucess name:" << fileInfo->displayName();
|
||||
//fix bug#143664, use launchAppWithDBus not show in recent issue
|
||||
RecentVFSManager::getInstance()->insert(fileInfo.get()->uri(), fileInfo.get()->mimeType(), fileInfo.get()->displayName(), g_app_info_get_name(m_app_info));
|
||||
return;
|
||||
|
@ -707,11 +709,10 @@ void FileLaunchAction::preCheck()
|
|||
|
||||
bool FileLaunchAction::launchAppWithDBus()
|
||||
{
|
||||
#ifdef KYLIN_COMMON
|
||||
//mavis不通过session而通过AppMgr
|
||||
bool mavis = (QString::compare("mavis", QString::fromStdString(KDKGetOSRelease("SUB_PROJECT_CODENAME")), Qt::CaseInsensitive) == 0);
|
||||
|
||||
if (isDesktopFileAction()) {
|
||||
if (isDesktopFileAction() && !m_force_with_arg) {
|
||||
bool intel = (QString::compare(V10_SP1_EDU, QString::fromStdString(KDKGetPrjCodeName()), Qt::CaseInsensitive) == 0);
|
||||
if (intel && mavis) {
|
||||
return launchAppWithAppMgr();
|
||||
|
@ -733,7 +734,6 @@ bool FileLaunchAction::launchAppWithDBus()
|
|||
return launchDefaultAppWithUrl();
|
||||
}
|
||||
}
|
||||
#endif // KYLIN_COMMON
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -779,7 +779,7 @@ bool FileLaunchAction::launchDefaultAppWithUrl()
|
|||
QString uri = fileInfo->uri();
|
||||
QUrl url = uri;
|
||||
|
||||
if (G_IS_DESKTOP_APP_INFO(m_app_info)) {
|
||||
if (G_IS_DESKTOP_APP_INFO(m_app_info) && false) {
|
||||
auto desktop_app_info = G_DESKTOP_APP_INFO(m_app_info);
|
||||
QString desktopFile = g_desktop_app_info_get_filename(desktop_app_info);
|
||||
|
||||
|
@ -793,7 +793,7 @@ bool FileLaunchAction::launchDefaultAppWithUrl()
|
|||
return true;
|
||||
}
|
||||
qDebug() << "[FileLaunchAction::LaunchAppWithArguments] failed, uri:" << uri;
|
||||
} else {
|
||||
} else if (G_IS_DESKTOP_APP_INFO(m_app_info)) {
|
||||
QDBusReply<bool> result = session.call("LaunchDefaultAppWithUrl", url.toString());
|
||||
qDebug() << "[FileLaunchAction::LaunchDefaultAppWithUrl] uri:" << url.toString();
|
||||
|
||||
|
@ -876,7 +876,6 @@ bool FileLaunchAction::launchAppWithSession()
|
|||
|
||||
bool FileLaunchAction::checkAppDisabled()
|
||||
{
|
||||
#ifdef KYLIN_COMMON
|
||||
bool intel = (QString::compare(V10_SP1_EDU, QString::fromStdString(KDKGetPrjCodeName()), Qt::CaseInsensitive) == 0);
|
||||
if (intel) {
|
||||
preCheck();
|
||||
|
@ -887,14 +886,12 @@ bool FileLaunchAction::checkAppDisabled()
|
|||
return true;
|
||||
}
|
||||
}
|
||||
#endif // KYLIN_COMMON
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool launchAppWithArguments(QString desktopFile, QStringList args)
|
||||
{
|
||||
#ifdef KYLIN_COMMON
|
||||
bool mavis = (QString::compare("mavis", QString::fromStdString(KDKGetOSRelease("SUB_PROJECT_CODENAME")), Qt::CaseInsensitive) == 0);
|
||||
int features = QString::fromStdString(KDKGetOSRelease("PRODUCT_FEATURES")).toInt();
|
||||
if (features == 2 || features == 3 || mavis) {
|
||||
|
@ -912,6 +909,5 @@ bool launchAppWithArguments(QString desktopFile, QStringList args)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
#endif // KYLIN_COMMON
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ std::shared_ptr<FileMetaInfo> FileMetaInfo::dupFromUri(const QString &uri)
|
|||
auto mgr = FileInfoManager::getInstance();
|
||||
auto info = mgr->findFileInfoByUri(uri);
|
||||
if (info) {
|
||||
//fixme: metainfo不安全, 在主线程中可能被修改
|
||||
auto metaInfo = mgr->findFileInfoByUri(uri)->m_meta_info;
|
||||
if (metaInfo) {
|
||||
QMutexLocker l(&(metaInfo->m_mutex));
|
||||
|
@ -112,6 +111,7 @@ FileMetaInfo::FileMetaInfo(FileMetaInfo *other)
|
|||
|
||||
FileMetaInfo::~FileMetaInfo()
|
||||
{
|
||||
QMutexLocker l(&m_mutex);
|
||||
}
|
||||
|
||||
void FileMetaInfo::setMetaInfoInt(const QString &key, int value)
|
||||
|
|
|
@ -121,7 +121,7 @@ retry_create_template:
|
|||
GError *err = nullptr;
|
||||
g_file_copy(wrapGFile(g_file_new_for_uri(FileUtils::urlEncode(m_src_uri).toUtf8())).get()->get(),
|
||||
wrapGFile(g_file_new_for_uri(m_target_uri.toUtf8())).get()->get(),
|
||||
GFileCopyFlags(G_FILE_COPY_TARGET_DEFAULT_PERMS | G_FILE_COPY_NOFOLLOW_SYMLINKS),
|
||||
GFileCopyFlags(G_FILE_COPY_NOFOLLOW_SYMLINKS),
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
|
@ -199,7 +199,7 @@ retry_create_template:
|
|||
if (path) {
|
||||
operationStartSnyc();
|
||||
QProcess p;
|
||||
p.start(QString("/usr/bin/sync -f '%1'").arg(path));
|
||||
p.start(QString("sync -f '%1'").arg(path));
|
||||
p.waitForFinished(-1);
|
||||
g_free(path);
|
||||
}
|
||||
|
|
|
@ -1,516 +0,0 @@
|
|||
/*
|
||||
* Peony-Qt's Library
|
||||
*
|
||||
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: ZhuoAn Li <lizhuoan@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "file-batch-rename-operation.h"
|
||||
#include "file-operation-manager.h"
|
||||
#include "file-utils.h"
|
||||
#include "file-info.h"
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
#include <glib/gprintf.h>
|
||||
#include <global-settings.h>
|
||||
#include <QUrl>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QFileInfo>
|
||||
|
||||
static QString set_desktop_name (QString file, QString& name, GError** error);
|
||||
|
||||
using namespace Peony;
|
||||
|
||||
FileBatchRenameOperation::FileBatchRenameOperation(QStringList uris, QString newName)
|
||||
{
|
||||
m_uris = uris;
|
||||
m_new_name = newName;
|
||||
|
||||
QString destUri = FileUtils::getParentUri(FileUtils::urlEncode(uris.first()));
|
||||
QStringList destUris;
|
||||
if (destUri != nullptr) {
|
||||
for (QString uri : uris) {
|
||||
destUri = FileUtils::urlEncode(FileUtils::urlDecode(uri) + "/" + m_new_name);
|
||||
m_old_names.append(FileUtils::getFileDisplayName(uri));
|
||||
destUris.append(destUri);
|
||||
}
|
||||
} else {
|
||||
qDebug() << "rename operation get dest uri error";
|
||||
}
|
||||
|
||||
m_info = std::make_shared<FileOperationInfo>(uris, destUris, FileOperationInfo::BatchRename);
|
||||
}
|
||||
|
||||
FileBatchRenameOperation::~FileBatchRenameOperation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FileBatchRenameOperation::run()
|
||||
{
|
||||
QString destUri;
|
||||
Q_EMIT operationStarted();
|
||||
|
||||
if (m_new_name == "/" || m_new_name == "." || !nameIsValid(m_new_name)) {
|
||||
FileOperationError except;
|
||||
except.srcUri = m_uris.first();
|
||||
except.errorType = ET_GIO;
|
||||
except.op = FileOpRename;
|
||||
except.dlgType = ED_WARNING;
|
||||
except.title = tr("File Rename error");
|
||||
except.errorStr = tr("Invalid file name %1%2%3 .").arg("\“").arg(m_new_name).arg("\”");
|
||||
|
||||
Q_EMIT errored(except);
|
||||
|
||||
Q_EMIT operationFinished();
|
||||
return;
|
||||
} else if (m_new_name.startsWith(".")) {
|
||||
auto showHidden = GlobalSettings::getInstance()->getValue(SHOW_HIDDEN_PREFERENCE).toBool();
|
||||
if (! showHidden)
|
||||
{
|
||||
FileOperationError except;
|
||||
except.srcUri = m_uris.first();
|
||||
except.errorType = ET_GIO;
|
||||
except.op = FileOpRenameToHideFile;
|
||||
except.dlgType = ED_WARNING;
|
||||
except.title = tr("File Rename warning");
|
||||
except.errorStr = tr("Are you sure to hidden these files?");
|
||||
|
||||
Q_EMIT errored(except);
|
||||
|
||||
//fix bug#161394, support cancel rename operation
|
||||
if (except.respCode == Cancel) {
|
||||
cancel();
|
||||
setHasError(true);
|
||||
//未做重命名操作,恢复之前的目标文件,仍然选中原来的文件
|
||||
getOperationInfo().get()->m_dest_dir_uri = getOperationInfo().get()->sources().first();
|
||||
Q_EMIT operationFinished();
|
||||
return;
|
||||
}else{
|
||||
//fix bug#174512, can not hide file immediately
|
||||
qDebug() << "Q_EMIT updateHiddenFile:"<<m_new_name;
|
||||
Q_EMIT GlobalSettings::getInstance()->updateHiddenFile(m_new_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_total_size = m_uris.count();
|
||||
m_current_offset = 0;
|
||||
for (auto uri : m_uris) {
|
||||
if (isCancelled())
|
||||
break;
|
||||
Q_EMIT operationPreparedOne (uri, 0);
|
||||
}
|
||||
|
||||
for (QString uri :m_uris) {
|
||||
if (isCancelled())
|
||||
break;
|
||||
OperatorThreadPause();
|
||||
QString oldName = FileUtils::getFileDisplayName(uri);
|
||||
QString newName = m_new_name;
|
||||
auto fileIconName = FileUtilsPrivate::getFileIconName(FileUtils::urlEncode(uri));
|
||||
std::shared_ptr<FileInfo> fileinfo = FileInfo::fromUri(uri);
|
||||
if(fileinfo && !fileinfo->isDir()){
|
||||
// bool showFileExtension = Peony::GlobalSettings::getInstance()->isExist(SHOW_FILE_EXTENSION)?
|
||||
// Peony::GlobalSettings::getInstance()->getValue(SHOW_FILE_EXTENSION).toBool():true;
|
||||
QString oldSuffix = getFileExtensionOfFile(oldName);
|
||||
QString newSuffix = getFileExtensionOfFile(newName);
|
||||
if (newSuffix.isEmpty()) {
|
||||
newName = newName.append(".").append(oldSuffix);
|
||||
} else if ((oldSuffix != newSuffix) && !oldSuffix.isEmpty()) {
|
||||
newName = newName.replace(newSuffix, oldSuffix);
|
||||
}
|
||||
} else if (fileinfo->isDir()) {
|
||||
QString newSuffix = getFileExtensionOfFile(newName);
|
||||
if (!newSuffix.isEmpty()) {
|
||||
newName.chop(newSuffix.length() + 1);
|
||||
}
|
||||
}
|
||||
auto file = wrapGFile(g_file_new_for_uri(FileUtils::urlEncode(uri).toUtf8().constData()));
|
||||
auto info = wrapGFileInfo(g_file_query_info(file.get()->get(), "*",
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
getCancellable().get()->get(),
|
||||
nullptr));
|
||||
|
||||
bool is_local_desktop_file = false;
|
||||
QUrl url = uri;
|
||||
QString oldDesktopName = "";
|
||||
//change the content of .desktop file;
|
||||
if (url.isLocalFile() && uri.endsWith(".desktop")) {
|
||||
GDesktopAppInfo *desktop_info = g_desktop_app_info_new_from_filename(url.path().toUtf8().constData());
|
||||
if (G_IS_DESKTOP_APP_INFO(desktop_info)) {
|
||||
bool is_executable = g_file_test (url.path().toUtf8().constData(), G_FILE_TEST_IS_EXECUTABLE);
|
||||
is_local_desktop_file = is_executable;
|
||||
if (is_executable) {
|
||||
g_autoptr (GError) error = nullptr;
|
||||
oldDesktopName = set_desktop_name (url.path (), newName, &error);
|
||||
if (error) {
|
||||
qDebug() << "set_desktop_name error code: " << error->code << " msg:" << error->message;
|
||||
}
|
||||
|
||||
//set attributes again.
|
||||
g_file_set_attributes_from_info(file.get()->get(), info.get()->get(), G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, &error);
|
||||
if (error) {
|
||||
qDebug() << "g_file_set_attributes_from_info error code: " << error->code << " msg: " << error->message;
|
||||
}
|
||||
}
|
||||
g_object_unref(desktop_info);
|
||||
}
|
||||
}
|
||||
|
||||
QString targetName = newName;
|
||||
if (is_local_desktop_file) {
|
||||
targetName = newName+".desktop";
|
||||
}
|
||||
|
||||
auto parent = FileUtils::getFileParent(file);
|
||||
auto newFile = FileUtils::resolveRelativePath(parent, targetName);
|
||||
while (FileUtils::isFileExsit(g_file_get_uri(newFile.get()->get()))) {
|
||||
QString fileUri = handleDuplicate(FileUtils::getFileUri(newFile));
|
||||
newName = FileUtils::getUriBaseName(fileUri);
|
||||
newFile = FileUtils::resolveRelativePath(parent, newName);
|
||||
getOperationInfo().get()->m_dest_dir_uri = FileUtils::getFileUri(newFile);
|
||||
}
|
||||
// getOperationInfo().get()->m_dest_dir_uri = FileUtils::getFileUri(newFile);
|
||||
m_new_names.append(newName);
|
||||
if (is_local_desktop_file) {
|
||||
GError *err = nullptr;
|
||||
g_file_move(file.get()->get(),
|
||||
newFile.get()->get(),
|
||||
G_FILE_COPY_ALL_METADATA,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&err);
|
||||
if (err) {
|
||||
qDebug()<<err->message;
|
||||
FileOperationError except;
|
||||
except.srcUri = uri;
|
||||
except.destDirUri = FileUtils::getFileUri(newFile);
|
||||
except.isCritical = true;
|
||||
except.op = FileOpRename;
|
||||
except.title = tr("Rename file error");
|
||||
except.errorType = ET_GIO;
|
||||
except.dlgType = ED_WARNING;
|
||||
except.errorCode = err->code;
|
||||
except.errorStr = err->message;
|
||||
|
||||
errored (except);
|
||||
|
||||
// fallback
|
||||
g_autoptr (GError) error = nullptr;
|
||||
set_desktop_name (url.path (), oldDesktopName, &error);
|
||||
if (error) {
|
||||
qDebug() << "fallback error: " << error->code << " msg: " << error->message;
|
||||
}
|
||||
|
||||
g_file_set_attributes_from_info(file.get()->get(), info.get()->get(), G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, &error);
|
||||
if (error) {
|
||||
qDebug() << "g_file_set_attributes_from_info error code: " << error->code << " msg: " << error->message;
|
||||
}
|
||||
|
||||
cancel ();
|
||||
}
|
||||
} else {
|
||||
retry:
|
||||
GError* err = nullptr;
|
||||
g_autofree char* newName = g_file_get_basename(newFile.get()->get());
|
||||
|
||||
g_file_set_display_name(file.get()->get(), newName, getCancellable().get()->get(), &err);
|
||||
|
||||
if (err) {
|
||||
FileOperationError except;
|
||||
except.srcUri = uri;
|
||||
except.errorType = ET_GIO;
|
||||
except.op = FileOpRename;
|
||||
except.dlgType = ED_WARNING;
|
||||
except.title = tr("Rename file error");
|
||||
except.destDirUri = FileUtils::getFileUri(newFile);
|
||||
qDebug() << "rename: " << g_file_get_uri(newFile.get()->get());
|
||||
except.dlgType = g_error_matches(err, g_io_error_quark(), G_IO_ERROR_FILENAME_TOO_LONG)? ED_RENAME: ED_WARNING;
|
||||
except.errorCode = err->code;
|
||||
except.errorStr = err->message;
|
||||
qDebug() << err->message;
|
||||
|
||||
if (G_IO_ERROR_EXISTS == err->code) {
|
||||
ExceptionResponse resp = prehandle(err);
|
||||
if (Other == resp) {
|
||||
except.dlgType = ED_CONFLICT;
|
||||
except.errorCode = G_IO_ERROR_EXISTS;
|
||||
}
|
||||
Q_EMIT errored(except);
|
||||
resp = except.respCode;
|
||||
switch (resp) {
|
||||
case BackupAll:
|
||||
case BackupOne:
|
||||
case OverWriteAll:
|
||||
break;
|
||||
case OverWriteOne: {
|
||||
// 避免重名替换
|
||||
//fix bug#143435, use m_src_uris is null cause crash issue
|
||||
if (FileUtils::isSamePath(except.srcUri, except.destDirUri)
|
||||
|| !FileUtils::isFileExsit(except.srcUri)
|
||||
|| !FileUtils::isFileExsit(except.destDirUri)) {
|
||||
break;
|
||||
}
|
||||
g_file_delete(newFile.get()->get(), nullptr, nullptr);
|
||||
goto retry;
|
||||
}
|
||||
case IgnoreAll:
|
||||
case IgnoreOne:
|
||||
break;
|
||||
case Cancel:
|
||||
cancel();
|
||||
goto cancel;
|
||||
case RenameOne: {
|
||||
m_new_name = except.respValue.value("newName").toString();
|
||||
newFile = FileUtils::resolveRelativePath(parent, m_new_name);
|
||||
getOperationInfo().get()->m_dest_dir_uri = FileUtils::getFileUri(newFile);
|
||||
setHasError(false);
|
||||
goto retry;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (!G_IO_ERROR_CANCELLED == err->code) {
|
||||
Q_EMIT errored(except);
|
||||
}
|
||||
switch (except.respCode) {
|
||||
case Retry:
|
||||
goto retry;
|
||||
case Cancel:
|
||||
cancel();
|
||||
break;
|
||||
case RenameOne: {
|
||||
m_new_name = except.respValue.value("newName").toString();
|
||||
newFile = FileUtils::resolveRelativePath(parent, m_new_name);
|
||||
getOperationInfo().get()->m_dest_dir_uri = FileUtils::getFileUri(newFile);
|
||||
setHasError(false);
|
||||
goto retry;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_error_free(err);
|
||||
}
|
||||
}
|
||||
|
||||
getOperationInfo().get()->m_dest_dir_uri = FileUtils::getFileUri(newFile);
|
||||
cancel:
|
||||
if (!isCancelled()) {
|
||||
auto string = g_file_get_uri(newFile.get()->get());
|
||||
destUri = string;
|
||||
if (string)
|
||||
g_free(string);
|
||||
m_info->m_node_map.insert(uri, destUri);
|
||||
m_info->m_newname = newName;
|
||||
m_info->m_oldname = oldName;
|
||||
}
|
||||
|
||||
fileSync(uri, destUri);
|
||||
m_current_offset += 1;
|
||||
Q_EMIT FileProgressCallback(uri, destUri, fileIconName, m_current_offset, m_total_size);
|
||||
}
|
||||
m_info->m_newnames = m_new_names;
|
||||
m_info->m_oldnames = m_old_names;
|
||||
if (isCancelled()) {
|
||||
Q_EMIT operationStartRollbacked();
|
||||
rollback(m_info);
|
||||
}
|
||||
|
||||
Q_EMIT operationFinished();
|
||||
//notifyFileWatcherOperationFinished();
|
||||
}
|
||||
|
||||
void FileBatchRenameOperation::rollback(std::shared_ptr<FileOperationInfo> info)
|
||||
{
|
||||
m_info->m_src_uris = info->m_node_map.keys();
|
||||
auto nodes = info->m_node_map;
|
||||
|
||||
for (auto srcUri : nodes.keys()) {
|
||||
auto destUri = nodes.value(srcUri);
|
||||
g_autoptr (GFile) srcFile = g_file_new_for_uri(srcUri.toUtf8().constData());
|
||||
g_autoptr (GFile) destFile = g_file_new_for_uri(destUri.toUtf8().constData());
|
||||
auto name = g_file_get_basename(srcFile);
|
||||
|
||||
g_file_set_display_name(destFile, name, 0, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QString FileBatchRenameOperation::getFileExtensionOfFile(const QString& file)
|
||||
{
|
||||
/* 一些常见扩展名处理,特殊情况以后待完善 */
|
||||
QFileInfo qFileInfo(file);
|
||||
QString suffix = qFileInfo.suffix();
|
||||
QString fileBaseName = qFileInfo.fileName().left(qFileInfo.fileName().length() - suffix.length() - 1);
|
||||
if (fileBaseName.isEmpty()){
|
||||
return QString();
|
||||
}
|
||||
else if(fileBaseName.endsWith(".tar")){
|
||||
return QString("tar").append(".").append(suffix);
|
||||
}
|
||||
else if(fileBaseName.endsWith(".7z")){
|
||||
return QString("7z").append(".").append(suffix);
|
||||
}
|
||||
|
||||
return suffix;
|
||||
}
|
||||
|
||||
ExceptionResponse FileBatchRenameOperation::prehandle(GError *err)
|
||||
{
|
||||
if (err && G_IO_ERROR_EXISTS == err->code) {
|
||||
return m_apply_all;
|
||||
}
|
||||
|
||||
return Other;
|
||||
}
|
||||
|
||||
QString FileBatchRenameOperation::handleDuplicate(QString uri)
|
||||
{
|
||||
QString handledName = nullptr;
|
||||
QString name = QUrl(uri).toDisplayString().split("/").last();
|
||||
|
||||
QRegExp regExpNum("\\(\\d+\\)");
|
||||
QRegExp regExp (QString("\\(\\d+\\)(\\.[0-9a-zA-Z\\.]+|)$"));
|
||||
|
||||
QString dupReg = nullptr;
|
||||
|
||||
if (name.contains(regExp)) {
|
||||
int num = 0;
|
||||
QString numStr = "";
|
||||
|
||||
QString ext = regExp.cap(0);
|
||||
if (ext.contains(regExpNum)) {
|
||||
numStr = regExpNum.cap(0);
|
||||
}
|
||||
|
||||
numStr.remove(0, 1);
|
||||
numStr.chop(1);
|
||||
num = numStr.toInt();
|
||||
++num;
|
||||
handledName = name.replace(regExp, ext.replace(regExpNum, QString("(%1)").arg(num)));
|
||||
} else {
|
||||
if (name.contains(".")) {
|
||||
auto list = name.split(".");
|
||||
if (list.count() <= 1) {
|
||||
handledName = name + QString("(1)");
|
||||
} else {
|
||||
int pos = list.count() - 1;
|
||||
if (list.last() == "gz"
|
||||
|| list.last() == "xz"
|
||||
|| list.last() == "Z"
|
||||
|| list.last() == "sit"
|
||||
|| list.last() == "bz"
|
||||
|| list.last() == "bz2") {
|
||||
--pos;
|
||||
}
|
||||
if (pos < 0) {
|
||||
pos = 0;
|
||||
}
|
||||
auto tmp = list;
|
||||
QStringList suffixList;
|
||||
for (int i = 0; i < list.count() - pos; i++) {
|
||||
suffixList.prepend(tmp.takeLast());
|
||||
}
|
||||
auto suffix = suffixList.join(".");
|
||||
|
||||
auto basename = tmp.join(".");
|
||||
name = basename + QString("(1)") + "." + suffix;
|
||||
if (name.endsWith(".")) {
|
||||
name.chop(1);
|
||||
}
|
||||
handledName = name;
|
||||
}
|
||||
} else {
|
||||
handledName = name + QString("(1)");
|
||||
}
|
||||
}
|
||||
|
||||
return handledName;
|
||||
}
|
||||
|
||||
static QString set_desktop_name (QString file, QString& name, GError** error)
|
||||
{
|
||||
QString oldName = "";
|
||||
GKeyFile *keyFile = g_key_file_new();
|
||||
g_key_file_load_from_file(keyFile, file.toUtf8().constData(), G_KEY_FILE_KEEP_COMMENTS, nullptr);
|
||||
QString locale_name = QLocale::system().name();
|
||||
QString local_name_key = QString("Name[%1]").arg(locale_name);
|
||||
if (g_key_file_has_key(keyFile, G_KEY_FILE_DESKTOP_GROUP, local_name_key.toUtf8().constData(), nullptr)) {
|
||||
oldName = g_key_file_get_string (keyFile, G_KEY_FILE_DESKTOP_GROUP, local_name_key.toUtf8().constData(), nullptr);
|
||||
g_key_file_set_value(keyFile, G_KEY_FILE_DESKTOP_GROUP, local_name_key.toUtf8().constData(), name.toUtf8().constData());
|
||||
} else {
|
||||
g_key_file_set_value(keyFile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, name.toUtf8().constData());
|
||||
}
|
||||
|
||||
g_key_file_save_to_file(keyFile, file.toUtf8().constData(), error);
|
||||
|
||||
if (keyFile) g_key_file_free(keyFile);
|
||||
|
||||
return oldName;
|
||||
}
|
||||
|
||||
FileBatchRenameInternalOperation::FileBatchRenameInternalOperation(std::shared_ptr<FileOperationInfo> info)
|
||||
{
|
||||
m_info = info;
|
||||
m_info->m_src_uris = m_info->m_node_map.keys();
|
||||
}
|
||||
|
||||
void FileBatchRenameInternalOperation::run()
|
||||
{
|
||||
Q_EMIT operationStarted();
|
||||
|
||||
auto nodes = m_info->m_node_map;
|
||||
|
||||
for (auto uri : nodes) {
|
||||
Q_EMIT operationPreparedOne(uri, 1);
|
||||
}
|
||||
Q_EMIT operationPrepared();
|
||||
|
||||
for (auto srcUri : nodes.keys()) {
|
||||
auto destUri = nodes.value(srcUri);
|
||||
g_autoptr (GFile) srcFile = g_file_new_for_uri(srcUri.toUtf8().constData());
|
||||
g_autoptr (GFile) destFile = g_file_new_for_uri(destUri.toUtf8().constData());
|
||||
|
||||
// FIXME: 桌面配置文件undo不生效问题
|
||||
// bool is_local_desktop_file = false;
|
||||
// if (srcUri.startsWith("file:///") && srcUri.endsWith(".desktop")) {
|
||||
// g_autoptr (GFile) srcFile = g_file_new_for_uri(srcUri.toUtf8().constData());
|
||||
// g_autofree gchar* path = g_file_get_path(srcFile);
|
||||
// g_autoptr (GDesktopAppInfo) app_info = g_desktop_app_info_new_from_filename(path);
|
||||
// if (app_info) {
|
||||
// is_local_desktop_file = true;
|
||||
// QUrl destUrl = destUri;
|
||||
// auto destName = destUrl.fileName();
|
||||
// destName.remove(".desktop");
|
||||
// set_desktop_name(path, destName, 0);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!is_local_desktop_file) {
|
||||
g_file_move(srcFile, destFile, GFileCopyFlags(G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_ALL_METADATA), 0, 0, 0, 0);
|
||||
// }
|
||||
|
||||
Q_EMIT operationProgressedOne(srcUri, destUri, 1);
|
||||
}
|
||||
|
||||
Q_EMIT operationFinished();
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Peony-Qt's Library
|
||||
*
|
||||
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: ZhuoAn Li <lizhuoan@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FILEBATCHRENAMEOPERATION_H
|
||||
#define FILEBATCHRENAMEOPERATION_H
|
||||
|
||||
#include "peony-core_global.h"
|
||||
#include "file-operation.h"
|
||||
#include <QMutex>
|
||||
|
||||
namespace Peony {
|
||||
|
||||
class PEONYCORESHARED_EXPORT FileBatchRenameOperation : public FileOperation
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FileBatchRenameOperation(QStringList uris, QString newName);
|
||||
~FileBatchRenameOperation();
|
||||
|
||||
void run() override;
|
||||
|
||||
std::shared_ptr<FileOperationInfo> getOperationInfo() override {
|
||||
return m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
GFileCopyFlags m_default_copy_flag = GFileCopyFlags(G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_ALL_METADATA);
|
||||
QStringList m_uris ;
|
||||
QString m_new_name = nullptr;
|
||||
QStringList m_old_names;
|
||||
QStringList m_new_names;
|
||||
std::shared_ptr<FileOperationInfo> m_info = nullptr;
|
||||
ExceptionResponse m_apply_all = Other;
|
||||
|
||||
goffset m_current_offset = 0;
|
||||
goffset m_total_size = 0 ;
|
||||
|
||||
QString getFileExtensionOfFile(const QString& file); /* 获取文件的文件扩展名 */
|
||||
ExceptionResponse prehandle(GError *err);
|
||||
QString handleDuplicate(const QString uri);
|
||||
void rollback(std::shared_ptr<FileOperationInfo> info);
|
||||
|
||||
};
|
||||
|
||||
class FileBatchRenameInternalOperation : public FileOperation
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FileBatchRenameInternalOperation(std::shared_ptr<FileOperationInfo> info);
|
||||
|
||||
void run() override;
|
||||
|
||||
std::shared_ptr<FileOperationInfo> getOperationInfo() override {
|
||||
return m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<FileOperationInfo> m_info = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // FILEBATCHRENAMEOPERATION_H
|
|
@ -25,18 +25,14 @@
|
|||
#include "file-node.h"
|
||||
#include "file-enumerator.h"
|
||||
#include "file-info.h"
|
||||
|
||||
#include "file-utils.h"
|
||||
#include "file-label-model.h"
|
||||
#include "file-operation-manager.h"
|
||||
#include "sound-effect.h"
|
||||
#include "clipboard-utils.h"
|
||||
#include <QProcess>
|
||||
#include <QStorageInfo>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
#include <QDebug>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include "file-copy.h"
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
|
||||
|
@ -57,12 +53,6 @@ FileCopyOperation::FileCopyOperation(QStringList sourceUris, QString destDirUri,
|
|||
|
||||
QUrl destDirUrl = Peony::FileUtils::urlEncode(destDirUri);
|
||||
QUrl firstSrcUrl = Peony::FileUtils::urlEncode(sourceUris.first());
|
||||
if("label" == firstSrcUrl.scheme())
|
||||
{
|
||||
QString scheme = firstSrcUrl.path().section("?schema=",-1,-1);
|
||||
QString path = firstSrcUrl.path().section("?schema=", 0, 0).section("/",2,-1);
|
||||
firstSrcUrl = QString(scheme).append(":///").append(path);
|
||||
}
|
||||
|
||||
if (destDirUrl.isParentOf(firstSrcUrl)) {
|
||||
if (1 == firstSrcUrl.path().split("/").count() - destDirUrl.path().split("/").count()) {
|
||||
|
@ -78,24 +68,12 @@ FileCopyOperation::FileCopyOperation(QStringList sourceUris, QString destDirUri,
|
|||
}
|
||||
}*/
|
||||
|
||||
QStringList srcUris;
|
||||
for(auto &uri : sourceUris){
|
||||
if(uri.startsWith("label://"))
|
||||
{
|
||||
QUrl url(uri);
|
||||
QString scheme = url.path().section("?schema=",-1,-1);
|
||||
QString path = url.path().section("?schema=", 0, 0).section("/",2,-1);
|
||||
uri = QString(scheme).append(":///").append(path);
|
||||
}
|
||||
srcUris.append(uri);
|
||||
}
|
||||
|
||||
m_conflict_files.clear();
|
||||
m_source_uris = srcUris;
|
||||
m_source_uris = sourceUris;
|
||||
m_dest_dir_uri = FileUtils::urlDecode(destDirUri);
|
||||
m_reporter = new FileNodeReporter;
|
||||
connect(m_reporter, &FileNodeReporter::nodeFound, this, &FileOperation::operationPreparedOne);
|
||||
m_info = std::make_shared<FileOperationInfo>(srcUris, destDirUri, FileOperationInfo::Copy);
|
||||
m_info = std::make_shared<FileOperationInfo>(sourceUris, destDirUri, FileOperationInfo::Copy);
|
||||
}
|
||||
|
||||
FileCopyOperation::~FileCopyOperation()
|
||||
|
@ -106,6 +84,7 @@ FileCopyOperation::~FileCopyOperation()
|
|||
|
||||
ExceptionResponse FileCopyOperation::prehandle(GError *err)
|
||||
{
|
||||
setHasError(true);
|
||||
// SoundEffect::getInstance()->copyOrMoveFailedMusic();
|
||||
|
||||
switch (err->code) {
|
||||
|
@ -148,7 +127,7 @@ void FileCopyOperation::progress_callback(goffset current_num_bytes,
|
|||
|
||||
QUrl url(Peony::FileUtils::urlEncode(p_this->m_current_src_uri));
|
||||
auto currnet = p_this->m_current_offset + current_num_bytes;
|
||||
auto total = p_this->m_total_size;
|
||||
auto total = p_this->m_total_szie;
|
||||
auto fileIconName = FileUtilsPrivate::getFileIconName(p_this->m_current_src_uri);
|
||||
auto destFileName = FileUtils::isFileDirectory(p_this->m_current_dest_dir_uri) ?
|
||||
p_this->m_current_dest_dir_uri + "/" + url.fileName() : p_this->m_current_dest_dir_uri;
|
||||
|
@ -162,7 +141,6 @@ void FileCopyOperation::copyRecursively(FileNode *node)
|
|||
|
||||
node->setState(FileNode::Handling);
|
||||
QString destName = "";
|
||||
QString destDir = m_dest_dir_uri;
|
||||
|
||||
fallback_retry:
|
||||
QString destFileUri = node->resolveDestFileUri(m_dest_dir_uri);
|
||||
|
@ -176,17 +154,6 @@ fallback_retry:
|
|||
|
||||
m_current_src_uri = node->uri();
|
||||
m_current_dest_dir_uri = destFileUri;
|
||||
g_autoptr(GFileInfo) srcFileInfo = nullptr;
|
||||
srcFileInfo = g_file_query_info(srcFile.get()->get()
|
||||
, G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET
|
||||
, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, nullptr);
|
||||
if (G_FILE_TYPE_SYMBOLIC_LINK == g_file_info_get_file_type(srcFileInfo)) {
|
||||
if (!copyLinkedFile(node, srcFileInfo, destFile)) {
|
||||
goto fallback_retry;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//fix bug#163573, can not copy readonly folder issue
|
||||
gboolean readonly_source_fs = FALSE;
|
||||
|
@ -241,15 +208,6 @@ fallback_retry:
|
|||
break;
|
||||
}
|
||||
case G_IO_ERROR_FILENAME_TOO_LONG: {
|
||||
if (node->destBaseName().length() > 255 &&
|
||||
m_dest_dir_uri.startsWith(QString("file://" + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/扩展"))) {
|
||||
QString msg = tr("The file name exceeds the limit");
|
||||
Q_EMIT operationInfoMsgBox(msg);
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
except.dlgType = ED_RENAME;
|
||||
Q_EMIT errored(except);
|
||||
auto typeData = except.respCode;
|
||||
|
@ -267,58 +225,23 @@ fallback_retry:
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else if (handle_type == SaveOne || handle_type == SaveAll) {
|
||||
if (node->destBaseName().length() > 255 && !m_is_long_name_error_msg_show &&
|
||||
m_dest_dir_uri.startsWith(QString("file://" + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/扩展"))) {
|
||||
QString msg = tr("The file name exceeds the limit");
|
||||
Q_EMIT operationInfoMsgBox(msg);
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
m_is_long_name_error_msg_show = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//handle.
|
||||
node->setState(FileNode::Handling);
|
||||
switch (handle_type) {
|
||||
case IgnoreOne: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Unhandled);
|
||||
node->setErrorResponse(IgnoreOne);
|
||||
if (!m_is_udf_warning && m_is_udf_burn_work) {
|
||||
return;
|
||||
}
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case IgnoreAll: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Unhandled);
|
||||
node->setErrorResponse(IgnoreOne);
|
||||
m_prehandle_hash.insert(err->code, IgnoreOne);
|
||||
if (!m_is_udf_warning && m_is_udf_burn_work) {
|
||||
return;
|
||||
}
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case OverWriteOne: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setState(FileNode::Handled);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
if (!m_is_udf_warning && m_is_udf_burn_work) {
|
||||
auto result = udfCopyWarningDialog();
|
||||
if (Cancel == result) {
|
||||
cancel();
|
||||
} else if (IgnoreOne == result || IgnoreAll == result) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// g_file_copy_attributes(srcFile.get()->get(),
|
||||
// destFile.get()->get(),
|
||||
// GFileCopyFlags(flags),
|
||||
|
@ -332,19 +255,9 @@ fallback_retry:
|
|||
break;
|
||||
}
|
||||
case OverWriteAll: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setState(FileNode::Handled);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
m_prehandle_hash.insert(err->code, OverWriteOne);
|
||||
if (!m_is_udf_warning && m_is_udf_burn_work) {
|
||||
m_is_udf_warning = true;
|
||||
auto result = udfCopyWarningDialog();
|
||||
if (Cancel == result) {
|
||||
cancel();
|
||||
} else if (IgnoreOne == result || IgnoreAll == result) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// g_file_copy_attributes(srcFile.get()->get(),
|
||||
// destFile.get()->get(),
|
||||
// GFileCopyFlags(flags),
|
||||
|
@ -357,6 +270,7 @@ fallback_retry:
|
|||
break;
|
||||
}
|
||||
case BackupOne: {
|
||||
node->setState(FileNode::Handled);
|
||||
node->setErrorResponse(BackupOne);
|
||||
// use custom name
|
||||
QString name = "";
|
||||
|
@ -389,6 +303,7 @@ fallback_retry:
|
|||
goto fallback_retry;
|
||||
}
|
||||
case BackupAll: {
|
||||
node->setState(FileNode::Handled);
|
||||
node->setErrorResponse(BackupOne);
|
||||
while (FileUtils::isFileExsit(node->resolveDestFileUri(m_dest_dir_uri))) {
|
||||
handleDuplicate(node);
|
||||
|
@ -411,46 +326,8 @@ fallback_retry:
|
|||
goto fallback_retry;
|
||||
}
|
||||
case RenameOne: {
|
||||
node->setErrorResponse(RenameOne);
|
||||
node->setDestFileName(except.respValue.value("newName").toString());
|
||||
goto fallback_retry;
|
||||
}
|
||||
case TruncateOne: {
|
||||
node->setErrorResponse(TruncateOne);
|
||||
auto respValut = except.respValue.value("cateType").toInt();
|
||||
if (m_cate_type == AllPost) {
|
||||
respValut = Post;
|
||||
} else if (m_cate_type == ALLFront) {
|
||||
respValut = Front;
|
||||
}
|
||||
node->truncateDestFileName(respValut);
|
||||
goto fallback_retry;
|
||||
}
|
||||
case TruncateAll: {
|
||||
node->setErrorResponse(TruncateOne);
|
||||
m_cate_type = except.respValue.value("cateType").toInt();
|
||||
node->truncateDestFileName(m_cate_type);
|
||||
if (Post == m_cate_type) {
|
||||
m_cate_type = AllPost;
|
||||
} else if (Front == m_cate_type) {
|
||||
m_cate_type = ALLFront;
|
||||
}
|
||||
m_prehandle_hash.insert(err->code, TruncateOne);
|
||||
goto fallback_retry;
|
||||
}
|
||||
case SaveOne: {
|
||||
node->setErrorResponse(SaveOne);
|
||||
if (!saveAsOtherPath()) {
|
||||
break;
|
||||
}
|
||||
goto fallback_retry;
|
||||
}
|
||||
case SaveAll: {
|
||||
node->setErrorResponse(SaveOne);
|
||||
m_prehandle_hash.insert(err->code, SaveOne);
|
||||
if (!saveAsOtherPath()) {
|
||||
break;
|
||||
}
|
||||
setHasError(false);
|
||||
goto fallback_retry;
|
||||
}
|
||||
case Cancel: {
|
||||
|
@ -463,31 +340,7 @@ fallback_retry:
|
|||
}
|
||||
} else {
|
||||
node->setState(FileNode::Handled);
|
||||
// if copy sucessed, flush all data
|
||||
g_autoptr(GFile) destFile = g_file_new_for_uri(destFileUri.toUtf8().constData());
|
||||
if (g_file_query_exists(destFile, nullptr)) {
|
||||
// copy file attribute
|
||||
// It is possible that some file systems do not support file attributes
|
||||
g_autoptr(GFile) srcFile = g_file_new_for_uri(srcUri.toUtf8().constData());
|
||||
g_file_copy_attributes(srcFile, destFile, G_FILE_COPY_ALL_METADATA, nullptr, &err);
|
||||
if (nullptr != err) {
|
||||
qWarning() <<destFileUri<<"copy attribute error:" << err->code << " --- " << err->message;
|
||||
g_error_free(err);
|
||||
err = nullptr;
|
||||
}
|
||||
QList<int> labelIds = FileLabelModel::getGlobalModel()->getFileLabelIds(srcUri);
|
||||
for(auto &labelId: labelIds){
|
||||
if(labelId <= 0)
|
||||
continue;
|
||||
FileLabelModel::getGlobalModel()->addLabelToFile(destFileUri, labelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (SaveOne == node->responseType() || SaveAll == node->responseType()) {
|
||||
m_dest_dir_uri = destDir;
|
||||
}
|
||||
|
||||
//assume that make dir finished anyway
|
||||
m_current_offset += node->size();
|
||||
Q_EMIT operationProgressedOne(node->uri(), node->destUri(), node->size());
|
||||
|
@ -497,14 +350,11 @@ fallback_retry:
|
|||
|
||||
//copy folder attributes after copy child, support copy readonly files
|
||||
//related bug#163573
|
||||
if (node->state() == FileNode::Handled || node->responseType() == OverWriteOne || node->responseType() == OverWriteAll) {
|
||||
g_file_copy_attributes(srcFile.get()->get(),
|
||||
destFile.get()->get(),
|
||||
GFileCopyFlags(flags),
|
||||
nullptr,
|
||||
&error);
|
||||
}
|
||||
|
||||
g_file_copy_attributes(srcFile.get()->get(),
|
||||
destFile.get()->get(),
|
||||
GFileCopyFlags(flags),
|
||||
nullptr,
|
||||
&error);
|
||||
if (error) {
|
||||
qDebug() << __func__ << error->code << error->message;
|
||||
}
|
||||
|
@ -519,14 +369,7 @@ fallback_retry:
|
|||
if (src) {
|
||||
srcInfo = g_file_query_info(src, "unix::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, nullptr);
|
||||
}
|
||||
if (SaveOne == node->responseType() || SaveAll == node->responseType()) {
|
||||
GFileWrapperPtr parentPtr = FileUtils::getFileParent(destFile);
|
||||
auto path = g_file_peek_path(parentPtr.get()->get());
|
||||
QDir destFileParentPath(path);
|
||||
if (!destFileParentPath.exists()) {
|
||||
destFileParentPath.mkpath(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (url.isLocalFile() && node->uri().endsWith(".desktop")) {
|
||||
GDesktopAppInfo* desktop_info = g_desktop_app_info_new_from_filename(url.path().toUtf8().constData());
|
||||
if (G_IS_DESKTOP_APP_INFO(desktop_info)) {
|
||||
|
@ -641,15 +484,6 @@ fallback_retry:
|
|||
break;
|
||||
}
|
||||
case G_IO_ERROR_FILENAME_TOO_LONG: {
|
||||
if (node->destBaseName().length() > 255 &&
|
||||
m_dest_dir_uri.startsWith(QString("file://" + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/扩展"))) {
|
||||
QString msg = tr("The file name exceeds the limit");
|
||||
Q_EMIT operationInfoMsgBox(msg);
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
except.dlgType = ED_RENAME;
|
||||
Q_EMIT errored(except);
|
||||
auto typeData = except.respCode;
|
||||
|
@ -664,53 +498,21 @@ fallback_retry:
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else if (handle_type == SaveOne || handle_type == SaveAll) {
|
||||
if (node->destBaseName().length() > 255 && !m_is_long_name_error_msg_show &&
|
||||
m_dest_dir_uri.startsWith(QString("file://" + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/扩展"))) {
|
||||
QString msg = tr("The file name exceeds the limit");
|
||||
Q_EMIT operationInfoMsgBox(msg);
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
m_is_long_name_error_msg_show = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//handle.
|
||||
node->setState(FileNode::Handling);
|
||||
switch (handle_type) {
|
||||
case IgnoreOne: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Unhandled);
|
||||
node->setErrorResponse(IgnoreOne);
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case IgnoreAll: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Unhandled);
|
||||
node->setErrorResponse(IgnoreOne);
|
||||
m_prehandle_hash.insert(err->code, IgnoreOne);
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case OverWriteOne: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Invalid);
|
||||
if (!m_is_udf_warning && m_is_udf_burn_work) {
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
auto result = udfCopyWarningDialog();
|
||||
if (Cancel == result) {
|
||||
cancel();
|
||||
} else if (IgnoreOne == result || IgnoreAll == result) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
FileCopy fileOverWriteOneCopy (node->uri(), destFileUri,
|
||||
(GFileCopyFlags)(m_default_copy_flag | G_FILE_COPY_OVERWRITE),
|
||||
getCancellable().get()->get(),
|
||||
|
@ -722,30 +524,12 @@ fallback_retry:
|
|||
fileCopy.connect(this, &FileOperation::operationCancel, &fileOverWriteOneCopy, &FileCopy::cancel, Qt::DirectConnection);
|
||||
if (m_is_pause) fileOverWriteOneCopy.pause();
|
||||
fileOverWriteOneCopy.run();
|
||||
if (fileCopy.getStatus() == FileCopy::FINISHED) {
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
} else {
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
}
|
||||
node->setState(FileNode::Handled);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
m_is_duplicated_copy = false;
|
||||
break;
|
||||
}
|
||||
case OverWriteAll: {
|
||||
setHasError(true);
|
||||
if (!m_is_udf_warning && m_is_udf_burn_work) {
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
m_prehandle_hash.insert(err->code, OverWriteOne);
|
||||
m_is_udf_warning = true;
|
||||
auto result = udfCopyWarningDialog();
|
||||
if (Cancel == result) {
|
||||
cancel();
|
||||
} else if (IgnoreOne == result || IgnoreAll == result) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
FileCopy fileOverWriteOneCopy (node->uri(), destFileUri,
|
||||
(GFileCopyFlags)(m_default_copy_flag | G_FILE_COPY_OVERWRITE),
|
||||
getCancellable().get()->get(),
|
||||
|
@ -757,18 +541,14 @@ fallback_retry:
|
|||
fileCopy.connect(this, &FileOperation::operationCancel, &fileOverWriteOneCopy, &FileCopy::cancel, Qt::DirectConnection);
|
||||
if (m_is_pause) fileOverWriteOneCopy.pause();
|
||||
fileOverWriteOneCopy.run();
|
||||
if (fileCopy.getStatus() == FileCopy::FINISHED) {
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
} else {
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
}
|
||||
node->setState(FileNode::Handled);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
m_prehandle_hash.insert(err->code, OverWriteOne);
|
||||
m_is_duplicated_copy = false;
|
||||
break;
|
||||
}
|
||||
case BackupOne: {
|
||||
node->setState(FileNode::Handled);
|
||||
node->setErrorResponse(BackupOne);
|
||||
// use custom name
|
||||
QString name = "";
|
||||
|
@ -792,6 +572,7 @@ fallback_retry:
|
|||
goto fallback_retry;
|
||||
}
|
||||
case BackupAll: {
|
||||
node->setState(FileNode::Handled);
|
||||
node->setErrorResponse(BackupOne);
|
||||
while (FileUtils::isFileExsit(node->resolveDestFileUri(m_dest_dir_uri))) {
|
||||
handleDuplicate(node);
|
||||
|
@ -803,46 +584,8 @@ fallback_retry:
|
|||
goto fallback_retry;
|
||||
}
|
||||
case RenameOne: {
|
||||
node->setErrorResponse(RenameOne);
|
||||
node->setDestFileName(except.respValue.value("newName").toString());
|
||||
goto fallback_retry;
|
||||
}
|
||||
case TruncateOne: {
|
||||
node->setErrorResponse(TruncateOne);
|
||||
auto respValut = except.respValue.value("cateType").toInt();
|
||||
if (m_cate_type == AllPost) {
|
||||
respValut = Post;
|
||||
} else if (m_cate_type == ALLFront) {
|
||||
respValut = Front;
|
||||
}
|
||||
node->truncateDestFileName(respValut);
|
||||
goto fallback_retry;
|
||||
}
|
||||
case TruncateAll: {
|
||||
node->setErrorResponse(TruncateOne);
|
||||
m_cate_type = except.respValue.value("cateType").toInt();
|
||||
node->truncateDestFileName(m_cate_type);
|
||||
if (Post == m_cate_type) {
|
||||
m_cate_type = AllPost;
|
||||
} else if (Front == m_cate_type) {
|
||||
m_cate_type = ALLFront;
|
||||
}
|
||||
m_prehandle_hash.insert(err->code, TruncateOne);
|
||||
goto fallback_retry;
|
||||
}
|
||||
case SaveOne: {
|
||||
node->setErrorResponse(SaveOne);
|
||||
if (!saveAsOtherPath()) {
|
||||
break;
|
||||
}
|
||||
goto fallback_retry;
|
||||
}
|
||||
case SaveAll: {
|
||||
node->setErrorResponse(SaveOne);
|
||||
m_prehandle_hash.insert(err->code, SaveOne);
|
||||
if (!saveAsOtherPath()) {
|
||||
break;
|
||||
}
|
||||
setHasError(false);
|
||||
goto fallback_retry;
|
||||
}
|
||||
case Cancel: {
|
||||
|
@ -905,11 +648,9 @@ fallback_retry:
|
|||
}
|
||||
}
|
||||
|
||||
if (SaveOne == node->responseType() || SaveAll == node->responseType()) {
|
||||
m_dest_dir_uri = destDir;
|
||||
}
|
||||
|
||||
m_current_offset += node->size();
|
||||
// fileSync(srcUri, destFileUri);
|
||||
fileSync(srcUri, destFileUri);
|
||||
Q_EMIT operationProgressedOne(node->uri(), node->destUri(), node->size());
|
||||
|
||||
if(srcUri.endsWith(".dsps") && destFileUri.endsWith(".dsps")){
|
||||
|
@ -917,7 +658,6 @@ fallback_retry:
|
|||
m_destUrisOfCopyDspsFiles.append(FileUtils::urlDecode(destFileUri));
|
||||
}
|
||||
}
|
||||
|
||||
destFile.reset();
|
||||
}
|
||||
|
||||
|
@ -995,10 +735,6 @@ void FileCopyOperation::run()
|
|||
m_is_udf_burn_work = true;
|
||||
bool isMountpoint = false;
|
||||
mHelper->judgeSpecialDiscOperation();
|
||||
auto discType = mHelper->getDiscType();
|
||||
if (discType.contains("DVD-RW") || discType.contains("CD-RW")) {
|
||||
Q_EMIT operationWithoutRecording();
|
||||
}
|
||||
g_autoptr(GFile) file = g_file_new_for_uri (m_dest_dir_uri.toUtf8().constData());
|
||||
if (file) {
|
||||
g_autoptr(GFileInfo) fileInfo = g_file_query_info(file, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, nullptr);
|
||||
|
@ -1031,48 +767,8 @@ void FileCopyOperation::run()
|
|||
|
||||
Q_EMIT operationPrepared();
|
||||
|
||||
m_total_size = *total_size;
|
||||
m_total_szie = *total_size;
|
||||
delete total_size;
|
||||
Q_EMIT operationTotalFileSize(m_total_size);
|
||||
if (isCancelled()) {
|
||||
Q_EMIT operationFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
//判断剩余空间是否满足拷贝所需空间
|
||||
auto destGfile = g_file_new_for_uri(m_dest_dir_uri.toUtf8().constData());
|
||||
auto destPath = g_file_get_path(destGfile);
|
||||
QStorageInfo storage(destPath);
|
||||
if (!storage.isValid()) {
|
||||
qWarning() << "The file path is not mounted correctly";
|
||||
} else {
|
||||
// If the storage is valid, get the available disk space
|
||||
quint64 diskFreeSpace = storage.bytesAvailable();
|
||||
if(m_total_size > diskFreeSpace && diskFreeSpace > 0) {
|
||||
// If there is not enough space, create a new FileOperationError object
|
||||
FileOperationError except;
|
||||
QString name;
|
||||
if (storage.rootPath() == "/") {
|
||||
name = tr("File System");
|
||||
} else if (storage.rootPath() == "/data") {
|
||||
name = tr("Data");
|
||||
} else {
|
||||
name = storage.name();
|
||||
}
|
||||
double total_file_size_gb = (double)m_total_size / (1024 * 1024 * 1024);
|
||||
double need_total_size_gb = (double)(m_total_size - diskFreeSpace) / (1024 * 1024 * 1024);
|
||||
except.errorStr = tr("%1 no space left on device. "
|
||||
"Copy file size: %2 GB, "
|
||||
"Space needed: %3 GB.").arg(name).arg(QString::number(total_file_size_gb, 'f', 3))
|
||||
.arg(QString::number(need_total_size_gb, 'f', 3));
|
||||
except.op = FileOpCopy;
|
||||
except.title = tr("File copy error");
|
||||
except.dlgType = ED_WARNING;
|
||||
Q_EMIT errored(except);
|
||||
Q_EMIT operationFinished();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_srcUrisOfCopyDspsFiles.clear();
|
||||
m_destUrisOfCopyDspsFiles.clear();
|
||||
|
@ -1091,22 +787,14 @@ void FileCopyOperation::run()
|
|||
}
|
||||
}
|
||||
|
||||
//comment to fix bug#177163, copy and paste file has error and play success sound issue
|
||||
//copy operation has finished, no need reset flag, keep the same with move-operation
|
||||
//setHasError(false);
|
||||
setHasError(false);
|
||||
QStringList burnUris = m_source_uris;
|
||||
for (auto node : nodes) {
|
||||
if (!isCancelled()) {
|
||||
if (node->state() != FileNode::Handled) {
|
||||
// 如果出现了不可处理的文件操作异常,则不允许用户进行此操作的undo/redo
|
||||
// FIXME: 对于多级自文件的场景,这么处理是有问题的,也许判断是否有不可回滚的异常处理机制需要再优化
|
||||
setHasError(true);
|
||||
}
|
||||
m_info->m_node_map.insert(node->uri(), node->destUri());
|
||||
if (m_is_udf_burn_work) {
|
||||
switch (node->responseType()) {
|
||||
case IgnoreOne:
|
||||
case OverWriteOne:
|
||||
burnUris.removeOne(node->uri());
|
||||
break;
|
||||
case BackupOne:
|
||||
|
@ -1119,6 +807,7 @@ void FileCopyOperation::run()
|
|||
}
|
||||
delete node;
|
||||
}
|
||||
|
||||
m_info->m_dest_uris = m_info->m_node_map.values();
|
||||
nodes.clear();
|
||||
#ifdef KY_UDF_BURN
|
||||
|
@ -1129,7 +818,7 @@ void FileCopyOperation::run()
|
|||
except.op = FileOpCopy;
|
||||
except.title = tr("File copy error");
|
||||
except.srcUri = m_source_uris.first();
|
||||
except.errorStr = mHelper->getDiscError();
|
||||
except.errorStr = tr("Burn failed");
|
||||
except.destDirUri = m_dest_dir_uri;
|
||||
except.dlgType = ED_WARNING;
|
||||
Q_EMIT errored(except);
|
||||
|
@ -1141,222 +830,13 @@ void FileCopyOperation::run()
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Q_EMIT operationFinished();
|
||||
sendSrcAndDestUrisOfCopyDspsFiles();
|
||||
if (m_is_long_name_file_operation) {
|
||||
Q_EMIT operationSaveAsLongNameFile(m_save_as_other_uri);
|
||||
}
|
||||
}
|
||||
|
||||
bool FileCopyOperation::copyLinkedFile(FileNode *node, GFileInfo *info, GFileWrapperPtr file)
|
||||
{
|
||||
g_autoptr(GError) err = nullptr;
|
||||
QString target = g_file_info_get_symlink_target(info);
|
||||
if (!target.startsWith("/"))
|
||||
{
|
||||
QString parentUri = FileUtils::getParentUri(m_current_src_uri);
|
||||
target = QUrl(parentUri).path() + "/" + target;
|
||||
}
|
||||
target.replace("%", "%25");
|
||||
target.replace("#", "%23");
|
||||
target.prepend("file://");
|
||||
QUrl url(target);
|
||||
const char* symlinkValue = url.path().toUtf8().constData();
|
||||
g_file_make_symbolic_link(file.get()->get(), symlinkValue, nullptr, &err);
|
||||
if (err) {
|
||||
qDebug() << "linkrun:" << err->message;
|
||||
FileOperationError except;
|
||||
except.srcUri = m_current_src_uri;
|
||||
except.errorType = ET_GIO;
|
||||
except.isCritical = true;
|
||||
except.errorStr = err->message;
|
||||
except.errorCode = err->code;
|
||||
except.op = FileOpCopy;
|
||||
except.title = tr("Link file error");
|
||||
except.destDirUri = m_current_dest_dir_uri;
|
||||
auto handle_type = prehandle(err);
|
||||
|
||||
if (handle_type == Other) {
|
||||
switch (err->code) {
|
||||
case G_IO_ERROR_EXISTS: {
|
||||
except.dlgType = ED_CONFLICT;
|
||||
Q_EMIT errored(except);
|
||||
auto typeData = except.respCode;
|
||||
handle_type = typeData;
|
||||
break;
|
||||
}
|
||||
case G_IO_ERROR_FILENAME_TOO_LONG: {
|
||||
except.dlgType = ED_RENAME;
|
||||
Q_EMIT errored(except);
|
||||
auto typeData = except.respCode;
|
||||
handle_type = typeData;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
except.dlgType = ED_WARNING;
|
||||
Q_EMIT errored(except);
|
||||
auto typeData = except.respCode;
|
||||
handle_type = typeData;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//handle.
|
||||
switch (handle_type) {
|
||||
node->setState(FileNode::Handling);
|
||||
case IgnoreOne: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Unhandled);
|
||||
node->setErrorResponse(IgnoreOne);
|
||||
return true;
|
||||
}
|
||||
case IgnoreAll: {
|
||||
setHasError(true);
|
||||
node->setState(FileNode::Unhandled);
|
||||
node->setErrorResponse(IgnoreOne);
|
||||
m_prehandle_hash.insert(err->code, IgnoreOne);
|
||||
return true;
|
||||
}
|
||||
case OverWriteOne: {
|
||||
setHasError(true);
|
||||
bool success = g_file_delete(file.get()->get(), nullptr, nullptr);
|
||||
if (!success) {
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setErrorResponse(Invalid);
|
||||
qWarning()<<"failed to remove Original dest file";
|
||||
return true;
|
||||
} else {
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case OverWriteAll: {
|
||||
setHasError(true);
|
||||
m_prehandle_hash.insert(err->code, OverWriteOne);
|
||||
bool success = g_file_delete(file.get()->get(), nullptr, nullptr);
|
||||
if (!success) {
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setErrorResponse(Invalid);
|
||||
qWarning()<<"failed to remove Original dest file";
|
||||
return true;
|
||||
} else {
|
||||
node->setState(FileNode::Invalid);
|
||||
node->setErrorResponse(OverWriteOne);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case BackupOne: {
|
||||
node->setErrorResponse(BackupOne);
|
||||
QString name = "";
|
||||
QStringList extendStr = node->destBaseName().split(".");
|
||||
if (extendStr.length() > 0) {
|
||||
extendStr.removeAt(0);
|
||||
}
|
||||
QString endStr = extendStr.join(".");
|
||||
if (except.respValue.contains("name")) {
|
||||
name = except.respValue["name"].toString();
|
||||
if (endStr != "" && name.endsWith(endStr)) {
|
||||
node->setDestFileName(name);
|
||||
} else if ("" != endStr && "" != name) {
|
||||
node->setDestFileName(name + "." + endStr);
|
||||
}
|
||||
}
|
||||
|
||||
while (FileUtils::isFileExsit(node->resolveDestFileUri(m_dest_dir_uri))) {
|
||||
handleDuplicate(node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case BackupAll: {
|
||||
node->setErrorResponse(BackupOne);
|
||||
while (FileUtils::isFileExsit(node->resolveDestFileUri(m_dest_dir_uri))) {
|
||||
handleDuplicate(node);
|
||||
}
|
||||
m_prehandle_hash.insert(err->code, BackupOne);
|
||||
return false;
|
||||
}
|
||||
case Retry: {
|
||||
return false;
|
||||
}
|
||||
case RenameOne: {
|
||||
node->setErrorResponse(RenameOne);
|
||||
node->setDestFileName(except.respValue.value("newName").toString());
|
||||
return false;
|
||||
}
|
||||
case Cancel: {
|
||||
node->setState(FileNode::Unhandled);
|
||||
cancel();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
node->setState(FileNode::Handled);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ExceptionResponse FileCopyOperation::udfCopyWarningDialog()
|
||||
{
|
||||
FileOperationError except;
|
||||
ExceptionResponse typeData = Invalid;
|
||||
except.errorType = ET_CUSTOM;
|
||||
except.op = FileOpCopy;
|
||||
except.title = tr("File copy error");
|
||||
except.srcUri = m_source_uris.first();
|
||||
except.errorStr = tr("Burning does not support replacement");
|
||||
except.destDirUri = m_dest_dir_uri;
|
||||
except.dlgType = ED_WARNING;
|
||||
Q_EMIT errored(except);
|
||||
typeData = except.respCode;
|
||||
return typeData;
|
||||
}
|
||||
|
||||
bool FileCopyOperation::saveAsOtherPath()
|
||||
{
|
||||
QString destUri = "file://" + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/扩展";
|
||||
QDBusInterface iface ("com.kylin.file.system.fuse","/com/kylin/file/system/fuse","com.kylin.file.system.fuse",QDBusConnection::systemBus());
|
||||
if (!iface.isValid()) {
|
||||
qWarning() << "fuse dbus has error : " << iface.lastError();
|
||||
return false;
|
||||
}
|
||||
if (!FileUtils::isFileExsit(destUri)) {
|
||||
QDir dir(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
|
||||
dir.mkdir("扩展");
|
||||
auto path = dir.path().append("/扩展");
|
||||
QDBusReply<bool> reply = iface.call("SetSetings", "true", path);
|
||||
if (reply.isValid()) {
|
||||
if (!reply.value()) {
|
||||
qInfo() << "fuse setings false";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
qWarning() << "fuse dbus has error : " << iface.lastError();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (m_current_src_uri.startsWith(destUri)) {
|
||||
return false;
|
||||
}
|
||||
m_save_as_other_uri = destUri;
|
||||
if (m_dest_dir_uri == m_save_as_other_uri) {
|
||||
if (m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
m_dest_dir_uri = m_save_as_other_uri;
|
||||
if (!m_is_long_name_file_operation) {
|
||||
m_is_long_name_file_operation = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileCopyOperation::cancel()
|
||||
{
|
||||
setHasError(true);
|
||||
if (m_reporter) {
|
||||
m_reporter->cancel();
|
||||
}
|
||||
|
|
|
@ -73,11 +73,6 @@ protected:
|
|||
*/
|
||||
void rollbackNodeRecursively(FileNode *node);
|
||||
|
||||
bool copyLinkedFile(FileNode *node, GFileInfo *info, GFileWrapperPtr file);
|
||||
|
||||
ExceptionResponse udfCopyWarningDialog();
|
||||
|
||||
bool saveAsOtherPath();
|
||||
private:
|
||||
/*!
|
||||
* \brief m_is_duplicated_copy
|
||||
|
@ -102,20 +97,15 @@ private:
|
|||
QSet<QString> m_conflict_files;
|
||||
QString m_current_src_uri = nullptr;
|
||||
QString m_current_dest_dir_uri = nullptr;
|
||||
QString m_save_as_other_uri= nullptr;
|
||||
|
||||
goffset m_current_offset = 0;
|
||||
goffset m_total_size = 0;
|
||||
goffset m_total_szie = 0;
|
||||
|
||||
GFileCopyFlags m_default_copy_flag = GFileCopyFlags(G_FILE_COPY_NOFOLLOW_SYMLINKS);
|
||||
|
||||
FileNodeReporter *m_reporter = nullptr;
|
||||
|
||||
bool m_is_udf_burn_work = false;
|
||||
bool m_is_udf_warning = false;
|
||||
bool m_is_long_name_file_operation = false;
|
||||
bool m_is_long_name_error_msg_show = false;
|
||||
int m_cate_type = 0;
|
||||
/*!
|
||||
* \brief m_prehandle_hash
|
||||
* \details
|
||||
|
|
|
@ -25,17 +25,11 @@
|
|||
#include "file-node.h"
|
||||
#include "file-node-reporter.h"
|
||||
#include "sound-effect.h"
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
#include "ksoundeffects.h"
|
||||
#endif
|
||||
#include <QApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QProcess>
|
||||
|
||||
using namespace Peony;
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
using namespace kdk;
|
||||
#endif
|
||||
|
||||
FileDeleteOperation::FileDeleteOperation(QStringList sourceUris, QObject *parent) : FileOperation(parent)
|
||||
{
|
||||
|
@ -59,7 +53,7 @@ void FileDeleteOperation::deleteRecursively(FileNode *node)
|
|||
{
|
||||
if (isCancelled())
|
||||
return;
|
||||
OperatorThreadPause();
|
||||
|
||||
auto fileIconName = FileUtilsPrivate::getFileIconName(FileUtils::urlEncode(node->uri()));
|
||||
GFile *file = g_file_new_for_uri(FileUtils::urlEncode(node->uri()).toUtf8().constData());
|
||||
if (node->isFolder()) {
|
||||
|
@ -193,7 +187,7 @@ void FileDeleteOperation::run()
|
|||
if (! path.isEmpty()) {
|
||||
operationStartSnyc();
|
||||
QProcess p;
|
||||
p.start(QString("/usr/bin/sync -f '%1'").arg(path));
|
||||
p.start(QString("sync -f '%1'").arg(path));
|
||||
p.waitForFinished(-1);
|
||||
}
|
||||
}
|
||||
|
@ -210,11 +204,7 @@ void FileDeleteOperation::run()
|
|||
|
||||
qApp->property("clearTrash");
|
||||
if(true == qApp->property("clearTrash").toBool()){
|
||||
//Peony::SoundEffect::getInstance()->recycleBinClearMusic();
|
||||
//Task#152997, use sdk play sound
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
kdk::KSoundEffects::playSound(SoundType::TRASH_EMPTY);
|
||||
#endif
|
||||
Peony::SoundEffect::getInstance()->recycleBinClearMusic();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,17 +25,11 @@
|
|||
|
||||
#include "gerror-wrapper.h"
|
||||
#include "sound-effect.h"
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
#include "ksoundeffects.h"
|
||||
#endif
|
||||
|
||||
#include <QUrl>
|
||||
#include <QProcess>
|
||||
|
||||
using namespace Peony;
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
using namespace kdk;
|
||||
#endif
|
||||
|
||||
FileLinkOperation::FileLinkOperation(QString srcUri, QString destDirUri, QObject *parent) : FileOperation (parent)
|
||||
{
|
||||
|
@ -102,11 +96,7 @@ retry:
|
|||
}
|
||||
}
|
||||
else{
|
||||
//SoundEffect::getInstance()->copyOrMoveSucceedMusic();
|
||||
//Task#152997, use sdk play sound
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
kdk::KSoundEffects::playSound(SoundType::OPERATION_FILE);
|
||||
#endif
|
||||
SoundEffect::getInstance()->copyOrMoveSucceedMusic();
|
||||
}
|
||||
|
||||
g_file_set_display_name(destFile.get()->get(), QUrl::fromPercentEncoding(m_dest_uri.split("/").last().toUtf8()).toUtf8().constData(), nullptr, nullptr);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -126,9 +126,7 @@ protected:
|
|||
void move();
|
||||
void moveForceUseFallback();
|
||||
void moveForceUseFallback(FileNode* node);
|
||||
bool copyLinkedFile(FileNode *node, GFileInfo *info, GFileWrapperPtr file);
|
||||
ExceptionResponse udfCopyWarningDialog();
|
||||
bool saveAsOtherPath();
|
||||
|
||||
/*!
|
||||
* \brief prehandle
|
||||
* \param err
|
||||
|
@ -165,10 +163,9 @@ private:
|
|||
* \brief m_current_dest_dir_uri, used in progress_callback.
|
||||
*/
|
||||
QString m_current_dest_dir_uri = nullptr;
|
||||
QString m_save_as_other_uri= nullptr;
|
||||
|
||||
goffset m_current_offset = 0;
|
||||
goffset m_total_size = 0;
|
||||
goffset m_total_szie = 0;
|
||||
|
||||
/*!
|
||||
* \brief m_force_use_callback
|
||||
|
@ -188,8 +185,6 @@ private:
|
|||
*/
|
||||
bool m_copy_move = false;
|
||||
|
||||
bool m_is_same_fs = false;
|
||||
|
||||
/*!
|
||||
* \brief m_move_action
|
||||
* replacing m_copy_move flag.
|
||||
|
@ -201,18 +196,10 @@ private:
|
|||
|
||||
FileNodeReporter *m_reporter = nullptr;
|
||||
|
||||
bool m_is_long_name_file_operation = false;
|
||||
|
||||
bool m_is_long_name_error_msg_show = false;
|
||||
|
||||
bool m_is_udf_burn_work = false;
|
||||
|
||||
bool m_is_udf_warning = false;
|
||||
|
||||
QStringList m_burn_uris;
|
||||
|
||||
int m_cate_type = 0;
|
||||
|
||||
/*!
|
||||
* \brief m_prehandle_hash
|
||||
* \details
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "file-info.h"
|
||||
#include "file-node-reporter.h"
|
||||
|
||||
#define PEONY_TRUNCATE_NAME_LIMIT 225
|
||||
|
||||
using namespace Peony;
|
||||
|
||||
|
@ -143,80 +142,3 @@ const QString FileNode::resolveDestFileUri(const QString &destRootDir)
|
|||
setDestUri(url);
|
||||
return url;
|
||||
}
|
||||
|
||||
void FileNode::truncateDestFileName(const int cateType)
|
||||
{
|
||||
auto newName = FileUtils::getNonSuffixedBaseNameFromUri(m_uri);
|
||||
auto destDirUri = FileUtils::getParentUri(destUri());
|
||||
auto fsType = FileUtils::getFsTypeFromFile(destDirUri);
|
||||
bool setLimitBytes = true;
|
||||
if (fsType.contains("ntfs")) {
|
||||
setLimitBytes = false;
|
||||
}
|
||||
auto suffix = m_basename;
|
||||
suffix = suffix.remove(newName);
|
||||
newName.remove(suffix);
|
||||
|
||||
if (setLimitBytes) {
|
||||
bool useForceChop = false;
|
||||
if (suffix.toLocal8Bit().count() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
qWarning()<<"suffix too long:"<<m_uri<<"use force chop instead";
|
||||
useForceChop = true;
|
||||
} else if (newName == m_basename) {
|
||||
qWarning()<<"failed to truncate suffix of"<<m_uri<<", use force chop instead";
|
||||
useForceChop = true;
|
||||
} else if (isFolder()) {
|
||||
useForceChop = true;
|
||||
}
|
||||
if (useForceChop) {
|
||||
newName = m_basename;
|
||||
if (TurnCateType::Post == cateType) {
|
||||
while (newName.toLocal8Bit().count() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
newName.chop(1);
|
||||
}
|
||||
} else if (TurnCateType::Front == cateType) {
|
||||
while (newName.toLocal8Bit().count() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
newName.remove(0,1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int limitBytes = PEONY_TRUNCATE_NAME_LIMIT - suffix.toLocal8Bit().count();
|
||||
if (TurnCateType::Post == cateType) {
|
||||
while (newName.toLocal8Bit().count() > limitBytes) {
|
||||
newName.chop(1);
|
||||
}
|
||||
} else if (TurnCateType::Front == cateType){
|
||||
while (newName.toLocal8Bit().count() > limitBytes) {
|
||||
newName.remove(0,1);
|
||||
}
|
||||
}
|
||||
newName = newName + suffix;
|
||||
}
|
||||
setDestFileName(newName);
|
||||
} else {
|
||||
bool useForceChop = false;
|
||||
if (suffix.length() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
qWarning()<<"suffix too long:"<<m_uri<<"use force chop instead";
|
||||
useForceChop = true;
|
||||
} else if (newName == m_basename) {
|
||||
qWarning()<<"failed to truncate suffix of"<<m_uri<<", use force chop instead";
|
||||
useForceChop = true;
|
||||
} else if (isFolder()) {
|
||||
useForceChop = true;
|
||||
}
|
||||
if (useForceChop) {
|
||||
newName = m_basename;
|
||||
while (newName.length() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
newName.chop(1);
|
||||
}
|
||||
} else {
|
||||
int limitBytes = PEONY_TRUNCATE_NAME_LIMIT - suffix.length();
|
||||
while (newName.length() > limitBytes) {
|
||||
newName.chop(1);
|
||||
}
|
||||
newName = newName + suffix;
|
||||
}
|
||||
|
||||
setDestFileName(newName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,13 +32,6 @@
|
|||
|
||||
namespace Peony {
|
||||
|
||||
enum TurnCateType {
|
||||
Post = 0,
|
||||
Front,
|
||||
AllPost,
|
||||
ALLFront,
|
||||
};
|
||||
|
||||
class FileNodeReporter;
|
||||
|
||||
/*!
|
||||
|
@ -182,8 +175,6 @@ public:
|
|||
}
|
||||
const QString resolveDestFileUri(const QString &destRootDir);
|
||||
|
||||
void truncateDestFileName(const int cateType);
|
||||
|
||||
private:
|
||||
QString m_uri = nullptr;
|
||||
QString m_basename = nullptr;
|
||||
|
|
|
@ -31,11 +31,6 @@
|
|||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QRadioButton>
|
||||
#include <QButtonGroup>
|
||||
#include <QCheckBox>
|
||||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
|
@ -47,9 +42,6 @@
|
|||
|
||||
#include "global-settings.h"
|
||||
|
||||
#define PEONY_TRUNCATE_NAME_LIMIT 225
|
||||
#define PEONY_RENAME_LIMIT 255
|
||||
|
||||
KyFileDialogRename::KyFileDialogRename(QWidget *parent) : KyFileOperationDialog(parent), Peony::FileOperationErrorHandler()
|
||||
{
|
||||
bool isTabletMode = false;
|
||||
|
@ -66,9 +58,9 @@ KyFileDialogRename::KyFileDialogRename(QWidget *parent) : KyFileOperationDialog(
|
|||
|
||||
setFixedWidth(600);
|
||||
if(true == isTabletMode){
|
||||
setFixedHeight(330);
|
||||
setFixedHeight(255);
|
||||
}else{
|
||||
setFixedHeight(300);
|
||||
setFixedHeight(225);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -101,8 +93,6 @@ void KyFileDialogRename::handle(Peony::FileOperationError &error)
|
|||
case Peony::FileOpCopy:
|
||||
line1 = tr("Copying \"%1\"").arg(newName); {
|
||||
auto destDir = Peony::FileUtils::urlDecode(error.destDirUri);
|
||||
QString fileName = destDir.split("/").last();
|
||||
destDir.chop(fileName.count() + 1);
|
||||
line2 = tr("To \"%1\"").arg(destDir);
|
||||
line3 = tr("Copying failed, the reason is: %1").arg(error.errorCode == G_IO_ERROR_FILENAME_TOO_LONG? tr("Filename too long"): error.errorStr);
|
||||
break;
|
||||
|
@ -110,8 +100,6 @@ void KyFileDialogRename::handle(Peony::FileOperationError &error)
|
|||
case Peony::FileOpMove: {
|
||||
line1 = tr("Moving \"%1\"").arg(newName);
|
||||
auto destDir = Peony::FileUtils::urlDecode(error.destDirUri);
|
||||
QString fileName = destDir.split("/").last();
|
||||
destDir.chop(fileName.count() + 1);
|
||||
line2 = tr("To \"%1\"").arg(destDir);
|
||||
line3 = tr("Moving failed, the reason is: %1").arg(error.errorCode == G_IO_ERROR_FILENAME_TOO_LONG? tr("Filename too long"): error.errorStr);
|
||||
break;
|
||||
|
@ -123,102 +111,75 @@ void KyFileDialogRename::handle(Peony::FileOperationError &error)
|
|||
}
|
||||
}
|
||||
|
||||
QString line;
|
||||
QStringList messages;
|
||||
line = qApp->fontMetrics().elidedText(line1, Qt::ElideMiddle, 500);
|
||||
messages.append(line);
|
||||
line = qApp->fontMetrics().elidedText(line2, Qt::ElideMiddle, 500);
|
||||
messages.append(line);
|
||||
line = qApp->fontMetrics().elidedText(line3, Qt::ElideMiddle, 500);
|
||||
messages.append(line);
|
||||
line1 = qApp->fontMetrics().elidedText(line1, Qt::ElideMiddle, 500);
|
||||
messages.append(line1);
|
||||
line2 = qApp->fontMetrics().elidedText(line2, Qt::ElideMiddle, 500);
|
||||
messages.append(line2);
|
||||
line3 = qApp->fontMetrics().elidedText(line3, Qt::ElideMiddle, 500);
|
||||
messages.append(line3);
|
||||
|
||||
auto labelText = messages.join('\n');
|
||||
|
||||
// page1
|
||||
auto pageOne = new QWidget(this);
|
||||
QRadioButton *skip = new QRadioButton(tr("Skip"), this);
|
||||
QRadioButton *cutOff = new QRadioButton(tr("Truncation"), this);
|
||||
QRadioButton *save = new QRadioButton(tr("Save"), this);
|
||||
QRadioButton *rename = new QRadioButton(tr("Rename"), this);
|
||||
QButtonGroup *onePageGroup = new QButtonGroup(this);
|
||||
QString specification;
|
||||
QLabel *specificationLabel = new QLabel(this);
|
||||
specificationLabel->setText(specification);
|
||||
specificationLabel->setWordWrap(true);
|
||||
|
||||
onePageGroup->addButton(skip, 0);
|
||||
onePageGroup->addButton(cutOff, 1);
|
||||
onePageGroup->addButton(save, 2);
|
||||
onePageGroup->addButton(rename, 3);
|
||||
skip->setChecked(true);
|
||||
|
||||
QVBoxLayout *oneLayout = new QVBoxLayout(this);
|
||||
auto page1 = new QWidget(this);
|
||||
auto gridLayout1 = new QGridLayout;
|
||||
gridLayout1->setSpacing(20);
|
||||
auto labelIcon = new QLabel;
|
||||
labelIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
gridLayout1->addWidget(labelIcon, 0, 0, Qt::AlignTop|Qt::AlignLeft);
|
||||
auto content = new QLabel;
|
||||
//content->setWordWrap(true);
|
||||
content->setWordWrap(true);
|
||||
//int textWidth = (this->width() - 40 - 40 - 24) * 3;
|
||||
//QString elidedString = qApp->fontMetrics().elidedText(error.errorStr, Qt::ElideMiddle, textWidth);
|
||||
content->setText(labelText);
|
||||
auto labelIcon = new QLabel;
|
||||
labelIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
labelIcon->setAlignment(Qt::AlignTop);
|
||||
|
||||
QHBoxLayout *centerLayout = new QHBoxLayout(this);
|
||||
centerLayout->addWidget(skip);
|
||||
centerLayout->addWidget(cutOff);
|
||||
centerLayout->addWidget(save);
|
||||
centerLayout->addWidget(rename);
|
||||
centerLayout->addStretch();
|
||||
QCheckBox *allApp = new QCheckBox(tr("All applications"), this);
|
||||
QDialogButtonBox *buttonBoxOne = new QDialogButtonBox(this);
|
||||
buttonBoxOne->setStandardButtons(QDialogButtonBox::NoButton);
|
||||
QPushButton *cancelBt = buttonBoxOne->addButton(tr("Cancel"), QDialogButtonBox::ActionRole);
|
||||
QPushButton *applyBt = buttonBoxOne->addButton(tr("Apply"), QDialogButtonBox::ActionRole);
|
||||
applyBt->setDefault(true);
|
||||
applyBt->setProperty("isImportant", true);
|
||||
QHBoxLayout *bottomLayout = new QHBoxLayout(this);
|
||||
bottomLayout->addWidget(allApp);
|
||||
bottomLayout->addStretch();
|
||||
bottomLayout->addWidget(buttonBoxOne);
|
||||
bottomLayout->setAlignment(buttonBoxOne, Qt::AlignRight);
|
||||
|
||||
oneLayout->addWidget(content);
|
||||
oneLayout->addLayout(centerLayout);
|
||||
oneLayout->addWidget(specificationLabel);
|
||||
oneLayout->addLayout(bottomLayout);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout(this);
|
||||
mainLayout->addWidget(labelIcon);
|
||||
mainLayout->addLayout(oneLayout);
|
||||
pageOne->setLayout(mainLayout);
|
||||
|
||||
stack->addWidget(pageOne);
|
||||
gridLayout1->addWidget(content, 0, 1, Qt::AlignTop);
|
||||
auto buttonBox = new QDialogButtonBox;
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::NoButton);
|
||||
auto skip = buttonBox->addButton(tr("Skip"), QDialogButtonBox::ActionRole);
|
||||
auto skipAll = buttonBox->addButton(tr("Skip All"), QDialogButtonBox::ActionRole);
|
||||
auto cancel = buttonBox->addButton(tr("Cancel"), QDialogButtonBox::ActionRole);
|
||||
auto rename = buttonBox->addButton(tr("Rename"), QDialogButtonBox::ActionRole);
|
||||
rename->setProperty("isImportant", true);
|
||||
rename->setDefault(true);
|
||||
rename->setFocus();
|
||||
gridLayout1->addWidget(buttonBox, 1, 1, Qt::AlignBottom|Qt::AlignRight);
|
||||
page1->setLayout(gridLayout1);
|
||||
stack->addWidget(page1);
|
||||
|
||||
// page2
|
||||
auto page2 = new QWidget(this);
|
||||
auto layout2 = new QGridLayout(this);
|
||||
auto textEdit = new RenameEditor(this);
|
||||
auto gridLayout2 = new QGridLayout;
|
||||
auto renameIcon = new QLabel;
|
||||
renameIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
|
||||
if (QGSettings::isSchemaInstalled("org.ukui.style")) {
|
||||
QGSettings *settings = new QGSettings("org.ukui.style", QByteArray(), this);
|
||||
connect(settings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
if("iconThemeName" == key){
|
||||
labelIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
renameIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
gridLayout2->addWidget(renameIcon, 0, 0, Qt::AlignTop|Qt::AlignLeft);
|
||||
auto label2 = new QLabel;
|
||||
label2->setText(tr("Please enter a new name"));
|
||||
gridLayout2->addWidget(label2, 0, 1, Qt::AlignLeft);
|
||||
auto textEdit = new RenameEditor;
|
||||
textEdit->setBackgroundRole(QPalette::Button);
|
||||
textEdit->setAutoFillBackground(true);
|
||||
textEdit->viewport()->setBackgroundRole(QPalette::Button);
|
||||
textEdit->viewport()->setAutoFillBackground(true);
|
||||
// int height = qApp->fontMetrics().lineSpacing() * 3 + qApp->fontMetrics().descent();
|
||||
// textEdit->setFixedHeight(height);
|
||||
|
||||
auto num = new QLabel;
|
||||
QString totalNum = QString("<span style=\"color:red;\">%1</span>/%2%3").arg(newName.toLocal8Bit().count()).arg(PEONY_RENAME_LIMIT).arg(tr("Bytes"));
|
||||
num->setText(totalNum);
|
||||
auto buttonBox2 = new QDialogButtonBox(this);
|
||||
gridLayout2->addWidget(textEdit, 1, 1, Qt::AlignTop);
|
||||
auto buttonBox2 = new QDialogButtonBox;
|
||||
buttonBox2->setStandardButtons(QDialogButtonBox::NoButton);
|
||||
auto cancel2 = buttonBox2->addButton(tr("Cancel"), QDialogButtonBox::ActionRole);
|
||||
auto ensure2 = buttonBox2->addButton(tr("Save"), QDialogButtonBox::ActionRole);
|
||||
auto ensure2 = buttonBox2->addButton(tr("OK"), QDialogButtonBox::ActionRole);
|
||||
ensure2->setDefault(true);
|
||||
ensure2->setEnabled(false);
|
||||
ensure2->setProperty("isImportant", true);
|
||||
|
||||
layout2->addWidget(textEdit, 0, 0, 4, 2, Qt::AlignTop);
|
||||
layout2->addWidget(num, 4, 1, Qt::AlignBottom|Qt::AlignRight);
|
||||
layout2->addWidget(buttonBox2, 5, 1, Qt::AlignBottom|Qt::AlignRight);
|
||||
page2->setLayout(layout2);
|
||||
gridLayout2->addWidget(buttonBox2, 2, 1, Qt::AlignBottom|Qt::AlignRight);
|
||||
page2->setLayout(gridLayout2);
|
||||
stack->addWidget(page2);
|
||||
|
||||
textEdit->setText(newName);
|
||||
|
@ -243,199 +204,16 @@ void KyFileDialogRename::handle(Peony::FileOperationError &error)
|
|||
}
|
||||
|
||||
textEdit->setTextCursor(cursor);
|
||||
|
||||
gridLayout2->addWidget(textEdit, 1, 1, Qt::AlignTop);
|
||||
textEdit->activateWindow();
|
||||
//textEdit->setFocus();
|
||||
|
||||
connect(textEdit, &QTextEdit::textChanged, this, [=](){
|
||||
QString currentNum ;
|
||||
if (textEdit->toPlainText().toLocal8Bit().count() > PEONY_RENAME_LIMIT) {
|
||||
ensure2->setEnabled(false);
|
||||
currentNum = QString("<span style=\"color:red;\">%1</span>").arg(textEdit->toPlainText().toLocal8Bit().count());
|
||||
} else {
|
||||
currentNum = QString("<span style=\"color:\">%1</span>").arg(textEdit->toPlainText().toLocal8Bit().count());
|
||||
ensure2->setEnabled(true);
|
||||
}
|
||||
QString totalNum = QString("%1/%2%3").arg(currentNum).arg(PEONY_RENAME_LIMIT).arg(tr("Bytes"));
|
||||
num->setText(totalNum);
|
||||
});
|
||||
|
||||
// page3
|
||||
QWidget *truncationWidget = new QWidget(this);
|
||||
QRadioButton *frontTruncation = new QRadioButton(tr("Front truncation"), this);
|
||||
QRadioButton *laterTruncation = new QRadioButton(tr("Post truncation"), this);
|
||||
QButtonGroup *truncationGroup = new QButtonGroup(this);
|
||||
truncationGroup->addButton(laterTruncation, 0);
|
||||
truncationGroup->addButton(frontTruncation, 1);
|
||||
laterTruncation->setChecked(true);
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::NoButton);
|
||||
QPushButton *cancelButton = buttonBox->addButton(tr("Cancel"), QDialogButtonBox::ActionRole);
|
||||
QPushButton *okButton = buttonBox->addButton(tr("OK"), QDialogButtonBox::ActionRole);
|
||||
okButton->setDefault(true);
|
||||
okButton->setProperty("isImportant", true);
|
||||
|
||||
QHBoxLayout *pageThreebottomLayout = new QHBoxLayout(this);
|
||||
pageThreebottomLayout->addWidget(frontTruncation);
|
||||
pageThreebottomLayout->addWidget(laterTruncation);
|
||||
pageThreebottomLayout->addStretch();
|
||||
pageThreebottomLayout->addWidget(cancelButton);
|
||||
pageThreebottomLayout->addWidget(okButton);
|
||||
|
||||
QLabel *truncatedLabel = new QLabel(this);
|
||||
truncatedLabel->setWordWrap(true);
|
||||
truncatedLabel->setText(newName);
|
||||
|
||||
QVBoxLayout *cutOffLayout = new QVBoxLayout(truncationWidget);
|
||||
cutOffLayout->addWidget(truncatedLabel);
|
||||
cutOffLayout->addStretch();
|
||||
cutOffLayout->addLayout(pageThreebottomLayout);
|
||||
truncationWidget->setLayout(cutOffLayout);
|
||||
stack->addWidget(truncationWidget);
|
||||
stack->setCurrentWidget(pageOne);
|
||||
|
||||
connect(cancelButton, &QPushButton::clicked, this, &KyFileDialogRename::reject);
|
||||
connect(okButton, &QPushButton::clicked, this, [=, &error]{
|
||||
int id = truncationGroup->checkedId();
|
||||
error.respValue.insert("cateType", id);
|
||||
if (Qt::CheckState::Checked == allApp->checkState()) {
|
||||
error.respCode = Peony::ExceptionResponse::TruncateAll;
|
||||
} else {
|
||||
error.respCode = Peony::ExceptionResponse::TruncateOne;
|
||||
}
|
||||
accept();
|
||||
});
|
||||
|
||||
connect(truncationGroup, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked), this, [=](QAbstractButton* button) {
|
||||
const int id = truncationGroup->id(button);
|
||||
const QString destName = truncateDestFileName(error.destDirUri, id);
|
||||
truncatedLabel->setText(destName);
|
||||
});
|
||||
Q_EMIT truncationGroup->buttonClicked(laterTruncation);
|
||||
|
||||
m_currentWidget = nullptr;
|
||||
connect(onePageGroup, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked), this, [=](QAbstractButton* button) {
|
||||
const int id = onePageGroup->id(button);
|
||||
switch(id) {
|
||||
case 0:
|
||||
allApp->show();
|
||||
specificationLabel->setText(tr("Description: Skip copying files of the current type"));
|
||||
break;
|
||||
case 1:{
|
||||
allApp->show();
|
||||
QString clickText = "<a href=\" \" style=\"color: #3D6BE5;text-decoration: none;\">"
|
||||
+ tr("truncate interval")
|
||||
+ "</a>.";
|
||||
QString text = tr("Explanation: Truncate the portion of the file name that exceeds 225 bytes and select");
|
||||
text = text + clickText;
|
||||
specificationLabel->setText(text);
|
||||
m_currentWidget = truncationWidget;
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
allApp->show();
|
||||
QString downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||
QString path = QString(tr("Description: By default, save to \"%1/扩展\".")).arg(downloadPath);
|
||||
specificationLabel->setText(path);
|
||||
break;
|
||||
}
|
||||
case 3:{
|
||||
allApp->hide();
|
||||
QString clickText = "<a href=\" \" style=\"color: #3D6BE5;text-decoration: none;\">"
|
||||
+ tr("modify the name")
|
||||
+ "</a>.";
|
||||
QString text = tr("Explanation: When renaming a file name, ensure it is within 225 bytes and ");
|
||||
text = text + clickText;
|
||||
specificationLabel->setText(text);
|
||||
m_currentWidget = page2;
|
||||
break;
|
||||
}
|
||||
};
|
||||
});
|
||||
Q_EMIT onePageGroup->buttonClicked(skip);
|
||||
|
||||
connect(specificationLabel, &QLabel::linkActivated, this, [=]() {
|
||||
const int id = onePageGroup->checkedId();
|
||||
if (1 == id) {
|
||||
QRect textRect = fontMetrics().boundingRect(truncatedLabel->text());
|
||||
int len = textRect.width()/(this->width() - stack->contentsMargins().left() - stack->contentsMargins().right());
|
||||
int totalHeight = qApp->fontMetrics().lineSpacing() *(len+1) + qApp->fontMetrics().descent();
|
||||
totalHeight = totalHeight + 150 > this->height() ? totalHeight + 150 : this->height();
|
||||
this->setFixedHeight(totalHeight);
|
||||
} else if (3 == id) {
|
||||
textEdit->setFocus();
|
||||
}
|
||||
stack->setCurrentWidget(m_currentWidget);
|
||||
});
|
||||
|
||||
if (QGSettings::isSchemaInstalled("org.ukui.style")) {
|
||||
QGSettings *settings = new QGSettings("org.ukui.style", QByteArray(), this);
|
||||
connect(settings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
if("iconThemeName" == key){
|
||||
labelIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
//renameIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(24, 24));
|
||||
} else if ("systemFont" == key || "systemFontSize" == key) {
|
||||
if (0 != stack->currentIndex()) {
|
||||
QFontMetrics font = qApp->fontMetrics();
|
||||
QRect textRect = fontMetrics().boundingRect(truncatedLabel->text());
|
||||
int len = textRect.width()/(this->width() - stack->contentsMargins().left() - stack->contentsMargins().right());
|
||||
int totalHeight = qApp->fontMetrics().lineSpacing() *(len+1) + qApp->fontMetrics().descent();
|
||||
totalHeight = totalHeight + 150 > this->height() ? totalHeight + 150 : this->height();
|
||||
this->setFixedHeight(totalHeight);
|
||||
}
|
||||
// int height = font.lineSpacing() * 3 + font.descent();
|
||||
// textEdit->setFixedHeight(height);
|
||||
// textEdit->setTextCursor(cursor);
|
||||
|
||||
// QStringList messages;
|
||||
// QString line;
|
||||
// line = qApp->fontMetrics().elidedText(line1, Qt::ElideMiddle, 500);
|
||||
// messages.append(line);
|
||||
// line = qApp->fontMetrics().elidedText(line2, Qt::ElideMiddle, 500);
|
||||
// messages.append(line);
|
||||
// line = qApp->fontMetrics().elidedText(line3, Qt::ElideMiddle, 500);
|
||||
// messages.append(line);
|
||||
// auto labelText = messages.join('\n');
|
||||
content->setText(labelText);
|
||||
this->repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
connect(cancelBt, &QPushButton::clicked, this, &KyFileDialogRename::reject);
|
||||
connect(applyBt, &QPushButton::clicked, this, [=, &error]{
|
||||
const int id = onePageGroup->checkedId();
|
||||
switch(id) {
|
||||
case 0:{
|
||||
if (Qt::CheckState::Checked == allApp->checkState()) {
|
||||
error.respCode = Peony::ExceptionResponse::IgnoreAll;
|
||||
} else {
|
||||
error.respCode = Peony::ExceptionResponse::IgnoreOne;
|
||||
}
|
||||
accept();
|
||||
break;
|
||||
}
|
||||
case 1:{
|
||||
QRect textRect = fontMetrics().boundingRect(truncatedLabel->text());
|
||||
int len = textRect.width()/(this->width() - stack->contentsMargins().left() - stack->contentsMargins().right());
|
||||
int totalHeight = qApp->fontMetrics().lineSpacing() *(len+1) + qApp->fontMetrics().descent();
|
||||
totalHeight = totalHeight + 150 > this->height() ? totalHeight + 150 : this->height();
|
||||
this->setFixedHeight(totalHeight);
|
||||
stack->setCurrentWidget(truncationWidget);
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
if (Qt::CheckState::Checked == allApp->checkState()) {
|
||||
error.respCode = Peony::ExceptionResponse::SaveAll;
|
||||
} else {
|
||||
error.respCode = Peony::ExceptionResponse::SaveOne;
|
||||
}
|
||||
accept();
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
stack->setCurrentWidget(page2);
|
||||
break;
|
||||
};
|
||||
stack->setCurrentWidget(page1);
|
||||
connect(rename, &QPushButton::clicked, this, [=]{
|
||||
setFixedHeight(300);
|
||||
stack->setCurrentWidget(page2);
|
||||
textEdit->setFocus();
|
||||
});
|
||||
connect(cancel2, &QPushButton::clicked, this, &KyFileDialogRename::reject);
|
||||
connect(ensure2, &QPushButton::clicked, this, [=, &error]{
|
||||
|
@ -444,110 +222,21 @@ void KyFileDialogRename::handle(Peony::FileOperationError &error)
|
|||
accept();
|
||||
});
|
||||
|
||||
connect(cancel, &QPushButton::clicked, this, &KyFileDialogRename::reject);
|
||||
|
||||
connect(skip, &QPushButton::clicked, this, [=, &error]{
|
||||
error.respCode = Peony::ExceptionResponse::IgnoreOne;
|
||||
accept();
|
||||
});
|
||||
connect(skipAll, &QPushButton::clicked, this, [=, &error]{
|
||||
error.respCode = Peony::ExceptionResponse::IgnoreAll;
|
||||
accept();
|
||||
});
|
||||
connect(textEdit, &RenameEditor::returnPressed, ensure2, &QPushButton::click);
|
||||
|
||||
if (!exec()) {
|
||||
error.respCode = responseCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const QString KyFileDialogRename::truncateDestFileName(const QString &uri, const int cateType)
|
||||
{
|
||||
QFileInfo file(uri);
|
||||
auto newName = Peony::FileUtils::getNonSuffixedBaseNameFromUri(uri);
|
||||
QString baseName = Peony::FileUtils::getUriBaseName(uri);
|
||||
baseName = Peony::FileUtils::urlDecode(baseName);
|
||||
auto destDirUri = Peony::FileUtils::getParentUri(uri);
|
||||
auto fsType = Peony::FileUtils::getFsTypeFromFile(uri);
|
||||
bool setLimitBytes = true;
|
||||
if (fsType.contains("ntfs")) {
|
||||
setLimitBytes = false;
|
||||
}
|
||||
auto suffix = baseName;
|
||||
suffix = suffix.remove(newName);
|
||||
newName.remove(suffix);
|
||||
|
||||
QString truncatedText;
|
||||
QString destName;
|
||||
if (setLimitBytes) {
|
||||
bool useForceChop = false;
|
||||
if (suffix.toLocal8Bit().count() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
qWarning()<<"suffix too long:"<<uri<<"use force chop instead";
|
||||
useForceChop = true;
|
||||
} else if (newName == baseName) {
|
||||
qWarning()<<"failed to truncate suffix of"<<uri<<", use force chop instead";
|
||||
useForceChop = true;
|
||||
} else if (file.isDir()) {
|
||||
useForceChop = true;
|
||||
}
|
||||
if (useForceChop) {
|
||||
newName = baseName;
|
||||
int len = newName.length();
|
||||
if (Peony::TurnCateType::Post == cateType) {
|
||||
while (newName.toLocal8Bit().count() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
newName.chop(1);
|
||||
}
|
||||
truncatedText = baseName.right(len - newName.length());
|
||||
destName = newName + "<s>" + truncatedText + "</s>";
|
||||
} else if (Peony::TurnCateType::Front == cateType) {
|
||||
while (newName.toLocal8Bit().count() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
newName.remove(0,1);
|
||||
}
|
||||
truncatedText = baseName.left(len - newName.length());
|
||||
destName = "<s>" + truncatedText + "</s>" + newName;
|
||||
}
|
||||
} else {
|
||||
QString tmp = newName;
|
||||
int len = tmp.length();
|
||||
int limitBytes = PEONY_TRUNCATE_NAME_LIMIT - suffix.toLocal8Bit().count();
|
||||
if (Peony::TurnCateType::Post == cateType) {
|
||||
while (newName.toLocal8Bit().count() > limitBytes) {
|
||||
newName.chop(1);
|
||||
}
|
||||
truncatedText = tmp.right(len - newName.length());
|
||||
destName = newName + "<s>" + truncatedText + "</s>";
|
||||
} else if (Peony::TurnCateType::Front == cateType){
|
||||
while (newName.toLocal8Bit().count() > limitBytes) {
|
||||
newName.remove(0,1);
|
||||
}
|
||||
truncatedText = tmp.left(len - newName.length());
|
||||
destName = "<s>" + truncatedText + "</s>" + newName;
|
||||
}
|
||||
destName = destName + suffix;
|
||||
}
|
||||
} else {
|
||||
bool useForceChop = false;
|
||||
if (suffix.length() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
qWarning()<<"suffix too long:"<<uri<<"use force chop instead";
|
||||
useForceChop = true;
|
||||
} else if (newName == baseName) {
|
||||
qWarning()<<"failed to truncate suffix of"<<uri<<", use force chop instead";
|
||||
useForceChop = true;
|
||||
} else if (file.isDir()) {
|
||||
useForceChop = true;
|
||||
}
|
||||
if (useForceChop) {
|
||||
newName = baseName;
|
||||
while (newName.length() > PEONY_TRUNCATE_NAME_LIMIT) {
|
||||
newName.chop(1);
|
||||
}
|
||||
int len = baseName.length();
|
||||
truncatedText = baseName.right(len - newName.length());
|
||||
destName = newName + "<s>" + truncatedText + "</s>";
|
||||
} else {
|
||||
QString tmp = newName;
|
||||
int limitBytes = PEONY_TRUNCATE_NAME_LIMIT - suffix.length();
|
||||
while (newName.length() > limitBytes) {
|
||||
newName.chop(1);
|
||||
}
|
||||
int len = tmp.length();
|
||||
truncatedText = tmp.right(len - newName.length());
|
||||
destName = newName + "<s>" + truncatedText + "</s>";
|
||||
destName = destName + suffix;
|
||||
}
|
||||
}
|
||||
return destName;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,24 +30,14 @@
|
|||
#include "kyfileoperationdialog.h"
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
|
||||
namespace Peony {
|
||||
enum TurnCateType {
|
||||
Post = 0,
|
||||
Front,
|
||||
};
|
||||
}
|
||||
|
||||
class KyFileDialogRename : public KyFileOperationDialog, public Peony::FileOperationErrorHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyFileDialogRename(QWidget *parent = nullptr);
|
||||
|
||||
void handle(Peony::FileOperationError &error) override;
|
||||
const QString truncateDestFileName(const QString &uri, const int cateType);
|
||||
QWidget *m_currentWidget = nullptr;
|
||||
|
||||
void handle(Peony::FileOperationError &error) override;
|
||||
private:
|
||||
QDBusInterface *m_statusManagerDBus = nullptr;
|
||||
};
|
||||
|
|
|
@ -79,7 +79,6 @@ Peony::FileOperationErrorDialogBase::FileOperationErrorDialogBase(QDialog *paren
|
|||
closebtn->setProperty ("isWindowButton", 0x02);
|
||||
closebtn->setIconSize (QSize(16, 16));
|
||||
closebtn->setIcon (QIcon::fromTheme("window-close-symbolic"));
|
||||
closebtn->setToolTip(tr("Close"));
|
||||
|
||||
headerLayout->addStretch ();
|
||||
// headerLayout->setSpacing (1);
|
||||
|
@ -208,15 +207,7 @@ QPushButton *Peony::FileOperationErrorDialogBase::addButton(QString name)
|
|||
{
|
||||
if (!name.isNull () && !name.isEmpty ()) {
|
||||
QPushButton* b = new QPushButton(name);
|
||||
b->setContentsMargins(0, 0, 0, 0);
|
||||
int buttonSize = qMax(96, b->sizeHint().width());
|
||||
b->resize(buttonSize, b->width());
|
||||
|
||||
connect(this, &FileOperationErrorDialogBase::fontChanged, b, [=]{
|
||||
int buttonSize = qMax(96, b->sizeHint().width());
|
||||
b->resize(buttonSize, b->width());
|
||||
});
|
||||
|
||||
b->setMinimumWidth(96);
|
||||
m_buttonRight->addWidget (b, Qt::AlignRight | Qt::AlignVCenter);
|
||||
return b;
|
||||
}
|
||||
|
@ -239,7 +230,6 @@ bool Peony::FileOperationErrorDialogBase::event(QEvent *event)
|
|||
{
|
||||
if (event->type() == QEvent::FontChange || event->type() == QEvent::ApplicationFontChange) {
|
||||
adjustTextContent();
|
||||
Q_EMIT this->fontChanged();
|
||||
}
|
||||
return QDialog::event(event);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@ public:
|
|||
|
||||
Q_SIGNALS:
|
||||
void cancel();
|
||||
void fontChanged();
|
||||
|
||||
protected:
|
||||
FileOperationError* m_error = nullptr;
|
||||
|
|
|
@ -31,22 +31,13 @@
|
|||
#include <file-utils.h>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include "sound-effect.h"
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
#include "ksoundeffects.h"
|
||||
#endif
|
||||
|
||||
#include "file-operation-dialog/kyfiledialogrename.h"
|
||||
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
using namespace kdk;
|
||||
#endif
|
||||
|
||||
static QPixmap drawSymbolicColoredPixmap (const QPixmap& source);
|
||||
|
||||
static QString formatGerrorString (const Peony::FileOperationError* error);
|
||||
|
||||
static const int ELIDE_TEXT_LENGTH = 960;
|
||||
|
||||
|
||||
Peony::FileOperationErrorDialogConflict::FileOperationErrorDialogConflict(FileOperationErrorDialogBase *parent)
|
||||
: FileOperationErrorDialogBase(parent)
|
||||
|
@ -228,21 +219,15 @@ Peony::FileOperationErrorDialogWarning::~FileOperationErrorDialogWarning()
|
|||
void Peony::FileOperationErrorDialogWarning::handle(Peony::FileOperationError &error)
|
||||
{
|
||||
m_error = &error;
|
||||
//SoundEffect::getInstance()->copyOrMoveFailedMusic();
|
||||
//Task#152997, use sdk play sound
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
kdk::KSoundEffects::playSound(SoundType::OPERATION_UNSUPPORTED);
|
||||
#endif
|
||||
SoundEffect::getInstance()->copyOrMoveFailedMusic();
|
||||
QStyleOptionViewItem opt;
|
||||
if (nullptr != m_error->errorStr) {
|
||||
auto errorText = m_error->errorStr;
|
||||
errorText.replace("\n", "<br>");
|
||||
QString htmlString = QString("<p>%1</p>")
|
||||
.arg(opt.fontMetrics.elidedText(m_error->errorStr/*.toHtmlEscaped()*/, Qt::ElideMiddle, ELIDE_TEXT_LENGTH).toHtmlEscaped());
|
||||
.arg(opt.fontMetrics.elidedText(m_error->errorStr/*.toHtmlEscaped()*/, Qt::ElideMiddle, 480).toHtmlEscaped());
|
||||
setText(htmlString);
|
||||
} else {
|
||||
QString htmlString = QString("<p>%1</p>")
|
||||
.arg(opt.fontMetrics.elidedText(tr("Make sure the disk is not full or write protected and that the file is not protected"), Qt::ElideMiddle, ELIDE_TEXT_LENGTH).toHtmlEscaped());
|
||||
.arg(opt.fontMetrics.elidedText(tr("Make sure the disk is not full or write protected and that the file is not protected"), Qt::ElideMiddle, 480).toHtmlEscaped());
|
||||
setText(htmlString);
|
||||
}
|
||||
|
||||
|
@ -350,11 +335,11 @@ void Peony::FileOperationErrorDialogNotSupported::handle(Peony::FileOperationErr
|
|||
QStyleOptionViewItem opt;
|
||||
if (nullptr != m_error->errorStr) {
|
||||
QString htmlString = QString("<p>%1</p>")
|
||||
.arg(opt.fontMetrics.elidedText(m_error->errorStr.toHtmlEscaped(), Qt::ElideMiddle, ELIDE_TEXT_LENGTH).toHtmlEscaped());
|
||||
.arg(opt.fontMetrics.elidedText(m_error->errorStr.toHtmlEscaped(), Qt::ElideMiddle, 480).toHtmlEscaped());
|
||||
setText(htmlString);
|
||||
} else {
|
||||
QString htmlString = QString("<p>%1</p>")
|
||||
.arg(opt.fontMetrics.elidedText(tr("Make sure the disk is not full or write protected and that the file is not protected"), Qt::ElideMiddle, ELIDE_TEXT_LENGTH).toHtmlEscaped());
|
||||
.arg(opt.fontMetrics.elidedText(tr("Make sure the disk is not full or write protected and that the file is not protected"), Qt::ElideMiddle, 480).toHtmlEscaped());
|
||||
setText(htmlString);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,11 +69,7 @@ enum ExceptionResponse {
|
|||
Force, // Force operation
|
||||
ForceAll, //
|
||||
RenameOne, // usually used for long name handling, etc...
|
||||
RenameAll, // not used yet
|
||||
TruncateOne, // truncate
|
||||
TruncateAll,
|
||||
SaveOne, //long name file save as other paht
|
||||
SaveAll,
|
||||
RenameAll // not used yet
|
||||
};
|
||||
|
||||
typedef enum{
|
||||
|
@ -88,7 +84,6 @@ typedef enum{
|
|||
FileOpCount, //file or dir file count
|
||||
FileOpCreateTemp, //create file or dir
|
||||
FileOpRenameToHideFile, // file or dir rename to a hide file
|
||||
FileOpRenameChangeType, // change file suffix cause type change
|
||||
FileOpNum,
|
||||
}FileOpsType;
|
||||
|
||||
|
|
|
@ -151,18 +151,14 @@ bool FileOperationHelper::discWriteOperation(const QStringList &sourUrisList, co
|
|||
//开启udfclient的初始化
|
||||
right = udfwrite->startUdfClient(&errinfo);
|
||||
if (!right) {
|
||||
if (udfwrite->isDiscRunning()) {
|
||||
m_disc_error_msg = errinfo;
|
||||
} else {
|
||||
m_disc_error_msg = tr("Burn failed");
|
||||
}
|
||||
m_disc_error_msg = errinfo;
|
||||
qDebug() << "udf clint error message: " << errinfo;
|
||||
for (QString filePath : list) {
|
||||
QFile file(filePath);
|
||||
if (file.exists()) {
|
||||
file.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
udfwrite->closeUdfClient();
|
||||
free(errinfo);
|
||||
return false;
|
||||
|
@ -172,7 +168,7 @@ bool FileOperationHelper::discWriteOperation(const QStringList &sourUrisList, co
|
|||
qDebug() << "udf write list:" << list << "dest name" << destName;
|
||||
right = udfwrite->writeMultiData(&errinfo, list, destName);
|
||||
if (!right) {
|
||||
m_disc_error_msg = tr("Burn failed");
|
||||
m_disc_error_msg = errinfo;
|
||||
qDebug() << "udf write error message: " << errinfo;
|
||||
for (QString filePath : list) {
|
||||
QFile file(filePath);
|
||||
|
|
|
@ -29,15 +29,12 @@
|
|||
#include <QApplication>
|
||||
#include <QTimer>
|
||||
#include <QtConcurrent>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusConnection>
|
||||
|
||||
#include "file-copy-operation.h"
|
||||
#include "file-delete-operation.h"
|
||||
#include "file-link-operation.h"
|
||||
#include "file-move-operation.h"
|
||||
#include "file-rename-operation.h"
|
||||
#include "file-batch-rename-operation.h"
|
||||
#include "file-trash-operation.h"
|
||||
#include "file-untrash-operation.h"
|
||||
|
||||
|
@ -50,10 +47,6 @@
|
|||
|
||||
#include "properties-window.h"
|
||||
#include "sound-effect.h"
|
||||
#include <kballontip.h>
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
#include "ksoundeffects.h"
|
||||
#endif
|
||||
|
||||
#include <QVector4D>
|
||||
|
||||
|
@ -61,9 +54,6 @@
|
|||
#include <unistd.h>
|
||||
|
||||
using namespace Peony;
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
using namespace kdk;
|
||||
#endif
|
||||
|
||||
static FileOperationManager *global_instance = nullptr;
|
||||
|
||||
|
@ -75,8 +65,7 @@ FileOperationManager::FileOperationManager(QObject *parent) : QObject(parent)
|
|||
qRegisterMetaType<Peony::GErrorWrapperPtr>("Peony::GErrorWrapperPtr&");
|
||||
m_thread_pool = new QThreadPool(this);
|
||||
m_progressbar = FileOperationProgressBar::getInstance();
|
||||
m_mount_operation_list = new QHash<QString, totalOperationInfo>;
|
||||
m_operation_use_list = new QHash<FileOperation*, currentOpertionInfo>;
|
||||
|
||||
if (!m_allow_parallel) {
|
||||
//Imitating queue execution.
|
||||
m_thread_pool->setMaxThreadCount(1);
|
||||
|
@ -92,33 +81,10 @@ FileOperationManager::FileOperationManager(QObject *parent) : QObject(parent)
|
|||
if (pconnection) {
|
||||
g_dbus_connection_signal_subscribe(pconnection, "org.freedesktop.login1", "org.freedesktop.login1.Manager", "PrepareForSleep", "/org/freedesktop/login1", NULL, G_DBUS_SIGNAL_FLAGS_NONE, systemSleep, this, NULL);
|
||||
}
|
||||
|
||||
QDBusConnection conn = QDBusConnection::sessionBus();
|
||||
if (!conn.isConnected()) {
|
||||
qCritical()<<"failed to init mDbusDateServer, can not connect to session dbus";
|
||||
return;
|
||||
}
|
||||
|
||||
m_iface = new QDBusInterface("org.ukui.peony", "/org/ukui/peony", "org.ukui.peony", QDBusConnection::sessionBus());
|
||||
if (!m_iface->isValid()){
|
||||
qCritical() << "Create /org/ukui/peony Interface Failed " << QDBusConnection::sessionBus().lastError();
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusConnection::sessionBus().connect("org.ukui.peony",
|
||||
"/org/ukui/peony",
|
||||
"org.ukui.peony",
|
||||
"opreateFinishedOfEngrampa",
|
||||
this,
|
||||
SLOT(slot_opreateFinishedOfEngrampa(QString, bool)));
|
||||
}
|
||||
|
||||
FileOperationManager::~FileOperationManager()
|
||||
{
|
||||
if(m_iface){
|
||||
delete m_iface;
|
||||
m_iface = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -159,7 +125,7 @@ QStringList FileOperationManager::getFilesOpenedByProc(const QString &procName)
|
|||
QStringList occupiedFiles;
|
||||
|
||||
QProcess process;
|
||||
QString cmd = QString("/usr/bin/lsof -c %1").arg(procName);
|
||||
QString cmd = QString("lsof -c %1").arg(procName);
|
||||
process.start(cmd);
|
||||
process.waitForFinished();
|
||||
QString infos = QString(process.readAll());
|
||||
|
@ -227,6 +193,7 @@ void FileOperationManager::startOperation(FileOperation *operation, bool addToHi
|
|||
}
|
||||
//end
|
||||
|
||||
|
||||
if (operationInfo.get()->operationType() == FileOperationInfo::Trash) {
|
||||
auto value = GlobalSettings::getInstance()->getValue("showTrashDialog");
|
||||
if (value.isValid()) {
|
||||
|
@ -316,141 +283,31 @@ void FileOperationManager::startOperation(FileOperation *operation, bool addToHi
|
|||
}
|
||||
|
||||
start:
|
||||
static bool oldQuitOnLastWindow = QApplication::quitOnLastWindowClosed();
|
||||
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
|
||||
connect(operation, &FileOperation::operationFinished, this, [=]() {
|
||||
operation->notifyFileWatcherOperationFinished();
|
||||
if (qApp->property("isPeony").toBool()) {
|
||||
auto settings = GlobalSettings::getInstance();
|
||||
bool runbackend = settings->getInstance()->getValue(RESIDENT_IN_BACKEND).toBool();
|
||||
QApplication::setQuitOnLastWindowClosed(!runbackend);
|
||||
QTimer::singleShot(1000, this, [=]() {
|
||||
int last_op_count = m_thread_pool->children().count();
|
||||
if (last_op_count == 0) {
|
||||
if (qApp->allWidgets().isEmpty()) {
|
||||
if (!runbackend) {
|
||||
qApp->quit();
|
||||
}
|
||||
auto settings = GlobalSettings::getInstance();
|
||||
bool runbackend = settings->getInstance()->getValue(RESIDENT_IN_BACKEND).toBool();
|
||||
QApplication::setQuitOnLastWindowClosed(!runbackend);
|
||||
|
||||
QTimer::singleShot(1000, this, [=]() {
|
||||
int last_op_count = m_thread_pool->children().count();
|
||||
if (last_op_count == 0) {
|
||||
if (qApp->allWidgets().isEmpty()) {
|
||||
if (!runbackend) {
|
||||
qApp->quit();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
QApplication::setQuitOnLastWindowClosed(oldQuitOnLastWindow);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
|
||||
|
||||
|
||||
bool allowParallel = m_allow_parallel;
|
||||
|
||||
connect(operation, &FileOperation::operationTotalFileSize, this, [=](const qint64& total_file_size) {
|
||||
// fix #171449
|
||||
if (m_progressbar->isHidden()) {
|
||||
m_progressbar->m_error = true;
|
||||
}
|
||||
|
||||
//story 19796 空间不足时预处理
|
||||
// Check if the operation is a copy or move operation
|
||||
auto info = operation->getOperationInfo();
|
||||
if (!info || (info->operationType() != FileOperationInfo::Copy
|
||||
&& info->operationType() != FileOperationInfo::Move)) {
|
||||
return;
|
||||
}
|
||||
// Check if the operation is already in the list of operations
|
||||
if (m_operation_use_list->contains(operation)) {
|
||||
qWarning() << "this operation already exist";
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the destination path of the operation
|
||||
auto destGfile = g_file_new_for_uri(info->target().toUtf8().constData());
|
||||
auto destPath = g_file_get_path(destGfile);
|
||||
|
||||
//Get the available disk space using QStorageInfo
|
||||
QStorageInfo storage(destPath);
|
||||
|
||||
// Check if the file path is mounted correctly
|
||||
if (!storage.isValid()) {
|
||||
if (m_progressbar->m_error) {
|
||||
m_progressbar->m_error = false;
|
||||
}
|
||||
qWarning() << "The file path is not mounted correctly";
|
||||
return;
|
||||
}
|
||||
|
||||
quint64 diskFreeSpace = storage.bytesAvailable();
|
||||
|
||||
// Check if there is an error getting the disk free space
|
||||
if (0 >= diskFreeSpace) {
|
||||
if (m_progressbar->m_error) {
|
||||
m_progressbar->m_error = false;
|
||||
}
|
||||
qWarning() << "get disk free space error!";
|
||||
return;
|
||||
}
|
||||
|
||||
QString mountRootName = storage.rootPath();
|
||||
|
||||
// Calculate the total size of the operation
|
||||
qint64 currentTotalSize = 0;
|
||||
totalOperationInfo totalInfo;
|
||||
|
||||
// Check if the mount root name is already in the list of mount operations
|
||||
if (m_mount_operation_list->contains(mountRootName)) {
|
||||
qint64 currentUseSize = m_mount_operation_list->value(mountRootName).totalSize;
|
||||
currentTotalSize = currentUseSize + total_file_size;
|
||||
totalInfo.totalSize = currentTotalSize;
|
||||
totalInfo.preoccupationSize = m_mount_operation_list->value(mountRootName).preoccupationSize;
|
||||
} else {
|
||||
currentTotalSize = total_file_size;
|
||||
totalInfo.totalSize = currentTotalSize;
|
||||
totalInfo.preoccupationSize = diskFreeSpace;
|
||||
}
|
||||
|
||||
// Check if there is enough disk space for the operation
|
||||
if(currentTotalSize > diskFreeSpace) {
|
||||
// Cancel the operation
|
||||
operation->cancel();
|
||||
|
||||
// Create an error message
|
||||
FileOperationError except;
|
||||
FileOperationErrorDialogWarning dialog;
|
||||
QString name;
|
||||
|
||||
if (mountRootName == "/") {
|
||||
name = tr("File System");
|
||||
} else if (mountRootName == "/data") {
|
||||
name = tr("Data");
|
||||
} else {
|
||||
name = storage.name();
|
||||
}
|
||||
except.title = tr("Insufficient storage space");
|
||||
double total_file_size_gb = (double)total_file_size / (1024 * 1024 * 1024);
|
||||
double need_total_size_gb = (double)(total_file_size - totalInfo.preoccupationSize) / (1024 * 1024 * 1024);
|
||||
except.errorStr = tr("%1 no space left on device. "
|
||||
"Copy file size: %2 GB, "
|
||||
"Space needed: %3 GB.").arg(name).arg(QString::number(total_file_size_gb, 'f', 3))
|
||||
.arg(QString::number(need_total_size_gb, 'f', 3));
|
||||
|
||||
// Display the error message
|
||||
dialog.handle(except);
|
||||
if (m_progressbar->m_error) {
|
||||
m_progressbar->m_error = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Record the operation information
|
||||
currentOpertionInfo opertionInfo;
|
||||
opertionInfo.mountRootName = mountRootName;
|
||||
opertionInfo.opertionFileSize = total_file_size;
|
||||
totalInfo.preoccupationSize -= total_file_size;
|
||||
m_mount_operation_list->insert(mountRootName, totalInfo);
|
||||
m_operation_use_list->insert(operation, opertionInfo);
|
||||
|
||||
m_progressbar->m_error = false;
|
||||
m_progressbar->showDelay(300);
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
|
||||
auto opType = operationInfo->operationType();
|
||||
switch (opType) {
|
||||
case FileOperationInfo::Trash:
|
||||
|
@ -507,36 +364,11 @@ start:
|
|||
proc->connect(proc, &ProgressBar::resume, operation, &FileOperation::operationResume);
|
||||
|
||||
operation->connect(operation, &FileOperation::errored, [=]() {
|
||||
if (operation->getOperationInfo()->m_type == FileOperationInfo::Copy || operation->getOperationInfo()->m_type == FileOperationInfo::Move) {
|
||||
return;
|
||||
}
|
||||
operation->setHasError(true);
|
||||
});
|
||||
|
||||
operation->connect(operation, &FileOperation::errored, this, &FileOperationManager::handleError, Qt::BlockingQueuedConnection);
|
||||
operation->connect(operation, &FileOperation::operationFinished, this, [=](){
|
||||
//story 19796,后续数据处理
|
||||
if (m_operation_use_list->contains(operation)) {
|
||||
// Get the operation info
|
||||
currentOpertionInfo operationInfo = m_operation_use_list->value(operation);
|
||||
// Get the mount root name and total size of the operation
|
||||
QString name = operationInfo.mountRootName;
|
||||
quint64 size = operationInfo.opertionFileSize;
|
||||
// Calculate the new size of the mount operation list
|
||||
size = m_mount_operation_list->value(name).totalSize - size;
|
||||
if (size == 0){
|
||||
m_mount_operation_list->remove(name);
|
||||
} else {
|
||||
totalOperationInfo info;
|
||||
info.totalSize = size;
|
||||
info.preoccupationSize = m_mount_operation_list->value(name).preoccupationSize;
|
||||
if (operation->isCancelled()) {
|
||||
info.preoccupationSize += operationInfo.opertionFileSize;
|
||||
}
|
||||
m_mount_operation_list->insert(name, info);
|
||||
}
|
||||
m_operation_use_list->remove(operation);
|
||||
}
|
||||
Q_EMIT this->operationFinished(operation->getOperationInfo(), !operation->hasError());
|
||||
if (operation->hasError()) {
|
||||
this->clearHistory();
|
||||
|
@ -547,24 +379,15 @@ start:
|
|||
auto info = operation->getOperationInfo();
|
||||
if (!info)
|
||||
return;
|
||||
if (info->m_type == FileOperationInfo::BatchRename) {
|
||||
info->m_type = FileOperationInfo::BatchRenameInternal;
|
||||
}
|
||||
if (info->operationType() != FileOperationInfo::Delete) {
|
||||
//fix bug#162024, play sound when operation finished
|
||||
if ((info->operationType() == FileOperationInfo::Copy ||
|
||||
info->operationType() == FileOperationInfo::Move) &&
|
||||
! info->m_has_error){
|
||||
//SoundEffect::getInstance()->copyOrMoveSucceedMusic();
|
||||
//Task#152997, use sdk play sound
|
||||
#ifdef KY_SDK_SOUND_EFFECTS
|
||||
kdk::KSoundEffects::playSound(SoundType::OPERATION_FILE);
|
||||
#endif
|
||||
}
|
||||
if(info->getOperationRecording()) {
|
||||
m_undo_stack.push(info);
|
||||
m_redo_stack.clear();
|
||||
if (info->operationType() == FileOperationInfo::Copy ||
|
||||
info->operationType() == FileOperationInfo::Move){
|
||||
SoundEffect::getInstance()->copyOrMoveSucceedMusic();
|
||||
}
|
||||
|
||||
m_undo_stack.push(info);
|
||||
m_redo_stack.clear();
|
||||
} else {
|
||||
this->clearHistory();
|
||||
}
|
||||
|
@ -603,20 +426,6 @@ start:
|
|||
m_thread_pool->start(operation);
|
||||
}
|
||||
|
||||
connect(operation, &FileOperation::operationWithoutRecording, this, [=]() {
|
||||
auto info = operation->getOperationInfo();
|
||||
if (info->getOperationRecording()) {
|
||||
info->setOperationRecording(false);
|
||||
}
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
connect(operation, &FileOperation::operationSaveAsLongNameFile, this, [=](const QString &uri){
|
||||
QString text = QString(tr("The long name file is saved to %1")).arg(uri);
|
||||
QMessageBox::information(nullptr,nullptr,text);
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
connect(operation, &FileOperation::operationInfoMsgBox, this, [=](const QString &msg){
|
||||
QString text = msg;
|
||||
QMessageBox::information(nullptr,nullptr,text);
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
Q_EMIT this->operationStarted(operation->getOperationInfo());
|
||||
|
||||
m_progressbar->showDelay();
|
||||
|
@ -664,10 +473,6 @@ void FileOperationManager::startUndoOrRedo(std::shared_ptr<FileOperationInfo> in
|
|||
op = new FileUntrashOperation(info->m_src_uris);
|
||||
break;
|
||||
}
|
||||
case FileOperationInfo::BatchRenameInternal: {
|
||||
op = new FileBatchRenameInternalOperation(info);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -843,36 +648,6 @@ void FileOperationManager::manuallyNotifyDirectoryChanged(FileOperationInfo *inf
|
|||
}
|
||||
}
|
||||
|
||||
void FileOperationManager::slot_opreateFinishedOfEngrampa(const QString &path, bool finish)
|
||||
{
|
||||
if(!finish || path.isEmpty())
|
||||
return;
|
||||
|
||||
if(!path.startsWith("smb://") && !path.startsWith("ftp://") && !path.startsWith("sftp://"))
|
||||
return;
|
||||
|
||||
for (auto watcher : m_watchers) {
|
||||
if(watcher->supportMonitor())
|
||||
continue;
|
||||
QString watcherUri = watcher->currentUri();
|
||||
//'file:///run/user/1000/gvfs/smb-share:server=xxx,share=xxx/' converted to 'smb://xxx'
|
||||
if(watcherUri.startsWith("file:///run/user/1000/gvfs/smb-share:")){
|
||||
GFile * file = g_file_new_for_uri(watcherUri.toUtf8().data());
|
||||
char *uri = g_file_get_uri(file);
|
||||
if (uri) {
|
||||
watcherUri = uri;
|
||||
}
|
||||
g_object_unref(file);
|
||||
g_free(uri);
|
||||
}
|
||||
//auto watcherDecodeUri = FileUtils::urlDecode(watcherUri);
|
||||
//auto destDecodePath = FileUtils::urlDecode(path);
|
||||
if (watcherUri == path || watcherUri == path + QString("/")){
|
||||
watcher->requestUpdateDirectory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: get opposite info correcty.
|
||||
FileOperationInfo::FileOperationInfo(QStringList srcUris,
|
||||
QString destDirUri,
|
||||
|
@ -951,11 +726,6 @@ void FileOperationInfo::oppositeInfoConstruct(Type type)
|
|||
commonOppositeInfoConstruct();
|
||||
break;
|
||||
}
|
||||
case BatchRenameInternal:
|
||||
case BatchRename: {
|
||||
m_opposite_type = BatchRenameInternal;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
m_opposite_type = Other;
|
||||
}
|
||||
|
@ -996,13 +766,6 @@ void FileOperationInfo::RenameOppositeInfoConstruct()
|
|||
m_dest_uris<<src;
|
||||
m_src_dir_uri = m_dest_dir_uri;
|
||||
}
|
||||
|
||||
void FileOperationInfo::BatchRenameOppositeInfoConstruct()
|
||||
{
|
||||
m_dest_dir_uris = m_src_uris;
|
||||
m_src_dir_uri = m_dest_dir_uri;
|
||||
}
|
||||
|
||||
void FileOperationInfo::UntrashOppositeInfoConstruct()
|
||||
{
|
||||
m_dest_uris = m_dest_dir_uris;
|
||||
|
@ -1020,10 +783,9 @@ void FileOperationInfo::trashOppositeInfoConstruct()
|
|||
|
||||
std::shared_ptr<FileOperationInfo> FileOperationInfo::getOppositeInfo(FileOperationInfo *info) {
|
||||
|
||||
auto oppositeInfo = std::make_shared<FileOperationInfo>(info->m_dest_uris, info->m_src_dir_uri, info->m_opposite_type);
|
||||
oppositeInfo->m_drop_action = info->m_drop_action;
|
||||
auto oppositeInfo = std::make_shared<FileOperationInfo>(info->m_dest_uris, info->m_src_dir_uri, m_opposite_type);
|
||||
if (info->m_drop_action == Qt::TargetMoveAction) {
|
||||
//oppositeInfo->m_drop_action = Qt::TargetMoveAction;
|
||||
oppositeInfo->m_drop_action = Qt::TargetMoveAction;
|
||||
oppositeInfo->m_type = FileOperationInfo::Move;
|
||||
}
|
||||
QMap<QString, QString> oppsiteMap;
|
||||
|
@ -1034,19 +796,10 @@ std::shared_ptr<FileOperationInfo> FileOperationInfo::getOppositeInfo(FileOperat
|
|||
oppositeInfo->m_node_map = oppsiteMap;
|
||||
oppositeInfo->m_newname = this->m_oldname;
|
||||
oppositeInfo->m_oldname = this->m_newname;
|
||||
oppositeInfo->m_newnames = this->m_newnames;
|
||||
oppositeInfo->m_oldnames = this->m_oldnames;
|
||||
|
||||
return oppositeInfo;
|
||||
}
|
||||
|
||||
void FileOperationInfo::setOperationRecording(bool state)
|
||||
{
|
||||
if (m_operation_recording != state) {
|
||||
m_operation_recording = state;
|
||||
}
|
||||
}
|
||||
|
||||
// S3/S4
|
||||
void FileOperationManager::systemSleep (GDBusConnection *connection, const gchar *senderName, const gchar *objectPath, const gchar *interfaceName, const gchar *signalName, GVariant *parameters, gpointer udata)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "peony-core_global.h"
|
||||
#include "file-operation-progress-bar.h"
|
||||
#include "file-operation-error-dialogs.h"
|
||||
class QDBusInterface;
|
||||
|
||||
|
||||
namespace Peony {
|
||||
|
||||
|
@ -82,8 +82,6 @@ Q_SIGNALS:
|
|||
void operationStarted(std::shared_ptr<FileOperationInfo> info);
|
||||
void operationFinished(std::shared_ptr<FileOperationInfo> info, bool successed);
|
||||
|
||||
void errored(FileOperationError& error);
|
||||
|
||||
public Q_SLOTS:
|
||||
void startOperation(FileOperation *operation, bool addToHistory = true);
|
||||
void startUndoOrRedo(std::shared_ptr<FileOperationInfo> info);
|
||||
|
@ -134,26 +132,12 @@ public Q_SLOTS:
|
|||
* not support monitoring.
|
||||
*/
|
||||
void manuallyNotifyDirectoryChanged(FileOperationInfo *info);
|
||||
|
||||
void slot_opreateFinishedOfEngrampa(const QString& path, bool finish);/* hotfix bug#188622 【文件管理器】连接共享文件夹后进行压缩/解压缩操作,需要手动刷新后才会显示 */
|
||||
|
||||
private:
|
||||
explicit FileOperationManager(QObject *parent = nullptr);
|
||||
~FileOperationManager();
|
||||
static void systemSleep (GDBusConnection* connection, const gchar* senderName, const gchar* objectPath, const gchar* interfaceName, const gchar* signalName, GVariant* parameters, gpointer udata);
|
||||
|
||||
private:
|
||||
struct currentOpertionInfo
|
||||
{
|
||||
QString mountRootName;
|
||||
quint64 opertionFileSize;
|
||||
};
|
||||
struct totalOperationInfo
|
||||
{
|
||||
quint64 preoccupationSize;
|
||||
quint64 totalSize;
|
||||
};
|
||||
|
||||
QThreadPool *m_thread_pool;
|
||||
bool m_allow_parallel = false;
|
||||
QVector<FileWatcher *> m_watchers;
|
||||
|
@ -161,9 +145,6 @@ private:
|
|||
FileOperationProgressBar *m_progressbar = nullptr;
|
||||
QStack<std::shared_ptr<FileOperationInfo>> m_undo_stack;
|
||||
QStack<std::shared_ptr<FileOperationInfo>> m_redo_stack;
|
||||
QHash<QString, totalOperationInfo> *m_mount_operation_list = nullptr;
|
||||
QHash<FileOperation*, currentOpertionInfo> *m_operation_use_list = nullptr;
|
||||
QDBusInterface* m_iface = nullptr;
|
||||
};
|
||||
|
||||
class FileOperationInfo : public QObject
|
||||
|
@ -186,8 +167,6 @@ public:
|
|||
CreateTxt,//delete
|
||||
CreateFolder,//delete
|
||||
CreateTemplate,//delete
|
||||
BatchRename,//batch rename
|
||||
BatchRenameInternal,
|
||||
Other//nothing to do
|
||||
};
|
||||
|
||||
|
@ -198,14 +177,8 @@ public:
|
|||
void commonOppositeInfoConstruct();
|
||||
void LinkOppositeInfoConstruct();
|
||||
void RenameOppositeInfoConstruct();
|
||||
void BatchRenameOppositeInfoConstruct();
|
||||
void UntrashOppositeInfoConstruct();
|
||||
void trashOppositeInfoConstruct();
|
||||
void setOperationRecording(bool state);
|
||||
|
||||
bool getOperationRecording() {
|
||||
return m_operation_recording;
|
||||
}
|
||||
|
||||
Type operationType() {
|
||||
return m_type;
|
||||
|
@ -241,13 +214,8 @@ public:
|
|||
QString m_oldname = nullptr;
|
||||
QString m_newname = nullptr;
|
||||
|
||||
QStringList m_oldnames;
|
||||
QStringList m_newnames;
|
||||
|
||||
bool m_has_error = false;
|
||||
|
||||
bool m_operation_recording = true;
|
||||
|
||||
//using for distiguist move action.
|
||||
Qt::DropAction m_drop_action = Qt::IgnoreAction;
|
||||
};
|
||||
|
|
|
@ -39,15 +39,10 @@ FileOperation::FileOperation(QObject *parent) : QObject (parent)
|
|||
m_cancellable_wrapper = wrapGCancellable(g_cancellable_new());
|
||||
setAutoDelete(true);
|
||||
connect(this, &FileOperation::operationPause, this, [=] () {
|
||||
m_is_pause.store(true);
|
||||
m_is_pause = true;
|
||||
});
|
||||
connect(this, &FileOperation::operationResume, this, [=] () {
|
||||
m_is_pause.store(false);
|
||||
m_wait_condition.wakeOne();
|
||||
});
|
||||
connect(this, &FileOperation::operationCancel, this, [=] () {
|
||||
m_is_pause.store(false);
|
||||
m_wait_condition.wakeOne();
|
||||
m_is_pause = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -73,14 +68,6 @@ void FileOperation::cancel()
|
|||
m_is_cancelled = true;
|
||||
}
|
||||
|
||||
void FileOperation::OperatorThreadPause()
|
||||
{
|
||||
m_mutex.lock();
|
||||
while (m_is_pause) {
|
||||
m_wait_condition.wait(&m_mutex);
|
||||
}
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
bool FileOperation::nameIsValid (QString& name)
|
||||
{
|
||||
|
@ -162,7 +149,7 @@ void FileOperation::fileSync(QString srcFile, QString destDir)
|
|||
QProcess p;
|
||||
auto shellPath = g_shell_quote(path);
|
||||
qDebug() << "DJ- start execute: " << QString("sync -f %1").arg(shellPath);
|
||||
p.start(QString("/usr/bin/sync -f %1").arg(shellPath));
|
||||
p.start(QString("sync -f %1").arg(shellPath));
|
||||
qDebug() << "DJ- execute: " << QString("sync -f %1 ok!!!").arg(shellPath);
|
||||
g_free(path);
|
||||
g_free(shellPath);
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <QObject>
|
||||
#include <QMetaType>
|
||||
#include <QRunnable>
|
||||
#include <QWaitCondition>
|
||||
|
||||
#include "gerror-wrapper.h"
|
||||
#include "gobject-template.h"
|
||||
|
@ -337,14 +336,6 @@ Q_SIGNALS:
|
|||
*/
|
||||
void operationCancel();
|
||||
|
||||
void operationTotalFileSize(const qint64& total_file_size);
|
||||
|
||||
void operationWithoutRecording();
|
||||
|
||||
void operationSaveAsLongNameFile(const QString &uri);
|
||||
|
||||
void operationInfoMsgBox(const QString &uri);
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void cancel();
|
||||
|
||||
|
@ -352,7 +343,6 @@ protected:
|
|||
void fileSync (QString srcFile, QString destFile);
|
||||
bool nameIsValid (QString& uri);
|
||||
bool makeFileNameValidForDestFS (QString& srcPath, QString& destPath, QString* newFileName);
|
||||
void OperatorThreadPause();
|
||||
|
||||
GCancellableWrapperPtr getCancellable() {
|
||||
return m_cancellable_wrapper;
|
||||
|
@ -368,10 +358,8 @@ protected:
|
|||
void sendSrcAndDestUrisOfCopyDspsFiles();
|
||||
|
||||
protected:
|
||||
QAtomicInteger<bool> m_is_pause = false;
|
||||
bool m_is_pause = false;
|
||||
QStringList m_src_uris;
|
||||
QMutex m_mutex;
|
||||
QWaitCondition m_wait_condition;
|
||||
|
||||
QStringList m_srcUrisOfCopyDspsFiles;/* 复制dsps文件的源路径列表 */
|
||||
QStringList m_destUrisOfCopyDspsFiles;/* 复制dsps文件的目的路径列表 */
|
||||
|
|
|
@ -7,7 +7,6 @@ include(file-operation-dialog/file-operation-dialog.pri)
|
|||
PKGCONFIG += gio-unix-2.0
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/file-batch-rename-operation.h \
|
||||
$$PWD/file-node.h \
|
||||
$$PWD/file-operation-helper.h \
|
||||
$$PWD/file-operation-internal-dialog.h \
|
||||
|
@ -33,7 +32,6 @@ HEADERS += \
|
|||
$$PWD/file-operation-error-dialog-base.h \
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/file-batch-rename-operation.cpp \
|
||||
$$PWD/file-node.cpp \
|
||||
$$PWD/file-operation-helper.cpp \
|
||||
$$PWD/file-operation-internal-dialog.cpp \
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include <QUrl>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QFileInfo>
|
||||
|
||||
static QString set_desktop_name (QString file, QString& name, GError** error);
|
||||
|
||||
|
@ -89,7 +88,7 @@ void FileRenameOperation::run()
|
|||
except.op = FileOpRenameToHideFile;
|
||||
except.dlgType = ED_WARNING;
|
||||
except.title = tr("File Rename warning");
|
||||
except.errorStr = tr("Are you sure to hidden this file?");
|
||||
except.errorStr = tr("The file %1%2%3 will be hidden when you refresh or change directory!").arg("\“").arg(m_new_name).arg("\”");
|
||||
|
||||
Q_EMIT errored(except);
|
||||
|
||||
|
@ -101,42 +100,9 @@ void FileRenameOperation::run()
|
|||
getOperationInfo().get()->m_dest_dir_uri = getOperationInfo().get()->sources().first();
|
||||
Q_EMIT operationFinished();
|
||||
return;
|
||||
}else{
|
||||
//fix bug#174512, can not hide file immediately
|
||||
qDebug() << "Q_EMIT updateHiddenFile:"<<m_new_name;
|
||||
Q_EMIT GlobalSettings::getInstance()->updateHiddenFile(m_new_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//task#144488, support cancel rename operation when change file type
|
||||
//修改了文件类型后缀名,提示用户改变文件类型可能导致文件不可用
|
||||
//修复新建文件夹改名错误弹框提示问题,无后缀名的文件不处理
|
||||
bool isFolder = FileUtils::getFileIsFolder(m_uri);
|
||||
if (! isFolder && (m_new_name.split(".").length() >1 || m_old_name.split(".").length() >1) &&
|
||||
m_new_name.split(".").last() != m_old_name.split(".").last()){
|
||||
FileOperationError except;
|
||||
except.srcUri = m_uri;
|
||||
except.errorType = ET_GIO;
|
||||
except.op = FileOpRenameChangeType;
|
||||
except.dlgType = ED_WARNING;
|
||||
except.title = tr("File Rename warning");
|
||||
except.errorStr = tr("When change the file suffix, the file may be invalid. "
|
||||
"Are you sure to change it ?");
|
||||
|
||||
Q_EMIT errored(except);
|
||||
|
||||
//support cancel rename operation when change file type
|
||||
if (except.respCode == Cancel) {
|
||||
cancel();
|
||||
setHasError(true);
|
||||
//未做重命名操作,恢复之前的目标文件,仍然选中原来的文件
|
||||
getOperationInfo().get()->m_dest_dir_uri = getOperationInfo().get()->sources().first();
|
||||
Q_EMIT operationFinished();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<FileInfo> fileinfo = FileInfo::fromUri(m_uri);
|
||||
if(fileinfo && !fileinfo->isDir()){
|
||||
bool showFileExtension = Peony::GlobalSettings::getInstance()->isExist(SHOW_FILE_EXTENSION)?
|
||||
|
@ -359,6 +325,7 @@ cancel:
|
|||
|
||||
}
|
||||
|
||||
#include <QFileInfo>
|
||||
QString FileRenameOperation::getFileExtensionOfFile(const QString& file)
|
||||
{
|
||||
/* 一些常见扩展名处理,特殊情况以后待完善 */
|
||||
|
|
|
@ -99,14 +99,8 @@ void FileTrashOperation::run()
|
|||
if (total_size/10 > ONE_GIB_SIZE){
|
||||
except.dlgType = ED_NOT_SUPPORTED;
|
||||
except.errorCode = G_IO_ERROR_NOT_SUPPORTED;
|
||||
except.title = "";
|
||||
//task #155670,155671 improve delete file permanently message
|
||||
except.errorStr = QObject::tr("The file is too large to be moved to the recycle bin. "
|
||||
"Do you want to permanently delete it?");
|
||||
if (m_total_count >1){
|
||||
except.errorStr = QObject::tr("These files are too large to be moved to the recycle bin. "
|
||||
"Do you want to permanently delete these %1 files?").arg(m_total_count);
|
||||
}
|
||||
except.title = tr("Can not trash");
|
||||
except.errorStr = tr("Can not trash files more than 10GB, would you like to delete it permanently?");
|
||||
|
||||
Q_EMIT errored(except);
|
||||
|
||||
|
@ -173,31 +167,19 @@ retry:
|
|||
} else {
|
||||
if (err->code == G_IO_ERROR_NOT_SUPPORTED) {
|
||||
except.dlgType = ED_NOT_SUPPORTED;
|
||||
//task #155670,155671 improve delete file permanently message
|
||||
except.errorStr = QObject::tr("Are you sure you want to permanently delete this file?"
|
||||
" Once deletion begins, "
|
||||
"the file will not be recoverable.");
|
||||
if (m_total_count >1){
|
||||
except.errorStr = QObject::tr("Are you sure you want to permanently delete these %1 files?"
|
||||
" Once deletion begins, "
|
||||
"these file will not be recoverable.").arg(m_total_count);
|
||||
}
|
||||
//auto fileName = g_file_get_basename(srcFile.get()->get());
|
||||
except.errorStr = tr("Can not trash this file, would you like to delete it permanently?");
|
||||
// if (fileName) {
|
||||
// g_free(fileName);
|
||||
// }
|
||||
} else if (err->code == G_IO_ERROR_FILENAME_TOO_LONG) {
|
||||
GError *error = nullptr;
|
||||
char *orig_path = g_file_get_path(srcFile.get()->get());
|
||||
char *basename = g_file_get_basename(srcFile.get()->get());
|
||||
QString trashDir = QString(g_get_user_data_dir()) + "/Trash/files";
|
||||
GFile *trash = g_file_new_for_path(trashDir.toUtf8().constData());
|
||||
GFile *dest_file = g_file_resolve_relative_path(trash, basename);
|
||||
g_object_unref(trash);
|
||||
g_file_move(srcFile.get()->get(), dest_file, G_FILE_COPY_NOFOLLOW_SYMLINKS, nullptr, nullptr, nullptr, &error);
|
||||
if (error && error->code == G_IO_ERROR_EXISTS) {
|
||||
except.errorCode = error->code;
|
||||
except.dlgType = ED_WARNING;
|
||||
except.errorStr = tr("An unmanageable conflict exists. Please check the recycle bin.");
|
||||
Q_EMIT errored(except);
|
||||
g_error_free(error);
|
||||
}
|
||||
g_file_move(srcFile.get()->get(), dest_file, G_FILE_COPY_NOFOLLOW_SYMLINKS, nullptr, nullptr, nullptr, nullptr);
|
||||
g_file_set_attribute_string(dest_file, "metadata::orig-path", orig_path, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, nullptr);
|
||||
g_object_unref(dest_file);
|
||||
if (orig_path) {
|
||||
|
|
|
@ -386,7 +386,7 @@ void FileUntrashOperation::run()
|
|||
// 2. restore the item from peony application.
|
||||
// 3. undo the operation in desktop application.
|
||||
// in this case trashedFileLocaledUri is empty, and could not get
|
||||
// the responding info. so I add a checkment to avoid the case happened.
|
||||
// the responding info. so I add a checkment to avoid the case happend.
|
||||
originUri = "file://" + metaInfo.get()->getMetaInfoString("orig-path");
|
||||
} else {
|
||||
qWarning()<<"invalid file meta info orig-path"<<trashedFileLocaledUri;
|
||||
|
|
|
@ -76,21 +76,6 @@ void SharedFileLinkOperation::createShareFilesSymbolicLink(QString &srcUri)
|
|||
}
|
||||
|
||||
g_autoptr (GError) error = nullptr;
|
||||
if(g_file_test(desktopfp.toUtf8().constData(), G_FILE_TEST_EXISTS)) {
|
||||
error = g_error_new (1, G_IO_ERROR_EXISTS, "%s", QString(tr("The dest file \"%1\" has existed!")).arg(desktopfp).toUtf8().constData());
|
||||
FileOperationError except;
|
||||
except.srcUri = m_src_uri;
|
||||
except.errorType = ET_GIO;
|
||||
except.isCritical = true;
|
||||
except.op = FileOpLink;
|
||||
except.title = tr("Link file error");
|
||||
except.destDirUri = m_dest_uri;
|
||||
except.errorStr = error->message;
|
||||
except.dlgType = ED_WARNING;
|
||||
Q_EMIT errored(except);
|
||||
return;
|
||||
}
|
||||
|
||||
GKeyFile* keyfile = g_key_file_new ();
|
||||
|
||||
g_key_file_set_value(keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, "true");
|
||||
|
@ -111,7 +96,7 @@ void SharedFileLinkOperation::createShareFilesSymbolicLink(QString &srcUri)
|
|||
g_key_file_set_value(keyfile, G_KEY_FILE_DESKTOP_GROUP, "X-Peony-CMD", "true");
|
||||
|
||||
// 可能会有路径重复的情况,后续需要做异常处理
|
||||
g_key_file_save_to_file(keyfile, desktopfp.toUtf8().constData(), &error);
|
||||
g_key_file_save_to_file(keyfile, desktopfp.toUtf8().constData(), nullptr);
|
||||
|
||||
if (keyfile) {
|
||||
g_key_file_free(keyfile);
|
||||
|
|
|
@ -34,13 +34,11 @@
|
|||
#include <QDir>
|
||||
#include <QIcon>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <udisks/udisks.h>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
#include <gio/gunixmounts.h>
|
||||
|
||||
using namespace Peony;
|
||||
|
||||
|
@ -343,7 +341,6 @@ QString FileUtils::getNonSuffixedBaseNameFromUri(const QString &uri)
|
|||
}
|
||||
}
|
||||
|
||||
#include "file-label-model.h"
|
||||
QString FileUtils::getFileDisplayName(const QString &uri)
|
||||
{
|
||||
auto fileInfo = FileInfo::fromUri(uri);
|
||||
|
@ -364,15 +361,6 @@ QString FileUtils::getFileDisplayName(const QString &uri)
|
|||
return showName;
|
||||
}
|
||||
}
|
||||
if(uri.startsWith("label://")){/* 标记模式uri的displayName */
|
||||
if("label:///" == uri){
|
||||
showName = QObject::tr("label");
|
||||
}else{
|
||||
showName = uri.section("/", -1,-1).replace("?schema=file","");
|
||||
}
|
||||
return showName;
|
||||
}
|
||||
|
||||
return fileInfo.get()->displayName();
|
||||
}
|
||||
|
||||
|
@ -667,8 +655,6 @@ const QStringList FileUtils::toDisplayUris(const QStringList &args)
|
|||
g_autofree gchar* file = g_strdup_printf ("file://%s/%s", currentDir, path.toUtf8 ().constData ());
|
||||
uris << file;
|
||||
}
|
||||
} else if (path.startsWith("mtp://") || path.startsWith("gphoto2://")) {
|
||||
uris << path;
|
||||
} else {
|
||||
uris << FileUtils::urlEncode (path);
|
||||
}
|
||||
|
@ -1018,6 +1004,7 @@ double FileUtils::getDeviceSize(const gchar * device_name)
|
|||
UDisksObject *object, *crypto_backing_object;
|
||||
UDisksBlock *block;
|
||||
UDisksClient *client =udisks_client_new_sync (NULL,NULL);
|
||||
|
||||
object = NULL;
|
||||
if (stat (device_name, &statbuf) != 0)
|
||||
{
|
||||
|
@ -1052,20 +1039,6 @@ double FileUtils::getDeviceSize(const gchar * device_name)
|
|||
return volume_size;
|
||||
}
|
||||
|
||||
quint64 FileUtils::getDiskFreeSpace(const gchar * path, bool &isState)
|
||||
{
|
||||
struct statvfs vfs;
|
||||
quint64 freeSize = 0;
|
||||
auto state = statvfs(path, &vfs);
|
||||
if(0 > state) {
|
||||
isState = false;
|
||||
qWarning() << "read statvfs error";
|
||||
} else {
|
||||
freeSize = vfs.f_bavail * vfs.f_bsize;
|
||||
}
|
||||
return freeSize;
|
||||
}
|
||||
|
||||
quint64 FileUtils::getFileSystemSize(QString uri)
|
||||
{
|
||||
QString unixDevice,dbusPath;
|
||||
|
@ -1140,27 +1113,6 @@ QString FileUtils::getMobieDataPath()
|
|||
return "";
|
||||
}
|
||||
|
||||
QString FileUtils::getFileSystemId(QString uri)
|
||||
{
|
||||
if (nullptr == uri) return "";
|
||||
|
||||
QString systemId = "";
|
||||
auto file = wrapGFile(g_file_new_for_uri(uri.toUtf8().constData()));
|
||||
auto info = wrapGFileInfo(g_file_query_info(file.get()->get(),
|
||||
G_FILE_ATTRIBUTE_ID_FILESYSTEM,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
nullptr,
|
||||
nullptr));
|
||||
if (!G_IS_FILE_INFO (info.get()->get()))
|
||||
return systemId;
|
||||
|
||||
if (info) {
|
||||
systemId = g_file_info_get_attribute_string(info.get()->get(), G_FILE_ATTRIBUTE_ID_FILESYSTEM);
|
||||
}
|
||||
|
||||
return systemId;
|
||||
}
|
||||
|
||||
bool FileUtils::isRemoteServerUri(const QString &uri)
|
||||
{
|
||||
if(uri.startsWith("smb://") || uri.startsWith("ftp://") || uri.startsWith("sftp://"))
|
||||
|
@ -1272,7 +1224,7 @@ QString FileUtils::handleSpecialSymbols(const QString &displayName)
|
|||
|
||||
QString FileUtils::getFsTypeFromFile(const QString &fileUri)
|
||||
{
|
||||
QString fsType = "ext";
|
||||
QString fsType = "";
|
||||
|
||||
g_autoptr (GFile) file = g_file_new_for_uri(fileUri.toUtf8().constData());
|
||||
g_autoptr (GMount) mount = g_file_find_enclosing_mount(file, nullptr, nullptr);
|
||||
|
@ -1288,12 +1240,6 @@ QString FileUtils::getFsTypeFromFile(const QString &fileUri)
|
|||
return fsType;
|
||||
|
||||
QString unixDevice = unix_file;
|
||||
|
||||
// try fix #179725
|
||||
if (unixDevice.startsWith("/dev/dm")) {
|
||||
return "ext";
|
||||
}
|
||||
|
||||
QString dbusPath = "/org/freedesktop/UDisks2/block_devices/" + unixDevice.split("/").last();
|
||||
if (! QDBusConnection::systemBus().isConnected())
|
||||
return fsType;
|
||||
|
@ -1312,44 +1258,6 @@ QString FileUtils::getFsTypeFromFile(const QString &fileUri)
|
|||
return fsType;
|
||||
}
|
||||
|
||||
bool FileUtils::isFuseFileSystem(const QString &fileUri)
|
||||
{
|
||||
g_autoptr (GFile) file = g_file_new_for_uri(fileUri.toUtf8().constData());
|
||||
g_autoptr (GFile) parent = g_file_get_parent(file);
|
||||
auto path = g_file_peek_path(parent);
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
g_autoptr (GUnixMountEntry) entry = g_unix_mount_at(path, NULL);
|
||||
if (!entry) {
|
||||
entry = g_unix_mount_for(path, NULL);
|
||||
if (!entry) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
auto fsType = g_unix_mount_get_fs_type(entry);
|
||||
if (QString(fsType).contains("fuse.kyfs")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool FileUtils::isLongNameFileOfNotDel2Trash(const QString &fileUri)
|
||||
{
|
||||
/* 存放长文件名目录的下,判断文件名超过224字符的,右键删除选项改成永久删除,不删除到回收站。link bug#188864 */
|
||||
QString extendDir = "file://" + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/扩展";/* 长文件名文件存放在家目录/下载/扩展目录下 */
|
||||
QString fileDecodeUri = urlDecode(fileUri);
|
||||
if(!fileDecodeUri.startsWith(extendDir))
|
||||
return false;
|
||||
|
||||
QString baseName = Peony::FileUtils::getUriBaseName(fileDecodeUri);
|
||||
qDebug()<<"file decodeUri:"<<fileDecodeUri<<";base name:"<<baseName<<";length of base name:"<<baseName.length();
|
||||
if(224 < baseName.length())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QString FileUtilsPrivate::getFileIconName(const QString &uri)
|
||||
{
|
||||
if (nullptr == uri) return "";
|
||||
|
@ -1368,7 +1276,16 @@ QString FileUtilsPrivate::getFileIconName(const QString &uri)
|
|||
if (g_icon && G_IS_ICON(g_icon)) {
|
||||
const gchar* const* icon_names = g_themed_icon_get_names(G_THEMED_ICON (g_icon));
|
||||
if (icon_names) {
|
||||
icon_name = QString(icon_names[0]);
|
||||
auto p = icon_names;
|
||||
while (*p) {
|
||||
QIcon icon = QIcon::fromTheme(*p);
|
||||
if (!icon.isNull()) {
|
||||
icon_name = QString (*p);
|
||||
break;
|
||||
} else {
|
||||
p++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//if it's a bootable-media,maybe we can get the icon from the mount directory.
|
||||
char *bootableIcon = g_icon_to_string(g_icon);
|
||||
|
|
|
@ -105,21 +105,16 @@ public:
|
|||
static quint64 getFileSystemSize(QString uri);
|
||||
static QString getFileSystemType(QString uri);
|
||||
static QString getMobieDataPath();
|
||||
static QString getFileSystemId(QString uri);
|
||||
static QString getApplicationName(const QString &uri);
|
||||
static bool isRemoteServerUri(const QString &uri);
|
||||
static bool isEmptyDisc(const QString &unixDevice);/* 判断是否是空光盘 */
|
||||
static bool isBusyDevice(const QString &unixDevice);/* 判断光盘是否正在使用 */
|
||||
static quint64 getDiskFreeSpace(const gchar *path, bool &isState); /* 获取磁盘剩余空间*/
|
||||
|
||||
NO_BLOCKING static QString getIconStringFromGIcon(GIcon *gicon, QString deviceFile = nullptr);
|
||||
static void saveCreateTime (const QString& url);
|
||||
static gint64 getCreateTimeOfMicro (const QString& url);
|
||||
static QString handleSpecialSymbols(const QString &displayName);
|
||||
BLOCKING static QString getFsTypeFromFile(const QString &fileUri);
|
||||
static bool isFuseFileSystem(const QString &fileUri);
|
||||
static bool isLongNameFileOfNotDel2Trash(const QString &fileUri);/* 判断是否是无法删除到回收站的长文件名文件 */
|
||||
|
||||
private:
|
||||
FileUtils();
|
||||
};
|
||||
|
|
|
@ -141,10 +141,9 @@ void FileWatcher::startMonitor()
|
|||
QString homeUri = "file://" + QStandardPaths::writableLocation(QStandardPaths::HomeLocation);/* 家目录 */
|
||||
bool favoriteCond = (m_uri=="favorite:///" && parentUri == homeUri);/* 快速访问下 */
|
||||
bool filesafeCond = (uri.startsWith("filesafe:///") && originalUri.startsWith("file:///"));
|
||||
bool labelCond = uri.startsWith("label://");/* 标识模式下 */
|
||||
if (parentUri == m_uri || parentUri == m_target_uri || parentUrl.toDisplayString() == m_uri
|
||||
|| parentUrl.toDisplayString() == m_target_uri || parentUri == originalUri || favoriteCond
|
||||
|| filesafeCond||labelCond) {
|
||||
|| filesafeCond) {
|
||||
Q_EMIT fileChanged(uri);
|
||||
qDebug()<<"file label changed"<<uri;
|
||||
}
|
||||
|
|
|
@ -33,9 +33,6 @@
|
|||
#include <QApplication>
|
||||
#include <QPalette>
|
||||
#include <QScreen>
|
||||
#ifdef KY_SDK_DATE
|
||||
#include <kysdk/kysdk-system/libkydate.h>
|
||||
#endif
|
||||
|
||||
#ifdef KY_SDK_SYSINFO
|
||||
#include <kysdk/kysdk-system/libkysysinfo.h>
|
||||
|
@ -56,48 +53,18 @@ GlobalSettings *GlobalSettings::getInstance()
|
|||
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_settings = new QSettings("org.ukui", "peony-qt-preferences", this);
|
||||
m_peonyGSettings = new QGSettings("org.ukui.peony.settings", "/org/ukui/peony/settings/", this);
|
||||
//set default allow parallel
|
||||
if (! m_settings->allKeys().contains(ALLOW_FILE_OP_PARALLEL)) {
|
||||
qDebug() << "default ALLOW_FILE_OP_PARALLEL:true";
|
||||
setValue(ALLOW_FILE_OP_PARALLEL, true);
|
||||
}
|
||||
//if local languege is chinese, set chinese first as default
|
||||
//if local languege is chinese, set chinese first as deafult
|
||||
if (QLocale::system().name().contains("zh") && !m_settings->allKeys().contains(SORT_CHINESE_FIRST))
|
||||
setValue(SORT_CHINESE_FIRST, true);
|
||||
for (auto key : m_settings->allKeys()) {
|
||||
m_cache.insert(key, m_settings->value(key));
|
||||
}
|
||||
|
||||
m_cache.insert(DISPLAY_STANDARD_ICONS, true);
|
||||
if (QGSettings::isSchemaInstalled("org.ukui.peony.settings")) {
|
||||
connect(m_peonyGSettings, &QGSettings::changed, this, [=] (const QString &key) {
|
||||
m_cache.remove(key);
|
||||
m_cache.insert(key, m_peonyGSettings->get(key));
|
||||
Q_EMIT this->valueChanged(key);
|
||||
});
|
||||
|
||||
for (auto key : m_peonyGSettings->keys()) {
|
||||
m_cache.remove(key);
|
||||
m_cache.insert(key, m_peonyGSettings->get(key));
|
||||
}
|
||||
}
|
||||
|
||||
m_cache.insert(TRASH_MOBILE_FILES, false);
|
||||
if (QGSettings::isSchemaInstalled("org.ukui.peony.settings")) {
|
||||
m_peonyGSettings = new QGSettings("org.ukui.peony.settings", "/org/ukui/peony/settings/", this);
|
||||
connect(m_peonyGSettings, &QGSettings::changed, this, [=] (const QString &key) {
|
||||
m_cache.remove(key);
|
||||
m_cache.insert(key, m_peonyGSettings->get(key));
|
||||
Q_EMIT this->valueChanged(key);
|
||||
});
|
||||
|
||||
for (auto key : m_peonyGSettings->keys()) {
|
||||
m_cache.remove(key);
|
||||
m_cache.insert(key, m_peonyGSettings->get(key));
|
||||
}
|
||||
}
|
||||
|
||||
m_date_format = tr("yyyy/MM/dd");
|
||||
m_time_format = tr("HH:mm:ss");
|
||||
if (QGSettings::isSchemaInstalled("org.ukui.control-center.panel.plugins")) {
|
||||
|
@ -224,7 +191,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
|||
setValue(DEFAULT_WINDOW_WIDTH, default_width);
|
||||
setValue(DEFAULT_WINDOW_HEIGHT, default_height);
|
||||
setValue(DEFAULT_SIDEBAR_WIDTH, 292);
|
||||
qDebug() << "default set DEFAULT_SIDEBAR_WIDTH:"<<210;
|
||||
qDebug() << "deafult set DEFAULT_SIDEBAR_WIDTH:"<<210;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,10 +224,6 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
|||
setValue (SORT_ORDER, 0);
|
||||
}
|
||||
|
||||
if (m_cache.value(DEFAULT_GRID_SIZE).isNull()) {
|
||||
setValue(DEFAULT_GRID_SIZE, QSize());
|
||||
}
|
||||
|
||||
#ifdef KY_SDK_SYSINFO
|
||||
auto machine = kdk_system_get_hostCloudPlatform();
|
||||
if (machine) {
|
||||
|
@ -274,7 +237,6 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
|||
m_cache.insert(IS_GUESTOS_MACHINE, false);
|
||||
}
|
||||
#endif
|
||||
initDateFormatDBus();
|
||||
}
|
||||
|
||||
GlobalSettings::~GlobalSettings()
|
||||
|
@ -361,55 +323,6 @@ const QVariant GlobalSettings::getValue(const QString &key)
|
|||
return m_cache.value(key);
|
||||
}
|
||||
|
||||
bool GlobalSettings::initDateFormatDBus()
|
||||
{
|
||||
#ifdef KY_SDK_DATE
|
||||
QDBusConnection conn = QDBusConnection::sessionBus();
|
||||
if (! conn.isConnected()) {
|
||||
qCritical()<<"failed to init mDbusDateServer, can not connect to session dbus";
|
||||
return false;
|
||||
}
|
||||
|
||||
mDbusDateServer = new QDBusInterface(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
QDBusConnection::sessionBus());
|
||||
|
||||
if (! mDbusDateServer->isValid()){
|
||||
qCritical() << "Create /com/kylin/kysdk/Date Interface Failed " << QDBusConnection::systemBus().lastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
QDBusConnection::sessionBus().connect(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
"ShortDateSignal",
|
||||
this,
|
||||
SLOT(sendShortDataFormat(QString)));
|
||||
|
||||
QDBusConnection::sessionBus().connect(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
"LongDateSignal",
|
||||
this,
|
||||
SLOT(sendLongDataFormat(QString)));
|
||||
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GlobalSettings::sendShortDataFormat(const QString &format)
|
||||
{
|
||||
Q_EMIT this->updateShortDataFormat(format);
|
||||
}
|
||||
|
||||
void GlobalSettings::sendLongDataFormat(const QString &format)
|
||||
{
|
||||
Q_EMIT this->updateLongDataFormat(format);
|
||||
}
|
||||
|
||||
bool GlobalSettings::isExist(const QString &key)
|
||||
{
|
||||
return !m_cache.value(key).isNull();
|
||||
|
@ -446,7 +359,7 @@ void GlobalSettings::resetAll()
|
|||
|
||||
void GlobalSettings::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
if (key == REMOTE_SERVER_REMOTE_IP || key == DEFAULT_WINDOW_SIZE || !m_peonyGSettings->keys().contains(key)) {
|
||||
if (key == REMOTE_SERVER_REMOTE_IP || key == DEFAULT_WINDOW_SIZE) {
|
||||
m_cache.remove(key);
|
||||
m_cache.insert(key, value);
|
||||
QtConcurrent::run([=]() {
|
||||
|
@ -522,55 +435,6 @@ QString GlobalSettings::getSystemTimeFormat()
|
|||
//m_system_time_format = m_date_format + " " + m_time_format;
|
||||
return m_system_time_format;
|
||||
}
|
||||
|
||||
QString GlobalSettings::transToSystemTimeFormat(guint64 mtime, bool longFormat)
|
||||
{
|
||||
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(mtime *1000);
|
||||
QString systemTimeFormat = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
struct tm *m_tm;
|
||||
time_t lt;
|
||||
lt = time(NULL);
|
||||
m_tm = localtime(<);
|
||||
|
||||
QDate date = dateTime.date();
|
||||
QTime qtime = dateTime.time();
|
||||
|
||||
m_tm->tm_year = date.year();
|
||||
m_tm->tm_mon = date.month();
|
||||
m_tm->tm_mday = date.day();
|
||||
|
||||
m_tm->tm_hour = qtime.hour();
|
||||
m_tm->tm_min = qtime.minute();
|
||||
m_tm->tm_sec = qtime.second();
|
||||
//qDebug() << "year:"<<date.year()<<"month:"<<date.month()<<"day:"<<date.day();
|
||||
//set date and time show format, task #101605
|
||||
auto ret = kdk_system_timeformat_transform(m_tm);
|
||||
auto formatDate = kdk_system_shortformat_transform(m_tm);
|
||||
//sdk接口会改变结构体数据,需要重初始化要使用的日期数据
|
||||
//属于接口缺陷,已跟SDK接口负责人沟通,先使用此方式
|
||||
m_tm->tm_year = date.year();
|
||||
m_tm->tm_mon = date.month();
|
||||
m_tm->tm_mday = date.day();
|
||||
if (longFormat)
|
||||
formatDate = kdk_system_longformat_transform(m_tm);
|
||||
if (ret && formatDate){
|
||||
QString dateStr = g_strdup_printf("%s %s", formatDate, ret->timesec);
|
||||
//qDebug() << "transToSystemTimeFormat:"<<dateStr<<systemTimeFormat;
|
||||
//释放结构体
|
||||
kdk_free_timeinfo(ret);
|
||||
|
||||
//use sdk interface
|
||||
if (dateStr.trimmed().length() > 0)
|
||||
return dateStr;
|
||||
}
|
||||
#endif
|
||||
|
||||
//old way of date, processed by self
|
||||
return dateTime.toString(systemTimeFormat);
|
||||
}
|
||||
|
||||
void GlobalSettings::setGSettingValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
if (!m_peony_gsettings)
|
||||
|
@ -589,9 +453,5 @@ void GlobalSettings::setGSettingValue(const QString &key, const QVariant &value)
|
|||
|
||||
QString GlobalSettings::getProjectName()
|
||||
{
|
||||
#ifdef KYLIN_COMMON
|
||||
return QString::fromStdString(KDKGetPrjCodeName());
|
||||
#else
|
||||
return "unknown-project-name";
|
||||
#endif // KYLIN_COMMON
|
||||
}
|
||||
|
|
|
@ -26,17 +26,14 @@
|
|||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QMutex>
|
||||
#include <QDBusInterface>
|
||||
|
||||
#include "peony-core_global.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
//顶部菜单 - Top menu
|
||||
#define RESIDENT_IN_BACKEND "resident"
|
||||
#define SHOW_HIDDEN_PREFERENCE "showHiddenFile"
|
||||
#define ALLOW_FILE_OP_PARALLEL "allowFileOpParallel"
|
||||
#define ALLOW_FILE_OP_PARALLEL "allow-file-op-parallel"
|
||||
#define FORBID_THUMBNAIL_IN_VIEW "doNotThumbnail"
|
||||
#define SHOW_IN_NEW_WINDOW "showInNewWindow"
|
||||
|
||||
//视图 - View
|
||||
#define DEFAULT_VIEW_ID "defaultViewId"
|
||||
|
@ -77,7 +74,6 @@
|
|||
#define LAST_DESKTOP_SORT_ORDER "lastDesktopSortOrder"
|
||||
#define TEMPLATES_DIR "templatesDir"
|
||||
#define DEFAULT_DESKTOP_ZOOM_LEVEL "defaultDesktopZoomLevel"
|
||||
#define DEFAULT_GRID_SIZE "default-grid-size"
|
||||
|
||||
//收藏的服务器IP - favorite ip
|
||||
#define REMOTE_SERVER_REMOTE_IP "remote-server/favorite-ip"
|
||||
|
@ -97,15 +93,9 @@
|
|||
#define SEND_URIS_OF_COPY_DSPS "sendUrisOfCopyDsps" /* send src and dest uris of copy dsps files to wps,默认值为false */
|
||||
#define DOC_IS_OCCUPIED_BY_WPS "docIsOccupiedByWps" /* 是否开启wps占用文件监控功能 */
|
||||
|
||||
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
|
||||
#define SEARCH_METHOD_KEY "fileIndexEnable"
|
||||
|
||||
//Control the display of desktop standard icons
|
||||
#define DISPLAY_STANDARD_ICONS "displayStandardIcons"
|
||||
|
||||
//control the mobile device trash file issue, if be true can trash mobile files
|
||||
#define TRASH_MOBILE_FILES "trashMobileFiles"
|
||||
|
||||
// control center
|
||||
#define UKUI_CONTROL_CENTER_PANEL_PLUGIN "org.ukui.control-center.panel.plugins" // schema
|
||||
#define UKUI_CONTROL_CENTER_PANEL_PLUGIN_TIME "org.ukui.control-center.panel.plugins.time" // time format key, value is '12' or '24'
|
||||
|
@ -136,12 +126,6 @@
|
|||
//dbus
|
||||
#define DBUS_STATUS_MANAGER_IF "com.kylin.statusmanager.interface"
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
#define SDK_DATE_SERVER_PATH "/com/kylin/kysdk/Date"
|
||||
#define SDK_DATE_SERVER_SERVICE "com.kylin.kysdk.DateServer"
|
||||
#define SDK_DATE_SERVER_INTERFACE "com.kylin.kysdk.DateInterface"
|
||||
#endif
|
||||
|
||||
class QGSettings;
|
||||
|
||||
namespace Peony {
|
||||
|
@ -163,15 +147,11 @@ public:
|
|||
static GlobalSettings *getInstance();
|
||||
const QVariant getValue(const QString &key);
|
||||
bool isExist(const QString &key);
|
||||
bool initDateFormatDBus();
|
||||
QString getProjectName();
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged(const QString &key);
|
||||
void updateHiddenFile(const QString &fileName);
|
||||
void signal_updateRemoteServer(const QString& server, bool add);
|
||||
void updateShortDataFormat(const QString &fileName);
|
||||
void updateLongDataFormat(const QString &fileName);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
|
@ -179,10 +159,7 @@ public Q_SLOTS:
|
|||
void resetAll();
|
||||
void setTimeFormat(const QString &value);
|
||||
void setDateFormat(const QString &value);
|
||||
void sendShortDataFormat(const QString &format);
|
||||
void sendLongDataFormat(const QString &format);
|
||||
QString getSystemTimeFormat();
|
||||
QString transToSystemTimeFormat(guint64 mtime, bool longFormat=false);
|
||||
|
||||
/*!
|
||||
* \brief 通过GSetting保存设置
|
||||
|
@ -217,7 +194,6 @@ private:
|
|||
QGSettings* m_gsettings = nullptr;
|
||||
QGSettings* m_control_center_plugin = nullptr;
|
||||
QGSettings* m_peony_gsettings = nullptr;
|
||||
QGSettings* m_peonyGSettings = nullptr; //fixme: 代码冲突遗留,后续仅保留一个peony gsettings实例
|
||||
QGSettings *m_gsettings_tablet_mode = nullptr;
|
||||
QGSettings *m_gsettings_dual_screen_mode = nullptr;
|
||||
QMutex m_mutex;
|
||||
|
@ -225,8 +201,6 @@ private:
|
|||
QString m_date_format = "";
|
||||
QString m_time_format = "";
|
||||
QString m_system_time_format = "";
|
||||
|
||||
QDBusInterface* mDbusDateServer = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,12 +26,6 @@ contains(DEFINES, "KY_UDF_BURN") {
|
|||
PKGCONFIG += kyudfburn
|
||||
}
|
||||
|
||||
# ukui-search
|
||||
contains(DEFINES, "KY_UKUI_SEARCH") {
|
||||
PKGCONFIG += ukui-search
|
||||
}
|
||||
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/file-copy.h \
|
||||
$$PWD/peony-log.h \
|
||||
|
|
|
@ -19,23 +19,19 @@ PKGCONFIG += glib-2.0 gio-2.0 gio-unix-2.0 poppler-qt5 gsettings-qt udisks2 libn
|
|||
DEFINES += PEONYCORE_LIBRARY
|
||||
|
||||
contains(DEFINES, KY_FILE_DIALOG) {
|
||||
PKGCONFIG += kysdk-applications
|
||||
PKGCONFIG += kysdk-qtwidgets
|
||||
}
|
||||
|
||||
contains(DEFINES, KY_SDK_SYSINFO) {
|
||||
PKGCONFIG += kysdk-system
|
||||
PKGCONFIG += kysdk-sysinfo
|
||||
}
|
||||
|
||||
contains(DEFINES, KY_SDK_QT_WIDGETS) {
|
||||
PKGCONFIG += kysdk-applications
|
||||
PKGCONFIG += kysdk-qtwidgets
|
||||
}
|
||||
|
||||
contains(DEFINES, KY_SDK_WAYLANDHELPER) {
|
||||
PKGCONFIG += kysdk-applications
|
||||
}
|
||||
|
||||
contains(DEFINES, KY_SDK_SYSINFO) {
|
||||
PKGCONFIG += kysdk-system
|
||||
PKGCONFIG += kysdk-waylandhelper
|
||||
}
|
||||
|
||||
schemes.files += org.ukui.peony.settings.gschema.xml
|
||||
|
@ -62,8 +58,7 @@ include(libpeony-qt.pri)
|
|||
TRANSLATIONS += ../translations/libpeony-qt/libpeony-qt_zh_CN.ts \
|
||||
../translations/libpeony-qt/libpeony-qt_tr.ts \
|
||||
../translations/libpeony-qt/libpeony-qt_cs.ts \
|
||||
../translations/libpeony-qt/libpeony-qt_bo_CN.ts \
|
||||
../translations/libpeony-qt/libpeony-qt_mn.ts
|
||||
../translations/libpeony-qt/libpeony-qt_bo_CN.ts
|
||||
|
||||
DESTDIR += $$PWD
|
||||
|
||||
|
@ -85,7 +80,7 @@ unix {
|
|||
# fixme:// format_dialog.h
|
||||
header.path = /usr/include/peony-qt
|
||||
header.files += *.h model/*.h file-operation/*.h vfs/*.h controls/ ../plugin-iface/*.h convenient-utils/*.h convenient-utils/disc/*.h windows/format_dialog.h windows/FMWindowIface.h \
|
||||
libpeony-qt/usershare-manager.h windows/udfFormatDialog.h windows/udfAppendBurnDataDialog.h windows/format-dlg-create-delegate.h
|
||||
libpeony-qt/usershare-manager.h windows/udfFormatDialog.h windows/udfAppendBurnDataDialog.h
|
||||
# header.depends = header2
|
||||
header.files += development-files/header-files/*
|
||||
INSTALLS += header
|
||||
|
|
|
@ -24,9 +24,6 @@
|
|||
#include "metadata-emblem-provider.h"
|
||||
#include "file-meta-info.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QThread>
|
||||
|
||||
using namespace Peony;
|
||||
|
||||
static MetadataEmblemProvider *global_instance = nullptr;
|
||||
|
@ -45,12 +42,7 @@ const QString MetadataEmblemProvider::emblemKey()
|
|||
|
||||
QStringList MetadataEmblemProvider::getFileEmblemIcons(const QString &uri)
|
||||
{
|
||||
std::shared_ptr<Peony::FileMetaInfo> metaInfo = nullptr;
|
||||
if (QThread::currentThread() == qApp->thread()) {
|
||||
metaInfo = FileMetaInfo::fromUri(uri);
|
||||
} else {
|
||||
metaInfo = requestDupMetaInfo(uri);
|
||||
}
|
||||
auto metaInfo = FileMetaInfo::dupFromUri(uri);
|
||||
if(!metaInfo || !metaInfo.get())
|
||||
return QStringList();
|
||||
return metaInfo->getMetaInfoStringListV1("emblems");
|
||||
|
@ -58,10 +50,5 @@ QStringList MetadataEmblemProvider::getFileEmblemIcons(const QString &uri)
|
|||
|
||||
MetadataEmblemProvider::MetadataEmblemProvider(QObject *parent) : EmblemProvider(parent)
|
||||
{
|
||||
connect(this, &MetadataEmblemProvider::requestDupMetaInfo, this, &MetadataEmblemProvider::getDupMetaInfo, Qt::BlockingQueuedConnection);
|
||||
}
|
||||
|
||||
std::shared_ptr<FileMetaInfo> MetadataEmblemProvider::getDupMetaInfo(const QString &uri)
|
||||
{
|
||||
return FileMetaInfo::dupFromUri(uri);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue