PreferencesDialog::PreferencesDialog( QMenuBar* menuBar, QWidget* parent )
    :unicorn::MainWindow( menuBar, parent ),
    ui( new Ui::PreferencesDialog )
{
    // Disable the minimize and maximize buttons.
    Qt::WindowFlags flags = this->windowFlags();
    flags &= ~Qt::WindowMinMaxButtonsHint;
    setWindowFlags(flags);

    ui->setupUi( this );

    setAttribute( Qt::WA_DeleteOnClose, true );

    static_cast<QAbstractButton*>( ui->toolBar->widgetForAction( ui->actionGeneral ) )->setAutoExclusive( true );
    static_cast<QAbstractButton*>( ui->toolBar->widgetForAction( ui->actionScrobbling ) )->setAutoExclusive( true );
    static_cast<QAbstractButton*>( ui->toolBar->widgetForAction( ui->actionDevices ) )->setAutoExclusive( true );
    static_cast<QAbstractButton*>( ui->toolBar->widgetForAction( ui->actionAccounts ) )->setAutoExclusive( true );
    static_cast<QAbstractButton*>( ui->toolBar->widgetForAction( ui->actionAdvanced ) )->setAutoExclusive( true );

    connect( ui->toolBar->widgetForAction( ui->actionGeneral ), SIGNAL(toggled(bool)), ui->actionGeneral, SLOT(setChecked(bool)) );
    connect( ui->toolBar->widgetForAction( ui->actionScrobbling ), SIGNAL(toggled(bool)), ui->actionScrobbling, SLOT(setChecked(bool)) );
    connect( ui->toolBar->widgetForAction( ui->actionDevices ), SIGNAL(toggled(bool)), ui->actionDevices, SLOT(setChecked(bool)) );
    connect( ui->toolBar->widgetForAction( ui->actionAccounts ), SIGNAL(toggled(bool)), ui->actionAccounts, SLOT(setChecked(bool)) );
    connect( ui->toolBar->widgetForAction( ui->actionAdvanced ), SIGNAL(toggled(bool)), ui->actionAdvanced, SLOT(setChecked(bool)) );

    connect( this, SIGNAL( saveNeeded() ), ui->general, SLOT( saveSettings() ) );
    connect( this, SIGNAL( saveNeeded() ), ui->scrobbling, SLOT( saveSettings() ) );
    connect( this, SIGNAL( saveNeeded() ), ui->ipod, SLOT( saveSettings() ) );
    connect( this, SIGNAL( saveNeeded() ), ui->accounts, SLOT( saveSettings() ) );
    connect( this, SIGNAL( saveNeeded() ), ui->advanced, SLOT( saveSettings() ) );

    connect( ui->general, SIGNAL( settingsChanged() ), SLOT( onSettingsChanged() ) );
    connect( ui->scrobbling, SIGNAL( settingsChanged() ), SLOT( onSettingsChanged() ) );
    connect( ui->ipod, SIGNAL( settingsChanged() ), SLOT( onSettingsChanged() ) );
    connect( ui->accounts, SIGNAL( settingsChanged() ), SLOT( onSettingsChanged() ) );
    connect( ui->advanced, SIGNAL( settingsChanged() ), SLOT( onSettingsChanged() ) );

    connect( ui->actionGeneral, SIGNAL(triggered()), SLOT(onTabButtonClicked()));
    connect( ui->actionScrobbling, SIGNAL(triggered()), SLOT(onTabButtonClicked()));
    connect( ui->actionDevices, SIGNAL(triggered()), SLOT(onTabButtonClicked()));
    connect( ui->actionAccounts, SIGNAL(triggered()), SLOT(onTabButtonClicked()));
    connect( ui->actionAdvanced, SIGNAL(triggered()), SLOT(onTabButtonClicked()));

    connect( ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(onStackCurrentChanged(int)), Qt::QueuedConnection );

#ifdef Q_OS_MAC
    ui->buttonBox->hide();
#endif
    connect( ui->buttonBox, SIGNAL( accepted() ), SLOT( onAccepted() ) );
    connect( ui->buttonBox, SIGNAL( rejected() ), SLOT( onRejected() ) );

    QAbstractButton* applyButton = ui->buttonBox->button( QDialogButtonBox::Apply );
    applyButton->setEnabled( false );
    connect( applyButton, SIGNAL( clicked() ), SLOT( onApplyButtonClicked() ) );

    setFixedWidth( 550 );

    ui->stackedWidget->setCurrentWidget( ui->accounts );
    ui->actionGeneral->trigger();
}
SGMSettingsMasterView::SGMSettingsMasterView(QWidget *parent) :
	QWidget(parent)
{
	sgmPluginsLocationView_ = new SGMPluginsLocationView();
	sgmDetectorsMasterView_ = new SGMDetectorsMasterView();

	connect(sgmPluginsLocationView_, SIGNAL(unsavedChanges(bool)), this, SLOT(onUnsavedChanges(bool)));
	connect(sgmDetectorsMasterView_, SIGNAL(unsavedChanges(bool)), this, SLOT(onUnsavedChanges(bool)));

	vl_ = new QVBoxLayout();
	vl_->addWidget(sgmPluginsLocationView_);
	vl_->addWidget(sgmDetectorsMasterView_);

	applyButton_ = new QPushButton("Apply");
	cancelButton_ = new QPushButton("Cancel");
	okButton_ = new QPushButton("Ok");

	connect(applyButton_, SIGNAL(clicked()), this, SLOT(onApplyButtonClicked()));
	connect(cancelButton_, SIGNAL(clicked()), this, SLOT(onCancelButtonClicked()));
	connect(okButton_, SIGNAL(clicked()), this, SLOT(onOkButtonClicked()));

	QHBoxLayout *hl = new QHBoxLayout();
	hl->addWidget(applyButton_);
	hl->addStretch(4);
	hl->addWidget(cancelButton_);
	hl->addWidget(okButton_);

	vl_->addLayout(hl);

	setLayout(vl_);
}
void SGMSettingsMasterView::onOkButtonClicked(){
	onApplyButtonClicked();
	close();
}