[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] KIO::SlaveBase and the event loop
From:       Sebastian =?iso-8859-1?q?Tr=FCg?= <strueg () mandriva ! com>
Date:       2008-07-14 16:27:26
Message-ID: 200807141827.26957.strueg () mandriva ! com
[Download RAW message or body]

Let me open with a question: Is there any technical problem with enabling 
event handling in KIO::SlaveBase?

The attached patch is not really pretty as it uses 
QCoreApplication::processEvents(). A proper implementation (which I would do 
once this issue is clarified) would be based on signal/slot communication.
But it works and allows to test the event handling.

As the event handling is disabled by default, nothing changes for existing kio 
slaves. But it allows my rebooted nepomuk search kio slave to update the 
folder contents when the database changes.

Cheers,
Sebastian

["slavebase-eventhandling.diff" (text/x-diff)]

Index: slavebase.h
===================================================================
--- slavebase.h	(revision 832330)
+++ slavebase.h	(working copy)
@@ -54,6 +54,16 @@
     virtual ~SlaveBase();
 
     /**
+     * Enable or disable event handling during dispatching.
+     *
+     * \param enabled if \p true events will be handled (for example
+     * signals will be delivered) during dispatching.
+     *
+     * The default is to not handle events.
+     */
+    void setEventHandlingEnabled( bool enabled );
+
+    /**
      * @internal
      * Terminate the slave by calling the destructor and then ::exit()
      */
Index: slavebase.cpp
===================================================================
--- slavebase.cpp	(revision 832330)
+++ slavebase.cpp	(working copy)
@@ -97,6 +97,7 @@
     KConfig *config;
     KConfigGroup *configGroup;
     KUrl onHoldUrl;
+    bool eventHandlingEnabled:1;
 
     struct timeval last_tv;
     KIO::filesize_t totalSize;
@@ -242,6 +243,7 @@
     d->remotefile = 0;
     d->inOpenLoop = false;
     d->exit_loop = false;
+    d->eventHandlingEnabled = false;
 }
 
 SlaveBase::~SlaveBase()
@@ -252,6 +254,13 @@
     s_protocol = "";
 }
 
+
+void SlaveBase::setEventHandlingEnabled( bool enabled )
+{
+    d->eventHandlingEnabled = enabled;
+}
+
+
 void SlaveBase::dispatchLoop()
 {
     while (!d->exit_loop) {
@@ -269,7 +278,7 @@
             ms = 1000 * qMax<time_t>(d->timeout - time(0), 1);
 
         int ret = -1;
-        if (d->appConnection.hasTaskAvailable() || \
d->appConnection.waitForIncomingTask(ms)) { +        if \
(d->appConnection.hasTaskAvailable() || (!d->eventHandlingEnabled && \
d->appConnection.waitForIncomingTask(ms))) {  // dispatch application messages
             int cmd;
             QByteArray data;
@@ -302,6 +311,9 @@
             kDebug(7019)<<" dispatchLoop() slave was killed, returning";
             return;
         }
+
+        if (d->eventHandlingEnabled)
+            QCoreApplication::processEvents();
     }
 }
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic