You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
259 lines
6.5 KiB
259 lines
6.5 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 2004 Frans Englich <frans.englich@telia.com>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqpixmap.h>
|
||
|
#include <tqstringlist.h>
|
||
|
#include <tqtabwidget.h>
|
||
|
#include <tqtooltip.h>
|
||
|
#include <tqvaluelist.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdecmodule.h>
|
||
|
#include <tdecmoduleinfo.h>
|
||
|
#include <tdecmoduleloader.h>
|
||
|
#include <tdecmoduleproxy.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <kdialog.h>
|
||
|
#include <kglobal.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kpushbutton.h>
|
||
|
#include <kservice.h>
|
||
|
#include <kstdguiitem.h>
|
||
|
|
||
12 years ago
|
#include "tdecmodulecontainer.h"
|
||
|
#include "tdecmodulecontainer.moc"
|
||
15 years ago
|
|
||
|
/***********************************************************************/
|
||
12 years ago
|
class TDECModuleContainer::TDECModuleContainerPrivate
|
||
15 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
TDECModuleContainerPrivate( const TQStringList& mods )
|
||
15 years ago
|
: modules( mods )
|
||
|
, tabWidget( 0 )
|
||
|
, buttons( 0 )
|
||
|
, hasRootKCM( false )
|
||
|
, btnRootMode( 0 )
|
||
|
, btnLayout( 0 )
|
||
|
, topLayout( 0 )
|
||
|
{}
|
||
|
|
||
15 years ago
|
TQStringList modules;
|
||
|
TQTabWidget *tabWidget;
|
||
15 years ago
|
int buttons;
|
||
|
bool hasRootKCM: 1;
|
||
|
KPushButton *btnRootMode;
|
||
15 years ago
|
TQHBoxLayout *btnLayout;
|
||
|
TQVBoxLayout *topLayout;
|
||
15 years ago
|
|
||
|
|
||
|
};
|
||
|
/***********************************************************************/
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/***********************************************************************/
|
||
12 years ago
|
TDECModuleContainer::TDECModuleContainer( TQWidget* parent, const char* name,
|
||
15 years ago
|
const TQString& mods )
|
||
12 years ago
|
: TDECModule( parent, name )
|
||
15 years ago
|
{
|
||
12 years ago
|
d = new TDECModuleContainerPrivate( TQStringList::split( ",", TQString(mods).remove( " " )) );
|
||
15 years ago
|
init();
|
||
|
}
|
||
|
|
||
12 years ago
|
TDECModuleContainer::TDECModuleContainer( TQWidget* parent, const char* name,
|
||
15 years ago
|
const TQStringList& mods )
|
||
12 years ago
|
: TDECModule( parent, name ), d( new TDECModuleContainerPrivate( mods ) )
|
||
15 years ago
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::init()
|
||
15 years ago
|
{
|
||
15 years ago
|
d->topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint(), "topLayout" );
|
||
|
d->tabWidget = new TQTabWidget(this, "tabWidget");
|
||
15 years ago
|
d->tabWidget->setMargin(KDialog::marginHint());
|
||
15 years ago
|
connect( d->tabWidget, TQT_SIGNAL( currentChanged( TQWidget* ) ), TQT_SLOT( tabSwitched( TQWidget* ) ));
|
||
15 years ago
|
d->topLayout->addWidget( d->tabWidget );
|
||
|
|
||
|
if ( !d->modules.isEmpty() )
|
||
|
{
|
||
|
/* Add our modules */
|
||
15 years ago
|
for ( TQStringList::Iterator it = d->modules.begin(); it != d->modules.end(); ++it )
|
||
15 years ago
|
addModule( (*it) );
|
||
|
|
||
|
finalize();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::finalize()
|
||
15 years ago
|
{
|
||
|
setButtons( d->buttons );
|
||
|
if ( d->hasRootKCM ) /* Add a root mode button */
|
||
|
{
|
||
|
if(!d->btnLayout) /* It could already be added */
|
||
|
{
|
||
15 years ago
|
d->btnLayout = new TQHBoxLayout(this, 0, 0, "btnLayout");
|
||
15 years ago
|
d->btnRootMode = new KPushButton(KStdGuiItem::adminMode(), this, "btnRootMode");
|
||
|
|
||
|
d->btnLayout->addWidget( d->btnRootMode );
|
||
|
d->btnLayout->addStretch();
|
||
|
d->topLayout->addLayout( d->btnLayout );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::addModule( const TQString& module )
|
||
15 years ago
|
{
|
||
|
/* In case it doesn't exist we just silently drop it.
|
||
|
* This allows people to easily extend containers.
|
||
13 years ago
|
* For example, KCM monitor gamma can be in tdegraphics.
|
||
15 years ago
|
*/
|
||
|
if ( !KService::serviceByDesktopName( module ) )
|
||
|
{
|
||
12 years ago
|
kdDebug(713) << "TDECModuleContainer: module '" <<
|
||
15 years ago
|
module << "' was not found and thus not loaded" << endl;
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
if( !TDECModuleLoader::testModule( module ))
|
||
15 years ago
|
return;
|
||
|
|
||
12 years ago
|
TDECModuleProxy* proxy = new TDECModuleProxy( module, false, d->tabWidget, module.latin1());
|
||
15 years ago
|
allModules.append( proxy );
|
||
|
|
||
12 years ago
|
d->tabWidget->addTab( proxy, TQIconSet(TDEGlobal::iconLoader()->loadIcon(
|
||
15 years ago
|
proxy->moduleInfo().icon(), KIcon::Desktop)),
|
||
|
/* QT eats ampersands for dinner. But not this time. */
|
||
14 years ago
|
proxy->moduleInfo().moduleName().replace( "&", "&&" ));
|
||
15 years ago
|
|
||
|
d->tabWidget->setTabToolTip( proxy, proxy->moduleInfo().comment() );
|
||
|
|
||
12 years ago
|
connect( proxy, TQT_SIGNAL(changed(TDECModuleProxy *)), TQT_SLOT(moduleChanged(TDECModuleProxy *)));
|
||
15 years ago
|
|
||
|
/* Collect our buttons - we go for the common deliminator */
|
||
|
d->buttons = d->buttons | proxy->realModule()->buttons();
|
||
|
|
||
|
/* If we should add an Administrator Mode button */
|
||
|
if ( proxy->moduleInfo().needsRootPrivileges() )
|
||
|
d->hasRootKCM=true;
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::tabSwitched( TQWidget * module )
|
||
15 years ago
|
{
|
||
|
if ( !d->hasRootKCM )
|
||
|
return;
|
||
|
|
||
|
/* Not like this. Not like this. */
|
||
|
disconnect( d->btnRootMode, 0, 0, 0 );
|
||
|
/* Welcome to the real world huh baby? */
|
||
|
|
||
12 years ago
|
TDECModuleProxy* mod = (TDECModuleProxy *) module;
|
||
15 years ago
|
|
||
|
if ( mod->moduleInfo().needsRootPrivileges() && !mod->rootMode() )
|
||
|
{
|
||
|
d->btnRootMode->setEnabled( true );
|
||
15 years ago
|
connect( d->btnRootMode, TQT_SIGNAL( clicked() ),
|
||
|
TQT_SLOT( runAsRoot() ));
|
||
|
connect( mod, TQT_SIGNAL( childClosed() ),
|
||
|
TQT_SLOT ( rootExited() ));
|
||
15 years ago
|
}
|
||
|
else
|
||
|
d->btnRootMode->setEnabled( false );
|
||
|
|
||
|
setQuickHelp( mod->quickHelp() );
|
||
12 years ago
|
setAboutData( const_cast<TDEAboutData*>(mod->aboutData()) );
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::runAsRoot()
|
||
15 years ago
|
{
|
||
|
if ( d->tabWidget->currentPage() )
|
||
12 years ago
|
( (TDECModuleProxy *) d->tabWidget->currentPage() )->runAsRoot();
|
||
15 years ago
|
d->btnRootMode->setEnabled( false );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::rootExited()
|
||
15 years ago
|
{
|
||
15 years ago
|
connect( d->btnRootMode, TQT_SIGNAL( clicked() ), TQT_SLOT( runAsRoot() ));
|
||
15 years ago
|
d->btnRootMode->setEnabled( true );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::save()
|
||
15 years ago
|
{
|
||
|
ModuleList list = changedModules;
|
||
|
ModuleList::iterator it;
|
||
|
for ( it = list.begin() ; it !=list.end() ; ++it )
|
||
|
{
|
||
|
(*it)->save();
|
||
|
}
|
||
|
|
||
|
emit changed( false );
|
||
|
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::load()
|
||
15 years ago
|
{
|
||
|
ModuleList list = allModules;
|
||
|
ModuleList::iterator it;
|
||
|
for ( it = list.begin() ; it !=list.end() ; ++it )
|
||
|
{
|
||
|
(*it)->load();
|
||
|
}
|
||
|
|
||
|
emit changed( false );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::defaults()
|
||
15 years ago
|
{
|
||
|
ModuleList list = allModules;
|
||
|
ModuleList::iterator it;
|
||
|
for ( it = list.begin() ; it !=list.end() ; ++it )
|
||
|
{
|
||
|
(*it)->defaults();
|
||
|
}
|
||
|
|
||
|
emit changed( true );
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDECModuleContainer::moduleChanged(TDECModuleProxy * proxy)
|
||
15 years ago
|
{
|
||
|
changedModules.append( proxy );
|
||
|
if( changedModules.isEmpty() )
|
||
|
return;
|
||
|
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
12 years ago
|
TDECModuleContainer::~TDECModuleContainer()
|
||
15 years ago
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
/***********************************************************************/
|
||
|
|
||
|
|
||
|
|
||
|
|