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 <tqstringlist.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 TQString &title, TQObject *parent, 00039 const char *name) 00040 : TQObject(parent, name), DCOPObject() 00041 { 00042 init(TQString(), title); 00043 } 00044 00045 KPanelAppMenu::KPanelAppMenu(const TQPixmap &icon, const TQString &title, 00046 TQObject *parent, const char *name) 00047 : TQObject(parent, name), DCOPObject() 00048 { 00049 00050 init(icon, title); 00051 } 00052 00053 00054 KPanelAppMenu::KPanelAppMenu(TQObject *parent, const char *name) 00055 : TQObject(parent, name), DCOPObject(name) 00056 { 00057 realObjId = name; 00058 } 00059 00060 00061 void KPanelAppMenu::init(const TQPixmap &icon, const TQString &title) 00062 { 00063 DCOPClient *client = kapp->dcopClient(); 00064 if(!client->isAttached()) 00065 client->attach(); 00066 TQByteArray sendData, replyData; 00067 TQCString replyType; 00068 { 00069 TQDataStream stream(sendData, IO_WriteOnly); 00070 stream << icon << title; 00071 if ( client->call("kicker", "kickerMenuManager", "createMenu(TQPixmap,TQString)", sendData, replyType, replyData ) ) { 00072 if (replyType != "TQCString") 00073 kdDebug() << "error! replyType for createMenu should be QCstring in KPanelAppMenu::init" << endl; 00074 else { 00075 TQDataStream reply( replyData, IO_ReadOnly ); 00076 reply >> realObjId; 00077 } 00078 } 00079 } 00080 { 00081 TQDataStream stream(sendData, IO_WriteOnly); 00082 stream << TQCString("activated(int)") << client->appId() << objId(); 00083 client->send("kicker", realObjId, "connectDCOPSignal(TQCString,TQCString,TQCString)", sendData); 00084 } 00085 } 00086 00087 KPanelAppMenu::~KPanelAppMenu() 00088 { 00089 DCOPClient *client = kapp->dcopClient(); 00090 TQByteArray sendData; 00091 TQDataStream stream(sendData, IO_WriteOnly); 00092 stream << realObjId; 00093 client->send("kicker", "kickerMenuManager", "removeMenu", sendData ); 00094 } 00095 00096 int KPanelAppMenu::insertItem(const TQPixmap &icon, const TQString &text, int id ) 00097 { 00098 if ( id < 0 ) 00099 id = panelmenu_get_seq_id(); 00100 DCOPClient *client = kapp->dcopClient(); 00101 TQByteArray sendData; 00102 TQDataStream stream(sendData, IO_WriteOnly); 00103 stream << icon << text << id; 00104 client->send("kicker", realObjId, "insertItem(TQPixmap,TQString,int)", sendData ); 00105 return id; 00106 } 00107 00108 00109 KPanelAppMenu *KPanelAppMenu::insertMenu(const TQPixmap &icon, const TQString &text, int id ) 00110 { 00111 if ( id < 0 ) 00112 id = panelmenu_get_seq_id(); 00113 DCOPClient *client = kapp->dcopClient(); 00114 TQByteArray sendData, replyData; 00115 TQCString replyType; 00116 TQDataStream stream(sendData, IO_WriteOnly); 00117 stream << icon << text << id; 00118 client->call("kicker", realObjId, "insertMenu(TQPixmap,TQString,int)", sendData, replyType, replyData ); 00119 if ( replyType != "TQCString") 00120 return 0; 00121 TQDataStream ret(replyData, IO_ReadOnly); 00122 TQCString subid; 00123 ret >> subid; 00124 00125 TQByteArray sendData2; 00126 TQDataStream stream2(sendData2, IO_WriteOnly); 00127 stream2 << TQCString("activated(int)") << client->appId() << subid; 00128 client->send("kicker", subid, "connectDCOPSignal(TQCString,TQCString,TQCString)", sendData2); 00129 00130 return new KPanelAppMenu(this, subid); 00131 } 00132 00133 00134 int KPanelAppMenu::insertItem(const TQString &text, int id ) 00135 { 00136 if ( id < 0 ) 00137 id = panelmenu_get_seq_id(); 00138 DCOPClient *client = kapp->dcopClient(); 00139 TQByteArray sendData; 00140 TQDataStream stream(sendData, IO_WriteOnly); 00141 stream << text << id; 00142 client->send("kicker", realObjId, "insertItem(TQString,int)", sendData ); 00143 return id; 00144 } 00145 00146 00147 void KPanelAppMenu::clear() 00148 { 00149 DCOPClient *client = kapp->dcopClient(); 00150 TQByteArray sendData; 00151 client->send("kicker", realObjId, "clear()", sendData); 00152 } 00153 00154 00155 bool KPanelAppMenu::process(const TQCString &fun, const TQByteArray &data, 00156 TQCString &replyType, TQByteArray &) 00157 { 00158 if ( fun == "activated(int)" ) { 00159 TQDataStream 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