diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 225c8093..92eb3e90 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -47,7 +47,7 @@ kde4_bool_to_01(X11_XSync_FOUND HAVE_XSYNC) # kidletim # check is to be added to get the proper set of headers. check_symbol_exists(strmode "string.h" HAVE_STRMODE) # karchive -check_function_exists(backtrace HAVE_BACKTRACE) # kdecore, kio +check_function_exists(backtrace HAVE_BACKTRACE) # kdecore check_function_exists(fdatasync HAVE_FDATASYNC) # kdecore check_function_exists(arc4random_uniform HAVE_ARC4RANDOM_UNIFORM) # kdecore check_function_exists(sendfile HAVE_SENDFILE) # kioslave diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index ec5597a0..37329004 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -373,15 +373,6 @@ install( DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/KDE/KParts ) - -install( - FILES - KSettings/Dialog - KSettings/Dispatcher - KSettings/PluginPage - DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/KDE/KSettings -) - install( FILES KTextEditor/Attribute diff --git a/includes/KSettings/Dialog b/includes/KSettings/Dialog deleted file mode 100644 index 3ed62f91..00000000 --- a/includes/KSettings/Dialog +++ /dev/null @@ -1 +0,0 @@ -#include "../../ksettings/dialog.h" diff --git a/includes/KSettings/Dispatcher b/includes/KSettings/Dispatcher deleted file mode 100644 index 808e6072..00000000 --- a/includes/KSettings/Dispatcher +++ /dev/null @@ -1 +0,0 @@ -#include "../../ksettings/dispatcher.h" diff --git a/includes/KSettings/PluginPage b/includes/KSettings/PluginPage deleted file mode 100644 index e6199ed4..00000000 --- a/includes/KSettings/PluginPage +++ /dev/null @@ -1 +0,0 @@ -#include "../../ksettings/pluginpage.h" diff --git a/kdecore/kdebug.areas b/kdecore/kdebug.areas index ce3eb3f9..5b4c9cf7 100644 --- a/kdecore/kdebug.areas +++ b/kdecore/kdebug.areas @@ -27,10 +27,7 @@ 265 kdeui (KIconEffect) 299 kdeui (KNotification) 300 kdeui (KConfigDialogManager) -700 kutils (KSettings::Dialog) -701 kutils (KSettings::Dispatcher) 702 kutils (KPluginSelector) -704 kutils (KSettings::ComponentsDialog) 710 kutils (KCMultiDialog) 711 kutils (KCModuleProxy) 712 kutils (KCModuleInfo) diff --git a/kutils/CMakeLists.txt b/kutils/CMakeLists.txt index ac1c73f5..fdcce677 100644 --- a/kutils/CMakeLists.txt +++ b/kutils/CMakeLists.txt @@ -27,10 +27,6 @@ set(kcmutils_LIB_SRCS kpluginselector.cpp kcmodulecontainer.cpp ksettingswidgetadaptor.cpp - ksettings/dispatcher.cpp - ksettings/dialog.cpp - ksettings/pluginpage.cpp - ksettings/componentsdialog.cpp ) add_library(kcmutils SHARED ${kcmutils_LIB_SRCS}) @@ -60,14 +56,6 @@ install( DESTINATION ${KDE4_INCLUDE_INSTALL_DIR} ) -install( - FILES - ksettings/dispatcher.h - ksettings/dialog.h - ksettings/pluginpage.h - DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/ksettings -) - install( TARGETS kcmutils EXPORT kdelibsTargets diff --git a/kutils/ksettings/README.dox b/kutils/ksettings/README.dox deleted file mode 100644 index 1953ac91..00000000 --- a/kutils/ksettings/README.dox +++ /dev/null @@ -1,275 +0,0 @@ -/** - -\namespace KSettings - -\short A collection of classes to create configuration dialogs that work over -component boundaries - -

How to use KSettings::Dialog in your application.

- -
-

1. Open the dialog from your app

- -All you need to do is instanciate KSettings::Dialog and show() it. I recommend -the following: - -create the 'Configure MyApp' StdAction like this: -\code -KStandardAction::preferences( this, SLOT( showConfigDialog() ), actionCollection ); -\endcode - -and the slot looks like this: -\code -if( m_dlg == 0 ) - m_dlg = new KSettings::Dialog( this ); -m_dlg->show(); -\endcode - -Of course you need to have the 'KSettings::Dialog * m_dlg' member var and -initialize it to 0 in the ctor. - -If your application uses KParts that don't set 'X-KDE-ParentApp=<the instance -name of your application>' then you need to use the second ctor of -KSettings::Dialog: -\code -m_dlg = new KSettings::Dialog( QStringList::split( ';', "component1;component2" ) ); -\endcode - -The KSettings::Dialog object will be destructed automatically by the QObject -mechanisms. - - -
-

2. Create pages for your dialog

