mirror of
https://github.com/moparisthebest/FireTray
synced 2024-11-11 03:25:07 -05:00
refactoring + make server_type a preference
This commit is contained in:
parent
b6a54fb005
commit
aa9e13a366
@ -56,9 +56,10 @@ firetray.UIOptions = {
|
|||||||
|
|
||||||
populateMailAccountTypes: function() {
|
populateMailAccountTypes: function() {
|
||||||
let targetTree = document.getElementById("ui_mail_account_types");
|
let targetTree = document.getElementById("ui_mail_account_types");
|
||||||
|
let serverTypes = firetray.Utils.getObjPref('server_types');
|
||||||
|
|
||||||
for (t in firetray.Messaging.SERVER_TYPES) {
|
for (t in serverTypes) {
|
||||||
let accType = firetray.Messaging.SERVER_TYPES[t];
|
let accType = serverTypes[t];
|
||||||
|
|
||||||
let item = document.createElement('treeitem');
|
let item = document.createElement('treeitem');
|
||||||
let row = document.createElement('treerow');
|
let row = document.createElement('treerow');
|
||||||
@ -84,9 +85,10 @@ firetray.UIOptions = {
|
|||||||
// the DOM parent where we do appendChild
|
// the DOM parent where we do appendChild
|
||||||
let targetNode = document.getElementById(parentId);
|
let targetNode = document.getElementById(parentId);
|
||||||
|
|
||||||
|
let serverTypes = firetray.Utils.getObjPref('server_types');
|
||||||
let accounts = new firetray.Messaging.Accounts(true);
|
let accounts = new firetray.Messaging.Accounts(true);
|
||||||
for (let accountServer in accounts) {
|
for (let accountServer in accounts) {
|
||||||
if (firetray.Messaging.SERVER_TYPES[accountServer.type].excluded)
|
if (serverTypes[accountServer.type].excluded)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
let nodeAccount = document.createElement("checkbox");
|
let nodeAccount = document.createElement("checkbox");
|
||||||
@ -94,7 +96,7 @@ firetray.UIOptions = {
|
|||||||
nodeAccount.setAttribute('id', accountServerKey);
|
nodeAccount.setAttribute('id', accountServerKey);
|
||||||
nodeAccount.setAttribute('label', accountServer.rootFolder.name);
|
nodeAccount.setAttribute('label', accountServer.rootFolder.name);
|
||||||
nodeAccount.setAttribute('checked',
|
nodeAccount.setAttribute('checked',
|
||||||
(firetray.Messaging.getPrefAccountsExcluded().indexOf(accountServerKey) >= 0));
|
(firetray.Utils.getArrayPref('accounts_to_exclude').indexOf(accountServerKey) >= 0));
|
||||||
let that = this;
|
let that = this;
|
||||||
nodeAccount.addEventListener('command', function(e){
|
nodeAccount.addEventListener('command', function(e){
|
||||||
that.updateMailAccountsExcluded(that.accountBoxId);}, true);
|
that.updateMailAccountsExcluded(that.accountBoxId);}, true);
|
||||||
@ -115,7 +117,7 @@ firetray.UIOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG("accounts_to_exclude:"+prefValue);
|
LOG("accounts_to_exclude:"+prefValue);
|
||||||
firetray.Messaging.setPrefAccountsExcluded(prefValue);
|
firetray.Utils.setArrayPref('accounts_to_exclude', prefValue);
|
||||||
|
|
||||||
firetray.Messaging.updateUnreadMsgCount();
|
firetray.Messaging.updateUnreadMsgCount();
|
||||||
},
|
},
|
||||||
@ -130,8 +132,8 @@ firetray.UIOptions = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save SERVER_TYPES to the "server_types" preference.
|
* Save the "server_types" preference. This is called by the pref's system
|
||||||
* This is called by the pref's system when the GUI element is altered.
|
* when the GUI element is altered.
|
||||||
*/
|
*/
|
||||||
saveTreeServerTypes: function() {
|
saveTreeServerTypes: function() {
|
||||||
let tree = document.getElementById("ui_tree_server_types");
|
let tree = document.getElementById("ui_tree_server_types");
|
||||||
@ -190,7 +192,10 @@ firetray.UIOptions = {
|
|||||||
cell.setAttribute('value',prefObj[serverTypeName].excluded);
|
cell.setAttribute('value',prefObj[serverTypeName].excluded);
|
||||||
// CAUTION: removeEventListener in onQuit()
|
// CAUTION: removeEventListener in onQuit()
|
||||||
cell.addEventListener(
|
cell.addEventListener(
|
||||||
'DOMAttrModified', that._userChangeValueTreeServerTypes, true);
|
'DOMAttrModified', function(e) {
|
||||||
|
that._userChangeValueTreeServerTypes(e);
|
||||||
|
firetray.Messaging.updateUnreadMsgCount();
|
||||||
|
}, true);
|
||||||
row.appendChild(cell);
|
row.appendChild(cell);
|
||||||
|
|
||||||
// server_type_name
|
// server_type_name
|
||||||
|
@ -30,19 +30,6 @@ if ("undefined" == typeof(firetray)) {
|
|||||||
|
|
||||||
|
|
||||||
firetray.Messaging = {
|
firetray.Messaging = {
|
||||||
// TODO: turn into pref.
|
|
||||||
/* NOTE: definition checks not implemented on purpose (performance mainly)
|
|
||||||
should be well defined in default prefs, and new types are unlikely to
|
|
||||||
appear soon. */
|
|
||||||
SERVER_TYPES: {
|
|
||||||
"pop3": { order: 1, excluded: false },
|
|
||||||
"imap": { order: 1, excluded: false },
|
|
||||||
"movemail": { order: 2, excluded: true },
|
|
||||||
"none": { order: 3, excluded: false },
|
|
||||||
"rss": { order: 4, excluded: true },
|
|
||||||
"nntp": { order: 5, excluded: true }
|
|
||||||
},
|
|
||||||
|
|
||||||
_unreadMsgCount: 0,
|
_unreadMsgCount: 0,
|
||||||
|
|
||||||
enable: function() {
|
enable: function() {
|
||||||
@ -85,46 +72,20 @@ firetray.Messaging = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* get/set accounts_to_exclude preference which is a stringified Array
|
|
||||||
* containing the keys of the accounts to exclude
|
|
||||||
*/
|
|
||||||
getPrefAccountsExcluded: function() {
|
|
||||||
return JSON.parse(
|
|
||||||
firetray.Utils.prefService.getCharPref('accounts_to_exclude'));
|
|
||||||
},
|
|
||||||
|
|
||||||
setPrefAccountsExcluded: function(aArray) {
|
|
||||||
if (!isArray(aArray)) throw new TypeError();
|
|
||||||
LOG(aArray);
|
|
||||||
firetray.Utils.prefService.setCharPref('accounts_to_exclude',
|
|
||||||
JSON.stringify(aArray));
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
// window.addEventListener('unload', function(e){filteredClipboard.saveList();}, false); // TRY DIFFERENT EVENTS
|
|
||||||
// var filteredClipboard = {
|
|
||||||
// prefix:"extensions.filteredclipboard.",
|
|
||||||
// saveList: function (){
|
|
||||||
// var str = JSON.stringify(treeView.model);
|
|
||||||
// var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
|
||||||
// prefManager.setCharPref(this.prefix + "jsondata", str);
|
|
||||||
// },
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* computes total unread message count
|
* computes total unread message count
|
||||||
* TODO: check news accounts shouldn't be considered
|
* TODO: check news accounts shouldn't be considered
|
||||||
*/
|
*/
|
||||||
updateUnreadMsgCount: function() {
|
updateUnreadMsgCount: function() {
|
||||||
LOG("unreadMsgCount");
|
LOG("unreadMsgCount");
|
||||||
|
let serverTypes = firetray.Utils.getObjPref('server_types');
|
||||||
|
|
||||||
this._unreadMsgCount = 0; // reset
|
this._unreadMsgCount = 0; // reset
|
||||||
try {
|
try {
|
||||||
let accounts = new this.Accounts();
|
let accounts = new this.Accounts();
|
||||||
for (let accountServer in accounts) {
|
for (let accountServer in accounts) {
|
||||||
if ( (this.SERVER_TYPES[accountServer.type].excluded)
|
if ( (serverTypes[accountServer.type].excluded)
|
||||||
|| (this.getPrefAccountsExcluded().indexOf(accountServer.key) >= 0) )
|
|| (firetray.Utils.getArrayPref('accounts_to_exclude').indexOf(accountServer.key) >= 0) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
let rootFolder = accountServer.rootFolder; // nsIMsgFolder
|
let rootFolder = accountServer.rootFolder; // nsIMsgFolder
|
||||||
@ -191,13 +152,14 @@ firetray.Messaging.Accounts.prototype.__iterator__ = function() {
|
|||||||
accountServers[i] = accountServer;
|
accountServers[i] = accountServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let serverTypes = firetray.Utils.getObjPref('server_types');
|
||||||
if (this.sortByTypeAndName) {
|
if (this.sortByTypeAndName) {
|
||||||
accountServers.sort(function(a,b) {
|
accountServers.sort(function(a,b) {
|
||||||
if (firetray.Messaging.SERVER_TYPES[a.type].order
|
if (serverTypes[a.type].order
|
||||||
< firetray.Messaging.SERVER_TYPES[b.type].order)
|
< serverTypes[b.type].order)
|
||||||
return -1;
|
return -1;
|
||||||
if (firetray.Messaging.SERVER_TYPES[a.type].order
|
if (serverTypes[a.type].order
|
||||||
> firetray.Messaging.SERVER_TYPES[b.type].order)
|
> serverTypes[b.type].order)
|
||||||
return 1;
|
return 1;
|
||||||
if (a.prettyName < b.prettyName)
|
if (a.prettyName < b.prettyName)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -38,6 +38,34 @@ firetray.Utils = {
|
|||||||
prefService: Services.prefs.getBranch("extensions.firetray."),
|
prefService: Services.prefs.getBranch("extensions.firetray."),
|
||||||
strings: Services.strings.createBundle("chrome://firetray/locale/overlay.properties"),
|
strings: Services.strings.createBundle("chrome://firetray/locale/overlay.properties"),
|
||||||
|
|
||||||
|
getObjPref: function(prefStr) {
|
||||||
|
try {
|
||||||
|
var objPref = JSON.parse(
|
||||||
|
firetray.Utils.prefService.getCharPref(prefStr));
|
||||||
|
} catch (x) {
|
||||||
|
ERROR(x);
|
||||||
|
}
|
||||||
|
return objPref;
|
||||||
|
},
|
||||||
|
setObjPref: function(prefStr, obj) {
|
||||||
|
LOG(obj);
|
||||||
|
try {
|
||||||
|
firetray.Utils.prefService.setCharPref(prefStr, JSON.stringify(obj));
|
||||||
|
} catch (x) {
|
||||||
|
ERROR(x);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getArrayPref: function(prefStr) {
|
||||||
|
let arrayPref = this.getObjPref(prefStr);
|
||||||
|
if (!isArray(arrayPref)) throw new TypeError();
|
||||||
|
return arrayPref;
|
||||||
|
},
|
||||||
|
setArrayPref: function(prefStr, aArray) {
|
||||||
|
if (!isArray(aArray)) throw new TypeError();
|
||||||
|
this.setObjPref(prefStr, aArray);
|
||||||
|
},
|
||||||
|
|
||||||
dumpObj: function(obj) {
|
dumpObj: function(obj) {
|
||||||
let str = "";
|
let str = "";
|
||||||
for(i in obj) {
|
for(i in obj) {
|
||||||
|
Loading…
Reference in New Issue
Block a user