[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-09-02 2:22:23
Message-ID: 20100902022223.0BF96AC857 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1170777 by weilbach:
generate dbus interface from ktorrents classes and cleanup. support for single file \
downloads works, but ktorrent does not behave as expected. more errorhandling.
M +15 -6 CMakeLists.txt
A interfaces (directory)
A interfaces/org.ktorrent.core.xml
A interfaces/org.ktorrent.group.xml
A interfaces/org.ktorrent.torrent.xml
M +15 -10 kio_torrent.cpp
M +5 -2 kio_torrent.h
A ktorrentcoreinterface.cpp [License: GENERATED FILE]
A ktorrentcoreinterface.h [License: GENERATED FILE]
M +84 -20 ktorrentdbusinterface.cpp
M +11 -3 ktorrentdbusinterface.h
A ktorrentgroupinterface.cpp [License: GENERATED FILE]
A ktorrentgroupinterface.h [License: GENERATED FILE]
A ktorrenttorrentinterface.cpp [License: GENERATED FILE]
A ktorrenttorrentinterface.h [License: GENERATED FILE]
--- trunk/playground/ioslaves/kio_torrent/CMakeLists.txt #1170776:1170777
@@ -1,6 +1,6 @@
project(KIO_TORRENT)
-find_package(Qt4 4.6.0 REQUIRED)
-find_package(KDE4 4.4.0 REQUIRED)
+find_package(Qt4 4.5.0 REQUIRED)
+find_package(KDE4 4.3.0 REQUIRED)
# set some default settings
include(KDE4Defaults)
@@ -15,22 +15,31 @@
include(CheckFunctionExists)
include(CheckTypeSize) #XFS
-
# according to http://www.cmake.org/pipermail/cmake/2008-June/022381.html
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}")
add_definitions( ${KDE4_DEFINITIONS} )
-include_directories( ${KDE4_INCLUDES}
- )
+include_directories( ${KDE4_INCLUDES} )
########### kio_torrent ###############
-set(kio_torrent_SRCS kio_torrent.cpp ktorrentdbusinterface.cpp dbusthread.cpp )
+set(kio_torrent_SRCS kio_torrent.cpp ktorrentdbusinterface.cpp dbusthread.cpp
+ ktorrentcoreinterface.cpp ktorrenttorrentinterface.cpp
+ ktorrentgroupinterface.cpp )
kde4_add_plugin(kio_torrent ${kio_torrent_SRCS})
target_link_libraries(kio_torrent ${KDE4_KIO_LIBS} )
+# set(ktorrent_torrent_xml ./interfaces/org.ktorrent.torrent.xml)
+#qt4_add_dbus_interfaces(kio_torrent_SRCS org.ktorrent.core.xml \
org.ktorrent.torrent.xml ) +# qt4_add_dbus_interface(kio_torrent_SRCS \
org.ktorrent.core.xml ktorrent_torrent_interface ) +# PKGCONFIG_GETVAR(dbus-1 prefix \
DBUS_PREFIX) +# set(ktorrent_core_xml ./interfaces/org.ktorrent.core.xml)
+#set(sso_xml ${DBUS_PREFIX}/share/dbus-1/interfaces/com.ubuntu.sso.xml)
+# set_source_files_properties(${ktorrent_core_xml} PROPERTIES NO_NAMESPACE TRUE)
+# qt4_add_dbus_interface(kio_torrent_SRCS ${ktorrent_core_xml} \
KTorrentCoreInterface) +
install(TARGETS kio_torrent DESTINATION ${PLUGIN_INSTALL_DIR} )
install( FILES torrent.protocol DESTINATION ${SERVICES_INSTALL_DIR} )
--- trunk/playground/ioslaves/kio_torrent/kio_torrent.cpp #1170776:1170777
@@ -56,7 +56,6 @@
TorrentProtocol::TorrentProtocol( const QByteArray &pool, const QByteArray &app ) : \
SlaveBase("torrent", pool, app ) , m_finishStat(false)
- , m_finishGet(false)
{
kDebug();
m_ktorrentDBusInterface = new KTorrentDBusInterface(this);
@@ -84,12 +83,9 @@
void TorrentProtocol::get( const KUrl& url )
{
- kDebug() << url.url();
- while( true ){
- if(m_finishGet){
- m_finishGet = false;
- break;
- }
+ kDebug() << url.url() << "path: " << m_path;
+ totalSize( m_size );
+ while( m_path.isEmpty() ){
usleep (100);
}
@@ -97,8 +93,12 @@
emit mimeType( mt->name() );
QFile file(m_path);
- if (!file.open(QIODevice::ReadOnly))
+ if (!file.open(QIODevice::ReadOnly)){
+ error(KIO::ERR_CANNOT_OPEN_FOR_READING,
+ i18n("File exits in KTorrent, but cannot open it on disk at path \"%1\". Have \
you removed the file manually?").arg(m_path)); + finished();
return;
+ }
while (!file.atEnd()) {
QByteArray d = file.read(1024*32);
@@ -114,9 +114,14 @@
m_finishStat = true;
}
-void TorrentProtocol::finishGet(const QString& path)
+void TorrentProtocol::setPath(const QString& path)
{
kDebug() << path;
- m_finishGet = true;
m_path = path;
}
+
+void TorrentProtocol::setSize(qlonglong size)
+{
+ kDebug();
+ m_size = size;
+}
--- trunk/playground/ioslaves/kio_torrent/kio_torrent.h #1170776:1170777
@@ -34,13 +34,16 @@
virtual void stat( const KUrl & url );
virtual void get( const KUrl & url );
+ virtual void setSize( qlonglong );
+ virtual void setPath( const QString& );
virtual void finishStat();
- virtual void finishGet(const QString& );
+
private:
KUrl m_url;
KTorrentDBusInterface* m_ktorrentDBusInterface;
- bool m_finishStat, m_finishGet;
+ bool m_finishStat;
QString m_path;
+ qlonglong m_size;
};
#endif // KIO_TORRENT_H
--- trunk/playground/ioslaves/kio_torrent/ktorrentdbusinterface.cpp #1170776:1170777
@@ -20,6 +20,7 @@
#include "ktorrentdbusinterface.h"
#include "kio_torrent.h"
#include "dbusthread.h"
+#include "ktorrentgroupinterface.h"
#include <stdlib.h>
#include <unistd.h>
@@ -36,11 +37,14 @@
#include <KUrl>
#include <kdebug.h>
-KTorrentDBusInterface::KTorrentDBusInterface(TorrentProtocol* slave)
+KTorrentDBusInterface::KTorrentDBusInterface(TorrentProtocol* slave) :
+ m_torrentInt( 0 )
+ , m_coreInt( 0 )
{
kDebug() << "Thread: " << thread();
m_mutex.lock();
m_slave = slave;
+ m_file = -1;
m_thread = new DBusThread(this);
m_thread->start();
moveToThread(m_thread);
@@ -50,50 +54,65 @@
{
kDebug() << "Thread: " << thread();
QDBusConnection bus = QDBusConnection::sessionBus();
- m_coreKtInterface = new QDBusInterface("org.ktorrent.ktorrent", "/core", \
"org.ktorrent.core", bus );
- QDBusReply<QStringList>groupList = m_coreKtInterface->call("groups");
+ m_coreInt = new org::ktorrent::core("org.ktorrent.ktorrent", "/core",
+ bus,
+ this);
+ QDBusReply<QStringList>groupList = m_coreInt->groups();
if (!groupList.isValid()) {
kError() << "Could not get the group list, do you have a compatible KTorrent \
version running?"; } else {
kDebug() << groupList.value();
if (!groupList.value().contains("kio_torrent")) {
- m_coreKtInterface->call("addGroup","kio_torrent");
+ m_coreInt->addGroup("kio_torrent");
}
- QDBusInterface groupInt("org.ktorrent.ktorrent", "/group/kio_torrent", \
"org.ktorrent.group"); + org::ktorrent::group \
groupInt("org.ktorrent.ktorrent", "/group/kio_torrent", bus, this ); \
//"org.ktorrent.group"); KStandardDirs *dirs = new KStandardDirs();
- groupInt.call("setDefaultSaveLocation",dirs->saveLocation("data","kio_torrent"));
+ groupInt.setDefaultSaveLocation(dirs->saveLocation("data","kio_torrent"));
}
bus.connect("org.ktorrent.ktorrent","/core","org.ktorrent.core","torrentAdded",this,SLOT(slotTorrentAdded(const \
QString &)));
bus.connect("org.ktorrent.ktorrent","/core","org.ktorrent.core","finished",this,SLOT(slotFinished(const \
QString &)));
bus.connect("org.ktorrent.ktorrent","/core","org.ktorrent.core","torrentRemoved",this,SLOT(slotTorrentRemoved(const \
QString &))); + bus.connect("org.ktorrent.ktorrent","/core","org.ktorrent.core","torrentStoppedByError",this,SLOT(slotTorrentStoppedByError(const \
QString &, const QString &))); m_mutex.unlock();
}
-//magnet:?xt=urn:btih:78a81f594d83326e48758991dc365b3c9903d4af&dn=dsl-3.4-vmx&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce
+
void KTorrentDBusInterface::load(const KUrl& u)
{
kDebug() << u.url() << " Thread: " << thread();
m_mutex.lock();
KUrl url = u;
- m_fl= url.queryItemValue("fl");
- kDebug() << "m_fl = " << m_fl;
- url.removeQueryItem("fl");
-
QString xt = url.queryItemValue("xt");
- m_tor = xt.replace("urn:btih:","");
+ QStringList args = xt.split(":");
+ m_tor = args[2].toLower();
+ m_file = args.count()>4 ? args[4].toUInt() : -1;
+ kDebug() << m_file;
- QDBusReply<QString>name = \
QDBusInterface("org.ktorrent.ktorrent","/torrent/"+m_tor).call("name"); + \
m_torrentInt = new org::ktorrent::torrent("org.ktorrent.ktorrent", "/torrent/"+m_tor, \
+ QDBusConnection::sessionBus(), + \
this); + QDBusReply<QString>name = m_torrentInt->name();
if(name.isValid()){
- kDebug() << "Torrent already loaded in KTorrent.";
+ kDebug() << "Torrent " + m_tor + " already loaded in KTorrent.";
+ if(m_file==-1&&m_torrentInt->bytesLeftToDownload().value()==0){
+ m_slave->setPath(m_torrentInt->pathOnDisk());
+ } else {
+ m_slave->setPath(m_torrentInt->filePathOnDisk(m_file));
+ }
+
+ m_torrentInt->setDoNotDownload(m_file, false);
m_slave->finishStat();
} else {
QString u = url.url().replace("torrent:","magnet:");
- if( !m_fl.isEmpty() ) // HACK
+ if( m_file != -1)
+ u.remove(":flid:"+args[4]);
+ if( m_file == -1 ) // HACK
u.resize(u.count()-1); // remove trailing &
kDebug() << "Load torrent in KTorrent: " << u;
- m_coreKtInterface->call("loadSilently", u, "kio_torrent");
+ m_coreInt->loadSilently(u, "kio_torrent");
+ m_coreInt->stop(m_tor);
}
m_mutex.unlock();
}
@@ -103,22 +122,67 @@
{
kDebug()<< tor;
if( tor == m_tor ){
- QDBusReply<QString>path = \
QDBusInterface("org.ktorrent.ktorrent","/torrent/"+m_tor).call("pathOnDisk"); + \
QDBusReply<QString>path; + if( m_file == -1 )
+ path = m_torrentInt->pathOnDisk();
+ else
+ path = m_torrentInt->filePathOnDisk(m_file);
if(!path.isValid()){
kDebug() << "Error getting path.";
+ m_slave->error(KIO::ERR_SLAVE_DEFINED, i18n("Could not fetch path from \
KTorrent.")); return;
}
QString p = path.value();
- p += !m_fl.isEmpty() ? "/"+m_fl : "";
- m_slave->finishGet( p );
+ m_slave->setPath( p );
}
}
void KTorrentDBusInterface::slotTorrentAdded(const QString& tor)
{
kDebug()<< tor;
- if( tor == m_tor )
+ if( tor != m_tor )
+ return;
+
+ QDBusReply<uint>numFiles = m_torrentInt->numFiles();
+ uint 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())); + return;
+ }
+
+ // disable all files except the one needed
+ kDebug() << "Number of files: " << n;
+ for(int i=0; i<n; i++){
+ kDebug() << "Set file path: " << m_torrentInt->filePath(i) << " to " << \
(i!=m_file); + m_torrentInt->setDoNotDownload(i, (i!=m_file) );
+ }
+
+ m_coreInt->start(m_tor);
+
+ QDBusReply<qulonglong> size;
+ if(m_file==-1)
+ size = m_torrentInt->totalSize();
+ else
+ size = m_torrentInt->fileSize(m_file);
+ m_fileSize = size.value();
+ kDebug() << "fileSize: " << m_fileSize;
+ m_slave->setSize(m_fileSize);
m_slave->finishStat();
}
+void KTorrentDBusInterface::slotTorrentRemoved(const QString& tor)
+{
+ kDebug()<< tor;
+ if( m_tor == tor)
+ m_slave->error(KIO::ERR_DOES_NOT_EXIST,i18n("Torrent has been removed from \
KTorrent.")); +}
+
+void KTorrentDBusInterface::slotTorrentStoppedByError(const QString& tor, const \
QString& error) +{
+ kDebug()<< tor << error;
+ if( m_tor == tor)
+ m_slave->error(KIO::ERR_CANNOT_OPEN_FOR_WRITING,error);
+}
+
+
#include "ktorrentdbusinterface.moc"
--- trunk/playground/ioslaves/kio_torrent/ktorrentdbusinterface.h #1170776:1170777
@@ -20,8 +20,10 @@
#ifndef KTORRENTDBUSINTERFACE_H
#define KTORRENTDBUSINTERFACE_H
+#include "ktorrentcoreinterface.h"
+#include "ktorrenttorrentinterface.h"
+
#include <QtCore/QMutex>
-#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusConnection>
#include <KUrl>
@@ -40,13 +42,19 @@
private slots:
void slotFinished(const QString&);
void slotTorrentAdded(const QString&);
+ void slotTorrentRemoved(const QString&);
+ void slotTorrentStoppedByError( const QString&, const QString&);
private:
- QDBusInterface* m_coreKtInterface;
+ org::ktorrent::core* m_coreInt;
+ org::ktorrent::torrent* m_torrentInt;
+ QDBusConnection* m_bus;
KUrl m_url;
QMutex m_mutex;
QThread* m_thread;
TorrentProtocol* m_slave;
- QString m_tor, m_fl;
+ QString m_tor;
+ int m_file;
+ qulonglong m_fileSize;
};
#endif // KTORRENTDBUSINTERFACE_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic