From kde-commits Mon Dec 06 16:57:36 2010 From: Marc Mutz Date: Mon, 06 Dec 2010 16:57:36 +0000 To: kde-commits Subject: branches/work/komo/kdelibs/kutils Message-Id: <20101206165736.EF996AC8A4 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=129165469431630 SVN commit 1204293 by mutz: KCMultiDialog: allow to add modules that are already instantiated, for WINCE M +32 -15 kcmultidialog.cpp M +7 -0 kcmultidialog.h M +1 -0 kcmultidialog_p.h --- branches/work/komo/kdelibs/kutils/kcmultidialog.cpp #1204292:1204293 @@ -328,11 +328,28 @@ //KAuthorized::authorizeControlModule( moduleInfo.service()->menuId() ) is //checked in noDisplay already - if ( moduleInfo.service()->noDisplay() ) + if ( moduleInfo.noDisplay() ) return 0; - KCModuleProxy *kcm = new KCModuleProxy(moduleInfo, 0, args); + Q_D(KCMultiDialog); + return d->addModuleInternal( moduleInfo, new KCModuleProxy(moduleInfo, 0, args), parentItem ); +} +KPageWidgetItem* KCMultiDialog::addModule( const KCModuleInfo& moduleInfo, KCModule * module, KPageWidgetItem *parentItem ) +{ + Q_D(KCMultiDialog); + if ( moduleInfo.noDisplay() ) + return 0; + else + return d->addModuleInternal( moduleInfo, new KCModuleProxy( moduleInfo, module ), parentItem ); +} + +KPageWidgetItem* KCMultiDialogPrivate::addModuleInternal( const KCModuleInfo& moduleInfo, KCModuleProxy * kcm, KPageWidgetItem *parentItem ) +{ + Q_Q(KCMultiDialog); + if ( !kcm ) + return 0; + kDebug(710) << moduleInfo.moduleName(); KPageWidgetItem *item = new KPageWidgetItem(kcm, moduleInfo.moduleName()); @@ -346,7 +363,7 @@ item->setProperty("_k_weight", moduleInfo.weight()); bool updateCurrentPage = false; - const KPageWidgetModel *model = qobject_cast(pageWidget()->model()); + const KPageWidgetModel *model = qobject_cast(q->pageWidget()->model()); Q_ASSERT(model); if (parentItem) { const QModelIndex parentIndex = model->index(parentItem); @@ -357,14 +374,14 @@ if (siblingItem->property("_k_weight").toInt() > moduleInfo.weight()) { // the item we found is heavier than the new module kDebug(710) << "adding KCM " << item->name() << " before " << siblingItem->name(); - insertPage(siblingItem, item); + q->insertPage(siblingItem, item); break; } } if (row >= siblingCount) { // the new module is either the first or the heaviest item kDebug(710) << "adding KCM " << item->name() << " with parent " << parentItem->name(); - addSubPage(parentItem, item); + q->addSubPage(parentItem, item); } } else { const int siblingCount = model->rowCount(); @@ -374,8 +391,8 @@ if (siblingItem->property("_k_weight").toInt() > moduleInfo.weight()) { // the item we found is heavier than the new module kDebug(710) << "adding KCM " << item->name() << " before " << siblingItem->name(); - insertPage(siblingItem, item); - if ( siblingItem == currentPage() ) + q->insertPage(siblingItem, item); + if ( siblingItem == q->currentPage() ) updateCurrentPage = true; break; @@ -384,24 +401,24 @@ if (row == siblingCount) { // the new module is either the first or the heaviest item kDebug(710) << "adding KCM " << item->name() << " at the top level"; - addPage(item); + q->addPage(item); } } - connect(kcm, SIGNAL(changed(bool)), this, SLOT(_k_clientChanged())); - connect(kcm->realModule(), SIGNAL(rootOnlyMessageChanged(bool,QString)), this, SLOT(_k_updateHeader(bool,QString))); + QObject::connect(kcm, SIGNAL(changed(bool)), q, SLOT(_k_clientChanged())); + QObject::connect(kcm->realModule(), SIGNAL(rootOnlyMessageChanged(bool,QString)), q, SLOT(_k_updateHeader(bool,QString))); - Q_D(KCMultiDialog); KCMultiDialogPrivate::CreatedModule cm; cm.kcm = kcm; cm.item = item; + if ( moduleInfo.service() ) cm.componentNames = moduleInfo.service()->property( "X-KDE-ParentComponents" ).toStringList(); - d->modules.append( cm ); + modules.append( cm ); - if ( d->modules.count() == 1 || updateCurrentPage ) + if ( modules.count() == 1 || updateCurrentPage ) { - setCurrentPage( item ); - d->updateButtons(kcm); + q->setCurrentPage( item ); + updateButtons(kcm); } return item; } --- branches/work/komo/kdelibs/kutils/kcmultidialog.h #1204292:1204293 @@ -27,6 +27,7 @@ #include class KCMultiDialogPrivate; +class KCModule; /** * @short A class that offers a KPageDialog containing arbitrary @@ -88,6 +89,12 @@ const QStringList& args = QStringList() ); /** + * \overload + * Takes an already-loaded KCModule as parameter. + **/ + KPageWidgetItem* addModule( const KCModuleInfo& moduleinfo, KCModule *module, KPageWidgetItem *parent = 0 ); + + /** * Removes all modules from the dialog. */ void clear(); --- branches/work/komo/kdelibs/kutils/kcmultidialog_p.h #1204292:1204293 @@ -58,6 +58,7 @@ private: void init(); void apply(); + KPageWidgetItem* addModuleInternal( const KCModuleInfo& moduleInfo, KCModuleProxy * kcm, KPageWidgetItem *parentItem ); }; #endif // KCMULTIDIALOG_P_H