| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
const PREF_CONN = 'network.http.max-persistent-connections-per-server'; |
|---|
| 40 |
|
|---|
| 41 |
var Prefs = { |
|---|
| 42 |
tempLocation: null, |
|---|
| 43 |
|
|---|
| 44 |
mappings: [ |
|---|
| 45 |
['removeCompleted', true], |
|---|
| 46 |
['removeAborted', false], |
|---|
| 47 |
['removeCanceled', false], |
|---|
| 48 |
['autoClose', 'closedta', false], |
|---|
| 49 |
['timeout', 300], |
|---|
| 50 |
['maxInProgress', 'ntask', 4], |
|---|
| 51 |
['maxChunks', 4], |
|---|
| 52 |
['setTime', true], |
|---|
| 53 |
['showOnlyFilenames', true], |
|---|
| 54 |
['conflictResolution', 3], |
|---|
| 55 |
['alertingSystem', 'alertbox', (SYSTEMSLASH == '\\') ? 1 : 0], |
|---|
| 56 |
['finishEvent', ''], |
|---|
| 57 |
['showTooltip', true], |
|---|
| 58 |
['maxAutoRetries', 10], |
|---|
| 59 |
['autoRetryInterval', 0], |
|---|
| 60 |
['autoClearComplete', false], |
|---|
| 61 |
['confirmRemove', true], |
|---|
| 62 |
['permissions', 384], |
|---|
| 63 |
['loadEndFirst', 0], |
|---|
| 64 |
['minimizeToTray', false], |
|---|
| 65 |
['flatReplacementChar', '-'] |
|---|
| 66 |
], |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
observe: function(subject, topic, prefName) { |
|---|
| 70 |
this._refreshPrefs(prefName); |
|---|
| 71 |
}, |
|---|
| 72 |
|
|---|
| 73 |
init: function() { |
|---|
| 74 |
try { |
|---|
| 75 |
this._resetConnPrefs(); |
|---|
| 76 |
this._refreshPrefs(); |
|---|
| 77 |
Preferences.addObserver('extensions.dta.', this); |
|---|
| 78 |
Preferences.addObserver('network.', this); |
|---|
| 79 |
} |
|---|
| 80 |
catch (ex) { |
|---|
| 81 |
Debug.log("failed to add pref-observer", ex); |
|---|
| 82 |
} |
|---|
| 83 |
}, |
|---|
| 84 |
|
|---|
| 85 |
_refreshPrefs: function(prefName) { |
|---|
| 86 |
Debug.logString("pref reload"); |
|---|
| 87 |
for each (let e in this.mappings) { |
|---|
| 88 |
let key, pref, def; |
|---|
| 89 |
if (!e) { |
|---|
| 90 |
return; |
|---|
| 91 |
} |
|---|
| 92 |
else if (e.length == 3) { |
|---|
| 93 |
key = e[0]; |
|---|
| 94 |
pref = e[1]; |
|---|
| 95 |
def = e[2]; |
|---|
| 96 |
} |
|---|
| 97 |
else { |
|---|
| 98 |
key = e[0]; |
|---|
| 99 |
pref = key.toLowerCase(); |
|---|
| 100 |
def = e[1]; |
|---|
| 101 |
} |
|---|
| 102 |
this[key] = Preferences.getExt(pref, def); |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
var perms = Prefs.permissions; |
|---|
| 106 |
if (perms & 0600) { |
|---|
| 107 |
perms |= 0100; |
|---|
| 108 |
} |
|---|
| 109 |
if (perms & 0060) { |
|---|
| 110 |
perms |= 0010; |
|---|
| 111 |
} |
|---|
| 112 |
if (perms & 0006) { |
|---|
| 113 |
perms |= 0001; |
|---|
| 114 |
} |
|---|
| 115 |
this.dirPermissions = perms; |
|---|
| 116 |
|
|---|
| 117 |
if (Preferences.getExt("saveTemp", true)) { |
|---|
| 118 |
try { |
|---|
| 119 |
this.tempLocation = Preferences.getExt("tempLocation", ''); |
|---|
| 120 |
if (this.tempLocation == '') { |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
var dsp = Serv('@mozilla.org/file/directory_service;1', 'nsIProperties'); |
|---|
| 124 |
this.tempLocation = dsp.get("TmpD", Ci.nsIFile); |
|---|
| 125 |
var profD = hash(dsp.get("ProfD", Ci.nsIFile).leafName); |
|---|
| 126 |
this.tempLocation.append("dtatmp-" + profD); |
|---|
| 127 |
Debug.log(this.tempLocation.path); |
|---|
| 128 |
} |
|---|
| 129 |
else { |
|---|
| 130 |
this.tempLocation = new FileFactory(this.tempLocation); |
|---|
| 131 |
} |
|---|
| 132 |
} catch (ex) { |
|---|
| 133 |
this.tempLocation = null; |
|---|
| 134 |
|
|---|
| 135 |
} |
|---|
| 136 |
} |
|---|
| 137 |
else { |
|---|
| 138 |
this.tempLocation = null; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
this.loadEndFirst *= 1024; |
|---|
| 143 |
|
|---|
| 144 |
if (!prefName || prefName == PREF_CONN) { |
|---|
| 145 |
let conns = (this.maxInProgress * this.maxChunks) + 2; |
|---|
| 146 |
let cur = Preferences.get(PREF_CONN, conns); |
|---|
| 147 |
|
|---|
| 148 |
if (conns != cur) { |
|---|
| 149 |
Preferences.setExt(PREF_CONN, cur); |
|---|
| 150 |
} |
|---|
| 151 |
if (conns > cur) { |
|---|
| 152 |
Preferences.set(PREF_CONN, conns); |
|---|
| 153 |
} |
|---|
| 154 |
} |
|---|
| 155 |
if (this.minimizeToTray) { |
|---|
| 156 |
TrayHandler.watch(); |
|---|
| 157 |
} |
|---|
| 158 |
else { |
|---|
| 159 |
TrayHandler.unwatch(); |
|---|
| 160 |
} |
|---|
| 161 |
}, |
|---|
| 162 |
shutdown: function() { |
|---|
| 163 |
Preferences.removeObserver('extensions.dta.', this); |
|---|
| 164 |
Preferences.removeObserver('network.', this); |
|---|
| 165 |
this._resetConnPrefs(); |
|---|
| 166 |
}, |
|---|
| 167 |
_resetConnPrefs: function() { |
|---|
| 168 |
let conn = Preferences.getExt(PREF_CONN, 0); |
|---|
| 169 |
if (conn) { |
|---|
| 170 |
Preferences.set(PREF_CONN, conn); |
|---|
| 171 |
Preferences.setExt(PREF_CONN, 0); |
|---|
| 172 |
} |
|---|
| 173 |
} |
|---|
| 174 |
}; |
|---|
| 175 |
Prefs.init(); |
|---|