Bug 136063 - partfileimportplugin's .torrent fetcher should be network-transparent
Summary: partfileimportplugin's .torrent fetcher should be network-transparent
Status: RESOLVED FIXED
Alias: None
Product: ktorrent
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR wishlist (vote)
Target Milestone: ---
Assignee: Joris Guisson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-21 01:35 UTC by Stefan Monov
Modified: 2007-05-19 13:37 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Monov 2006-10-21 01:35:35 UTC
Version:           2.0.3 (using KDE 3.5.5 "release 19.1" , openSUSE )
Compiler:          Target: i586-suse-linux
OS:                Linux (i686) release 2.6.16.21-0.25-default

How to reproduce:
Try to import a partially downloaded torrent with the following descriptor file:
http://example.com/something.torrent

Observed result:
Cannot load the torrent file : Unable to open torrent file /something.torrent : No such file or directory
Comment 1 Joris Guisson 2006-10-21 11:08:53 UTC
We do not support this at the moment, don't know when we can add this.
Comment 2 Joris Guisson 2007-05-19 13:37:40 UTC
SVN commit 666284 by guisson:

Made import dialog network transparent for the torrent file

BUG: 136063



 M  +1 -0      ChangeLog  
 M  +67 -21    plugins/partfileimport/importdialog.cpp  
 M  +8 -0      plugins/partfileimport/importdialog.h  


--- trunk/extragear/network/ktorrent/ChangeLog #666283:666284
@@ -26,6 +26,7 @@
 - Improved system tray popup icon : we now use boxed style KPassivePopup instead of Qt tooltips, it also only disappears when the cursor
 is moved away from the tray icon and the text can be updated
 - The log now gets autorotated when it gets larger then 10 MB
+- Import dialog is now network transparent for the torrent file 
 
 Changes in 2.1.4
 - Fixed crash in parsing of DHT messages
--- trunk/extragear/network/ktorrent/plugins/partfileimport/importdialog.cpp #666283:666284
@@ -23,6 +23,8 @@
 #include <kurlrequester.h>
 #include <kpushbutton.h>
 #include <kmessagebox.h>
+#include <kio/job.h>
+#include <kio/jobclasses.h>
 #include <util/log.h>
 #include <util/error.h>
 #include <util/file.h>
@@ -74,32 +76,12 @@
 		// only used for check in separate thread, so does not apply for the import plugin
 	}
 	
-	void ImportDialog::onImport()
+	void ImportDialog::import(Torrent & tor)
 	{
-		m_progress->setEnabled(true);
-		m_import_btn->setEnabled(false);
-		m_cancel_btn->setEnabled(false);
-		m_torrent_url->setEnabled(false);
-		m_data_url->setEnabled(false);
-		
 		// get the urls
 		KURL tor_url = KURL::fromPathOrURL(m_torrent_url->url());
 		KURL data_url = KURL::fromPathOrURL(m_data_url->url());
-		Torrent tor;
 		
-		// try to load the torrent
-		try
-		{
-			tor.load(tor_url.path(),false);
-		}
-		catch (Error & e)
-		{
-			KMessageBox::error(this,i18n("Cannot load the torrent file : %1").arg(e.toString()),
-							   i18n("Error"));
-			reject();
-			return;
-		}
-		
 		// now we need to check the data
 		DataChecker* dc = 0;
 		if (tor.isMultiFile())
@@ -203,6 +185,70 @@
 		accept();
 	}
 	
+	void ImportDialog::onTorrentGetReult(KIO::Job* j)
+	{
+		if (j->error())
+		{
+			j->showErrorDialog(this);
+			reject();
+		}
+		else
+		{
+			KIO::StoredTransferJob* stj = (KIO::StoredTransferJob*)j;
+			Torrent tor;
+		
+			// try to load the torrent
+			try
+			{
+				tor.load(stj->data(),false);
+			}
+			catch (Error & e)
+			{
+				KMessageBox::error(this,i18n("Cannot load the torrent file : %1").arg(e.toString()),
+								   i18n("Error"));
+				reject();
+				return;
+			}
+			import(tor);
+		}
+	}
+	
+	void ImportDialog::onImport()
+	{
+		m_progress->setEnabled(true);
+		m_import_btn->setEnabled(false);
+		m_cancel_btn->setEnabled(false);
+		m_torrent_url->setEnabled(false);
+		m_data_url->setEnabled(false);
+		
+		KURL tor_url = KURL::fromPathOrURL(m_torrent_url->url());
+		if (!tor_url.isLocalFile())
+		{
+			// download the torrent file
+			KIO::StoredTransferJob* j = KIO::storedGet(tor_url);
+			connect(j,SIGNAL(result(KIO::Job* )),this,SLOT(onTorrentGetReult(KIO::Job*)));
+		}
+		else
+		{
+			KURL tor_url = KURL::fromPathOrURL(m_torrent_url->url());
+			Torrent tor;
+		
+			// try to load the torrent
+			try
+			{
+				tor.load(tor_url.path(),false);
+			}
+			catch (Error & e)
+			{
+				KMessageBox::error(this,i18n("Cannot load the torrent file : %1").arg(e.toString()),
+								   i18n("Error"));
+				reject();
+				return;
+			}
+			import(tor);
+		}
+	}
+	
 	void ImportDialog::writeIndex(const QString & file,const BitSet & chunks)
 	{
 		// first try to open it
--- trunk/extragear/network/ktorrent/plugins/partfileimport/importdialog.h #666283:666284
@@ -33,7 +33,12 @@
 	class Torrent;
 }
 
+namespace KIO
+{
+	class Job;
+}
 
+
 namespace kt
 {
 	class CoreInterface;
@@ -48,6 +53,7 @@
 		
 	public slots:
 		void onImport();
+		void onTorrentGetReult(KIO::Job* j);
 	
 	private:
 		void writeIndex(const QString & file,const bt::BitSet & chunks);
@@ -61,6 +67,8 @@
 		virtual void status(bt::Uint32 num_failed,bt::Uint32 num_downloaded);
 		virtual void finished();
 		
+		void import(bt::Torrent & tor);
+		
 	private:
 		CoreInterface* core;
 	};