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_targetpage.h"
# include "ui_proxypage.h"
# 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>
# include <QDir>
# include <QFileInfo>
# include <QVBoxLayout>
# include <QHBoxLayout>
# include <QFormLayout>
# include <QLabel>
# include <QCheckBox>
# include <QMessageBox>
# include <QFileDialog>
# include <QGraphicsPixmapItem>
# include <QApplication>
# include <QSettings>
# include <QNetworkProxy>
# include <functional>
using namespace ConversionUtilities ;
using namespace Dialogs ;
using namespace Widgets ;
using namespace Network ;
namespace QtGui {
2016-04-04 14:51:51 +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 ( )
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
{
if ( hasBeenShown ( ) ) {
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
{
if ( hasBeenShown ( ) ) {
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
dlg - > setFileMode ( QFileDialog : : DirectoryOnly ) ;
dlg - > setWindowTitle ( QApplication : : translate ( " QtGui::GeneralTargetOptionPage " , " Select download target directory " ) ) ;
dlg - > setDirectory ( ui ( ) - > defaultTargetLineEdit - > text ( ) ) ;
QObject : : connect ( dlg , & QFileDialog : : accepted , [ this , dlg ] {
if ( dlg - > selectedFiles ( ) . size ( ) = = 1 ) {
ui ( ) - > defaultTargetLineEdit - > setText ( dlg - > selectedFiles ( ) . at ( 0 ) ) ;
}
} ) ;
dlg - > show ( ) ;
}
2016-04-04 14:51:51 +02:00
UiPage : : UiPage ( QWidget * parentWidget ) :
OptionPage ( parentWidget ) ,
2015-04-22 19:32:04 +02:00
m_multiSelectionCheckBox ( nullptr )
{ }
2016-04-04 14:51:51 +02:00
UiPage : : ~ UiPage ( )
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
{
if ( hasBeenShown ( ) ) {
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
{
if ( hasBeenShown ( ) ) {
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 ) ;
layout - > addWidget ( m_multiSelectionCheckBox = new QCheckBox ( QApplication : : translate ( " QtGui::GeneralUiOptionPage " , " enable multi-selection " ) , widget ) ) ;
widget - > setLayout ( layout ) ;
return widget ;
}
2016-04-04 14:51:51 +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 ( )
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
{
if ( hasBeenShown ( ) ) {
// set entered values to proxy
if ( ui ( ) - > enableCheckBox - > isChecked ( ) ) {
switch ( ui ( ) - > typeComboBox - > currentIndex ( ) ) {
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
{
if ( hasBeenShown ( ) ) {
switch ( proxy ( ) . type ( ) ) {
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 ;
default :
;
}
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
{
QStringList parts = ui ( ) - > hostNameLineEdit - > text ( ) . split ( " : " , QString : : SkipEmptyParts ) ;
if ( parts . count ( ) = = 2 ) {
bool ok ;
int port = parts . at ( 1 ) . toInt ( & ok ) ;
if ( ok ) {
ui ( ) - > hostNameLineEdit - > setText ( parts . at ( 0 ) ) ;
ui ( ) - > portSpinBox - > setValue ( port ) ;
}
}
}
2016-04-04 14:51:51 +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 ( )
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
{
if ( hasBeenShown ( ) ) {
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
{
if ( hasBeenShown ( ) ) {
if ( useCustomUserAgent ( ) ) {
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 ;
}
2016-04-04 14:51:51 +02:00
MiscPage : : MiscPage ( QWidget * parentWidget ) :
OptionPage ( parentWidget ) ,
2015-04-22 19:32:04 +02:00
m_redirectCheckBox ( nullptr )
{ }
2016-04-04 14:51:51 +02:00
MiscPage : : ~ MiscPage ( )
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
{
if ( hasBeenShown ( ) ) {
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
{
if ( hasBeenShown ( ) ) {
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 ) ;
layout - > addWidget ( m_redirectCheckBox = new QCheckBox ( QApplication : : translate ( " QtGui::NetworkMiscOptionPage " , " follow redirections without asking " ) , widget ) ) ;
widget - > setLayout ( layout ) ;
return widget ;
}
2016-04-04 14:51:51 +02:00
StatsPage : : StatsPage ( QWidget * parentWidget ) :
OptionPage ( parentWidget ) ,
2015-04-22 19:32:04 +02:00
m_receivedLabel ( nullptr )
{ }
2016-04-04 14:51:51 +02:00
StatsPage : : ~ StatsPage ( )
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
{
if ( hasBeenShown ( ) ) {
2015-09-12 17:59:43 +02:00
m_receivedLabel - > setText ( QString : : fromStdString ( ConversionUtilities : : 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 ;
}
SettingsDialog : : SettingsDialog ( QWidget * parent ) :
Dialogs : : SettingsDialog ( parent )
{
// setup categories
QList < Dialogs : : OptionCategory * > categories ;
Dialogs : : OptionCategory * category ;
category = new Dialogs : : OptionCategory ( this ) ;
category - > setDisplayName ( tr ( " General " ) ) ;
2016-04-04 14:51:51 +02:00
category - > assignPages ( QList < Dialogs : : OptionPage * > ( ) < < new TargetPage ( this ) < < new UiPage ( ) ) ;
2015-12-02 00:43:01 +01:00
category - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " preferences-other " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/32x32/categories/preferences-general.png " ) ) ) ) ;
2015-04-22 19:32:04 +02:00
categories < < category ;
category = new Dialogs : : OptionCategory ( this ) ;
category - > setDisplayName ( tr ( " Network " ) ) ;
2015-12-02 00:43:01 +01:00
category - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " preferences-system-network " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/32x32/categories/preferences-network.png " ) ) ) ) ;
2016-04-04 14:51:51 +02:00
category - > assignPages ( QList < Dialogs : : OptionPage * > ( ) < < new ProxyPage ( ) < < new UserAgentPage ( ) < < new MiscPage ( ) < < new StatsPage ( ) ) ;
2015-04-22 19:32:04 +02:00
categories < < category ;
category = new Dialogs : : OptionCategory ( this ) ;
category - > setDisplayName ( tr ( " Specific " ) ) ;
category - > setIcon ( QIcon ( QStringLiteral ( " :/icons/hicolor/32x32/categories/preferences-specific.png " ) ) ) ;
category - > assignPages ( QList < Dialogs : : OptionPage * > ( ) ) ;
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 ) ;
setWindowIcon ( QIcon : : fromTheme ( QStringLiteral ( " preferences-other " ) , QIcon ( QStringLiteral ( " :/icons/hicolor/32x32/categories/preferences-general.png " ) ) ) ) ;
}
SettingsDialog : : ~ SettingsDialog ( )
{ }
2016-08-14 22:52:15 +02:00
Dialogs : : QtSettings & qtSettings ( )
{
static Dialogs : : QtSettings v ;
return v ;
}
2015-04-22 19:32:04 +02:00
void restoreSettings ( )
{
QSettings settings ( QSettings : : IniFormat , QSettings : : UserScope , QApplication : : organizationName ( ) , QApplication : : applicationName ( ) ) ;
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
2015-09-16 17:32:33 +02:00
const auto errorMsg = QApplication : : translate ( " QtGui::Settings " , " Unable to read Grooveshark authentication information file. \n \n Reason: %1 \n \n The values stored in this file are required when connection to Grooveshark. Built-in will values be used instead, but these might be deprecated. " ) ;
2015-12-05 22:56:32 +01:00
const auto groovesharkAuthenticationFile = ConfigFile : : locateConfigFile ( QStringLiteral ( PROJECT_NAME ) , QStringLiteral ( " json/groovesharkauthenticationinfo.json " ) , & settings ) ;
2015-04-22 19:32:04 +02:00
QString reason ;
2015-09-16 17:32:33 +02:00
if ( ! groovesharkAuthenticationFile . isEmpty ( ) ) {
2015-04-22 19:32:04 +02:00
if ( ! GroovesharkDownload : : loadAuthenticationInformationFromFile ( groovesharkAuthenticationFile , & reason ) ) {
2015-09-16 17:32:33 +02:00
QMessageBox : : warning ( nullptr , QApplication : : applicationName ( ) , errorMsg . arg ( reason ) ) ;
2015-04-22 19:32:04 +02:00
}
} else {
2015-09-16 17:32:33 +02:00
QMessageBox : : warning ( nullptr , QApplication : : applicationName ( ) , errorMsg . arg ( QApplication : : translate ( " QtGui::Settings " , " Unable to find \" groovesharkauthenticationinfo.json \" . " ) ) ) ;
2015-04-22 19:32:04 +02:00
}
}
void saveSettings ( )
{
QSettings settings ( QSettings : : IniFormat , QSettings : : UserScope , QApplication : : organizationName ( ) , QApplication : : applicationName ( ) ) ;
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
}
}
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 )