# dcop Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# dcopstart.cpp

    00001 /*****************************************************************
    00002 Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
    00003
    00004 Permission is hereby granted, free of charge, to any person obtaining a copy
    00005 of this software and associated documentation files (the "Software"), to deal
    00006 in the Software without restriction, including without limitation the rights
    00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00008 copies of the Software, and to permit persons to whom the Software is
    00009 furnished to do so, subject to the following conditions:
    00010
    00011 The above copyright notice and this permission notice shall be included in
    00012 all copies or substantial portions of the Software.
    00013
    00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00017 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    00018 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00019 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    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     /*char **args = 0;*/
    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.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:16:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003