From 9f2fe2b67808c1d1358b7c95120c1c7e4198083f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 4 May 2016 17:56:51 +0800 Subject: [PATCH] Move CachedSettingValue instances to header file --- src/gui/torrentcreatordlg.cpp | 68 ++++++++++++++++------------------- src/gui/torrentcreatordlg.h | 14 ++++++++ 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/gui/torrentcreatordlg.cpp b/src/gui/torrentcreatordlg.cpp index c3c8fc0af..05a619570 100644 --- a/src/gui/torrentcreatordlg.cpp +++ b/src/gui/torrentcreatordlg.cpp @@ -41,32 +41,26 @@ #include "base/bittorrent/torrentcreatorthread.h" #include "base/bittorrent/torrentinfo.h" #include "base/global.h" -#include "base/settingsstorage.h" #include "base/utils/fs.h" #include "ui_torrentcreatordlg.h" -namespace -{ #define SETTINGS_KEY(name) "TorrentCreator/" name - CachedSettingValue storeDialogSize(SETTINGS_KEY("Dimension")); - - CachedSettingValue storePieceSize(SETTINGS_KEY("PieceSize")); - CachedSettingValue storePrivateTorrent(SETTINGS_KEY("PrivateTorrent")); - CachedSettingValue storeStartSeeding(SETTINGS_KEY("StartSeeding")); - CachedSettingValue storeIgnoreRatio(SETTINGS_KEY("IgnoreRatio")); - - CachedSettingValue storeLastAddPath(SETTINGS_KEY("LastAddPath"), QDir::homePath()); - CachedSettingValue storeTrackerList(SETTINGS_KEY("TrackerList")); - CachedSettingValue storeWebSeedList(SETTINGS_KEY("WebSeedList")); - CachedSettingValue storeComments(SETTINGS_KEY("Comments")); - CachedSettingValue storeLastSavePath(SETTINGS_KEY("LastSavePath"), QDir::homePath()); -} TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent, const QString &defaultPath) : QDialog(parent) , m_ui(new Ui::TorrentCreatorDlg) , m_creatorThread(new BitTorrent::TorrentCreatorThread(this)) + , m_storeDialogSize(SETTINGS_KEY("Dimension")) + , m_storePieceSize(SETTINGS_KEY("PieceSize")) + , m_storePrivateTorrent(SETTINGS_KEY("PrivateTorrent")) + , m_storeStartSeeding(SETTINGS_KEY("StartSeeding")) + , m_storeIgnoreRatio(SETTINGS_KEY("IgnoreRatio")) + , m_storeLastAddPath(SETTINGS_KEY("LastAddPath"), QDir::homePath()) + , m_storeTrackerList(SETTINGS_KEY("TrackerList")) + , m_storeWebSeedList(SETTINGS_KEY("WebSeedList")) + , m_storeComments(SETTINGS_KEY("Comments")) + , m_storeLastSavePath(SETTINGS_KEY("LastSavePath"), QDir::homePath()) { m_ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); @@ -166,13 +160,13 @@ void TorrentCreatorDlg::onCreateButtonClicked() input = fi.canonicalFilePath(); // get save path - QString lastPath = storeLastSavePath; + QString lastPath = m_storeLastSavePath; QString destination = QFileDialog::getSaveFileName(this, tr("Select where to save the new torrent"), lastPath, tr("Torrent Files (*.torrent)")); if (destination.isEmpty()) return; if (!destination.endsWith(C_TORRENT_FILE_EXTENSION, Qt::CaseInsensitive)) destination += C_TORRENT_FILE_EXTENSION; - storeLastSavePath = Utils::Fs::branchPath(destination); + m_storeLastSavePath = Utils::Fs::branchPath(destination); // Disable dialog & set busy cursor setInteractionEnabled(false); @@ -239,34 +233,34 @@ void TorrentCreatorDlg::setInteractionEnabled(bool enabled) void TorrentCreatorDlg::saveSettings() { - storeLastAddPath = m_ui->textInputPath->text().trimmed(); + m_storeLastAddPath = m_ui->textInputPath->text().trimmed(); - storePieceSize = m_ui->comboPieceSize->currentIndex(); - storePrivateTorrent = m_ui->check_private->isChecked(); - storeStartSeeding = m_ui->checkStartSeeding->isChecked(); - storeIgnoreRatio = m_ui->checkIgnoreShareLimits->isChecked(); + m_storePieceSize = m_ui->comboPieceSize->currentIndex(); + m_storePrivateTorrent = m_ui->check_private->isChecked(); + m_storeStartSeeding = m_ui->checkStartSeeding->isChecked(); + m_storeIgnoreRatio = m_ui->checkIgnoreShareLimits->isChecked(); - storeTrackerList = m_ui->trackers_list->toPlainText(); - storeWebSeedList = m_ui->URLSeeds_list->toPlainText(); - storeComments = m_ui->txt_comment->toPlainText(); + m_storeTrackerList = m_ui->trackers_list->toPlainText(); + m_storeWebSeedList = m_ui->URLSeeds_list->toPlainText(); + m_storeComments = m_ui->txt_comment->toPlainText(); - storeDialogSize = size(); + m_storeDialogSize = size(); } void TorrentCreatorDlg::loadSettings() { - m_ui->textInputPath->setText(storeLastAddPath); + m_ui->textInputPath->setText(m_storeLastAddPath); - m_ui->comboPieceSize->setCurrentIndex(storePieceSize); - m_ui->check_private->setChecked(storePrivateTorrent); - m_ui->checkStartSeeding->setChecked(storeStartSeeding); - m_ui->checkIgnoreShareLimits->setChecked(storeIgnoreRatio); + m_ui->comboPieceSize->setCurrentIndex(m_storePieceSize); + m_ui->check_private->setChecked(m_storePrivateTorrent); + m_ui->checkStartSeeding->setChecked(m_storeStartSeeding); + m_ui->checkIgnoreShareLimits->setChecked(m_storeIgnoreRatio); m_ui->checkIgnoreShareLimits->setEnabled(m_ui->checkStartSeeding->isChecked()); - m_ui->trackers_list->setPlainText(storeTrackerList); - m_ui->URLSeeds_list->setPlainText(storeWebSeedList); - m_ui->txt_comment->setPlainText(storeComments); + m_ui->trackers_list->setPlainText(m_storeTrackerList); + m_ui->URLSeeds_list->setPlainText(m_storeWebSeedList); + m_ui->txt_comment->setPlainText(m_storeComments); - if (storeDialogSize.value().isValid()) - resize(storeDialogSize); + if (m_storeDialogSize.value().isValid()) + resize(m_storeDialogSize); } diff --git a/src/gui/torrentcreatordlg.h b/src/gui/torrentcreatordlg.h index 2783b8f4a..6faf83a32 100644 --- a/src/gui/torrentcreatordlg.h +++ b/src/gui/torrentcreatordlg.h @@ -33,6 +33,8 @@ #include +#include "base/settingvalue.h" + namespace Ui { class TorrentCreatorDlg; @@ -71,6 +73,18 @@ private: Ui::TorrentCreatorDlg *m_ui; BitTorrent::TorrentCreatorThread *m_creatorThread; + + // settings + CachedSettingValue m_storeDialogSize; + CachedSettingValue m_storePieceSize; + CachedSettingValue m_storePrivateTorrent; + CachedSettingValue m_storeStartSeeding; + CachedSettingValue m_storeIgnoreRatio; + CachedSettingValue m_storeLastAddPath; + CachedSettingValue m_storeTrackerList; + CachedSettingValue m_storeWebSeedList; + CachedSettingValue m_storeComments; + CachedSettingValue m_storeLastSavePath; }; #endif