[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-09-16 12:47:15
Message-ID: 20100916124715.967B3AC88C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1176027 by weilbach:

Improve memory management. Don't cleanup other running, but otherwise removable \
torrents. Respect KTorrent MaxShareRatio settings for the group.


 M  +1 -0      kio_magnet.cpp  
 M  +30 -10    ktorrentdbusinterface.cpp  
 M  +3 -0      magnetsettings.kcfg  


--- trunk/playground/ioslaves/kio_magnet/kio_magnet.cpp #1176026:1176027
@@ -144,6 +144,7 @@
 	    ps += max_ipc_size;
 	else 
 	    ps = m_size;
+	kDebug() << "processed size: " << ps;
         processedSize(ps);
     }
     kDebug() << "reading ended.";
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.cpp #1176026:1176027
@@ -45,6 +45,7 @@
         , m_file( -1 )
         , m_fileSize( 0 )
         , m_passedTime( 0 )
+	, m_process( 0 )
 {
     kDebug() << "Thread: " << thread();
     m_mutex.lock();
@@ -56,7 +57,15 @@
 KTorrentDBusInterface::~KTorrentDBusInterface()
 {
     kDebug();
+    if (!m_tor.isEmpty()) {
+        QStringList rt = MagnetSettings::runningTorrents();
+        rt.removeAll(m_tor);
+        MagnetSettings::setRunningTorrents(rt);
+    }
     MagnetSettings::self()->writeConfig();
+    delete m_process;
+    delete m_torrentInt;
+    // TODO check memory managment
 }
 
 void KTorrentDBusInterface::init()
@@ -105,7 +114,7 @@
                 m_passedTime+=timeout;
             } else {
                 m_slave->error(KIO::ERR_COULD_NOT_CONNECT,
-                               i18n("Could not connect to KTorrent via DBus after %1 \
seconds. Is it installed?") +                               i18n("Could not connect \
                to KTorrent via DBus after %1 seconds. Is it broken?")
                                .arg(m_passedTime));
                 return;
             }
@@ -127,12 +136,20 @@
     } else {
         if (!groupList.value().contains("Web Share")) {
             m_coreInt->addGroup("Web Share");
-        }
         org::ktorrent::group groupInt("org.ktorrent.ktorrent", "/group/Web Share", \
bus );  KStandardDirs *dirs = new KStandardDirs();
-        groupInt.setDefaultSaveLocation(dirs->saveLocation("data","Web Share"));
+            groupInt.setDefaultSaveLocation(dirs->saveLocation("data","kio_torrent/"));
  groupInt.setMaxShareRatio(MagnetSettings::maxShareRatio());
+	    delete dirs;
+        } else {
+            org::ktorrent::group groupInt("org.ktorrent.ktorrent", "/group/Web \
Share", bus ); +	    // respect changes inside KTorrent
+	    if(groupInt.maxShareRatio().isValid())
+		MagnetSettings::setMaxShareRatio(groupInt.maxShareRatio());
+	    else
+		groupInt.setMaxShareRatio(MagnetSettings::maxShareRatio());
     }
+    }
 
     connect(m_coreInt,SIGNAL(torrentAdded(const \
                QString&)),this,SLOT(slotTorrentAdded(const QString&)));
     connect(m_coreInt,SIGNAL(finished(const QString&)),this,SLOT(slotFinished(const \
QString&))); @@ -238,11 +255,11 @@
     QList<QString>::const_iterator it = torrents.begin();
     QList<QString>::const_iterator end = torrents.end();
     for (;it!=end;it++) {
-        if ((*it)==m_tor)
+        if ((*it)==m_tor||MagnetSettings::runningTorrents().contains((*it)))
             break;
         KTorrentTorrentInterface* torrentInt = new \
org::ktorrent::torrent("org.ktorrent.ktorrent", "/torrent/"+(*it),  \
                QDBusConnection::sessionBus());
-        if (!torrentInt->isValid() || // remove finished/broken torrents TODO do not \
break other running torrents +        if (!torrentInt->isValid() ||
                 (torrentInt->bytesLeft()==0 && \
torrentInt->shareRatio()>=MagnetSettings::maxShareRatio())) {  QStringList mt = \
MagnetSettings::managedTorrents();  mt.removeAll((*it));
@@ -252,8 +269,8 @@
             kDebug() << "remove " << (*it) << " torrent.";
             continue;
         }
-        totalSize+=torrentInt->bytesDownloaded(); // TODO might get wrong results if \
                network connection is buggy
-        if (torrentInt->bytesLeft()==0) { // only add finished torrents, otherwise \
we might remove running downloads below +        \
totalSize+=torrentInt->bytesDownloaded(); // TODO might get wrong results if network \
connection is buggy? +        if (torrentInt->bytesLeft()==0) {
             tList[(*it)]=torrentInt->shareRatio();
             kDebug() << (*it) << "-> " << torrentInt->shareRatio();
         }
@@ -310,13 +327,16 @@
     if ( tor != m_tor )
         return;
 
-    cleanup();
-
     QStringList mt = MagnetSettings::managedTorrents();
+    QStringList rt = MagnetSettings::runningTorrents();
     mt.append(m_tor);
+    rt.append(m_tor);
     MagnetSettings::setManagedTorrents(mt);
+    MagnetSettings::setRunningTorrents(rt);
     MagnetSettings::self()->writeConfig();
 
+    cleanup();
+
     QDBusReply<uint>numFiles = m_torrentInt->numFiles();
     int n = numFiles.value();
     if (m_file==-1&&n!=0) { // TODO add directory support
@@ -363,7 +383,7 @@
 {
     kDebug()<< tor << error;
     if ( m_tor == tor) {
-        m_slave->error(KIO::ERR_CANNOT_OPEN_FOR_WRITING,error);
+        m_slave->error(KIO::ERR_ABORTED,error);
         m_coreInt->remove(tor,true);
         QStringList mt = MagnetSettings::managedTorrents();
         mt.removeAll(m_tor);
--- trunk/playground/ioslaves/kio_magnet/magnetsettings.kcfg #1176026:1176027
@@ -33,6 +33,9 @@
 	    <entry name="ManagedTorrents" type="StringList">
 		<label>Torrents inside KTorrent which are managed by this modules.</label>
 	    </entry>
+	    <entry name="RunningTorrents" type="StringList">
+		    <label>Torrents currently used by the I/O-Slaves.</label>
+	    </entry>
 	    <entry name="MaxShareRatio" type="Double">
 		<label>The maximum share ratio which should be targeted for each torrent.</label>
 		<default>1.2</default>


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

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