lib Library API Documentation

koscript_scriptmenu.cc

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 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"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 28 04:04:01 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003