diff options
Diffstat (limited to 'kdcop')
-rw-r--r-- | kdcop/CMakeLists.txt | 36 | ||||
-rw-r--r-- | kdcop/Makefile.am | 23 | ||||
-rw-r--r-- | kdcop/README | 11 | ||||
-rw-r--r-- | kdcop/kdcop.cpp | 37 | ||||
-rw-r--r-- | kdcop/kdcoplistview.cpp | 157 | ||||
-rw-r--r-- | kdcop/kdcoplistview.h | 133 | ||||
-rw-r--r-- | kdcop/kdcopui.rc | 15 | ||||
-rw-r--r-- | kdcop/kdcopview.ui | 149 | ||||
-rw-r--r-- | kdcop/kdcopwindow.cpp | 1238 | ||||
-rw-r--r-- | kdcop/kdcopwindow.h | 64 |
10 files changed, 1863 insertions, 0 deletions
diff --git a/kdcop/CMakeLists.txt b/kdcop/CMakeLists.txt new file mode 100644 index 000000000..70f19988b --- /dev/null +++ b/kdcop/CMakeLists.txt @@ -0,0 +1,36 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### other data ################################ + +install( FILES kdcopui.rc DESTINATION ${DATA_INSTALL_DIR}/kdcop ) + + +##### kdcop (executable) ######################## + +tde_add_executable( kdcop AUTOMOC + SOURCES + kdcop.cpp kdcopwindow.cpp kdcoplistview.cpp kdcopview.ui + LINK tdeio-shared + DESTINATION ${BIN_INSTALL_DIR} +) diff --git a/kdcop/Makefile.am b/kdcop/Makefile.am new file mode 100644 index 000000000..25c33f654 --- /dev/null +++ b/kdcop/Makefile.am @@ -0,0 +1,23 @@ +# +# KDCOP Makefile.am +# +# Copyright 2000 Matthias Kalle Dalheimer, [email protected] +# +# + +INCLUDES = $(all_includes) + +bin_PROGRAMS = kdcop + +kdcop_SOURCES = kdcop.cpp kdcopwindow.cpp kdcoplistview.cpp kdcopview.ui +kdcop_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TDEUI) $(LIB_TDECORE) $(LIB_TDEIO) -lDCOP $(LIB_QT) + +noinst_HEADERS = kdcopwindow.h +METASOURCES = AUTO + +rcdir = $(kde_datadir)/kdcop +rc_DATA = kdcopui.rc + +messages: rc.cpp + $(XGETTEXT) rc.cpp *.cpp -o $(podir)/kdcop.pot + diff --git a/kdcop/README b/kdcop/README new file mode 100644 index 000000000..049678f2c --- /dev/null +++ b/kdcop/README @@ -0,0 +1,11 @@ +This is a browser/executor for DCOP. It queries the DCOP clients in a system, +their interfaces, and the interfaces' arguments. You can even execute DCOP +calls by double-clicking on a call. If the method has parameters, kdcop will +open a dialog and prompt you for them. If the method returns a return value, +you will see it in a message box after the call. + +This little tool fairly much does what I wanted it to do, but let me know if +you want more features. + +Kalle Dalheimer, <[email protected]> + diff --git a/kdcop/kdcop.cpp b/kdcop/kdcop.cpp new file mode 100644 index 000000000..436a4a59a --- /dev/null +++ b/kdcop/kdcop.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2000 by Matthias Kalle Dalheimer <[email protected]> + * + * Licensed under the Artistic License. + */ +#include <tdeapplication.h> +#include <tdelocale.h> +#include <tdeaboutdata.h> +#include <tdecmdlineargs.h> + +#include "kdcopwindow.h" + +static const TDECmdLineOptions options[] = +{ + TDECmdLineLastOption +}; + +int main( int argc, char ** argv ) +{ + TDEAboutData aboutData( "kdcop", I18N_NOOP("KDCOP"), + "0.1", I18N_NOOP( "A graphical DCOP browser/client" ), + TDEAboutData::License_Artistic, + "(c) 2000, Matthias Kalle Dalheimer"); + aboutData.addAuthor("Matthias Kalle Dalheimer",0, "[email protected]"); + aboutData.addAuthor("Rik Hemsley",0, "[email protected]"); + aboutData.addAuthor("Ian Reinhart Geiser",0,"[email protected]"); + TDECmdLineArgs::init( argc, argv, &aboutData ); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication a; + + KDCOPWindow* kdcopwindow = new KDCOPWindow; + a.setMainWidget( kdcopwindow ); + kdcopwindow->show(); + + return a.exec(); +} diff --git a/kdcop/kdcoplistview.cpp b/kdcop/kdcoplistview.cpp new file mode 100644 index 000000000..eae4b0bfe --- /dev/null +++ b/kdcop/kdcoplistview.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2000 by Ian Reinhart Geiser <[email protected]> + * + * Licensed under the Artistic License. + */ + +#include "kdcoplistview.h" +#include "kdcoplistview.moc" +#include <kdebug.h> +#include <tqdragobject.h> +#include <tqstringlist.h> +#include <tqregexp.h> + + +KDCOPListView::KDCOPListView ( TQWidget *parent, const char *name) + : TDEListView(parent, name) +{ + kdDebug() << "Building new list." << endl; + setDragEnabled(true); +} + + +KDCOPListView::~KDCOPListView () +{ + +} + +TQDragObject *KDCOPListView::dragObject() +{ + kdDebug() << "Drag object called... " << endl; + if(!currentItem()) + return 0; + else + return new TQTextDrag(encode(this->selectedItem()), this); +} + +void KDCOPListView::setMode( const TQString &theMode ) +{ + mode = theMode; +} + +TQString KDCOPListView::encode(TQListViewItem *theCode) +{ + DCOPBrowserItem * item = static_cast<DCOPBrowserItem *>(theCode); + + if (item->type() != DCOPBrowserItem::Function) + return ""; + + DCOPBrowserFunctionItem * fitem = + static_cast<DCOPBrowserFunctionItem *>(item); + + TQString function = TQString::fromUtf8(fitem->function()); + TQString application = TQString::fromUtf8(fitem->app()); + TQString object = TQString::fromUtf8(fitem->object()); + + kdDebug() << function << endl; + TQString returnType = function.section(' ', 0,0); + TQString returnCode = ""; + TQString normalisedSignature; + TQStringList types; + TQStringList names; + + TQString unNormalisedSignature(function); + + int s = unNormalisedSignature.find(' '); + + if ( s < 0 ) + s = 0; + else + s++; + + unNormalisedSignature = unNormalisedSignature.mid(s); + + int left = unNormalisedSignature.find('('); + int right = unNormalisedSignature.findRev(')'); + + if (-1 == left) + { + // Fucked up function signature. + return ""; + } + if (left > 0 && left + 1 < right - 1) + { + types = TQStringList::split + (',', unNormalisedSignature.mid(left + 1, right - left - 1)); + for (TQStringList::Iterator it = types.begin(); it != types.end(); ++it) + { + (*it) = (*it).stripWhiteSpace(); + int s = (*it).find(' '); + if (-1 != s) + { + names.append((*it).mid(s + 1)); + (*it) = (*it).left(s); + } + } + } + + if ( mode == "C++") + { + TQString args; + for( unsigned int i = 0; i < names.count(); i++) + { + args += types[i] + " " + names[i] + ";\n"; + } + TQString dcopRef = "DCOPRef m_" + application + object + + "(\""+ application + "\",\"" + object +"\");\n"; + + TQString stringNames = names.join(","); + TQString stringTypes = types.join(","); + if( returnType != "void") + returnType += " return" + returnType + " ="; + else + returnType = ""; + returnCode = args + + dcopRef + + returnType + + "m_" + application + object + + ".call(\"" + unNormalisedSignature.left(left) + + "(" + stringTypes + ")\""; + if(!stringNames.isEmpty()) + returnCode += ", "; + returnCode += stringNames + ");\n"; + } + else if (mode == "Shell") + { + returnCode = "dcop " + application + " " + object + " " + + unNormalisedSignature.left(left) + " " + names.join(" "); + } + else if (mode == "Python") + { + TQString setup; + setup = "m_" + + application + object + + " = dcop.DCOPObject( \"" + + application + "\",\"" + + object + "\")\n"; + + for( unsigned int i = 0; i < names.count(); i++) + { + setup += names[i] + " #set value here.\n"; + } + returnCode = setup + + "reply" + + returnType + + " = m_" + + application + object + "." + + unNormalisedSignature.left(left) + + "(" + names.join(",") + ")\n"; + } + return returnCode; +} + +TQString KDCOPListView::getCurrentCode() const +{ + // fixing warning + return TQString::null; +} diff --git a/kdcop/kdcoplistview.h b/kdcop/kdcoplistview.h new file mode 100644 index 000000000..8b537a152 --- /dev/null +++ b/kdcop/kdcoplistview.h @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2000 by Ian Reinhart Geiser <[email protected]> + * + * Licensed under the Artistic License. + */ + +#ifndef __KDCOPLISTVIEW_H__ +#define __KDCOPLISTVIEW_H__ + + +#include <tdelistview.h> +class TQDragObject; + +class KDCOPListView : public TDEListView +{ + Q_OBJECT + + public: + KDCOPListView ( TQWidget * parent = 0, const char * name = 0 ); + virtual ~KDCOPListView(); + TQDragObject *dragObject(); + void setMode(const TQString &mode); + TQString getCurrentCode() const; + + private: + TQString encode(TQListViewItem *code); + TQString mode; + +}; + +class DCOPBrowserItem : public TQListViewItem +{ + public: + + enum Type { Application, Interface, Function }; + + DCOPBrowserItem(TQListView * parent, Type type); + DCOPBrowserItem(TQListViewItem * parent, Type type); + + virtual ~DCOPBrowserItem() {} + + Type type() const; + + private: + + Type type_; +}; + +class DCOPBrowserApplicationItem : public TQObject, public DCOPBrowserItem +{ + Q_OBJECT + public: + + DCOPBrowserApplicationItem(TQListView * parent, const TQCString & app); + virtual ~DCOPBrowserApplicationItem() {} + + TQCString app() const { return app_; } + + virtual void setOpen(bool o); + + protected: + + virtual void populate(); + + private: + + TQCString app_; + private slots: + /** + * Theses two slots are used to get the icon of the application + */ + void retreiveIcon(int callId, const TQCString& replyType, const TQByteArray &replyData); + void slotGotWindowName(int callId, const TQCString& replyType, const TQByteArray &replyData); +}; + +class DCOPBrowserInterfaceItem : public TQObject, public DCOPBrowserItem +{ + public: + + DCOPBrowserInterfaceItem + ( + DCOPBrowserApplicationItem * parent, + const TQCString & app, + const TQCString & object, + bool def + ); + + virtual ~DCOPBrowserInterfaceItem() {} + + TQCString app() const { return app_; } + TQCString object() const { return object_; } + + virtual void setOpen(bool o); + + protected: + + virtual void populate(); + + private: + + TQCString app_; + TQCString object_; +}; + + +class DCOPBrowserFunctionItem : public DCOPBrowserItem +{ + public: + + DCOPBrowserFunctionItem + ( + DCOPBrowserInterfaceItem * parent, + const TQCString & app, + const TQCString & object, + const TQCString & function + ); + + virtual ~DCOPBrowserFunctionItem() {} + + TQCString app() const { return app_; } + TQCString object() const { return object_; } + TQCString function() const { return function_; } + + virtual void setOpen(bool o); + + private: + + TQCString app_; + TQCString object_; + TQCString function_; +}; + +#endif diff --git a/kdcop/kdcopui.rc b/kdcop/kdcopui.rc new file mode 100644 index 000000000..7843c78dc --- /dev/null +++ b/kdcop/kdcopui.rc @@ -0,0 +1,15 @@ +<!DOCTYPE kpartgui> +<kpartgui name="kcop" version="2"> +<MenuBar> + <Menu name="execute"><text>&Extra</text> + <Action name="reload"/> + <Action name="execute"/> + <Action name="langmode"/> + </Menu> +</MenuBar> +<ToolBar fullWidth="true" name="mainToolBar"><text>Main Toolbar</text> + <Action name="reload"/> + <Action name="execute"/> + <Action name="langmode"/> +</ToolBar> +</kpartgui> diff --git a/kdcop/kdcopview.ui b/kdcop/kdcopview.ui new file mode 100644 index 000000000..3b67fa242 --- /dev/null +++ b/kdcop/kdcopview.ui @@ -0,0 +1,149 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>kdcopview</class> +<author>Ian Reinhart Geiser [email protected]</author> +<widget class="TQWidget"> + <property name="name"> + <cstring>kdcopview</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>392</width> + <height>356</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="TDEListViewSearchLine" row="0" column="1"> + <property name="name"> + <cstring>kListViewSearchLine1</cstring> + </property> + </widget> + <widget class="TQLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>&Search:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kListViewSearchLine1</cstring> + </property> + </widget> + <widget class="TQSplitter" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>splitter8</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <widget class="KDCOPListView"> + <property name="name"> + <cstring>lv</cstring> + </property> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>layout18</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLabel" row="0" column="1"> + <property name="name"> + <cstring>l_replyType</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + <property name="text"> + <string>none</string> + </property> + <property name="indent"> + <number>0</number> + </property> + </widget> + <widget class="TDEListBox" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>lb_replyData</cstring> + </property> + </widget> + <widget class="TQLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Returned data type:</string> + </property> + </widget> + </grid> + </widget> + </widget> + </grid> +</widget> +<customwidgets> + <customwidget> + <class>KDCOPListView</class> + <header location="local">kdcoplistview.h</header> + <sizehint> + <width>100</width> + <height>100</height> + </sizehint> + <container>1</container> + <sizepolicy> + <hordata>5</hordata> + <verdata>5</verdata> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + <pixmap>image0</pixmap> + </customwidget> +</customwidgets> +<images> + <image name="image0"> + <data format="PNG" length="1077">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000003fc49444154388d8d95bf8b1d5518869fbbb9c237b2c133b291195cc91d8c901123b901c10d0ae6a260162d526c1348a3a90ca952064208e4afd0d804d204d20436c5425218660b8b142bb98bcd2cba700e66e17cc5ca7cc5c5b59899bb2e3639301ccecc99f7bcf37c3f66505515fdb879e7f28106c33040004390d75a6799e3eead07835e6b5055153f3dbc76b0f9a4e6bbeb374810c4a59846001a8c04f9ffbc6fb008b667f85033ad6b4298b2b29273f5cabdc11060f359cdb5eb37c88a12f581b8eb4916419c302e0bc06318513da186b807588a9981b50ef334073336373d57afc0e0c2d7d9c1eab7d728f2028d4abd5b532c6794e3827c048d050c8f99875e3c18f59610438199b557348c861802e21a861a201141a3e2773de5a982d54b63d46abc5698edd0980711404804b2cc906c8aeed4bcfce51ca6862460114484103c43c3104989bb9ee254cee46289d78a697880598d0f0e9a04882449827382732d029729c5e715d38d73a86f0030031086209846f2e594c9c5926815d3700f5563ba51e243cb0e1130431c141f45ca158f19e499a1238f698e598374fb16ba2390148c9a3a3c2204a37af81f51dacde32f857cd4307d9ef362a3681d02c5190fd23b6ef58622024079dae1b542f1d4bf1698a5479c4ed64ac69f0a6635eb78eaed02b71cc94bc59c918f14f5d2398605ebf2c5f018010de0778e3a9d7c3366f2c50a82c30cc65f05c008bf15edd9805b8e80748e8585f67617746b2b69ee1463fc59c9e4c24a6b1c0594171b0e4168acaf3fc88b2ea1a5b539676ca6883820993b2dcf66ac5e1a236244ad31f3448dc4d0174782aab4e29d4e5f300b3de32e84385700463e1256afe424a2789ba2566356230e266b119701d2e0b20ea6b9b677747ac33963f5886b133c1f41d4b60798f398295e3dceb587a72ee1fc5a4483ce194fb7928eb11e326e307c00b3402246f9491b88f5fb4abd33e5e9e3c8d3fb393bdb74a81a9c335ce63b0c73b873c6c39e71bd05e2eaf6f346707eada67af821eb3fa6f316593dce893e52ae84ae77d0f50a87df7647181f7b6fd9ddfee0e4c7d8fe1be83f7f723c0fcccc182e1af9fbaf9037e1f8db4a9acd4897f63971728fa1f4a22032c46cc6e23bc6eecb04b31936d396b10f757bd0f302cc28c6be7bc9c8c7f53ca5e4d0d03c5ffbcc9434301a837fd6b23e76e66c76fb6f9d311c24eccf0cfd23e5d55f43d2b780453b2a6ac0106606d12fb1b39d72e2dd7da282fa25767e4fd0bd86a5a561fb07f9fe87d583cc1524ce1d561c4656186916c9ce18346ddcc2961035254cdb369a9581fc54c3f439780f1a947b3fafb77f90950b399bcf3cceda3cb46e9ebe00911c7b725862fd73c4c08cb8d9ee830655253bdd0671505515fdb879e7f241083aafbc3e835e679d6570f7d6a3417fe75f216c6016a81220570000000049454e44ae426082</data> + </image> +</images> +<includes> + <include location="global" impldecl="in implementation">kdialog.h</include> +</includes> +<layoutdefaults spacing="6" margin="11"/> +<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/> +<includehints> + <includehint>tdelistviewsearchline.h</includehint> + <includehint>kdcoplistview.h</includehint> + <includehint>tdelistbox.h</includehint> +</includehints> +</UI> diff --git a/kdcop/kdcopwindow.cpp b/kdcop/kdcopwindow.cpp new file mode 100644 index 000000000..92e226852 --- /dev/null +++ b/kdcop/kdcopwindow.cpp @@ -0,0 +1,1238 @@ +/* + * Copyright (C) 2000 by Matthias Kalle Dalheimer <[email protected]> + * 2004 by Olivier Goffart <ogoffart @ tiscalinet.be> + * + * Licensed under the Artistic License. + */ + +#include "kdcopwindow.h" +#include "kdcoplistview.h" + +#include <dcopclient.h> +#include <tdelocale.h> +#include <kdatastream.h> +#include <kstdaction.h> +#include <tdeaction.h> +#include <tdeapplication.h> +#include <tdemessagebox.h> +#include <kdialog.h> +#include <tdeglobal.h> +#include <kiconloader.h> +#include <klineedit.h> +#include <keditlistbox.h> +#include <tdelistbox.h> +#include <kdialogbase.h> +#include <tdestdaccel.h> +#include <kcolorbutton.h> +#include <tdelistviewsearchline.h> + +#include <tqtimer.h> +#include <tqwidgetstack.h> +#include <tqlabel.h> +#include <tqsplitter.h> +#include <tqlayout.h> +#include <tqcheckbox.h> +#include <tqlineedit.h> +#include <tqvalidator.h> +#include <tqpushbutton.h> +#include <tqkeycode.h> +#include <tqpixmap.h> +#include <tqcursor.h> +#include <tqsize.h> +#include <tqrect.h> +#include <tqclipboard.h> +#include <tqdatetime.h> +#include <dcopref.h> +#include <tqvbox.h> +#include <tqimage.h> +#include <tqheader.h> + +#include <kdebug.h> +#include <kkeydialog.h> +#include <stdio.h> +#include <kstatusbar.h> +#include <kurl.h> +#include <kurlrequester.h> + +class DCOPBrowserApplicationItem; +class DCOPBrowserInterfaceItem; +class DCOPBrowserFunctionItem; + +//------------------------------ + +class KMultiIntEdit : public TQVBox +{ +public: + KMultiIntEdit(TQWidget *parent , const char * name=0) : TQVBox(parent,name) {} + void addField(int key, const TQString & caption ) + { + TQHBox *l=new TQHBox(this); + new TQLabel(caption + ": ", l); + KLineEdit* e = new KLineEdit( l ); + m_widgets.insert(key, e ) ; + e->setValidator( new TQIntValidator( TQT_TQOBJECT(e) ) ); + } + int field(int key) + { + KLineEdit *e=m_widgets[key]; + if(!e) return 0; + return e->text().toInt(); + } + +private: + TQMap<int,KLineEdit*> m_widgets; +}; + +//------------------------------ + +DCOPBrowserItem::DCOPBrowserItem +(TQListView * parent, DCOPBrowserItem::Type type) + : TQListViewItem(parent), + type_(type) +{ +} + +DCOPBrowserItem::DCOPBrowserItem +(TQListViewItem * parent, DCOPBrowserItem::Type type) + : TQListViewItem(parent), + type_(type) +{ +} + + DCOPBrowserItem::Type +DCOPBrowserItem::type() const +{ + return type_; +} + +// ------------------------------------------------------------------------ + +DCOPBrowserApplicationItem::DCOPBrowserApplicationItem +(TQListView * parent, const TQCString & app) + : DCOPBrowserItem(parent, Application), + app_(app) +{ + setExpandable(true); + setText(0, TQString::fromUtf8(app_)); + setPixmap(0, TDEGlobal::iconLoader()->loadIcon( TQString::fromLatin1( "application-x-executable" ), TDEIcon::Small )); + + + /* Get the icon: we use the icon from a mainwindow in that class. + a lot of applications has a app-mainwindow#1 object, but others can still have + a main window with another name. In that case, we search for a main window with the qt object. + * Why don't search with qt dirrectly? + simply because some application that have a 'mainwindow#1' doesn't have a qt object. And, for + reason i don't know, some application return stanges result. Some konqueror instance are returning + konqueror-mainwindow#3 while only the #1 exists, I already seen the same problem with konsole + * All calls are async to don't block the GUI if the clients does not reply immediatly + */ + + TQRegExp rx( "([^\\-]+)"); // remove the possible processus id + rx.search(app_); // konqueror-123 => konqueror-mainwindow#1 + TQString mainWindowName= rx.cap(1) + "-mainwindow#1" ; + + TQByteArray data; + int callId=kapp->dcopClient()->callAsync( app_, mainWindowName.utf8(), "icon()", data, this, TQT_SLOT(retreiveIcon(int, const TQCString&, const TQByteArray&))); + + if(!callId) + { + //maybe there is another mainwindow registered with another name. + TQByteArray data; + TQDataStream arg(data, IO_WriteOnly); + arg << TQCString( "MainWindow" ); + + kapp->dcopClient()->callAsync( app_, "qt", "find(TQCString)", data, this, TQT_SLOT(slotGotWindowName(int, const TQCString&, const TQByteArray& ))); + } +} + + void +DCOPBrowserApplicationItem::setOpen(bool o) +{ + DCOPBrowserItem::setOpen(o); + + if (0 == firstChild()) + populate(); +} + + void +DCOPBrowserApplicationItem::populate() +{ + TDEApplication::setOverrideCursor(tqwaitCursor); + + bool ok = false; + bool isDefault = false; + + QCStringList objs = kapp->dcopClient()->remoteObjects(app_, &ok); + + for (QCStringList::ConstIterator it = objs.begin(); it != objs.end(); ++it) + { + if (*it == "default") + { + isDefault = true; + continue; + } + new DCOPBrowserInterfaceItem(this, app_, *it, isDefault); + isDefault = false; + } + + TDEApplication::restoreOverrideCursor(); +} + +void DCOPBrowserApplicationItem::slotGotWindowName(int /*callId*/, const TQCString& /*replyType*/, const TQByteArray &replyData) +{ + TQDataStream reply(replyData, IO_ReadOnly); + QCStringList mainswindows; + reply >> mainswindows; + TQStringList sl=TQStringList::split("/",mainswindows.first() ); + if(sl.count() >= 1) + { + TQString mainWindowName=sl[1]; + if(!mainWindowName.isEmpty()) + { + TQByteArray data; + kapp->dcopClient()->callAsync( app_, mainWindowName.utf8(), "icon()", data, + this, TQT_SLOT(retreiveIcon(int, const TQCString&, const TQByteArray&))); + } + } +} + +void DCOPBrowserApplicationItem::retreiveIcon(int /*callId*/,const TQCString& /*replyType*/, const TQByteArray &replyData) +{ + TQDataStream reply(replyData, IO_ReadOnly); + TQPixmap returnQPixmap; + reply >> returnQPixmap; + if(!returnQPixmap.isNull()) + setPixmap(0, TQPixmap(TQImage(returnQPixmap.convertToImage()).smoothScale(16,16)) ); + else + kdDebug() << "Unable to retreive the icon" << endl; +} + +// ------------------------------------------------------------------------ + +DCOPBrowserInterfaceItem::DCOPBrowserInterfaceItem +( + DCOPBrowserApplicationItem * parent, + const TQCString & app, + const TQCString & object, + bool def +) + : DCOPBrowserItem(parent, Interface), + app_(app), + object_(object) +{ + setExpandable(true); + + if (def) + setText(0, i18n("%1 (default)").arg(TQString::fromUtf8(object_))); + else + setText(0, TQString::fromUtf8(object_)); +} + + void +DCOPBrowserInterfaceItem::setOpen(bool o) +{ + DCOPBrowserItem::setOpen(o); + + if (0 == firstChild()) + populate(); +} + + void +DCOPBrowserInterfaceItem::populate() +{ + TDEApplication::setOverrideCursor(tqwaitCursor); + + bool ok = false; + + QCStringList funcs = kapp->dcopClient()->remoteFunctions(app_, object_, &ok); + + for (QCStringList::ConstIterator it = funcs.begin(); it != funcs.end(); ++it) + if ((*it) != "QCStringList functions()") + new DCOPBrowserFunctionItem(this, app_, object_, *it); + + TDEApplication::restoreOverrideCursor(); +} + +// ------------------------------------------------------------------------ + +DCOPBrowserFunctionItem::DCOPBrowserFunctionItem +( + DCOPBrowserInterfaceItem * parent, + const TQCString & app, + const TQCString & object, + const TQCString & function +) + : DCOPBrowserItem(parent, Function), + app_(app), + object_(object), + function_(function) +{ + setExpandable(false); + setText(0, TQString::fromUtf8(function_)); +} + + void +DCOPBrowserFunctionItem::setOpen(bool o) +{ + DCOPBrowserItem::setOpen(o); +} + +// ------------------------------------------------------------------------ + +KDCOPWindow::KDCOPWindow(TQWidget *parent, const char * name) + : TDEMainWindow(parent, name) +{ + dcopClient = kapp->dcopClient(); + dcopClient->attach(); + resize( 377, 480 ); + statusBar()->message(i18n("Welcome to the TDE DCOP browser")); + + mainView = new kdcopview(this, "KDCOP"); + mainView->kListViewSearchLine1->setListView( mainView->lv ); + setCentralWidget(mainView); + mainView->lv->addColumn(i18n("Application")); + mainView->lv->header()->setStretchEnabled(true, 0); +// mainView->lv->addColumn(i18n("Interface")); +// mainView->lv->addColumn(i18n("Function")); + mainView->lv->setDragAutoScroll( FALSE ); + mainView->lv->setRootIsDecorated( TRUE ); + connect + ( + mainView->lv, + TQT_SIGNAL(doubleClicked(TQListViewItem *)), + TQT_SLOT(slotCallFunction(TQListViewItem *)) + ); + + connect + ( + mainView->lv, + TQT_SIGNAL(currentChanged(TQListViewItem *)), + TQT_SLOT(slotCurrentChanged(TQListViewItem *)) + ); + + + // set up the actions + KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT( close() ), actionCollection() ); + KStdAction::copy( TQT_TQOBJECT(this), TQT_SLOT( slotCopy()), actionCollection() ); + KStdAction::keyBindings( guiFactory(), TQT_SLOT( configureShortcuts() ), actionCollection() ); + + + (void) new TDEAction( i18n( "&Reload" ), "reload", TDEStdAccel::shortcut(TDEStdAccel::Reload), TQT_TQOBJECT(this), TQT_SLOT( slotReload() ), actionCollection(), "reload" ); + + exeaction = + new TDEAction + ( + i18n("&Execute"), + "application-x-executable", + CTRL + Key_E, + TQT_TQOBJECT(this), + TQT_SLOT(slotCallFunction()), + actionCollection(), + "execute" + ); + + exeaction->setEnabled(false); + exeaction->setToolTip(i18n("Execute the selected DCOP call.")); + + langmode = new TDESelectAction ( i18n("Language Mode"), + CTRL + Key_M, + TQT_TQOBJECT(this), + TQT_SLOT(slotMode()), + actionCollection(), + "langmode"); + langmode->setEditable(false); + langmode->setItems(TQStringList::split(",", "Shell,C++,Python")); + langmode->setToolTip(i18n("Set the current language export.")); + langmode->setCurrentItem(0); + slotMode(); + connect + ( + dcopClient, + TQT_SIGNAL(applicationRegistered(const TQCString &)), + TQT_SLOT(slotApplicationRegistered(const TQCString &)) + ); + + connect + ( + dcopClient, + TQT_SIGNAL(applicationRemoved(const TQCString &)), + TQT_SLOT(slotApplicationUnregistered(const TQCString &)) + ); + + dcopClient->setNotifications(true); + createGUI(); + setCaption(i18n("DCOP Browser")); + mainView->lb_replyData->hide(); + TQTimer::singleShot(0, this, TQT_SLOT(slotFillApplications())); +} + + +void KDCOPWindow::slotCurrentChanged( TQListViewItem* i ) +{ + DCOPBrowserItem* item = (DCOPBrowserItem*)i; + + if( item->type() == DCOPBrowserItem::Function ) + exeaction->setEnabled( true ); + else + exeaction->setEnabled( false ); +} + + +void KDCOPWindow::slotCallFunction() +{ + slotCallFunction( mainView->lv->currentItem() ); +} + +void KDCOPWindow::slotReload() +{ + slotFillApplications(); +} + +void KDCOPWindow::slotCallFunction( TQListViewItem* it ) +{ + if(it == 0) + return; + DCOPBrowserItem * item = static_cast<DCOPBrowserItem *>(it); + + if (item->type() != DCOPBrowserItem::Function) + return; + + DCOPBrowserFunctionItem * fitem = + static_cast<DCOPBrowserFunctionItem *>(item); + + TQString unNormalisedSignature = TQString::fromUtf8(fitem->function()); + TQString normalisedSignature; + TQStringList types; + TQStringList names; + + if (!getParameters(unNormalisedSignature, normalisedSignature, types, names)) + { + KMessageBox::error + (this, i18n("No parameters found."), i18n("DCOP Browser Error")); + + return; + } + + TQByteArray data; + TQByteArray replyData; + + TQCString replyType; + + TQDataStream arg(data, IO_WriteOnly); + + KDialogBase mydialog( this, "KDCOP Parameter Entry", true, + TQString::null, KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ); + + mydialog.setCaption + ( i18n("Call Function %1").arg( static_cast<const char *>(fitem->function()) ) ); + + TQFrame *frame = mydialog.makeMainWidget(); + + TQLabel* h1 = new TQLabel( i18n( "Name" ), frame ); + TQLabel* h2 = new TQLabel( i18n( "Type" ), frame ); + TQLabel* h3 = new TQLabel( i18n( "Value" ), frame ); + + TQGridLayout* grid = new TQGridLayout( frame, types.count() + 2, 3, + 0, KDialog::spacingHint() ); + + grid->addWidget( h1, 0, 0 ); + grid->addWidget( h2, 0, 1 ); + grid->addWidget( h3, 0, 2 ); + + // Build up a dialog for parameter entry if there are any parameters. + + if (types.count()) + { + int i = 0; + + TQPtrList<TQWidget> wl; + + for (TQStringList::ConstIterator it = types.begin(); it != types.end(); ++it) + { + i++; + + const TQString type = *it; + + const TQString name = i-1 < (int)names.count() ? names[i-1] : TQString::null; + + if( type == "int" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "int", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + e->setValidator( new TQIntValidator( TQT_TQOBJECT(e) ) ); + } + else if ( type == "unsigned" || type == "uint" || type == "unsigned int" + || type == "TQ_UINT32" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "unsigned int", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + + TQIntValidator* iv = new TQIntValidator( TQT_TQOBJECT(e) ); + iv->setBottom( 0 ); + e->setValidator( iv ); + } + else if ( type == "long" || type == "long int" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "long", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + e->setValidator( new TQIntValidator( TQT_TQOBJECT(e) ) ); + } + else if ( type == "ulong" || type == "unsigned long" || type == "unsigned long int" + || type == "TQ_UINT64" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "unsigned long", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + e->setValidator( new TQIntValidator( TQT_TQOBJECT(e) ) ); + } + else if ( type == "short" || type == "short int" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "long", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + e->setValidator( new TQIntValidator( TQT_TQOBJECT(e) ) ); + } + else if ( type == "ushort" || type == "unsigned short" || type == "unsigned short int" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "unsigned short", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + e->setValidator( new TQIntValidator( TQT_TQOBJECT(e) ) ); + } + else if ( type == "float" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "float", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + e->setValidator( new TQDoubleValidator( TQT_TQOBJECT(e) ) ); + } + else if ( type == "double" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "double", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + e->setValidator( new TQDoubleValidator( TQT_TQOBJECT(e) ) ); + } + else if ( type == "bool" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "bool", frame ); + grid->addWidget( l, i, 1 ); + TQCheckBox* c = new TQCheckBox( frame ); + grid->addWidget( c, i, 2 ); + wl.append( c ); + } + else if ( type == "TQString" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQString", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if ( type == "TQCString" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQString", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if ( type == "TQStringList" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQStringList", frame ); + grid->addWidget( l, i, 1 ); + KEditListBox* e = new KEditListBox ( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if ( type == "TQValueList<TQCString>" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQValueList<TQCString>", frame ); + grid->addWidget( l, i, 1 ); + KEditListBox* e = new KEditListBox ( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if ( type == "KURL" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "KURL", frame ); + grid->addWidget( l, i, 1 ); + KLineEdit* e = new KLineEdit( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if ( type == "TQColor" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQColor", frame ); + grid->addWidget( l, i, 1 ); + KColorButton* e = new KColorButton( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if ( type == "TQSize" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQSize", frame ); + grid->addWidget( l, i, 1 ); + KMultiIntEdit* e = new KMultiIntEdit( frame ); + e->addField( 1, i18n("Width") ); + e->addField( 2, i18n("Height") ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if ( type == "TQPoint" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQPoint", frame ); + grid->addWidget( l, i, 1 ); + KMultiIntEdit* e = new KMultiIntEdit( frame ); + e->addField( 1, i18n("X") ); + e->addField( 2, i18n("Y") ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if ( type == "TQRect" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQRect", frame ); + grid->addWidget( l, i, 1 ); + KMultiIntEdit* e = new KMultiIntEdit( frame ); + e->addField( 1, i18n("Left") ); + e->addField( 2, i18n("Top") ); + e->addField( 3, i18n("Width") ); + e->addField( 4, i18n("Height") ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else if( type == "TQPixmap" ) + { + TQLabel* n = new TQLabel( name, frame ); + grid->addWidget( n, i, 0 ); + TQLabel* l = new TQLabel( "TQPixmap", frame ); + grid->addWidget( l, i, 1 ); + KURLRequester* e = new KURLRequester( frame ); + grid->addWidget( e, i, 2 ); + wl.append( e ); + } + else + { + KMessageBox::sorry(this, i18n("Cannot handle datatype %1").arg(type)); + return; + } + } + + if (!wl.isEmpty()) + wl.at(0)->setFocus(); + + i++; + + int ret = mydialog.exec(); + + if (TQDialog::Accepted != ret) + return; + + // extract the arguments + + i = 0; + + for (TQStringList::ConstIterator it = types.begin(); it != types.end(); ++it) + { + TQString type = *it; + + if ( type == "int" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text().toInt(); + } + else if ( type == "unsigned" || type == "uint" || type == "unsigned int" + || type == "TQ_UINT32" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text().toUInt(); + } + else if( type == "long" || type == "long int" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text().toLong(); + } + else if( type == "ulong" || type == "unsigned long" || type == "unsigned long int" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text().toULong(); + } + else if( type == "short" || type == "short int" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text().toShort(); + } + else if( type == "ushort" || type == "unsigned short" || type == "unsigned short int" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text().toUShort(); + } + else if ( type == "TQ_UINT64" ) + { + KLineEdit* e = ( KLineEdit* )wl.at( i ); + arg << e->text().toULongLong(); + } + else if( type == "float" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text().toFloat(); + } + else if( type == "double" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text().toDouble(); + } + else if( type == "bool" ) + { + TQCheckBox* c = (TQCheckBox*)wl.at( i ); + arg << c->isChecked(); + } + else if( type == "TQCString" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << TQCString( e->text().local8Bit() ); + } + else if( type == "TQString" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << e->text(); + } + else if( type == "TQStringList" ) + { + KEditListBox* e = (KEditListBox*)wl.at( i ); + arg << e->items(); + } + else if( type == "TQValueList<TQCString>" ) + { + KEditListBox* e = (KEditListBox*)wl.at( i ); + for (int i = 0; i < e->count(); i++) + arg << TQCString( e->text(i).local8Bit() ); + } + else if( type == "KURL" ) + { + KLineEdit* e = (KLineEdit*)wl.at( i ); + arg << KURL( e->text() ); + } + else if( type == "TQColor" ) + { + KColorButton* e = (KColorButton*)wl.at( i ); + arg << e->color(); + } + else if( type == "TQSize" ) + { + KMultiIntEdit* e = (KMultiIntEdit*)wl.at( i ); + arg << TQSize(e->field(1) , e->field(2)) ; + } + else if( type == "TQPoint" ) + { + KMultiIntEdit* e = (KMultiIntEdit*)wl.at( i ); + arg << TQPoint(e->field(1) , e->field(2)) ; + } + else if( type == "TQRect" ) + { + KMultiIntEdit* e = (KMultiIntEdit*)wl.at( i ); + arg << TQRect(e->field(1) , e->field(2) , e->field(3) , e->field(4)) ; + } + else if( type == "TQPixmap" ) + { + KURLRequester* e= (KURLRequester*)wl.at( i ); + arg << TQPixmap(e->url()); + } + else + { + KMessageBox::sorry(this, i18n("Cannot handle datatype %1").arg(type)); + return; + } + + i++; + } + } + + DCOPRef( fitem->app(), "MainApplication-Interface" ).call( "updateUserTimestamp", kapp->userTimestamp()); + + // Now do the DCOP call + + bool callOk = + dcopClient->call + ( + fitem->app(), + fitem->object(), + normalisedSignature.utf8(), + data, + replyType, + replyData + ); + + if (!callOk) + { + kdDebug() + << "call failed( " + << fitem->app().data() + << ", " + << fitem->object().data() + << ", " + << normalisedSignature + << " )" + << endl; + + statusBar()->message(i18n("DCOP call failed")); + + TQString msg = i18n("<p>DCOP call failed.</p>%1"); + + bool appRegistered = dcopClient->isApplicationRegistered(fitem->app()); + + if (appRegistered) + { + msg = + msg.arg + ( + i18n + ( + "<p>Application is still registered with DCOP;" + " I do not know why this call failed.</p>" + ) + ); + } + else + { + msg = + msg.arg + ( + i18n + ( + "<p>The application appears to have unregistered with DCOP.</p>" + ) + ); + } + + KMessageBox::information(this, msg); + } + else + { + TQString coolSignature = + TQString::fromUtf8(fitem->app()) + + "." + + TQString::fromUtf8(fitem->object()) + + "." + + normalisedSignature ; + + statusBar()->message(i18n("DCOP call %1 executed").arg(coolSignature)); + + if (replyType != "void" && replyType != "ASYNC" && !replyType.isEmpty() ) + { + TQDataStream reply(replyData, IO_ReadOnly); + if (demarshal(replyType, reply, mainView->lb_replyData)) + { + mainView->l_replyType->setText + ( + i18n("<strong>%1</strong>") + .arg(TQString::fromUtf8(replyType)) + ); + mainView->lb_replyData->show(); + } + else + { + mainView->l_replyType->setText(i18n("Unknown type %1.").arg(TQString::fromUtf8(replyType))); + mainView->lb_replyData->hide(); + } + } + else + { + mainView->l_replyType->setText(i18n("No returned values")); + mainView->lb_replyData->hide(); + } + } +} + + +void KDCOPWindow::slotFillApplications() +{ + TDEApplication::setOverrideCursor(tqwaitCursor); + + QCStringList apps = dcopClient->registeredApplications(); + TQCString appId = dcopClient->appId(); + + mainView->lv->clear(); + + for (QCStringList::ConstIterator it = apps.begin(); it != apps.end(); ++it) + { + if ((*it) != appId && (*it).left(9) != "anonymous") + { + new DCOPBrowserApplicationItem(mainView->lv, *it); + } + } + + TDEApplication::restoreOverrideCursor(); +} + +bool KDCOPWindow::demarshal +( + TQCString & replyType, + TQDataStream & reply, + TQListBox *theList +) +{ + TQStringList ret; + TQPixmap pret; + bool isValid = true; + theList->clear(); + ret.clear(); + + if ( replyType == "TQVariant" ) + { + // read data type from stream + TQ_INT32 type; + reply >> type; + + // change replyType to real typename + replyType = TQVariant::typeToName( (TQVariant::Type)type ); + + // demarshal data with a recursive call + return demarshal(replyType, reply, theList); + } + else if ( replyType == "int" ) + { + int i; + reply >> i; + ret << TQString::number(i); + } + else if ( replyType == "uint" || replyType == "unsigned int" + || replyType == "TQ_UINT32" ) + { + uint i; + reply >> i; + ret << TQString::number(i); + } + else if ( replyType == "long" || replyType == "long int" ) + { + long l; + reply >> l; + ret << TQString::number(l); + } + else if ( replyType == "ulong" || replyType == "unsigned long" || replyType == "unsigned long int" ) + { + ulong l; + reply >> l; + ret << TQString::number(l); + } + else if ( replyType == "TQ_UINT64" ) + { + TQ_UINT64 i; + reply >> i; + ret << TQString::number(i); + } + else if ( replyType == "float" ) + { + float f; + reply >> f; + ret << TQString::number(f); + } + else if ( replyType == "double" ) + { + double d; + reply >> d; + ret << TQString::number(d); + } + else if (replyType == "bool") + { + bool b; + reply >> b; + ret << (b ? TQString::fromUtf8("true") : TQString::fromUtf8("false")); + } + else if (replyType == "TQString") + { + TQString s; + reply >> s; + ret << s; + } + else if (replyType == "TQStringList") + { + reply >> ret; + } + else if (replyType == "TQCString") + { + TQCString r; + reply >> r; + ret << TQString::fromUtf8(r); + } + else if (replyType == "QCStringList") + { + QCStringList lst; + reply >> lst; + + for (QCStringList::ConstIterator it(lst.begin()); it != lst.end(); ++it) + ret << *it; + } + else if (replyType == "KURL") + { + KURL r; + reply >> r; + ret << r.prettyURL(); + } + else if (replyType == "TQSize") + { + TQSize r; + reply >> r; + ret << TQString::number(r.width()) + "x" + TQString::number(r.height()); + } + else if (replyType == "TQPoint") + { + TQPoint r; + reply >> r; + ret << "(" + TQString::number(r.x()) + "," + TQString::number(r.y()) + ")"; + } + else if (replyType == "TQRect") + { + TQRect r; + reply >> r; + ret << TQString::number(r.x()) + "x" + TQString::number(r.y()) + "+" + TQString::number(r.height()) + "+" + TQString::number(r.width()); + } + else if (replyType == "TQFont") + { + TQFont r; + reply >> r; + ret << r.rawName(); + } + else if (replyType == "TQCursor") + { + TQCursor r; + reply >> r; + //theList->insertItem(r, 1); + ret << "Cursor #" + TQString::number(r.shape()); + } + else if (replyType == "TQPixmap") + { + TQPixmap r; + reply >> r; + theList->insertItem(r, 1); + } + else if (replyType == "TQColor") + { + TQColor r; + reply >> r; + TQString color = r.name(); + TQPixmap p(15,15); + p.fill(r); + theList->insertItem(p,color, 1); + } + else if (replyType == "TQDateTime") + { + TQDateTime r; + reply >> r; + ret << r.toString(); + } + else if (replyType == "TQDate") + { + TQDate r; + reply >> r; + ret << r.toString(); + } + else if (replyType == "TQTime") + { + TQTime r; + reply >> r; + ret << r.toString(); + } + else if (replyType == "DCOPRef") + { + DCOPRef r; + reply >> r; + if (!r.app().isEmpty() && !r.obj().isEmpty()) + ret << TQString("DCOPRef(%1, %2)").arg(static_cast<const char *>(r.app()), static_cast<const char *>(r.obj())); + } + else + { + ret << + i18n("Do not know how to demarshal %1").arg(TQString::fromUtf8(replyType)); + isValid = false; + } + + if (!ret.isEmpty()) + theList->insertStringList(ret); + return isValid; +} + + void +KDCOPWindow::slotApplicationRegistered(const TQCString & appName) +{ + TQListViewItemIterator it(mainView->lv); + + for (; it.current(); ++it) + { + DCOPBrowserApplicationItem * item = + static_cast<DCOPBrowserApplicationItem *>(it.current()); + + if (item->app() == appName) + return; + } + + TQCString appId = dcopClient->appId(); + + if (appName != appId && appName.left(9) != "anonymous") + { + new DCOPBrowserApplicationItem(mainView->lv, appName); + } +} + + void +KDCOPWindow::slotApplicationUnregistered(const TQCString & appName) +{ + TQListViewItemIterator it(mainView->lv); + + for (; it.current(); ++it) + { + DCOPBrowserApplicationItem * item = + static_cast<DCOPBrowserApplicationItem *>(it.current()); + + if (item->app() == appName) + { + delete item; + return; + } + } +} + + bool +KDCOPWindow::getParameters +( + const TQString & _unNormalisedSignature, + TQString & normalisedSignature, + TQStringList & types, + TQStringList & names +) +{ + TQString unNormalisedSignature(_unNormalisedSignature); + + int s = unNormalisedSignature.find(' '); + + if ( s < 0 ) + s = 0; + else + s++; + + unNormalisedSignature = unNormalisedSignature.mid(s); + + int left = unNormalisedSignature.find('('); + int right = unNormalisedSignature.findRev(')'); + + if (-1 == left) + { + // Fucked up function signature. + return false; + } + + TQStringList intTypes; + intTypes << "int" << "unsigned" << "long" << "bool" ; + + if (left > 0 && left + 1 < right - 1) + { + types = + TQStringList::split + (',', unNormalisedSignature.mid(left + 1, right - left - 1)); + + for (TQStringList::Iterator it = types.begin(); it != types.end(); ++it) + { + (*it) = (*it).simplifyWhiteSpace(); + + int s = (*it).findRev(' '); + + if (-1 != s && !intTypes.contains((*it).mid(s + 1))) + { + names.append((*it).mid(s + 1)); + + (*it) = (*it).left(s); + } + } + } + + normalisedSignature = + unNormalisedSignature.left(left) + "(" + types.join(",") + ")"; + + return true; +} +void KDCOPWindow::slotCopy() +{ + // Copy pixmap and text to the clipboard from the + // below list view. If there is nothing selected from + // the below menu then tell the tree to copy its current + // selection as text. + TQClipboard *clipboard = TQApplication::clipboard(); + if (mainView->lb_replyData->count()!= 0) + { + + //if (!mainView->lb_replyData->pixmap(mainView->lb_replyData->currentItem())->isNull()) + //{ + kdDebug() << "Is pixmap" << endl; + // TQPixmap p; + // p = *mainView->lb_replyData->pixmap(mainView->lb_replyData->currentItem()); + // clipboard->setPixmap(p); + //} + TQString t = mainView->lb_replyData->text(mainView->lb_replyData->currentItem()); + if (!t.isNull()) + clipboard->setText(t); + } +} + +void KDCOPWindow::slotMode() +{ + kdDebug () << "Going to mode " << langmode->currentText() << endl; + // Tell lv what the current mode is here... + mainView->lv->setMode(langmode->currentText()); +} + +#include "kdcopwindow.moc" diff --git a/kdcop/kdcopwindow.h b/kdcop/kdcopwindow.h new file mode 100644 index 000000000..bf0fe532e --- /dev/null +++ b/kdcop/kdcopwindow.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2000 by Matthias Kalle Dalheimer <[email protected]> + * + * Licensed under the Artistic License. + */ + +#ifndef __KDCOPWINDOW_H__ +#define __KDCOPWINDOW_H__ + +class DCOPClient; +class TQListViewItem; +class TDEAction; +class TDESelectAction; +class TQWidgetStack; +class TQLabel; +class KDCOPListView; + +#include <tdemainwindow.h> +#include "kdcoplistview.h" +#include "kdcopview.h" + +class KDCOPWindow : public TDEMainWindow +{ + Q_OBJECT + + public: + + KDCOPWindow( TQWidget* parent = 0, const char* name = 0 ); + + protected slots: + + void slotCurrentChanged( TQListViewItem* item ); + void slotCallFunction(); + void slotCallFunction( TQListViewItem* item ); + void slotApplicationRegistered(const TQCString &); + void slotApplicationUnregistered(const TQCString &); + void slotFillApplications(); + void slotCopy(); + void slotMode(); + void slotReload(); + private: + void fillObjects( DCOPBrowserItem*, const char* app ); + void fillFunctions( DCOPBrowserItem*, const char* app, const char* obj ); + + bool getParameters + ( + const TQString & unNormalisedSignature, + TQString & normalisedSignature, + TQStringList & types, + TQStringList & names + ); + + bool demarshal(TQCString & replyType, TQDataStream & reply, TQListBox *theList); + + DCOPClient * dcopClient; + TDEAction * exeaction; + TDESelectAction * langmode; + kdcopview * mainView; + TQVBoxLayout * mainLayout; +}; + + + +#endif |