diff --git a/src/GUI.cpp b/src/GUI.cpp index 289a6ccc1..e7e52a3aa 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -218,6 +218,15 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis } qDebug("GUI Built"); +#ifdef Q_WS_WIN + if(!Preferences::isFileAssocOk()) { + if(QMessageBox::question(0, tr("Torrent file association"), + tr("qBittorrent is not the default application to open torrent files.\nDo you want to associate qBittorrent to torrent files?"), + QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { + Preferences::setFileAssoc(); + } + } +#endif } // Destructor diff --git a/src/preferences.h b/src/preferences.h index 90d4c9ed6..140cb6bac 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -37,6 +37,12 @@ #include #include +#ifndef DISABLE_GUI +#include +#else +#include +#endif + #define QBT_REALM "Web UI Access" enum scheduler_days { EVERY_DAY, WEEK_DAYS, WEEK_ENDS, MON, TUE, WED, THU, FRI, SAT, SUN }; @@ -993,6 +999,36 @@ public: QSettings settings("qBittorrent", "qBittorrent"); return settings.value(QString::fromUtf8("Preferences/Win32/PythonPath"), "").toString(); } + + static bool isFileAssocOk() { + QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat); + if(settings.value(".torrent/Default").toString() != "qBittorrent") { + qDebug(".torrent != qBittorrent"); + return false; + } + qDebug("Checking shell command"); + QString shell_command = settings.value("qBittorrent/shell/open/command/Default", "").toString(); + qDebug("Shell command is: %s", qPrintable(shell_command)); + QRegExp exe_reg("\"([^\"]+)\".*"); + if(exe_reg.indexIn(shell_command) < 0) + return false; + QString assoc_exe = exe_reg.cap(1); + qDebug("exe: %s", qPrintable(assoc_exe)); + return (assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) == 0); + } + + static void setFileAssoc() { + QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat); + settings.setValue(".torrent/Default", "qBittorrent"); + settings.setValue(".torrent/Content Type", "application/x-bittorrent"); + settings.setValue("qBittorrent/shell/Default", "open"); + const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\""; + settings.setValue("qBittorrent/shell/open/command/Default", command_str); + settings.setValue("qBittorrent/Content Type/Default", "application/x-bittorrent"); + const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",0"; + settings.setValue("qBittorrent/DefaultIcon/Default", icon_str); + } + #endif }; diff --git a/src/qbittorrent.ico b/src/qbittorrent.ico new file mode 100644 index 000000000..e8ac738c1 Binary files /dev/null and b/src/qbittorrent.ico differ diff --git a/src/qbittorrent.rc b/src/qbittorrent.rc new file mode 100644 index 000000000..c1d62be48 --- /dev/null +++ b/src/qbittorrent.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "qbittorrent.ico" diff --git a/src/src.pro b/src/src.pro index 1b456823a..ed01a0e5c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -133,6 +133,7 @@ DEFINES += QT_USE_FAST_CONCATENATION QT_USE_FAST_OPERATOR_PLUS # win32:LIBS += -ltorrent -lboost_system # win32:LIBS += -lz ? win32 { + RC_FILE = qbittorrent.rc # Adapt these paths on Windows LIBS += C:/qbittorrent/libs/libtorrent.lib \