[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-12-12 10:29:29
Message-ID: 20101212102929.C8688AC8A8 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1205728 by weilbach:

Adjusted to new stream dbus interface in KTorrent. Fixes.


 M  +1 -1      CMakeLists.txt  
 M  +4 -8      interfaces/org.ktorrent.torrent.xml  
 M  +2 -2      kio_magnet.cpp  
 M  +52 -25    ktorrentdbusinterface.cpp  
 M  +3 -0      ktorrentdbusinterface.h  
 M  +1 -1      ktorrenttorrentinterface.cpp  
 M  +6 -13     ktorrenttorrentinterface.h  


--- trunk/playground/ioslaves/kio_magnet/CMakeLists.txt #1205727:1205728
@@ -27,7 +27,7 @@
 
 set(kio_magnet_SRCS kio_magnet.cpp ktorrentdbusinterface.cpp dbusthread.cpp 
                      ktorrentcoreinterface.cpp ktorrenttorrentinterface.cpp
-                     ktorrentgroupinterface.cpp )
+                     ktorrenttorrentfilestreaminterface.cpp \
ktorrentgroupinterface.cpp )  
 
 kde4_add_kcfg_files(kio_magnet_SRCS magnetsettings.kcfgc)
--- trunk/playground/ioslaves/kio_magnet/interfaces/org.ktorrent.torrent.xml \
#1205727:1205728 @@ -158,14 +158,6 @@
       <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>
@@ -187,5 +179,9 @@
     <method name="seedTime">
       <arg type="d" direction="out"/>
     </method>
+    <method name="createStream">
+      <arg type="b" direction="out"/>
+      <arg name="file_index" type="u" direction="in"/>
+    </method>
   </interface>
 </node>
--- trunk/playground/ioslaves/kio_magnet/kio_magnet.cpp #1205727:1205728
@@ -200,7 +200,7 @@
     while ( !m_added ) {
         if (m_size!=-1) {
             totalSize( m_size );
-            m_size = -1;
+//            m_size = -1;
         }
         usleep (added_sleep);
     }
@@ -245,7 +245,7 @@
         return;
     }
     while (true) {
-        if (m_downloaded || m_ktorrentDBusInterface->seek(m_position)) {
+        if (m_downloaded || m_ktorrentDBusInterface->seek(m_position+size)) {
             file.seek(m_position);
             QByteArray d = file.read(size);
             data(d);
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.cpp #1205727:1205728
@@ -21,6 +21,9 @@
 #include "kio_magnet.h"
 #include "dbusthread.h"
 #include "ktorrentgroupinterface.h"
+#include "ktorrenttorrentinterface.h"
+#include "ktorrentcoreinterface.h"
+#include "ktorrenttorrentfilestreaminterface.h"
 #include "magnetsettings.h"
 
 #include <QtCore/QMutex>
@@ -44,6 +47,7 @@
 KTorrentDBusInterface::KTorrentDBusInterface(MagnetProtocol* slave) :
         m_coreInt( 0 )
         , m_torrentInt( 0 )
+        , m_streamInt( 0 )
         , m_slave( slave )
         , m_file( -1 )
         , m_fileSize( 0 )
@@ -66,9 +70,9 @@
         MagnetSettings::setRunningTorrents(rt);
     }
     MagnetSettings::self()->writeConfig();
-    m_torrentInt->createTorrentFileStream(m_file,false);
     delete m_process;
     delete m_torrentInt;
+    delete m_streamInt;
     // TODO check memory managment
 }
 
@@ -165,9 +169,30 @@
 
 bool KTorrentDBusInterface::seek(qint64 pos)
 {
-    return m_torrentInt->seekStream(pos);
+	if( !m_streamInt )
+		return false;
+	else
+	    return m_streamInt->seek( pos );
 }
 
+bool KTorrentDBusInterface::createFileStream( int file )
+{
+    kDebug();
+    if ( !m_torrentInt ) {
+        kDebug() << "Torrent interface not initialized. This should not happen.";
+        return false;
+    }
+
+    if ( m_torrentInt->createStream( file ) ) {
+        m_streamInt = new org::ktorrent::torrentfilestream( "org.ktorrent.ktorrent",
+                                                           \
"/torrent/"+m_tor+"/stream", +                                                        \
QDBusConnection::sessionBus() ); +        return true;
+    } else {
+        return false;
+    }
+}
+
 void KTorrentDBusInterface::load(const KUrl& u)
 {
     kDebug() << u.url() << " Thread: " << thread();
@@ -200,33 +225,33 @@
             m_slave->setPath(m_torrentInt->pathOnDisk());
             m_slave->setSize(m_torrentInt->totalSize());
             m_coreInt->start(m_tor);
-            m_torrentInt->createTorrentFileStream(0,true);
+            createFileStream(0);
         } else { 
             m_torrentInt->setDoNotDownload(m_file, false);
             m_slave->setPath(m_torrentInt->filePathOnDisk(m_file));
             m_slave->setSize(m_torrentInt->fileSize(m_file));
             m_coreInt->start(m_tor);
-            m_torrentInt->createTorrentFileStream(m_file,true);
+            createFileStream(m_file);
         }
         m_slave->added();
     } else {
-        m_torrentUrl = m_url.queryItem("to");
-        KUrl source( m_torrentUrl );
-        if (!MagnetSettings::trustedHosts().contains(source.host())) {
-            if ( m_slave->messageBox(KIO::SlaveBase::WarningYesNo,
-                                     i18n("The host \"%1\" is not known yet. Do you \
                want to trust its shared sources?")
-                                     .arg(source.host()),
-                                     i18n("Host not known")) != KMessageBox::Yes ) {
-                kDebug()<<"host rejected.";
-                m_slave->error(KIO::ERR_ABORTED,i18n("Host rejected."));
-                m_mutex.unlock();
-                return;
-            } else {
-                QStringList hosts = MagnetSettings::trustedHosts();
-                hosts << source.host();
-                MagnetSettings::setTrustedHosts(hosts);
-            }
-        }
+//         m_torrentUrl = m_url.queryItem("to");
+//         KUrl source( m_torrentUrl );
+//         if (!MagnetSettings::trustedHosts().contains(source.host())) {
+//             if ( m_slave->messageBox(KIO::SlaveBase::WarningYesNo,
+//                                      i18n("The host \"%1\" is not known yet. Do \
you want to trust its shared sources?") +//                                      \
.arg(source.host()), +//                                      i18n("Host not known")) \
!= KMessageBox::Yes ) { +//                 kDebug()<<"host rejected.";
+//                 m_slave->error(KIO::ERR_ABORTED,i18n("Host rejected."));
+//                 m_mutex.unlock();
+//                 return;
+//             } else {
+//                 QStringList hosts = MagnetSettings::trustedHosts();
+//                 hosts << source.host();
+//                 MagnetSettings::setTrustedHosts(hosts);
+//             }
+//         }
         m_coreInt->loadSilently(m_url.url(),"MagnetShare");
     }
 
@@ -254,7 +279,7 @@
 void KTorrentDBusInterface::cleanup()
 {
     kDebug();
-    if (!m_torrentInt)
+/*    if (!m_torrentInt)
         return;
 
     qulonglong totalSize=0;
@@ -270,6 +295,7 @@
             mt.removeAll(torrent);
             MagnetSettings::setManagedTorrents( mt );
             delete torrentInt;
+			torrentInt = 0;
             m_coreInt->remove(torrent,true);
             kDebug() << "removed " << torrent << " torrent.";
             continue;
@@ -302,7 +328,7 @@
         }
     }
 
-    MagnetSettings::self()->writeConfig();
+    MagnetSettings::self()->writeConfig();*/
 }
 
 void KTorrentDBusInterface::slotFinished(const QString& tor)
