kwin Library API Documentation

killer.cpp

00001 /****************************************************************************
00002 
00003  Copyright (C) 2003 Lubos Lunak        <l.lunak@kde.org>
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a
00006 copy of this software and associated documentation files (the "Software"),
00007 to deal in the Software without restriction, including without limitation
00008 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00009 and/or sell copies of the Software, and to permit persons to whom the
00010 Software is furnished to do so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00018 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00020 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00021 DEALINGS IN THE SOFTWARE.
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     // no need for I18N_NOOP(), this is not supposed to be used directly
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     KLocale::setMainCatalogue( "kwin" ); // the messages are in kwin's .po file
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     }
KDE Logo
This file is part of the documentation for kwin Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 11:21:59 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003