2 Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "proxywidget.h"
21 #include "kinfocenter_interface.h"
23 #include <kpushbutton.h>
26 #include <QHBoxLayout>
27 #include <QVBoxLayout>
28 #include <QResizeEvent>
29 #include <Q3ScrollView>
31 #include <QtDBus/QtDBus>
32 #include <Q3WhatsThis>
35 #include <kapplication.h>
37 #include <kseparator.h>
39 #include <kstandardguiitem.h>
42 #include <unistd.h> // for getuid()
44 #include "proxywidget.moc"
46 class WhatsThis
: public Q3WhatsThis
49 WhatsThis( ProxyWidget
* parent
)
50 : Q3WhatsThis( parent
), proxy( parent
) {}
54 QString
text( const QPoint
& ) {
55 if ( !proxy
->quickHelp().isEmpty() )
56 return proxy
->quickHelp();
58 return i18n("The currently loaded configuration module.");
65 ////////////////////////////////////////////////////////////////////////////////////////////////////////
68 class RootInfoWidget
: public QLabel
71 RootInfoWidget(QWidget
*parent
, const char *name
);
72 void setRootMessage(const QString
& s
) { setText(s
); }
75 RootInfoWidget::RootInfoWidget(QWidget
*parent
, const char *name
= 0)
78 setObjectName( name
);
79 setFrameShape(QFrame::Box
);
80 setFrameShadow(QFrame::Raised
);
82 setText(i18n("<b>Changes in this module require root access.</b><br />"
83 "Click the \"Administrator Mode\" button to "
84 "allow modifications in this module."));
86 this->setWhatsThis( i18n("This module requires special permissions, probably "
87 "for system-wide modifications; therefore, it is "
88 "required that you provide the root password to be "
89 "able to change the module's properties. If you "
90 "do not provide the password, the module will be "
95 ////////////////////////////////////////////////////////////////////////////////////////////////////////
97 class ProxyView
: public Q3ScrollView
100 ProxyView(KCModule
*client
, const QString
& title
, QWidget
*parent
, bool run_as_root
, const char *name
);
103 virtual void resizeEvent(QResizeEvent
*);
105 QWidget
*contentWidget
;
110 class ProxyContentWidget
: public QWidget
113 ProxyContentWidget( QWidget
* parent
) : QWidget( parent
) {}
114 ~ProxyContentWidget(){}
116 // this should be really done by qscrollview in AutoOneFit mode!
117 QSize
sizeHint() const { return minimumSizeHint(); }
121 ProxyView::ProxyView(KCModule
*_client
, const QString
&, QWidget
*parent
, bool run_as_root
, const char *name
)
122 : Q3ScrollView(parent
, name
), client(_client
)
124 setResizePolicy(Q3ScrollView::AutoOneFit
);
125 setFrameStyle( NoFrame
);
126 contentWidget
= new ProxyContentWidget( viewport() );
128 QVBoxLayout
* vbox
= new QVBoxLayout( contentWidget
);
131 if (run_as_root
&& _client
->useRootOnlyMessage()) // notify the user
133 RootInfoWidget
*infoBox
= new RootInfoWidget(contentWidget
);
134 vbox
->addWidget( infoBox
);
135 QString msg
= _client
->rootOnlyMessage();
137 infoBox
->setRootMessage(msg
);
138 vbox
->setSpacing(KDialog::spacingHint());
140 client
->setParent(contentWidget
);
143 vbox
->addWidget( client
);
144 vbox
->activate(); // make sure we have a proper minimumSizeHint
145 addChild(contentWidget
);
148 void ProxyView::resizeEvent(QResizeEvent
*e
)
150 Q3ScrollView::resizeEvent(e
);
154 ////////////////////////////////////////////////////////////////////////////////////////////////////////
157 ProxyWidget::ProxyWidget(KCModule
*client
, const QString
&title
,
162 setWindowTitle(title
);
164 #warning "kde4: DBUS port"
168 // Make root modules look as similar as possible...
169 DCOPCString replyType
;
170 QByteArray replyData
;
172 if (kapp
->dcopClient()->call("kcontrol", "moduleIface", "getPalette()", QByteArray(),
173 replyType
, replyData
))
174 if ( replyType
== "QPalette") {
175 QDataStream
reply( replyData
);
180 /* // Doesn't work ...
181 if (kapp->dcopClient()->call("kcontrol", "moduleIface", "getStyle()", QByteArray(),
182 replyType, replyData))
183 if ( replyType == "QString") {
184 QDataStream reply( replyData, QIODevice::ReadOnly );
190 if (kapp
->dcopClient()->call("kcontrol", "moduleIface", "getFont()", QByteArray(),
191 replyType
, replyData
))
192 if ( replyType
== "QFont") {
193 QDataStream
reply( replyData
);
200 view
= new ProxyView(client
, title
, this, run_as_root
, "proxyview");
201 (void) new WhatsThis( this );
203 connect(_client
, SIGNAL(changed(bool)), SLOT(clientChanged(bool)));
204 connect(_client
, SIGNAL(quickHelpChanged()), SIGNAL(quickHelpChanged()));
206 _sep
= new KSeparator(Qt::Horizontal
, this);
208 _help
= new KPushButton( KStandardGuiItem::help(), this );
209 _default
= new KPushButton( KStandardGuiItem::defaults(), this );
210 _apply
= new KPushButton( KStandardGuiItem::apply(), this );
211 _reset
= new KPushButton( KStandardGuiItem::reset(), this );
212 _root
= new KPushButton( KGuiItem(i18n( "&Administrator Mode" )), this );
214 bool mayModify
= (!run_as_root
|| !_client
->useRootOnlyMessage()) && !KCGlobal::isInfoCenter();
216 // only enable the requested buttons
217 int b
= _client
->buttons();
218 _help
->setVisible(false & (b
& KCModule::Help
));
219 _default
->setVisible(mayModify
&& (b
& KCModule::Default
));
220 _apply
->setVisible(mayModify
&& (b
& KCModule::Apply
));
221 _reset
->setVisible(mayModify
&& (b
& KCModule::Apply
));
222 _root
->setVisible(run_as_root
);
224 // disable initial buttons
225 _apply
->setEnabled( false );
226 _reset
->setEnabled( false );
228 connect(_help
, SIGNAL(clicked()), SLOT(helpClicked()));
229 connect(_default
, SIGNAL(clicked()), SLOT(defaultClicked()));
230 connect(_apply
, SIGNAL(clicked()), SLOT(applyClicked()));
231 connect(_reset
, SIGNAL(clicked()), SLOT(resetClicked()));
232 connect(_root
, SIGNAL(clicked()), SLOT(rootClicked()));
234 QVBoxLayout
*top
= new QVBoxLayout(this);
235 top
->setMargin(KDialog::marginHint());
236 top
->setSpacing(KDialog::spacingHint());
237 top
->addWidget(view
);
238 top
->addWidget(_sep
);
240 QHBoxLayout
*buttons
= new QHBoxLayout();
241 top
->addItem(buttons
);
242 buttons
->setSpacing(4);
243 buttons
->addWidget(_help
);
244 buttons
->addWidget(_default
);
247 buttons
->addWidget(_root
);
250 buttons
->addStretch(1);
253 buttons
->addWidget(_apply
);
254 buttons
->addWidget(_reset
);
260 ProxyWidget::~ProxyWidget()
265 QString
ProxyWidget::quickHelp() const
268 return _client
->quickHelp();
273 void ProxyWidget::helpClicked()
279 OrgKdeKinfocenterInterface
kinfocenter("org.kde.kinfocenter", "/moduleIface", QDBusConnection::sessionBus());
280 kinfocenter
.invokeHelp();
284 void ProxyWidget::defaultClicked()
290 void ProxyWidget::applyClicked()
293 clientChanged(false);
296 void ProxyWidget::resetClicked()
299 clientChanged(false);
302 void ProxyWidget::rootClicked()
307 void ProxyWidget::clientChanged(bool state
)
309 _apply
->setEnabled(state
);
310 _reset
->setEnabled(state
);
312 // forward the signal
316 const KAboutData
*ProxyWidget::aboutData() const
318 return _client
->aboutData();
321 // vim: sw=2 sts=2 et