1 /****************************************************************************************
2 * Copyright (c) 2004-2008 Mark Kretschmann <kretschmann@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17 #define DEBUG_PREFIX "ConfigDialog"
18
19 #include "ConfigDialog.h"
20
21 #include "amarokconfig.h"
22 #include "ConfigDialogBase.h"
23 #include "configdialog/dialogs/CollectionConfig.h"
24 #include "configdialog/dialogs/DatabaseConfig.h"
25 #include "configdialog/dialogs/GeneralConfig.h"
26 #include "configdialog/dialogs/MetadataConfig.h"
27 #include "configdialog/dialogs/NotificationsConfig.h"
28 #include "configdialog/dialogs/PlaybackConfig.h"
29 #include "configdialog/dialogs/PluginsConfig.h"
30 #include "configdialog/dialogs/ScriptsConfig.h"
31 #include "core/support/Amarok.h"
32 #include "core/support/Debug.h"
33
34 #include <KLocalizedString>
35
36
37 QString Amarok2ConfigDialog::s_currentPage = QStringLiteral("GeneralConfig");
38
39 //////////////////////////////////////////////////////////////////////////////////////////
40 // PUBLIC
41 //////////////////////////////////////////////////////////////////////////////////////////
42
Amarok2ConfigDialog(QWidget * parent,const char * name,KConfigSkeleton * config)43 Amarok2ConfigDialog::Amarok2ConfigDialog( QWidget *parent, const char* name, KConfigSkeleton *config )
44 : KConfigDialog( parent, name, config )
45 {
46 DEBUG_BLOCK
47 setAttribute( Qt::WA_DeleteOnClose );
48
49 ConfigDialogBase *general = new GeneralConfig( this );
50 ConfigDialogBase *collection = new CollectionConfig( this );
51 ConfigDialogBase *metadata = new MetadataConfig( this );
52 ConfigDialogBase *playback = new PlaybackConfig( this );
53 ConfigDialogBase *notify = new NotificationsConfig( this );
54 ConfigDialogBase *database = new DatabaseConfig( this, config );
55 ConfigDialogBase *plugins = new PluginsConfig( this );
56 ConfigDialogBase *scripts = new ScriptsConfig( this );
57 //ConfigDialogBase* mediadevice = new MediadeviceConfig( this );
58
59 addPage( general, i18nc( "Miscellaneous settings", "General" ), QStringLiteral("preferences-other-amarok"), i18n( "Configure General Options" ) );
60 addPage( collection, i18n( "Local Collection" ), QStringLiteral("drive-harddisk"), i18n( "Configure Local Collection" ) );
61 addPage( metadata, i18n( "Metadata" ), QStringLiteral("amarok_playcount"), i18n( "Configure Metadata Handling" ) );
62 addPage( playback, i18n( "Playback" ), QStringLiteral("preferences-media-playback-amarok"), i18n( "Configure Playback" ) );
63 addPage( notify, i18n( "Notifications" ), QStringLiteral("preferences-indicator-amarok"), i18n( "Configure Notifications" ) );
64 addPage( database, i18n( "Database" ), QStringLiteral("server-database"), i18n( "Configure Database" ) );
65 addPage( plugins, i18n( "Plugins" ), QStringLiteral("preferences-plugin"), i18n( "Configure Plugins" ) );
66 addPage( scripts, i18n( "Scripts" ), QStringLiteral("preferences-plugin-script"), i18n( "Configure Scripts" ) );
67 //addPage( mediadevice, i18n( "Media Devices" ), "preferences-multimedia-player-amarok", i18n( "Configure Portable Player Support" ) );
68
69 QPushButton *okButton = buttonBox()->button(QDialogButtonBox::Ok);
70 okButton->setDefault(true);
71 okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
72
73 KWindowConfig::restoreWindowSize(windowHandle(), Amarok::config( QStringLiteral("ConfigDialog") ));
74 }
75
~Amarok2ConfigDialog()76 Amarok2ConfigDialog::~Amarok2ConfigDialog()
77 {
78 DEBUG_BLOCK
79
80 KPageWidgetItem* pageItem = currentPage();
81
82 foreach( ConfigDialogBase *configPage, m_pageList )
83 {
84 if( m_pageMap[configPage] == pageItem )
85 {
86 s_currentPage = configPage->metaObject()->className();
87 break;
88 }
89 }
90
91 KConfigGroup config = Amarok::config( QStringLiteral("ConfigDialog") );
92 KWindowConfig::saveWindowSize(windowHandle(), config);
93 AmarokConfig::self()->save();
94 }
95
updateButtons()96 void Amarok2ConfigDialog::updateButtons() //SLOT
97 {
98 DEBUG_BLOCK
99
100 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled( hasChanged() );
101 }
102
103 /** Reimplemented from KConfigDialog */
addPage(ConfigDialogBase * page,const QString & itemName,const QString & pixmapName,const QString & header,bool manage)104 void Amarok2ConfigDialog::addPage( ConfigDialogBase *page, const QString &itemName, const QString &pixmapName, const QString &header, bool manage )
105 {
106 connect( page, &ConfigDialogBase::settingsChanged, this, &Amarok2ConfigDialog::settingsChanged );
107
108 // Add the widget pointer to our list, for later reference
109 m_pageList << page;
110 KPageWidgetItem *pageWidget = KConfigDialog::addPage( page, itemName, pixmapName, header, manage );
111 m_pageMap.insert( page, pageWidget );
112 }
113
show(QString page)114 void Amarok2ConfigDialog::show( QString page )
115 {
116 if( page.isNull() )
117 {
118 page = s_currentPage;
119 }
120
121 foreach( ConfigDialogBase *configPage, m_pageList )
122 {
123 if( configPage->metaObject()->className() == page )
124 {
125 KPageWidgetItem *pageItem = m_pageMap[configPage];
126 KConfigDialog::setCurrentPage( pageItem );
127 break;
128 }
129 }
130
131 KConfigDialog::show();
132 raise();
133 activateWindow();
134 }
135
136 //////////////////////////////////////////////////////////////////////////////////////////
137 // PROTECTED SLOTS
138 //////////////////////////////////////////////////////////////////////////////////////////
139
140 /**
141 * Update the settings from the dialog.
142 * Example use: User clicks Ok or Apply button in a configure dialog.
143 * REIMPLEMENTED
144 */
updateSettings()145 void Amarok2ConfigDialog::updateSettings()
146 {
147 foreach( ConfigDialogBase* page, m_pageList )
148 page->updateSettings();
149 }
150
151 /**
152 * Update the configuration-widgets in the dialog based on Amarok's current settings.
153 * Example use: Initialisation of dialog.
154 * Example use: User clicks Reset button in a configure dialog.
155 * REIMPLEMENTED
156 */
updateWidgets()157 void Amarok2ConfigDialog::updateWidgets()
158 {
159 foreach( ConfigDialogBase* page, m_pageList )
160 page->updateWidgets();
161 }
162
163 /**
164 * Update the configuration-widgets in the dialog based on the default values for Amarok's settings.
165 * Example use: User clicks Defaults button in a configure dialog.
166 * REIMPLEMENTED
167 */
updateWidgetsDefault()168 void Amarok2ConfigDialog::updateWidgetsDefault()
169 {
170 foreach( ConfigDialogBase* page, m_pageList )
171 page->updateWidgetsDefault();
172 }
173
174
175 //////////////////////////////////////////////////////////////////////////////////////////
176 // PROTECTED
177 //////////////////////////////////////////////////////////////////////////////////////////
178
179 /**
180 * @return true if any configuration items we are managing changed from Amarok's stored settings
181 * We manage the engine combo box and some of the OSD settings
182 * REIMPLEMENTED
183 */
hasChanged()184 bool Amarok2ConfigDialog::hasChanged()
185 {
186 DEBUG_BLOCK
187
188 bool changed = false;
189
190 foreach( ConfigDialogBase* page, m_pageList )
191 if( page->hasChanged() ) {
192 changed = true;
193 debug() << "Changed: " << page->metaObject()->className();
194 }
195
196 return changed;
197 }
198
199 /** REIMPLEMENTED */
isDefault()200 bool Amarok2ConfigDialog::isDefault()
201 {
202 bool def = false;
203
204 foreach( ConfigDialogBase* page, m_pageList )
205 if( page->isDefault() )
206 def = true;
207
208 return def;
209 }
210
211
212 //////////////////////////////////////////////////////////////////////////////////////////
213 // PRIVATE SLOTS
214 //////////////////////////////////////////////////////////////////////////////////////////
215
216
217 //////////////////////////////////////////////////////////////////////////////////////////
218 // PRIVATE
219 //////////////////////////////////////////////////////////////////////////////////////////
220
221
222