- -Every page is a KCM. This is what you need for creating a page: - -\code -class MyAppConfig : public KCModule -{ - Q_OBJECT -public: - MyAppConfig( QWidget *parent, const char *name = 0, const QStringList &args = - QStringList() ); - ~MyAppConfig(); - - void load(); - void save(); - void defaults(); -} -\endcode - -and in the cpp file: - -\code -K_PLUGIN_FACTORY(MyAppConfigFactory, - registerPlugin(); - ) -K_EXPORT_PLUGIN(MyAppConfigFactory("kcm_myappconfig")); - -MyAppConfig::MyAppConfig(QWidget *parent, const char *, const QVariantList &args) - : KCModule(MyAppConfigFactory::instance(), parent, args) -{ - // create the pages GUI - load(); -} - -// implementations for the other methods -\endcode - -For the KConfig object you can either use -KGlobal::config() (I don't recommend it) or KSimpleConfig( "myapprc" ). -I added a method to KSettings::Dispatcher that gives you the KConfig -object for every registered instance name: \ref KSettings::Dispatcher::configForInstanceName - - -
-

3. The .desktop file for the page

- -The .desktop file holds all the information for the dialog to find the page and -insert it at the right place (with the right icon, name and comment). - -An example file: -\verbatim -[Desktop Entry] -Encoding=UTF-8 -Icon=myapp -Type=Service -ServiceTypes=KCModule - -X-KDE-Library=myappconfig -X-KDE-ParentApp=myapp -X-KDE-ParentComponents=myapp -X-KDE-Weight=10 - -Name=General -Comment=General configuration of my app -\endverbatim - - -Some explanation for those keys: -- You just keep 'Encoding', 'Type' and 'ServiceTypes' like - in the example. For very special needs you might add another ServiceType to - the list... -- Icon is the icon that will be used in the listview/iconview for your page. -- X-KDE-Library is the name of the library where the page is in. The library - always needs to be prefixed with kcm_ but you don't write the prefix in the - desktop file. For more docu on this look for the KCModule docu. -- X-KDE-ParentApp is the name of the application this config page belongs to. It - is used by the first two \ref KSettings::Dialog constructors. The Dialog will - use all modules that set X-KDE-ParentApp to - KGlobal::instance()->instanceName(). It - should be pretty easy to find out what name that is: look at the first - argument to the KAboutData ctor. -- X-KDE-ParentComponents is a list of the components (plugin/KPart/whatever) - this config page belongs to. Normally there is only one component. - It is used for two things: - -# If you use KSettings::Dispatcher the dispatcher will notify all components - in this list after the save() method of your KCM has been called. The - components then can reload the configuration and apply the changes the user - did to the config. - -# If your component is used by another application (that is not = - X-KDE-ParentApp) then it may add the name of the component to the ctor of - KSettings::Dialog and the dialog will automatically include all config - pages that have the components name in their ParentComponents list. -- X-KDE-Weight sets the order for the modules to be inserted into the dialog. - The higher the number (heavier) the lower the module will appear in the list. - (the default value is 100) -- Name is the string that is shown in the listview/iconview right below the - icon. -- Comment is the string that is shown on top of the config page for a short - description what you can do on this page. - - -
-

4. The .setdlg file for hierarchical (TreeList) page layouts

- -If your config dialog should show a tree of pages in the config dialog you need -to define that hierarchy with a .setdlg file. - -The file should be installed in apps/<appname>/<appname>.setdlg. If third party -plugins need to merge in they will install their file to -apps/<appname>/ksettingsdialog/<pluginname>.setdlg. - -A .setdlg file contains one or more blocks like the following: - -\verbatim -[id] -Name= -Comment= -Icon= -Weight= -Parent= -\endverbatim - -- The group name (id) is the name you use in the .desktop file of the page: - If your page's .desktop file says "X-KDE-CfgDlgHierarchy=id" then it will be - inserted as a child of this entry. -- \p Name: The name of the section. It will appear in the listview. -- \p Comment: A description of what the modules in this section are. It will - appear in the place where the KCMs are placed when the user clicks on the item - in the listview. -- \p Icon: An icon for the item. -- \p Weight: Defines the position in the listview. See X-KDE-Weight above. -- \p Parent: If this group should be a child of another group write the parent's - group id here. - -
-

5. The Pluginselector

- -There are two ways to use the KPluginSelector widget. One is to use the class -directly and the second to use KSettings::PluginPage as baseclass for a config -page that shows the KPluginSelector widget. - -I'll cover the second usage here and the calls to addPlugins are just the same -for the first. - -To create a plugin page you need the following code: - -\code -K_PLUGIN_FACTORY(MyAppPluginConfigFactory, - registerPlugin(); - ) -K_EXPORT_PLUGIN(MyAppConfigFactory("kcm_myapppluginconfig")); - -MyAppPluginConfig(QWidget * parent, const char *, const QVariantList & args) - : PluginPage(MyAppPluginConfigFactory::instance(), parent, args) -{ - pluginSelector()->addPlugins( ... ); - pluginSelector()->addPlugins( ... ); - . - . - . -} -\endcode - -pluginSelector() returns a pointer to the KPluginSelector widget of the page. -There are three addPlugins methods available, two for adding KParts plugins and -one for the rest. - - -
-

6. The .desktop files of plugin config pages

- -this is the entry for the Makefile.am: - -\verbatim -myappconfigpagedir = $(kde_servicesdir)/ -myappconfigpage_DATA = myappconfigpage.desktop -\endverbatim - - -And this is what the .desktop file looks like: - -\verbatim -[Desktop Entry] -Encoding=UTF-8 -Type=Service -Icon= -ServiceTypes=KPluginInfo - -Name=MyPlugin -Comment=My plugin is cool and does foo and bar. - -X-KDE-PluginInfo-Name=myplugin - -X-KDE-PluginInfo-Author= -X-KDE-PluginInfo-Email= -X-KDE-PluginInfo-Website=http://www.myplugin.org/ -X-KDE-PluginInfo-Category=CoolPlugins -X-KDE-PluginInfo-Version=0.1 -X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-EnabledByDefault=true -X-KDE-PluginInfo-Depends=myotherplugin -X-KDE-CfgDlgHierarchy=GroupID -\endverbatim - -Explanation: -mandatory entries: -- leave \p Type and \p Encoding like in the example -- \p Name -- \p Comment -- \p X-KDE-PluginInfo-Name is the "internal name" of the plugin. -- You need to have \p KPluginInfo in \p ServiceTypes but of course you may have more - entries in there. - -optional entries: -- \p Icon is the icon used for your plugin (it's shown in the pluginselector if you - set one). -- \p X-KDE-PluginInfo-Author and \p X-KDE-PluginInfo-Email is some information about the author of the plugin. -- \p X-KDE-PluginInfo-Website is the address for a webpage for this plugin. -- \p X-KDE-PluginInfo-Category is used if your application has different categories of plugins. -- \p X-KDE-PluginInfo-Version is the version of this plugin. -- \p X-KDE-PluginInfo-License is the license of this plugin. -- \p X-KDE-PluginInfo-EnabledByDefault tells the program whether the plugin - should be enabled on first startup or not. -- \p X-KDE-PluginInfo-Depends can be used to tell the application that you need to have - myotherplugin enabled for your plugin to work. -- \p X-KDE-CfgDlgHierarchy is used if you use a \p KSettings::Dialog::ConfigurableInline - KSettings::Dialog to put the plugin checkbox into the group with the GroupID - you set here. - -If you have questions contact Matthias Kretz . -*/ -// vim: tw=80 - \ No newline at end of file diff --git a/kutils/ksettings/componentsdialog.cpp b/kutils/ksettings/componentsdialog.cpp deleted file mode 100644 index 0fe41807..00000000 --- a/kutils/ksettings/componentsdialog.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include "componentsdialog_p.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace KSettings -{ - -class ComponentsDialog::ComponentsDialogPrivate -{ - public: - QTreeWidget * listview; - QFrame * infowidget; - QLabel * iconwidget; - QLabel * commentwidget; - QLabel * descriptionwidget; - QMap plugininfomap; - QList plugininfolist; -}; - -ComponentsDialog::ComponentsDialog( QWidget * parent, const char * name ) - : KDialog( parent ), d( new ComponentsDialogPrivate ) -{ - setObjectName( name ); - setModal( false ); - setCaption( i18n( "Select Components" ) ); - - QWidget * page = new QWidget( this ); - setMainWidget( page ); - QHBoxLayout *hbox = new QHBoxLayout( page ); - hbox->setMargin( 0 ); - - d->listview = new QTreeWidget( page ); - d->listview->setMinimumSize( 200, 200 ); - d->infowidget = new QFrame( page ); - d->infowidget->setMinimumSize( 200, 200 ); - - QVBoxLayout *vbox = new QVBoxLayout( d->infowidget ); - vbox->setMargin( 0 ); - - d->iconwidget = new QLabel( d->infowidget ); - vbox->addWidget( d->iconwidget ); - vbox->addWidget( new KSeparator( d->infowidget ) ); - d->commentwidget = new QLabel( d->infowidget ); - d->commentwidget->setWordWrap( true ); - vbox->addWidget( d->commentwidget ); - d->descriptionwidget = new QLabel( d->infowidget ); - d->descriptionwidget->setWordWrap( true ); - vbox->addWidget( d->descriptionwidget ); - - d->listview->setAcceptDrops( false ); - - connect( d->listview, SIGNAL(itemPressed(QTreeWidgetItem*,int)), this, - SLOT(executed(QTreeWidgetItem*,int)) ); - connect( d->listview, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, - SLOT(executed(QTreeWidgetItem*,int)) ); - connect( d->listview, SIGNAL(itemSelectionChanged(QTreeWidgetItem*,int)), this, - SLOT(executed(QTreeWidgetItem*,int)) ); -} - -ComponentsDialog::~ComponentsDialog() -{ - delete d; -} - -void ComponentsDialog::addPluginInfo( KPluginInfo * info ) -{ - d->plugininfolist.append( info ); -} - -void ComponentsDialog::setPluginInfos( const QMap & - plugininfos ) -{ - QMapIterator it(plugininfos); - while (it.hasNext()) { - it.next(); - d->plugininfolist.append( it.value() ); - } -} - -void ComponentsDialog::setPluginInfos( const QList &plugins ) -{ - d->plugininfolist = plugins; -} - -void ComponentsDialog::show() -{ - // clear the treelist - d->listview->clear(); - d->plugininfomap.clear(); - - // construct the treelist - for( QList::ConstIterator it = d->plugininfolist.constBegin(); - it != d->plugininfolist.constEnd(); ++it ) - { - ( *it )->load(); - QTreeWidgetItem * item = new QTreeWidgetItem( d->listview, QStringList( ( *it )->name() ) ); - if( ! ( *it )->icon().isEmpty() ) - item->setIcon( 0, SmallIcon( ( *it )->icon(), IconSize( KIconLoader::Small ) ) ); - item->setCheckState( 0, ( *it )->isPluginEnabled() ? Qt::Checked : Qt::Unchecked ); - d->plugininfomap[ item ] = ( *it ); - } - KDialog::show(); -} - -void ComponentsDialog::executed( QTreeWidgetItem * item, int ) -{ - kDebug( 704 ) ; - if( item == 0 ) - return; - - bool checked = ( item->checkState(0) == Qt::Checked ); - - kDebug( 704 ) << "it's a " << ( checked ? "checked" : "unchecked" ) - << " QCheckListItem"; - - KPluginInfo * info = d->plugininfomap[ item ]; - info->setPluginEnabled( checked ); - //checkDependencies( info ); - // show info about the component on the right - d->iconwidget->setPixmap( SmallIcon( info->icon(), KIconLoader::SizeLarge ) ); - d->commentwidget->setText( info->comment() ); - //d->descriptionwidget->setText( info->description() ); -} - -void ComponentsDialog::savePluginInfos() -{ - for( QList::ConstIterator it = d->plugininfolist.constBegin(); - it != d->plugininfolist.constEnd(); ++it ) - { - if ((*it)->config().isValid()) { - ( *it )->save(); - (*it)->config().sync(); - } - } -} - -void ComponentsDialog::slotOk() -{ - savePluginInfos(); - KDialog::slotButtonClicked( Ok ); -} - -void ComponentsDialog::slotApply() -{ - savePluginInfos(); - KDialog::slotButtonClicked( Apply ); -} - -} //namespace - -#include "moc_componentsdialog_p.cpp" diff --git a/kutils/ksettings/componentsdialog_p.h b/kutils/ksettings/componentsdialog_p.h deleted file mode 100644 index e8da3910..00000000 --- a/kutils/ksettings/componentsdialog_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef COMPONENTSDIALOG_P_H -#define COMPONENTSDIALOG_P_H - -#include -#include - -#include - -#include -class KPluginInfo; -#include - -namespace KSettings -{ - -/** - Dialog for selecting which plugins should be active for an application. Set - the list of available plugins with \ref setPluginInfos. The dialog will save the - configuration on clicking ok or apply to the applications config file. Connect - to the okClicked() and applyClicked() signals to be notified about - configuration changes. -*/ -class KCMUTILS_EXPORT ComponentsDialog : public KDialog -{ - Q_OBJECT - public: - /** - Create Dialog. - - @param parent parent widget - @param name name - */ - explicit ComponentsDialog( QWidget * parent = 0, const char * name = 0 ); - ~ComponentsDialog(); - - /** - Add a plugin that the dialog offers for selection. - */ - void addPluginInfo( KPluginInfo * ); - /** - Set list of plugins the dialog offers for selection. (Overwrites a previous list) - */ - void setPluginInfos( const QMap & plugininfos ); - /** - Set list of plugins the dialog offers for selection. (Overwrites a previous list) - */ - void setPluginInfos( const QList &plugins ); - - /** - * reimplemented - */ - void show(); - - protected Q_SLOTS: - void slotOk(); - void slotApply(); - - private Q_SLOTS: - void executed( QTreeWidgetItem *, int ); - - private: - void savePluginInfos(); - - class ComponentsDialogPrivate; - ComponentsDialogPrivate* const d; -}; - -} - -#endif // COMPONENTSDIALOG_P_H diff --git a/kutils/ksettings/dialog.cpp b/kutils/ksettings/dialog.cpp deleted file mode 100644 index d477de03..00000000 --- a/kutils/ksettings/dialog.cpp +++ /dev/null @@ -1,562 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include "dialog.h" -#include "dialog_p.h" - -#include "dispatcher.h" -//#include "componentsdialog_p.h" - -#include "klocale.h" -#include "kservicegroup.h" -#include "kdebug.h" -#include "kservicetypetrader.h" -#include "kconfig.h" -#include "kstandarddirs.h" -#include "kcomponentdata.h" -#include "kiconloader.h" -#include "kpixmapwidget.h" - -#include -#include -#include - -uint qHash(const KCModuleInfo &info) -{ - return qHash(info.fileName()); -} - -namespace KSettings -{ - -Dialog::Dialog(QWidget *parent) - : KCMultiDialog(*new DialogPrivate, new KPageWidget, parent) -{ -} - -Dialog::Dialog(const QStringList &components, QWidget *parent) - : KCMultiDialog(*new DialogPrivate, new KPageWidget, parent) -{ - Q_D(Dialog); - d->components = components; -} - -Dialog::~Dialog() -{ -} - -void Dialog::setAllowComponentSelection(bool selection) -{ - d_func()->staticlistview = !selection; -} - -bool Dialog::allowComponentSelection() const -{ - return !d_func()->staticlistview; -} - -void Dialog::setKCMArguments(const QStringList& arguments) -{ - Q_D(Dialog); - d->arguments = arguments; -} - -void Dialog::setComponentBlacklist(const QStringList& blacklist) -{ - Q_D(Dialog); - d->componentBlacklist = blacklist; -} - -void Dialog::addPluginInfos(const KPluginInfo::List &plugininfos) -{ - Q_D(Dialog); - for (KPluginInfo::List::ConstIterator it = plugininfos.begin(); - it != plugininfos.end(); ++it ) { - d->registeredComponents.append(it->pluginName()); - if (it->kcmServices().isEmpty()) { - // this plugin has no kcm services, still we want to show the disable/enable stuff - // so add a dummy kcm - KService::Ptr service = it->service(); - d->kcmInfos << KCModuleInfo(service); - continue; - } - foreach (const KService::Ptr &service, it->kcmServices()) { - d->kcmInfos << KCModuleInfo(service); - } - } - - // The plugin, when disabled, disables all the KCMs described by kcmServices(). - // - Normally they are grouped using a .setdlg file so that the group parent can get a - // checkbox to enable/disable the plugin. - // - If the plugin does not belong to a group and has only one KCM the checkbox can be - // used with this KCM. - // - If the plugin belongs to a group but there are other modules in the group that do not - // belong to this plugin we give a kError and show no checkbox - // - If the plugin belongs to multiple groups we give a kError and show no checkbox - d->plugininfos = plugininfos; -} - -KPluginInfo::List Dialog::pluginInfos() const -{ - return d_func()->plugininfos; -} - -void Dialog::showEvent(QShowEvent *) -{ - Q_D(Dialog); - if (d->firstshow) { - setUpdatesEnabled(false); - d->kcmInfos += d->instanceServices(); - if (!d->components.isEmpty()) { - d->kcmInfos += d->parentComponentsServices(d->components); - } - d->createDialogFromServices(); - d->firstshow = false; - setUpdatesEnabled(true); - } - Dispatcher::syncConfiguration(); -} - -DialogPrivate::DialogPrivate() - : staticlistview(true), firstshow(true), pluginStateDirty(0) -{ -} - -QSet DialogPrivate::instanceServices() -{ - //kDebug(700) ; - QString componentName = KGlobal::mainComponent().componentName(); - registeredComponents.append(componentName); - //kDebug(700) << "calling KServiceGroup::childGroup( " << componentName << " )"; - KServiceGroup::Ptr service = KServiceGroup::childGroup( componentName ); - - QSet ret; - - if( service && service->isValid() ) - { - //kDebug(700) << "call was successful"; - const KServiceGroup::List list = service->entries(); - for( KServiceGroup::List::ConstIterator it = list.begin(); - it != list.end(); ++it ) - { - KSycocaEntry::Ptr p = (*it); - if( p->isType( KST_KService ) ) - { - //kDebug( 700 ) << "found service"; - ret << KCModuleInfo(KService::Ptr::staticCast(p)); - } - else - kWarning( 700 ) << "KServiceGroup::childGroup returned" - " something else than a KService"; - } - } - - return ret; -} - -QSet DialogPrivate::parentComponentsServices(const QStringList &kcdparents) -{ - registeredComponents += kcdparents; - QString constraint = kcdparents.join("' in [X-KDE-ParentComponents]) or ('"); - constraint = "('" + constraint + "' in [X-KDE-ParentComponents])"; - - //kDebug(700) << "constraint = " << constraint; - const QList services = KServiceTypeTrader::self()->query("KCModule", constraint); - QSet ret; - foreach (const KService::Ptr &service, services) { - ret << KCModuleInfo(service); - } - return ret; -} - -bool DialogPrivate::isPluginForKCMEnabled(const KCModuleInfo *moduleinfo, KPluginInfo &pinfo) const -{ - // if the user of this class requested to hide disabled modules - // we check whether it should be enabled or not - bool enabled = true; - //kDebug(700) << "check whether the '" << moduleinfo->moduleName() << "' KCM should be shown"; - // for all parent components - const QStringList parentComponents = moduleinfo->service()->property( - "X-KDE-ParentComponents" ).toStringList(); - for( QStringList::ConstIterator pcit = parentComponents.begin(); - pcit != parentComponents.end(); ++pcit ) - { - // if the parentComponent is not registered ignore it - if (!registeredComponents.contains(*pcit)) { - continue; - } - - // we check if the parent component is a plugin - // if not the KCModule must be enabled - enabled = true; - if (pinfo.pluginName() == *pcit) { - // it is a plugin: we check whether the plugin is enabled - pinfo.load(); - enabled = pinfo.isPluginEnabled(); - //kDebug(700) << "parent " << *pcit << " is " << (enabled ? "enabled" : "disabled"); - } - // if it is enabled we're done for this KCModuleInfo - if (enabled) { - return true; - } - } - return enabled; -} - -bool DialogPrivate::isPluginImmutable(const KPluginInfo &pinfo) const -{ - return pinfo.property("X-KDE-PluginInfo-Immutable").toBool(); -} - -KPageWidgetItem *DialogPrivate::createPageItem(KPageWidgetItem *parentItem, - const QString &name, const QString &comment, - const QString &iconName, int weight) -{ - Q_Q(Dialog); - QWidget * page = new QWidget( q ); - - QCheckBox *checkBox = new QCheckBox(i18n("Enable component"), page); - KPixmapWidget *iconWidget = new KPixmapWidget(page); - QLabel *commentLabel = new QLabel(comment, page); - commentLabel->setTextFormat(Qt::RichText); - QVBoxLayout * layout = new QVBoxLayout(page); - layout->addWidget(checkBox); - layout->addWidget(iconWidget); - layout->addWidget(commentLabel); - layout->addStretch(); - page->setLayout(layout); - - KPageWidgetItem *item = new KPageWidgetItem(page, name); - item->setIcon(KIcon(iconName)); - iconWidget->setPixmap(item->icon().pixmap(128, 128)); - item->setProperty("_k_weight", weight); - checkBoxForItem.insert(item, checkBox); - - const KPageWidgetModel *model = qobject_cast(q->pageWidget()->model()); - Q_ASSERT(model); - - if (parentItem) { - const QModelIndex parentIndex = model->index(parentItem); - const int siblingCount = model->rowCount(parentIndex); - int row = 0; - for (; row < siblingCount; ++row) { - KPageWidgetItem *siblingItem = model->item(parentIndex.child(row, 0)); - if (siblingItem->property("_k_weight").toInt() > weight) { - // the item we found is heavier than the new module - q->insertPage(siblingItem, item); - break; - } - } - if (row == siblingCount) { - // the new module is either the first or the heaviest item - q->addSubPage(parentItem, item); - } - } else { - const int siblingCount = model->rowCount(); - int row = 0; - for (; row < siblingCount; ++row) { - KPageWidgetItem *siblingItem = model->item(model->index(row, 0)); - if (siblingItem->property("_k_weight").toInt() > weight) { - // the item we found is heavier than the new module - q->insertPage(siblingItem, item); - break; - } - } - if (row == siblingCount) { - // the new module is either the first or the heaviest item - q->addPage(item); - } - } - - return (item); -} - -void DialogPrivate::parseGroupFile( const QString & filename ) -{ - KConfig file( filename, KConfig::SimpleConfig ); - const QStringList groups = file.groupList(); - foreach (const QString &group, groups) { - if (group.isEmpty()) { - continue; - } - KConfigGroup conf(&file, group); - - const QString parentId = conf.readEntry("Parent"); - KPageWidgetItem *parentItem = pageItemForGroupId.value(parentId); - KPageWidgetItem *item = createPageItem(parentItem, conf.readEntry("Name"), conf.readEntry("Comment"), - conf.readEntry("Icon"), conf.readEntry("Weight", 100)); - pageItemForGroupId.insert(group, item); - } -} - -void DialogPrivate::createDialogFromServices() -{ - Q_Q(Dialog); - // read .setdlg files - QString setdlgpath = KStandardDirs::locate( "appdata", KGlobal::mainComponent().componentName() + ".setdlg" ); - const QStringList setdlgaddon = KGlobal::dirs()->findAllResources( "appdata", "ksettingsdialog/*.setdlg" ); - if (!setdlgpath.isNull()) { - parseGroupFile(setdlgpath); - } - if (setdlgaddon.size() > 0) { - for (QStringList::ConstIterator it = setdlgaddon.begin(); it != setdlgaddon.end(); ++it) { - parseGroupFile(*it); - } - } - - //kDebug(700) << kcmInfos.count(); - foreach (const KCModuleInfo &info, kcmInfos) { - const QStringList parentComponents = info.service()->property("X-KDE-ParentComponents").toStringList(); - bool blacklisted = false; - foreach (const QString &parentComponent, parentComponents) { - if (componentBlacklist.contains(parentComponent)) { - blacklisted = true; - break; - } - } - if (blacklisted) { - continue; - } - const QString parentId = info.service()->property("X-KDE-CfgDlgHierarchy", QVariant::String).toString(); - KPageWidgetItem *parent = pageItemForGroupId.value(parentId); - if (!parent) { - // dummy kcm - bool foundPlugin = false; - foreach (const KPluginInfo &pinfo, plugininfos) { - if (pinfo.service() == info.service()) { - if (!pinfo.kcmServices().count()) { - const KService::Ptr service = info.service(); - // FIXME get weight from service or plugin info - const int weight = 1000; - KPageWidgetItem *item = createPageItem(0, service->name(), service->comment(), service->icon(), weight); - connectItemCheckBox(item, pinfo, pinfo.isPluginEnabled()); - foundPlugin = true; - break; - } - } - } - if (foundPlugin) { - continue; - } - } - KPageWidgetItem *item = q->addModule(info, parent, arguments); - kDebug(700) << "added KCM '" << info.moduleName() << "'"; - foreach (KPluginInfo pinfo, plugininfos) { - kDebug(700) << pinfo.pluginName(); - if (pinfo.kcmServices().contains(info.service())) { - const bool isEnabled = isPluginForKCMEnabled(&info, pinfo); - kDebug(700) << "correct KPluginInfo for this KCM"; - // this KCM belongs to a plugin - if (parent && pinfo.kcmServices().count() >= 1) { - item->setEnabled(isEnabled); - const KPluginInfo &plugin = pluginForItem.value(parent); - if (plugin.isValid()) { - if (plugin != pinfo) { - kError(700) << "A group contains more than one plugin: '" - << plugin.pluginName() << "' and '" << pinfo.pluginName() - << "'. Now it won't be possible to enable/disable the plugin."; - parent->setCheckable(false); - q->disconnect(parent, SIGNAL(toggled(bool)), q, SLOT(_k_updateEnabledState(bool))); - } - // else everything is fine - } else { - connectItemCheckBox(parent, pinfo, isEnabled); - } - } else { - pluginForItem.insert(item, pinfo); - item->setCheckable(!isPluginImmutable(pinfo)); - item->setChecked(isEnabled); - q->connect(item, SIGNAL(toggled(bool)), q, SLOT(_k_updateEnabledState(bool))); - } - break; - } - } - } - // now that the KCMs are in, check for empty groups and remove them again - { - const KPageWidgetModel *model = qobject_cast(q->pageWidget()->model()); - const QHash::ConstIterator end = pageItemForGroupId.constEnd(); - QHash::ConstIterator it = pageItemForGroupId.constBegin(); - for (; it != end; ++it) { - const QModelIndex index = model->index(it.value()); - KPluginInfo pinfo; - foreach (const KPluginInfo &p, plugininfos) { - if (p.name()==it.key()) { - pinfo = p; - break; - } - } - bool allowEmpty = false; - if (pinfo.isValid()) { - allowEmpty = pinfo.property("X-KDE-PluginInfo-AllowEmptySettings").toBool(); - } - - if (!index.child(0, 0).isValid()) { - // no children, and it's not allowed => remove this item - if (!allowEmpty) { - q->removePage(it.value()); - } else { - connectItemCheckBox(it.value(), pinfo, pinfo.isPluginEnabled()); - } - } - } - } - - // TODO: Don't show the reset button until the issue with the - // KPluginSelector::load() method is solved. - // Problem: - // KCMultiDialog::show() call KCModule::load() to reset all KCMs - // (KPluginSelector::load() resets all plugin selections and all plugin - // KCMs). - // The reset button calls KCModule::load(), too but in this case we want the - // KPluginSelector to only reset the current visible plugin KCM and not - // touch the plugin selections. - // I have no idea how to check that in KPluginSelector::load()... - //q->showButton(KDialog::User1, true); - - QObject::connect(q, SIGNAL(okClicked()), q, SLOT(_k_syncConfiguration())); - QObject::connect(q, SIGNAL(applyClicked()), q, SLOT(_k_syncConfiguration())); - QObject::connect(q, SIGNAL(configCommitted(QByteArray)), q, - SLOT(_k_reparseConfiguration(QByteArray))); -} - -void DialogPrivate::connectItemCheckBox(KPageWidgetItem *item, const KPluginInfo &pinfo, bool isEnabled) -{ - Q_Q(Dialog); - QCheckBox *checkBox = checkBoxForItem.value(item); - Q_ASSERT(checkBox); - pluginForItem.insert(item, pinfo); - item->setCheckable(!isPluginImmutable(pinfo)); - item->setChecked(isEnabled); - checkBox->setVisible(!isPluginImmutable(pinfo)); - checkBox->setChecked(isEnabled); - q->connect(item, SIGNAL(toggled(bool)), q, SLOT(_k_updateEnabledState(bool))); - q->connect(item, SIGNAL(toggled(bool)), checkBox, SLOT(setChecked(bool))); - q->connect(checkBox, SIGNAL(clicked(bool)), item, SLOT(setChecked(bool))); -} - -void DialogPrivate::_k_syncConfiguration() -{ - Q_Q(Dialog); - const QHash::Iterator endIt = pluginForItem.end(); - QHash::Iterator it = pluginForItem.begin(); - for (; it != endIt; ++it) { - KPageWidgetItem *item = it.key(); - KPluginInfo pinfo = it.value(); - pinfo.setPluginEnabled(item->isChecked()); - pinfo.save(); - } - if (pluginStateDirty > 0) { - emit q->pluginSelectionChanged(); - pluginStateDirty = 0; - } - Dispatcher::syncConfiguration(); -} - -void DialogPrivate::_k_reparseConfiguration(const QByteArray &a) -{ - Dispatcher::reparseConfiguration(a); -} - -/* -void DialogPrivate::_k_configureTree() -{ - kDebug( 700 ) ; - QObject::connect(subdlg, SIGNAL(okClicked()), q, SLOT(_k_updateTreeList())); - QObject::connect(subdlg, SIGNAL(applyClicked()), q, SLOT(_k_updateTreeList())); - QObject::connect(subdlg, SIGNAL(okClicked()), q, SIGNAL(pluginSelectionChanged())); - QObject::connect(subdlg, SIGNAL(applyClicked()), q, SIGNAL(pluginSelectionChanged())); -} -*/ - -void DialogPrivate::_k_clientChanged() -{ - if (pluginStateDirty > 0) { - Q_Q(Dialog); - q->enableButton(KDialog::Apply, true); - } else { - KCMultiDialogPrivate::_k_clientChanged(); - } -} - -void DialogPrivate::_k_updateEnabledState(bool enabled) -{ - Q_Q(Dialog); - KPageWidgetItem *item = qobject_cast(q->sender()); - if (!item) { - kWarning(700) << "invalid sender"; - return; - } - - // iterate over all child KPageWidgetItem objects and check whether they need to be enabled/disabled - const KPageWidgetModel *model = qobject_cast(q->pageWidget()->model()); - Q_ASSERT(model); - QModelIndex index = model->index(item); - if (!index.isValid()) { - kWarning(700) << "could not find item in model"; - return; - } - - const KPluginInfo &pinfo = pluginForItem.value(item); - if (!pinfo.isValid()) { - kWarning(700) << "could not find KPluginInfo in item"; - return; - } - if (pinfo.isPluginEnabled() != enabled) { - ++pluginStateDirty; - } else { - --pluginStateDirty; - } - if (pluginStateDirty < 2) { - _k_clientChanged(); - } - - //kDebug(700) ; - - QModelIndex firstborn = index.child(0, 0); - if (firstborn.isValid()) { - //kDebug(700) << "iterating over children"; - // change all children - index = firstborn; - QStack stack; - while (index.isValid()) { - //kDebug(700) << index; - KPageWidgetItem *item = model->item(index); - //kDebug(700) << "item->setEnabled(" << enabled << ')'; - item->setEnabled(enabled); - firstborn = index.child(0, 0); - if (firstborn.isValid()) { - stack.push(index); - index = firstborn; - } else { - index = index.sibling(index.row() + 1, 0); - while (!index.isValid() && !stack.isEmpty()) { - index = stack.pop(); - index = index.sibling(index.row() + 1, 0); - } - } - } - } -} - -} //namespace - -#include "moc_dialog.cpp" - -// vim: ts=4 diff --git a/kutils/ksettings/dialog.h b/kutils/ksettings/dialog.h deleted file mode 100644 index 0765cc2a..00000000 --- a/kutils/ksettings/dialog.h +++ /dev/null @@ -1,184 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef KSETTINGS_DIALOG_H -#define KSETTINGS_DIALOG_H - -#include "kcmutils_export.h" -#include "../kcmultidialog.h" - -#include -#include - -#include -class KPluginInfo; -class KCModuleInfo; - -namespace KSettings -{ - class DialogPrivate; - -/** - * @short Generic configuration dialog that works over component boundaries - * - * For more information see \ref KSettings. - * - * This class aims to standardize the use of configuration dialogs in KDE - * applications. Especially when using KParts and/or Plugins you face problems - * creating a consistent config dialog. - * - * To show a configuration dialog you only have to call the show method and be - * done with it. A code example: - * - * You initialize \p m_cfgdlg with - * \code - * m_cfgdlg = new Dialog( this ); - * \endcode - * If you use a KPart that was not especially designed for your app you can use - * the second constructor: - * \code - * QStringList kpartslist; - * for( all my kparts ) - * kpartslist += m_mypart->componentData().componentName(); - * m_cfgdlg = new Dialog( kpartslist, this ); - * \endcode - * and the action for the config dialog is connected to the show slot: - * \code - * KStandardAction::preferences( m_cfgdlg, SLOT( show() ), actionCollection() ); - * \endcode - * - * If you need to be informed when the config was changed and applied in the - * dialog you might want to take a look at Dispatcher. - * - * For more information see \ref KSettings. - * - * @author Matthias Kretz - */ -class KCMUTILS_EXPORT Dialog : public KCMultiDialog -{ - friend class PageNode; - Q_DECLARE_PRIVATE(Dialog) - Q_OBJECT - public: - /** - * Construct a new Preferences Dialog for the application. It uses all - * KCMs with X-KDE-ParentApp set to KGlobal::mainComponent().componentName(). - * - * @param content Select whether you want a static or configurable - * config dialog. - * @param parent The parent is only used as the parent for the - * dialog - centering the dialog over the parent - * widget. - */ - explicit Dialog(QWidget * parent = 0); - - /** - * Construct a new Preferences Dialog with the pages for the selected - * instance names. For example if you want to have the configuration - * pages for the kviewviewer KPart you would pass a - * QStringList consisting of only the name of the part "kviewviewer". - * - * @param components A list of the names of the components that your - * config dialog should merge the config pages in. - * @param parent The parent is only used as the parent for the - * dialog - centering the dialog over the parent - * widget. - */ - explicit Dialog(const QStringList & components, QWidget * parent = 0); - - ~Dialog(); - - /** - * If you use a Configurable dialog you need to pass KPluginInfo - * objects that the dialog should configure. - */ - void addPluginInfos(const QList &plugininfos); - - /** - * Sets the argument list that is given to all the KControlModule's when - * they are created. - * Use this if you have KControlModule's that need special arguments to - * work - * - * Note that this function only works before showing the - * KSettings::Dialog for the first time. - * @param arguments The list of arguments passed to each KCM - */ - void setKCMArguments(const QStringList& arguments); - - /** - * Set the blacklisted component list. Any KCM that lists one - * of the components in the given blacklist is not loaded even if it - * would fit otherwise. This is a way to explicitly prevent loading of - * certain KControlModules. - * - * Note that this function only works before showing the - * KSettings::Dialog for the first time. - * @param blacklist the list of components that prevent a KCM from being - * loaded - */ - void setComponentBlacklist(const QStringList& blacklist); - - /** - * Tells the dialog whether the entries in the listview are all static - * or whether it should add checkboxes to select which parts - * of the optional functionality should be active or not. - * - * Note that this function only works before showing the dialog for the first time. - * - * Defaults to \p false. - * - * @param allowSelection \p true The user can select what functionality he wants. - * @param allowSelection \p false While running no entries are added or deleted - */ - void setAllowComponentSelection(bool allowSelection); - - bool allowComponentSelection() const; - - /** - * Returns a list of all KPluginInfo objects the dialog uses. - */ - QList pluginInfos() const; - - protected: - /** - * Reimplemented to lazy create the dialog on first show. - */ - void showEvent(QShowEvent *); - - Q_SIGNALS: - /** - * If you use the dialog in Configurable mode and want to be notified - * when the user changes the plugin selections use this signal. It's - * emitted if the selection has changed and the user pressed Apply or - * Ok. In the slot you would then load and unload the plugins as - * requested. - */ - void pluginSelectionChanged(); - - private: - //Q_PRIVATE_SLOT(d_func(), void _k_configureTree()) - Q_PRIVATE_SLOT(d_func(), void _k_updateEnabledState(bool)) - Q_PRIVATE_SLOT(d_func(), void _k_syncConfiguration()) - Q_PRIVATE_SLOT(d_func(), void _k_reparseConfiguration(const QByteArray &)) -}; - -} - -#endif // KSETTINGS_DIALOG_H diff --git a/kutils/ksettings/dialog_p.h b/kutils/ksettings/dialog_p.h deleted file mode 100644 index 9a9bc86f..00000000 --- a/kutils/ksettings/dialog_p.h +++ /dev/null @@ -1,112 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2007 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef KSETTINGS_DIALOG_P_H -#define KSETTINGS_DIALOG_P_H - -#include "dialog.h" -#include "../kcmultidialog_p.h" -#include "../kcmoduleinfo.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -namespace KSettings -{ - -class DialogPrivate : public KCMultiDialogPrivate -{ - friend class PageNode; - Q_DECLARE_PUBLIC(Dialog) - protected: - DialogPrivate(); - - QHash pageItemForGroupId; - QHash pluginForItem; - QHash checkBoxForItem; - KPluginInfo::List plugininfos; - - QStringList registeredComponents; - QSet kcmInfos; - QStringList componentBlacklist; - QStringList arguments; - QStringList components; - - bool staticlistview : 1; - bool firstshow : 1; - quint32 pluginStateDirty : 30; - - //void _k_configureTree(); - void _k_updateEnabledState(bool); - void _k_syncConfiguration(); - void _k_reparseConfiguration(const QByteArray &a); - virtual void _k_clientChanged(); - - KPageWidgetItem *createPageItem(KPageWidgetItem *parentItem, - const QString &name, const QString &comment, - const QString &iconName, int weight); - - void connectItemCheckBox(KPageWidgetItem *item, const KPluginInfo &pinfo, - bool isEnabled); - - private: - /** - * @internal - * Check whether the plugin associated with this KCM is enabled. - */ - bool isPluginForKCMEnabled(const KCModuleInfo *moduleinfo, KPluginInfo &pinfo) const; - bool isPluginImmutable(const KPluginInfo &pinfo) const; - - QSet instanceServices(); - QSet parentComponentsServices(const QStringList &); - - /** - * @internal - * Read the .setdlg file and add it to the groupmap - */ - void parseGroupFile(const QString &); - - /** - * @internal - * If this module is put into a TreeList hierarchy this will return a - * list of the names of the parent modules. - */ - //QStringList parentModuleNames(KCModuleInfo *); - - /** - * @internal - * This method is called only once. The KCMultiDialog is not created - * until it's really needed. So if some method needs to access d->dlg it - * checks for 0 and if it's not created this method will do it. - */ - void createDialogFromServices(); -}; - -} // namespace KSettings -#endif // KSETTINGS_DIALOG_P_H diff --git a/kutils/ksettings/dispatcher.cpp b/kutils/ksettings/dispatcher.cpp deleted file mode 100644 index a56c4c47..00000000 --- a/kutils/ksettings/dispatcher.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include "dispatcher.h" -#include "dispatcher_p.h" - -#include -#include -#include -#include -#include - -namespace KSettings -{ - -namespace Dispatcher -{ - -K_GLOBAL_STATIC(DispatcherPrivate, d) - -void registerComponent(const KComponentData &componentData, QObject *recv, const char *slot) -{ - Q_ASSERT(componentData.isValid()); - // keep the KComponentData around and call - // componentData.config()->reparseConfiguration when the app should reparse - QString componentName = componentData.componentName(); - kDebug(701) << componentName; - d->m_componentName[recv] = componentName; - if (!d->m_componentInfo.contains(componentName)) { - d->m_componentInfo[componentName].componentData = componentData; - } - d->m_componentInfo[componentName].slotList.append(ComponentInfo::Slot(recv, slot)); - - ++(d->m_componentInfo[componentName].count); - QObject::connect(recv, SIGNAL(destroyed(QObject*)), d, SLOT(unregisterComponent(QObject*))); -} - -KSharedConfig::Ptr configForComponentName(const QString &componentName) -{ - kDebug(701) ; - if (d->m_componentInfo.contains(componentName)) { - KComponentData componentData = d->m_componentInfo[componentName].componentData; - if (componentData.isValid()) { - return componentData.config(); - } - } - kError(701) << "configForComponentName('" << componentName.constData() - << "') could not find the KComponentData object"; - Q_ASSERT(!d->m_componentInfo.isEmpty()); - return d->m_componentInfo.constBegin()->componentData.config(); -} - -QList componentNames() -{ - kDebug(701) ; - QList names; - for (QMap::ConstIterator it = d->m_componentInfo.constBegin(); it != d->m_componentInfo.constEnd(); ++it) { - if ((*it).count > 0) { - names.append(it.key()); - } - } - return names; -} - -void reparseConfiguration(const QString & componentName) -{ - kDebug(701) << componentName; - // check if the componentName is valid: - if (! d->m_componentInfo.contains(componentName)) { - return; - } - // first we reparse the config of the componentData so that the KConfig object - // will be up to date - KSharedConfig::Ptr config = d->m_componentInfo[componentName].componentData.config(); - config->reparseConfiguration(); - foreach(const ComponentInfo::Slot& slot, d->m_componentInfo[componentName].slotList ) { - QMetaObject::invokeMethod(slot.first, slot.second); - } -} - -void syncConfiguration() -{ - for (QMap::ConstIterator it = d->m_componentInfo.constBegin(); it != d->m_componentInfo.constEnd(); ++it) { - KSharedConfig::Ptr config = (*it).componentData.config(); - config->sync(); - } -} - -void DispatcherPrivate::unregisterComponent(QObject *obj) -{ - if (!m_componentName.contains(obj)) { - kWarning(701) << "Tried to unregister an object which is not already registered."; - return; - } - - QString name = m_componentName[obj]; - m_componentName.remove(obj); //obj will be destroyed when we return, so we better remove this entry - --(m_componentInfo[name].count); - kDebug(701) << "componentName=" << name << "refcount=" << m_componentInfo[name].count; - Q_ASSERT(m_componentInfo[name].count >= 0); - if (m_componentInfo[name].count == 0) { - m_componentInfo.remove(name); - } -} - -} // namespace Dispatcher -} // namespace KSettings - -#include "moc_dispatcher_p.cpp" diff --git a/kutils/ksettings/dispatcher.h b/kutils/ksettings/dispatcher.h deleted file mode 100644 index 39dc3965..00000000 --- a/kutils/ksettings/dispatcher.h +++ /dev/null @@ -1,87 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef KSETTINGS_DISPATCHER_H -#define KSETTINGS_DISPATCHER_H - -#include -#include -#include -#include - -namespace KSettings -{ - -/** - * @short Dispatch change notifications from the KCMs to the program. - * - * Since your program does not have direct control over the KCMs that get loaded - * into KSettings::Dialog you need a way to get notified. This is what you do: - * \code - * Dispatcher::registerComponent(componentData(), this, "loadSettings"); - * \endcode - * - * @author Matthias Kretz - */ -namespace Dispatcher -{ - /** - * Register a slot to be called when the configuration for the componentData - * has changed. @p componentData is the KComponentData object - * that is passed to KPluginFactory (if it is used). You can query - * it with MyPluginFactory::componentData(). - * componentData.componentName() is also the same name that is put into the - * .desktop file of the KCMs for the X-KDE-ParentComponents. - * - * @param componentData The KComponentData object - * @param recv The object that should receive the signal - * @param slot The slot to be called: "slotName" - */ - KCMUTILS_EXPORT void registerComponent(const KComponentData &componentData, QObject *recv, const char *slot); - - /** - * @return the KConfig object that belongs to the componentName - */ - KCMUTILS_EXPORT KSharedConfig::Ptr configForComponentName(const QString &componentName); - - /** - * @return a list of all the componentData names that are currently - * registered - */ - KCMUTILS_EXPORT QList componentNames(); - - /** - * Call this function when the configuration belonging to the associated - * componentData name has changed. The registered slot will be called. - * - * @param componentName The value of X-KDE-ParentComponents. - */ - KCMUTILS_EXPORT void reparseConfiguration(const QString &componentName); - - /** - * When this function is called the KConfig objects of all the registered - * instances are sync()ed. This is useful when some other KConfig - * objects will read/write from/to the same config file, so that you - * can first write out the current state of the KConfig objects. - */ - KCMUTILS_EXPORT void syncConfiguration(); -} // namespace Dispatcher - -} -#endif // KSETTINGS_DISPATCHER_H diff --git a/kutils/ksettings/dispatcher_p.h b/kutils/ksettings/dispatcher_p.h deleted file mode 100644 index 0a7d6046..00000000 --- a/kutils/ksettings/dispatcher_p.h +++ /dev/null @@ -1,59 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2007 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef DISPATCHER_P_H -#define DISPATCHER_P_H - -#include -#include -#include -#include - -#include - -namespace KSettings -{ -namespace Dispatcher -{ - -class ComponentInfo -{ -public: - KComponentData componentData; - typedef QPair Slot; - QList slotList; - int count; - - ComponentInfo() : count(0) {} -}; - -class DispatcherPrivate : public QObject -{ - Q_OBJECT - public: - QMap m_componentInfo; - QMap m_componentName; - - public Q_SLOTS: - void unregisterComponent(QObject *); -}; - -} // namespace Dispatcher -} // namespace KSettings -#endif // DISPATCHER_P_H diff --git a/kutils/ksettings/pluginpage.cpp b/kutils/ksettings/pluginpage.cpp deleted file mode 100644 index 7200fb93..00000000 --- a/kutils/ksettings/pluginpage.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#include "ksettings/pluginpage.h" -#include "kpluginselector.h" -#include -#include -#include "ksettings/dispatcher.h" -#include - -namespace KSettings -{ - -class PluginPagePrivate -{ - public: - PluginPagePrivate() - : selwid( 0 ) - { - } - - KPluginSelector * selwid; - void _k_reparseConfiguration(const QByteArray &a); -}; - -PluginPage::PluginPage(const KComponentData &componentData, QWidget *parent, const QVariantList &args) - : KCModule(componentData, parent, args), - d_ptr(new PluginPagePrivate) -{ - Q_D(PluginPage); - //d->q_ptr = this; -// ( new QVBoxLayout( this, 0, KDialog::spacingHint() ) )->setAutoAdd( true ); - d->selwid = new KPluginSelector( this ); - connect( d->selwid, SIGNAL(changed(bool)), this, SIGNAL(changed(bool)) ); - connect(d->selwid, SIGNAL(configCommitted(QByteArray)), this, - SLOT(_k_reparseConfiguration(QByteArray))); -} - -void PluginPagePrivate::_k_reparseConfiguration(const QByteArray &a) -{ - Dispatcher::reparseConfiguration(a); -} - -PluginPage::~PluginPage() -{ - delete d_ptr; -} - -KPluginSelector * PluginPage::pluginSelector() -{ - return d_ptr->selwid; -} - -void PluginPage::load() -{ - d_ptr->selwid->load(); -} - -void PluginPage::save() -{ - d_ptr->selwid->save(); -} - -void PluginPage::defaults() -{ - d_ptr->selwid->defaults(); -} - -} //namespace - -#include "moc_pluginpage.cpp" diff --git a/kutils/ksettings/pluginpage.h b/kutils/ksettings/pluginpage.h deleted file mode 100644 index 3c3d62b0..00000000 --- a/kutils/ksettings/pluginpage.h +++ /dev/null @@ -1,115 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2003 Matthias Kretz - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - -*/ - -#ifndef KSETTINGS_PLUGINPAGE_H -#define KSETTINGS_PLUGINPAGE_H - -#include -#include - -class KPluginSelector; - -namespace KSettings -{ - class PluginPagePrivate; - -/** - * @short Convenience KCModule for creating a plugins config page. - * - * This class makes it very easy to create a plugins configuration page to your - * program. All you need to do is create a class that is derived from - * PluginPage and add the appropriate plugin information to the KPluginSelector. - * This is done using the pluginSelector() method: - * \code - * K_PLUGIN_FACTORY(MyAppPluginConfigFactory, - * registerPlugin(); - * ) - * K_EXPORT_PLUGIN(MyAppConfigFactory("kcm_myapppluginconfig")); - * - * MyAppPluginConfig(QWidget * parent, const QVariantList & args) - * : PluginPage(MyAppPluginConfigFactory::componentData(), parent, args) - * { - * pluginSelector()->addPlugins( KGlobal::mainComponent().componentName(), i18n( "General Plugins" ), "General" ); - * pluginSelector()->addPlugins( KGlobal::mainComponent().componentName(), i18n( "Effects" ), "Effects" ); - * } - * \endcode - * - * All that remains to be done is to create the appropriate .desktop file - * \verbatim - [Desktop Entry] - Encoding=UTF-8 - Icon=plugin - Type=Service - ServiceTypes=KCModule - - X-KDE-Library=myapppluginconfig - X-KDE-ParentApp=myapp - X-KDE-ParentComponents=myapp - - Name=Plugins - Comment=Select and configure your plugins: - \endverbatim - * - * @author Matthias Kretz - */ -class KCMUTILS_EXPORT PluginPage : public KCModule -{ - Q_OBJECT - Q_DECLARE_PRIVATE(PluginPage) - public: - /** - * Standard KCModule constructor. - * Automatically creates the KPluginSelector widget. - */ - explicit PluginPage( const KComponentData &componentData, - QWidget *parent = 0, - const QVariantList &args = QVariantList() ); - - ~PluginPage(); - - /** - * @return a reference to the KPluginSelector. - */ - KPluginSelector * pluginSelector(); - - /** - * Load the state of the plugins (selected or not) from the KPluginInfo - * objects. For KParts plugins everything should work automatically. For - * your own type of plugins you might need to reimplement the - * KPluginInfo::pluginLoaded() method. If that doesn't fit your needs - * you can also reimplement this method. - */ - virtual void load(); - - /** - * Save the state of the plugins to KConfig objects - */ - virtual void save(); - virtual void defaults(); - - protected: - PluginPagePrivate *const d_ptr; - - private: - Q_PRIVATE_SLOT(d_func(), void _k_reparseConfiguration(const QByteArray &a)) -}; - -} - -#endif // KSETTINGS_PLUGINPAGE_H