root/trunk/chrome/content/dta/manager/prefs.js

Revision 1092, 5.0 kB (checked in by MaierMan, 2 years ago)

#588: Let users choose flatcurl/flatdirs slash replacement character

Line 
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is DownThemAll!
15  *
16  * The Initial Developers of the Original Code are Stefano Verna and Federico Parodi
17  * Portions created by the Initial Developers are Copyright (C) 2004-2007
18  * the Initial Developers. All Rights Reserved.
19  *
20  * Contributor(s):
21  *    Stefano Verna <stefano.verna@gmail.com>
22  *    Federico Parodi <f.parodi@tiscali.it>
23  *    Nils Maier <MaierMan@web.de>
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
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   // nsIObserver
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           // #44: generate a default tmp dir on per-profile basis
122           // hash the profD, as it would be otherwise a minor information leak
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         // XXX: error handling
135       }
136     }
137     else {
138       this.tempLocation = null;
139     }
140    
141     // Make this KB
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();
Note: See TracBrowser for help on using the browser.