From 3dd7ac0549c7f2e1a5ec0751ad0bc6dc8408cbd9 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 7 Oct 2012 23:05:33 +0300 Subject: [PATCH] Add option to start qbt with Windows startup. --- src/preferences/options.ui | 7 +++++++ src/preferences/options_imp.cpp | 12 ++++++++++++ src/preferences/options_imp.h | 3 +++ src/preferences/preferences.h | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/preferences/options.ui b/src/preferences/options.ui index 3f1a6b054..c9c1ec16b 100755 --- a/src/preferences/options.ui +++ b/src/preferences/options.ui @@ -350,6 +350,13 @@ Desktop + + + + Start qBittorrent on Windows start up + + + diff --git a/src/preferences/options_imp.cpp b/src/preferences/options_imp.cpp index 7559cdc84..4395ff03f 100755 --- a/src/preferences/options_imp.cpp +++ b/src/preferences/options_imp.cpp @@ -122,6 +122,7 @@ options_imp::options_imp(QWidget *parent): #endif #ifndef Q_WS_WIN + checkStartup->setVisible(false); groupFileAssociation->setVisible(false); #endif #if LIBTORRENT_VERSION_MINOR < 16 @@ -141,6 +142,9 @@ options_imp::options_imp(QWidget *parent): connect(checkCloseToSystray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkMinimizeToSysTray, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkStartMinimized, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); +#ifdef Q_WS_WIN + connect(checkStartup, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); +#endif connect(checkShowSplash, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkProgramExitConfirm, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkPreventFromSuspend, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); @@ -372,6 +376,7 @@ void options_imp::saveOptions() { pref.setConfirmOnExit(checkProgramExitConfirm->isChecked()); pref.setPreventFromSuspend(preventFromSuspend()); #ifdef Q_WS_WIN + pref.setStartup(Startup()); // Windows: file association settings Preferences::setTorrentFileAssoc(checkAssociateTorrents->isChecked()); Preferences::setMagnetLinkAssoc(checkAssociateMagnetLinks->isChecked()); @@ -546,6 +551,7 @@ void options_imp::loadOptions() { checkProgramExitConfirm->setChecked(pref.confirmOnExit()); checkPreventFromSuspend->setChecked(pref.preventFromSuspend()); #ifdef Q_WS_WIN + checkStartup->setChecked(pref.Startup()); // Windows: file association settings checkAssociateTorrents->setChecked(Preferences::isTorrentFileAssocSet()); checkAssociateMagnetLinks->setChecked(Preferences::isMagnetLinkAssocSet()); @@ -974,6 +980,12 @@ bool options_imp::isSlashScreenDisabled() const { return !checkShowSplash->isChecked(); } +#ifdef Q_WS_WIN +bool options_imp::Startup() const { + return checkStartup->isChecked(); +} +#endif + bool options_imp::preventFromSuspend() const { return checkPreventFromSuspend->isChecked(); } diff --git a/src/preferences/options_imp.h b/src/preferences/options_imp.h index 3ee3dfbfb..ff5dd3906 100755 --- a/src/preferences/options_imp.h +++ b/src/preferences/options_imp.h @@ -101,6 +101,9 @@ private: bool startMinimized() const; bool isSlashScreenDisabled() const; bool preventFromSuspend() const; +#ifdef Q_WS_WIN + bool Startup() const; +#endif // Downloads QString getSavePath() const; bool isTempPathEnabled() const; diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index c46e7f8f7..87bc03e9e 100755 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -181,6 +181,24 @@ public: setValue("Preferences/General/PreventFromSuspend", b); } +#ifdef Q_WS_WIN + bool Startup() const { + QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); + return settings.contains("qBittorrent"); + } + + void setStartup(bool b) { + QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); + if (b) { + const QString bin_path = "\""+qApp->applicationFilePath().replace("/", "\\")+"\""; + settings.setValue("qBittorrent", bin_path); + } + else { + settings.remove("qBittorrent"); + } + } +#endif + // Downloads QString getSavePath() const { QString save_path = value(QString::fromUtf8("Preferences/Downloads/SavePath")).toString();