| Summary: | dcop command to silently load torrents to a specific directory | ||
|---|---|---|---|
| Product: | [Applications] ktorrent | Reporter: | Goten Xiao <gotenxiao> |
| Component: | general | Assignee: | Joris Guisson <joris.guisson> |
| Status: | RESOLVED WORKSFORME | ||
| Severity: | wishlist | ||
| Priority: | NOR | ||
| Version First Reported In: | unspecified | ||
| Target Milestone: | --- | ||
| Platform: | Slackware | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | Adds openTorrentSilentlyDir dcop functionality | ||
|
Description
Goten Xiao
2007-03-16 02:38:15 UTC
Sure why not, shouldn't be that much of an effort to do, but I don't know when we will have the time to do that. Created attachment 20003 [details]
Adds openTorrentSilentlyDir dcop functionality
Doesn't have any checking, but it works.
SVN commit 643430 by guisson:
Added patch from Goten Xiao which adds a DCOP method to load torrents silently with a save location
BUG: 143037
M +1 -0 dcopinterface.h
M +5 -0 ktorrent.cpp
M +6 -0 ktorrent.h
M +52 -11 ktorrentcore.cpp
M +3 -0 ktorrentcore.h
M +5 -0 ktorrentdcop.cpp
M +1 -0 ktorrentdcop.h
M +1 -0 main.cpp
--- trunk/extragear/network/ktorrent/apps/ktorrent/dcopinterface.h #643429:643430
@@ -62,6 +62,7 @@
virtual bool showSystemTrayIcon() = 0;
virtual QValueList<int> intSettings() = 0;
virtual bool isBlockedIP(QString ip) = 0;
+ virtual void openTorrentSilentlyDir(const QString & file, const QString & savedir) = 0;
};
--- trunk/extragear/network/ktorrent/apps/ktorrent/ktorrent.cpp #643429:643430
@@ -915,5 +915,10 @@
delete tb;
}
+void KTorrent::loadSilentlyDir(const KURL& url, const KURL& savedir)
+{
+ m_core->loadSilentlyDir(url, savedir);
+}
+
#include "ktorrent.moc"
--- trunk/extragear/network/ktorrent/apps/ktorrent/ktorrent.h #643429:643430
@@ -122,6 +122,12 @@
*/
void loadSilently(const KURL& url);
+ /**
+ * Does the same as loadSilently, except accepts a directory to
+ * save to
+ */
+ void loadSilentlyDir(const KURL& url, const KURL& savedir);
+
/// Open a view with the given group
void openView(kt::Group* g);
--- trunk/extragear/network/ktorrent/apps/ktorrent/ktorrentcore.cpp #643429:643430
@@ -296,28 +296,37 @@
if (err == KIO::ERR_USER_CANCELED)
{
loadingFinished(j->url(),false,true);
- return;
}
-
- if (err)
+ else if (err)
{
loadingFinished(j->url(),false,false);
}
else
{
- // load in the file (target is always local)
- QString dir = Settings::saveDir();
- if (!Settings::useSaveDir())
+ QString dir;
+ if (custom_save_locations.contains(j))
{
- loadingFinished(j->url(),false,false);
+ // we have a custom save location so save to that
+ dir = custom_save_locations[j].path();
+ custom_save_locations.erase(j);
}
+ else if (!Settings::useSaveDir())
+ {
+ // incase save dir is not set, use home director
+ Out(SYS_GEN|LOG_NOTICE) << "Cannot load " << j->url() << " silently, default save location not set !" << endl;
+ Out(SYS_GEN|LOG_NOTICE) << "Using home directory instead !" << endl;
+ dir = QDir::homeDirPath();
+ }
else
{
- if (dir != QString::null && load(j->data(),dir,true,j->url()))
- loadingFinished(j->url(),true,false);
- else
- loadingFinished(j->url(),false,false);
+ dir = Settings::saveDir();
}
+
+
+ if (dir != QString::null && load(j->data(),dir,true,j->url()))
+ loadingFinished(j->url(),true,false);
+ else
+ loadingFinished(j->url(),false,false);
}
}
@@ -347,6 +356,38 @@
}
}
+void KTorrentCore::loadSilentlyDir(const KURL& url, const KURL& savedir)
+{
+ if (url.isLocalFile())
+ {
+ QString path = url.path();
+ QString dir = savedir.path();
+ QFileInfo fi(dir);
+ if (!fi.exists() || !fi.isWritable() || !fi.isDir())
+ {
+ Out(SYS_GEN|LOG_NOTICE) << "Cannot load " << path << " silently, destination directory is not OK ! Using default save directory." << endl;
+ dir = Settings::saveDir();
+ if (!Settings::useSaveDir())
+ {
+ Out(SYS_GEN|LOG_NOTICE) << "Default save directory not set, using home directory !" << endl;
+ dir = QDir::homeDirPath();
+ }
+ }
+
+ if (dir != QString::null && load(path,dir,true))
+ loadingFinished(url,true,false);
+ else
+ loadingFinished(url,false,true);
+ }
+ else
+ {
+ // download to a random file in tmp
+ KIO::Job* j = KIO::storedGet(url,false,true);
+ custom_save_locations.insert(j,savedir); // keep track of save location
+ connect(j,SIGNAL(result(KIO::Job*)),this,SLOT(downloadFinishedSilently( KIO::Job* )));
+ }
+}
+
void KTorrentCore::start(kt::TorrentInterface* tc)
{
qman->start(tc);
--- trunk/extragear/network/ktorrent/apps/ktorrent/ktorrentcore.h #643429:643430
@@ -20,6 +20,7 @@
#ifndef KTORRENTCORE_H
#define KTORRENTCORE_H
+#include <qmap.h>
#include <qtimer.h>
#include <qcstring.h>
#include <util/constants.h>
@@ -176,6 +177,7 @@
virtual void load(const KURL& url);
virtual void loadSilently(const KURL& url);
+ virtual void loadSilentlyDir(const KURL& url, const KURL& savedir);
virtual float getGlobalMaxShareRatio() const;
@@ -321,6 +323,7 @@
bt::Uint64 removed_bytes_up,removed_bytes_down;
kt::PluginManager* pman;
bt::QueueManager* qman;
+ QMap<KIO::Job*,KURL> custom_save_locations; // map to store save locations
};
#endif
--- trunk/extragear/network/ktorrent/apps/ktorrent/ktorrentdcop.cpp #643429:643430
@@ -246,4 +246,9 @@
return bt::IPBlocklist::instance().isBlocked(ip);
}
+void KTorrentDCOP::openTorrentSilentlyDir(const QString & file, const QString & savedir)
+{
+ app->loadSilentlyDir(KURL::fromPathOrURL(file), KURL::fromPathOrURL(savedir));
+}
+
#include "ktorrentdcop.moc"
--- trunk/extragear/network/ktorrent/apps/ktorrent/ktorrentdcop.h #643429:643430
@@ -68,6 +68,7 @@
virtual bool showSystemTrayIcon();
virtual QValueList<int> intSettings();
virtual bool isBlockedIP(QString ip);
+ virtual void openTorrentSilentlyDir(const QString & file, const QString & savedir);
};
--- trunk/extragear/network/ktorrent/apps/ktorrent/main.cpp #643429:643430
@@ -109,6 +109,7 @@
about.addCredit("Alexander Dymo",I18N_NOOP("IDEAl code from KDevelop"),"adymo@kdevelop.org");
about.addCredit("Scott Wolchok",I18N_NOOP("Conversion speed improvement in ipfilter plugin"),"swolchok@umich.edu");
about.addCredit("Bryan Burns of Juniper Networks",I18N_NOOP("Discovered 2 security vulnerabilities (both are fixed)"),0);
+ about.addCredit("Goten Xiao",I18N_NOOP("Patch to load silently with a save location"),0);
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions(options);
Patch seems to have disappeared from the codebase (was not present in either 2.1.3 or 2.1.4, and I can't seem to get on anonsvn at the moment). 2.1.3 and 2.1.4 are only bug fix releases, they do not contain new stuff Ah, fair enough. |