PageRenderTime 269ms CodeModel.GetById 101ms app.highlight 138ms RepoModel.GetById 23ms app.codeStats 0ms

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