00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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