From kde-commits Sun Jul 31 22:10:13 2005 From: Kun Xi Date: Sun, 31 Jul 2005 22:10:13 +0000 To: kde-commits Subject: branches/work/soc-kdepim-scripting/kontact/src Message-Id: <1122847813.718220.25704.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=112284782729633 SVN commit 441775 by kunxi: Now, everything works. We just need to refactor scriptManager. -- We don't need a singleton pattern. Each part would have a scriptManager, and the part-specific menu items are connected to it. With GUI rc, the part-specific menu items are merged to the Kontact Add-on Menu. M +5 -3 kontactui.rc M +28 -12 mainwindow.cpp M +1 -0 mainwindow.h --- branches/work/soc-kdepim-scripting/kontact/src/kontactui.rc #441774:441775 @@ -12,6 +12,11 @@ + &Add-ons + + + + &Settings @@ -27,9 +32,6 @@ --> - &Tools - - &Help --- branches/work/soc-kdepim-scripting/kontact/src/mainwindow.cpp #441774:441775 @@ -65,11 +65,6 @@ #include #include -#include -#include -#include "kjsengine.h" -#include "scriptmanager.h" - #include "aboutdialog.h" #include "iconsidepane.h" #include "mainwindow.h" @@ -79,6 +74,12 @@ #include "statusbarprogresswidget.h" #include "broadcaststatus.h" +#include +#include +#include +#include "kjsengine.h" +#include "scriptmanager.h" + using namespace Kontact; class SettingsDialogWrapper : public KSettings::Dialog @@ -106,10 +107,11 @@ // Set this to be the group leader for all subdialogs - this means // modal subdialogs will only affect this dialog, not the other windows setWFlags( getWFlags() | WGroupLeader ); - setupScripts(); initGUI(); initObject(); + + setupScripts(); publishObjects(); } @@ -893,12 +895,9 @@ void MainWindow::setupScripts() { // refered to kate/app/katemainwindow.cpp - kdDebug() << "setupScripts" << endl; - kdDebug() << "path:" << QString(kapp->name()) +"/scripts/" << endl; QStringList scripts = KGlobal::dirs()->findAllResources("data", QString(kapp->name()) + "/scripts/*.desktop", false, true ); for (QStringList::Iterator it = scripts.begin(); it != scripts.end(); ++it ) { - kdDebug() << "finding Add-on " << *it << endl; KPIM::ScriptManager::instance()->addScript( *it ); } } @@ -906,17 +905,23 @@ void MainWindow::publishObjects() { KPIM::KJSEngine::instance()->addObject(this, "Kontact"); + QPtrList actions; + QSignalMapper *addonMapper = new QSignalMapper( this ); + connect( addonMapper, SIGNAL( mapped( const QString& )), this, SLOT( runScript( const QString& ))); QDictIterator it ( KPIM::ScriptManager::instance()->scripts()); for(; it.current(); ++it ) { KPIM::ScriptInfo* si = it.current(); - kdDebug(5600) << "Loading Add-on: " << it.currentKey() << endl; + kdDebug() << "Loading Add-on: " << it.currentKey() << endl; if( si->loadOption == "Autoload" ) KPIM::KJSEngine::instance()->runFile( si->scriptName ); else { if ( si->loadOption == "LoadOnDemand" ) { - scriptMenu->popupMenu()->insertItem( it.currentKey()); + KAction* newAction = new KAction(it.currentKey(), 0, 0, 0 ); + connect( newAction, SIGNAL( activated() ), addonMapper, SLOT( map()) ); + addonMapper->setMapping( newAction, newAction->text() ); + actions.append( newAction ); } else { kdDebug(5600) << "WARNING: unknown LoadOption for " << it.currentKey() << endl; continue; @@ -924,7 +929,10 @@ } } - connect( scriptMenu->popupMenu(), SIGNAL(activated( int )), this, SLOT(runScript( int ))); + unplugActionList( "addons_kontact" ); + plugActionList( "addons_kontact", actions ); + + //connect( scriptMenu->popupMenu(), SIGNAL(activated( int )), this, SLOT(runScript( int ))); } void MainWindow::runScript( int idx ) @@ -936,4 +944,12 @@ KPIM::ScriptManager::instance()->runScript( menu ); } + +void MainWindow::runScript( const QString& idx ) +{ + QString menu = idx; + menu.remove('&'); + KPIM::ScriptManager::instance()->runScript( menu ); +} + #include "mainwindow.moc" --- branches/work/soc-kdepim-scripting/kontact/src/mainwindow.h #441774:441775 @@ -133,6 +133,7 @@ void configureShortcuts(); void configureToolbars(); void runScript( int idx ); + void runScript( const QString& idx ); private: QFrame *mTopWidget;