mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 09:55:55 +00:00
Move helper functions to Utils::Gui namespace
This commit is contained in:
parent
0f1fc7be9d
commit
adbd34c795
@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <QAtomicInt>
|
#include <QAtomicInt>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
@ -55,6 +56,7 @@
|
|||||||
#endif // Q_OS_MAC
|
#endif // Q_OS_MAC
|
||||||
#include "addnewtorrentdialog.h"
|
#include "addnewtorrentdialog.h"
|
||||||
#include "gui/guiiconprovider.h"
|
#include "gui/guiiconprovider.h"
|
||||||
|
#include "gui/utils.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "shutdownconfirmdialog.h"
|
#include "shutdownconfirmdialog.h"
|
||||||
#else // DISABLE_GUI
|
#else // DISABLE_GUI
|
||||||
@ -529,7 +531,7 @@ int Application::exec(const QStringList ¶ms)
|
|||||||
msgBox.setText(tr("Application failed to start."));
|
msgBox.setText(tr("Application failed to start."));
|
||||||
msgBox.setInformativeText(err.message());
|
msgBox.setInformativeText(err.message());
|
||||||
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
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();
|
msgBox.exec();
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -45,6 +45,10 @@
|
|||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "base/utils/string.h"
|
#include "base/utils/string.h"
|
||||||
|
|
||||||
|
#ifndef DISABLE_GUI
|
||||||
|
#include "gui/utils.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const int USAGE_INDENTATION = 4;
|
const int USAGE_INDENTATION = 4;
|
||||||
@ -580,7 +584,7 @@ void displayUsage(const QString &prgName)
|
|||||||
#else
|
#else
|
||||||
QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prgName), QMessageBox::Ok);
|
QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prgName), QMessageBox::Ok);
|
||||||
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
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();
|
msgBox.exec();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,10 @@ Q_IMPORT_PLUGIN(QICOPlugin)
|
|||||||
#include "cmdoptions.h"
|
#include "cmdoptions.h"
|
||||||
#include "upgrade.h"
|
#include "upgrade.h"
|
||||||
|
|
||||||
|
#ifndef DISABLE_GUI
|
||||||
|
#include "gui/utils.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Signal handlers
|
// Signal handlers
|
||||||
void sigNormalHandler(int signum);
|
void sigNormalHandler(int signum);
|
||||||
#ifdef STACKTRACE
|
#ifdef STACKTRACE
|
||||||
@ -328,7 +332,7 @@ void displayBadArgMessage(const QString &message)
|
|||||||
QMessageBox msgBox(QMessageBox::Critical, QObject::tr("Bad command line"),
|
QMessageBox msgBox(QMessageBox::Critical, QObject::tr("Bad command line"),
|
||||||
message + QLatin1Char('\n') + help, QMessageBox::Ok);
|
message + QLatin1Char('\n') + help, QMessageBox::Ok);
|
||||||
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
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();
|
msgBox.exec();
|
||||||
#else
|
#else
|
||||||
const QString errMsg = QObject::tr("Bad command line: ") + '\n'
|
const QString errMsg = QObject::tr("Bad command line: ") + '\n'
|
||||||
@ -364,7 +368,7 @@ bool userAgreesWithLegalNotice()
|
|||||||
msgBox.addButton(QObject::tr("Cancel"), QMessageBox::RejectRole);
|
msgBox.addButton(QObject::tr("Cancel"), QMessageBox::RejectRole);
|
||||||
const QAbstractButton *agreeButton = msgBox.addButton(QObject::tr("I Agree"), QMessageBox::AcceptRole);
|
const QAbstractButton *agreeButton = msgBox.addButton(QObject::tr("I Agree"), QMessageBox::AcceptRole);
|
||||||
msgBox.show(); // Need to be shown or to moveToCenter does not work
|
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();
|
msgBox.exec();
|
||||||
if (msgBox.clickedButton() == agreeButton) {
|
if (msgBox.clickedButton() == agreeButton) {
|
||||||
// Save the answer
|
// Save the answer
|
||||||
|
@ -32,12 +32,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <QBitArray>
|
#ifdef Q_OS_WIN
|
||||||
#include <QByteArray>
|
#include <windows.h>
|
||||||
#include <QDebug>
|
#endif
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include <libtorrent/address.hpp>
|
#include <libtorrent/address.hpp>
|
||||||
#include <libtorrent/alert_types.hpp>
|
#include <libtorrent/alert_types.hpp>
|
||||||
@ -47,17 +44,20 @@
|
|||||||
#include <libtorrent/magnet_uri.hpp>
|
#include <libtorrent/magnet_uri.hpp>
|
||||||
#include <libtorrent/time.hpp>
|
#include <libtorrent/time.hpp>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#include <QBitArray>
|
||||||
#include <windows.h>
|
#include <QDateTime>
|
||||||
#endif
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
#include "base/profile.h"
|
#include "base/profile.h"
|
||||||
|
#include "base/tristatebool.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/misc.h"
|
|
||||||
#include "base/utils/string.h"
|
|
||||||
#include "peerinfo.h"
|
#include "peerinfo.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "trackerentry.h"
|
#include "trackerentry.h"
|
||||||
|
@ -32,7 +32,9 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <libtorrent/torrent_handle.hpp>
|
||||||
|
#include <libtorrent/torrent_status.hpp>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
@ -40,50 +42,47 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include <libtorrent/torrent_handle.hpp>
|
|
||||||
#include <libtorrent/torrent_status.hpp>
|
|
||||||
|
|
||||||
#include "base/tristatebool.h"
|
|
||||||
#include "private/speedmonitor.h"
|
#include "private/speedmonitor.h"
|
||||||
#include "infohash.h"
|
#include "infohash.h"
|
||||||
#include "torrentinfo.h"
|
#include "torrentinfo.h"
|
||||||
|
|
||||||
class QBitArray;
|
|
||||||
class QStringList;
|
|
||||||
template<typename T, typename U> struct QPair;
|
|
||||||
|
|
||||||
extern const QString QB_EXT;
|
extern const QString QB_EXT;
|
||||||
|
|
||||||
|
class QBitArray;
|
||||||
|
class QDateTime;
|
||||||
|
class QStringList;
|
||||||
|
class QUrl;
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
class alert;
|
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 stats_alert;
|
||||||
|
struct storage_moved_alert;
|
||||||
|
struct storage_moved_failed_alert;
|
||||||
struct torrent_checked_alert;
|
struct torrent_checked_alert;
|
||||||
struct torrent_finished_alert;
|
struct torrent_finished_alert;
|
||||||
struct torrent_paused_alert;
|
struct torrent_paused_alert;
|
||||||
struct torrent_resumed_alert;
|
struct torrent_resumed_alert;
|
||||||
struct save_resume_data_alert;
|
struct torrent_status;
|
||||||
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 tracker_error_alert;
|
struct tracker_error_alert;
|
||||||
struct tracker_reply_alert;
|
struct tracker_reply_alert;
|
||||||
struct tracker_warning_alert;
|
struct tracker_warning_alert;
|
||||||
struct fastresume_rejected_alert;
|
|
||||||
struct torrent_status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace BitTorrent
|
namespace BitTorrent
|
||||||
{
|
{
|
||||||
struct PeerAddress;
|
|
||||||
class Session;
|
|
||||||
class PeerInfo;
|
class PeerInfo;
|
||||||
|
class Session;
|
||||||
class TrackerEntry;
|
class TrackerEntry;
|
||||||
struct AddTorrentParams;
|
struct AddTorrentParams;
|
||||||
|
struct PeerAddress;
|
||||||
|
|
||||||
struct CreateTorrentParams
|
struct CreateTorrentParams
|
||||||
{
|
{
|
||||||
|
@ -30,14 +30,15 @@
|
|||||||
|
|
||||||
#include <libtorrent/error_code.hpp>
|
#include <libtorrent/error_code.hpp>
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/misc.h"
|
|
||||||
#include "base/utils/string.h"
|
|
||||||
#include "infohash.h"
|
#include "infohash.h"
|
||||||
#include "trackerentry.h"
|
#include "trackerentry.h"
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QtGlobal>
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#include "base/indexrange.h"
|
#include "base/indexrange.h"
|
||||||
|
@ -40,42 +40,24 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
#include <CoreServices/CoreServices.h>
|
|
||||||
#include <Carbon/Carbon.h>
|
#include <Carbon/Carbon.h>
|
||||||
|
#include <CoreServices/CoreServices.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QSysInfo>
|
|
||||||
#include <QUrl>
|
|
||||||
|
|
||||||
#ifdef DISABLE_GUI
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#else
|
#include <QRegularExpression>
|
||||||
#include <QApplication>
|
#include <QSet>
|
||||||
#include <QDesktopServices>
|
#include <QSysInfo>
|
||||||
#include <QScreen>
|
|
||||||
#include <QStyle>
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QWindow>
|
|
||||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <QDBusMessage>
|
|
||||||
#endif
|
#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/unicodestrings.h"
|
||||||
#include "base/utils/string.h"
|
#include "base/utils/string.h"
|
||||||
#include "fs.h"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -249,34 +231,6 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action)
|
|||||||
#endif
|
#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)
|
QString Utils::Misc::unitString(const SizeUnit unit, const bool isSpeed)
|
||||||
{
|
{
|
||||||
const auto &unitString = units[static_cast<int>(unit)];
|
const auto &unitString = units[static_cast<int>(unit)];
|
||||||
@ -493,73 +447,6 @@ QString Utils::Misc::parseHtmlLinks(const QString &rawText)
|
|||||||
return result;
|
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<PCTSTR>(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<int, 3>;
|
|
||||||
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()
|
QString Utils::Misc::osName()
|
||||||
{
|
{
|
||||||
// static initialization for usage in signal handler
|
// static initialization for usage in signal handler
|
||||||
|
@ -29,9 +29,6 @@
|
|||||||
#ifndef UTILS_MISC_H
|
#ifndef UTILS_MISC_H
|
||||||
#define UTILS_MISC_H
|
#define UTILS_MISC_H
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
@ -39,14 +36,10 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QPoint>
|
|
||||||
#include <QSize>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QUrl>
|
|
||||||
|
|
||||||
#include "base/types.h"
|
enum class ShutdownDialogAction;
|
||||||
|
|
||||||
/* Miscellaneous functions that can be useful */
|
/* Miscellaneous functions that can be useful */
|
||||||
|
|
||||||
@ -99,13 +92,6 @@ namespace Utils
|
|||||||
QList<int> intListfromStringList(const QStringList &l);
|
QList<int> intListfromStringList(const QStringList &l);
|
||||||
QList<bool> boolListfromStringList(const QStringList &l);
|
QList<bool> 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
|
#ifdef Q_OS_WIN
|
||||||
QString windowsSystemPath();
|
QString windowsSystemPath();
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "addnewtorrentdialog.h"
|
#include "addnewtorrentdialog.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
@ -1130,7 +1130,7 @@ void MainWindow::showEvent(QShowEvent *e)
|
|||||||
|
|
||||||
// Make sure the window is initially centered
|
// Make sure the window is initially centered
|
||||||
if (!m_posInitialized) {
|
if (!m_posInitialized) {
|
||||||
move(Utils::Misc::screenCenter(this));
|
move(Utils::Gui::screenCenter(this));
|
||||||
m_posInitialized = true;
|
m_posInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,14 @@
|
|||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
#include "base/bittorrent/filepriority.h"
|
#include "base/bittorrent/filepriority.h"
|
||||||
#include "base/bittorrent/session.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));
|
qDebug("Trying to open file at %s", qUtf8Printable(filePath));
|
||||||
// Flush data
|
// Flush data
|
||||||
m_torrent->flushCache();
|
m_torrent->flushCache();
|
||||||
Utils::Misc::openPath(filePath);
|
Utils::Gui::openPath(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolder)
|
void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolder)
|
||||||
@ -563,9 +565,9 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containingFolde
|
|||||||
MacUtils::openFiles(QSet<QString>{absolutePath});
|
MacUtils::openFiles(QSet<QString>{absolutePath});
|
||||||
#else
|
#else
|
||||||
if (containingFolder)
|
if (containingFolder)
|
||||||
Utils::Misc::openFolderSelect(absolutePath);
|
Utils::Gui::openFolderSelect(absolutePath);
|
||||||
else
|
else
|
||||||
Utils::Misc::openPath(absolutePath);
|
Utils::Gui::openPath(absolutePath);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +35,9 @@
|
|||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QSortFilterProxyModel>
|
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QTreeView>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
|
|
||||||
class QHeaderView;
|
class QHeaderView;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class QStandardItem;
|
|
||||||
class QStandardItemModel;
|
class QStandardItemModel;
|
||||||
|
|
||||||
template <typename T> class CachedSettingValue;
|
template <typename T> class CachedSettingValue;
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
#include "base/utils/misc.h"
|
|
||||||
#include "ui_shutdownconfirmdialog.h"
|
#include "ui_shutdownconfirmdialog.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@ -63,7 +62,7 @@ ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDial
|
|||||||
|
|
||||||
// Always on top
|
// Always on top
|
||||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
||||||
move(Utils::Misc::screenCenter(this));
|
move(Utils::Gui::screenCenter(this));
|
||||||
|
|
||||||
m_timer.setInterval(1000); // 1sec
|
m_timer.setInterval(1000); // 1sec
|
||||||
connect(&m_timer, &QTimer::timeout, this, &ShutdownConfirmDialog::updateSeconds);
|
connect(&m_timer, &QTimer::timeout, this, &ShutdownConfirmDialog::updateSeconds);
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "transferlistmodel.h"
|
#include "transferlistmodel.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "transferlistsortmodel.h"
|
#include "transferlistsortmodel.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include "base/bittorrent/torrenthandle.h"
|
#include "base/bittorrent/torrenthandle.h"
|
||||||
@ -35,7 +36,6 @@
|
|||||||
#include "base/utils/string.h"
|
#include "base/utils/string.h"
|
||||||
#include "transferlistmodel.h"
|
#include "transferlistmodel.h"
|
||||||
|
|
||||||
|
|
||||||
TransferListSortModel::TransferListSortModel(QObject *parent)
|
TransferListSortModel::TransferListSortModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
#include "transferlistmodel.h"
|
#include "transferlistmodel.h"
|
||||||
#include "transferlistsortmodel.h"
|
#include "transferlistsortmodel.h"
|
||||||
#include "updownratiodialog.h"
|
#include "updownratiodialog.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
#include "macutilities.h"
|
#include "macutilities.h"
|
||||||
@ -341,7 +342,7 @@ TransferListModel *TransferListWidget::getSourceModel() const
|
|||||||
|
|
||||||
void TransferListWidget::previewFile(const QString &filePath)
|
void TransferListWidget::previewFile(const QString &filePath)
|
||||||
{
|
{
|
||||||
Utils::Misc::openPath(filePath);
|
Utils::Gui::openPath(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const
|
inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const
|
||||||
@ -386,9 +387,9 @@ void TransferListWidget::torrentDoubleClicked()
|
|||||||
MacUtils::openFiles(QSet<QString>{torrent->contentPath(true)});
|
MacUtils::openFiles(QSet<QString>{torrent->contentPath(true)});
|
||||||
#else
|
#else
|
||||||
if (torrent->filesCount() == 1)
|
if (torrent->filesCount() == 1)
|
||||||
Utils::Misc::openFolderSelect(torrent->contentPath(true));
|
Utils::Gui::openFolderSelect(torrent->contentPath(true));
|
||||||
else
|
else
|
||||||
Utils::Misc::openPath(torrent->contentPath(true));
|
Utils::Gui::openPath(torrent->contentPath(true));
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -592,9 +593,9 @@ void TransferListWidget::openSelectedTorrentsFolder() const
|
|||||||
QString path = torrent->contentPath(true);
|
QString path = torrent->contentPath(true);
|
||||||
if (!pathsList.contains(path)) {
|
if (!pathsList.contains(path)) {
|
||||||
if (torrent->filesCount() == 1)
|
if (torrent->filesCount() == 1)
|
||||||
Utils::Misc::openFolderSelect(path);
|
Utils::Gui::openFolderSelect(path);
|
||||||
else
|
else
|
||||||
Utils::Misc::openPath(path);
|
Utils::Gui::openPath(path);
|
||||||
}
|
}
|
||||||
pathsList.insert(path);
|
pathsList.insert(path);
|
||||||
}
|
}
|
||||||
|
@ -28,14 +28,30 @@
|
|||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include <Objbase.h>
|
||||||
|
#include <Shlobj.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QPixmap>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
|
#include <QPoint>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
#include <QUrl>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
|
||||||
|
#include "base/utils/fs.h"
|
||||||
|
#include "base/utils/version.h"
|
||||||
|
|
||||||
void Utils::Gui::resize(QWidget *widget, const QSize &newSize)
|
void Utils::Gui::resize(QWidget *widget, const QSize &newSize)
|
||||||
{
|
{
|
||||||
if (newSize.isValid())
|
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);
|
const int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize, nullptr, widget);
|
||||||
return {s, s};
|
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<PCTSTR>(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<int, 3>;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
@ -29,11 +29,11 @@
|
|||||||
#ifndef UTILS_GUI_H
|
#ifndef UTILS_GUI_H
|
||||||
#define UTILS_GUI_H
|
#define UTILS_GUI_H
|
||||||
|
|
||||||
#include <QtGlobal>
|
|
||||||
#include <QPixmap>
|
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
|
||||||
class QIcon;
|
class QIcon;
|
||||||
|
class QPixmap;
|
||||||
|
class QPoint;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
@ -55,6 +55,11 @@ namespace Utils
|
|||||||
QSize smallIconSize(const QWidget *widget = nullptr);
|
QSize smallIconSize(const QWidget *widget = nullptr);
|
||||||
QSize mediumIconSize(const QWidget *widget = nullptr);
|
QSize mediumIconSize(const QWidget *widget = nullptr);
|
||||||
QSize largeIconSize(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include "serialize_torrent.h"
|
#include "serialize_torrent.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/bittorrent/torrenthandle.h"
|
#include "base/bittorrent/torrenthandle.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user