[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-13 7:28:15
Message-ID: 20101213072815.5C61AAC8A7 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1206054 by weilbach:
Works now as intended. Still problems with KLauncher to fire up KTorrent when \
needed...
A interfaces/org.ktorrent.torrentfilestream.xml
M +25 -3 kio_magnet.cpp
M +5 -5 kio_magnet.h
M +18 -18 ktorrentdbusinterface.cpp
M +2 -0 ktorrentdbusinterface.h
--- trunk/playground/ioslaves/kio_magnet/kio_magnet.cpp #1206053:1206054
@@ -30,6 +30,7 @@
#include <kstandarddirs.h>
#include <KUrl>
#include <KMimeType>
+#include <kmessagebox.h>
#include <kdebug.h>
const int added_sleep = 10000;
@@ -137,6 +138,12 @@
while ( !m_added ) {
usleep (added_sleep);
}
+
+ if(!confirm()){
+ finished();
+ return;
+ }
+ m_ktorrentDBusInterface->startTorrent();
totalSize( m_size );
QFileInfo info(m_path);
@@ -181,9 +188,26 @@
finished();
}
-void MagnetProtocol::added()
+bool MagnetProtocol::confirm()
{
+ if( m_isNew ){
+ if ( messageBox(KIO::SlaveBase::QuestionYesNo
+ , i18n( "Do you want to download and share the \
torrent-file: \"%1\"?" ).arg( m_name ) + , i18n( \
"Magnet-Link confirmation" )) == KMessageBox::No ) { + \
error(KIO::ERR_UNKNOWN, i18n("Download of torrent-file \"%1\" rejected by \
user.").arg( m_name )); + m_ktorrentDBusInterface->stopFileDownloading();
+ return false;
+ }
+ }
+ return true;
+}
+
+void MagnetProtocol::added( const QString& name, bool isNew )
+{
kDebug();
+
+ m_isNew = isNew;
+ m_name = name;
m_added = true;
}
@@ -200,7 +224,6 @@
while ( !m_added ) {
if (m_size!=-1) {
totalSize( m_size );
-// m_size = -1;
}
usleep (added_sleep);
}
@@ -264,7 +287,6 @@
position(offset);
}
-
void MagnetProtocol::setPath(const QString& path)
{
kDebug() << path;
--- trunk/playground/ioslaves/kio_magnet/kio_magnet.h #1206053:1206054
@@ -27,9 +27,8 @@
class KTorrentDBusInterface;
class QMutex;
-class MagnetProtocol : public QObject, public KIO::SlaveBase
+class MagnetProtocol : public KIO::SlaveBase
{
- Q_OBJECT
public:
MagnetProtocol( const QByteArray &pool, const QByteArray &app );
virtual ~MagnetProtocol();
@@ -43,14 +42,15 @@
virtual void setSize( qint64 );
virtual void setNumFiles( int );
virtual void setPath( const QString& );
- virtual void added();
+ virtual void added( const QString&, bool );
virtual void downloaded();
private:
+ virtual bool confirm();
KUrl m_url;
KTorrentDBusInterface* m_ktorrentDBusInterface;
- bool m_added, m_downloaded;
- QString m_path;
+ bool m_added, m_downloaded, m_isNew;
+ QString m_path, m_name;
qint64 m_size, m_position;
int m_numFiles;
};
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.cpp #1206053:1206054
@@ -36,7 +36,6 @@
#include <kstandarddirs.h>
#include <KUrl>
#include <kdebug.h>
-#include <kmessagebox.h>
#include <KMimeType>
#include <kio/jobclasses.h>
#include <kio/job.h>
@@ -233,7 +232,7 @@
m_coreInt->start(m_tor);
createFileStream(m_file);
}
- m_slave->added();
+ m_slave->added(name,false);
} else {
// m_torrentUrl = m_url.queryItem("to");
// KUrl source( m_torrentUrl );
@@ -338,22 +337,13 @@
void KTorrentDBusInterface::slotTorrentAdded(const QString& tor)
{
- m_slave->messageBox(KIO::SlaveBase::QuestionYesNo, "TEST", "TEST" );
kDebug()<< tor;
+
if ( tor != m_tor )
return;
m_coreInt->stop(tor);
- 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));
- return;
- }
- m_coreInt->start(tor);
-
QStringList mt = MagnetSettings::managedTorrents();
QStringList rt = MagnetSettings::runningTorrents();
mt.append(m_tor);
@@ -376,11 +366,6 @@
m_torrentInt->setDoNotDownload(i, (i!=m_file) );
}
- // TODO stream all torrents for now
- createFileStream(m_file);
-
- m_coreInt->start(m_tor);
-
QDBusReply<qulonglong> size;
if (m_file==-1)
size = m_torrentInt->totalSize();
@@ -402,9 +387,24 @@
QString p = path.value();
m_slave->setPath( p );
- m_slave->added();
+ // TODO stream all torrents for now
+ createFileStream(m_file);
+
+ m_slave->added(m_torrentInt->filePath(m_file),true);
}
+void KTorrentDBusInterface::startTorrent()
+{
+ kDebug();
+ m_coreInt->start(m_tor);
+}
+
+void KTorrentDBusInterface::stopFileDownloading()
+{
+ kDebug();
+ m_torrentInt->setDoNotDownload(m_file,false);
+}
+
void KTorrentDBusInterface::slotTorrentRemoved(const QString& tor)
{
kDebug()<< tor;
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.h #1206053:1206054
@@ -43,6 +43,8 @@
virtual ~KTorrentDBusInterface();
virtual void load(const KUrl&);
virtual void init();
+ void startTorrent();
+ void stopFileDownloading();
bool seek(qint64 pos);
private slots:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic