koscript_scriptmenu.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <kstandarddirs.h>
00021 #include <kinstance.h>
00022 #include <klocale.h>
00023
00024 #include "koscript_scriptmenu.h"
00025 #include "kscript.h"
00026
00027 #include <kpopupmenu.h>
00028 #include <kmessagebox.h>
00029
00030 KScriptMenu::KScriptMenu( const DCOPRef& ref, KInstance* instance, const QString& text, QObject* parent, const char* name )
00031 : KActionMenu( text, parent, name ), m_ref( ref ), m_instance( instance ), m_interpreter( 0 )
00032 {
00033 m_actions.setAutoDelete( TRUE );
00034 m_filenames.setAutoDelete( TRUE );
00035
00036 QStringList scripts = m_instance->dirs()->findAllResources( "scripts", "*", TRUE );
00037 QStringList::Iterator it = scripts.begin();
00038 for( ; it != scripts.end(); ++it )
00039 {
00040 QString file = *it;
00041 int pos = file.findRev( '.' );
00042 if ( pos != -1 )
00043 file = file.left( pos );
00044
00045 QString name = file;
00046 pos = file.findRev( '/' );
00047 name = file.mid( pos + 1 );
00048 KAction* action = new KAction( name, 0, (QObject*)0, name.latin1() );
00049 m_actions.append( action );
00050 action->plug( popupMenu() );
00051 connect( action, SIGNAL( activated() ), this, SLOT( slotActivated() ) );
00052
00053 m_filenames.insert( action, new QString( *it ) );
00054 }
00055 }
00056
00057 KScriptMenu::~KScriptMenu()
00058 {
00059 if ( m_interpreter )
00060 delete m_interpreter;
00061 }
00062
00063 void KScriptMenu::slotActivated()
00064 {
00065 QString* str = m_filenames[ (void*)sender() ];
00066 if ( !str )
00067 return;
00068
00069 kdDebug() << "Running " << str << endl;
00070
00071 if ( !m_interpreter )
00072 m_interpreter = new KSInterpreter();
00073
00074 QStringList args;
00075 args.append( m_ref.app() );
00076 args.append( m_ref.object() );
00077
00078 QString ex = m_interpreter->runScript( *str, args );
00079 if ( !ex.isEmpty() )
00080 {
00081 KMessageBox::error( 0, ex, i18n("KScript Error"));
00082 }
00083 }
00084
00085 #include "koscript_scriptmenu.moc"
This file is part of the documentation for lib Library Version 1.3.5.