1 /* This file is part of the KDE libraries
2 Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "kcmodulecontainer.h"
21 #include "kcmodulecontainer.moc"
23 #include <QtGui/QLayout>
24 #include <QtGui/QPixmap>
25 #include <QtCore/QStringList>
28 #include <kcmoduleinfo.h>
29 #include <kcmoduleloader.h>
30 #include <kcmoduleproxy.h>
36 #include <kiconloader.h>
37 #include <kpushbutton.h>
39 #include <kstandardguiitem.h>
40 #include <ktabwidget.h>
42 /***********************************************************************/
43 class KCModuleContainer::KCModuleContainerPrivate
46 KCModuleContainerPrivate( const QStringList
& mods
)
53 KTabWidget
*tabWidget
;
54 KCModule::Buttons buttons
;
55 QVBoxLayout
*topLayout
;
59 /***********************************************************************/
63 // The KCModuleContainer is only a wrapper around real KCModules. Therefore it doesn't need a
64 // special KComponentData and can just use the global instance. The contained KCModules create their own
65 // KComponentData objects when needed.
66 /***********************************************************************/
67 KCModuleContainer::KCModuleContainer( QWidget
* parent
, const QString
& mods
)
68 : KCModule( KGlobal::mainComponent(), parent
),d(new KCModuleContainerPrivate( QString(mods
).remove( ' ' ).split( ',' ) ))
73 KCModuleContainer::KCModuleContainer( QWidget
* parent
, const QStringList
& mods
)
74 : KCModule( KGlobal::mainComponent(), parent
), d( new KCModuleContainerPrivate( mods
) )
79 void KCModuleContainer::init()
81 d
->topLayout
= new QVBoxLayout( this );
82 d
->topLayout
->setMargin( 0 );
83 d
->topLayout
->setSpacing( KDialog::spacingHint() );
84 d
->topLayout
->setObjectName( "topLayout" );
85 d
->tabWidget
= new KTabWidget(this);
86 d
->tabWidget
->setObjectName( "tabWidget");
87 connect( d
->tabWidget
, SIGNAL( currentChanged( QWidget
* ) ), SLOT( tabSwitched( QWidget
* ) ));
88 d
->topLayout
->addWidget( d
->tabWidget
);
90 if ( !d
->modules
.isEmpty() )
93 for ( QStringList::const_iterator it
= d
->modules
.constBegin(); it
!= d
->modules
.constEnd(); ++it
)
98 void KCModuleContainer::addModule( const QString
& module
)
100 /* In case it doesn't exist we just silently drop it.
101 * This allows people to easily extend containers.
102 * For example, KCM monitor gamma can be in kdegraphics.
104 KService::Ptr service
= KService::serviceByDesktopName( module
);
107 kDebug(713) << "KCModuleContainer: module '" <<
108 module
<< "' was not found and thus not loaded" << endl
;
112 if ( service
->noDisplay() )
115 KCModuleProxy
* proxy
= new KCModuleProxy( service
, d
->tabWidget
);
116 allModules
.append( proxy
);
118 proxy
->setObjectName( module
.toLatin1() );
120 d
->tabWidget
->addTab( proxy
, KIcon( proxy
->moduleInfo().icon() ),
121 /* Qt eats ampersands for dinner. But not this time. */
122 proxy
->moduleInfo().moduleName().replace( '&', "&&" ));
124 d
->tabWidget
->setTabToolTip( d
->tabWidget
->indexOf( proxy
), proxy
->moduleInfo().comment() );
126 connect( proxy
, SIGNAL(changed(KCModuleProxy
*)), SLOT(moduleChanged(KCModuleProxy
*)));
128 /* Collect our buttons - we go for the common deliminator */
129 setButtons( buttons() | proxy
->realModule()->buttons() );
132 void KCModuleContainer::tabSwitched( QWidget
* module
)
134 KCModuleProxy
* mod
= (KCModuleProxy
*) module
;
135 setQuickHelp( mod
->quickHelp() );
136 setAboutData( mod
->aboutData() );
139 void KCModuleContainer::save()
141 ModuleList list
= changedModules
;
142 ModuleList::iterator it
;
143 for ( it
= list
.begin() ; it
!=list
.end() ; ++it
)
148 emit
changed( false );
152 void KCModuleContainer::load()
154 ModuleList list
= allModules
;
155 ModuleList::iterator it
;
156 for ( it
= list
.begin() ; it
!=list
.end() ; ++it
)
161 emit
changed( false );
164 void KCModuleContainer::defaults()
166 ModuleList list
= allModules
;
167 ModuleList::iterator it
;
168 for ( it
= list
.begin() ; it
!=list
.end() ; ++it
)
173 emit
changed( true );
177 void KCModuleContainer::moduleChanged(KCModuleProxy
* proxy
)
179 changedModules
.append( proxy
);
180 if( changedModules
.isEmpty() )
186 KCModuleContainer::~KCModuleContainer()
191 /***********************************************************************/