[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/kcontrol4/src
From: Ben Cooksley <sourtooth () gmail ! com>
Date: 2009-03-02 5:07:55
Message-ID: 1235970475.734587.24195.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 933996 by bcooksley:
Ensure the modules can save, revert and switch to default settings and invoke help. \
Implement querying the user if there are changes waiting to be saved. Do not keep \
more than one module loaded at a time. Ensure only modules that are valid and the \
user is authorised to use are loaded
M +2 -2 app/SettingsBase.cpp
M +1 -1 classic/ClassicMode.cpp
M +138 -29 core/ModuleView.cpp
M +10 -4 core/ModuleView.h
--- trunk/playground/base/kcontrol4/src/app/SettingsBase.cpp #933995:933996
@@ -61,10 +61,10 @@
possibleViews.insert( activeService->library(), controller );
controller->init( rootModule, activeService, KGlobal::config()->group( \
activeService->name() ) ); stackedWidget->addWidget(controller->mainWidget());
- connect(controller, SIGNAL(dirtyStateChanged(bool)), this, \
SLOT(toggleDirtyState(bool)));
connect(controller, SIGNAL(actionsChanged()), this, \
SLOT(updateViewActions()));
- connect(controller->moduleView(), SIGNAL(moduleChanged()), this, \
SLOT(moduleChanged()));
connect(searchText, SIGNAL(textChanged(const QString&)), controller, \
SLOT(searchChanged(const QString&))); + connect(controller->moduleView(), \
SIGNAL(moduleSwitched()), this, SLOT(moduleChanged())); + \
connect(controller->moduleView(), SIGNAL(configurationChanged(bool)), this, \
SLOT(toggleDirtyState(bool))); } else {
kWarning() << "View load error: " + error;
}
--- trunk/playground/base/kcontrol4/src/classic/ClassicMode.cpp #933995:933996
@@ -94,7 +94,7 @@
connect( classicTree, SIGNAL(activated(const QModelIndex&)), this, \
SLOT(changeModule(const QModelIndex&)));
connect( classicTree, SIGNAL(collapsed(QModelIndex)), this, \
SLOT(expandColumns()));
connect( classicTree, SIGNAL(expanded(QModelIndex)), this, \
SLOT(expandColumns()));
- connect( mModuleView, SIGNAL( moduleLoaded() ), this, SLOT( moduleLoaded() ) );
+ connect( mModuleView, SIGNAL( moduleSwitched() ), this, SLOT( moduleLoaded() ) \
);
expandColumns();
QList<int> defaultSizes;
--- trunk/playground/base/kcontrol4/src/core/ModuleView.cpp #933995:933996
@@ -21,33 +21,42 @@
#include "ModuleView.h"
#include <QMap>
+#include <QProcess>
#include <QScrollArea>
#include <QStackedWidget>
#include <KCModuleInfo>
#include <KCModuleProxy>
+#include <KMessageBox>
+#include <KStandardGuiItem>
+#include <KAuthorized>
#include <KDebug>
class ModuleView::Private {
public:
- Private()
- : mActiveModule( 0 ),
- mActiveProxy( 0 ) {}
+ Private() : mStackedWidget(0), mActiveProxy(0), mActiveScroller(0), \
mActiveModule(0) { }
QStackedWidget * mStackedWidget;
+ KCModuleProxy * mActiveProxy;
+ QScrollArea * mActiveScroller;
KCModuleInfo * mActiveModule;
- KCModuleProxy * mActiveProxy;
- QMap<KCModuleInfo*, QScrollArea*> mProxies;
};
-ModuleView::ModuleView( QWidget *parent ) : KDialog( parent ), d( new Private() )
+ModuleView::ModuleView( QWidget * parent ) : KDialog( parent ), d( new Private() )
{
+ // Configure the dialog
setWindowFlags( Qt::Widget );
setButtons( KDialog::Help | KDialog::Default | KDialog::Apply | KDialog::Reset \
); setDefaultButton( KDialog::Reset );
-
- d->mStackedWidget = new QStackedWidget( this );
- setMainWidget( d->mStackedWidget );
+ // Prevent the buttons from being used
+ enableButton(Apply, false);
+ enableButton(Reset, false);
+ enableButton(Default, false);
+ enableButton(Help, false);
+ // Connect up the buttons
+ connect( this, SIGNAL(applyClicked()), this, SLOT(saveModule()));
+ connect( this, SIGNAL(resetClicked()), this, SLOT(loadModule()));
+ connect( this, SIGNAL(helpClicked()), this, SLOT(invokeHelp()));
}
ModuleView::~ModuleView()
@@ -57,7 +66,11 @@
KCModuleInfo * ModuleView::activeModule() const
{
- return d->mActiveModule;
+ if( d->mActiveModule ) {
+ return d->mActiveModule;
+ } else {
+ return 0;
+ }
}
const KAboutData * ModuleView::aboutData() const
@@ -71,28 +84,124 @@
void ModuleView::loadModule( KCModuleInfo * module )
{
+ if( !module ) {
+ return;
+ }
+
+ if( !module->service() ) {
+ kWarning() << "ModuleInfo has no associated KService" ;
+ return;
+ }
+ if ( !KAuthorized::authorizeControlModule( module->service()->menuId() ) ) {
+ kWarning() << "Not authorised to load module" ;
+ return;
+ }
+ if( module->service()->noDisplay() ) {
+ return;
+ }
+ if( d->mActiveScroller ) {
+ closeModule();
+ }
+ // Set it as the active module
d->mActiveModule = module;
- if ( module ) {
- if ( d->mProxies.contains( module ) ) {
- kDebug() << "already exists";
- d->mStackedWidget->setCurrentWidget( d->mProxies[module] );
- } else {
- QScrollArea *scrollArea = new QScrollArea( d->mStackedWidget );
- KCModuleProxy *proxy = new KCModuleProxy( *module, scrollArea );
- d->mActiveProxy = proxy;
- scrollArea->setWidget( proxy );
- scrollArea->setWidgetResizable( true );
- scrollArea->setFrameStyle( QFrame::NoFrame );
- scrollArea->viewport()->setAutoFillBackground( false );
- proxy->setAutoFillBackground( false );
- d->mStackedWidget->addWidget( scrollArea );
- d->mStackedWidget->setCurrentWidget( scrollArea );
- d->mProxies.insert( module, scrollArea );
- }
+ // Create the items
+ d->mActiveScroller = new QScrollArea( this );
+ d->mActiveProxy = new KCModuleProxy( *module, d->mActiveScroller );
+ // Prepare the module
+ d->mActiveProxy->setAutoFillBackground( false );
+ // Prepare the scroll area
+ d->mActiveScroller->setWidgetResizable( true );
+ d->mActiveScroller->setFrameStyle( QFrame::NoFrame );
+ d->mActiveScroller->viewport()->setAutoFillBackground( false );
+ d->mActiveScroller->setWidget( d->mActiveProxy );
+ // Allow it to signal properly
+ connect( this, SIGNAL(defaultClicked()), d->mActiveProxy, SLOT(defaults()));
+ connect( d->mActiveProxy, SIGNAL(changed(bool)), this, \
SLOT(moduleChanged(bool))); + // Set it to be shown and signal that
+ setMainWidget( d->mActiveScroller );
+ emit moduleSwitched();
+}
- emit moduleLoaded();
+bool ModuleView::resolveChanges()
+{
+ if( !d->mActiveProxy || !d->mActiveProxy->changed() ) {
+ return true;
}
- emit moduleChanged();
+
+ // Let the user decide
+ int queryUser = KMessageBox::warningYesNoCancel(
+ this,
+ i18n("There are unsaved changes in the active module.\n"
+ "Do you want to apply the changes or discard them?"),
+ i18n("Unsaved Changes"),
+ KStandardGuiItem::save(),
+ KStandardGuiItem::discard(),
+ KStandardGuiItem::cancel() );
+
+ switch (queryUser) {
+ case KMessageBox::Yes:
+ d->mActiveProxy->save();
+ return true;
+
+ case KMessageBox::No:
+ d->mActiveProxy->load();
+ return true;
+
+ case KMessageBox::Cancel:
+ return false;
+
+ default:
+ Q_ASSERT(false);
+ return false;
+ }
}
+void ModuleView::closeModule()
+{
+ if( !d->mActiveProxy ) {
+ return;
+ }
+ if( !resolveChanges() ) {
+ return;
+ }
+ d->mActiveScroller->deleteLater();
+ d->mActiveScroller = 0;
+ d->mActiveProxy = 0;
+}
+
+void ModuleView::saveModule()
+{
+ if( d->mActiveProxy ) {
+ d->mActiveProxy->save();
+ }
+}
+
+void ModuleView::loadModule()
+{
+ if( d->mActiveProxy ) {
+ d->mActiveProxy->load();
+ }
+}
+
+void ModuleView::invokeHelp()
+{
+ if( !d->mActiveProxy ) {
+ return;
+ }
+
+ QString docPath = d->mActiveProxy->moduleInfo().docPath();
+ if( docPath.isEmpty() ) {
+ return;
+ }
+ KUrl url( KUrl("help:/"), docPath );
+ QProcess::startDetached("khelpcenter", QStringList() << url.url());
+}
+
+void ModuleView::moduleChanged(bool change)
+{
+ enableButton( Apply, change );
+ enableButton( Reset, change );
+ emit configurationChanged(change);
+}
+
#include "ModuleView.moc"
--- trunk/playground/base/kcontrol4/src/core/ModuleView.h #933995:933996
@@ -32,18 +32,24 @@
Q_OBJECT
public:
- explicit ModuleView( QWidget *parent = 0 );
+ explicit ModuleView(QWidget * parent = 0);
~ModuleView();
KCModuleInfo * activeModule() const;
const KAboutData * aboutData() const;
+ bool resolveChanges();
public Q_SLOTS:
- void loadModule( KCModuleInfo * module );
+ void loadModule(KCModuleInfo * module);
+ void moduleChanged(bool change);
+ void invokeHelp();
+ void loadModule();
+ void saveModule();
+ void closeModule();
Q_SIGNALS:
- void moduleChanged();
- void moduleLoaded();
+ void moduleSwitched();
+ void configurationChanged(bool change);
private:
class Private;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic