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. 51
      src/preferences/preferences.h

1
Changelog

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
* 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
- COSMETIC: Display speed at the beginning of the Window title
- OTHER: Display libraries versions in about dialog (sledgehammer999)

5
src/mainwindow.cpp

@ -284,11 +284,12 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo @@ -284,11 +284,12 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo
qDebug("GUI Built");
#ifdef Q_WS_WIN
if(!pref.neverCheckFileAssoc() && !Preferences::isFileAssocOk()) {
if(!pref.neverCheckFileAssoc() && (!Preferences::isTorrentFileAssocSet() || !Preferences::isMagnetLinkAssocSet())) {
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?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
Preferences::setFileAssoc();
Preferences::setTorrentFileAssoc(true);
Preferences::setMagnetLinkAssoc(true);
} else {
pref.setNeverCheckFileAssoc();
}

49
src/preferences/options.ui

@ -170,9 +170,9 @@ @@ -170,9 +170,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>489</width>
<height>601</height>
<y>-176</y>
<width>485</width>
<height>632</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
@ -434,6 +434,29 @@ @@ -434,6 +434,29 @@
</item>
</layout>
</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>
</widget>
</item>
@ -487,8 +510,8 @@ @@ -487,8 +510,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>501</width>
<height>999</height>
<width>488</width>
<height>902</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -947,8 +970,8 @@ @@ -947,8 +970,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>489</width>
<height>560</height>
<width>443</width>
<height>506</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
@ -1391,8 +1414,8 @@ @@ -1391,8 +1414,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>507</width>
<height>510</height>
<width>384</width>
<height>440</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">
@ -1803,8 +1826,8 @@ @@ -1803,8 +1826,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>546</width>
<height>492</height>
<width>530</width>
<height>444</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@ -2176,8 +2199,8 @@ @@ -2176,8 +2199,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>451</width>
<height>594</height>
<width>419</width>
<height>535</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">

15
src/preferences/options_imp.cpp

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

51
src/preferences/preferences.h

@ -1083,11 +1083,11 @@ public: @@ -1083,11 +1083,11 @@ public:
return value(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), false).toBool();
}
void setNeverCheckFileAssoc(bool check=true) {
void setNeverCheckFileAssoc(bool check = true) {
setValue(QString::fromUtf8("Preferences/Win32/NeverCheckFileAssocation"), check);
}
static bool isFileAssocOk() {
static bool isTorrentFileAssocSet() {
QSettings settings("HKEY_CLASSES_ROOT", QIniSettings::NativeFormat);
if(settings.value(".torrent/Default").toString() != "qBittorrent") {
qDebug(".torrent != qBittorrent");
@ -1107,37 +1107,72 @@ public: @@ -1107,37 +1107,72 @@ public:
const QString icon_str = "\""+qApp->applicationFilePath().replace("/", "\\")+"\",1";
if(settings.value("qBittorrent/DefaultIcon/Default", icon_str).toString().compare(icon_str, Qt::CaseInsensitive) != 0)
return false;
return true;
}
static bool isMagnetLinkAssocSet() {
QSettings settings("HKEY_CLASSES_ROOT", QIniSettings::NativeFormat);
// 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)
return false;
assoc_exe = exe_reg.cap(1);
QString assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qPrintable(assoc_exe));
if(assoc_exe.compare(qApp->applicationFilePath().replace("/", "\\"), Qt::CaseInsensitive) != 0)
return false;
return true;
}
static void setFileAssoc() {
static void setTorrentFileAssoc(bool set) {
QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
// .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/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("/", "\\")+"\",1";
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
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/Content Type", "application/x-magnet");
settings.setValue("Magnet/URL Protocol", "");
settings.setValue("Magnet/DefaultIcon/Default", icon_str);
settings.setValue("Magnet/shell/Default", "open");
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
bool isTrackerEnabled() const {

Loading…
Cancel
Save