use new settings dialog API

This commit is contained in:
Martchus 2016-04-04 14:51:51 +02:00
parent 5fa121a853
commit 556adff727
8 changed files with 147 additions and 217 deletions

View File

@ -223,7 +223,7 @@ void AddMultipleDownloadsResultsPage::initializePage()
connect(m_finder, &DownloadFinder::finished, this, &AddMultipleDownloadsResultsPage::finderFinished);
connect(m_finder, &DownloadFinder::newResultsAvailable, this, &AddMultipleDownloadsResultsPage::finderHasResults);
m_finder->setContinueAutomatically(false);
m_finder->setProxy(NetworkProxyOptionPage::proxy());
m_finder->setProxy(ProxyPage::proxy());
m_finder->start();
}
}

View File

@ -49,11 +49,11 @@ void DownloadInteraction::downloadRequiresOutputDevice(Download *download, size_
{
QString fileName = download->suitableFilename();
// use default directory and the "suitable file name" to determine the target path
if(GeneralTargetOptionPage::determineTargetFileWithoutAsking() // if correspondent option is set
if(TargetPage::determineTargetFileWithoutAsking() // if correspondent option is set
&& !forceFileDialog // and the caller don't wants to force the file dialog
&& (GeneralTargetOptionPage::targetDirectory().isEmpty() || QDir(GeneralTargetOptionPage::targetDirectory()).exists()) // and the default directory exists or is empty
&& (TargetPage::targetDirectory().isEmpty() || QDir(TargetPage::targetDirectory()).exists()) // and the default directory exists or is empty
&& !fileName.isEmpty()) { // and the file name is not empty
download->provideOutputDevice(optionIndex, new QFile(GeneralTargetOptionPage::targetDirectory() % QChar('/') % fileName), true);
download->provideOutputDevice(optionIndex, new QFile(TargetPage::targetDirectory() % QChar('/') % fileName), true);
} else { // aks the user for the target path otherwise
QFileDialog *dlg = new QFileDialog(m_parentWidget);
#ifndef Q_OS_WIN
@ -62,7 +62,7 @@ void DownloadInteraction::downloadRequiresOutputDevice(Download *download, size_
#endif
dlg->setFileMode(QFileDialog::AnyFile);
dlg->setAcceptMode(QFileDialog::AcceptSave);
dlg->setDirectory(GeneralTargetOptionPage::targetDirectory());
dlg->setDirectory(TargetPage::targetDirectory());
dlg->selectFile(fileName);
dlg->setOption(QFileDialog::DontConfirmOverwrite, true);
if(!download->title().isEmpty()) {
@ -82,7 +82,7 @@ void DownloadInteraction::downloadRequiresOutputDevice(Download *download, size_
void DownloadInteraction::downloadRequriesOverwritePermission(Download *download, size_t optionIndex, const QString &file)
{
if(GeneralTargetOptionPage::overwriteWithoutAsking()) {
if(TargetPage::overwriteWithoutAsking()) {
download->setOverwritePermission(optionIndex, PermissionStatus::Allowed);
} else {
QString message = tr("<p>The output file <i>%1</i> already exists.</p><p>Do you want to overwrite the existing file?</p>").arg(file);
@ -100,7 +100,7 @@ void DownloadInteraction::downloadRequriesOverwritePermission(Download *download
connect(dlg, &QMessageBox::finished, [download, optionIndex, dlg, overwriteButton, overwriteAlwaysButton, selectOtherButton, abortButton, this] (int) {
if(dlg->clickedButton() == overwriteAlwaysButton) {
// set dontAskBeforeOverwriting to true if the user clicked yes to all
GeneralTargetOptionPage::overwriteWithoutAsking() = true;
TargetPage::overwriteWithoutAsking() = true;
}
if(dlg->clickedButton() == overwriteButton || dlg->clickedButton() == overwriteAlwaysButton) {
download->setOverwritePermission(optionIndex, PermissionStatus::Allowed);
@ -117,7 +117,7 @@ void DownloadInteraction::downloadRequriesOverwritePermission(Download *download
void DownloadInteraction::downloadRequriesAppendingPermission(Download *download, size_t optionIndex, const QString &file, quint64 offset, quint64 fileSize)
{
if(GeneralTargetOptionPage::overwriteWithoutAsking()) {
if(TargetPage::overwriteWithoutAsking()) {
download->setAppendPermission(optionIndex, PermissionStatus::Allowed);
} else {
QString message = tr("<p>The output file <i>%1</i> already exists. The downloader assumes it contains previously downloaded data.</p><p>Do you want to <b>append</b> the received data to the existing file?</p>").arg(file);
@ -147,7 +147,7 @@ void DownloadInteraction::downloadRequriesAppendingPermission(Download *download
void DownloadInteraction::downloadRequiresRedirectionPermission(Download *download, size_t optionIndex)
{
if(NetworkMiscOptionPage::redirectWithoutAsking()) {
if(MiscPage::redirectWithoutAsking()) {
download->setRedirectPermission(optionIndex, PermissionStatus::Allowed);
} else {
const QUrl &originalUrl = download->downloadUrl(download->options().at(optionIndex).redirectionOf());
@ -164,7 +164,7 @@ void DownloadInteraction::downloadRequiresRedirectionPermission(Download *downlo
connect(dlg, &QMessageBox::finished, [download, optionIndex, dlg, this] (int result) {
switch(result) {
case QMessageBox::YesToAll:
NetworkMiscOptionPage::redirectWithoutAsking() = true;
MiscPage::redirectWithoutAsking() = true;
download->setRedirectPermission(optionIndex, PermissionStatus::AlwaysAllowed);
break;
case QMessageBox::Yes:

View File

@ -79,7 +79,7 @@ MainWindow::MainWindow(QWidget *parent) :
m_ui->setupUi(this);
// load settings
restoreGeometry(GeneralUiOptionPage::mainWindowGeometry());
restoreGeometry(UiPage::mainWindowGeometry());
// setup tray icon and its context menu
setupTrayIcon();
@ -453,7 +453,7 @@ void MainWindow::removeSelectedDownloads()
// methods for several gui features
void MainWindow::updateSelectionMode()
{
m_ui->downloadsTreeView->setSelectionMode(GeneralUiOptionPage::multiSelection() ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection);
m_ui->downloadsTreeView->setSelectionMode(UiPage::multiSelection() ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection);
}
void MainWindow::updateStartStopControls()
@ -750,11 +750,11 @@ void MainWindow::resetGroovesharkSession()
void MainWindow::exploreDownloadsDir()
{
if(GeneralTargetOptionPage::targetDirectory().isEmpty()) {
if(TargetPage::targetDirectory().isEmpty()) {
QMessageBox::warning(this, windowTitle(), tr("There is no download target selected."));
} else {
if(QDir(GeneralTargetOptionPage::targetDirectory()).exists()) {
DesktopUtils::openLocalFileOrDir(GeneralTargetOptionPage::targetDirectory());
if(QDir(TargetPage::targetDirectory()).exists()) {
DesktopUtils::openLocalFileOrDir(TargetPage::targetDirectory());
} else {
QMessageBox::warning(this, windowTitle(), tr("The selected download directory doesn't exist anymore."));
}
@ -779,8 +779,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
}
}
}
GeneralUiOptionPage::mainWindowGeometry() = saveGeometry();
GeneralUiOptionPage::mainWindowState() = saveState();
UiPage::mainWindowGeometry() = saveGeometry();
UiPage::mainWindowState() = saveState();
}
void MainWindow::downloadChangedStatus(Download *download)
@ -830,7 +830,7 @@ void MainWindow::updateOverallStatus(Download *download)
qint64 newBytesReceived = download->newBytesReceived();
qint64 newBytesToReceive = download->newBytesToReceive();
m_totalSpeed += download->shiftSpeed();
NetworkStatsOptionPage::bytesReceived() += newBytesReceived;
StatsPage::bytesReceived() += newBytesReceived;
m_stillToReceive += newBytesToReceive - newBytesReceived;
m_remainingTime = m_totalSpeed > 0
? TimeSpan::fromSeconds(static_cast<double>(m_stillToReceive) / (m_totalSpeed * 125.0))

View File

@ -7,11 +7,11 @@
<x>0</x>
<y>0</y>
<width>245</width>
<height>195</height>
<height>220</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure proxy server</string>
<string>Proxy</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>

View File

@ -5,7 +5,7 @@
// include configuration from separate header file when building with CMake
#ifndef APP_METADATA_AVAIL
#include "resources/config.h"
# include "resources/config.h"
#endif
#include <qtutilities/resources/resources.h>
@ -38,19 +38,14 @@ using namespace Network;
namespace QtGui {
GeneralTargetOptionPage::GeneralTargetOptionPage(QWidget *parentWindow) :
Dialogs::UiFileBasedOptionPage<Ui::TargetPage>(parentWindow)
TargetPage::TargetPage(QWidget *parentWindow) :
TargetPageBase(parentWindow)
{}
GeneralTargetOptionPage::~GeneralTargetOptionPage()
TargetPage::~TargetPage()
{}
QString GeneralTargetOptionPage::displayName() const
{
return QApplication::translate("QtGui::GeneralTargetOptionPage", "Target directory");
}
bool GeneralTargetOptionPage::apply()
bool TargetPage::apply()
{
if(hasBeenShown()) {
targetDirectory() = ui()->defaultTargetLineEdit->text();
@ -60,7 +55,7 @@ bool GeneralTargetOptionPage::apply()
return true;
}
void GeneralTargetOptionPage::reset()
void TargetPage::reset()
{
if(hasBeenShown()) {
ui()->defaultTargetLineEdit->setText(targetDirectory());
@ -69,27 +64,27 @@ void GeneralTargetOptionPage::reset()
}
}
QString &GeneralTargetOptionPage::targetDirectory()
QString &TargetPage::targetDirectory()
{
static QString dir;
return dir;
}
bool &GeneralTargetOptionPage::overwriteWithoutAsking()
bool &TargetPage::overwriteWithoutAsking()
{
static bool val = false;
return val;
}
bool &GeneralTargetOptionPage::determineTargetFileWithoutAsking()
bool &TargetPage::determineTargetFileWithoutAsking()
{
static bool val = true;
return val;
}
QWidget *GeneralTargetOptionPage::setupWidget()
QWidget *TargetPage::setupWidget()
{
QWidget *widget = UiFileBasedOptionPage<Ui::TargetPage>::setupWidget();
QWidget *widget = TargetPageBase::setupWidget();
// draw icon to info icon graphics view
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, widget);
QGraphicsScene *scene = new QGraphicsScene();
@ -97,11 +92,11 @@ QWidget *GeneralTargetOptionPage::setupWidget()
scene->addItem(item);
ui()->infoIconGraphicsView->setScene(scene);
// connect signals and slots
QObject::connect(ui()->selectDefaultDirPushButton, &QPushButton::clicked, std::bind(&GeneralTargetOptionPage::selectTargetDirectory, this));
QObject::connect(ui()->selectDefaultDirPushButton, &QPushButton::clicked, std::bind(&TargetPage::selectTargetDirectory, this));
return widget;
}
void GeneralTargetOptionPage::selectTargetDirectory()
void TargetPage::selectTargetDirectory()
{
QFileDialog *dlg = new QFileDialog(parentWindow());
#ifdef Q_OS_WIN
@ -121,19 +116,15 @@ void GeneralTargetOptionPage::selectTargetDirectory()
dlg->show();
}
GeneralUiOptionPage::GeneralUiOptionPage() :
UiPage::UiPage(QWidget *parentWidget) :
OptionPage(parentWidget),
m_multiSelectionCheckBox(nullptr)
{}
GeneralUiOptionPage::~GeneralUiOptionPage()
UiPage::~UiPage()
{}
QString GeneralUiOptionPage::displayName() const
{
return QApplication::translate("QtGui::GeneralUiOptionPage", "User interface");
}
bool GeneralUiOptionPage::apply()
bool UiPage::apply()
{
if(hasBeenShown()) {
multiSelection() = m_multiSelectionCheckBox->isChecked();
@ -141,34 +132,35 @@ bool GeneralUiOptionPage::apply()
return true;
}
void GeneralUiOptionPage::reset()
void UiPage::reset()
{
if(hasBeenShown()) {
m_multiSelectionCheckBox->setChecked(multiSelection());
}
}
QByteArray &GeneralUiOptionPage::mainWindowGeometry()
QByteArray &UiPage::mainWindowGeometry()
{
static QByteArray geometry;
return geometry;
}
QByteArray &GeneralUiOptionPage::mainWindowState()
QByteArray &UiPage::mainWindowState()
{
static QByteArray state;
return state;
}
bool &GeneralUiOptionPage::multiSelection()
bool &UiPage::multiSelection()
{
static bool val = false;
return val;
}
QWidget *GeneralUiOptionPage::setupWidget()
QWidget *UiPage::setupWidget()
{
QWidget *widget = new QWidget();
widget->setWindowTitle(QApplication::translate("QtGui::GeneralUiOptionPage", "User interface"));
QVBoxLayout *layout = new QVBoxLayout(widget);
QLabel *mainWindowLabel = new QLabel(QApplication::translate("QtGui::GeneralUiOptionPage", "Main window"));
mainWindowLabel->setStyleSheet(QStringLiteral("font-weight: bold;"));
@ -178,18 +170,14 @@ QWidget *GeneralUiOptionPage::setupWidget()
return widget;
}
NetworkProxyOptionPage::NetworkProxyOptionPage()
ProxyPage::ProxyPage(QWidget *parentWidget) :
ProxyPageBase(parentWidget)
{}
NetworkProxyOptionPage::~NetworkProxyOptionPage()
ProxyPage::~ProxyPage()
{}
QString NetworkProxyOptionPage::displayName() const
{
return QApplication::translate("QtGui::NetworkProxyOptionPage", "Proxy server");
}
bool NetworkProxyOptionPage::apply()
bool ProxyPage::apply()
{
if(hasBeenShown()) {
// set entered values to proxy
@ -213,7 +201,7 @@ bool NetworkProxyOptionPage::apply()
return true;
}
void NetworkProxyOptionPage::reset()
void ProxyPage::reset()
{
if(hasBeenShown()) {
switch(proxy().type()) {
@ -242,23 +230,24 @@ void NetworkProxyOptionPage::reset()
}
}
QNetworkProxy &NetworkProxyOptionPage::proxy()
QNetworkProxy &ProxyPage::proxy()
{
static QNetworkProxy proxy;
return proxy;
}
QWidget *NetworkProxyOptionPage::setupWidget()
QWidget *ProxyPage::setupWidget()
{
QWidget *widget = Dialogs::UiFileBasedOptionPage<Ui::ProxyPage>::setupWidget();
QWidget *widget = ProxyPageBase::setupWidget();
widget->setWindowTitle(QApplication::translate("QtGui::NetworkProxyOptionPage", "Proxy server"));
ui()->widget->setEnabled(false);
// connect signals and slots
QObject::connect(ui()->enableCheckBox, &QCheckBox::clicked, ui()->widget, &QWidget::setEnabled);
QObject::connect(ui()->hostNameLineEdit, &QLineEdit::editingFinished, std::bind(&NetworkProxyOptionPage::updateProxy, this));
QObject::connect(ui()->hostNameLineEdit, &QLineEdit::editingFinished, std::bind(&ProxyPage::updateProxy, this));
return widget;
}
void NetworkProxyOptionPage::updateProxy()
void ProxyPage::updateProxy()
{
QStringList parts = ui()->hostNameLineEdit->text().split(":", QString::SkipEmptyParts);
if(parts.count() == 2) {
@ -271,18 +260,14 @@ void NetworkProxyOptionPage::updateProxy()
}
}
NetworkUserAgentOptionPage::NetworkUserAgentOptionPage()
UserAgentPage::UserAgentPage(QWidget *parentWidget) :
UserAgentPageBase(parentWidget)
{}
NetworkUserAgentOptionPage::~NetworkUserAgentOptionPage()
UserAgentPage::~UserAgentPage()
{}
QString NetworkUserAgentOptionPage::displayName() const
{
return QApplication::translate("QtGui::NetworkUserAgentOptionPage", "HTTP user agent");
}
bool NetworkUserAgentOptionPage::apply()
bool UserAgentPage::apply()
{
if(hasBeenShown()) {
useCustomUserAgent() = ui()->customRadioButton->isChecked();
@ -291,7 +276,7 @@ bool NetworkUserAgentOptionPage::apply()
return true;
}
void NetworkUserAgentOptionPage::reset()
void UserAgentPage::reset()
{
if(hasBeenShown()) {
if(useCustomUserAgent()) {
@ -303,31 +288,27 @@ void NetworkUserAgentOptionPage::reset()
}
}
bool &NetworkUserAgentOptionPage::useCustomUserAgent()
bool &UserAgentPage::useCustomUserAgent()
{
static bool useCustomUserAgent = false;
return useCustomUserAgent;
}
QString &NetworkUserAgentOptionPage::customUserAgent()
QString &UserAgentPage::customUserAgent()
{
static QString userAgent;
return userAgent;
}
NetworkMiscOptionPage::NetworkMiscOptionPage() :
MiscPage::MiscPage(QWidget *parentWidget) :
OptionPage(parentWidget),
m_redirectCheckBox(nullptr)
{}
NetworkMiscOptionPage::~NetworkMiscOptionPage()
MiscPage::~MiscPage()
{}
QString NetworkMiscOptionPage::displayName() const
{
return QApplication::translate("QtGui::NetworkMiscOptionPage", "Misc");
}
bool NetworkMiscOptionPage::apply()
bool MiscPage::apply()
{
if(hasBeenShown()) {
redirectWithoutAsking() = m_redirectCheckBox->isChecked();
@ -335,67 +316,65 @@ bool NetworkMiscOptionPage::apply()
return true;
}
void NetworkMiscOptionPage::reset()
void MiscPage::reset()
{
if(hasBeenShown()) {
m_redirectCheckBox->setChecked(redirectWithoutAsking());
}
}
bool &NetworkMiscOptionPage::redirectWithoutAsking()
bool &MiscPage::redirectWithoutAsking()
{
static bool val = false;
return val;
}
QWidget *NetworkMiscOptionPage::setupWidget()
QWidget *MiscPage::setupWidget()
{
QWidget *widget = new QWidget();
widget->setWindowTitle(QApplication::translate("QtGui::NetworkMiscOptionPage", "Misc"));
QVBoxLayout *layout = new QVBoxLayout(widget);
layout->addWidget(m_redirectCheckBox = new QCheckBox(QApplication::translate("QtGui::NetworkMiscOptionPage", "follow redirections without asking"), widget));
widget->setLayout(layout);
return widget;
}
NetworkStatsOptionPage::NetworkStatsOptionPage() :
StatsPage::StatsPage(QWidget *parentWidget) :
OptionPage(parentWidget),
m_receivedLabel(nullptr)
{}
NetworkStatsOptionPage::~NetworkStatsOptionPage()
StatsPage::~StatsPage()
{}
QString NetworkStatsOptionPage::displayName() const
{
return QApplication::translate("QtGui::NetworkStatsOptionPage", "Statistics");
}
bool NetworkStatsOptionPage::apply()
bool StatsPage::apply()
{
return true;
}
void NetworkStatsOptionPage::reset()
void StatsPage::reset()
{
if(hasBeenShown()) {
m_receivedLabel->setText(QString::fromStdString(ConversionUtilities::dataSizeToString(bytesReceived(), true)));
}
}
quint64 &NetworkStatsOptionPage::bytesReceived()
quint64 &StatsPage::bytesReceived()
{
static quint64 received;
return received;
}
QWidget *NetworkStatsOptionPage::setupWidget()
QWidget *StatsPage::setupWidget()
{
QWidget *widget = new QWidget();
widget->setWindowTitle(QApplication::translate("QtGui::NetworkStatsOptionPage", "Statistics"));
QVBoxLayout *mainLayout = new QVBoxLayout(widget);
QFormLayout *formLayout = new QFormLayout(widget);
formLayout->addRow(QApplication::translate("QtGui::NetworkStatsOptionPage", "Received data"), m_receivedLabel = new QLabel());
QPushButton *refreshButton = new QPushButton(QApplication::translate("QtGui::NetworkStatsOptionPage", "Refresh"));
refreshButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
QObject::connect(refreshButton, &QPushButton::clicked, std::bind(&NetworkStatsOptionPage::reset, this));
QObject::connect(refreshButton, &QPushButton::clicked, std::bind(&StatsPage::reset, this));
mainLayout->addLayout(formLayout);
mainLayout->addWidget(refreshButton);
widget->setLayout(mainLayout);
@ -411,14 +390,14 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
category = new Dialogs::OptionCategory(this);
category->setDisplayName(tr("General"));
category->assignPages(QList<Dialogs::OptionPage *>() << new GeneralTargetOptionPage(this) << new GeneralUiOptionPage());
category->assignPages(QList<Dialogs::OptionPage *>() << new TargetPage(this) << new UiPage());
category->setIcon(QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/32x32/categories/preferences-general.png"))));
categories << category;
category = new Dialogs::OptionCategory(this);
category->setDisplayName(tr("Network"));
category->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-network"), QIcon(QStringLiteral(":/icons/hicolor/32x32/categories/preferences-network.png"))));
category->assignPages(QList<Dialogs::OptionPage *>() << new NetworkProxyOptionPage() << new NetworkUserAgentOptionPage() << new NetworkMiscOptionPage() << new NetworkStatsOptionPage());
category->assignPages(QList<Dialogs::OptionPage *>() << new ProxyPage() << new UserAgentPage() << new MiscPage() << new StatsPage());
categories << category;
category = new Dialogs::OptionCategory(this);
@ -440,18 +419,18 @@ void restoreSettings()
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName());
settings.beginGroup("application");
GeneralTargetOptionPage::targetDirectory() = settings.value("defaulttargetdirectory").toString();
GeneralTargetOptionPage::overwriteWithoutAsking() = settings.value("overwritewithoutasking", false).toBool();
GeneralTargetOptionPage::determineTargetFileWithoutAsking() = settings.value("determinetargetfilewithoutasking", true).toBool();
NetworkMiscOptionPage::redirectWithoutAsking() = settings.value("redirectwithoutasking", true).toBool();
NetworkUserAgentOptionPage::useCustomUserAgent() = settings.value("usecustomuseragent", false).toBool();
NetworkUserAgentOptionPage::customUserAgent() = settings.value("customuseragent").toString();
TargetPage::targetDirectory() = settings.value("defaulttargetdirectory").toString();
TargetPage::overwriteWithoutAsking() = settings.value("overwritewithoutasking", false).toBool();
TargetPage::determineTargetFileWithoutAsking() = settings.value("determinetargetfilewithoutasking", true).toBool();
MiscPage::redirectWithoutAsking() = settings.value("redirectwithoutasking", true).toBool();
UserAgentPage::useCustomUserAgent() = settings.value("usecustomuseragent", false).toBool();
UserAgentPage::customUserAgent() = settings.value("customuseragent").toString();
settings.beginGroup("proxy");
bool validProxyType;
int proxyType = settings.value("type", QVariant(QNetworkProxy::NoProxy)).toInt(&validProxyType);
validProxyType = proxyType >= 0 && proxyType <= 5;
QNetworkProxy &proxy = NetworkProxyOptionPage::proxy();
QNetworkProxy &proxy = ProxyPage::proxy();
proxy.setType(validProxyType ? static_cast<QNetworkProxy::ProxyType>(proxyType) : QNetworkProxy::NoProxy);
proxy.setHostName(settings.value("hostname").toString());
proxy.setPort(settings.value("port", QVariant(0)).toUInt());
@ -461,13 +440,13 @@ void restoreSettings()
settings.endGroup();
settings.beginGroup("statistics");
NetworkStatsOptionPage::bytesReceived() = settings.value("totalbytesreceived", 0).toLongLong();
StatsPage::bytesReceived() = settings.value("totalbytesreceived", 0).toLongLong();
settings.endGroup();
settings.beginGroup("mainwindow");
GeneralUiOptionPage::mainWindowGeometry() = settings.value("geometry").toByteArray();
GeneralUiOptionPage::mainWindowState() = settings.value("state").toByteArray();
GeneralUiOptionPage::multiSelection() = settings.value("multiselection").toBool();
UiPage::mainWindowGeometry() = settings.value("geometry").toByteArray();
UiPage::mainWindowState() = settings.value("state").toByteArray();
UiPage::multiSelection() = settings.value("multiselection").toBool();
// load grooveshark authentication file
const auto errorMsg = QApplication::translate("QtGui::Settings", "Unable to read Grooveshark authentication information file.\n\nReason: %1\n\nThe values stored in this file are required when connection to Grooveshark. Built-in will values be used instead, but these might be deprecated.");
@ -487,15 +466,15 @@ void saveSettings()
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName());
settings.beginGroup("application");
settings.setValue("defaulttargetdirectory", GeneralTargetOptionPage::targetDirectory());
settings.setValue("overwritewithoutasking", GeneralTargetOptionPage::overwriteWithoutAsking());
settings.setValue("determinetargetfilewithoutasking", GeneralTargetOptionPage::determineTargetFileWithoutAsking());
settings.setValue("redirectwithoutasking", NetworkMiscOptionPage::redirectWithoutAsking());
settings.setValue("usecustomuseragent", NetworkUserAgentOptionPage::useCustomUserAgent());
settings.setValue("customuseragent", NetworkUserAgentOptionPage::customUserAgent());
settings.setValue("defaulttargetdirectory", TargetPage::targetDirectory());
settings.setValue("overwritewithoutasking", TargetPage::overwriteWithoutAsking());
settings.setValue("determinetargetfilewithoutasking", TargetPage::determineTargetFileWithoutAsking());
settings.setValue("redirectwithoutasking", MiscPage::redirectWithoutAsking());
settings.setValue("usecustomuseragent", UserAgentPage::useCustomUserAgent());
settings.setValue("customuseragent", UserAgentPage::customUserAgent());
settings.beginGroup("proxy");
const QNetworkProxy &proxy = NetworkProxyOptionPage::proxy();
const QNetworkProxy &proxy = ProxyPage::proxy();
settings.setValue("type", proxy.type());
settings.setValue("hostname", proxy.hostName());
settings.setValue("port", proxy.port());
@ -505,21 +484,21 @@ void saveSettings()
settings.endGroup();
settings.beginGroup("statistics");
settings.setValue("totalbytesreceived", NetworkStatsOptionPage::bytesReceived());
settings.setValue("totalbytesreceived", StatsPage::bytesReceived());
settings.endGroup();
settings.beginGroup("mainwindow");
settings.setValue("geometry", GeneralUiOptionPage::mainWindowGeometry());
settings.setValue("state", GeneralUiOptionPage::mainWindowState());
settings.setValue("multiselection", GeneralUiOptionPage::multiSelection());
settings.setValue("geometry", UiPage::mainWindowGeometry());
settings.setValue("state", UiPage::mainWindowState());
settings.setValue("multiselection", UiPage::multiSelection());
settings.endGroup();
}
void applySettingsToDownload(Download *download)
{
download->setDefaultUserAgentUsed(!NetworkUserAgentOptionPage::useCustomUserAgent());
download->setCustomUserAgent(NetworkUserAgentOptionPage::useCustomUserAgent() ? NetworkUserAgentOptionPage::customUserAgent() : QString());
download->setProxy(NetworkProxyOptionPage::proxy());
download->setDefaultUserAgentUsed(!UserAgentPage::useCustomUserAgent());
download->setCustomUserAgent(UserAgentPage::useCustomUserAgent() ? UserAgentPage::customUserAgent() : QString());
download->setProxy(ProxyPage::proxy());
}
}

View File

@ -9,13 +9,11 @@
#include <qtutilities/settingsdialog/settingsdialog.h>
#include <qtutilities/settingsdialog/optionpage.h>
QT_BEGIN_NAMESPACE
class QByteArray;
class QLabel;
class QLineEdit;
class QCheckBox;
class QNetworkProxy;
QT_END_NAMESPACE
QT_FORWARD_DECLARE_CLASS(QByteArray)
QT_FORWARD_DECLARE_CLASS(QLabel)
QT_FORWARD_DECLARE_CLASS(QLineEdit)
QT_FORWARD_DECLARE_CLASS(QCheckBox)
QT_FORWARD_DECLARE_CLASS(QNetworkProxy)
namespace Network {
class Download;
@ -23,118 +21,55 @@ class Download;
namespace QtGui {
namespace Ui {
class TargetPage;
class ProxyPage;
class UserAgentPage;
}
class GeneralTargetOptionPage : public Dialogs::UiFileBasedOptionPage<Ui::TargetPage>
{
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(TargetPage)
DECLARE_SETUP_WIDGETS
public:
explicit GeneralTargetOptionPage(QWidget *parentWindow);
~GeneralTargetOptionPage();
QString displayName() const;
bool apply();
void reset();
static QString &targetDirectory();
static bool &overwriteWithoutAsking();
static bool &determineTargetFileWithoutAsking();
protected:
QWidget *setupWidget();
private:
void selectTargetDirectory();
};
END_DECLARE_OPTION_PAGE
class GeneralUiOptionPage : public Dialogs::OptionPage
{
BEGIN_DECLARE_OPTION_PAGE(UiPage)
DECLARE_SETUP_WIDGETS
public:
explicit GeneralUiOptionPage();
~GeneralUiOptionPage();
QString displayName() const;
bool apply();
void reset();
static QByteArray &mainWindowGeometry();
static QByteArray &mainWindowState();
static bool &multiSelection();
protected:
QWidget *setupWidget();
private:
QCheckBox *m_multiSelectionCheckBox;
};
END_DECLARE_OPTION_PAGE
class NetworkProxyOptionPage : public Dialogs::UiFileBasedOptionPage<Ui::ProxyPage>
{
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(ProxyPage)
DECLARE_SETUP_WIDGETS
public:
explicit NetworkProxyOptionPage();
~NetworkProxyOptionPage();
QString displayName() const;
bool apply();
void reset();
static QNetworkProxy &proxy();
protected:
QWidget *setupWidget();
private:
void updateProxy();
};
END_DECLARE_OPTION_PAGE
class NetworkUserAgentOptionPage : public Dialogs::UiFileBasedOptionPage<Ui::UserAgentPage>
{
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(UserAgentPage)
public:
explicit NetworkUserAgentOptionPage();
~NetworkUserAgentOptionPage();
QString displayName() const;
bool apply();
void reset();
static bool &useCustomUserAgent();
static QString &customUserAgent();
};
END_DECLARE_OPTION_PAGE
class NetworkMiscOptionPage : public Dialogs::OptionPage
{
BEGIN_DECLARE_OPTION_PAGE(MiscPage)
DECLARE_SETUP_WIDGETS
public:
explicit NetworkMiscOptionPage();
~NetworkMiscOptionPage();
QString displayName() const;
bool apply();
void reset();
static bool &redirectWithoutAsking();
protected:
QWidget *setupWidget();
private:
QCheckBox *m_redirectCheckBox;
};
END_DECLARE_OPTION_PAGE
class NetworkStatsOptionPage : public Dialogs::OptionPage
{
BEGIN_DECLARE_OPTION_PAGE(StatsPage)
DECLARE_SETUP_WIDGETS
public:
explicit NetworkStatsOptionPage();
~NetworkStatsOptionPage();
QString displayName() const;
bool apply();
void reset();
static quint64 &bytesReceived();
protected:
QWidget *setupWidget();
private:
QLabel *m_receivedLabel;
};
END_DECLARE_OPTION_PAGE
class SettingsDialog : public Dialogs::SettingsDialog
{

View File

@ -2,8 +2,16 @@
<ui version="4.0">
<class>QtGui::TargetPage</class>
<widget class="QWidget" name="QtGui::TargetPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>180</height>
</rect>
</property>
<property name="windowTitle">
<string>Select target directory</string>
<string>Target directory</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>

View File

@ -2,8 +2,16 @@
<ui version="4.0">
<class>QtGui::UserAgentPage</class>
<widget class="QWidget" name="QtGui::UserAgentPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>239</width>
<height>68</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure user agent</string>
<string>HTTP user agent</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@ -15,7 +23,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Use a random default user agent</string>
<string>Use a ra&amp;ndom default user agent</string>
</property>
</widget>
</item>
@ -30,7 +38,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Custom user agent</string>
<string>&amp;Custom user agent</string>
</property>
</widget>
</item>