dcopstart.cpp
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 
00078 
00079 int main( int argc, char** argv )
00080 {
00081     if (( argc < 2) || (argv[1][0] == '-' )) {
00082     fprintf( stderr, "Usage: dcopstart <application> [url1] [url2] ...\n" );
00083     exit(0);
00084     }
00085 
00086     DCOPClient client;
00087     client.attach();
00088     dcop = &client;
00089 
00090     QCString app;
00091     QCString objid;
00092     QCString function;
00093     
00094     startApp( argv[1], argc - 2, (const char**)&argv[2] );
00095 
00096     return 0;
00097 }
 
This file is part of the documentation for dcop Library Version 3.2.0.