mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-02 13:48:05 -06:00
Move helper functions to Utils::Gui namespace
This commit is contained in:
@@ -32,12 +32,9 @@
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
|
||||
#include <QBitArray>
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QStringList>
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <libtorrent/address.hpp>
|
||||
#include <libtorrent/alert_types.hpp>
|
||||
@@ -47,17 +44,20 @@
|
||||
#include <libtorrent/magnet_uri.hpp>
|
||||
#include <libtorrent/time.hpp>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <QBitArray>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
|
||||
#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"
|
||||
|
||||
@@ -32,7 +32,9 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <libtorrent/torrent_handle.hpp>
|
||||
#include <libtorrent/torrent_status.hpp>
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
@@ -40,50 +42,47 @@
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
#include <libtorrent/torrent_handle.hpp>
|
||||
#include <libtorrent/torrent_status.hpp>
|
||||
|
||||
#include "base/tristatebool.h"
|
||||
#include "private/speedmonitor.h"
|
||||
#include "infohash.h"
|
||||
#include "torrentinfo.h"
|
||||
|
||||
class QBitArray;
|
||||
class QStringList;
|
||||
template<typename T, typename U> struct QPair;
|
||||
|
||||
extern const QString QB_EXT;
|
||||
|
||||
class QBitArray;
|
||||
class QDateTime;
|
||||
class QStringList;
|
||||
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
|
||||
{
|
||||
|
||||
@@ -30,14 +30,15 @@
|
||||
|
||||
#include <libtorrent/error_code.hpp>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "infohash.h"
|
||||
#include "trackerentry.h"
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QList>
|
||||
#include <QtGlobal>
|
||||
#include <QVector>
|
||||
|
||||
#include "base/indexrange.h"
|
||||
|
||||
@@ -40,42 +40,24 @@
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QSysInfo>
|
||||
#include <QUrl>
|
||||
|
||||
#ifdef DISABLE_GUI
|
||||
#include <QCoreApplication>
|
||||
#else
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QScreen>
|
||||
#include <QStyle>
|
||||
#include <QWidget>
|
||||
#include <QWindow>
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
#include <QSysInfo>
|
||||
|
||||
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB)
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusMessage>
|
||||
#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<int>(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<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()
|
||||
{
|
||||
// static initialization for usage in signal handler
|
||||
|
||||
@@ -29,9 +29,6 @@
|
||||
#ifndef UTILS_MISC_H
|
||||
#define UTILS_MISC_H
|
||||
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -39,14 +36,10 @@
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include <QDir>
|
||||
#include <QPoint>
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
|
||||
#include "base/types.h"
|
||||
enum class ShutdownDialogAction;
|
||||
|
||||
/* Miscellaneous functions that can be useful */
|
||||
|
||||
@@ -99,13 +92,6 @@ namespace Utils
|
||||
QList<int> intListfromStringList(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
|
||||
QString windowsSystemPath();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user