dcop
dcopstart.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "../kdatastream.h"
00024 #include "../dcopclient.h"
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <ctype.h>
00028
00029 #include <qstringlist.h>
00030
00031 static DCOPClient* dcop = 0;
00032
00033 void startApp(const char *_app, int argc, const char **args)
00034 {
00035 const char *function = 0;
00036 QString app = QString::fromLatin1(_app);
00037 if (app.endsWith(".desktop"))
00038 function = "start_service_by_desktop_path(QString,QStringList)";
00039 else
00040 function = "start_service_by_desktop_name(QString,QStringList)";
00041 QStringList URLs;
00042 for(int i = 0; i < argc; i++)
00043 {
00044 URLs.append(QString::fromLocal8Bit(args[i]));
00045 }
00046
00047 QByteArray data, replyData;
00048 QCString replyType;
00049 QDataStream arg(data, IO_WriteOnly);
00050 arg << app << URLs;
00051
00052 if ( !dcop->call( "klauncher", "klauncher", function, data, replyType, replyData) ) {
00053 qWarning( "call failed");
00054 exit(1);
00055 } else {
00056 QDataStream reply(replyData, IO_ReadOnly);
00057
00058 if ( replyType != "serviceResult" )
00059 {
00060 qWarning( "unexpected result '%s'", replyType.data());
00061 exit(1);
00062 }
00063 int result;
00064 QCString dcopName;
00065 QString error;
00066 reply >> result >> dcopName >> error;
00067 if (result != 0)
00068 {
00069 qWarning("Error: %s", error.local8Bit().data());
00070 exit(1);
00071 }
00072 if (!dcopName.isEmpty())
00073 puts(dcopName.data());
00074 }
00075 }
00076
00077 #ifdef Q_OS_WIN
00078 # define main kdemain
00079 #endif
00080
00081 int main( int argc, char** argv )
00082 {
00083 if (( argc < 2) || (argv[1][0] == '-' )) {
00084 fprintf( stderr, "Usage: dcopstart <application> [url1] [url2] ...\n" );
00085 exit(0);
00086 }
00087
00088 DCOPClient client;
00089 client.attach();
00090 dcop = &client;
00091
00092 QCString app;
00093 QCString objid;
00094 QCString function;
00095
00096 startApp( argv[1], argc - 2, (const char**)&argv[2] );
00097
00098 return 0;
00099 }