• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

dcop

dcopstart.cpp

Go to the documentation of this file.
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 #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     /*char **args = 0;*/
00096     startApp( argv[1], argc - 2, (const char**)&argv[2] );
00097 
00098     return 0;
00099 }

dcop

Skip menu "dcop"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal