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 <kapplication.h>
39 #include <kaboutdata.h>
41 #include <kcmoduleinfo.h>
42 #include <kcmoduleloader.h>
48 #include <kstandarddirs.h>
53 #include "kcmoduleproxy.h"
54 #include "kcmoduleproxyIface.h"
55 #include "kcmoduleproxyIfaceImpl.h"
58 class KCModuleProxy::KCModuleProxyPrivate
71 , rootCommunicator( 0 )
74 , withFallback( false )
77 , bogusOccupier( false )
78 , isInitialized( false )
81 ~KCModuleProxyPrivate()
88 delete rootCommunicator;
98 KCModuleProxyIfaceImpl *dcopObject;
99 DCOPClient *dcopClient;
100 TQVBoxLayout *topLayout;
101 KCModuleProxyRootCommunicatorImpl *rootCommunicator;
158 TQApplication::setOverrideCursor( Qt::WaitCursor );
162 if( !d->isInitialized )
164 d->dcopName = TQString(
moduleInfo().handle().prepend(
"KCModuleProxy-")).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 KCModuleProxyIfaceImpl( d->dcopName, that );
186 that, name(), d->args );
188 connect( d->kcm, TQT_SIGNAL(
changed(
bool ) ),
189 TQT_SLOT(moduleChanged(
bool)) );
190 connect( d->kcm, TQT_SIGNAL( destroyed() ),
191 TQT_SLOT( moduleDestroyed() ) );
192 connect( d->kcm, TQT_SIGNAL(quickHelpChanged()),
193 TQT_SIGNAL(quickHelpChanged()));
194 TQWhatsThis::add( that, d->kcm->quickHelp() );
196 d->topLayout->addWidget( d->kcm );
200 !
KUser().isSuperUser() )
203 d->rootInfo =
new TQLabel( that,
"rootInfo" );
204 d->topLayout->insertWidget( 0, d->rootInfo );
206 d->rootInfo->setFrameShape(TQFrame::Box);
207 d->rootInfo->setFrameShadow(TQFrame::Raised);
209 const TQString msg = d->kcm->rootOnlyMsg();
211 d->rootInfo->setText(i18n(
212 "<b>Changes in this section requires root access.</b><br />"
213 "Click the \"Administrator Mode\" button to "
214 "allow modifications."));
216 d->rootInfo->setText(msg);
218 TQWhatsThis::add( d->rootInfo, i18n(
219 "This section requires special permissions, probably "
220 "for system-wide changes; therefore, it is "
221 "required that you provide the root password to be "
222 "able to change the module's properties. If "
223 "you do not provide the password, the module will be "
229 kdDebug(711) <<
"Module already loaded, loading KCMError" <<
endl;
231 d->dcopClient->detach();
233 d->dcopClient->attach();
235 d->dcopClient->setNotifications(
true );
236 connect( d->dcopClient, TQT_SIGNAL( applicationRemoved(
const TQCString& )),
237 TQT_SLOT( applicationRemoved(
const TQCString& )));
240 TQByteArray replyData, data;
243 TQDataStream arg, stream( replyData, IO_ReadOnly );
245 if( d->dcopClient->call( d->dcopName, d->dcopName,
"applicationName()",
246 data, replyType, replyData ))
251 i18n(
"Argument is application name",
"This configuration section is "
252 "already opened in %1" ).arg( result ),
" ", that );
254 d->topLayout->addWidget( d->kcm );
258 kdDebug(711) <<
"Calling KCModuleProxy's DCOP interface for fetching the name failed." <<
endl;
259 d->bogusOccupier =
true;
260 TQApplication::restoreOverrideCursor();
265 TQApplication::restoreOverrideCursor();
270 void KCModuleProxy::applicationRemoved(
const TQCString& app )
272 if( app == d->dcopName )
278 d->dcopClient->setNotifications(
false );
303 TQApplication::setOverrideCursor( Qt::WaitCursor );
305 delete d->rootProcess;
306 delete d->embedWidget;
307 delete d->embedFrame;
309 d->embedFrame =
new TQVBox(
this,
"embedFrame" );
310 d->embedFrame->setFrameStyle( TQFrame::Box | TQFrame::Raised );
312 TQPalette pal( red );
313 pal.setColor( TQColorGroup::Background,
314 colorGroup().background() );
315 d->embedFrame->setPalette( pal );
316 d->embedFrame->setLineWidth( 2 );
317 d->embedFrame->setMidLineWidth( 2 );
318 d->topLayout->addWidget(d->embedFrame,1);
320 d->embedWidget =
new QXEmbed( d->embedFrame,
"embedWidget" );
322 d->embedFrame->show();
324 TQLabel *lblBusy =
new TQLabel(i18n(
"<big>Loading...</big>"), d->embedWidget,
"lblBusy" );
325 lblBusy->setTextFormat(RichText);
326 lblBusy->setAlignment(AlignCenter);
327 lblBusy->setGeometry(0,0, d->kcm->width(), d->kcm->height());
344 if (cmd.left(5) ==
"kdesu")
346 cmd = TQString(cmd.remove(0,5)).stripWhiteSpace();
349 while( cmd.length() > 1 && cmd[ 0 ] ==
'-' )
350 cmd = TQString(cmd.remove( 0, cmd.find(
' ' ) )).stripWhiteSpace();
353 if (cmd.left(8) ==
"kcmshell")
354 cmd = TQString(cmd.remove(0,8)).stripWhiteSpace();
358 if (!kdesu.isEmpty())
363 *d->rootProcess << kdesu;
364 *d->rootProcess <<
"--nonewdcop" <<
"-n" <<
"-d" << TQString(
"-i%1" ).arg(
moduleInfo().icon());
366 *d->rootProcess << TQString(
"%1 %2 --embed-proxy %3 --lang %4").arg(
locate(
"exe",
"kcmshell"))
369 connect(d->rootProcess, TQT_SIGNAL(processExited(
KProcess*)), TQT_SLOT(rootExited()));
380 d->rootCommunicator =
new KCModuleProxyRootCommunicatorImpl( d->dcopName +
"-RootCommunicator",
this );
384 TQApplication::restoreOverrideCursor();
389 delete d->embedWidget;
391 delete d->embedFrame;
394 TQApplication::restoreOverrideCursor();
397 void KCModuleProxy::rootExited()
401 if ( d->embedWidget->embeddedWinId() )
402 XDestroyWindow(qt_xdisplay(), d->embedWidget->embeddedWinId());
404 delete d->embedWidget;
407 delete d->rootProcess;
410 delete d->embedFrame;
413 delete d->rootCommunicator;
414 d->rootCommunicator = 0;
419 d->topLayout->invalidate();
424 moduleChanged(
false );
439 XKillClient(qt_xdisplay(), d->embedWidget->embeddedWinId());
445 delete d->dcopObject;
448 if( d->dcopClient && !d->dcopClient->detach() )
449 kdDebug(711) <<
"Unregistering from DCOP failed." <<
endl;
451 delete d->dcopClient;
458 void KCModuleProxy::moduleChanged(
bool c )
460 if( d->changed == c )
468 void KCModuleProxy::moduleDestroyed()
474 TQWidget * parent,
const char * name,
const TQStringList & args)
475 : TQWidget( parent, name )
479 d->withFallback = withFallback;
483 TQWidget * parent,
const char * name,
const TQStringList & args )
484 : TQWidget( parent, name )
488 d->withFallback = withFallback;
492 TQWidget * parent,
const char * name,
493 const TQStringList & args)
494 : TQWidget( parent, name )
498 d->withFallback = withFallback;
505 d =
new KCModuleProxyPrivate( info );
519 callRootModule(
"load()" );
523 moduleChanged(
false );
530 callRootModule(
"save()" );
534 moduleChanged(
false );
538 void KCModuleProxy::callRootModule(
const TQCString&
function )
540 TQByteArray sendData, replyData;
545 if( !kapp->dcopClient()->call( d->dcopName, d->dcopName,
function, sendData,
546 replyType, replyData,
true, -1 ))
547 kdDebug(711) <<
"Calling function '" <<
function <<
"' failed." <<
endl;
554 callRootModule(
"defaults()" );
566 TQByteArray data, replyData;
569 if (kapp->dcopClient()->call(d->dcopName, d->dcopName,
"quickHelp()",
570 data, replyType, replyData))
571 kdDebug(711) <<
"Calling DCOP function bool changed() failed." <<
endl;
574 TQDataStream reply(replyData, IO_ReadOnly);
575 if (replyType ==
"TQString")
582 kdDebug(711) <<
"DCOP function changed() returned mumbo jumbo." <<
endl;
584 return TQString::null;
603 KCModule::Help | KCModule::Default | KCModule::Apply ;
643 emit quickHelpChanged();
647 #include "kcmoduleproxy.moc"