From adbd34c79571938e3463bd5635c899e726b2fd86 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 2 Mar 2019 13:22:13 +0800 Subject: [PATCH] Move helper functions to Utils::Gui namespace --- src/app/application.cpp | 4 +- src/app/cmdoptions.cpp | 6 +- src/app/main.cpp | 8 +- src/base/bittorrent/torrenthandle.cpp | 22 ++-- src/base/bittorrent/torrenthandle.h | 39 +++--- src/base/bittorrent/torrentinfo.cpp | 5 +- src/base/bittorrent/torrentinfo.h | 1 - src/base/utils/misc.cpp | 121 +----------------- src/base/utils/misc.h | 16 +-- src/gui/addnewtorrentdialog.cpp | 1 + src/gui/mainwindow.cpp | 2 +- src/gui/properties/propertieswidget.cpp | 8 +- src/gui/search/searchjobwidget.cpp | 3 +- src/gui/search/searchjobwidget.h | 1 - src/gui/shutdownconfirmdialog.cpp | 3 +- src/gui/transferlistmodel.cpp | 1 + src/gui/transferlistsortmodel.cpp | 2 +- src/gui/transferlistwidget.cpp | 11 +- src/gui/utils.cpp | 106 +++++++++++++++ src/gui/utils.h | 9 +- src/webui/api/serialize/serialize_torrent.cpp | 2 + 21 files changed, 184 insertions(+), 187 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index d2acbd829..a288b655d 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -55,6 +56,7 @@ #endif // Q_OS_MAC #include "addnewtorrentdialog.h" #include "gui/guiiconprovider.h" +#include "gui/utils.h" #include "mainwindow.h" #include "shutdownconfirmdialog.h" #else // DISABLE_GUI @@ -529,7 +531,7 @@ int Application::exec(const QStringList ¶ms) msgBox.setText(tr("Application failed to start.")); msgBox.setInformativeText(err.message()); msgBox.show(); // Need to be shown or to moveToCenter does not work - msgBox.move(Utils::Misc::screenCenter(&msgBox)); + msgBox.move(Utils::Gui::screenCenter(&msgBox)); msgBox.exec(); #endif return 1; diff --git a/src/app/cmdoptions.cpp b/src/app/cmdoptions.cpp index a0339fbb5..a237cb700 100644 --- a/src/app/cmdoptions.cpp +++ b/src/app/cmdoptions.cpp @@ -45,6 +45,10 @@ #include "base/utils/misc.h" #include "base/utils/string.h" +#ifndef DISABLE_GUI +#include "gui/utils.h" +#endif + namespace { const int USAGE_INDENTATION = 4; @@ -580,7 +584,7 @@ void displayUsage(const QString &prgName) #else QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prgName), QMessageBox::Ok); msgBox.show(); // Need to be shown or to moveToCenter does not work - msgBox.move(Utils::Misc::screenCenter(&msgBox)); + msgBox.move(Utils::Gui::screenCenter(&msgBox)); msgBox.exec(); #endif } diff --git a/src/app/main.cpp b/src/app/main.cpp index 96887b4b7..21fb29f67 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -76,6 +76,10 @@ Q_IMPORT_PLUGIN(QICOPlugin) #include "cmdoptions.h" #include "upgrade.h" +#ifndef DISABLE_GUI +#include "gui/utils.h" +#endif + // Signal handlers void sigNormalHandler(int signum); #ifdef STACKTRACE @@ -328,7 +332,7 @@ void displayBadArgMessage(const QString &message) QMessageBox msgBox(QMessageBox::Critical, QObject::tr("Bad command line"), message + QLatin1Char('\n') + help, QMessageBox::Ok); msgBox.show(); // Need to be shown or to moveToCenter does not work - msgBox.move(Utils::Misc::screenCenter(&msgBox)); + msgBox.move(Utils::Gui::screenCenter(&msgBox)); msgBox.exec(); #else const QString errMsg = QObject::tr("Bad command line: ") + '\n' @@ -364,7 +368,7 @@ bool userAgreesWithLegalNotice() msgBox.addButton(QObject::tr("Cancel"), QMessageBox::RejectRole); const QAbstractButton *agreeButton = msgBox.addButton(QObject::tr("I Agree"), QMessageBox::AcceptRole); msgBox.show(); // Need to be shown or to moveToCenter does not work - msgBox.move(Utils::Misc::screenCenter(&msgBox)); + msgBox.move(Utils::Gui::screenCenter(&msgBox)); msgBox.exec(); if (msgBox.clickedButton() == agreeButton) { // Save the answer diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 4558ea9cc..51c3a2a3f 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -32,12 +32,9 @@ #include #include -#include -#include -#include -#include -#include -#include +#ifdef Q_OS_WIN +#include +#endif #include #include @@ -47,17 +44,20 @@ #include #include -#ifdef Q_OS_WIN -#include -#endif +#include +#include +#include +#include +#include +#include +#include #include "base/global.h" #include "base/logger.h" #include "base/preferences.h" #include "base/profile.h" +#include "base/tristatebool.h" #include "base/utils/fs.h" -#include "base/utils/misc.h" -#include "base/utils/string.h" #include "peerinfo.h" #include "session.h" #include "trackerentry.h" diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 5acaa0405..96e3c127f 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -32,7 +32,9 @@ #include -#include +#include +#include + #include #include #include @@ -40,50 +42,47 @@ #include #include -#include -#include - -#include "base/tristatebool.h" #include "private/speedmonitor.h" #include "infohash.h" #include "torrentinfo.h" +extern const QString QB_EXT; + class QBitArray; +class QDateTime; class QStringList; -template struct QPair; - -extern const QString QB_EXT; +class QUrl; namespace libtorrent { class alert; + struct fastresume_rejected_alert; + struct file_completed_alert; + struct file_renamed_alert; + struct file_rename_failed_alert; + struct metadata_received_alert; + struct save_resume_data_alert; + struct save_resume_data_failed_alert; struct stats_alert; + struct storage_moved_alert; + struct storage_moved_failed_alert; struct torrent_checked_alert; struct torrent_finished_alert; struct torrent_paused_alert; struct torrent_resumed_alert; - struct save_resume_data_alert; - struct save_resume_data_failed_alert; - struct file_renamed_alert; - struct file_rename_failed_alert; - struct storage_moved_alert; - struct storage_moved_failed_alert; - struct metadata_received_alert; - struct file_completed_alert; + struct torrent_status; struct tracker_error_alert; struct tracker_reply_alert; struct tracker_warning_alert; - struct fastresume_rejected_alert; - struct torrent_status; } namespace BitTorrent { - struct PeerAddress; - class Session; class PeerInfo; + class Session; class TrackerEntry; struct AddTorrentParams; + struct PeerAddress; struct CreateTorrentParams { diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index 66b44705c..ef383de80 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -30,14 +30,15 @@ #include +#include #include #include +#include #include +#include #include #include "base/utils/fs.h" -#include "base/utils/misc.h" -#include "base/utils/string.h" #include "infohash.h" #include "trackerentry.h" diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index 972ff6aab..cc5d3865a 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -33,7 +33,6 @@ #include #include -#include #include #include "base/indexrange.h" diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index f9d93fc12..ee87c3e1d 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -40,42 +40,24 @@ #endif #ifdef Q_OS_MAC -#include #include +#include #endif #include -#include -#include -#include -#include +#include #include +#include #include -#include -#ifdef DISABLE_GUI -#include -#else -#include -#include -#include -#include -#include -#include #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) #include -#include #endif -#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) -#include "base/utils/version.h" -#endif -#endif // DISABLE_GUI -#include "base/logger.h" +#include "base/types.h" #include "base/unicodestrings.h" #include "base/utils/string.h" -#include "fs.h" namespace { @@ -249,34 +231,6 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action) #endif } -#ifndef DISABLE_GUI -QPoint Utils::Misc::screenCenter(const QWidget *w) -{ - // Returns the QPoint which the widget will be placed center on screen (where parent resides) - - if (!w) - return {}; - - QRect r = QGuiApplication::primaryScreen()->availableGeometry(); - const QPoint primaryScreenCenter {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)}; - - const QWidget *parent = w->parentWidget(); - if (!parent) - return primaryScreenCenter; - - const QWindow *window = parent->window()->windowHandle(); - if (!window) - return primaryScreenCenter; - - const QScreen *screen = window->screen(); - if (!screen) - return primaryScreenCenter; - - r = screen->availableGeometry(); - return {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)}; -} -#endif - QString Utils::Misc::unitString(const SizeUnit unit, const bool isSpeed) { const auto &unitString = units[static_cast(unit)]; @@ -493,73 +447,6 @@ QString Utils::Misc::parseHtmlLinks(const QString &rawText) return result; } -#ifndef DISABLE_GUI -// Open the given path with an appropriate application -void Utils::Misc::openPath(const QString &absolutePath) -{ - const QString path = Utils::Fs::fromNativePath(absolutePath); - // Hack to access samba shares with QDesktopServices::openUrl - if (path.startsWith("//")) - QDesktopServices::openUrl(Utils::Fs::toNativePath("file:" + path)); - else - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); -} - -// Open the parent directory of the given path with a file manager and select -// (if possible) the item at the given path -void Utils::Misc::openFolderSelect(const QString &absolutePath) -{ - const QString path = Utils::Fs::fromNativePath(absolutePath); - // If the item to select doesn't exist, try to open its parent - if (!QFileInfo::exists(path)) { - openPath(path.left(path.lastIndexOf('/'))); - return; - } -#ifdef Q_OS_WIN - HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED); - PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast(Utils::Fs::toNativePath(path).utf16())); - if (pidl) { - ::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0); - ::ILFree(pidl); - } - if ((hresult == S_OK) || (hresult == S_FALSE)) - ::CoUninitialize(); -#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC) - QProcess proc; - proc.start("xdg-mime", {"query", "default", "inode/directory"}); - proc.waitForFinished(); - const QString output = proc.readLine().simplified(); - if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop")) { - proc.startDetached("dolphin", {"--select", Utils::Fs::toNativePath(path)}); - } - else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop") - || (output == "nautilus-folder-handler.desktop")) { - proc.start("nautilus", {"--version"}); - proc.waitForFinished(); - const QString nautilusVerStr = QString(proc.readLine()).remove(QRegularExpression("[^0-9.]")); - using NautilusVersion = Utils::Version; - if (NautilusVersion::tryParse(nautilusVerStr, {1, 0, 0}) > NautilusVersion {3, 28}) - proc.startDetached("nautilus", {Utils::Fs::toNativePath(path)}); - else - proc.startDetached("nautilus", {"--no-desktop", Utils::Fs::toNativePath(path)}); - } - else if (output == "nemo.desktop") { - proc.startDetached("nemo", {"--no-desktop", Utils::Fs::toNativePath(path)}); - } - else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop")) { - proc.startDetached("konqueror", {"--select", Utils::Fs::toNativePath(path)}); - } - else { - // "caja" manager can't pinpoint the file, see: https://github.com/qbittorrent/qBittorrent/issues/5003 - openPath(path.left(path.lastIndexOf('/'))); - } -#else - openPath(path.left(path.lastIndexOf('/'))); -#endif -} - -#endif // DISABLE_GUI - QString Utils::Misc::osName() { // static initialization for usage in signal handler diff --git a/src/base/utils/misc.h b/src/base/utils/misc.h index f1a081b11..a8ca900f0 100644 --- a/src/base/utils/misc.h +++ b/src/base/utils/misc.h @@ -29,9 +29,6 @@ #ifndef UTILS_MISC_H #define UTILS_MISC_H -#include -#include - #include #ifdef Q_OS_WIN @@ -39,14 +36,10 @@ #include #endif -#include -#include -#include #include #include -#include -#include "base/types.h" +enum class ShutdownDialogAction; /* Miscellaneous functions that can be useful */ @@ -99,13 +92,6 @@ namespace Utils QList intListfromStringList(const QStringList &l); QList boolListfromStringList(const QStringList &l); -#ifndef DISABLE_GUI - void openPath(const QString &absolutePath); - void openFolderSelect(const QString &absolutePath); - - QPoint screenCenter(const QWidget *w); -#endif - #ifdef Q_OS_WIN QString windowsSystemPath(); diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 0a6d15f8d..5296f8983 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -29,6 +29,7 @@ #include "addnewtorrentdialog.h" #include +#include #include #include #include diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index e8b50e035..72261b2a7 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1130,7 +1130,7 @@ void MainWindow::showEvent(QShowEvent *e) // Make sure the window is initially centered if (!m_posInitialized) { - move(Utils::Misc::screenCenter(this)); + move(Utils::Gui::screenCenter(this)); m_posInitialized = true; } } diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 4835112fa..5b9a8fcee 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -30,12 +30,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include "base/bittorrent/filepriority.h" #include "base/bittorrent/session.h" @@ -527,7 +529,7 @@ void PropertiesWidget::openFile(const QModelIndex &index) qDebug("Trying to open file at %s", qUtf8Printable(filePath)); // Flush data m_torrent->flushCache(); - Utils::Misc::openPath(filePath); + Utils::Gui::openPath(filePath); } void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolder) @@ -563,9 +565,9 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolde MacUtils::openFiles(QSet{absolutePath}); #else if (containingFolder) - Utils::Misc::openFolderSelect(absolutePath); + Utils::Gui::openFolderSelect(absolutePath); else - Utils::Misc::openPath(absolutePath); + Utils::Gui::openPath(absolutePath); #endif } diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index fe391d5fc..483400196 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -35,10 +35,9 @@ #include #include #include -#include #include #include -#include +#include #include "base/bittorrent/session.h" #include "base/preferences.h" diff --git a/src/gui/search/searchjobwidget.h b/src/gui/search/searchjobwidget.h index f31167ca7..9d71c9913 100644 --- a/src/gui/search/searchjobwidget.h +++ b/src/gui/search/searchjobwidget.h @@ -36,7 +36,6 @@ class QHeaderView; class QModelIndex; -class QStandardItem; class QStandardItemModel; template class CachedSettingValue; diff --git a/src/gui/shutdownconfirmdialog.cpp b/src/gui/shutdownconfirmdialog.cpp index 002ad691c..82de9afaa 100644 --- a/src/gui/shutdownconfirmdialog.cpp +++ b/src/gui/shutdownconfirmdialog.cpp @@ -35,7 +35,6 @@ #include #include "base/preferences.h" -#include "base/utils/misc.h" #include "ui_shutdownconfirmdialog.h" #include "utils.h" @@ -63,7 +62,7 @@ ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDial // Always on top setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); - move(Utils::Misc::screenCenter(this)); + move(Utils::Gui::screenCenter(this)); m_timer.setInterval(1000); // 1sec connect(&m_timer, &QTimer::timeout, this, &ShutdownConfirmDialog::updateSeconds); diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index 9d69d5da4..eb98486ac 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -30,6 +30,7 @@ #include "transferlistmodel.h" #include +#include #include #include #include diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index c33691eba..a291a06be 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -28,6 +28,7 @@ #include "transferlistsortmodel.h" +#include #include #include "base/bittorrent/torrenthandle.h" @@ -35,7 +36,6 @@ #include "base/utils/string.h" #include "transferlistmodel.h" - TransferListSortModel::TransferListSortModel(QObject *parent) : QSortFilterProxyModel(parent) { diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 218de9795..27f11362c 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -63,6 +63,7 @@ #include "transferlistmodel.h" #include "transferlistsortmodel.h" #include "updownratiodialog.h" +#include "utils.h" #ifdef Q_OS_MAC #include "macutilities.h" @@ -341,7 +342,7 @@ TransferListModel *TransferListWidget::getSourceModel() const void TransferListWidget::previewFile(const QString &filePath) { - Utils::Misc::openPath(filePath); + Utils::Gui::openPath(filePath); } inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const @@ -386,9 +387,9 @@ void TransferListWidget::torrentDoubleClicked() MacUtils::openFiles(QSet{torrent->contentPath(true)}); #else if (torrent->filesCount() == 1) - Utils::Misc::openFolderSelect(torrent->contentPath(true)); + Utils::Gui::openFolderSelect(torrent->contentPath(true)); else - Utils::Misc::openPath(torrent->contentPath(true)); + Utils::Gui::openPath(torrent->contentPath(true)); #endif break; } @@ -592,9 +593,9 @@ void TransferListWidget::openSelectedTorrentsFolder() const QString path = torrent->contentPath(true); if (!pathsList.contains(path)) { if (torrent->filesCount() == 1) - Utils::Misc::openFolderSelect(path); + Utils::Gui::openFolderSelect(path); else - Utils::Misc::openPath(path); + Utils::Gui::openPath(path); } pathsList.insert(path); } diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp index 9151284a1..367d9086a 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -28,14 +28,30 @@ #include "utils.h" +#ifdef Q_OS_WIN +#include +#include +#endif + #include +#include #include +#include +#include +#include #include +#include +#include +#include #include #include +#include #include #include +#include "base/utils/fs.h" +#include "base/utils/version.h" + void Utils::Gui::resize(QWidget *widget, const QSize &newSize) { if (newSize.isValid()) @@ -112,3 +128,93 @@ QSize Utils::Gui::largeIconSize(const QWidget *widget) const int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize, nullptr, widget); return {s, s}; } + +QPoint Utils::Gui::screenCenter(const QWidget *w) +{ + // Returns the QPoint which the widget will be placed center on screen (where parent resides) + + if (!w) + return {}; + + QRect r = QGuiApplication::primaryScreen()->availableGeometry(); + const QPoint primaryScreenCenter {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)}; + + const QWidget *parent = w->parentWidget(); + if (!parent) + return primaryScreenCenter; + + const QWindow *window = parent->window()->windowHandle(); + if (!window) + return primaryScreenCenter; + + const QScreen *screen = window->screen(); + if (!screen) + return primaryScreenCenter; + + r = screen->availableGeometry(); + return {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)}; +} + +// Open the given path with an appropriate application +void Utils::Gui::openPath(const QString &absolutePath) +{ + const QString path = Utils::Fs::fromNativePath(absolutePath); + // Hack to access samba shares with QDesktopServices::openUrl + if (path.startsWith("//")) + QDesktopServices::openUrl(Utils::Fs::toNativePath("file:" + path)); + else + QDesktopServices::openUrl(QUrl::fromLocalFile(path)); +} + +// Open the parent directory of the given path with a file manager and select +// (if possible) the item at the given path +void Utils::Gui::openFolderSelect(const QString &absolutePath) +{ + const QString path = Utils::Fs::fromNativePath(absolutePath); + // If the item to select doesn't exist, try to open its parent + if (!QFileInfo::exists(path)) { + openPath(path.left(path.lastIndexOf('/'))); + return; + } +#ifdef Q_OS_WIN + HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED); + PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast(Utils::Fs::toNativePath(path).utf16())); + if (pidl) { + ::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0); + ::ILFree(pidl); + } + if ((hresult == S_OK) || (hresult == S_FALSE)) + ::CoUninitialize(); +#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC) + QProcess proc; + proc.start("xdg-mime", {"query", "default", "inode/directory"}); + proc.waitForFinished(); + const QString output = proc.readLine().simplified(); + if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop")) { + proc.startDetached("dolphin", {"--select", Utils::Fs::toNativePath(path)}); + } + else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop") + || (output == "nautilus-folder-handler.desktop")) { + proc.start("nautilus", {"--version"}); + proc.waitForFinished(); + const QString nautilusVerStr = QString(proc.readLine()).remove(QRegularExpression("[^0-9.]")); + using NautilusVersion = Utils::Version; + if (NautilusVersion::tryParse(nautilusVerStr, {1, 0, 0}) > NautilusVersion {3, 28}) + proc.startDetached("nautilus", {Utils::Fs::toNativePath(path)}); + else + proc.startDetached("nautilus", {"--no-desktop", Utils::Fs::toNativePath(path)}); + } + else if (output == "nemo.desktop") { + proc.startDetached("nemo", {"--no-desktop", Utils::Fs::toNativePath(path)}); + } + else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop")) { + proc.startDetached("konqueror", {"--select", Utils::Fs::toNativePath(path)}); + } + else { + // "caja" manager can't pinpoint the file, see: https://github.com/qbittorrent/qBittorrent/issues/5003 + openPath(path.left(path.lastIndexOf('/'))); + } +#else + openPath(path.left(path.lastIndexOf('/'))); +#endif +} diff --git a/src/gui/utils.h b/src/gui/utils.h index ee1c7e76d..9da4e6326 100644 --- a/src/gui/utils.h +++ b/src/gui/utils.h @@ -29,11 +29,11 @@ #ifndef UTILS_GUI_H #define UTILS_GUI_H -#include -#include #include class QIcon; +class QPixmap; +class QPoint; class QWidget; namespace Utils @@ -55,6 +55,11 @@ namespace Utils QSize smallIconSize(const QWidget *widget = nullptr); QSize mediumIconSize(const QWidget *widget = nullptr); QSize largeIconSize(const QWidget *widget = nullptr); + + QPoint screenCenter(const QWidget *w); + + void openPath(const QString &absolutePath); + void openFolderSelect(const QString &absolutePath); } } diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index 7b511b3d5..225bf8757 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -28,6 +28,8 @@ #include "serialize_torrent.h" +#include + #include "base/bittorrent/session.h" #include "base/bittorrent/torrenthandle.h" #include "base/utils/fs.h"