• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KUtils

  • kutils
kcmodulecontainer.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
3
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.
8
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.
13
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.
18*/
19
20#include "kcmodulecontainer.h"
21#include "kcmodulecontainer.moc"
22
23#include <QtGui/QLayout>
24#include <QtGui/QPixmap>
25#include <QtCore/QStringList>
26
27#include <kcmodule.h>
28#include <kcmoduleinfo.h>
29#include <kcmoduleloader.h>
30#include <kcmoduleproxy.h>
31#include <kdebug.h>
32#include <kdialog.h>
33#include <kglobal.h>
34#include <kguiitem.h>
35#include <kicon.h>
36#include <kiconloader.h>
37#include <kpushbutton.h>
38#include <kservice.h>
39#include <kstandardguiitem.h>
40#include <ktabwidget.h>
41
42/***********************************************************************/
43class KCModuleContainer::KCModuleContainerPrivate
44{
45 public:
46 KCModuleContainerPrivate( const QStringList& mods )
47 : modules( mods )
48 , tabWidget( 0 )
49 , topLayout( 0 )
50 {}
51
52 QStringList modules;
53 KTabWidget *tabWidget;
54 KCModule::Buttons buttons;
55 QVBoxLayout *topLayout;
56
57
58};
59/***********************************************************************/
60
61
62
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/***********************************************************************/
67KCModuleContainer::KCModuleContainer( QWidget* parent, const QString& mods )
68 : KCModule( KGlobal::mainComponent(), parent ),
69 d(new KCModuleContainerPrivate( QString(mods).remove( ' ' ).split( ',', QString::SkipEmptyParts ) ))
70{
71 init();
72}
73
74KCModuleContainer::KCModuleContainer( QWidget* parent, const QStringList& mods )
75 : KCModule( KGlobal::mainComponent(), parent ),
76 d( new KCModuleContainerPrivate( mods ) )
77{
78 init();
79}
80
81void KCModuleContainer::init()
82{
83 d->topLayout = new QVBoxLayout( this );
84 d->topLayout->setMargin( 0 );
85 d->topLayout->setObjectName( "topLayout" );
86 d->tabWidget = new KTabWidget(this);
87 d->tabWidget->setObjectName( "tabWidget");
88 connect( d->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabSwitched(int)));
89 d->topLayout->addWidget( d->tabWidget );
90
91 if ( !d->modules.isEmpty() )
92 {
93 /* Add our modules */
94 for ( QStringList::const_iterator it = d->modules.constBegin(); it != d->modules.constEnd(); ++it )
95 addModule( (*it) );
96 }
97}
98
99void KCModuleContainer::addModule( const QString& module )
100{
101 /* In case it doesn't exist we just silently drop it.
102 * This allows people to easily extend containers.
103 * For example, KCM monitor gamma can be in kdegraphics.
104 */
105 KService::Ptr service = KService::serviceByDesktopName( module );
106 if ( !service )
107 {
108 kDebug(713) << "KCModuleContainer: module '" <<
109 module << "' was not found and thus not loaded" << endl;
110 return;
111 }
112
113 if ( service->noDisplay() )
114 return;
115
116 KCModuleProxy* proxy = new KCModuleProxy( service, d->tabWidget );
117 allModules.append( proxy );
118
119 proxy->setObjectName( module.toLatin1() );
120
121 d->tabWidget->addTab( proxy, KIcon( proxy->moduleInfo().icon() ),
122 /* Qt eats ampersands for dinner. But not this time. */
123 proxy->moduleInfo().moduleName().replace( '&', "&&" ));
124
125 d->tabWidget->setTabToolTip( d->tabWidget->indexOf( proxy ), proxy->moduleInfo().comment() );
126
127 connect( proxy, SIGNAL(changed(KCModuleProxy*)), SLOT(moduleChanged(KCModuleProxy*)));
128
129 /* Collect our buttons - we go for the common deliminator */
130 setButtons( buttons() | proxy->realModule()->buttons() );
131}
132
133void KCModuleContainer::tabSwitched(int index)
134{
135 KCModuleProxy* mod = static_cast<KCModuleProxy *>(d->tabWidget->widget(index));
136 setQuickHelp( mod->quickHelp() );
137 setAboutData( mod->aboutData() );
138}
139
140void KCModuleContainer::save()
141{
142 ModuleList list = changedModules;
143 ModuleList::iterator it;
144 for ( it = list.begin() ; it !=list.end() ; ++it )
145 {
146 (*it)->save();
147 }
148
149 emit changed( false );
150
151}
152
153void KCModuleContainer::load()
154{
155 ModuleList list = allModules;
156 ModuleList::iterator it;
157 for ( it = list.begin() ; it !=list.end() ; ++it )
158 {
159 (*it)->load();
160 }
161
162 emit changed( false );
163}
164
165void KCModuleContainer::defaults()
166{
167 ModuleList list = allModules;
168 ModuleList::iterator it;
169 for ( it = list.begin() ; it !=list.end() ; ++it )
170 {
171 (*it)->defaults();
172 }
173
174 emit changed( true );
175}
176
177
178void KCModuleContainer::moduleChanged(KCModuleProxy * proxy)
179{
180 changedModules.append( proxy );
181 if( changedModules.isEmpty() )
182 return;
183
184 emit changed(true);
185}
186
187KCModuleContainer::~KCModuleContainer()
188{
189 delete d;
190}
191
192/***********************************************************************/
193
194
195
196
KCModuleContainer::load
void load()
Reimplemented for internal purposes.
Definition: kcmodulecontainer.cpp:153
KCModuleContainer::~KCModuleContainer
virtual ~KCModuleContainer()
Default destructor.
Definition: kcmodulecontainer.cpp:187
KCModuleContainer::allModules
ModuleList allModules
A list of all modules which are encapsulated.
Definition: kcmodulecontainer.h:127
KCModuleContainer::changedModules
ModuleList changedModules
A list containing KCModuleProxy objects which have changed and must be saved.
Definition: kcmodulecontainer.h:122
KCModuleContainer::save
void save()
Reimplemented for internal purposes.
Definition: kcmodulecontainer.cpp:140
KCModuleContainer::defaults
void defaults()
Reimplemented for internal purposes.
Definition: kcmodulecontainer.cpp:165
KCModuleContainer::addModule
void addModule(const QString &module)
Adds the specified module to the tab widget.
Definition: kcmodulecontainer.cpp:99
KCModuleContainer::KCModuleContainer
KCModuleContainer(QWidget *parent, const QStringList &mods)
Creates a KCModuleContainer with tabs, each one containing one of the specified modules in mods.
Definition: kcmodulecontainer.cpp:74
KCModuleInfo::comment
QString comment() const
Definition: kcmoduleinfo.cpp:161
KCModuleInfo::icon
QString icon() const
Definition: kcmoduleinfo.cpp:166
KCModuleInfo::moduleName
QString moduleName() const
Definition: kcmoduleinfo.cpp:151
KCModuleProxy
Encapsulates a KCModule for embedding.
Definition: kcmoduleproxy.h:68
KCModuleProxy::realModule
KCModule * realModule() const
Access to the actual module.
Definition: kcmoduleproxy.cpp:71
KCModuleProxy::moduleInfo
KCModuleInfo moduleInfo() const
Definition: kcmoduleproxy.cpp:330
KCModuleProxy::quickHelp
QString quickHelp() const
Definition: kcmoduleproxy.cpp:292
KCModuleProxy::aboutData
const KAboutData * aboutData() const
Definition: kcmoduleproxy.cpp:297
KCModule
KCModule::setButtons
void setButtons(Buttons btn)
KCModule::changed
void changed(bool state)
KCModule::buttons
Buttons buttons() const
KIcon
KService::serviceByDesktopName
static Ptr serviceByDesktopName(const QString &_name)
KSharedPtr< KService >
KTabWidget
QList< KCModuleProxy * >
QWidget
kDebug
#define kDebug
kcmodule.h
kcmodulecontainer.h
kcmoduleinfo.h
kcmoduleloader.h
kcmoduleproxy.h
kdebug.h
kdialog.h
kglobal.h
kguiitem.h
kicon.h
kiconloader.h
kpushbutton.h
kservice.h
kstandardguiitem.h
ktabwidget.h
KGlobal
mainComponent
const KComponentData & mainComponent()
list
QStringList list(const QString &fileClass)
remove
KGuiItem remove()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KUtils

Skip menu "KUtils"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal