[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-10 13:48:08
Message-ID: 20100910134808.F0D48AC88F () svn ! kde ! org
[Download RAW message or body]
SVN commit 1173803 by weilbach:
Properly support .torrent http urls with unpatched ktorrent.
M +37 -12 ktorrentdbusinterface.cpp
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.cpp #1173802:1173803
@@ -25,9 +25,7 @@
#include <QtCore/QMutex>
#include <QtCore/QThread>
#include <QtCore/QTimer>
-#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusConnection>
-#include <QtDBus/QDBusConnectionInterface>
#include <QtDBus/QDBusReply>
#include <kcomponentdata.h>
@@ -63,7 +61,9 @@
kDebug() << "Could not initialize org.ktorrent.ktorrent /core. KTorrent \
seems to be not running."; m_process = new KProcess();
if (m_process->startDetached("ktorrent")==-2) {
- m_slave->error(KIO::ERR_COULD_NOT_CONNECT, i18n("Cannot start process \
for KTorrent. This should not happen, even if KTorrent is not installed.")); + \
m_slave->error(KIO::ERR_COULD_NOT_CONNECT, + i18n("Cannot \
start process for KTorrent. This should not happen, \ + even if KTorrent is not \
installed.")); return;
}
m_process->waitForStarted();
@@ -85,7 +85,9 @@
QTimer::singleShot(timeout,this,SLOT(initializeDBus()));
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?").arg(m_passedTime)); + \
m_slave->error(KIO::ERR_COULD_NOT_CONNECT, + \
i18n("Could not connect to KTorrent via DBus after %1 seconds. Is it installed?") + \
.arg(m_passedTime)); return;
}
}
@@ -100,7 +102,8 @@
QDBusConnection bus = QDBusConnection::sessionBus();
QDBusReply<QStringList>groupList = m_coreInt->groups();
if (!groupList.isValid()) {
- m_slave->error(KIO::ERR_COULD_NOT_CONNECT,i18n("Could not get the group \
list, do you have a compatible KTorrent version running?")); + \
m_slave->error(KIO::ERR_COULD_NOT_CONNECT, + i18n("Could not \
get the group list, do you have a compatible KTorrent version running?")); return;
} else {
if (!groupList.value().contains("MagnetFS")) {
@@ -109,12 +112,14 @@
org::ktorrent::group groupInt("org.ktorrent.ktorrent", "/group/MagnetFS", \
bus ); KStandardDirs *dirs = new KStandardDirs();
groupInt.setDefaultSaveLocation(dirs->saveLocation("data","MagnetFS"));
+ groupInt.setMaxShareRatio(1.2);
}
connect(m_coreInt,SIGNAL(torrentAdded(const \
QString&)),this,SLOT(slotTorrentAdded(const QString&)));
connect(m_coreInt,SIGNAL(finished(const QString&)),this,SLOT(slotFinished(const \
QString&)));
connect(m_coreInt,SIGNAL(torrentRemoved(const \
QString&)),this,SLOT(slotTorrentRemoved(const QString&)));
- connect(m_coreInt,SIGNAL(torrentStoppedByError(const QString&, const \
QString&)),this,SLOT(slotTorrentStoppedByError(const QString&,const QString&))); + \
connect(m_coreInt,SIGNAL(torrentStoppedByError(const QString&, const QString&)), + \
this,SLOT(slotTorrentStoppedByError(const QString&,const QString&))); \
m_mutex.unlock(); }
@@ -124,12 +129,25 @@
m_mutex.lock();
KUrl url = u;
- // TODO parse correctly + error handling
QString xt = url.queryItemValue("xt");
QStringList args = xt.split(":");
- m_tor = args[2].toLower();
- m_file = args.count()>4 ? args[4].toUInt() : -1;
+ int aSize = args.size();
+ int btihIndex = args.indexOf("btih");
+ if ( btihIndex==-1 || aSize==btihIndex ) {
+ QString msg = i18n("This magnet-link is <b>not supported</b>. \
+ Torrent support is necessary at the moment, so you need to have at least a \
btih-hash \ + value in the xt-parameter. Try to copy and paste the link into a \
supported application."); + m_slave->error(KIO::ERR_ABORTED,msg);
+ m_slave->finish();
+ m_mutex.unlock();
+ return;
+ }
+ m_tor = args[btihIndex+1].toLower();
+
+ int flidIndex = args.indexOf("flid");
+ m_file = ( flidIndex!=-1 && aSize>flidIndex ) ? args[flidIndex+1].toUInt() : -1;
+
m_torrentInt = new org::ktorrent::torrent("org.ktorrent.ktorrent", \
"/torrent/"+m_tor, QDBusConnection::sessionBus());
QDBusReply<QString>name = m_torrentInt->name();
@@ -146,9 +164,15 @@
m_torrentInt->setDoNotDownload(m_file, false);
m_slave->finish();
} else {
- QString u = url.url();
- if ( m_file != -1)
+ QString u;
+ // TODO merge this properly in KTorrents magnet support
+ if (!url.host().isEmpty()&&!url.path().isEmpty()&&url.host()!="localhost") { \
// assume the http link works + u = \
url.url().split("?")[0].replace("magnet:","http:"); + } else {
+ u = "magnet:?" + url.url().split("?")[1];
+ if ( m_file != -1) //TODO
u.remove(":flid:"+args[4]);
+ }
kDebug() << "Load torrent in KTorrent: " << u;
m_coreInt->loadSilently(u, "MagnetFS");
@@ -186,7 +210,8 @@
QDBusReply<uint>numFiles = m_torrentInt->numFiles();
int n = numFiles.value();
if (m_file==-1&&n!=0) {
- m_slave->error(KIO::ERR_IS_DIRECTORY, i18n("Torrent \"%1\" contains a \
directory but no path to file given.").arg(m_torrentInt->name())); + \
m_slave->error(KIO::ERR_IS_DIRECTORY, i18n("Torrent \"%1\" contains a directory but \
no path to file given.") + .arg(m_torrentInt->name()));
delete m_coreInt;
return;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic