[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: KDcop patch.
From: Olivier Goffart <ogoffart () tiscalinet ! be>
Date: 2004-11-07 11:28:55
Message-ID: 200411071228.55820.ogoffart () tiscalinet ! be
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
I wrote some time ago a patch for kdcop which let to connect to DCop signals
to display a messageBox when the signal is emitted.
I used it because i developped a small server application, and i wanted to
test if it emits the correct signals at the correct moment.
As i don't realy know who is the actual maintainer of KDcop, i send this to
this list.
Let me know if you are interested.
["kdcop_signals.diff" (text/x-diff)]
? Doxyfile
? kdcop.kdevelop
? kdcop.kdevelop.filelist
? kdcop.kdevelop.pcs
? kdcop.kdevses
? kdcop_signals.diff
? kdcopwindow.kidl
? kdcopwindow_skel.cpp
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdebase/kdcop/Makefile.am,v
retrieving revision 1.5
diff -u -p -b -B -r1.5 Makefile.am
Index: kdcop.cpp
===================================================================
RCS file: /home/kde/kdebase/kdcop/kdcop.cpp,v
retrieving revision 1.6
diff -u -p -b -B -r1.6 kdcop.cpp
--- kdcop.cpp 24 Feb 2004 11:30:09 -0000 1.6
+++ kdcop.cpp 7 Nov 2004 11:15:34 -0000
@@ -24,6 +24,7 @@ int main( int argc, char ** argv )
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");
+ aboutData.addAuthor("Olivier Goffart",0,"ogoffart@tiscalinet.be");
KCmdLineArgs::init( argc, argv, &aboutData );
KCmdLineArgs::addCmdLineOptions( options );
Index: kdcoplistview.h
===================================================================
RCS file: /home/kde/kdebase/kdcop/kdcoplistview.h,v
retrieving revision 1.6
diff -u -p -b -B -r1.6 kdcoplistview.h
--- kdcoplistview.h 31 Mar 2004 20:48:07 -0000 1.6
+++ kdcoplistview.h 7 Nov 2004 11:15:34 -0000
@@ -41,6 +41,10 @@ class DCOPBrowserItem : public QListView
Type type() const;
+ virtual QCString app() const { return QCString(); }
+ virtual QCString object() const { return QCString(); }
+
+
private:
Type type_;
Index: kdcopui.rc
===================================================================
RCS file: /home/kde/kdebase/kdcop/kdcopui.rc,v
retrieving revision 1.4
diff -u -p -b -B -r1.4 kdcopui.rc
--- kdcopui.rc 10 Sep 2003 14:23:42 -0000 1.4
+++ kdcopui.rc 7 Nov 2004 11:15:34 -0000
@@ -1,15 +1,17 @@
<!DOCTYPE kpartgui>
-<kpartgui name="kcop" version="2">
+<kpartgui name="kcop" version="3">
<MenuBar>
<Menu name="execute"><text>&Extra</text>
<Action name="reload"/>
<Action name="execute"/>
+ <Action name="connect"/>
<Action name="langmode"/>
</Menu>
</MenuBar>
<ToolBar fullWidth="true" name="mainToolBar"><text>Main Toolbar</text>
<Action name="reload"/>
<Action name="execute"/>
+ <Action name="connect"/>
<Action name="langmode"/>
</ToolBar>
</kpartgui>
Index: kdcopwindow.cpp
===================================================================
RCS file: /home/kde/kdebase/kdcop/kdcopwindow.cpp,v
retrieving revision 1.51
diff -u -p -b -B -r1.51 kdcopwindow.cpp
--- kdcopwindow.cpp 5 Sep 2004 12:18:53 -0000 1.51
+++ kdcopwindow.cpp 7 Nov 2004 11:15:35 -0000
@@ -278,10 +278,10 @@ DCOPBrowserFunctionItem::setOpen(bool o)
// ------------------------------------------------------------------------
KDCOPWindow::KDCOPWindow(QWidget *parent, const char * name)
- : KMainWindow(parent, name)
+ : KMainWindow(parent, name) , DCOPObject( "SignalReceiver")
{
dcopClient = kapp->dcopClient();
- dcopClient->attach();
+ //dcopClient->attach();
resize( 377, 480 );
statusBar()->message(i18n("Welcome to the KDE DCOP browser"));
@@ -341,6 +342,10 @@ KDCOPWindow::KDCOPWindow(QWidget *parent
langmode->setToolTip(i18n("Set the current language export."));
langmode->setCurrentItem(0);
slotMode();
+
+ conaction = new KAction( i18n("&Make Connection") , "connect_creating" , 0 , this \
, SLOT( slotConnect() ) , actionCollection() , "connect" ); + conaction->setToolTip( \
i18n("Make a connection from a DCOP signal" ) ); +
connect
(
dcopClient,
@@ -367,10 +374,7 @@ void KDCOPWindow::slotCurrentChanged( QL
{
DCOPBrowserItem* item = (DCOPBrowserItem*)i;
- if( item->type() == DCOPBrowserItem::Function )
- exeaction->setEnabled( true );
- else
- exeaction->setEnabled( false );
+ exeaction->setEnabled( item->type() == DCOPBrowserItem::Function );
}
@@ -858,25 +862,24 @@ void KDCOPWindow::slotCallFunction( QLis
}
else
{
+ mainView->lb_replyData->clear();
+
QString coolSignature =
- QString::fromUtf8(fitem->app())
- + "."
- + QString::fromUtf8(fitem->object())
- + "."
- + normalisedSignature ;
+ 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))
+ QStringList ret;
+ if (demarshal(replyType, reply, ret))
{
- mainView->l_replyType->setText
- (
- i18n("<strong>%1</strong>")
- .arg(QString::fromUtf8(replyType))
- );
+ if (!ret.isEmpty())
+ mainView->lb_replyData->insertStringList(ret);
+
+ mainView->l_replyType->setText(i18n("<strong>%1</strong>").arg(QString::fromUtf8(replyType)));
mainView->lb_replyData->show();
}
else
@@ -912,19 +916,14 @@ void KDCOPWindow::slotFillApplications()
}
KApplication::restoreOverrideCursor();
+
}
-bool KDCOPWindow::demarshal
-(
- QCString & replyType,
- QDataStream & reply,
- QListBox *theList
-)
+
+bool KDCOPWindow::demarshal( QCString & replyType, QDataStream & reply, QStringList \
&ret ) {
- QStringList ret;
QPixmap pret;
bool isValid = true;
- theList->clear();
ret.clear();
if ( replyType == "QVariant" )
@@ -937,7 +936,7 @@ bool KDCOPWindow::demarshal
replyType = QVariant::typeToName( (QVariant::Type)type );
// demarshal data with a recursive call
- return demarshal(replyType, reply, theList);
+ return demarshal(replyType, reply, ret);
}
else if ( replyType == "int" )
{
@@ -1053,7 +1052,7 @@ bool KDCOPWindow::demarshal
{
QPixmap r;
reply >> r;
- theList->insertItem(r, 1);
+ mainView->lb_replyData->insertItem(r, 1);
}
else if (replyType == "QColor")
{
@@ -1062,7 +1061,7 @@ bool KDCOPWindow::demarshal
QString color = r.name();
QPixmap p(15,15);
p.fill(r);
- theList->insertItem(p,color, 1);
+ mainView->lb_replyData->insertItem(p,color, 1);
}
else if (replyType == "QDateTime")
{
@@ -1096,8 +1095,6 @@ bool KDCOPWindow::demarshal
isValid = false;
}
- if (!ret.isEmpty())
- theList->insertStringList(ret);
return isValid;
}
@@ -1109,9 +1106,9 @@ KDCOPWindow::slotApplicationRegistered(c
for (; it.current(); ++it)
{
DCOPBrowserApplicationItem * item =
- static_cast<DCOPBrowserApplicationItem *>(it.current());
+ dynamic_cast<DCOPBrowserApplicationItem *>(it.current());
- if (item->app() == appName)
+ if (item && item->app() == appName)
return;
}
@@ -1131,9 +1128,9 @@ KDCOPWindow::slotApplicationUnregistered
for (; it.current(); ++it)
{
DCOPBrowserApplicationItem * item =
- static_cast<DCOPBrowserApplicationItem *>(it.current());
+ dynamic_cast<DCOPBrowserApplicationItem *>(it.current());
- if (item->app() == appName)
+ if (item && item->app() == appName)
{
delete item;
return;
@@ -1229,4 +1226,109 @@ void KDCOPWindow::slotMode()
mainView->lv->setMode(langmode->currentText());
}
+void KDCOPWindow::slotConnect()
+{
+ QString obj;
+ QString app;
+
+ DCOPBrowserItem * item = dynamic_cast<DCOPBrowserItem \
*>(mainView->lv->currentItem()); +
+ if(item)
+ {
+ obj=QString::fromUtf8(item->object());
+ app=QString::fromUtf8(item->app());
+ }
+
+ KDialogBase mydialog( this, "KDCOP Parameter Entry", true,
+ QString::null, KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true );
+
+ mydialog.setCaption ( i18n("Do a DCOP Signal Connection"));
+
+ QFrame *frame = mydialog.makeMainWidget();
+
+ QGridLayout* grid = new QGridLayout( frame, 4 , 2, 0, KDialog::spacingHint() );
+
+ grid->addWidget( new QLabel( i18n("Sender Application") , frame ) , 0, 0 );
+ KLineEdit* le_app = new KLineEdit( frame );
+ le_app->setText(app);
+ grid->addWidget( le_app, 0, 1 );
+
+ grid->addWidget( new QLabel( i18n("Sender Object") , frame ) , 1, 0 );
+ KLineEdit* le_obj = new KLineEdit( frame );
+ le_obj->setText(obj);
+ grid->addWidget( le_obj, 1, 1 );
+
+ grid->addWidget( new QLabel( i18n("Signal") , frame ) , 2, 0 );
+ KLineEdit* le_sig = new KLineEdit( frame );
+ grid->addWidget( le_sig, 2, 1 );
+
+ QCheckBox* c_vol = new QCheckBox( i18n("Volatile") , frame );
+ grid->addWidget( c_vol , 3, 0 );
+
+ if (mydialog.exec() != QDialog::Accepted )
+ return;
+
+ app=le_app->text();
+ obj=le_obj->text();
+ QString sig=le_sig->text();
+ bool vol=c_vol->isChecked();
+
+ bool r=kapp->dcopClient()->connectDCOPSignal( app.utf8(), obj.utf8(), sig.utf8(), \
"SignalReceiver" , sig.utf8() , vol ); + if(!r)
+ {
+ KMessageBox::error(this, i18n("Unable to establish the Connection"), i18n("DCOP \
Browser Error")); + }
+ else
+ {
+ statusBar()->message(i18n("DCOP Signal connected"));
+ }
+}
+
+
+bool KDCOPWindow::process(const QCString &fun, const QByteArray &data, QCString& \
replyType, QByteArray &replyData) +{
+ if(DCOPObject::process( fun, data, replyType, replyData ))
+ return true;
+
+// kdDebug () << "Got a signal: " << fun << data << endl;
+
+ QString unNormalisedSignature = QString::fromUtf8(fun);
+ QStringList types;
+
+ int left = unNormalisedSignature.find('(');
+ int right = unNormalisedSignature.findRev(')');
+
+ if (left > 0 && left + 1 < right - 1)
+ types = QStringList::split(',', unNormalisedSignature.mid(left + 1, right - left - \
1)); +
+ QDataStream arg( data, IO_ReadOnly );
+ QString argsStr;
+
+ for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
+ {
+ QString type = *it;
+ QStringList ret;
+ QCString t=type.utf8();
+ if(demarshal(t, arg, ret))
+ {
+ argsStr += i18n("<br><i>%1</i> = %2").arg(type, ret.join(",") ) ;
+ }
+ else
+ {
+ i18n("<br>Unknown type '%1' next arguments cannot be parsed").arg( type);
+ break;
+ }
+ }
+
+ DCOPClient *o=callingDcopClient();
+
+ QString message=i18n("<qt>A signal has been received by the application <i>%1</i> \
:<br><b>%2</b>%3</qt>") + .arg( o ? QString::fromUtf8(o->senderId()) : \
i18n("-unknown-") , unNormalisedSignature , argsStr ); +
+ KMessageBox::information(this, message, i18n("DCOP Signal Received"));
+
+ return true;
+}
+
+
#include "kdcopwindow.moc"
Index: kdcopwindow.h
===================================================================
RCS file: /home/kde/kdebase/kdcop/kdcopwindow.h,v
retrieving revision 1.14
diff -u -p -b -B -r1.14 kdcopwindow.h
--- kdcopwindow.h 31 Mar 2004 20:48:07 -0000 1.14
+++ kdcopwindow.h 7 Nov 2004 11:15:35 -0000
@@ -16,10 +16,11 @@ class QLabel;
class KDCOPListView;
#include <kmainwindow.h>
+#include <dcopobject.h>
#include "kdcoplistview.h"
#include "kdcopview.h"
-class KDCOPWindow : public KMainWindow
+class KDCOPWindow : public KMainWindow , public DCOPObject
{
Q_OBJECT
@@ -27,8 +28,11 @@ class KDCOPWindow : public KMainWindow
KDCOPWindow( QWidget* parent = 0, const char* name = 0 );
+ virtual bool process(const QCString &fun, const QByteArray &data, QCString& \
replyType, QByteArray &replyData); +
protected slots:
+
void slotCurrentChanged( QListViewItem* item );
void slotCallFunction();
void slotCallFunction( QListViewItem* item );
@@ -38,6 +42,9 @@ class KDCOPWindow : public KMainWindow
void slotCopy();
void slotMode();
void slotReload();
+ void slotConnect();
+
+
private:
void fillObjects( DCOPBrowserItem*, const char* app );
void fillFunctions( DCOPBrowserItem*, const char* app, const char* obj );
@@ -50,13 +57,15 @@ class KDCOPWindow : public KMainWindow
QStringList & names
);
- bool demarshal(QCString & replyType, QDataStream & reply, QListBox *theList);
+ bool demarshal(QCString & replyType, QDataStream & reply, QStringList &);
DCOPClient * dcopClient;
KAction * exeaction;
+ KAction * conaction;
KSelectAction * langmode;
kdcopview * mainView;
QVBoxLayout * mainLayout;
+
};
[Attachment #6 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic