/src/settingsdialog.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 553 lines · 408 code · 103 blank · 42 comment · 30 complexity · e00dee76b378b40b27eb9e485c7463d7 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  5. * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  6. * Copyright 2012, Teo Mrnjavac <teo@kde.org>
  7. *
  8. * Tomahawk is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Tomahawk is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "SettingsDialog.h"
  22. #include "ui_ProxyDialog.h"
  23. #include "ui_Settings_Accounts.h"
  24. #include "ui_Settings_Collection.h"
  25. #include "ui_Settings_Advanced.h"
  26. #include "config.h"
  27. #include "AtticaManager.h"
  28. #include "AclRegistry.h"
  29. #include "TomahawkApp.h"
  30. #include "TomahawkSettings.h"
  31. #include "accounts/DelegateConfigWrapper.h"
  32. #include "Pipeline.h"
  33. #include "Resolver.h"
  34. #include "ExternalResolverGui.h"
  35. #include "utils/TomahawkUtilsGui.h"
  36. #include "utils/GuiHelpers.h"
  37. #include "accounts/AccountDelegate.h"
  38. #include "database/Database.h"
  39. #include "network/Servent.h"
  40. #include "utils/AnimatedSpinner.h"
  41. #include "accounts/AccountModel.h"
  42. #include "accounts/Account.h"
  43. #include "accounts/AccountManager.h"
  44. #include "accounts/AccountModelFilterProxy.h"
  45. #include "accounts/ResolverAccount.h"
  46. #include "utils/Logger.h"
  47. #include "accounts/AccountFactoryWrapper.h"
  48. #include "accounts/spotify/SpotifyAccount.h"
  49. #include "thirdparty/Qocoa/qtoolbartabdialog.h"
  50. #include "thirdparty/Qocoa/qbutton.h"
  51. #include <QDesktopServices>
  52. #include <QFileDialog>
  53. #include <QMessageBox>
  54. #include <QNetworkConfiguration>
  55. #include <QNetworkProxy>
  56. #include <QVBoxLayout>
  57. #include <QSizeGrip>
  58. #include <QToolBar>
  59. using namespace Tomahawk;
  60. using namespace Accounts;
  61. SettingsDialog::SettingsDialog(QObject *parent )
  62. : QObject( parent )
  63. , m_accountsWidgetUi( new Ui_Settings_Accounts )
  64. , m_accountsWidget( new QWidget )
  65. , m_collectionWidgetUi( new Ui_Settings_Collection )
  66. , m_collectionWidget( new QWidget )
  67. , m_advancedWidgetUi( new Ui_Settings_Advanced )
  68. , m_advancedWidget( new QWidget )
  69. , m_proxySettings( 0 )
  70. , m_rejected( false )
  71. , m_restartRequired( false )
  72. , m_accountModel( 0 )
  73. , m_sipSpinner( 0 )
  74. {
  75. m_accountsWidgetUi->setupUi( m_accountsWidget );
  76. m_collectionWidgetUi->setupUi( m_collectionWidget );
  77. m_advancedWidgetUi->setupUi( m_advancedWidget );
  78. m_accountsWidgetUi->accountsFilterCombo->setFocusPolicy( Qt::NoFocus );
  79. m_dialog = new QToolbarTabDialog;
  80. TomahawkSettings* s = TomahawkSettings::instance();
  81. m_advancedWidgetUi->checkBoxReporter->setChecked( s->crashReporterEnabled() );
  82. m_advancedWidgetUi->checkBoxHttp->setChecked( s->httpEnabled() );
  83. //Network settings
  84. TomahawkSettings::ExternalAddressMode mode = TomahawkSettings::instance()->externalAddressMode();
  85. if ( mode == TomahawkSettings::Lan )
  86. m_advancedWidgetUi->lanOnlyRadioButton->setChecked( true );
  87. else if ( mode == TomahawkSettings::Static )
  88. m_advancedWidgetUi->staticIpRadioButton->setChecked( true );
  89. else
  90. m_advancedWidgetUi->upnpRadioButton->setChecked( true );
  91. m_advancedWidgetUi->staticHostNamePortLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  92. m_advancedWidgetUi->staticHostName->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  93. m_advancedWidgetUi->staticPort->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  94. m_advancedWidgetUi->staticHostNameLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  95. m_advancedWidgetUi->staticPortLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  96. bool useProxy = TomahawkSettings::instance()->proxyType() == QNetworkProxy::Socks5Proxy;
  97. m_advancedWidgetUi->enableProxyCheckBox->setChecked( useProxy );
  98. m_advancedWidgetUi->proxyButton->setEnabled( useProxy );
  99. m_advancedWidgetUi->aclEntryClearButton->setEnabled( TomahawkSettings::instance()->aclEntries().size() > 0 );
  100. connect( m_advancedWidgetUi->aclEntryClearButton, SIGNAL( clicked( bool ) ), this, SLOT( aclEntryClearButtonClicked() ) );
  101. #ifdef Q_WS_MAC
  102. // Avoid resize handles on sheets on osx
  103. m_proxySettings.setSizeGripEnabled( true );
  104. QSizeGrip* p = m_proxySettings.findChild< QSizeGrip* >();
  105. p->setFixedSize( 0, 0 );
  106. #endif
  107. m_accountsWidgetUi->installFromFileBtn->setText( tr( "Install from file" ) );
  108. // Accounts
  109. AccountDelegate* accountDelegate = new AccountDelegate( this );
  110. m_accountsWidgetUi->accountsView->setItemDelegate( accountDelegate );
  111. m_accountsWidgetUi->accountsView->setContextMenuPolicy( Qt::CustomContextMenu );
  112. m_accountsWidgetUi->accountsView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
  113. m_accountsWidgetUi->accountsView->setMouseTracking( true );
  114. connect( accountDelegate, SIGNAL( openConfig( Tomahawk::Accounts::Account* ) ), this, SLOT( openAccountConfig( Tomahawk::Accounts::Account* ) ) );
  115. connect( accountDelegate, SIGNAL( openConfig( Tomahawk::Accounts::AccountFactory* ) ), this, SLOT( openAccountFactoryConfig( Tomahawk::Accounts::AccountFactory* ) ) );
  116. connect( accountDelegate, SIGNAL( update( QModelIndex ) ), m_accountsWidgetUi->accountsView, SLOT( update( QModelIndex ) ) );
  117. m_accountModel = new AccountModel( this );
  118. m_accountProxy = new AccountModelFilterProxy( m_accountModel );
  119. m_accountProxy->setSourceModel( m_accountModel );
  120. connect( m_accountProxy, SIGNAL( startInstalling( QPersistentModelIndex ) ), accountDelegate, SLOT( startInstalling(QPersistentModelIndex) ) );
  121. connect( m_accountProxy, SIGNAL( doneInstalling( QPersistentModelIndex ) ), accountDelegate, SLOT( doneInstalling(QPersistentModelIndex) ) );
  122. connect( m_accountProxy, SIGNAL( errorInstalling( QPersistentModelIndex ) ), accountDelegate, SLOT( errorInstalling(QPersistentModelIndex) ) );
  123. connect( m_accountProxy, SIGNAL( scrollTo( QModelIndex ) ), this, SLOT( scrollTo( QModelIndex ) ) );
  124. m_accountsWidgetUi->accountsView->setModel( m_accountProxy );
  125. connect( m_accountsWidgetUi->installFromFileBtn, SIGNAL( clicked( bool ) ), this, SLOT( installFromFile() ) );
  126. connect( m_accountModel, SIGNAL( createAccount( Tomahawk::Accounts::AccountFactory* ) ), this, SLOT( createAccountFromFactory( Tomahawk::Accounts::AccountFactory* ) ) );
  127. m_accountsWidgetUi->accountsFilterCombo->addItem( tr( "All" ), Accounts::NoType );
  128. m_accountsWidgetUi->accountsFilterCombo->addItem( accountTypeToString( SipType ), SipType );
  129. m_accountsWidgetUi->accountsFilterCombo->addItem( accountTypeToString( ResolverType ), ResolverType );
  130. m_accountsWidgetUi->accountsFilterCombo->addItem( accountTypeToString( StatusPushType ), StatusPushType );
  131. connect( m_accountsWidgetUi->accountsFilterCombo, SIGNAL( activated( int ) ), this, SLOT( accountsFilterChanged( int ) ) );
  132. if ( !Servent::instance()->isReady() )
  133. {
  134. m_sipSpinner = new AnimatedSpinner( m_accountsWidgetUi->accountsView );
  135. m_sipSpinner->fadeIn();
  136. connect( Servent::instance(), SIGNAL( ready() ), this, SLOT( serventReady() ) );
  137. }
  138. // ADVANCED
  139. m_advancedWidgetUi->staticHostName->setText( s->externalHostname() );
  140. m_advancedWidgetUi->staticPort->setValue( s->externalPort() );
  141. m_advancedWidgetUi->proxyButton->setVisible( true );
  142. m_collectionWidgetUi->checkBoxWatchForChanges->setChecked( s->watchForChanges() );
  143. m_collectionWidgetUi->scannerTimeSpinBox->setValue( s->scannerTime() );
  144. m_collectionWidgetUi->enableEchonestCatalog->setChecked( s->enableEchonestCatalogs() );
  145. connect( m_collectionWidgetUi->checkBoxWatchForChanges, SIGNAL( clicked( bool ) ), SLOT( updateScanOptionsView() ) );
  146. if ( m_collectionWidgetUi->checkBoxWatchForChanges->isChecked() )
  147. {
  148. m_collectionWidgetUi->scanTimeLabel->show();
  149. m_collectionWidgetUi->scannerTimeSpinBox->show();
  150. }
  151. else
  152. {
  153. m_collectionWidgetUi->scanTimeLabel->hide();
  154. m_collectionWidgetUi->scannerTimeSpinBox->hide();
  155. }
  156. foreach ( const QString& dir, TomahawkSettings::instance()->scannerPaths() )
  157. {
  158. m_collectionWidgetUi->dirTree->checkPath( dir, Qt::Checked );
  159. }
  160. int buttonsWidth = qMax( m_advancedWidgetUi->proxyButton->sizeHint().width(),
  161. m_advancedWidgetUi->aclEntryClearButton->sizeHint().width() );
  162. m_advancedWidgetUi->proxyButton->setFixedWidth( buttonsWidth );
  163. m_advancedWidgetUi->aclEntryClearButton->setFixedWidth( buttonsWidth );
  164. #ifndef Q_OS_MAC
  165. m_advancedWidget->setMinimumSize( m_advancedWidget->sizeHint() );
  166. m_accountsWidget->setMinimumWidth( 500 );
  167. #else
  168. m_accountsWidget->setContentsMargins( 6, 6, 6, 6 );
  169. m_accountsWidgetUi->horizontalLayout->setContentsMargins( 0, 0, 0, 0 );
  170. m_accountsWidgetUi->installFromFileBtn->setContentsMargins( -4, 0, 0, 0 );
  171. m_accountsWidget->setMinimumSize( 550, 400 );
  172. m_accountsWidgetUi->accountsView->setAttribute( Qt::WA_MacShowFocusRect, false );
  173. m_collectionWidget->setContentsMargins( 6, 6, 6, 6 );
  174. m_collectionWidget->setMinimumHeight( m_collectionWidgetUi->verticalLayout->sizeHint().height() + 20 );
  175. m_collectionWidgetUi->dirTree->setAttribute( Qt::WA_MacShowFocusRect, false );
  176. m_advancedWidget->setContentsMargins( 6, 6, 6, 6 );
  177. m_advancedWidget->setMinimumHeight( m_advancedWidgetUi->verticalLayout->sizeHint().height() );
  178. #endif
  179. // NOW PLAYING
  180. // #ifdef Q_WS_MAC
  181. // ui->checkBoxEnableAdium->setChecked( s->nowPlayingEnabled() );
  182. // #else
  183. // ui->checkBoxEnableAdium->hide();
  184. // #endif
  185. m_dialog->addTab( m_accountsWidget, QPixmap( RESPATH "images/account-settings.png" ), tr( "Services" ), tr( "Configure the accounts and services used by Tomahawk "
  186. "to search and retrieve music, find your friends and "
  187. "update your status." ) );
  188. m_dialog->addTab( m_collectionWidget, QPixmap( RESPATH "images/music-settings.png" ), tr( "Collection" ), tr( "Manage how Tomahawk finds music on your computer." ));
  189. m_dialog->addTab( m_advancedWidget, QPixmap( RESPATH "images/advanced-settings.png" ), tr( "Advanced" ), tr( "Configure Tomahawk's advanced settings, including "
  190. "network connectivity settings, browser interaction "
  191. "and more." ) );
  192. m_dialog->setCurrentIndex( 0 );
  193. connect( m_advancedWidgetUi->proxyButton, SIGNAL( clicked() ), SLOT( showProxySettings() ) );
  194. connect( m_advancedWidgetUi->lanOnlyRadioButton, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
  195. connect( m_advancedWidgetUi->staticIpRadioButton, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
  196. connect( m_advancedWidgetUi->upnpRadioButton, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
  197. connect( m_advancedWidgetUi->lanOnlyRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
  198. connect( m_advancedWidgetUi->staticIpRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
  199. connect( m_advancedWidgetUi->upnpRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
  200. connect( m_advancedWidgetUi->enableProxyCheckBox, SIGNAL( toggled(bool) ), SLOT( toggleProxyEnabled() ) );
  201. connect( m_dialog, SIGNAL( accepted() ), SLOT( saveSettings() ) );
  202. connect( m_dialog, SIGNAL( rejected() ), SLOT( onRejected() ) );
  203. }
  204. void
  205. SettingsDialog::saveSettings()
  206. {
  207. qDebug() << Q_FUNC_INFO;
  208. TomahawkSettings* s = TomahawkSettings::instance();
  209. s->setCrashReporterEnabled( m_advancedWidgetUi->checkBoxReporter->checkState() == Qt::Checked );
  210. s->setHttpEnabled( m_advancedWidgetUi->checkBoxHttp->checkState() == Qt::Checked );
  211. s->setProxyType( m_advancedWidgetUi->enableProxyCheckBox->isChecked() ? QNetworkProxy::Socks5Proxy : QNetworkProxy::NoProxy );
  212. s->setExternalAddressMode( m_advancedWidgetUi->upnpRadioButton->isChecked() ? TomahawkSettings::Upnp : ( m_advancedWidgetUi->lanOnlyRadioButton->isChecked() ? TomahawkSettings::Lan : TomahawkSettings::Static ) );
  213. s->setExternalHostname( m_advancedWidgetUi->staticHostName->text() );
  214. s->setExternalPort( m_advancedWidgetUi->staticPort->value() );
  215. s->setScannerPaths( m_collectionWidgetUi->dirTree->getCheckedPaths() );
  216. s->setWatchForChanges( m_collectionWidgetUi->checkBoxWatchForChanges->isChecked() );
  217. s->setScannerTime( m_collectionWidgetUi->scannerTimeSpinBox->value() );
  218. s->setEnableEchonestCatalogs( m_collectionWidgetUi->enableEchonestCatalog->isChecked() );
  219. // s->setNowPlayingEnabled( ui->checkBoxEnableAdium->isChecked() );
  220. s->applyChanges();
  221. s->sync();
  222. if ( m_restartRequired )
  223. QMessageBox::information( 0, tr( "Information" ), tr( "Some changed settings will not take effect until Tomahawk is restarted" ) );
  224. TomahawkUtils::NetworkProxyFactory* proxyFactory = TomahawkUtils::proxyFactory();
  225. if ( !m_advancedWidgetUi->enableProxyCheckBox->isChecked() )
  226. {
  227. tDebug() << Q_FUNC_INFO << "Got NoProxy selected";
  228. proxyFactory->setProxy( QNetworkProxy::NoProxy );
  229. }
  230. else
  231. {
  232. tDebug() << Q_FUNC_INFO << "Got Socks5Proxy selected";
  233. proxyFactory->setProxy( QNetworkProxy( QNetworkProxy::Socks5Proxy, s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() ) );
  234. if ( !s->proxyNoProxyHosts().isEmpty() )
  235. {
  236. tDebug() << Q_FUNC_INFO << "noproxy hosts:" << s->proxyNoProxyHosts();
  237. tDebug() << Q_FUNC_INFO << "split noproxy line edit is " << s->proxyNoProxyHosts().split( ' ', QString::SkipEmptyParts );
  238. proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ' ', QString::SkipEmptyParts ) );
  239. }
  240. }
  241. }
  242. SettingsDialog::~SettingsDialog()
  243. {
  244. m_accountsWidget->deleteLater();
  245. m_collectionWidget->deleteLater();
  246. m_advancedWidget->deleteLater();
  247. m_dialog->deleteLater();
  248. }
  249. void
  250. SettingsDialog::show()
  251. {
  252. m_dialog->setCurrentIndex( 0 );
  253. m_dialog->show();
  254. }
  255. void
  256. SettingsDialog::serventReady()
  257. {
  258. m_sipSpinner->fadeOut();
  259. }
  260. void
  261. SettingsDialog::onRejected()
  262. {
  263. m_rejected = true;
  264. }
  265. void
  266. SettingsDialog::changeEvent( QEvent *e )
  267. {
  268. switch ( e->type() )
  269. {
  270. case QEvent::LanguageChange:
  271. m_accountsWidgetUi->retranslateUi( m_accountsWidget );
  272. m_collectionWidgetUi->retranslateUi( m_collectionWidget );
  273. m_advancedWidgetUi->retranslateUi( m_advancedWidget );
  274. break;
  275. default:
  276. break;
  277. }
  278. }
  279. void
  280. SettingsDialog::showProxySettings()
  281. {
  282. m_proxySettings.exec();
  283. if ( m_proxySettings.result() == QDialog::Accepted )
  284. m_proxySettings.saveSettings();
  285. }
  286. void
  287. SettingsDialog::toggleRemoteMode()
  288. {
  289. m_advancedWidgetUi->staticHostNamePortLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  290. m_advancedWidgetUi->staticHostName->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  291. m_advancedWidgetUi->staticPort->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  292. m_advancedWidgetUi->staticHostNameLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  293. m_advancedWidgetUi->staticPortLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
  294. }
  295. void
  296. SettingsDialog::toggleProxyEnabled()
  297. {
  298. m_advancedWidgetUi->proxyButton->setEnabled( m_advancedWidgetUi->enableProxyCheckBox->isChecked() );
  299. }
  300. void
  301. SettingsDialog::updateScanOptionsView()
  302. {
  303. if ( m_collectionWidgetUi->checkBoxWatchForChanges->isChecked() )
  304. {
  305. m_collectionWidgetUi->scanTimeLabel->show();
  306. m_collectionWidgetUi->scannerTimeSpinBox->show();
  307. }
  308. else
  309. {
  310. m_collectionWidgetUi->scanTimeLabel->hide();
  311. m_collectionWidgetUi->scannerTimeSpinBox->hide();
  312. }
  313. }
  314. void
  315. SettingsDialog::accountsFilterChanged( int )
  316. {
  317. AccountType filter = static_cast< AccountType >( m_accountsWidgetUi->accountsFilterCombo->itemData( m_accountsWidgetUi->accountsFilterCombo->currentIndex() ).toInt() );
  318. m_accountProxy->setFilterType( filter );
  319. }
  320. void
  321. SettingsDialog::openAccountFactoryConfig( AccountFactory* factory )
  322. {
  323. QList< Account* > accts;
  324. foreach ( Account* acct, AccountManager::instance()->accounts() )
  325. {
  326. if ( AccountManager::instance()->factoryForAccount( acct ) == factory )
  327. accts << acct;
  328. if ( accts.size() > 1 )
  329. break;
  330. }
  331. Q_ASSERT( accts.size() > 0 ); // Shouldn't have a config wrench if there are no accounts!
  332. if ( accts.size() == 1 )
  333. {
  334. // If there's just one, open the config directly w/ the delete button. Otherwise open the multi dialog
  335. openAccountConfig( accts.first(), true );
  336. return;
  337. }
  338. #ifndef Q_OS_MAC
  339. AccountFactoryWrapper dialog( factory, 0 );
  340. QWeakPointer< AccountFactoryWrapper > watcher( &dialog );
  341. dialog.exec();
  342. #else
  343. // on osx a sheet needs to be non-modal
  344. AccountFactoryWrapper* dialog = new AccountFactoryWrapper( factory, 0 );
  345. dialog->show();
  346. #endif
  347. }
  348. void
  349. SettingsDialog::createAccountFromFactory( AccountFactory* factory )
  350. {
  351. TomahawkUtils::createAccountFromFactory( factory, 0 );
  352. }
  353. void
  354. SettingsDialog::openAccountConfig( Account* account, bool showDelete )
  355. {
  356. TomahawkUtils::openAccountConfig( account, 0, showDelete );
  357. }
  358. void
  359. SettingsDialog::installFromFile()
  360. {
  361. const QString resolver = QFileDialog::getOpenFileName( 0, tr( "Install resolver from file" ), TomahawkSettings::instance()->scriptDefaultPath() );
  362. if( !resolver.isEmpty() )
  363. {
  364. const QFileInfo resolverAbsoluteFilePath( resolver );
  365. TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
  366. if ( resolverAbsoluteFilePath.baseName() == "spotify_tomahawkresolver" )
  367. {
  368. // HACK if this is a spotify resolver, we treat is specially.
  369. // usually we expect the user to just download the spotify resolver from attica,
  370. // however developers, those who build their own tomahawk, can't do that, or linux
  371. // users can't do that. However, we have an already-existing SpotifyAccount that we
  372. // know exists that we need to use this resolver path.
  373. //
  374. // Hence, we special-case the spotify resolver and directly set the path on it here.
  375. SpotifyAccount* acct = 0;
  376. foreach ( Account* account, AccountManager::instance()->accounts() )
  377. {
  378. if ( SpotifyAccount* spotify = qobject_cast< SpotifyAccount* >( account ) )
  379. {
  380. acct = spotify;
  381. break;
  382. }
  383. }
  384. if ( acct )
  385. {
  386. acct->setManualResolverPath( resolver );
  387. return;
  388. }
  389. }
  390. Account* acct = AccountManager::instance()->accountFromPath( resolver );
  391. AccountManager::instance()->addAccount( acct );
  392. TomahawkSettings::instance()->addAccount( acct->accountId() );
  393. AccountManager::instance()->enableAccount( acct );
  394. }
  395. }
  396. void
  397. SettingsDialog::aclEntryClearButtonClicked()
  398. {
  399. QMessageBox::StandardButton button = QMessageBox::question(
  400. 0,
  401. tr( "Delete all Access Control entries?" ),
  402. tr( "Do you really want to delete all Access Control entries? You will be asked for a decision again for each peer that you connect to." ),
  403. QMessageBox::Ok | QMessageBox::Cancel,
  404. QMessageBox::Ok
  405. );
  406. if ( button == QMessageBox::Ok )
  407. {
  408. ACLRegistry::instance()->wipeEntries();
  409. m_advancedWidgetUi->aclEntryClearButton->setEnabled( false );
  410. }
  411. }
  412. void
  413. SettingsDialog::scrollTo( const QModelIndex& idx )
  414. {
  415. m_accountsWidgetUi->accountsView->scrollTo( idx, QAbstractItemView::PositionAtBottom );
  416. }
  417. void
  418. SettingsDialog::requiresRestart()
  419. {
  420. m_restartRequired = true;
  421. }
  422. ProxyDialog::ProxyDialog( QWidget *parent )
  423. : QDialog( parent )
  424. , ui( new Ui::ProxyDialog )
  425. {
  426. ui->setupUi( this );
  427. // ugly, I know, but...
  428. TomahawkSettings* s = TomahawkSettings::instance();
  429. ui->hostLineEdit->setText( s->proxyHost() );
  430. ui->portSpinBox->setValue( s->proxyPort() );
  431. ui->userLineEdit->setText( s->proxyUsername() );
  432. ui->passwordLineEdit->setText( s->proxyPassword() );
  433. ui->checkBoxUseProxyForDns->setChecked( s->proxyDns() );
  434. ui->noHostLineEdit->setText( s->proxyNoProxyHosts() );
  435. }
  436. void
  437. ProxyDialog::saveSettings()
  438. {
  439. qDebug() << Q_FUNC_INFO;
  440. //First set settings
  441. TomahawkSettings* s = TomahawkSettings::instance();
  442. s->setProxyHost( ui->hostLineEdit->text() );
  443. int port = ui->portSpinBox->value();
  444. s->setProxyPort( port );
  445. s->setProxyNoProxyHosts( ui->noHostLineEdit->text() );
  446. s->setProxyUsername( ui->userLineEdit->text() );
  447. s->setProxyPassword( ui->passwordLineEdit->text() );
  448. s->setProxyDns( ui->checkBoxUseProxyForDns->checkState() == Qt::Checked );
  449. s->sync();
  450. }