mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-30 21:26:02 +00:00
modify the M.O.M so the API is practically the same as the O.M, so the only method that accepts an id is changeId
This commit is contained in:
parent
29d01993c9
commit
65545df485
@ -76,19 +76,7 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
folderSort: true
|
||||
});
|
||||
|
||||
this.optionsManager = new Deluge.MultiOptionsManager({
|
||||
defaults: {
|
||||
'add_paused': false,
|
||||
'compact_allocation': false,
|
||||
'download_location': '',
|
||||
'max_connections_per_torrent': -1,
|
||||
'max_download_speed_per_torrent': -1,
|
||||
'max_upload_slots_per_torrent': -1,
|
||||
'max_upload_speed_per_torrent': -1,
|
||||
'prioritize_first_last_pieces': false,
|
||||
'file_priorities': []
|
||||
}
|
||||
});
|
||||
this.optionsManager = new Deluge.MultiOptionsManager();
|
||||
|
||||
this.form = this.add({
|
||||
xtype: 'form',
|
||||
@ -96,7 +84,8 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
title: _('Options'),
|
||||
bodyStyle: 'padding: 5px;',
|
||||
border: false,
|
||||
height: 170
|
||||
height: 170,
|
||||
disabled: true
|
||||
});
|
||||
|
||||
var fieldset = this.form.add({
|
||||
@ -158,28 +147,28 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
width: 200,
|
||||
defaultType: 'uxspinner'
|
||||
});
|
||||
this.optionsManager.bind('max_download_speed_per_torrent', fieldset.add({
|
||||
this.optionsManager.bind('max_download_speed', fieldset.add({
|
||||
fieldLabel: _('Max Down Speed'),
|
||||
/*labelStyle: 'margin-left: 10px',*/
|
||||
name: 'max_download_speed_per_torrent',
|
||||
name: 'max_download_speed',
|
||||
width: 60
|
||||
}));
|
||||
this.optionsManager.bind('max_upload_speed_per_torrent', fieldset.add({
|
||||
this.optionsManager.bind('max_upload_speed', fieldset.add({
|
||||
fieldLabel: _('Max Up Speed'),
|
||||
/*labelStyle: 'margin-left: 10px',*/
|
||||
name: 'max_upload_speed_per_torrent',
|
||||
name: 'max_upload_speed',
|
||||
width: 60
|
||||
}));
|
||||
this.optionsManager.bind('max_connections_per_torrent', fieldset.add({
|
||||
this.optionsManager.bind('max_connections', fieldset.add({
|
||||
fieldLabel: _('Max Connections'),
|
||||
/*labelStyle: 'margin-left: 10px',*/
|
||||
name: 'max_connections_per_torrent',
|
||||
name: 'max_connections',
|
||||
width: 60
|
||||
}));
|
||||
this.optionsManager.bind('max_upload_slots_per_torrent', fieldset.add({
|
||||
this.optionsManager.bind('max_upload_slots', fieldset.add({
|
||||
fieldLabel: _('Max Upload Slots'),
|
||||
/*labelStyle: 'margin-left: 10px',*/
|
||||
name: 'max_upload_slots_per_torrent',
|
||||
name: 'max_upload_slots',
|
||||
width: 60
|
||||
}));
|
||||
|
||||
@ -225,7 +214,10 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
Ext.each(Ext.keys(fileIndexes), function(index) {
|
||||
priorities[index] = fileIndexes[index];
|
||||
});
|
||||
this.optionsManager.set(torrent['info_hash'], 'file_priorities', priorities);
|
||||
|
||||
var oldId = this.optionsManager.changeId(torrent['info_hash'], false);
|
||||
this.optionsManager.set('file_priorities', priorities);
|
||||
this.optionsManager.changeId(oldId, false);
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
@ -249,8 +241,18 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
|
||||
Deluge.Client.core.get_config_values(keys, {
|
||||
success: function(config) {
|
||||
config['file_priorities'] = [];
|
||||
this.optionsManager.options = config;
|
||||
var options = {
|
||||
'file_priorities': [],
|
||||
'add_paused': config.add_paused,
|
||||
'compact_allocation': config.compact_allocation,
|
||||
'download_location': config.download_location,
|
||||
'max_connections': config.max_connections_per_torrent,
|
||||
'max_download_speed': config.max_download_speed_per_torrent,
|
||||
'max_upload_slots': config.max_upload_slots_per_torrent,
|
||||
'max_upload_speed': config.max_upload_speed_per_torrent,
|
||||
'prioritize_first_last_pieces': config.prioritize_first_last_pieces
|
||||
}
|
||||
this.optionsManager.options = options;
|
||||
},
|
||||
scope: this
|
||||
});
|
||||
@ -261,7 +263,9 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
},
|
||||
|
||||
getOptions: function(torrentId) {
|
||||
var options = this.optionsManager.get(torrentId);
|
||||
var oldId = this.optionsManager.changeId(torrentId, false);
|
||||
var options = this.optionsManager.get();
|
||||
this.optionsManager.changeId(oldTorrentId, false);
|
||||
Ext.each(options['file_priorities'], function(priority, index) {
|
||||
options['file_priorities'][index] = (priority) ? 1 : 0;
|
||||
});
|
||||
@ -276,7 +280,7 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
|
||||
this.clearFiles();
|
||||
var root = this.files.getRootNode();
|
||||
var priorities = this.optionsManager.get(this.torrentId, 'file_priorities');
|
||||
var priorities = this.optionsManager.get('file_priorities');
|
||||
|
||||
this.walkFileTree(this.torrents[torrentId]['files_tree'], function(filename, type, entry, parent) {
|
||||
if (type == 'dir') {
|
||||
@ -321,7 +325,7 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
},
|
||||
|
||||
onFolderCheck: function(node, checked) {
|
||||
var priorities = this.optionsManager.get(this.torrentId, 'file_priorities');
|
||||
var priorities = this.optionsManager.get('file_priorities');
|
||||
node.cascade(function(child) {
|
||||
if (!child.ui.checkbox) {
|
||||
child.attributes.checked = checked;
|
||||
@ -330,13 +334,13 @@ Ext.deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
|
||||
}
|
||||
priorities[child.attributes.fileindex] = checked;
|
||||
}, this);
|
||||
this.optionsManager.update(this.torrentId, 'file_priorities', priorities);
|
||||
this.optionsManager.update('file_priorities', priorities);
|
||||
},
|
||||
|
||||
onNodeCheck: function(node, checked) {
|
||||
var priorities = this.optionsManager.get(this.torrentId, 'file_priorities');
|
||||
var priorities = this.optionsManager.get('file_priorities');
|
||||
priorities[node.attributes.fileindex] = checked;
|
||||
this.optionsManager.update(this.torrentId, 'file_priorities', priorities);
|
||||
this.optionsManager.update('file_priorities', priorities);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -369,7 +369,7 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, {
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
if (this.torrentId) this.optionsManager.reset(this.torrentId);
|
||||
if (this.torrentId) this.optionsManager.reset();
|
||||
},
|
||||
|
||||
update: function(torrentId) {
|
||||
@ -388,19 +388,19 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, {
|
||||
},
|
||||
|
||||
onApply: function() {
|
||||
var changed = this.optionsManager.getDirty(this.torrentId);
|
||||
var changed = this.optionsManager.getDirty();
|
||||
if (!Ext.isEmpty(changed['prioritize_first_last'])) {
|
||||
var value = changed['prioritize_first_last'];
|
||||
Deluge.Client.core.set_torrent_prioritize_first_last(this.torrentId, value, {
|
||||
success: function() {
|
||||
this.optionsManager.set(this.torrentId, 'prioritize_first_last', value);
|
||||
this.optionsManager.set('prioritize_first_last', value);
|
||||
},
|
||||
scope: this
|
||||
});
|
||||
}
|
||||
Deluge.Client.core.set_torrent_options([this.torrentId], changed, {
|
||||
success: function() {
|
||||
this.optionsManager.commit(this.torrentId);
|
||||
this.optionsManager.commit();
|
||||
},
|
||||
scope: this
|
||||
});
|
||||
@ -419,8 +419,8 @@ Ext.deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, {
|
||||
this.fields['private'].setValue(torrent['private']);
|
||||
this.fields['private'].setDisabled(true);
|
||||
delete torrent['private'];
|
||||
this.optionsManager.setDefault(this.torrentId, torrent);
|
||||
var stop_at_ratio = this.optionsManager.get(this.torrentId, 'stop_at_ratio');
|
||||
this.optionsManager.setDefault(torrent);
|
||||
var stop_at_ratio = this.optionsManager.get('stop_at_ratio');
|
||||
this.fields.remove_at_ratio.setDisabled(!stop_at_ratio);
|
||||
this.fields.stop_ratio.setDisabled(!stop_at_ratio);
|
||||
}
|
||||
|
@ -48,47 +48,43 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
||||
* Changes bound fields to use the specified id.
|
||||
* @param {String} id
|
||||
*/
|
||||
changeId: function(id) {
|
||||
changeId: function(id, updateBinds) {
|
||||
var oldId = this.currentId;
|
||||
this.currentId = id;
|
||||
for (var option in this.options) {
|
||||
if (!this.binds[option]) continue;
|
||||
Ext.each(this.binds[option], function(bind) {
|
||||
bind.setValue(this.get(id, option));
|
||||
}, this);
|
||||
if (updateBinds) {
|
||||
for (var option in this.options) {
|
||||
if (!this.binds[option]) continue;
|
||||
Ext.each(this.binds[option], function(bind) {
|
||||
bind.setValue(this.get(option));
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
return oldId;
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes all the changed values to be the default values
|
||||
* @param {String} id
|
||||
*/
|
||||
commit: function(id) {
|
||||
this.stored[id] = Ext.apply(this.stored[id], this.changed[id]);
|
||||
this.reset(id);
|
||||
commit: function() {
|
||||
this.stored[this.currentId] = Ext.apply(this.stored[this.currentId], this.changed[this.currentId]);
|
||||
this.reset();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the value for an option
|
||||
* @param {String} id
|
||||
* @param {String|Array} [option] A single option or an array of options to return.
|
||||
* @returns {Object} the options value.
|
||||
*/
|
||||
get: function() {
|
||||
var id = arguments[0];
|
||||
if (arguments.length == 1) {
|
||||
var options = {};
|
||||
for (var option in this.options) {
|
||||
options[option] = (this.isDirty(id, option)) ? this.changed[id][option] : this.getDefault(id, option);
|
||||
}
|
||||
return options;
|
||||
} else if (arguments.length == 2) {
|
||||
var option = arguments[1];
|
||||
return (this.isDirty(id, option)) ? this.changed[id][option] : this.getDefault(id, option);
|
||||
var option = arguments[0];
|
||||
return (this.isDirty(option)) ? this.changed[this.currentId][option] : this.getDefault(option);
|
||||
} else {
|
||||
var options = {};
|
||||
Ext.each(arguments, function(option) {
|
||||
if (option == id) return;
|
||||
options[option] = (this.isDirty(id, option)) ? this.changed[id][option] : this.getDefault(id, option);
|
||||
if (!this.has(option)) return;
|
||||
options[option] = (this.isDirty(option)) ? this.changed[this.currentId][option] : this.getDefault(option);
|
||||
}, this);
|
||||
return options;
|
||||
}
|
||||
@ -96,51 +92,46 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
||||
|
||||
/**
|
||||
* Get the default value for an option.
|
||||
* @param {String} id
|
||||
* @param {String|Array} [option] A single option or an array of options to return.
|
||||
* @returns {Object} the value of the option
|
||||
*/
|
||||
getDefault: function(id, option) {
|
||||
return (this.has(id, option)) ? this.stored[id][option] : this.options[option];
|
||||
getDefault: function(option) {
|
||||
return (this.has(option)) ? this.stored[this.currentId][option] : this.options[option];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the dirty (changed) values.
|
||||
* @param {String} id
|
||||
* @returns {Object} the changed options
|
||||
*/
|
||||
getDirty: function(id) {
|
||||
return (this.changed[id]) ? this.changed[id] : {};
|
||||
getDirty: function() {
|
||||
return (this.changed[this.currentId]) ? this.changed[this.currentId] : {};
|
||||
},
|
||||
|
||||
/**
|
||||
* Check to see if the option has been changed.
|
||||
* @param {String} id
|
||||
* @param {String} option
|
||||
* @returns {Boolean} true if the option has been changed, else false.
|
||||
*/
|
||||
isDirty: function(id, option) {
|
||||
return (this.changed[id] && !Ext.isEmpty(this.changed[id][option]));
|
||||
isDirty: function(option) {
|
||||
return (this.changed[this.currentId] && !Ext.isEmpty(this.changed[this.currentId][option]));
|
||||
},
|
||||
|
||||
/**
|
||||
* Check to see if an id has had an option set to something other than the
|
||||
* default value.
|
||||
* @param {String} id
|
||||
* @param {String} option
|
||||
* @returns {Boolean} true if the id has an option, else false.
|
||||
*/
|
||||
has: function(id, option) {
|
||||
return (this.stored[id] && !Ext.isEmpty(this.stored[id][option]));
|
||||
has: function(option) {
|
||||
return (this.stored[this.currentId] && !Ext.isEmpty(this.stored[this.currentId][option]));
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset the options back to the default values for the specified id.
|
||||
* @param {String} id
|
||||
*/
|
||||
reset: function(id) {
|
||||
if (!this.changed[id]) return;
|
||||
delete this.changed[id];
|
||||
reset: function() {
|
||||
if (!this.changed[this.currentId]) return;
|
||||
delete this.changed[this.currentId];
|
||||
},
|
||||
|
||||
/**
|
||||
@ -149,13 +140,13 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
||||
* @param {String} option
|
||||
* @param {Object} value The value for the option
|
||||
*/
|
||||
setDefault: function(id, option, value) {
|
||||
setDefault: function(option, value) {
|
||||
if (value === undefined) {
|
||||
for (var key in option) {
|
||||
this.setDefault(id, key, option[key]);
|
||||
this.setDefault(key, option[key]);
|
||||
}
|
||||
} else {
|
||||
var oldValue = this.getDefault(id, option);
|
||||
var oldValue = this.getDefault(option);
|
||||
value = this.convertValueType(oldValue, value);
|
||||
|
||||
// If the value is the same as the old value there is
|
||||
@ -163,11 +154,11 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
||||
if (oldValue == value) return;
|
||||
|
||||
// Store the new default
|
||||
if (!this.stored[id]) this.stored[id] = {};
|
||||
this.stored[id][option] = value;
|
||||
if (!this.stored[this.currentId]) this.stored[this.currentId] = {};
|
||||
this.stored[this.currentId][option] = value;
|
||||
|
||||
if (!this.isDirty(id, option)) {
|
||||
this.fireEvent('changed', id, option, value, oldValue);
|
||||
if (!this.isDirty(option)) {
|
||||
this.fireEvent('changed', this.currentId, option, value, oldValue);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -178,27 +169,27 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
||||
* @param {String|Object} option or options to update
|
||||
* @param {Object} [value];
|
||||
*/
|
||||
update: function(id, option, value) {
|
||||
update: function(option, value) {
|
||||
if (value === undefined) {
|
||||
for (var key in option) {
|
||||
this.update(id, key, option[key]);
|
||||
this.update(key, option[key]);
|
||||
}
|
||||
} else {
|
||||
if (!this.changed[id]) this.changed[id] = {};
|
||||
if (!this.changed[this.currentId]) this.changed[this.currentId] = {};
|
||||
|
||||
var defaultValue = this.getDefault(id, option);
|
||||
var defaultValue = this.getDefault(option);
|
||||
value = this.convertValueType(defaultValue, value);
|
||||
|
||||
var oldValue = this.get(id, option);
|
||||
var oldValue = this.get(option);
|
||||
if (oldValue == value) return;
|
||||
|
||||
if (defaultValue == value) {
|
||||
if (this.isDirty(id, option)) delete this.changed[id][option];
|
||||
this.fireEvent('changed', id, option, value, oldValue);
|
||||
if (this.isDirty(option)) delete this.changed[this.currentId][option];
|
||||
this.fireEvent('changed', this.currentId, option, value, oldValue);
|
||||
return;
|
||||
} else {
|
||||
this.changed[id][option] = value;
|
||||
this.fireEvent('changed', id, option, value, oldValue);
|
||||
this.changed[this.currentId][option] = value;
|
||||
this.fireEvent('changed', this.currentId, option, value, oldValue);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -212,7 +203,7 @@ Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, {
|
||||
* @private
|
||||
*/
|
||||
onFieldChange: function(field, event) {
|
||||
this.update(this.currentId, field._doption, field.getValue());
|
||||
this.update(field._doption, field.getValue());
|
||||
},
|
||||
|
||||
onChange: function(id, option, newValue, oldValue) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user