improved download restart by preserving the preferences of the original download

This commit is contained in:
hamza zia 2014-06-03 12:58:40 +08:00
parent 1b6969cf81
commit 8f0500c78e

View File

@ -1,16 +1,16 @@
angular angular
.module('webui.ctrls.download', [ .module('webui.ctrls.download', [
"ui.bootstrap", "ui.bootstrap",
'webui.services.utils', 'webui.services.rpc', 'webui.services.alerts', 'webui.services.utils', 'webui.services.rpc', 'webui.services.rpc.helpers', 'webui.services.alerts',
'webui.services.settings', 'webui.services.modals', 'webui.services.configuration', 'webui.services.settings', 'webui.services.modals', 'webui.services.configuration',
]) ])
.controller('MainCtrl', [ .controller('MainCtrl', [
'$scope', '$name', '$enable', '$rpc', '$utils', '$alerts', '$modals', '$scope', '$name', '$enable', '$rpc', '$rpchelpers', '$utils', '$alerts', '$modals',
'$fileSettings', '$activeInclude', '$waitingExclude', '$pageSize', '$fileSettings', '$activeInclude', '$waitingExclude', '$pageSize',
// for document title // for document title
'$window', '$window',
function( function(
scope, name, enable, rpc, utils, alerts, modals, scope, name, enable, rpc, rhelpers, utils, alerts, modals,
fsettings, activeInclude, waitingExclude, pageSize, fsettings, activeInclude, waitingExclude, pageSize,
window window
) { ) {
@ -42,6 +42,8 @@ function(
// assumes downloads which are started by URIs, not torrents. // assumes downloads which are started by URIs, not torrents.
// the preferences are also not transferred, just simple restart // the preferences are also not transferred, just simple restart
rpc.once('getOption', [d.gid], function(data) {
var prefs = data[0];
rpc.once('getFiles', [d.gid], function(data) { rpc.once('getFiles', [d.gid], function(data) {
var files = data[0]; var files = data[0];
var uris = var uris =
@ -55,12 +57,13 @@ function(
}).value(); }).value();
if (uris.length > 0) { if (uris.length > 0) {
console.log('adding uris:', uris); console.log('adding uris:', uris, prefs);
scope.remove(d, function() { scope.remove(d, function() {
rpc.once('addUri', uris, angular.noop, true); rhelpers.addUris(uris, prefs);
}, true); }, true);
} }
}); });
});
} }
@ -75,6 +78,9 @@ function(
// otherwise permanantly remove it // otherwise permanantly remove it
// d: the download ctx // d: the download ctx
scope.remove = function(d, cb, noConfirm) { scope.remove = function(d, cb, noConfirm) {
// HACK to make sure an angular digest is not running, as only one can happen at a time, and confirm is a blocking
// call so an rpc response can also trigger a digest call
setTimeout(function() {
if (!noConfirm && !confirm("Remove %s and associated meta-data?".replace("%s", d.name))) { if (!noConfirm && !confirm("Remove %s and associated meta-data?".replace("%s", d.name))) {
return; return;
} }
@ -89,9 +95,10 @@ function(
d.followedFrom = null; d.followedFrom = null;
} }
rpc.once(method, [d.gid], cb); rpc.once(method, [d.gid], cb);
}, 0);
} }
// start filling in the model of active, // start filling in the model of active,
// waiting and stopped download // waiting and stopped download
rpc.subscribe('tellActive', [], function(data) { rpc.subscribe('tellActive', [], function(data) {
scope.$apply(function() { scope.$apply(function() {
@ -506,16 +513,17 @@ function(
rpc.once('getOption', [d.gid], function(data) { rpc.once('getOption', [d.gid], function(data) {
var vals = data[0]; var vals = data[0];
for (var i in fsettings) { var sets = _.cloneDeep(fsettings);
for (var i in sets) {
if (type == 'active' && activeInclude.indexOf(i) == -1) continue; if (type == 'active' && activeInclude.indexOf(i) == -1) continue;
if (type == 'waiting' && waitingExclude.indexOf(i) != -1) continue; if (type == 'waiting' && waitingExclude.indexOf(i) != -1) continue;
settings[i] = fsettings[i]; settings[i] = sets[i];
settings[i].val = vals[i] || settings[i].val; settings[i].val = vals[i] || settings[i].val;
} }
modals.invoke('settings', settings, scope.name + ' settings', function(settings) { modals.invoke('settings', settings, d.name + ' settings', 'Change', function(settings) {
var sets = {}; var sets = {};
for (var i in settings) { sets[i] = settings[i].val }; for (var i in settings) { sets[i] = settings[i].val };