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

List:       kde-commits
Subject:    playground/ioslaves/kio_magnet
From:       Christian Weilbach <christian () whiletaker ! homeip ! net>
Date:       2010-11-10 12:32:15
Message-ID: 20101110123215.C0DA9AC89E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1195119 by weilbach:

Finally works with direct streaming in patched KTorrent trunk.

 M  +8 -0      interfaces/org.ktorrent.torrent.xml  
 M  +12 -5     kio_magnet.cpp  
 M  +23 -15    ktorrentdbusinterface.cpp  
 M  +1 -0      ktorrentdbusinterface.h  
 M  +16 -2     ktorrenttorrentinterface.h  


--- trunk/playground/ioslaves/kio_magnet/interfaces/org.ktorrent.torrent.xml #1195118:1195119
@@ -158,6 +158,14 @@
       <arg name="file_index" type="u" direction="in"/>
       <arg name="dnd" type="b" direction="in"/>
     </method>
+    <method name="createTorrentFileStream">
+      <arg name="file_index" type="u" direction="in"/>
+      <arg name="streaming_mode" type="b" direction="in"/>
+    </method>
+    <method name="seekStream">
+      <arg type="b" direction="out"/>
+      <arg name="pos" type="x" direction="in"/>
+    </method>
     <method name="stats">
       <arg type="ay" direction="out"/>
     </method>
--- trunk/playground/ioslaves/kio_magnet/kio_magnet.cpp #1195118:1195119
@@ -124,10 +124,6 @@
         }
     }
 
-    KMimeType::Ptr mt = KMimeType::findByUrl( m_path, 0, true /* local URL */ );
-    kDebug() << "mimetype: " << mt->name();
-    emit mimeType( mt->name() );
-
     QFile file(m_path);
     if (!file.open(QIODevice::ReadOnly)) {
         error(KIO::ERR_ABORTED,
@@ -136,8 +132,16 @@
         return;
     }
 
-    qulonglong ps = 0;
+    bool emitMimetype=true;
+    qint64 ps = 0;
     while (!file.atEnd()) {
+        if (ps>32 && emitMimetype ) {
+            KMimeType::Ptr mt = KMimeType::findByUrl( m_path, 0, true /* local URL */ );
+            kDebug() << "mimetype: " << mt->name();
+            emit mimeType( mt->name() );
+	    emitMimetype=false;
+        }
+        if (m_ktorrentDBusInterface->seek(ps+max_ipc_size)) {
         QByteArray d = file.read(max_ipc_size);
         data(d);
 	if( (m_size - ps) > max_ipc_size )
@@ -146,7 +150,10 @@
 	    ps = m_size;
 	kDebug() << "processed size: " << ps;
         processedSize(ps);
+        } else {
+            usleep(100);
     }
+    }
     kDebug() << "reading ended.";
     file.close();
     finished();
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.cpp #1195118:1195119
@@ -162,6 +162,11 @@
     m_mutex.unlock();
 }
 
+bool KTorrentDBusInterface::seek(qint64 pos)
+{
+    return m_torrentInt->seekStream(pos);
+}
+
 void KTorrentDBusInterface::load(const KUrl& u)
 {
     kDebug() << u.url() << " Thread: " << thread();
@@ -299,21 +304,7 @@
 void KTorrentDBusInterface::slotFinished(const QString& tor)
 {
     kDebug()<< tor;
-    if ( tor == m_tor ) {
-        QDBusReply<QString>path;
-        if ( m_file == -1 )
-            path = m_torrentInt->pathOnDisk();
-        else
-            path = m_torrentInt->filePathOnDisk(m_file);
-        if (!path.isValid()) {
-            m_slave->error(KIO::ERR_SLAVE_DEFINED, i18n("Could not fetch path from KTorrent."));
-            delete m_coreInt;
-            return;
         }
-        QString p = path.value();
-        m_slave->setPath( p );
-    }
-}
 
 void KTorrentDBusInterface::slotTorrentAdded(const QString& tor)
 {
@@ -349,6 +340,9 @@
         m_torrentInt->setDoNotDownload(i, (i!=m_file) );
     }
 
+    // stream all torrents
+    m_torrentInt->createTorrentFileStream(m_file,true);
+
     m_coreInt->start(m_tor);
 
     QDBusReply<qulonglong> size;
@@ -357,8 +351,22 @@
     else
         size = m_torrentInt->fileSize(m_file);
     m_fileSize = size.value();
+    m_slave->setSize(m_fileSize);
     kDebug() << "fileSize: " << m_fileSize;
-    m_slave->setSize(m_fileSize);
+
+    QDBusReply<QString>path;
+    if ( m_file == -1 )
+        path = m_torrentInt->pathOnDisk();
+    else
+        path = m_torrentInt->filePathOnDisk(m_file);
+    if (!path.isValid()) {
+        m_slave->error(KIO::ERR_SLAVE_DEFINED, i18n("Could not fetch path from KTorrent."));
+        delete m_coreInt;
+        return;
+    }
+    QString p = path.value();
+    m_slave->setPath( p );
+
     m_slave->finish();
 }
 
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.h #1195118:1195119
@@ -42,6 +42,7 @@
     virtual ~KTorrentDBusInterface();
     virtual void load(const KUrl&);
     virtual void init();
+    bool seek(qint64 pos);
 
 private slots:
     void cleanup();
--- trunk/playground/ioslaves/kio_magnet/ktorrenttorrentinterface.h #1195118:1195119
@@ -8,8 +8,8 @@
  * Do not edit! All changes made to it will be lost.
  */
 
-#ifndef KTORRENTTORRENTINTERFACE_H_1283376263
-#define KTORRENTTORRENTINTERFACE_H_1283376263
+#ifndef KTORRENTTORRENTINTERFACE_H_1289391006
+#define KTORRENTTORRENTINTERFACE_H_1289391006
 
 #include <QtCore/QObject>
 #include <QtCore/QByteArray>
@@ -112,6 +112,13 @@
         return asyncCallWithArgumentList(QLatin1String("chunks"), argumentList);
     }
 
+    inline QDBusPendingReply<> createTorrentFileStream(uint file_index, bool streaming_mode)
+    {
+        QList<QVariant> argumentList;
+        argumentList << qVariantFromValue(file_index) << qVariantFromValue(streaming_mode);
+        return asyncCallWithArgumentList(QLatin1String("createTorrentFileStream"), argumentList);
+    }
+
     inline QDBusPendingReply<QString> currentTracker()
     {
         QList<QVariant> argumentList;
@@ -296,6 +303,13 @@
         return asyncCallWithArgumentList(QLatin1String("seedersTotal"), argumentList);
     }
 
+    inline QDBusPendingReply<bool> seekStream(qlonglong pos)
+    {
+        QList<QVariant> argumentList;
+        argumentList << qVariantFromValue(pos);
+        return asyncCallWithArgumentList(QLatin1String("seekStream"), argumentList);
+    }
+
     inline QDBusPendingReply<> setAllowedToStart(bool on)
     {
         QList<QVariant> argumentList;
[prev in list] [next in list] [prev in thread] [next in thread] 

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