Browse Source

Use CachedSettingValue

adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
2e8c01d88c
  1. 163
      src/gui/torrentcreatordlg.cpp
  2. 22
      src/gui/torrentcreatordlg.h

163
src/gui/torrentcreatordlg.cpp

@ -49,20 +49,18 @@
namespace namespace
{ {
#define SETTINGS_KEY(name) "TorrentCreator/" name #define SETTINGS_KEY(name) "TorrentCreator/" name
const QString KEY_DIALOG_SIZE = SETTINGS_KEY("Dimension"); CachedSettingValue<QSize> storeDialogSize(SETTINGS_KEY("Dimension"));
const QString KEY_PIECE_SIZE = SETTINGS_KEY("PieceSize"); CachedSettingValue<int> storePieceSize(SETTINGS_KEY("PieceSize"));
const QString KEY_PRIVATE_TORRENT = SETTINGS_KEY("PrivateTorrent"); CachedSettingValue<bool> storePrivateTorrent(SETTINGS_KEY("PrivateTorrent"));
const QString KEY_START_SEEDING = SETTINGS_KEY("StartSeeding"); CachedSettingValue<bool> storeStartSeeding(SETTINGS_KEY("StartSeeding"));
const QString KEY_SETTING_IGNORE_RATIO = SETTINGS_KEY("IgnoreRatio"); CachedSettingValue<bool> storeIgnoreRatio(SETTINGS_KEY("IgnoreRatio"));
const QString KEY_LAST_ADD_PATH = SETTINGS_KEY("LastAddPath"); CachedSettingValue<QString> storeLastAddPath(SETTINGS_KEY("LastAddPath"), QDir::homePath());
const QString KEY_TRACKER_LIST = SETTINGS_KEY("TrackerList"); CachedSettingValue<QString> storeTrackerList(SETTINGS_KEY("TrackerList"));
const QString KEY_WEB_SEED_LIST = SETTINGS_KEY("WebSeedList"); CachedSettingValue<QString> storeWebSeedList(SETTINGS_KEY("WebSeedList"));
const QString KEY_COMMENTS = SETTINGS_KEY("Comments"); CachedSettingValue<QString> storeComments(SETTINGS_KEY("Comments"));
const QString KEY_LAST_SAVE_PATH = SETTINGS_KEY("LastSavePath"); CachedSettingValue<QString> storeLastSavePath(SETTINGS_KEY("LastSavePath"), QDir::homePath());
SettingsStorage *settings() { return SettingsStorage::instance(); }
} }
TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent, const QString &defaultPath) TorrentCreatorDlg::TorrentCreatorDlg(QWidget *parent, const QString &defaultPath)
@ -159,13 +157,13 @@ void TorrentCreatorDlg::onCreateButtonClicked()
input = fi.canonicalFilePath(); input = fi.canonicalFilePath();
// get save path // get save path
QString lastPath = getLastSavePath(); QString lastPath = storeLastSavePath;
QString destination = QFileDialog::getSaveFileName(this, tr("Select where to save the new torrent"), lastPath, tr("Torrent Files (*.torrent)")); QString destination = QFileDialog::getSaveFileName(this, tr("Select where to save the new torrent"), lastPath, tr("Torrent Files (*.torrent)"));
if (destination.isEmpty()) if (destination.isEmpty())
return; return;
if (!destination.endsWith(".torrent", Qt::CaseInsensitive)) if (!destination.endsWith(".torrent", Qt::CaseInsensitive))
destination += ".torrent"; destination += ".torrent";
setLastSavePath(Utils::Fs::branchPath(destination)); storeLastSavePath = Utils::Fs::branchPath(destination);
// Disable dialog & set busy cursor // Disable dialog & set busy cursor
setInteractionEnabled(false); setInteractionEnabled(false);
@ -245,133 +243,34 @@ void TorrentCreatorDlg::showProgressBar(bool show)
void TorrentCreatorDlg::saveSettings() void TorrentCreatorDlg::saveSettings()
{ {
setLastAddPath(m_ui->textInputPath->text().trimmed()); storeLastAddPath = m_ui->textInputPath->text().trimmed();
setSettingPieceSize(m_ui->comboPieceSize->currentIndex()); storePieceSize = m_ui->comboPieceSize->currentIndex();
setSettingPrivateTorrent(m_ui->check_private->isChecked()); storePrivateTorrent = m_ui->check_private->isChecked();
setSettingStartSeeding(m_ui->checkStartSeeding->isChecked()); storeStartSeeding = m_ui->checkStartSeeding->isChecked();
setSettingIgnoreRatio(m_ui->checkIgnoreShareLimits->isChecked()); storeIgnoreRatio = m_ui->checkIgnoreShareLimits->isChecked();
setTrackerList(m_ui->trackers_list->toPlainText()); storeTrackerList = m_ui->trackers_list->toPlainText();
setWebSeedList(m_ui->URLSeeds_list->toPlainText()); storeWebSeedList = m_ui->URLSeeds_list->toPlainText();
setComments(m_ui->txt_comment->toPlainText()); storeComments = m_ui->txt_comment->toPlainText();
setDialogSize(size()); storeDialogSize = size();
} }
void TorrentCreatorDlg::loadSettings() void TorrentCreatorDlg::loadSettings()
{ {
m_ui->textInputPath->setText(!m_defaultPath.isEmpty() ? m_defaultPath : getLastAddPath()); m_ui->textInputPath->setText(!m_defaultPath.isEmpty() ? m_defaultPath : storeLastAddPath);
m_ui->comboPieceSize->setCurrentIndex(getSettingPieceSize()); m_ui->comboPieceSize->setCurrentIndex(storePieceSize);
m_ui->check_private->setChecked(getSettingPrivateTorrent()); m_ui->check_private->setChecked(storePrivateTorrent);
m_ui->checkStartSeeding->setChecked(getSettingStartSeeding()); m_ui->checkStartSeeding->setChecked(storeStartSeeding);
m_ui->checkIgnoreShareLimits->setChecked(getSettingIgnoreRatio()); m_ui->checkIgnoreShareLimits->setChecked(storeIgnoreRatio);
m_ui->checkIgnoreShareLimits->setEnabled(m_ui->checkStartSeeding->isChecked()); m_ui->checkIgnoreShareLimits->setEnabled(m_ui->checkStartSeeding->isChecked());
m_ui->trackers_list->setPlainText(getTrackerList()); m_ui->trackers_list->setPlainText(storeTrackerList);
m_ui->URLSeeds_list->setPlainText(getWebSeedList()); m_ui->URLSeeds_list->setPlainText(storeWebSeedList);
m_ui->txt_comment->setPlainText(getComments()); m_ui->txt_comment->setPlainText(storeComments);
resize(getDialogSize());
}
QSize TorrentCreatorDlg::getDialogSize() const
{
return settings()->loadValue(KEY_DIALOG_SIZE, size()).toSize();
}
void TorrentCreatorDlg::setDialogSize(const QSize &size)
{
settings()->storeValue(KEY_DIALOG_SIZE, size);
}
int TorrentCreatorDlg::getSettingPieceSize() const
{
return settings()->loadValue(KEY_PIECE_SIZE).toInt();
}
void TorrentCreatorDlg::setSettingPieceSize(const int size)
{
settings()->storeValue(KEY_PIECE_SIZE, size);
}
bool TorrentCreatorDlg::getSettingPrivateTorrent() const if (storeDialogSize.value().isValid())
{ resize(storeDialogSize);
return settings()->loadValue(KEY_PRIVATE_TORRENT).toBool();
}
void TorrentCreatorDlg::setSettingPrivateTorrent(const bool b)
{
settings()->storeValue(KEY_PRIVATE_TORRENT, b);
}
bool TorrentCreatorDlg::getSettingStartSeeding() const
{
return settings()->loadValue(KEY_START_SEEDING).toBool();
}
void TorrentCreatorDlg::setSettingStartSeeding(const bool b)
{
settings()->storeValue(KEY_START_SEEDING, b);
}
bool TorrentCreatorDlg::getSettingIgnoreRatio() const
{
return settings()->loadValue(KEY_SETTING_IGNORE_RATIO).toBool();
}
void TorrentCreatorDlg::setSettingIgnoreRatio(const bool ignore)
{
settings()->storeValue(KEY_SETTING_IGNORE_RATIO, ignore);
}
QString TorrentCreatorDlg::getLastAddPath() const
{
return settings()->loadValue(KEY_LAST_ADD_PATH, QDir::homePath()).toString();
}
void TorrentCreatorDlg::setLastAddPath(const QString &path)
{
settings()->storeValue(KEY_LAST_ADD_PATH, path);
}
QString TorrentCreatorDlg::getTrackerList() const
{
return settings()->loadValue(KEY_TRACKER_LIST).toString();
}
void TorrentCreatorDlg::setTrackerList(const QString &list)
{
settings()->storeValue(KEY_TRACKER_LIST, list);
}
QString TorrentCreatorDlg::getWebSeedList() const
{
return settings()->loadValue(KEY_WEB_SEED_LIST).toString();
}
void TorrentCreatorDlg::setWebSeedList(const QString &list)
{
settings()->storeValue(KEY_WEB_SEED_LIST, list);
}
QString TorrentCreatorDlg::getComments() const
{
return settings()->loadValue(KEY_COMMENTS).toString();
}
void TorrentCreatorDlg::setComments(const QString &str)
{
settings()->storeValue(KEY_COMMENTS, str);
}
QString TorrentCreatorDlg::getLastSavePath() const
{
return settings()->loadValue(KEY_LAST_SAVE_PATH, QDir::homePath()).toString();
}
void TorrentCreatorDlg::setLastSavePath(const QString &path)
{
settings()->storeValue(KEY_LAST_SAVE_PATH, path);
} }

