Skip to content

Commit

Permalink
fix: can not show backup file in File Manager
Browse files Browse the repository at this point in the history
Change-Id: Iaaa2c41235e6384d5df1fe69744f513642ef0957
  • Loading branch information
zccrs committed Apr 19, 2018
1 parent b6e9dc5 commit d670fa6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
28 changes: 25 additions & 3 deletions app/src/widgets/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ QString findHonestChild()
return QStandardPaths::findExecutable("deepin-clone-honest");
}

bool MainWindow::showFileItem(const QString &file)
{
QString honest_child = findHonestChild();

if (honest_child.isEmpty())
return false;

QProcess process;
QStringList env_list = process.environment();

env_list << honestChildEnvironment();
env_list << QString("%1=%2").arg(DEEPIN_CLONE_SHOW_FILE).arg(file);

process.setProcessChannelMode(QProcess::ForwardedChannels);
process.setEnvironment(env_list);

process.start(honest_child);

if (!process.waitForFinished())
return false;

return process.exitCode() == 0;
}

bool MainWindow::openUrl(const QUrl &url)
{
QString honest_child = findHonestChild();
Expand Down Expand Up @@ -698,9 +722,7 @@ void MainWindow::onButtonClicked()
return setStatus(Working);
}
case ShowBackupFile: {
dCDebug("Show \"%s\" on file manager", qPrintable(m_targetFile));

DDesktopServices::showFileItem(m_targetFile);
dCDebug("Show \"%s\" on file manager. finished: %s", qPrintable(m_targetFile), showFileItem(m_targetFile) ? "true" : "false");
return;
}
case Quit: {
Expand Down
2 changes: 2 additions & 0 deletions app/src/widgets/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class MainWindow : public DMainWindow

void startWithFile(const QString &source, const QString &target);

static bool showFileItem(const QString &file);

private slots:
bool openUrl(const QUrl &url);

Expand Down
3 changes: 2 additions & 1 deletion common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ DEFINES += DEEPIN_CLONE_UID=\\\"DEEPIN_CLONE_UID\\\"\
DEEPIN_CLONE_TITLE=\\\"DEEPIN_CLONE_TITLE\\\"\
DEEPIN_CLONE_FILE_NAME=\\\"DEEPIN_CLONE_FILE_NAME\\\"\
DEEPIN_CLONE_NAME_FILTER=\\\"DEEPIN_CLONE_NAME_FILTER\\\"\
DEEPIN_CLONE_GET_FILE=\\\"DEEPIN_CLONE_GET_FILE\\\"
DEEPIN_CLONE_GET_FILE=\\\"DEEPIN_CLONE_GET_FILE\\\"\
DEEPIN_CLONE_SHOW_FILE=\\\"DEEPIN_CLONE_SHOW_FILE\\\"
3 changes: 3 additions & 0 deletions honest_child/honest_child.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ VERSION = 0.0.1
TEMPLATE = app
QT += widgets

CONFIG += link_pkgconfig
PKGCONFIG += dtkwidget

DEFINES += QT_MESSAGELOGCONTEXT
DEFINES += HOST_ARCH_$$QMAKE_HOST.arch HOST_ARCH=\\\"$$QMAKE_HOST.arch\\\"

Expand Down
11 changes: 9 additions & 2 deletions honest_child/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <QDebug>
#include <QThread>

#include <DDesktopServices>

#include <unistd.h>
#include <stdio.h>

Expand Down Expand Up @@ -55,9 +57,8 @@ int main(int argc, char *argv[])
setuid(uid);
}

QApplication *app = new QApplication(argc, argv);

if (qEnvironmentVariableIsSet(DEEPIN_CLONE_OPEN_DIALOG)) {
QApplication *app = new QApplication(argc, argv);
QFileDialog dialog(0, QString(), QDir::homePath());

dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint);
Expand Down Expand Up @@ -91,7 +92,13 @@ int main(int argc, char *argv[])
thread->wait();
thread->quit();
} else if (qEnvironmentVariableIsSet(DEEPIN_CLONE_OPEN_URL)) {
QGuiApplication *app = new QGuiApplication(argc, argv);
Q_UNUSED(app)
QDesktopServices::openUrl(QUrl(QString::fromUtf8(qgetenv(DEEPIN_CLONE_OPEN_URL))));
} else if (qEnvironmentVariableIsSet(DEEPIN_CLONE_SHOW_FILE)) {
DTK_WIDGET_NAMESPACE::DDesktopServices::showFileItem(QString::fromUtf8(qgetenv(DEEPIN_CLONE_SHOW_FILE)));
} else {
return -1;
}

return 0;
Expand Down

0 comments on commit d670fa6

Please sign in to comment.