summaryrefslogtreecommitdiffstats
path: root/kdcop
diff options
context:
space:
mode:
Diffstat (limited to 'kdcop')
-rw-r--r--kdcop/Makefile.am23
-rw-r--r--kdcop/README11
-rw-r--r--kdcop/kdcop.cpp37
-rw-r--r--kdcop/kdcoplistview.cpp157
-rw-r--r--kdcop/kdcoplistview.h133
-rw-r--r--kdcop/kdcopui.rc15
-rw-r--r--kdcop/kdcopview.ui149
-rw-r--r--kdcop/kdcopwindow.cpp1238
-rw-r--r--kdcop/kdcopwindow.h64
9 files changed, 1827 insertions, 0 deletions
diff --git a/kdcop/Makefile.am b/kdcop/Makefile.am
new file mode 100644
index 000000000..358d45549
--- /dev/null
+++ b/kdcop/Makefile.am
@@ -0,0 +1,23 @@
+#
+# KDCOP Makefile.am
+#
+# Copyright 2000 Matthias Kalle Dalheimer, kalle@dalheimer.de
+#
+#
+
+INCLUDES = $(all_includes)
+
+bin_PROGRAMS = kdcop
+
+kdcop_SOURCES = kdcop.cpp kdcopwindow.cpp kdcoplistview.cpp kdcopview.ui
+kdcop_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_KIO) -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, <kalle@kde.org>
+
diff --git a/kdcop/kdcop.cpp b/kdcop/kdcop.cpp
new file mode 100644
index 000000000..41d7c3dd0
--- /dev/null
+++ b/kdcop/kdcop.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2000 by Matthias Kalle Dalheimer <kalle@kde.org>
+ *
+ * Licensed under the Artistic License.
+ */
+#include <kapplication.h>
+#include <klocale.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+
+#include "kdcopwindow.h"
+
+static const KCmdLineOptions options[] =
+{
+ KCmdLineLastOption
+};
+
+int main( int argc, char ** argv )
+{
+ KAboutData aboutData( "kdcop", I18N_NOOP("KDCOP"),
+ "0.1", I18N_NOOP( "A graphical DCOP browser/client" ),
+ KAboutData::License_Artistic,
+ "(c) 2000, Matthias Kalle Dalheimer");
+ aboutData.addAuthor("Matthias Kalle Dalheimer",0, "kalle@kde.org");
+ aboutData.addAuthor("Rik Hemsley",0, "rik@kde.org");
+ aboutData.addAuthor("Ian Reinhart Geiser",0,"geiseri@kde.org");
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options );
+
+ KApplication 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..07e0b9fb8
--- /dev/null
+++ b/kdcop/kdcoplistview.cpp
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2000 by Ian Reinhart Geiser <geiseri@kde.org>
+ *
+ * Licensed under the Artistic License.
+ */
+
+#include "kdcoplistview.h"
+#include "kdcoplistview.moc"
+#include <kdebug.h>
+#include <qdragobject.h>
+#include <qstringlist.h>
+#include <qregexp.h>
+
+
+KDCOPListView::KDCOPListView ( QWidget *parent, const char *name)
+ : KListView(parent, name)
+{
+ kdDebug() << "Building new list." << endl;
+ setDragEnabled(true);
+}
+
+
+KDCOPListView::~KDCOPListView ()
+{
+
+}
+
+QDragObject *KDCOPListView::dragObject()
+{
+ kdDebug() << "Drag object called... " << endl;
+ if(!currentItem())
+ return 0;
+ else
+ return new QTextDrag(encode(this->selectedItem()), this);
+}
+
+void KDCOPListView::setMode( const QString &theMode )
+{
+ mode = theMode;
+}
+
+QString KDCOPListView::encode(QListViewItem *theCode)
+{
+ DCOPBrowserItem * item = static_cast<DCOPBrowserItem *>(theCode);
+
+ if (item->type() != DCOPBrowserItem::Function)
+ return "";
+
+ DCOPBrowserFunctionItem * fitem =
+ static_cast<DCOPBrowserFunctionItem *>(item);
+
+ QString function = QString::fromUtf8(fitem->function());
+ QString application = QString::fromUtf8(fitem->app());
+ QString object = QString::fromUtf8(fitem->object());
+
+ kdDebug() << function << endl;
+ QString returnType = function.section(' ', 0,0);
+ QString returnCode = "";
+ QString normalisedSignature;
+ QStringList types;
+ QStringList names;
+
+ QString 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 = QStringList::split
+ (',', unNormalisedSignature.mid(left + 1, right - left - 1));
+ for (QStringList::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++")
+ {
+ QString args;
+ for( unsigned int i = 0; i < names.count(); i++)
+ {
+ args += types[i] + " " + names[i] + ";\n";
+ }
+ QString dcopRef = "DCOPRef m_" + application + object
+ + "(\""+ application + "\",\"" + object +"\");\n";
+
+ QString stringNames = names.join(",");
+ QString 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")
+ {
+ QString 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;
+}
+
+QString KDCOPListView::getCurrentCode() const
+{
+ // fixing warning
+ return QString::null;
+}
diff --git a/kdcop/kdcoplistview.h b/kdcop/kdcoplistview.h
new file mode 100644
index 000000000..4a14620cc
--- /dev/null
+++ b/kdcop/kdcoplistview.h
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2000 by Ian Reinhart Geiser <geiseri@kde.org>
+ *
+ * Licensed under the Artistic License.
+ */
+
+#ifndef __KDCOPLISTVIEW_H__
+#define __KDCOPLISTVIEW_H__
+
+
+#include <klistview.h>
+class QDragObject;
+
+class KDCOPListView : public KListView
+{
+ Q_OBJECT
+
+ public:
+ KDCOPListView ( QWidget * parent = 0, const char * name = 0 );
+ virtual ~KDCOPListView();
+ QDragObject *dragObject();
+ void setMode(const QString &mode);
+ QString getCurrentCode() const;
+
+ private:
+ QString encode(QListViewItem *code);
+ QString mode;
+
+};
+
+class DCOPBrowserItem : public QListViewItem
+{
+ public:
+
+ enum Type { Application, Interface, Function };
+
+ DCOPBrowserItem(QListView * parent, Type type);
+ DCOPBrowserItem(QListViewItem * parent, Type type);
+
+ virtual ~DCOPBrowserItem() {}
+
+ Type type() const;
+
+ private:
+
+ Type type_;
+};
+
+class DCOPBrowserApplicationItem : public QObject, public DCOPBrowserItem
+{
+ Q_OBJECT
+ public:
+
+ DCOPBrowserApplicationItem(QListView * parent, const QCString & app);
+ virtual ~DCOPBrowserApplicationItem() {}
+
+ QCString app() const { return app_; }
+
+ virtual void setOpen(bool o);
+
+ protected:
+
+ virtual void populate();
+
+ private:
+
+ QCString app_;
+ private slots:
+ /**
+ * Theses two slots are used to get the icon of the application
+ */
+ void retreiveIcon(int callId, const QCString& replyType, const QByteArray &replyData);
+ void slotGotWindowName(int callId, const QCString& replyType, const QByteArray &replyData);
+};
+
+class DCOPBrowserInterfaceItem : public QObject, public DCOPBrowserItem
+{
+ public:
+
+ DCOPBrowserInterfaceItem
+ (
+ DCOPBrowserApplicationItem * parent,
+ const QCString & app,
+ const QCString & object,
+ bool def
+ );
+
+ virtual ~DCOPBrowserInterfaceItem() {}
+
+ QCString app() const { return app_; }
+ QCString object() const { return object_; }
+
+ virtual void setOpen(bool o);
+
+ protected:
+
+ virtual void populate();
+
+ private:
+
+ QCString app_;
+ QCString object_;
+};
+
+
+class DCOPBrowserFunctionItem : public DCOPBrowserItem
+{
+ public:
+
+ DCOPBrowserFunctionItem
+ (
+ DCOPBrowserInterfaceItem * parent,
+ const QCString & app,
+ const QCString & object,
+ const QCString & function
+ );
+
+ virtual ~DCOPBrowserFunctionItem() {}
+
+ QCString app() const { return app_; }
+ QCString object() const { return object_; }
+ QCString function() const { return function_; }
+
+ virtual void setOpen(bool o);
+
+ private:
+
+ QCString app_;
+ QCString object_;
+ QCString 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>&amp;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..5d1de7a93
--- /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 geiseri@kde.org</author>
+<widget class="QWidget">
+ <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="KListViewSearchLine" row="0" column="1">
+ <property name="name">
+ <cstring>kListViewSearchLine1</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Search:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>kListViewSearchLine1</cstring>
+ </property>
+ </widget>
+ <widget class="QSplitter" 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="QLayoutWidget">
+ <property name="name">
+ <cstring>layout18</cstring>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel" 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="KListBox" row="1" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>lb_replyData</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" 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>klistviewsearchline.h</includehint>
+ <includehint>kdcoplistview.h</includehint>
+ <includehint>klistbox.h</includehint>
+</includehints>
+</UI>
diff --git a/kdcop/kdcopwindow.cpp b/kdcop/kdcopwindow.cpp
new file mode 100644
index 000000000..506fb22ef
--- /dev/null
+++ b/kdcop/kdcopwindow.cpp
@@ -0,0 +1,1238 @@
+/*
+ * Copyright (C) 2000 by Matthias Kalle Dalheimer <kalle@kde.org>
+ * 2004 by Olivier Goffart <ogoffart @ tiscalinet.be>
+ *
+ * Licensed under the Artistic License.
+ */
+
+#include "kdcopwindow.h"
+#include "kdcoplistview.h"
+
+#include <dcopclient.h>
+#include <klocale.h>
+#include <kdatastream.h>
+#include <kstdaction.h>
+#include <kaction.h>
+#include <kapplication.h>
+#include <kmessagebox.h>
+#include <kdialog.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klineedit.h>
+#include <keditlistbox.h>
+#include <klistbox.h>
+#include <kdialogbase.h>
+#include <kstdaccel.h>
+#include <kcolorbutton.h>
+#include <klistviewsearchline.h>
+
+#include <qtimer.h>
+#include <qwidgetstack.h>
+#include <qlabel.h>
+#include <qsplitter.h>
+#include <qlayout.h>
+#include <qcheckbox.h>
+#include <qlineedit.h>
+#include <qvalidator.h>
+#include <qpushbutton.h>
+#include <qkeycode.h>
+#include <qpixmap.h>
+#include <qcursor.h>
+#include <qsize.h>
+#include <qrect.h>
+#include <qclipboard.h>
+#include <qdatetime.h>
+#include <dcopref.h>
+#include <qvbox.h>
+#include <qimage.h>
+#include <qheader.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 QVBox
+{
+public:
+ KMultiIntEdit(QWidget *parent , const char * name=0) : QVBox(parent,name) {}
+ void addField(int key, const QString & caption )
+ {
+ QHBox *l=new QHBox(this);
+ new QLabel(caption + ": ", l);
+ KLineEdit* e = new KLineEdit( l );
+ m_widgets.insert(key, e ) ;
+ e->setValidator( new QIntValidator( e ) );
+ }
+ int field(int key)
+ {
+ KLineEdit *e=m_widgets[key];
+ if(!e) return 0;
+ return e->text().toInt();
+ }
+
+private:
+ QMap<int,KLineEdit*> m_widgets;
+};
+
+//------------------------------
+
+DCOPBrowserItem::DCOPBrowserItem
+(QListView * parent, DCOPBrowserItem::Type type)
+ : QListViewItem(parent),
+ type_(type)
+{
+}
+
+DCOPBrowserItem::DCOPBrowserItem
+(QListViewItem * parent, DCOPBrowserItem::Type type)
+ : QListViewItem(parent),
+ type_(type)
+{
+}
+
+ DCOPBrowserItem::Type
+DCOPBrowserItem::type() const
+{
+ return type_;
+}
+
+// ------------------------------------------------------------------------
+
+DCOPBrowserApplicationItem::DCOPBrowserApplicationItem
+(QListView * parent, const QCString & app)
+ : DCOPBrowserItem(parent, Application),
+ app_(app)
+{
+ setExpandable(true);
+ setText(0, QString::fromUtf8(app_));
+ setPixmap(0, KGlobal::iconLoader()->loadIcon( QString::fromLatin1( "exec" ), KIcon::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
+ */
+
+ QRegExp rx( "([^\\-]+)"); // remove the possible processus id
+ rx.search(app_); // konqueror-123 => konqueror-mainwindow#1
+ QString mainWindowName= rx.cap(1) + "-mainwindow#1" ;
+
+ QByteArray data;
+ int callId=kapp->dcopClient()->callAsync( app_, mainWindowName.utf8(), "icon()", data, this, SLOT(retreiveIcon(int, const QCString&, const QByteArray&)));
+
+ if(!callId)
+ {
+ //maybe there is another mainwindow registered with another name.
+ QByteArray data;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << QCString( "MainWindow" );
+
+ kapp->dcopClient()->callAsync( app_, "qt", "find(QCString)", data, this, SLOT(slotGotWindowName(int, const QCString&, const QByteArray& )));
+ }
+}
+
+ void
+DCOPBrowserApplicationItem::setOpen(bool o)
+{
+ DCOPBrowserItem::setOpen(o);
+
+ if (0 == firstChild())
+ populate();
+}
+
+ void
+DCOPBrowserApplicationItem::populate()
+{
+ KApplication::setOverrideCursor(waitCursor);
+
+ 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;
+ }
+
+ KApplication::restoreOverrideCursor();
+}
+
+void DCOPBrowserApplicationItem::slotGotWindowName(int /*callId*/, const QCString& /*replyType*/, const QByteArray &replyData)
+{
+ QDataStream reply(replyData, IO_ReadOnly);
+ QCStringList mainswindows;
+ reply >> mainswindows;
+ QStringList sl=QStringList::split("/",mainswindows.first() );
+ if(sl.count() >= 1)
+ {
+ QString mainWindowName=sl[1];
+ if(!mainWindowName.isEmpty())
+ {
+ QByteArray data;
+ kapp->dcopClient()->callAsync( app_, mainWindowName.utf8(), "icon()", data,
+ this, SLOT(retreiveIcon(int, const QCString&, const QByteArray&)));
+ }
+ }
+}
+
+void DCOPBrowserApplicationItem::retreiveIcon(int /*callId*/,const QCString& /*replyType*/, const QByteArray &replyData)
+{
+ QDataStream reply(replyData, IO_ReadOnly);
+ QPixmap returnQPixmap;
+ reply >> returnQPixmap;
+ if(!returnQPixmap.isNull())
+ setPixmap(0, QPixmap(returnQPixmap.convertToImage().smoothScale(16,16)) );
+ else
+ kdDebug() << "Unable to retreive the icon" << endl;
+}
+
+// ------------------------------------------------------------------------
+
+DCOPBrowserInterfaceItem::DCOPBrowserInterfaceItem
+(
+ DCOPBrowserApplicationItem * parent,
+ const QCString & app,
+ const QCString & object,
+ bool def
+)
+ : DCOPBrowserItem(parent, Interface),
+ app_(app),
+ object_(object)
+{
+ setExpandable(true);
+
+ if (def)
+ setText(0, i18n("%1 (default)").arg(QString::fromUtf8(object_)));
+ else
+ setText(0, QString::fromUtf8(object_));
+}
+
+ void
+DCOPBrowserInterfaceItem::setOpen(bool o)
+{
+ DCOPBrowserItem::setOpen(o);
+
+ if (0 == firstChild())
+ populate();
+}
+
+ void
+DCOPBrowserInterfaceItem::populate()
+{
+ KApplication::setOverrideCursor(waitCursor);
+
+ 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);
+
+ KApplication::restoreOverrideCursor();
+}
+
+// ------------------------------------------------------------------------
+
+DCOPBrowserFunctionItem::DCOPBrowserFunctionItem
+(
+ DCOPBrowserInterfaceItem * parent,
+ const QCString & app,
+ const QCString & object,
+ const QCString & function
+)
+ : DCOPBrowserItem(parent, Function),
+ app_(app),
+ object_(object),
+ function_(function)
+{
+ setExpandable(false);
+ setText(0, QString::fromUtf8(function_));
+}
+
+ void
+DCOPBrowserFunctionItem::setOpen(bool o)
+{
+ DCOPBrowserItem::setOpen(o);
+}
+
+// ------------------------------------------------------------------------
+
+KDCOPWindow::KDCOPWindow(QWidget *parent, const char * name)
+ : KMainWindow(parent, name)
+{
+ dcopClient = kapp->dcopClient();
+ dcopClient->attach();
+ resize( 377, 480 );
+ statusBar()->message(i18n("Welcome to the KDE 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,
+ SIGNAL(doubleClicked(QListViewItem *)),
+ SLOT(slotCallFunction(QListViewItem *))
+ );
+
+ connect
+ (
+ mainView->lv,
+ SIGNAL(currentChanged(QListViewItem *)),
+ SLOT(slotCurrentChanged(QListViewItem *))
+ );
+
+
+ // set up the actions
+ KStdAction::quit( this, SLOT( close() ), actionCollection() );
+ KStdAction::copy( this, SLOT( slotCopy()), actionCollection() );
+ KStdAction::keyBindings( guiFactory(), SLOT( configureShortcuts() ), actionCollection() );
+
+
+ (void) new KAction( i18n( "&Reload" ), "reload", KStdAccel::shortcut(KStdAccel::Reload), this, SLOT( slotReload() ), actionCollection(), "reload" );
+
+ exeaction =
+ new KAction
+ (
+ i18n("&Execute"),
+ "exec",
+ CTRL + Key_E,
+ this,
+ SLOT(slotCallFunction()),
+ actionCollection(),
+ "execute"
+ );
+
+ exeaction->setEnabled(false);
+ exeaction->setToolTip(i18n("Execute the selected DCOP call."));
+
+ langmode = new KSelectAction ( i18n("Language Mode"),
+ CTRL + Key_M,
+ this,
+ SLOT(slotMode()),
+ actionCollection(),
+ "langmode");
+ langmode->setEditable(false);
+ langmode->setItems(QStringList::split(",", "Shell,C++,Python"));
+ langmode->setToolTip(i18n("Set the current language export."));
+ langmode->setCurrentItem(0);
+ slotMode();
+ connect
+ (
+ dcopClient,
+ SIGNAL(applicationRegistered(const QCString &)),
+ SLOT(slotApplicationRegistered(const QCString &))
+ );
+
+ connect
+ (
+ dcopClient,
+ SIGNAL(applicationRemoved(const QCString &)),
+ SLOT(slotApplicationUnregistered(const QCString &))
+ );
+
+ dcopClient->setNotifications(true);
+ createGUI();
+ setCaption(i18n("DCOP Browser"));
+ mainView->lb_replyData->hide();
+ QTimer::singleShot(0, this, SLOT(slotFillApplications()));
+}
+
+
+void KDCOPWindow::slotCurrentChanged( QListViewItem* 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( QListViewItem* it )
+{
+ if(it == 0)
+ return;
+ DCOPBrowserItem * item = static_cast<DCOPBrowserItem *>(it);
+
+ if (item->type() != DCOPBrowserItem::Function)
+ return;
+
+ DCOPBrowserFunctionItem * fitem =
+ static_cast<DCOPBrowserFunctionItem *>(item);
+
+ QString unNormalisedSignature = QString::fromUtf8(fitem->function());
+ QString normalisedSignature;
+ QStringList types;
+ QStringList names;
+
+ if (!getParameters(unNormalisedSignature, normalisedSignature, types, names))
+ {
+ KMessageBox::error
+ (this, i18n("No parameters found."), i18n("DCOP Browser Error"));
+
+ return;
+ }
+
+ QByteArray data;
+ QByteArray replyData;
+
+ QCString replyType;
+
+ QDataStream arg(data, IO_WriteOnly);
+
+ KDialogBase mydialog( this, "KDCOP Parameter Entry", true,
+ QString::null, KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true );
+
+ mydialog.setCaption
+ ( i18n("Call Function %1").arg( fitem->function() ) );
+
+ QFrame *frame = mydialog.makeMainWidget();
+
+ QLabel* h1 = new QLabel( i18n( "Name" ), frame );
+ QLabel* h2 = new QLabel( i18n( "Type" ), frame );
+ QLabel* h3 = new QLabel( i18n( "Value" ), frame );
+
+ QGridLayout* grid = new QGridLayout( 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;
+
+ QPtrList<QWidget> wl;
+
+ for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
+ {
+ i++;
+
+ const QString type = *it;
+
+ const QString name = i-1 < (int)names.count() ? names[i-1] : QString::null;
+
+ if( type == "int" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "int", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ e->setValidator( new QIntValidator( e ) );
+ }
+ else if ( type == "unsigned" || type == "uint" || type == "unsigned int"
+ || type == "Q_UINT32" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "unsigned int", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+
+ QIntValidator* iv = new QIntValidator( e );
+ iv->setBottom( 0 );
+ e->setValidator( iv );
+ }
+ else if ( type == "long" || type == "long int" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "long", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ e->setValidator( new QIntValidator( e ) );
+ }
+ else if ( type == "ulong" || type == "unsigned long" || type == "unsigned long int"
+ || type == "Q_UINT64" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "unsigned long", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ e->setValidator( new QIntValidator( e ) );
+ }
+ else if ( type == "short" || type == "short int" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "long", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ e->setValidator( new QIntValidator( e ) );
+ }
+ else if ( type == "ushort" || type == "unsigned short" || type == "unsigned short int" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "unsigned short", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ e->setValidator( new QIntValidator( e ) );
+ }
+ else if ( type == "float" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "float", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ e->setValidator( new QDoubleValidator( e ) );
+ }
+ else if ( type == "double" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "double", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ e->setValidator( new QDoubleValidator( e ) );
+ }
+ else if ( type == "bool" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "bool", frame );
+ grid->addWidget( l, i, 1 );
+ QCheckBox* c = new QCheckBox( frame );
+ grid->addWidget( c, i, 2 );
+ wl.append( c );
+ }
+ else if ( type == "QString" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QString", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ }
+ else if ( type == "QCString" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QString", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ }
+ else if ( type == "QStringList" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QStringList", frame );
+ grid->addWidget( l, i, 1 );
+ KEditListBox* e = new KEditListBox ( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ }
+ else if ( type == "QValueList<QCString>" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QValueList<QCString>", frame );
+ grid->addWidget( l, i, 1 );
+ KEditListBox* e = new KEditListBox ( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ }
+ else if ( type == "KURL" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "KURL", frame );
+ grid->addWidget( l, i, 1 );
+ KLineEdit* e = new KLineEdit( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ }
+ else if ( type == "QColor" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QColor", frame );
+ grid->addWidget( l, i, 1 );
+ KColorButton* e = new KColorButton( frame );
+ grid->addWidget( e, i, 2 );
+ wl.append( e );
+ }
+ else if ( type == "QSize" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QSize", 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 == "QPoint" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QPoint", 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 == "QRect" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QRect", 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 == "QPixmap" )
+ {
+ QLabel* n = new QLabel( name, frame );
+ grid->addWidget( n, i, 0 );
+ QLabel* l = new QLabel( "QPixmap", 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 (QDialog::Accepted != ret)
+ return;
+
+ // extract the arguments
+
+ i = 0;
+
+ for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
+ {
+ QString 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 == "Q_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 == "Q_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" )
+ {
+ QCheckBox* c = (QCheckBox*)wl.at( i );
+ arg << c->isChecked();
+ }
+ else if( type == "QCString" )
+ {
+ KLineEdit* e = (KLineEdit*)wl.at( i );
+ arg << QCString( e->text().local8Bit() );
+ }
+ else if( type == "QString" )
+ {
+ KLineEdit* e = (KLineEdit*)wl.at( i );
+ arg << e->text();
+ }
+ else if( type == "QStringList" )
+ {
+ KEditListBox* e = (KEditListBox*)wl.at( i );
+ arg << e->items();
+ }
+ else if( type == "QValueList<QCString>" )
+ {
+ KEditListBox* e = (KEditListBox*)wl.at( i );
+ for (int i = 0; i < e->count(); i++)
+ arg << QCString( e->text(i).local8Bit() );
+ }
+ else if( type == "KURL" )
+ {
+ KLineEdit* e = (KLineEdit*)wl.at( i );
+ arg << KURL( e->text() );
+ }
+ else if( type == "QColor" )
+ {
+ KColorButton* e = (KColorButton*)wl.at( i );
+ arg << e->color();
+ }
+ else if( type == "QSize" )
+ {
+ KMultiIntEdit* e = (KMultiIntEdit*)wl.at( i );
+ arg << QSize(e->field(1) , e->field(2)) ;
+ }
+ else if( type == "QPoint" )
+ {
+ KMultiIntEdit* e = (KMultiIntEdit*)wl.at( i );
+ arg << QPoint(e->field(1) , e->field(2)) ;
+ }
+ else if( type == "QRect" )
+ {
+ KMultiIntEdit* e = (KMultiIntEdit*)wl.at( i );
+ arg << QRect(e->field(1) , e->field(2) , e->field(3) , e->field(4)) ;
+ }
+ else if( type == "QPixmap" )
+ {
+ KURLRequester* e= (KURLRequester*)wl.at( i );
+ arg << QPixmap(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"));
+
+ QString 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
+ {
+ QString coolSignature =
+ QString::fromUtf8(fitem->app())
+ + "."
+ + QString::fromUtf8(fitem->object())
+ + "."
+ + normalisedSignature ;
+
+ statusBar()->message(i18n("DCOP call %1 executed").arg(coolSignature));
+
+ if (replyType != "void" && replyType != "ASYNC" && !replyType.isEmpty() )
+ {
+ QDataStream reply(replyData, IO_ReadOnly);
+ if (demarshal(replyType, reply, mainView->lb_replyData))
+ {
+ mainView->l_replyType->setText
+ (
+ i18n("<strong>%1</strong>")
+ .arg(QString::fromUtf8(replyType))
+ );
+ mainView->lb_replyData->show();
+ }
+ else
+ {
+ mainView->l_replyType->setText(i18n("Unknown type %1.").arg(QString::fromUtf8(replyType)));
+ mainView->lb_replyData->hide();
+ }
+ }
+ else
+ {
+ mainView->l_replyType->setText(i18n("No returned values"));
+ mainView->lb_replyData->hide();
+ }
+ }
+}
+
+
+void KDCOPWindow::slotFillApplications()
+{
+ KApplication::setOverrideCursor(waitCursor);
+
+ QCStringList apps = dcopClient->registeredApplications();
+ QCString 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);
+ }
+ }
+
+ KApplication::restoreOverrideCursor();
+}
+
+bool KDCOPWindow::demarshal
+(
+ QCString & replyType,
+ QDataStream & reply,
+ QListBox *theList
+)
+{
+ QStringList ret;
+ QPixmap pret;
+ bool isValid = true;
+ theList->clear();
+ ret.clear();
+
+ if ( replyType == "QVariant" )
+ {
+ // read data type from stream
+ Q_INT32 type;
+ reply >> type;
+
+ // change replyType to real typename
+ replyType = QVariant::typeToName( (QVariant::Type)type );
+
+ // demarshal data with a recursive call
+ return demarshal(replyType, reply, theList);
+ }
+ else if ( replyType == "int" )
+ {
+ int i;
+ reply >> i;
+ ret << QString::number(i);
+ }
+ else if ( replyType == "uint" || replyType == "unsigned int"
+ || replyType == "Q_UINT32" )
+ {
+ uint i;
+ reply >> i;
+ ret << QString::number(i);
+ }
+ else if ( replyType == "long" || replyType == "long int" )
+ {
+ long l;
+ reply >> l;
+ ret << QString::number(l);
+ }
+ else if ( replyType == "ulong" || replyType == "unsigned long" || replyType == "unsigned long int" )
+ {
+ ulong l;
+ reply >> l;
+ ret << QString::number(l);
+ }
+ else if ( replyType == "Q_UINT64" )
+ {
+ Q_UINT64 i;
+ reply >> i;
+ ret << QString::number(i);
+ }
+ else if ( replyType == "float" )
+ {
+ float f;
+ reply >> f;
+ ret << QString::number(f);
+ }
+ else if ( replyType == "double" )
+ {
+ double d;
+ reply >> d;
+ ret << QString::number(d);
+ }
+ else if (replyType == "bool")
+ {
+ bool b;
+ reply >> b;
+ ret << (b ? QString::fromUtf8("true") : QString::fromUtf8("false"));
+ }
+ else if (replyType == "QString")
+ {
+ QString s;
+ reply >> s;
+ ret << s;
+ }
+ else if (replyType == "QStringList")
+ {
+ reply >> ret;
+ }
+ else if (replyType == "QCString")
+ {
+ QCString r;
+ reply >> r;
+ ret << QString::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 == "QSize")
+ {
+ QSize r;
+ reply >> r;
+ ret << QString::number(r.width()) + "x" + QString::number(r.height());
+ }
+ else if (replyType == "QPoint")
+ {
+ QPoint r;
+ reply >> r;
+ ret << "(" + QString::number(r.x()) + "," + QString::number(r.y()) + ")";
+ }
+ else if (replyType == "QRect")
+ {
+ QRect r;
+ reply >> r;
+ ret << QString::number(r.x()) + "x" + QString::number(r.y()) + "+" + QString::number(r.height()) + "+" + QString::number(r.width());
+ }
+ else if (replyType == "QFont")
+ {
+ QFont r;
+ reply >> r;
+ ret << r.rawName();
+ }
+ else if (replyType == "QCursor")
+ {
+ QCursor r;
+ reply >> r;
+ //theList->insertItem(r, 1);
+ ret << "Cursor #" + QString::number(r.shape());
+ }
+ else if (replyType == "QPixmap")
+ {
+ QPixmap r;
+ reply >> r;
+ theList->insertItem(r, 1);
+ }
+ else if (replyType == "QColor")
+ {
+ QColor r;
+ reply >> r;
+ QString color = r.name();
+ QPixmap p(15,15);
+ p.fill(r);
+ theList->insertItem(p,color, 1);
+ }
+ else if (replyType == "QDateTime")
+ {
+ QDateTime r;
+ reply >> r;
+ ret << r.toString();
+ }
+ else if (replyType == "QDate")
+ {
+ QDate r;
+ reply >> r;
+ ret << r.toString();
+ }
+ else if (replyType == "QTime")
+ {
+ QTime r;
+ reply >> r;
+ ret << r.toString();
+ }
+ else if (replyType == "DCOPRef")
+ {
+ DCOPRef r;
+ reply >> r;
+ if (!r.app().isEmpty() && !r.obj().isEmpty())
+ ret << QString("DCOPRef(%1, %2)").arg(r.app(), r.obj());
+ }
+ else
+ {
+ ret <<
+ i18n("Do not know how to demarshal %1").arg(QString::fromUtf8(replyType));
+ isValid = false;
+ }
+
+ if (!ret.isEmpty())
+ theList->insertStringList(ret);
+ return isValid;
+}
+
+ void
+KDCOPWindow::slotApplicationRegistered(const QCString & appName)
+{
+ QListViewItemIterator it(mainView->lv);
+
+ for (; it.current(); ++it)
+ {
+ DCOPBrowserApplicationItem * item =
+ static_cast<DCOPBrowserApplicationItem *>(it.current());
+
+ if (item->app() == appName)
+ return;
+ }
+
+ QCString appId = dcopClient->appId();
+
+ if (appName != appId && appName.left(9) != "anonymous")
+ {
+ new DCOPBrowserApplicationItem(mainView->lv, appName);
+ }
+}
+
+ void
+KDCOPWindow::slotApplicationUnregistered(const QCString & appName)
+{
+ QListViewItemIterator 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 QString & _unNormalisedSignature,
+ QString & normalisedSignature,
+ QStringList & types,
+ QStringList & names
+)
+{
+ QString 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;
+ }
+
+ QStringList intTypes;
+ intTypes << "int" << "unsigned" << "long" << "bool" ;
+
+ if (left > 0 && left + 1 < right - 1)
+ {
+ types =
+ QStringList::split
+ (',', unNormalisedSignature.mid(left + 1, right - left - 1));
+
+ for (QStringList::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.
+ QClipboard *clipboard = QApplication::clipboard();
+ if (mainView->lb_replyData->count()!= 0)
+ {
+
+ //if (!mainView->lb_replyData->pixmap(mainView->lb_replyData->currentItem())->isNull())
+ //{
+ kdDebug() << "Is pixmap" << endl;
+ // QPixmap p;
+ // p = *mainView->lb_replyData->pixmap(mainView->lb_replyData->currentItem());
+ // clipboard->setPixmap(p);
+ //}
+ QString 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..18e4ecfb6
--- /dev/null
+++ b/kdcop/kdcopwindow.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2000 by Matthias Kalle Dalheimer <kalle@kde.org>
+ *
+ * Licensed under the Artistic License.
+ */
+
+#ifndef __KDCOPWINDOW_H__
+#define __KDCOPWINDOW_H__
+
+class DCOPClient;
+class QListViewItem;
+class KAction;
+class KSelectAction;
+class QWidgetStack;
+class QLabel;
+class KDCOPListView;
+
+#include <kmainwindow.h>
+#include "kdcoplistview.h"
+#include "kdcopview.h"
+
+class KDCOPWindow : public KMainWindow
+{
+ Q_OBJECT
+
+ public:
+
+ KDCOPWindow( QWidget* parent = 0, const char* name = 0 );
+
+ protected slots:
+
+ void slotCurrentChanged( QListViewItem* item );
+ void slotCallFunction();
+ void slotCallFunction( QListViewItem* item );
+ void slotApplicationRegistered(const QCString &);
+ void slotApplicationUnregistered(const QCString &);
+ 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 QString & unNormalisedSignature,
+ QString & normalisedSignature,
+ QStringList & types,
+ QStringList & names
+ );
+
+ bool demarshal(QCString & replyType, QDataStream & reply, QListBox *theList);
+
+ DCOPClient * dcopClient;
+ KAction * exeaction;
+ KSelectAction * langmode;
+ kdcopview * mainView;
+ QVBoxLayout * mainLayout;
+};
+
+
+
+#endif