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

List:       kde-commits
Subject:    playground/ioslaves/kio_torrent
From:       Christian Weilbach <christian () whiletaker ! homeip ! net>
Date:       2010-06-21 22:53:42
Message-ID: 20100621230153.56D6BAC8DA () svn ! kde ! org
[Download RAW message or body]

SVN commit 1140989 by weilbach:

Some cleanups and better thread understanding. Still no success with dbus signal \
catching though.


 M  +15 -18    dbusthread.cpp  
 M  +4 -1      dbusthread.h  
 M  +23 -4     kio_torrent.cpp  
 M  +4 -0      kio_torrent.h  


--- trunk/playground/ioslaves/kio_torrent/dbusthread.cpp #1140988:1140989
@@ -18,9 +18,9 @@
 */
 
 #include "dbusthread.h"
+#include "kio_torrent.h"
 
 #include <QtCore/QMutex>
-#include <QtCore/QCoreApplication>
 #include <QtCore/QThread>
 #include <QtDBus/QDBusInterface>
 #include <QtDBus/QDBusConnection>
@@ -32,9 +32,17 @@
 #include <KUrl>
 #include <kdebug.h>
 
+DBusThread::DBusThread(TorrentProtocol* slave)
+{
+    kDebug();
+    m_slave = slave;
+}
+
+
 void DBusThread::run()
 {
     kDebug();
+    initializeDBus();
     kDebug() << " starting event loop.";
     exec();
     kDebug() << " event loop finished.";
@@ -42,9 +50,10 @@
 
 void DBusThread::initializeDBus()
 {
+    kDebug();
     m_mutex.lock();
     QDBusConnection bus = QDBusConnection::sessionBus();
-    m_coreKtInterface = new QDBusInterface("org.ktorrent.ktorrent", "/core", \
"org.ktorrent.core", bus, this ); +    m_coreKtInterface = new \
QDBusInterface("org.ktorrent.ktorrent", "/core", "org.ktorrent.core", bus );  \
QDBusReply<QStringList>groupList = m_coreKtInterface->call("groups");  if \
                (!groupList.isValid()) {
         kError() << "Could not get the group list, do you have a compatible KTorrent \
version running?"; @@ -57,36 +66,24 @@
         KStandardDirs *dirs = new KStandardDirs();
         groupInt.call("setDefaultSaveLocation",dirs->saveLocation("data","kio_torrent"));
  }
-    kDebug() << 2;
 
-/*    if (!connect(m_coreKtInterface, SIGNAL(finished(const QString&)),
+    if (!connect(m_coreKtInterface, SIGNAL(finished(const QString&)),
                  this, SLOT(slotFinished(const QString&)))) {
         kDebug() << "Could not connect to finished().";
     }
     if (!connect(m_coreKtInterface, SIGNAL(torrentAdded(const QString&)),
                  this, SLOT(slotTorrentAdded(const QString&)))) {
         kDebug() << "Could not connect to torrentAdded().:";
-    }*/
-    bus.connect("org.ktorrent.ktorrent","/core","org.ktorrent.core","torrentAdded",this,SLOT(slotTorrentAdded(const \
QString &))); +    }
+//     bus.connect("org.ktorrent.ktorrent","/core","org.ktorrent.core","torrentAdded",this,SLOT(slotTorrentAdded(const \
QString &)));  //     \
bus.connect("org.ktorrent.ktorrent","/core","org.ktorrent.core","torrentRemoved",this,SLOT(torrentRemoved(const \
QString &)));  m_mutex.unlock();
 }
 
-void DBusThread::get( const KUrl& url )
-{
-    kDebug() << url.url();
-    m_mutex.lock();
-    m_url = url;
-    QString httpUrl = url.url();
-    httpUrl.replace("torrent:","http:");
-    QStringList splitUrl = httpUrl.split(QRegExp(".torrent(/)"));
-    m_coreKtInterface->call("loadSilently", splitUrl[0]+".torrent","kio_torrent");
-    m_mutex.unlock();
-}
-
 void DBusThread::slotFinished(const QString& tor)
 {
     kDebug()<< tor;
+    m_slave->finishGet();
 }
 
 void DBusThread::slotTorrentAdded(const QString& tor)
--- trunk/playground/ioslaves/kio_torrent/dbusthread.h #1140988:1140989
@@ -26,13 +26,15 @@
 #include <QtDBus/QDBusConnection>
 #include <KUrl>
 
+class TorrentProtocol;
+
 class DBusThread : public QThread
 {
     Q_OBJECT
     public:
+        DBusThread( TorrentProtocol* );
         void run();
 	void initializeDBus();
-        void get(const KUrl&);
 
     private slots:
         void slotFinished(const QString&);
@@ -41,6 +43,7 @@
         QDBusInterface* m_coreKtInterface;
         KUrl m_url;
 	QMutex m_mutex;
+	TorrentProtocol* m_slave;
 };
 
 #endif // DBUSTHREAD_H
--- trunk/playground/ioslaves/kio_torrent/kio_torrent.cpp #1140988:1140989
@@ -53,11 +53,13 @@
 }
 
 TorrentProtocol::TorrentProtocol( const QByteArray &pool, const QByteArray &app ) : \
SlaveBase("torrent", pool, app ) +    , m_finishGet(false)
 {
     kDebug();
-    m_dbusThread = new DBusThread();
+    m_dbusThread = new DBusThread(this);
     m_dbusThread->start();
-    m_dbusThread->initializeDBus();
+    QDBusConnection bus = QDBusConnection::sessionBus();
+    m_coreKtInterface = new QDBusInterface("org.ktorrent.ktorrent", "/core", \
"org.ktorrent.core", bus);  }
 
 TorrentProtocol::~TorrentProtocol()
@@ -82,6 +84,23 @@
 void TorrentProtocol::get( const KUrl& url )
 {
     kDebug() << url.url();
-    m_dbusThread->get( url );
-    while( true ) sleep (1000);
+    QString httpUrl = url.url();
+    httpUrl.replace("torrent:","http:");
+    QStringList splitUrl = httpUrl.split(QRegExp(".torrent(/)"));
+    m_coreKtInterface->call("loadSilently", splitUrl[0]+".torrent","kio_torrent");
+    while( true ){
+      if(m_finishGet){
+	m_finishGet = false;
+	finished();
+	break;
 }
+      sleep (1000);
+    }
+}
+
+void TorrentProtocol::finishGet()
+{
+    kDebug();
+    m_finishGet = true;
+}
+
--- trunk/playground/ioslaves/kio_torrent/kio_torrent.h #1140988:1140989
@@ -25,6 +25,7 @@
 #include <kio/slavebase.h>
 
 class DBusThread;
+class QDBusInterface;
 
 class TorrentProtocol : public KIO::SlaveBase
 {
@@ -35,9 +36,12 @@
         virtual void listDir( const KUrl & url );
         virtual void stat( const KUrl & url );
         virtual void get( const KUrl & url );
+	virtual void finishGet();
     private:
         KUrl m_url;
         DBusThread* m_dbusThread;
+	QDBusInterface* m_coreKtInterface;
+	bool m_finishGet;
 };
 
 #endif // KIO_TORRENT_H


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

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