File indexing completed on 2024-05-05 04:47:31
0001 /**************************************************************************************** 0002 * Copyright (c) 2004-2008 Mark Kretschmann <kretschmann@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #define DEBUG_PREFIX "ConfigDialog" 0018 0019 #include "ConfigDialog.h" 0020 0021 #include "amarokconfig.h" 0022 #include "ConfigDialogBase.h" 0023 #include "configdialog/dialogs/CollectionConfig.h" 0024 #include "configdialog/dialogs/DatabaseConfig.h" 0025 #include "configdialog/dialogs/GeneralConfig.h" 0026 #include "configdialog/dialogs/MetadataConfig.h" 0027 #include "configdialog/dialogs/NotificationsConfig.h" 0028 #include "configdialog/dialogs/PlaybackConfig.h" 0029 #include "configdialog/dialogs/PluginsConfig.h" 0030 #include "configdialog/dialogs/ScriptsConfig.h" 0031 #include "core/support/Amarok.h" 0032 #include "core/support/Debug.h" 0033 0034 #include <KLocalizedString> 0035 0036 0037 QString Amarok2ConfigDialog::s_currentPage = QStringLiteral("GeneralConfig"); 0038 0039 ////////////////////////////////////////////////////////////////////////////////////////// 0040 // PUBLIC 0041 ////////////////////////////////////////////////////////////////////////////////////////// 0042 0043 Amarok2ConfigDialog::Amarok2ConfigDialog( QWidget *parent, const char* name, KCoreConfigSkeleton *config ) 0044 : KConfigDialog( parent, name, config ) 0045 { 0046 DEBUG_BLOCK 0047 setAttribute( Qt::WA_DeleteOnClose ); 0048 0049 ConfigDialogBase *general = new GeneralConfig( this ); 0050 ConfigDialogBase *collection = new CollectionConfig( this ); 0051 ConfigDialogBase *metadata = new MetadataConfig( this ); 0052 ConfigDialogBase *playback = new PlaybackConfig( this ); 0053 ConfigDialogBase *notify = new NotificationsConfig( this ); 0054 ConfigDialogBase *database = new DatabaseConfig( this, config ); 0055 ConfigDialogBase *plugins = new PluginsConfig( this ); 0056 ConfigDialogBase *scripts = new ScriptsConfig( this ); 0057 //ConfigDialogBase* mediadevice = new MediadeviceConfig( this ); 0058 0059 addPage( general, i18nc( "Miscellaneous settings", "General" ), QStringLiteral("preferences-other-amarok"), i18n( "Configure General Options" ) ); 0060 addPage( collection, i18n( "Local Collection" ), QStringLiteral("drive-harddisk"), i18n( "Configure Local Collection" ) ); 0061 addPage( metadata, i18n( "Metadata" ), QStringLiteral("amarok_playcount"), i18n( "Configure Metadata Handling" ) ); 0062 addPage( playback, i18n( "Playback" ), QStringLiteral("preferences-media-playback-amarok"), i18n( "Configure Playback" ) ); 0063 addPage( notify, i18n( "Notifications" ), QStringLiteral("preferences-indicator-amarok"), i18n( "Configure Notifications" ) ); 0064 addPage( database, i18n( "Database" ), QStringLiteral("server-database"), i18n( "Configure Database" ) ); 0065 addPage( plugins, i18n( "Plugins" ), QStringLiteral("preferences-plugin"), i18n( "Configure Plugins" ) ); 0066 addPage( scripts, i18n( "Scripts" ), QStringLiteral("preferences-plugin-script"), i18n( "Configure Scripts" ) ); 0067 //addPage( mediadevice, i18n( "Media Devices" ), "preferences-multimedia-player-amarok", i18n( "Configure Portable Player Support" ) ); 0068 0069 QPushButton *okButton = buttonBox()->button(QDialogButtonBox::Ok); 0070 okButton->setDefault(true); 0071 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0072 0073 KWindowConfig::restoreWindowSize(windowHandle(), Amarok::config( QStringLiteral("ConfigDialog") )); 0074 } 0075 0076 Amarok2ConfigDialog::~Amarok2ConfigDialog() 0077 { 0078 DEBUG_BLOCK 0079 0080 KPageWidgetItem* pageItem = currentPage(); 0081 0082 foreach( ConfigDialogBase *configPage, m_pageList ) 0083 { 0084 if( m_pageMap[configPage] == pageItem ) 0085 { 0086 s_currentPage = configPage->metaObject()->className(); 0087 break; 0088 } 0089 } 0090 0091 KConfigGroup config = Amarok::config( QStringLiteral("ConfigDialog") ); 0092 KWindowConfig::saveWindowSize(windowHandle(), config); 0093 AmarokConfig::self()->save(); 0094 } 0095 0096 void Amarok2ConfigDialog::updateButtons() //SLOT 0097 { 0098 DEBUG_BLOCK 0099 0100 buttonBox()->button(QDialogButtonBox::Apply)->setEnabled( hasChanged() ); 0101 } 0102 0103 /** Reimplemented from KConfigDialog */ 0104 void Amarok2ConfigDialog::addPage( ConfigDialogBase *page, const QString &itemName, const QString &pixmapName, const QString &header, bool manage ) 0105 { 0106 connect( page, &ConfigDialogBase::settingsChanged, this, &Amarok2ConfigDialog::settingsChanged ); 0107 0108 // Add the widget pointer to our list, for later reference 0109 m_pageList << page; 0110 KPageWidgetItem *pageWidget = KConfigDialog::addPage( page, itemName, pixmapName, header, manage ); 0111 m_pageMap.insert( page, pageWidget ); 0112 } 0113 0114 void Amarok2ConfigDialog::show( QString page ) 0115 { 0116 if( page.isNull() ) 0117 { 0118 page = s_currentPage; 0119 } 0120 0121 foreach( ConfigDialogBase *configPage, m_pageList ) 0122 { 0123 if( configPage->metaObject()->className() == page ) 0124 { 0125 KPageWidgetItem *pageItem = m_pageMap[configPage]; 0126 KConfigDialog::setCurrentPage( pageItem ); 0127 break; 0128 } 0129 } 0130 0131 KConfigDialog::show(); 0132 raise(); 0133 activateWindow(); 0134 } 0135 0136 ////////////////////////////////////////////////////////////////////////////////////////// 0137 // PROTECTED SLOTS 0138 ////////////////////////////////////////////////////////////////////////////////////////// 0139 0140 /** 0141 * Update the settings from the dialog. 0142 * Example use: User clicks Ok or Apply button in a configure dialog. 0143 * REIMPLEMENTED 0144 */ 0145 void Amarok2ConfigDialog::updateSettings() 0146 { 0147 foreach( ConfigDialogBase* page, m_pageList ) 0148 page->updateSettings(); 0149 } 0150 0151 /** 0152 * Update the configuration-widgets in the dialog based on Amarok's current settings. 0153 * Example use: Initialisation of dialog. 0154 * Example use: User clicks Reset button in a configure dialog. 0155 * REIMPLEMENTED 0156 */ 0157 void Amarok2ConfigDialog::updateWidgets() 0158 { 0159 foreach( ConfigDialogBase* page, m_pageList ) 0160 page->updateWidgets(); 0161 } 0162 0163 /** 0164 * Update the configuration-widgets in the dialog based on the default values for Amarok's settings. 0165 * Example use: User clicks Defaults button in a configure dialog. 0166 * REIMPLEMENTED 0167 */ 0168 void Amarok2ConfigDialog::updateWidgetsDefault() 0169 { 0170 foreach( ConfigDialogBase* page, m_pageList ) 0171 page->updateWidgetsDefault(); 0172 } 0173 0174 0175 ////////////////////////////////////////////////////////////////////////////////////////// 0176 // PROTECTED 0177 ////////////////////////////////////////////////////////////////////////////////////////// 0178 0179 /** 0180 * @return true if any configuration items we are managing changed from Amarok's stored settings 0181 * We manage the engine combo box and some of the OSD settings 0182 * REIMPLEMENTED 0183 */ 0184 bool Amarok2ConfigDialog::hasChanged() 0185 { 0186 DEBUG_BLOCK 0187 0188 bool changed = false; 0189 0190 foreach( ConfigDialogBase* page, m_pageList ) 0191 if( page->hasChanged() ) { 0192 changed = true; 0193 debug() << "Changed: " << page->metaObject()->className(); 0194 } 0195 0196 return changed; 0197 } 0198 0199 /** REIMPLEMENTED */ 0200 bool Amarok2ConfigDialog::isDefault() 0201 { 0202 bool def = false; 0203 0204 foreach( ConfigDialogBase* page, m_pageList ) 0205 if( page->isDefault() ) 0206 def = true; 0207 0208 return def; 0209 } 0210 0211 0212 ////////////////////////////////////////////////////////////////////////////////////////// 0213 // PRIVATE SLOTS 0214 ////////////////////////////////////////////////////////////////////////////////////////// 0215 0216 0217 ////////////////////////////////////////////////////////////////////////////////////////// 0218 // PRIVATE 0219 ////////////////////////////////////////////////////////////////////////////////////////// 0220 0221