KNotify
notifybyexecute.cpp
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2005-2006 by Olivier Goffart <ogoffart at kde.org> 00003 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2, or (at your option) 00008 any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 */ 00020 00021 #include "notifybyexecute.h" 00022 00023 #include <QHash> 00024 #include <QProcess> 00025 00026 #include "knotifyconfig.h" 00027 00028 #include <kdebug.h> 00029 #include <kmacroexpander.h> 00030 00031 00032 00033 00034 NotifyByExecute::NotifyByExecute(QObject *parent) : KNotifyPlugin(parent) 00035 { 00036 } 00037 00038 00039 NotifyByExecute::~NotifyByExecute() 00040 { 00041 } 00042 00043 00044 00045 void NotifyByExecute::notify( int id, KNotifyConfig * config ) 00046 { 00047 QString command=config->readEntry( "Execute" ); 00048 00049 kDebug(300) << command; 00050 00051 if (!command.isEmpty()) { 00052 // kDebug(300) << "executing command '" << command << "'"; 00053 QHash<QChar,QString> subst; 00054 subst.insert( 'e', config->eventid ); 00055 subst.insert( 'a', config->appname ); 00056 subst.insert( 's', config->text ); 00057 subst.insert( 'w', QString::number( (int)config->winId )); 00058 subst.insert( 'i', QString::number( id )); 00059 QString execLine = KMacroExpander::expandMacrosShellQuote( command, subst ); 00060 if ( execLine.isEmpty() ) 00061 execLine = command; // fallback 00062 //TODO fixme on WIN32 00063 QProcess::startDetached( "/bin/sh", QStringList() << "-c" << execLine ); 00064 } 00065 00066 finish( id ); 00067 } 00068 00069 #include "notifybyexecute.moc"