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::finished, this, &AddMultipleDownloadsResultsPage::finderFinished);
connect(m_finder, &DownloadFinder::newResultsAvailable, this, &AddMultipleDownloadsResultsPage::finderHasResults); connect(m_finder, &DownloadFinder::newResultsAvailable, this, &AddMultipleDownloadsResultsPage::finderHasResults);
m_finder->setContinueAutomatically(false); m_finder->setContinueAutomatically(false);
m_finder->setProxy(NetworkProxyOptionPage::proxy()); m_finder->setProxy(ProxyPage::proxy());
m_finder->start(); m_finder->start();
} }
} }

View File

@ -49,11 +49,11 @@ void DownloadInteraction::downloadRequiresOutputDevice(Download *download, size_
{ {
QString fileName = download->suitableFilename(); QString fileName = download->suitableFilename();
// use default directory and the "suitable file name" to determine the target path // 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 && !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 && !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 } else { // aks the user for the target path otherwise
QFileDialog *dlg = new QFileDialog(m_parentWidget); QFileDialog *dlg = new QFileDialog(m_parentWidget);
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
@ -62,7 +62,7 @@ void DownloadInteraction::downloadRequiresOutputDevice(Download *download, size_
#endif #endif
dlg->setFileMode(QFileDialog::AnyFile); dlg->setFileMode(QFileDialog::AnyFile);
dlg->setAcceptMode(QFileDialog::AcceptSave); dlg->setAcceptMode(QFileDialog::AcceptSave);
dlg->setDirectory(GeneralTargetOptionPage::targetDirectory()); dlg->setDirectory(TargetPage::targetDirectory());
dlg->selectFile(fileName); dlg->selectFile(fileName);
dlg->setOption(QFileDialog::DontConfirmOverwrite, true); dlg->setOption(QFileDialog::DontConfirmOverwrite, true);
if(!download->title().isEmpty()) { 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) void DownloadInteraction::downloadRequriesOverwritePermission(Download *download, size_t optionIndex, const QString &file)
{ {
if(GeneralTargetOptionPage::overwriteWithoutAsking()) { if(TargetPage::overwriteWithoutAsking()) {
download->setOverwritePermission(optionIndex, PermissionStatus::Allowed); download->setOverwritePermission(optionIndex, PermissionStatus::Allowed);
} else { } 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); 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) { connect(dlg, &QMessageBox::finished, [download, optionIndex, dlg, overwriteButton, overwriteAlwaysButton, selectOtherButton, abortButton, this] (int) {
if(dlg->clickedButton() == overwriteAlwaysButton) { if(dlg->clickedButton() == overwriteAlwaysButton) {
// set dontAskBeforeOverwriting to true if the user clicked yes to all // set dontAskBeforeOverwriting to true if the user clicked yes to all
GeneralTargetOptionPage::overwriteWithoutAsking() = true; TargetPage::overwriteWithoutAsking() = true;
} }
if(dlg->clickedButton() == overwriteButton || dlg->clickedButton() == overwriteAlwaysButton) { if(dlg->clickedButton() == overwriteButton || dlg->clickedButton() == overwriteAlwaysButton) {
download->setOverwritePermission(optionIndex, PermissionStatus::Allowed); 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) 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); download->setAppendPermission(optionIndex, PermissionStatus::Allowed);
} else { } 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); 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) void DownloadInteraction::downloadRequiresRedirectionPermission(Download *download, size_t optionIndex)
{ {
if(NetworkMiscOptionPage::redirectWithoutAsking()) { if(MiscPage::redirectWithoutAsking()) {
download->setRedirectPermission(optionIndex, PermissionStatus::Allowed); download->setRedirectPermission(optionIndex, PermissionStatus::Allowed);
} else { } else {
const QUrl &originalUrl = download->downloadUrl(download->options().at(optionIndex).redirectionOf()); 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) { connect(dlg, &QMessageBox::finished, [download, optionIndex, dlg, this] (int result) {
switch(result) { switch(result) {
case QMessageBox::YesToAll: case QMessageBox::YesToAll:
NetworkMiscOptionPage::redirectWithoutAsking() = true; MiscPage::redirectWithoutAsking() = true;
download->setRedirectPermission(optionIndex, PermissionStatus::AlwaysAllowed); download->setRedirectPermission(optionIndex, PermissionStatus::AlwaysAllowed);
break; break;
case QMessageBox::Yes: case QMessageBox::Yes:

View File

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

View File

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

View File

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

View File

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

View File

@ -2,8 +2,16 @@
<ui version="4.0"> <ui version="4.0">
<class>QtGui::TargetPage</class> <class>QtGui::TargetPage</class>
<widget class="QWidget" name="QtGui::TargetPage"> <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"> <property name="windowTitle">
<string>Select target directory</string> <string>Target directory</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>

View File

@ -2,8 +2,16 @@
<ui version="4.0"> <ui version="4.0">
<class>QtGui::UserAgentPage</class> <class>QtGui::UserAgentPage</class>
<widget class="QWidget" name="QtGui::UserAgentPage"> <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"> <property name="windowTitle">
<string>Configure user agent</string> <string>HTTP user agent</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
@ -15,7 +23,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Use a random default user agent</string> <string>Use a ra&amp;ndom default user agent</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -30,7 +38,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Custom user agent</string> <string>&amp;Custom user agent</string>
</property> </property>
</widget> </widget>
</item> </item>