| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kpanelappmenu.cpp

    00001 /*
    00002
    00003 (C) Daniel M. Duley <mosfet@kde.org>
    00004 (C) Matthias Ettrich <ettrich@kde.org>
    00005
    00006 Permission is hereby granted, free of charge, to any person obtaining a copy
    00007 of this software and associated documentation files (the "Software"), to deal
    00008 in the Software without restriction, including without limitation the rights
    00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00010 copies of the Software, and to permit persons to whom the Software is
    00011 furnished to do so, subject to the following conditions:
    00012
    00013 The above copyright notice and this permission notice shall be included in
    00014 all copies or substantial portions of the Software.
    00015
    00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00019 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00022
    00023 */
    00024
    00025 #include "kpanelappmenu.h"
    00026 #include <qstringlist.h>
    00027 #include <dcopclient.h>
    00028 #include <kapplication.h>
    00029 #include <kdebug.h>
    00030
    00031 static int panelmenu_get_seq_id()
    00032 {
    00033     static int panelmenu_seq_no = -2;
    00034     return panelmenu_seq_no--;
    00035 }
    00036
    00037
    00038 KPanelAppMenu::KPanelAppMenu(const QString &title, QObject *parent,
    00039                        const char *name)
    00040     : QObject(parent, name), DCOPObject()
    00041 {
    00042     init(QString::null, title);
    00043 }
    00044
    00045 KPanelAppMenu::KPanelAppMenu(const QPixmap &icon, const QString &title,
    00046                        QObject *parent, const char *name)
    00047 : QObject(parent, name), DCOPObject()
    00048 {
    00049
    00050     init(icon, title);
    00051 }
    00052
    00053
    00054 KPanelAppMenu::KPanelAppMenu(QObject *parent, const char *name)
    00055   : QObject(parent, name), DCOPObject(name)
    00056 {
    00057   realObjId = name;
    00058 }
    00059
    00060
    00061 void KPanelAppMenu::init(const QPixmap &icon, const QString &title)
    00062 {
    00063     DCOPClient *client = kapp->dcopClient();
    00064     if(!client->isAttached())
    00065     client->attach();
    00066     QByteArray sendData, replyData;
    00067     QCString replyType;
    00068     {
    00069     QDataStream stream(sendData, IO_WriteOnly);
    00070     stream << icon << title;
    00071     if ( client->call("kicker", "kickerMenuManager", "createMenu(QPixmap,QString)", sendData, replyType, replyData ) ) {
    00072       if (replyType != "QCString")
    00073         kdDebug() << "error! replyType for createMenu should be QCstring in KPanelAppMenu::init" << endl;
    00074       else {
    00075         QDataStream reply( replyData, IO_ReadOnly );
    00076         reply >> realObjId;
    00077       }
    00078     }
    00079     }
    00080     {
    00081     QDataStream stream(sendData, IO_WriteOnly);
    00082     stream << QCString("activated(int)") << client->appId() << objId();
    00083     client->send("kicker", realObjId, "connectDCOPSignal(QCString,QCString,QCString)", sendData);
    00084     }
    00085 }
    00086
    00087 KPanelAppMenu::~KPanelAppMenu()
    00088 {
    00089     DCOPClient *client = kapp->dcopClient();
    00090     QByteArray sendData;
    00091     QDataStream stream(sendData, IO_WriteOnly);
    00092     stream << realObjId;
    00093     client->send("kicker", "kickerMenuManager", "removeMenu", sendData );
    00094 }
    00095
    00096 int KPanelAppMenu::insertItem(const QPixmap &icon, const QString &text, int id )
    00097 {
    00098     if ( id < 0 )
    00099     id = panelmenu_get_seq_id();
    00100     DCOPClient *client = kapp->dcopClient();
    00101     QByteArray sendData;
    00102     QDataStream stream(sendData, IO_WriteOnly);
    00103     stream << icon << text << id;
    00104     client->send("kicker", realObjId, "insertItem(QPixmap,QString,int)", sendData );
    00105     return id;
    00106 }
    00107
    00108
    00109 KPanelAppMenu *KPanelAppMenu::insertMenu(const QPixmap &icon, const QString &text, int id )
    00110 {
    00111     if ( id < 0 )
    00112         id = panelmenu_get_seq_id();
    00113     DCOPClient *client = kapp->dcopClient();
    00114     QByteArray sendData, replyData;
    00115     QCString replyType;
    00116     QDataStream stream(sendData, IO_WriteOnly);
    00117     stream << icon << text << id;
    00118     client->call("kicker", realObjId, "insertMenu(QPixmap,QString,int)", sendData, replyType, replyData );
    00119     if ( replyType != "QCString")
    00120       return 0;
    00121     QDataStream ret(replyData, IO_ReadOnly);
    00122     QCString subid;
    00123     ret >> subid;
    00124
    00125     QByteArray sendData2;
    00126     QDataStream stream2(sendData2, IO_WriteOnly);
    00127     stream2 << QCString("activated(int)") << client->appId() << subid;
    00128     client->send("kicker", subid, "connectDCOPSignal(QCString,QCString,QCString)", sendData2);
    00129
    00130     return new KPanelAppMenu(this, subid);
    00131 }
    00132
    00133
    00134 int KPanelAppMenu::insertItem(const QString &text, int id )
    00135 {
    00136     if ( id < 0 )
    00137     id = panelmenu_get_seq_id();
    00138     DCOPClient *client = kapp->dcopClient();
    00139     QByteArray sendData;
    00140     QDataStream stream(sendData, IO_WriteOnly);
    00141     stream << text << id;
    00142     client->send("kicker", realObjId, "insertItem(QString,int)", sendData );
    00143     return id;
    00144 }
    00145
    00146
    00147 void KPanelAppMenu::clear()
    00148 {
    00149     DCOPClient *client = kapp->dcopClient();
    00150     QByteArray sendData;
    00151     client->send("kicker", realObjId, "clear()", sendData);
    00152 }
    00153
    00154
    00155 bool KPanelAppMenu::process(const QCString &fun, const QByteArray &data,
    00156              QCString &replyType, QByteArray &)
    00157 {
    00158     if ( fun == "activated(int)" ) {
    00159     QDataStream dataStream( data, IO_ReadOnly );
    00160     int id;
    00161     dataStream >> id;
    00162     emit activated( id );
    00163     replyType = "void";
    00164     return true;
    00165     }
    00166     return false;
    00167 }
    00168
    00169
    00170 #include "kpanelappmenu.moc"
    00171
    00172
    00173
    00174
    00175
    00176
    00177
    00178
    00179
    00180
    00181
    00182

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:19 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003