killer.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <kcmdlineargs.h>
00026 #include <kapplication.h>
00027 #include <kmessagebox.h>
00028 #include <kprocess.h>
00029 #include <klocale.h>
00030 #include <unistd.h>
00031 #include <kwin.h>
00032 #include <X11/Xlib.h>
00033
00034 static const KCmdLineOptions options[] =
00035 {
00036
00037 { "pid <pid>", "PID of the application to terminate.", 0 },
00038 { "hostname <hostname>", "Hostname on which the application is running.", 0 },
00039 { "windowname <caption>", "Caption of the window to be terminated.", 0 },
00040 { "applicationname <name>", "Name of the application to be terminated.", 0 },
00041 { "wid <id>", "ID of resource belonging to the application.", 0 },
00042 { "timestamp <time>", "Time of user action causing killing.", 0 },
00043 KCmdLineLastOption
00044 };
00045
00046 int main( int argc, char* argv[] )
00047 {
00048 KGlobal::locale()->setMainCatalogue( "kwin" );
00049 KCmdLineArgs::init( argc, argv, "kwin_killer_helper", I18N_NOOP( "KWin" ),
00050 I18N_NOOP( "KWin helper utility" ), "1.0" );
00051 KCmdLineArgs::addCmdLineOptions( options );
00052 KApplication app;
00053 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00054 QCString hostname = args->getOption( "hostname" );
00055 bool pid_ok = false;
00056 pid_t pid = args->getOption( "pid" ).toULong( &pid_ok );
00057 QString caption = QString::fromUtf8( args->getOption( "windowname" ));
00058 QString appname = QString::fromLatin1( args->getOption( "applicationname" ));
00059 bool id_ok = false;
00060 Window id = args->getOption( "wid" ).toULong( &id_ok );
00061 bool time_ok = false;
00062 Time timestamp =args->getOption( "timestamp" ).toULong( &time_ok );
00063 args->clear();
00064 if( !pid_ok || pid == 0 || !id_ok || id == None || !time_ok || timestamp == CurrentTime
00065 || hostname.isEmpty() || caption.isEmpty() || appname.isEmpty())
00066 {
00067 KCmdLineArgs::usage( i18n( "This helper utility is not supposed to be called directly!" ));
00068 return 1;
00069 }
00070 QString question = i18n(
00071 "<qt>Window with title \"<b>%2</b>\" is not responding. "
00072 "This window belongs to application <b>%1</b> (PID=%3, hostname=%4).<p>"
00073 "Do you wish to terminate this application? (All unsaved data in this application will be lost.)</qt>" )
00074 .arg( appname ).arg( caption ).arg( pid ).arg( hostname );
00075 app.updateUserTimestamp( timestamp );
00076 if( KMessageBox::warningYesNoWId( id, question, "" ) == KMessageBox::Yes )
00077 {
00078 if( hostname != "localhost" )
00079 {
00080 KProcess proc;
00081 proc << "xon" << hostname << "kill" << pid;
00082 proc.start( KProcess::DontCare );
00083 }
00084 else
00085 ::kill( pid, SIGKILL );
00086 XKillClient( qt_xdisplay(), id );
00087 }
00088 }
This file is part of the documentation for kwin Library Version 3.2.2.