@@ -312,6 +338,7 @@
 
 void KTorrentDBusInterface::slotTorrentAdded(const QString& tor)
 {
+	m_slave->messageBox(KIO::SlaveBase::QuestionYesNo, "TEST", "TEST" );
     kDebug()<< tor;
     if ( tor != m_tor )
         return;
@@ -320,8 +347,8 @@
     if ( m_slave->messageBox(KIO::SlaveBase::QuestionYesNo
                              , i18n( "Do you want to download and share the Torrent: \
                \"%1\"?" ).arg( m_torrentInt->name() )
                              , i18n( "Magnet-Link confirmation" )) != \
KMessageBox::Yes ) { +        m_coreInt->remove(tor,true);
         m_slave->error(KIO::ERR_UNKNOWN, i18n("Download of torrent %1 rejected by \
                user.").arg(tor));
-        m_coreInt->remove(tor,true);
         return;
     }
     m_coreInt->start(tor);
@@ -350,7 +377,7 @@
     }
 
     // TODO stream all torrents for now
-    m_torrentInt->createTorrentFileStream(m_file,true);
+    createFileStream(m_file);
 
     m_coreInt->start(m_tor);
 
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.h #1205727:1205728
@@ -22,6 +22,7 @@
 
 #include "ktorrentcoreinterface.h"
 #include "ktorrenttorrentinterface.h"
+#include "ktorrenttorrentfilestreaminterface.h"
 
 #include <QtCore/QMutex>
 #include <QtDBus/QDBusConnection>
@@ -55,8 +56,10 @@
     void initDBus();
     void setupDBus();
     void findFile();
+    bool createFileStream( int file );
     org::ktorrent::core* m_coreInt;
     org::ktorrent::torrent* m_torrentInt;
+    org::ktorrent::torrentfilestream* m_streamInt;
     KProcess* m_process;
     QDBusConnection* m_bus;
     KUrl m_url;
--- trunk/playground/ioslaves/kio_magnet/ktorrenttorrentinterface.cpp \
#1205727:1205728 @@ -1,6 +1,6 @@
 /*
  * This file was generated by qdbusxml2cpp version 0.7
- * Command line was: qdbusxml2cpp interfaces/org.ktorrent.torrent.xml -c \
KTorrentTorrentInterface -p ktorrenttorrentinterface + * Command line was: \
qdbusxml2cpp -c KTorrentTorrentInterface org.ktorrent.torrent.xml -p \
                ktorrenttorrentinterface
  *
  * qdbusxml2cpp is Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
  *
--- trunk/playground/ioslaves/kio_magnet/ktorrenttorrentinterface.h #1205727:1205728
@@ -1,6 +1,6 @@
 /*
  * This file was generated by qdbusxml2cpp version 0.7
- * Command line was: qdbusxml2cpp interfaces/org.ktorrent.torrent.xml -c \
KTorrentTorrentInterface -p ktorrenttorrentinterface + * Command line was: \
qdbusxml2cpp -c KTorrentTorrentInterface org.ktorrent.torrent.xml -p \
                ktorrenttorrentinterface
  *
  * qdbusxml2cpp is Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
  *
@@ -8,8 +8,8 @@
  * Do not edit! All changes made to it will be lost.
  */
 
-#ifndef KTORRENTTORRENTINTERFACE_H_1289391006
-#define KTORRENTTORRENTINTERFACE_H_1289391006
+#ifndef KTORRENTTORRENTINTERFACE_H_1292059091
+#define KTORRENTTORRENTINTERFACE_H_1292059091
 
 #include <QtCore/QObject>
 #include <QtCore/QByteArray>
@@ -112,11 +112,11 @@
         return asyncCallWithArgumentList(QLatin1String("chunks"), argumentList);
     }
 
-    inline QDBusPendingReply<> createTorrentFileStream(uint file_index, bool \
streaming_mode) +    inline QDBusPendingReply<bool> createStream(uint file_index)
     {
         QList<QVariant> argumentList;
-        argumentList << qVariantFromValue(file_index) << \
                qVariantFromValue(streaming_mode);
-        return asyncCallWithArgumentList(QLatin1String("createTorrentFileStream"), \
argumentList); +        argumentList << qVariantFromValue(file_index);
+        return asyncCallWithArgumentList(QLatin1String("createStream"), \
argumentList);  }
 
     inline QDBusPendingReply<QString> currentTracker()
@@ -303,13 +303,6 @@
         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