[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-12 23:04:53
Message-ID: 20100912230453.D858BAC887 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1174607 by weilbach:
Start of a kcm module. Add config options for share size and supported licenses and \
first code support. Cleanups.
M +6 -0 CMakeLists.txt
A kcm (directory)
A kcm.fileshare (directory)
A kcm/CMakeLists.txt
A kcm/controlcenter.ui
A kcm/webshare.cpp [License: GPL (v2+)]
A kcm/webshare.desktop
A kcm/webshare.h [License: GPL (v2+)]
M +2 -2 kio_magnet.cpp
M +115 -12 ktorrentdbusinterface.cpp
M +5 -2 ktorrentdbusinterface.h
A magnetsettings.kcfg
A magnetsettings.kcfgc
--- trunk/playground/ioslaves/kio_magnet/CMakeLists.txt #1174606:1174607
@@ -21,12 +21,18 @@
include_directories( ${KDE4_INCLUDES} )
+add_subdirectory("kcm")
+
########### kio_magnet ###############
set(kio_magnet_SRCS kio_magnet.cpp ktorrentdbusinterface.cpp dbusthread.cpp
ktorrentcoreinterface.cpp ktorrenttorrentinterface.cpp
ktorrentgroupinterface.cpp )
+
+kde4_add_kcfg_files(kio_magnet_SRCS magnetsettings.kcfgc)
+install(FILES magnetsettings.kcfg DESTINATION ${KCFG_INSTALL_DIR})
+
kde4_add_plugin(kio_magnet ${kio_magnet_SRCS})
target_link_libraries(kio_magnet ${KDE4_KIO_LIBS} )
--- trunk/playground/ioslaves/kio_magnet/kio_magnet.cpp #1174606:1174607
@@ -115,7 +115,7 @@
if ( m_finish ) {
totalSize( m_size );
} else {
- while ( !m_finish ) {
+ while ( m_path.isEmpty() ) {
if (m_size!=-1) {
totalSize( m_size );
m_size = -1;
@@ -130,7 +130,7 @@
QFile file(m_path);
if (!file.open(QIODevice::ReadOnly)) {
- error(KIO::ERR_CANNOT_OPEN_FOR_READING,
+ error(KIO::ERR_ABORTED,
i18n("File exits in KTorrent, but cannot open it on disk at path \
\"%1\". Have you removed the file manually?").arg(m_path)); close();
return;
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.cpp #1174606:1174607
@@ -21,6 +21,7 @@
#include "kio_magnet.h"
#include "dbusthread.h"
#include "ktorrentgroupinterface.h"
+#include "magnetsettings.h"
#include <QtCore/QMutex>
#include <QtCore/QThread>
@@ -51,8 +52,25 @@
moveToThread(m_thread);
}
+KTorrentDBusInterface::~KTorrentDBusInterface()
+{
+ kDebug();
+ MagnetSettings::self()->writeConfig();
+}
+
void KTorrentDBusInterface::init()
{
+ kDebug();
+ if (!MagnetSettings::enabled()) {
+ m_slave->error(KIO::ERR_ABORTED,i18n("The Web share for magnet-links is \
disabled. \ + You can set it up at \
settings:/network-and-connectivity/sharing")); // TODO + } else {
+ initDBus();
+ }
+}
+
+void KTorrentDBusInterface::initDBus()
+{
kDebug() << "Thread: " << thread();
m_coreInt = new org::ktorrent::core("org.ktorrent.ktorrent", "/core",
QDBusConnection::sessionBus());
@@ -69,11 +87,11 @@
m_process->waitForStarted();
QTimer::singleShot(timeout,this,SLOT(initializeDBus()));
} else {
- initializeDBus();
+ connectToDBus();
}
}
-void KTorrentDBusInterface::initializeDBus()
+void KTorrentDBusInterface::connectToDBus()
{
kDebug();
@@ -106,12 +124,12 @@
i18n("Could not get the group list, do you have a compatible \
KTorrent version running?")); return;
} else {
- if (!groupList.value().contains("MagnetFS")) {
- m_coreInt->addGroup("MagnetFS");
+ if (!groupList.value().contains("Web Share")) {
+ m_coreInt->addGroup("Web Share");
}
- org::ktorrent::group groupInt("org.ktorrent.ktorrent", "/group/MagnetFS", \
bus ); + org::ktorrent::group groupInt("org.ktorrent.ktorrent", "/group/Web \
Share", bus ); KStandardDirs *dirs = new KStandardDirs();
- groupInt.setDefaultSaveLocation(dirs->saveLocation("data","MagnetFS"));
+ groupInt.setDefaultSaveLocation(dirs->saveLocation("data","Web Share"));
groupInt.setMaxShareRatio(1.2);
}
@@ -136,8 +154,8 @@
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."); + Torrent support is necessary at the moment, so you need to \
have at least a btih:HASHVALUE \ + 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();
@@ -148,6 +166,21 @@
int flidIndex = args.indexOf("flid");
m_file = ( flidIndex!=-1 && aSize>flidIndex ) ? args[flidIndex+1].toUInt() : -1;
+ int licIndex = args.indexOf("lic");
+ m_lic = (licIndex!=-1 && aSize>licIndex ) ? args[licIndex+1] : "unkown";
+ if ( !MagnetSettings::allowedLicenses().contains(m_lic) ) {
+ if (MagnetSettings::recheckUnknownLicense()) {
+ kDebug() << "TODO find the right gui way to ask";
+ } else {
+ m_slave->error(KIO::ERR_ABORTED,i18n("The license\"%1\" is not enabled.\
+ You can reconfigure the licenses at \
+ settings:/network-and-connectivity/sharing") // \
TODO fix link + .arg(m_lic));
+ m_mutex.unlock();
+ return;
+ }
+ }
+
m_torrentInt = new org::ktorrent::torrent("org.ktorrent.ktorrent", \
"/torrent/"+m_tor, QDBusConnection::sessionBus());
QDBusReply<QString>name = m_torrentInt->name();
@@ -170,18 +203,67 @@
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]);
+ if ( m_file != -1)
+ u.remove(QString(":flid:%1").arg(m_file));
+ u.remove(QString(":lic:"+m_lic));
}
kDebug() << "Load torrent in KTorrent: " << u;
- m_coreInt->loadSilently(u, "MagnetFS");
+ m_coreInt->loadSilently(u, "Web Share");
m_coreInt->stop(m_tor);
}
m_mutex.unlock();
}
+void KTorrentDBusInterface::cleanup()
+{
+ kDebug();
+ if (!m_torrentInt)
+ return;
+ qulonglong totalSize=0;
+ QHash<QString,double> tList;
+ QStringList torrents = MagnetSettings::managedTorrents();
+ QList<QString>::const_iterator it = torrents.begin();
+ QList<QString>::const_iterator end = torrents.end();
+ for (;it!=end;it++) {
+ if ((*it)==m_tor)
+ break;
+ KTorrentTorrentInterface* torrentInt = new \
org::ktorrent::torrent("org.ktorrent.ktorrent", "/torrent/"+(*it), + \
QDBusConnection::sessionBus()); + if \
(!torrentInt->isValid()||torrentInt->bytesLeft()==0) { + QStringList mt = \
MagnetSettings::managedTorrents(); + mt.removeAll((*it));
+ MagnetSettings::setManagedTorrents( mt );
+ m_coreInt->remove((*it),true);
+ continue;
+ }
+ totalSize+=torrentInt->bytesDownloaded(); // TODO might get wrong results if \
network connection is buggy + tList[(*it)]=torrentInt->shareRatio();
+ delete torrentInt;
+ }
+ // TODO add ktorrent plugin to allow sane total size management?
+ if (totalSize>MagnetSettings::shareSize()*1024*1024&&m_torrentInt->isValid()) {
+ totalSize+=m_file!=-1 ? m_torrentInt->fileSize(m_file) : \
m_torrentInt->totalSize(); +
+ QList<double> vals = tList.values();
+ qSort( vals );
+ foreach( double val, vals ) {
+ QString tor = tList.key(val);
+ KTorrentTorrentInterface* torrentInt = new \
org::ktorrent::torrent("org.ktorrent.ktorrent", "/torrent/"+tor, + \
QDBusConnection::sessionBus()); + \
totalSize-=torrentInt->bytesDownloaded(); + delete torrentInt;
+ tList.take(tor);
+ if (totalSize<MagnetSettings::shareSize()*1024*1024) {
+ break;
+ }
+ }
+ }
+
+ MagnetSettings::self()->writeConfig();
+}
+
void KTorrentDBusInterface::slotFinished(const QString& tor)
{
kDebug()<< tor;
@@ -198,8 +280,15 @@
}
QString p = path.value();
m_slave->setPath( p );
+
+ if ( m_torrentInt->bytesLeft() == 0 ) {
+ m_coreInt->remove(tor,true);
+ QStringList mt = MagnetSettings::managedTorrents();
+ mt.removeAll(m_tor);
+ MagnetSettings::setManagedTorrents(mt);
}
}
+}
void KTorrentDBusInterface::slotTorrentAdded(const QString& tor)
{
@@ -207,9 +296,16 @@
if ( tor != m_tor )
return;
+ cleanup();
+
+ QStringList mt = MagnetSettings::managedTorrents();
+ mt.append(m_tor);
+ MagnetSettings::setManagedTorrents(mt);
+ MagnetSettings::self()->writeConfig();
+
QDBusReply<uint>numFiles = m_torrentInt->numFiles();
int n = numFiles.value();
- if (m_file==-1&&n!=0) {
+ if (m_file==-1&&n!=0) { // TODO
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;
@@ -242,6 +338,9 @@
kDebug()<< tor;
if ( m_tor == tor) {
m_slave->error(KIO::ERR_DOES_NOT_EXIST,i18n("Torrent has been removed from \
KTorrent.")); + QStringList mt = MagnetSettings::managedTorrents();
+ mt.removeAll(m_tor);
+ MagnetSettings::setManagedTorrents(mt);
delete m_coreInt;
}
}
@@ -251,6 +350,10 @@
kDebug()<< tor << error;
if ( m_tor == tor) {
m_slave->error(KIO::ERR_CANNOT_OPEN_FOR_WRITING,error);
+ m_coreInt->remove(tor,true);
+ QStringList mt = MagnetSettings::managedTorrents();
+ mt.removeAll(m_tor);
+ MagnetSettings::setManagedTorrents(mt);
delete m_coreInt;
}
}
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.h #1174606:1174607
@@ -37,16 +37,19 @@
Q_OBJECT
public:
KTorrentDBusInterface( MagnetProtocol* );
+ virtual ~KTorrentDBusInterface();
virtual void load(const KUrl&);
virtual void init();
private slots:
- void initializeDBus();
+ void cleanup();
+ void connectToDBus();
void slotFinished(const QString&);
void slotTorrentAdded(const QString&);
void slotTorrentRemoved(const QString&);
void slotTorrentStoppedByError( const QString&, const QString&);
private:
+ void initDBus();
void setupDBus();
org::ktorrent::core* m_coreInt;
org::ktorrent::torrent* m_torrentInt;
@@ -56,7 +59,7 @@
QMutex m_mutex;
QThread* m_thread;
MagnetProtocol* m_slave;
- QString m_tor;
+ QString m_tor, m_lic;
int m_file, m_passedTime;
qulonglong m_fileSize;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic