[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-11-12 19:26:44
Message-ID: 20101112192644.0F577AC89E () svn ! kde ! org
[Download RAW message or body]
SVN commit 1196196 by weilbach:
Fixed open() and read(). Works now properly for magnet links (checked with piratebay \
magnet links). Started to work on listDir() support. Cleanups.
M +59 -17 kio_magnet.cpp
M +1 -1 kio_magnet.h
--- trunk/playground/ioslaves/kio_magnet/kio_magnet.cpp #1196195:1196196
@@ -86,29 +86,50 @@
UDSEntry entry;
entry.insert( KIO::UDSEntry::UDS_NAME, KUrl(m_path).fileName() );
- entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG ); // a file
+ QFileInfo info(m_path);
+ if (info.isDir()) {
+ entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
+ } else {
+ entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG );
+ }
entry.insert( KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH ); // \
readable by everybody
statEntry(entry);
finished();
}
-/*void MagnetProtocol::listDir(const KUrl& url)
+void MagnetProtocol::listDir(const KUrl& url)
{
kDebug() << url.url();
- error(KIO::ERR_IS_FILE,url.url());
m_ktorrentDBusInterface->load( url );
while ( true ) {
if (m_numFiles) {
totalSize( m_numFiles);
- finished();
- break;
+ } else {
+ usleep(10000);
}
- usleep(100);
}
- KIO::SlaveBase::listDir(url);
-}*/
+ QFileInfo pathInfo(m_path);
+ if (pathInfo.isDir()) {
+ QDir dir(m_path);
+ QFileInfoList list = dir.entryInfoList();
+ QFileInfo info;
+ foreach(info, list) {
+ UDSEntry entry;
+ entry.insert( KIO::UDSEntry::UDS_NAME, info.filePath() );
+ if (info.isDir()) {
+ entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
+ } else {
+ entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG );
+ }
+ entry.insert( KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH ); \
// readable by everybody + listEntry(entry,false);
+ }
+ }
+ finished();
+}
+
void MagnetProtocol::get( const KUrl& url )
{
kDebug() << url.url() << "path: " << m_path;
@@ -118,18 +139,25 @@
}
totalSize( m_size );
+ QFileInfo info(m_path);
QFile file(m_path);
+ if (info.isFile()) {
if (!file.open(QIODevice::ReadOnly)) {
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;
}
+ } else if (info.isDir()) {
+ emit mimeType( "inode/directory" );
+ finished();
+ return;
+ }
bool emitMimetype=true;
qint64 ps = 0;
while (!file.atEnd()) {
- if (m_ktorrentDBusInterface->seek(ps+max_ipc_size)) {
+ if (m_downloaded || m_ktorrentDBusInterface->seek(ps+max_ipc_size)) {
if ( emitMimetype ) {
KMimeType::Ptr mt = KMimeType::findByUrl( m_path, 0, true /* local \
URL */ ); kDebug() << "mimetype: " << mt->name();
@@ -174,20 +202,26 @@
totalSize( m_size );
m_size = -1;
}
- usleep (100);
+ usleep (added_sleep);
}
- KMimeType::Ptr mt = KMimeType::findByUrl( m_path, 0, true /* local URL */ );
- emit mimeType( mt->name() );
-
+ QFileInfo info(m_path);
QFile file(m_path);
+ if (info.isFile()) {
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;
}
+ } else if (info.isDir()) {
+ emit mimeType( "inode/directory" );
+ emit opened();
+ return;
+ }
+ KMimeType::Ptr mt = KMimeType::findByUrl( m_path, 0, false ); // assume non \
local, as we might not have the magic header yet + emit mimeType( mt->name() );
m_position = 0;
position( 0 );
emit opened();
@@ -196,22 +230,32 @@
void MagnetProtocol::read(filesize_t size)
{
kDebug() << size;
- while ( m_path.isEmpty() ) {
+ while ( !m_added ) {
usleep (added_sleep);
}
QFile file(m_path);
if (!file.open(QIODevice::ReadOnly)) {
+ if (file.error()) {
+ } else {
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)); + }
close();
return;
}
+ while (true) {
+ if (m_downloaded || m_ktorrentDBusInterface->seek(m_position)) {
file.seek(m_position);
QByteArray d = file.read(size);
data(d);
+ m_position += size;
file.close();
+ } else {
+ usleep(10000);
}
+ }
+}
void MagnetProtocol::seek(filesize_t offset)
{
@@ -224,14 +268,12 @@
void MagnetProtocol::setPath(const QString& path)
{
kDebug() << path;
- if (m_path!=path)
m_path = path;
}
void MagnetProtocol::setSize(qint64 size)
{
kDebug() << size;
- if (m_size!=size)
m_size = size;
}
--- trunk/playground/ioslaves/kio_magnet/kio_magnet.h #1196195:1196196
@@ -35,7 +35,7 @@
virtual ~MagnetProtocol();
virtual void stat( const KUrl & url );
-// virtual void listDir( const KUrl & url );
+ virtual void listDir( const KUrl & url );
virtual void get( const KUrl & url );
virtual void open( const KUrl &url, QIODevice::OpenMode mode );
virtual void read( KIO::filesize_t );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic