2015-09-08 17:05:59 +02:00
|
|
|
#include "./settings.h"
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2015-09-08 17:05:59 +02:00
|
|
|
#include "../network/download.h"
|
|
|
|
#include "../network/groovesharkdownload.h"
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-25 22:07:31 +02:00
|
|
|
#include "resources/config.h"
|
2015-12-05 22:56:32 +01:00
|
|
|
|
2016-09-12 21:53:18 +02:00
|
|
|
#include "ui_proxypage.h"
|
2017-05-01 03:22:50 +02:00
|
|
|
#include "ui_targetpage.h"
|
2016-09-12 21:53:18 +02:00
|
|
|
#include "ui_useragentpage.h"
|
|
|
|
|
2015-09-16 17:32:33 +02:00
|
|
|
#include <qtutilities/resources/resources.h>
|
2015-04-22 19:32:04 +02:00
|
|
|
#include <qtutilities/settingsdialog/optioncategory.h>
|
|
|
|
#include <qtutilities/settingsdialog/optioncategorymodel.h>
|
2016-08-14 22:52:15 +02:00
|
|
|
#include <qtutilities/settingsdialog/qtsettings.h>
|
2015-04-22 19:32:04 +02:00
|
|
|
#include <qtutilities/widgets/clearlineedit.h>
|
|
|
|
|
|
|
|
#include <c++utilities/conversion/stringconversion.h>
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QCheckBox>
|
2015-04-22 19:32:04 +02:00
|
|
|
#include <QDir>
|
2017-05-01 03:22:50 +02:00
|
|
|
#include <QFileDialog>
|
2015-04-22 19:32:04 +02:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QFormLayout>
|
2017-05-01 03:22:50 +02:00
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <QHBoxLayout>
|
2015-04-22 19:32:04 +02:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QNetworkProxy>
|
2017-05-01 03:22:50 +02:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QVBoxLayout>
|
2015-04-22 19:32:04 +02:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
2019-06-10 22:50:15 +02:00
|
|
|
using namespace CppUtilities;
|
|
|
|
using namespace QtUtilities;
|
2015-04-22 19:32:04 +02:00
|
|
|
using namespace Network;
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
TargetPage::TargetPage(QWidget *parentWindow)
|
|
|
|
: TargetPageBase(parentWindow)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
TargetPage::~TargetPage()
|
2017-05-01 03:22:50 +02:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool TargetPage::apply()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
targetDirectory() = ui()->defaultTargetLineEdit->text();
|
|
|
|
overwriteWithoutAsking() = ui()->overwriteCheckBox->isChecked();
|
|
|
|
determineTargetFileWithoutAsking() = ui()->askOnlyWhenThereIsNoAppropriateFilenameCheckBox->isChecked();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
void TargetPage::reset()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
ui()->defaultTargetLineEdit->setText(targetDirectory());
|
|
|
|
ui()->overwriteCheckBox->setChecked(overwriteWithoutAsking());
|
|
|
|
ui()->askOnlyWhenThereIsNoAppropriateFilenameCheckBox->setChecked(determineTargetFileWithoutAsking());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QString &TargetPage::targetDirectory()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static QString dir;
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool &TargetPage::overwriteWithoutAsking()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static bool val = false;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool &TargetPage::determineTargetFileWithoutAsking()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static bool val = true;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QWidget *TargetPage::setupWidget()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2016-04-04 14:51:51 +02:00
|
|
|
QWidget *widget = TargetPageBase::setupWidget();
|
2015-04-22 19:32:04 +02:00
|
|
|
// draw icon to info icon graphics view
|
|
|
|
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, widget);
|
|
|
|
QGraphicsScene *scene = new QGraphicsScene();
|
|
|
|
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(icon.pixmap(32, 32));
|
|
|
|
scene->addItem(item);
|
|
|
|
ui()->infoIconGraphicsView->setScene(scene);
|
|
|
|
// connect signals and slots
|
2016-04-04 14:51:51 +02:00
|
|
|
QObject::connect(ui()->selectDefaultDirPushButton, &QPushButton::clicked, std::bind(&TargetPage::selectTargetDirectory, this));
|
2015-04-22 19:32:04 +02:00
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
void TargetPage::selectTargetDirectory()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
QFileDialog *dlg = new QFileDialog(parentWindow());
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// the native dialog can only be shown modal under Windows
|
|
|
|
dlg->setModal(true);
|
|
|
|
#else
|
|
|
|
dlg->setModal(false);
|
|
|
|
#endif
|
2019-07-07 12:03:38 +02:00
|
|
|
dlg->setOption(QFileDialog::ShowDirsOnly, true);
|
2015-04-22 19:32:04 +02:00
|
|
|
dlg->setWindowTitle(QApplication::translate("QtGui::GeneralTargetOptionPage", "Select download target directory"));
|
|
|
|
dlg->setDirectory(ui()->defaultTargetLineEdit->text());
|
|
|
|
QObject::connect(dlg, &QFileDialog::accepted, [this, dlg] {
|
2017-05-01 03:22:50 +02:00
|
|
|
if (dlg->selectedFiles().size() == 1) {
|
2015-04-22 19:32:04 +02:00
|
|
|
ui()->defaultTargetLineEdit->setText(dlg->selectedFiles().at(0));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dlg->show();
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
UiPage::UiPage(QWidget *parentWidget)
|
|
|
|
: OptionPage(parentWidget)
|
|
|
|
, m_multiSelectionCheckBox(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
UiPage::~UiPage()
|
2017-05-01 03:22:50 +02:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool UiPage::apply()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
multiSelection() = m_multiSelectionCheckBox->isChecked();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
void UiPage::reset()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
m_multiSelectionCheckBox->setChecked(multiSelection());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QByteArray &UiPage::mainWindowGeometry()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static QByteArray geometry;
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QByteArray &UiPage::mainWindowState()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static QByteArray state;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool &UiPage::multiSelection()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static bool val = false;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QWidget *UiPage::setupWidget()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
QWidget *widget = new QWidget();
|
2016-04-04 14:51:51 +02:00
|
|
|
widget->setWindowTitle(QApplication::translate("QtGui::GeneralUiOptionPage", "User interface"));
|
2015-04-22 19:32:04 +02:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(widget);
|
|
|
|
QLabel *mainWindowLabel = new QLabel(QApplication::translate("QtGui::GeneralUiOptionPage", "Main window"));
|
|
|
|
mainWindowLabel->setStyleSheet(QStringLiteral("font-weight: bold;"));
|
|
|
|
layout->addWidget(mainWindowLabel);
|
2017-05-01 03:22:50 +02:00
|
|
|
layout->addWidget(
|
2019-12-30 21:58:54 +01:00
|
|
|
m_multiSelectionCheckBox = new QCheckBox(QApplication::translate("QtGui::GeneralUiOptionPage", "Enable multi-selection"), widget));
|
2015-04-22 19:32:04 +02:00
|
|
|
widget->setLayout(layout);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
ProxyPage::ProxyPage(QWidget *parentWidget)
|
|
|
|
: ProxyPageBase(parentWidget)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
ProxyPage::~ProxyPage()
|
2017-05-01 03:22:50 +02:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool ProxyPage::apply()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
// set entered values to proxy
|
2017-05-01 03:22:50 +02:00
|
|
|
if (ui()->enableCheckBox->isChecked()) {
|
|
|
|
switch (ui()->typeComboBox->currentIndex()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
case 0:
|
|
|
|
proxy().setType(QNetworkProxy::HttpProxy);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
proxy().setType(QNetworkProxy::Socks5Proxy);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
proxy().setType(QNetworkProxy::NoProxy);
|
|
|
|
}
|
|
|
|
proxy().setHostName(ui()->hostNameLineEdit->text());
|
|
|
|
proxy().setPort(ui()->portSpinBox->value());
|
|
|
|
proxy().setUser(ui()->userNameLineEdit->text());
|
|
|
|
proxy().setPassword(ui()->passwordLineEdit->text());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
void ProxyPage::reset()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
|
|
|
switch (proxy().type()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
case QNetworkProxy::HttpProxy:
|
|
|
|
ui()->typeComboBox->setCurrentIndex(1);
|
|
|
|
ui()->enableCheckBox->setChecked(true);
|
|
|
|
ui()->widget->setEnabled(true);
|
|
|
|
break;
|
|
|
|
case QNetworkProxy::Socks5Proxy:
|
|
|
|
ui()->typeComboBox->setCurrentIndex(2);
|
|
|
|
ui()->enableCheckBox->setChecked(true);
|
|
|
|
ui()->widget->setEnabled(true);
|
|
|
|
break;
|
|
|
|
case QNetworkProxy::NoProxy:
|
|
|
|
ui()->typeComboBox->setCurrentIndex(0);
|
|
|
|
ui()->enableCheckBox->setChecked(false);
|
|
|
|
ui()->widget->setEnabled(false);
|
|
|
|
break;
|
2017-05-01 03:22:50 +02:00
|
|
|
default:;
|
2015-04-22 19:32:04 +02:00
|
|
|
}
|
|
|
|
ui()->hostNameLineEdit->setText(proxy().hostName());
|
|
|
|
ui()->portSpinBox->setValue(proxy().port());
|
|
|
|
ui()->userNameLineEdit->setText(proxy().user());
|
|
|
|
ui()->passwordLineEdit->setText(proxy().password());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QNetworkProxy &ProxyPage::proxy()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static QNetworkProxy proxy;
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QWidget *ProxyPage::setupWidget()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2016-04-04 14:51:51 +02:00
|
|
|
QWidget *widget = ProxyPageBase::setupWidget();
|
|
|
|
widget->setWindowTitle(QApplication::translate("QtGui::NetworkProxyOptionPage", "Proxy server"));
|
2015-04-22 19:32:04 +02:00
|
|
|
ui()->widget->setEnabled(false);
|
|
|
|
// connect signals and slots
|
|
|
|
QObject::connect(ui()->enableCheckBox, &QCheckBox::clicked, ui()->widget, &QWidget::setEnabled);
|
2016-04-04 14:51:51 +02:00
|
|
|
QObject::connect(ui()->hostNameLineEdit, &QLineEdit::editingFinished, std::bind(&ProxyPage::updateProxy, this));
|
2015-04-22 19:32:04 +02:00
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
void ProxyPage::updateProxy()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2020-09-04 00:57:42 +02:00
|
|
|
QStringList parts = ui()->hostNameLineEdit->text().split(":", Qt::SkipEmptyParts);
|
2017-05-01 03:22:50 +02:00
|
|
|
if (parts.count() == 2) {
|
2015-04-22 19:32:04 +02:00
|
|
|
bool ok;
|
|
|
|
int port = parts.at(1).toInt(&ok);
|
2017-05-01 03:22:50 +02:00
|
|
|
if (ok) {
|
2015-04-22 19:32:04 +02:00
|
|
|
ui()->hostNameLineEdit->setText(parts.at(0));
|
|
|
|
ui()->portSpinBox->setValue(port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
UserAgentPage::UserAgentPage(QWidget *parentWidget)
|
|
|
|
: UserAgentPageBase(parentWidget)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
UserAgentPage::~UserAgentPage()
|
2017-05-01 03:22:50 +02:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool UserAgentPage::apply()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
useCustomUserAgent() = ui()->customRadioButton->isChecked();
|
|
|
|
customUserAgent() = ui()->customLineEdit->text();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
void UserAgentPage::reset()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
|
|
|
if (useCustomUserAgent()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
ui()->customRadioButton->setChecked(true);
|
|
|
|
} else {
|
|
|
|
ui()->defaultRadioButton->setChecked(true);
|
|
|
|
}
|
|
|
|
ui()->customLineEdit->setText(customUserAgent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool &UserAgentPage::useCustomUserAgent()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static bool useCustomUserAgent = false;
|
|
|
|
return useCustomUserAgent;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QString &UserAgentPage::customUserAgent()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static QString userAgent;
|
|
|
|
return userAgent;
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
MiscPage::MiscPage(QWidget *parentWidget)
|
|
|
|
: OptionPage(parentWidget)
|
|
|
|
, m_redirectCheckBox(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
MiscPage::~MiscPage()
|
2017-05-01 03:22:50 +02:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool MiscPage::apply()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
redirectWithoutAsking() = m_redirectCheckBox->isChecked();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
void MiscPage::reset()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2015-04-22 19:32:04 +02:00
|
|
|
m_redirectCheckBox->setChecked(redirectWithoutAsking());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool &MiscPage::redirectWithoutAsking()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static bool val = false;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QWidget *MiscPage::setupWidget()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
QWidget *widget = new QWidget();
|
2016-04-04 14:51:51 +02:00
|
|
|
widget->setWindowTitle(QApplication::translate("QtGui::NetworkMiscOptionPage", "Misc"));
|
2015-04-22 19:32:04 +02:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(widget);
|
2017-05-01 03:22:50 +02:00
|
|
|
layout->addWidget(
|
2019-12-30 21:58:54 +01:00
|
|
|
m_redirectCheckBox = new QCheckBox(QApplication::translate("QtGui::NetworkMiscOptionPage", "Follow redirections without asking"), widget));
|
2015-04-22 19:32:04 +02:00
|
|
|
widget->setLayout(layout);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
StatsPage::StatsPage(QWidget *parentWidget)
|
|
|
|
: OptionPage(parentWidget)
|
|
|
|
, m_receivedLabel(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
StatsPage::~StatsPage()
|
2017-05-01 03:22:50 +02:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
bool StatsPage::apply()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
void StatsPage::reset()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
2017-05-01 03:22:50 +02:00
|
|
|
if (hasBeenShown()) {
|
2019-06-10 22:50:15 +02:00
|
|
|
m_receivedLabel->setText(QString::fromStdString(dataSizeToString(bytesReceived(), true)));
|
2015-04-22 19:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
quint64 &StatsPage::bytesReceived()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
static quint64 received;
|
|
|
|
return received;
|
|
|
|
}
|
|
|
|
|
2016-04-04 14:51:51 +02:00
|
|
|
QWidget *StatsPage::setupWidget()
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
QWidget *widget = new QWidget();
|
2016-04-04 14:51:51 +02:00
|
|
|
widget->setWindowTitle(QApplication::translate("QtGui::NetworkStatsOptionPage", "Statistics"));
|
2015-04-22 19:32:04 +02:00
|
|
|
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);
|
2016-04-04 14:51:51 +02:00
|
|
|
QObject::connect(refreshButton, &QPushButton::clicked, std::bind(&StatsPage::reset, this));
|
2015-04-22 19:32:04 +02:00
|
|
|
mainLayout->addLayout(formLayout);
|
|
|
|
mainLayout->addWidget(refreshButton);
|
|
|
|
widget->setLayout(mainLayout);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:22:50 +02:00
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent)
|
2019-06-10 22:50:15 +02:00
|
|
|
: QtUtilities::SettingsDialog(parent)
|
2015-04-22 19:32:04 +02:00
|
|
|
{
|
|
|
|
// setup categories
|
2019-06-10 22:50:15 +02:00
|
|
|
QList<OptionCategory *> categories;
|
|
|
|
OptionCategory *category;
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2019-06-10 22:50:15 +02:00
|
|
|
category = new OptionCategory(this);
|
2015-04-22 19:32:04 +02:00
|
|
|
category->setDisplayName(tr("General"));
|
2019-08-10 22:05:18 +02:00
|
|
|
category->assignPages({ new TargetPage(this), new UiPage() });
|
2017-05-01 03:22:50 +02:00
|
|
|
category->setIcon(
|
2022-09-10 16:37:52 +02:00
|
|
|
QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/32x32/categories/preferences-other.svg"))));
|
2015-04-22 19:32:04 +02:00
|
|
|
categories << category;
|
|
|
|
|
2019-06-10 22:50:15 +02:00
|
|
|
category = new OptionCategory(this);
|
2015-04-22 19:32:04 +02:00
|
|
|
category->setDisplayName(tr("Network"));
|
2017-05-01 03:22:50 +02:00
|
|
|
category->setIcon(QIcon::fromTheme(
|
2022-09-10 16:37:52 +02:00
|
|
|
QStringLiteral("preferences-system-network"), QIcon(QStringLiteral(":/icons/hicolor/32x32/categories/applications-internet.svg"))));
|
2019-08-10 22:05:18 +02:00
|
|
|
category->assignPages({ new ProxyPage(), new UserAgentPage(), new MiscPage(), new StatsPage() });
|
2015-04-22 19:32:04 +02:00
|
|
|
categories << category;
|
|
|
|
|
2016-08-14 22:52:15 +02:00
|
|
|
categories << qtSettings().category();
|
|
|
|
|
2015-04-22 19:32:04 +02:00
|
|
|
categoryModel()->setCategories(categories);
|
|
|
|
|
|
|
|
setMinimumSize(800, 450);
|
2017-05-01 03:22:50 +02:00
|
|
|
setWindowIcon(
|
2022-09-10 16:37:52 +02:00
|
|
|
QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/32x32/categories/preferences-other.svg"))));
|
2015-04-22 19:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
2017-05-01 03:22:50 +02:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:32:04 +02:00
|
|
|
|
2019-06-10 22:50:15 +02:00
|
|
|
QtSettings &qtSettings()
|
2016-08-14 22:52:15 +02:00
|
|
|
{
|
2019-06-10 22:50:15 +02:00
|
|
|
static QtSettings v;
|
2016-08-14 22:52:15 +02:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:32:04 +02:00
|
|
|
void restoreSettings()
|
|
|
|
{
|
2017-02-20 19:58:41 +01:00
|
|
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(PROJECT_NAME));
|
|
|
|
// move old config to new location
|
2017-05-01 03:22:50 +02:00
|
|
|
const QString oldConfig
|
|
|
|
= QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName()).fileName();
|
2017-02-20 19:58:41 +01:00
|
|
|
QFile::rename(oldConfig, settings.fileName()) || QFile::remove(oldConfig);
|
|
|
|
settings.sync();
|
2015-04-22 19:32:04 +02:00
|
|
|
|
|
|
|
settings.beginGroup("application");
|
2016-04-04 14:51:51 +02:00
|
|
|
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();
|
2015-04-22 19:32:04 +02:00
|
|
|
|
|
|
|
settings.beginGroup("proxy");
|
|
|
|
bool validProxyType;
|
|
|
|
int proxyType = settings.value("type", QVariant(QNetworkProxy::NoProxy)).toInt(&validProxyType);
|
|
|
|
validProxyType = proxyType >= 0 && proxyType <= 5;
|
2016-04-04 14:51:51 +02:00
|
|
|
QNetworkProxy &proxy = ProxyPage::proxy();
|
2015-04-22 19:32:04 +02:00
|
|
|
proxy.setType(validProxyType ? static_cast<QNetworkProxy::ProxyType>(proxyType) : QNetworkProxy::NoProxy);
|
|
|
|
proxy.setHostName(settings.value("hostname").toString());
|
|
|
|
proxy.setPort(settings.value("port", QVariant(0)).toUInt());
|
|
|
|
proxy.setUser(settings.value("user").toString());
|
|
|
|
proxy.setPassword(settings.value("password").toString());
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup("statistics");
|
2016-04-04 14:51:51 +02:00
|
|
|
StatsPage::bytesReceived() = settings.value("totalbytesreceived", 0).toLongLong();
|
2015-04-22 19:32:04 +02:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup("mainwindow");
|
2016-04-04 14:51:51 +02:00
|
|
|
UiPage::mainWindowGeometry() = settings.value("geometry").toByteArray();
|
|
|
|
UiPage::mainWindowState() = settings.value("state").toByteArray();
|
|
|
|
UiPage::multiSelection() = settings.value("multiselection").toBool();
|
2015-04-22 19:32:04 +02:00
|
|
|
|
|
|
|
// load grooveshark authentication file
|
|
|
|
QString reason;
|
2019-08-20 22:27:15 +02:00
|
|
|
if (!GroovesharkDownload::loadAuthenticationInformationFromFile(QStringLiteral(":/jsonobjects/groovesharkauthenticationinfo"), &reason)) {
|
2017-05-01 03:22:50 +02:00
|
|
|
QMessageBox::warning(nullptr, QApplication::applicationName(),
|
2019-08-20 22:27:15 +02:00
|
|
|
QCoreApplication::translate("QtGui::restoreSettings", "Unable to load Grooveshark authentication file: %1").arg(reason));
|
2015-04-22 19:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveSettings()
|
|
|
|
{
|
2017-02-20 19:58:41 +01:00
|
|
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(PROJECT_NAME));
|
2015-04-22 19:32:04 +02:00
|
|
|
|
|
|
|
settings.beginGroup("application");
|
2016-04-04 14:51:51 +02:00
|
|
|
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());
|
2015-04-22 19:32:04 +02:00
|
|
|
|
|
|
|
settings.beginGroup("proxy");
|
2016-04-04 14:51:51 +02:00
|
|
|
const QNetworkProxy &proxy = ProxyPage::proxy();
|
2015-04-22 19:32:04 +02:00
|
|
|
settings.setValue("type", proxy.type());
|
|
|
|
settings.setValue("hostname", proxy.hostName());
|
|
|
|
settings.setValue("port", proxy.port());
|
|
|
|
settings.setValue("user", proxy.user());
|
|
|
|
settings.setValue("password", proxy.password());
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup("statistics");
|
2016-04-04 14:51:51 +02:00
|
|
|
settings.setValue("totalbytesreceived", StatsPage::bytesReceived());
|
2015-04-22 19:32:04 +02:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.beginGroup("mainwindow");
|
2016-04-04 14:51:51 +02:00
|
|
|
settings.setValue("geometry", UiPage::mainWindowGeometry());
|
|
|
|
settings.setValue("state", UiPage::mainWindowState());
|
|
|
|
settings.setValue("multiselection", UiPage::multiSelection());
|
2015-04-22 19:32:04 +02:00
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void applySettingsToDownload(Download *download)
|
|
|
|
{
|
2016-04-04 14:51:51 +02:00
|
|
|
download->setDefaultUserAgentUsed(!UserAgentPage::useCustomUserAgent());
|
|
|
|
download->setCustomUserAgent(UserAgentPage::useCustomUserAgent() ? UserAgentPage::customUserAgent() : QString());
|
|
|
|
download->setProxy(ProxyPage::proxy());
|
2015-04-22 19:32:04 +02:00
|
|
|
}
|
2019-07-20 20:20:58 +02:00
|
|
|
} // namespace QtGui
|
2016-09-12 21:53:18 +02:00
|
|
|
|
|
|
|
INSTANTIATE_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, TargetPage)
|
|
|
|
INSTANTIATE_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, ProxyPage)
|
|
|
|
INSTANTIATE_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, UserAgentPage)
|