20 #include <tqapplication.h>
22 #include <tqdatastream.h>
24 #include <tqfileinfo.h>
29 #include <tqscrollview.h>
30 #include <tqtextstream.h>
32 #include <tqwhatsthis.h>
35 #include <dcopclient.h>
38 #include <tdeapplication.h>
39 #include <tdeaboutdata.h>
40 #include <tdecmodule.h>
41 #include <tdecmoduleinfo.h>
42 #include <tdecmoduleloader.h>
46 #include <tdeprocess.h>
48 #include <tdestandarddirs.h>
53 #include "tdecmoduleproxy.h"
54 #include "tdecmoduleproxyIface.h"
55 #include "tdecmoduleproxyIfaceImpl.h"
58 class TDECModuleProxy::TDECModuleProxyPrivate
71 , rootCommunicator( 0 )
74 , withFallback( false )
77 , bogusOccupier( false )
78 , isInitialized( false )
81 ~TDECModuleProxyPrivate()
88 delete rootCommunicator;
98 TDECModuleProxyIfaceImpl *dcopObject;
99 DCOPClient *dcopClient;
100 TQVBoxLayout *topLayout;
101 TDECModuleProxyRootCommunicatorImpl *rootCommunicator;
158 TQApplication::setOverrideCursor( TQt::WaitCursor );
162 if( !d->isInitialized )
164 d->dcopName = TQString(
moduleInfo().handle().prepend(
"TDECModuleProxy-")).utf8();
165 d->topLayout =
new TQVBoxLayout( that, 0, 0,
"topLayout" );
167 d->isInitialized =
true;
171 d->dcopClient =
new DCOPClient();
173 if( !d->dcopClient->isRegistered() )
174 d->dcopClient->registerAs( d->dcopName,
false );
176 d->dcopClient->setAcceptCalls(
true );
178 if( d->dcopClient->appId() == d->dcopName || d->bogusOccupier )
181 kdDebug(711) <<
"Module not already loaded, loading module" <<
endl;
183 d->dcopObject =
new TDECModuleProxyIfaceImpl( d->dcopName, that );
186 that, name(), d->args );
188 connect( d->kcm, TQ_SIGNAL(
changed(
bool ) ),
189 TQ_SLOT(moduleChanged(
bool)) );
190 connect( d->kcm, TQ_SIGNAL( destroyed() ),
191 TQ_SLOT( moduleDestroyed() ) );
192 connect( d->kcm, TQ_SIGNAL(quickHelpChanged()),
193 TQ_SIGNAL(quickHelpChanged()));
194 TQWhatsThis::add( that, d->kcm->quickHelp() );
196 d->topLayout->addWidget( d->kcm );
199 d->kcm->useRootOnlyMsg() &&
201 !
KUser().isSuperUser() )
204 d->rootInfo =
new TQLabel( that,
"rootInfo" );
205 d->topLayout->insertWidget( 0, d->rootInfo );
207 d->rootInfo->setFrameShape(TQFrame::Box);
208 d->rootInfo->setFrameShadow(TQFrame::Raised);
210 const TQString msg = d->kcm->rootOnlyMsg();
212 d->rootInfo->setText(i18n(
213 "<b>Changes in this section requires root access.</b><br />"
214 "Click the \"Administrator Mode\" button to "
215 "allow modifications."));
217 d->rootInfo->setText(msg);
219 TQWhatsThis::add( d->rootInfo, i18n(
220 "This section requires special permissions, probably "
221 "for system-wide changes; therefore, it is "
222 "required that you provide the root password to be "
223 "able to change the module's properties. If "
224 "you do not provide the password, the module will be "
230 kdDebug(711) <<
"Module already loaded, loading KCMError" <<
endl;
232 d->dcopClient->detach();
234 d->dcopClient->attach();
236 d->dcopClient->setNotifications(
true );
237 connect( d->dcopClient, TQ_SIGNAL( applicationRemoved(
const TQCString& )),
238 TQ_SLOT( applicationRemoved(
const TQCString& )));
241 TQByteArray replyData, data;
244 TQDataStream arg, stream( replyData, IO_ReadOnly );
246 if( d->dcopClient->call( d->dcopName, d->dcopName,
"applicationName()",
247 data, replyType, replyData ))
252 i18n(
"Argument is application name",
"This configuration section is "
253 "already opened in %1" ).arg( result ),
" ", that );
255 d->topLayout->addWidget( d->kcm );
259 kdDebug(711) <<
"Calling TDECModuleProxy's DCOP interface for fetching the name failed." <<
endl;
260 d->bogusOccupier =
true;
261 TQApplication::restoreOverrideCursor();
266 TQApplication::restoreOverrideCursor();
271 void TDECModuleProxy::applicationRemoved(
const TQCString& app )
273 if( app == d->dcopName )
279 d->dcopClient->setNotifications(
false );
295 TQWidget::showEvent( ev );
304 TQApplication::setOverrideCursor( TQt::WaitCursor );
306 delete d->rootProcess;
307 delete d->embedWidget;
308 delete d->embedFrame;
310 d->embedFrame =
new TQVBox(
this,
"embedFrame" );
311 d->embedFrame->setFrameStyle( TQFrame::Box | TQFrame::Raised );
313 TQPalette pal( red );
314 pal.setColor( TQColorGroup::Background,
315 colorGroup().background() );
316 d->embedFrame->setPalette( pal );
317 d->embedFrame->setLineWidth( 2 );
318 d->embedFrame->setMidLineWidth( 2 );
319 d->topLayout->addWidget(d->embedFrame,1);
321 d->embedWidget =
new QXEmbed( d->embedFrame,
"embedWidget" );
323 d->embedFrame->show();
325 TQLabel *lblBusy =
new TQLabel(i18n(
"<big>Loading...</big>"), d->embedWidget,
"lblBusy" );
326 lblBusy->setTextFormat(RichText);
327 lblBusy->setAlignment(AlignCenter);
328 lblBusy->setGeometry(0,0, d->kcm->width(), d->kcm->height());
345 if (cmd.left(5) ==
"tdesu")
347 cmd = TQString(cmd.remove(0,5)).stripWhiteSpace();
350 while( cmd.length() > 1 && cmd[ 0 ] ==
'-' )
351 cmd = TQString(cmd.remove( 0, cmd.find(
' ' ) )).stripWhiteSpace();
354 if (cmd.left(8) ==
"tdecmshell")
355 cmd = TQString(cmd.remove(0,8)).stripWhiteSpace();
359 if (!tdesu.isEmpty())
364 *d->rootProcess << tdesu;
365 *d->rootProcess <<
"--nonewdcop" <<
"-n" <<
"-d" << TQString(
"-i%1" ).arg(
moduleInfo().icon());
367 *d->rootProcess << TQString(
"%1 %2 --embed-proxy %3 --lang %4").arg(
locate(
"exe",
"tdecmshell"))
370 connect(d->rootProcess, TQ_SIGNAL(processExited(
TDEProcess*)), TQ_SLOT(rootExited()));
380 tdeApp->dcopClient();
381 d->rootCommunicator =
new TDECModuleProxyRootCommunicatorImpl( d->dcopName +
"-RootCommunicator",
this );
385 TQApplication::restoreOverrideCursor();
390 delete d->embedWidget;
392 delete d->embedFrame;
395 TQApplication::restoreOverrideCursor();
398 void TDECModuleProxy::rootExited()
402 if ( d->embedWidget->embeddedWinId() )
403 XDestroyWindow(tqt_xdisplay(), d->embedWidget->embeddedWinId());
405 delete d->embedWidget;
408 delete d->rootProcess;
411 delete d->embedFrame;
414 delete d->rootCommunicator;
415 d->rootCommunicator = 0;
420 d->topLayout->invalidate();
425 moduleChanged(
false );
440 XKillClient(tqt_xdisplay(), d->embedWidget->embeddedWinId());
446 delete d->dcopObject;
449 if( d->dcopClient && !d->dcopClient->detach() )
450 kdDebug(711) <<
"Unregistering from DCOP failed." <<
endl;
452 delete d->dcopClient;
459 void TDECModuleProxy::moduleChanged(
bool c )
461 if( d->changed == c )
469 void TDECModuleProxy::moduleDestroyed()
475 TQWidget * parent,
const char * name,
const TQStringList & args)
476 : TQWidget( parent, name )
480 d->withFallback = withFallback;
484 TQWidget * parent,
const char * name,
const TQStringList & args )
485 : TQWidget( parent, name )
489 d->withFallback = withFallback;
493 TQWidget * parent,
const char * name,
494 const TQStringList & args)
495 : TQWidget( parent, name )
499 d->withFallback = withFallback;
506 d =
new TDECModuleProxyPrivate( info );
520 callRootModule(
"load()" );
524 moduleChanged(
false );
531 callRootModule(
"save()" );
535 moduleChanged(
false );
539 void TDECModuleProxy::callRootModule(
const TQCString&
function )
541 TQByteArray sendData, replyData;
546 if( !tdeApp->dcopClient()->call( d->dcopName, d->dcopName,
function, sendData,
547 replyType, replyData,
true, -1 ))
548 kdDebug(711) <<
"Calling function '" <<
function <<
"' failed." <<
endl;
555 callRootModule(
"defaults()" );
567 TQByteArray data, replyData;
570 if (tdeApp->dcopClient()->call(d->dcopName, d->dcopName,
"quickHelp()",
571 data, replyType, replyData))
572 kdDebug(711) <<
"Calling DCOP function bool changed() failed." <<
endl;
575 TQDataStream reply(replyData, IO_ReadOnly);
576 if (replyType ==
"TQString")
583 kdDebug(711) <<
"DCOP function changed() returned mumbo jumbo." <<
endl;
585 return TQString::null;
609 return TQString::null;
621 return TQString::null;
628 TDECModule::Help | TDECModule::Default | TDECModule::Apply ;
668 emit quickHelpChanged();
672 #include "tdecmoduleproxy.moc"