Browse Source

Add file association settings to program preferences (Windows)

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
b58b4d0066
  1. 1
      Changelog
  2. 5
      src/mainwindow.cpp
  3. 49
      src/preferences/options.ui
  4. 15
      src/preferences/options_imp.cpp
  5. 49
      src/preferences/preferences.h

1
Changelog

@ -1,4 +1,5 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.9.0 * Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.9.0
- FEATURE: Add file association settings to program preferences (Windows)
- BUGFIX: Add tray menu entry for toggling window visibility - BUGFIX: Add tray menu entry for toggling window visibility
- COSMETIC: Display speed at the beginning of the Window title - COSMETIC: Display speed at the beginning of the Window title
- OTHER: Display libraries versions in about dialog (sledgehammer999) - OTHER: Display libraries versions in about dialog (sledgehammer999)

5
src/mainwindow.cpp

@ -284,11 +284,12 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo
qDebug("GUI Built"); qDebug("GUI Built");
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
if(!pref.neverCheckFileAssoc() && !Preferences::isFileAssocOk()) { if(!pref.neverCheckFileAssoc() && (!Preferences::isTorrentFileAssocSet() || !Preferences::isMagnetLinkAssocSet())) {
if(QMessageBox::question(0, tr("Torrent file association"), if(QMessageBox::question(0, tr("Torrent file association"),
tr("qBittorrent is not the default application to open torrent files or Magnet links.\nDo you want to associate qBittorrent to torrent files and Magnet links?"), tr("qBittorrent is not the default application to open torrent files or Magnet links.\nDo you want to associate qBittorrent to torrent files and Magnet links?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
Preferences::setFileAssoc(); Preferences::setTorrentFileAssoc(true);
Preferences::setMagnetLinkAssoc(true);
} else { } else {
pref.setNeverCheckFileAssoc(); pref.setNeverCheckFileAssoc();
} }

49
src/preferences/options.ui

@ -170,9 +170,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-176</y>
<width>489</width> <width>485</width>
<height>601</height> <height>632</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_9"> <layout class="QVBoxLayout" name="verticalLayout_9">
@ -434,6 +434,29 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QGroupBox" name="groupFileAssociation">
<property name="title">
<string>File association</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
<item>
<widget class="QCheckBox" name="checkAssociateTorrents">
<property name="text">
<string>Use qBittorrent for .torrent files</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkAssociateMagnetLinks">
<property name="text">
<string>Use qBittorrent for magnet links</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -487,8 +510,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>501</width> <width>488</width>
<height>999</height> <height>902</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -947,8 +970,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>489</width> <width>443</width>
<height>560</height> <height>506</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_20"> <layout class="QVBoxLayout" name="verticalLayout_20">
@ -1391,8 +1414,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>507</width> <width>384</width>
<height>510</height> <height>440</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_33"> <layout class="QVBoxLayout" name="verticalLayout_33">
@ -1803,8 +1826,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>546</width> <width>530</width>
<height>492</height> <height>444</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_7"> <layout class="QVBoxLayout" name="verticalLayout_7">
@ -2176,8 +2199,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>451</width> <width>419</width>
<height>594</height> <height>535</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_23"> <layout class="QVBoxLayout" name="verticalLayout_23">

15
src/preferences/options_imp.cpp

@ -120,6 +120,11 @@ options_imp::options_imp(QWidget *parent):
#if defined(QT_NO_OPENSSL) #if defined(QT_NO_OPENSSL)
checkWebUiHttps->setVisible(false); checkWebUiHttps->setVisible(false);
#endif #endif
#ifndef Q_WS_WIN
groupFileAssociation->setVisible(false);
#endif
// Connect signals / slots // Connect signals / slots
// Proxy tab // Proxy tab
connect(comboProxyType, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxy(int))); connect(comboProxyType, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxy(int)));
@ -355,6 +360,11 @@ void options_imp::saveOptions(){
pref.setSplashScreenDisabled(isSlashScreenDisabled()); pref.setSplashScreenDisabled(isSlashScreenDisabled());
pref.setConfirmOnExit(checkProgramExitConfirm->isChecked()); pref.setConfirmOnExit(checkProgramExitConfirm->isChecked());
pref.setPreventFromSuspend(preventFromSuspend()); pref.setPreventFromSuspend(preventFromSuspend());
#ifdef Q_WS_WIN
// Windows: file association settings
Preferences::setTorrentFileAssoc(checkAssociateTorrents->isChecked());
Preferences::setMagnetLinkAssoc(checkAssociateMagnetLinks->isChecked());
#endif
// End General preferences // End General preferences
// Downloads preferences // Downloads preferences
@ -519,6 +529,11 @@ void options_imp::loadOptions(){
comboTrayIcon->setCurrentIndex(pref.trayIconStyle()); comboTrayIcon->setCurrentIndex(pref.trayIconStyle());
checkProgramExitConfirm->setChecked(pref.confirmOnExit()); checkProgramExitConfirm->setChecked(pref.confirmOnExit());
checkPreventFromSuspend->setChecked(pref.preventFromSuspend()); checkPreventFromSuspend->setChecked(pref.preventFromSuspend());
#ifdef Q_WS_WIN
// Windows: file association settings
checkAssociateTorrents->setChecked(Preferences::isTorrentFileAssocSet());
checkAssociateMagnetLinks->setChecked(Preferences::isMagnetLinkAssocSet());
#endif
// End General preferences // End General preferences
// Downloads preferences // Downloads preferences
QString save_path = pref.getSavePath(); QString save_path = pref.getSavePath();

49
src/preferences/preferences.h

@ -1087,7 +1087,7 @@ public:
setValue(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), check); setValue(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), check);
} }
static bool isFileAssocOk() { static bool isTorrentFileAssocSet() {
QSettings settings("HKEY_CLASSES_ROOT", QIniSettings::NativeFormat); QSettings settings("HKEY_CLASSES_ROOT", QIniSettings::NativeFormat);
if(settings.value(".torrent/Default").toString() != "qBittorrent") { if(settings.value(".torrent/Default").toString() != "qBittorrent") {
qDebug(".torrent != qBittorrent"); qDebug(".torrent != qBittorrent");
@ -1107,37 +1107,72 @@ public:
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1"; const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
if(settings.value("qBittorrent/DefaultIcon/Default", icon_str).toString().compare(icon_str, Qt::CaseInsensitive) != 0) if(settings.value("qBittorrent/DefaultIcon/Default", icon_str).toString().compare(icon_str, Qt::CaseInsensitive) != 0)
return false; return false;
return true;
}
static bool isMagnetLinkAssocSet() {
QSettings settings("HKEY_CLASSES_ROOT", QIniSettings::NativeFormat);
// Check magnet link assoc // Check magnet link assoc
shell_command = settings.value("Magnet/shell/open/command/Default", "").toString(); QRegExp exe_reg("\"([^\"]+)\".*");
QString shell_command = settings.value("Magnet/shell/open/command/Default", "").toString();
if(exe_reg.indexIn(shell_command) < 0) if(exe_reg.indexIn(shell_command) < 0)
return false; return false;
assoc_exe = exe_reg.cap(1); QString assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qPrintable(assoc_exe)); qDebug("exe: %s", qPrintable(assoc_exe));
if(assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0) if(assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
return false; return false;
return true; return true;
} }
static void setFileAssoc() { static void setTorrentFileAssoc(bool set) {
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat); QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
// .Torrent association // .Torrent association
if (set) {
const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
settings.setValue(".torrent/Default", "qBittorrent"); settings.setValue(".torrent/Default", "qBittorrent");
settings.setValue(".torrent/Content Type", "application/x-bittorrent"); settings.setValue(".torrent/Content Type", "application/x-bittorrent");
settings.setValue("qBittorrent/shell/Default", "open"); 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/shell/open/command/Default", command_str);
settings.setValue("qBittorrent/Content Type/Default", "application/x-bittorrent"); settings.setValue("qBittorrent/Content Type/Default", "application/x-bittorrent");
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
settings.setValue("qBittorrent/DefaultIcon/Default", icon_str); settings.setValue("qBittorrent/DefaultIcon/Default", icon_str);
} else {
settings.remove(".torrent/Default");
settings.remove(".torrent/Content Type");
settings.remove("qBittorrent/shell/Default");
settings.remove("qBittorrent/shell/open/command/Default");
settings.remove("qBittorrent/Content Type/Default");
settings.remove("qBittorrent/DefaultIcon/Default");
}
}
static void setMagnetLinkAssoc(bool set) {
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
// Magnet association // Magnet association
if (set) {
const QString command_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\" \"%1\"";
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
settings.setValue("Magnet/Default", "Magnet URI"); settings.setValue("Magnet/Default", "Magnet URI");
settings.setValue("Magnet/Content Type", "application/x-magnet"); settings.setValue("Magnet/Content Type", "application/x-magnet");
settings.setValue("Magnet/URL Protocol", ""); settings.setValue("Magnet/URL Protocol", "");
settings.setValue("Magnet/DefaultIcon/Default", icon_str); settings.setValue("Magnet/DefaultIcon/Default", icon_str);
settings.setValue("Magnet/shell/Default", "open"); settings.setValue("Magnet/shell/Default", "open");
settings.setValue("Magnet/shell/open/command/Default", command_str); settings.setValue("Magnet/shell/open/command/Default", command_str);
} else {
settings.remove("Magnet/Default");
settings.remove("Magnet/Content Type");
settings.remove("Magnet/URL Protocol");
settings.remove("Magnet/DefaultIcon/Default");
settings.remove("Magnet/shell/Default");
settings.remove("Magnet/shell/open/command/Default");
}
} }
#endif #endif
bool isTrackerEnabled() const { bool isTrackerEnabled() const {

Loading…
Cancel
Save