22
src/gui/torrentcreatordlg.h

@ -69,28 +69,6 @@ private:
void showProgressBar(bool show); void showProgressBar(bool show);
void setInteractionEnabled(bool enabled); void setInteractionEnabled(bool enabled);
// settings storage
QSize getDialogSize() const;
void setDialogSize(const QSize &size);
int getSettingPieceSize() const;
void setSettingPieceSize(const int size);
bool getSettingPrivateTorrent() const;
void setSettingPrivateTorrent(const bool b);
bool getSettingStartSeeding() const;
void setSettingStartSeeding(const bool b);
bool getSettingIgnoreRatio() const;
void setSettingIgnoreRatio(const bool ignore);
QString getLastAddPath() const;
void setLastAddPath(const QString &path);
QString getTrackerList() const;
void setTrackerList(const QString &list);
QString getWebSeedList() const;
void setWebSeedList(const QString &list);
QString getComments() const;
void setComments(const QString &str);
QString getLastSavePath() const;
void setLastSavePath(const QString &path);
Ui::TorrentCreatorDlg *m_ui; Ui::TorrentCreatorDlg *m_ui;
BitTorrent::TorrentCreatorThread *m_creatorThread; BitTorrent::TorrentCreatorThread *m_creatorThread;
QString m_defaultPath; QString m_defaultPath;

Loading…
Cancel
Save