1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-12-22 05:48:49 -05:00

* re-introduce dumpObj() useful for DOM elements

* merge server_types and excluded_accounts into one mail_accounts pref

This is visually more intuitive. So do we use the same tree for both. But we
store them into 2 different "branches" of the corresponding preference
object. We need to keep track of them separately because of account
creation/deletion.
This commit is contained in:
foudfou 2011-11-02 01:48:41 +01:00
parent 4d4c21b9f9
commit 5ad5b3c3d4
7 changed files with 87 additions and 98 deletions

3
TODO
View File

@ -1,7 +1,6 @@
=TODO=
* make accounts_to_exclude a tree that is modified by server_types_to_exclude,
or include accounts into server_types' tree ?
* options: in mail_accounts, have serverTypes interact with excludedAccounts
* add "enable biff notification" option. And if true:

View File

@ -15,7 +15,6 @@ if ("undefined" == typeof(firetray)) {
};
firetray.UIOptions = {
accountBoxId: "ui_accounts_box",
onLoad: function() {
if(firetray.Handler.inMailApp) {
@ -33,7 +32,7 @@ firetray.UIOptions = {
// cleaning: removeEventListener on cells
// NOTE: not sure this is necessary on window close
let items = document.getElementById("ui_server_types").childNodes;
let items = document.getElementById("ui_mail_accounts").childNodes;
for (let i=0; i < items.length; i++) {
let cells = items[i].getElementsByTagName("treecell");
// col 2 and 3: server_type_excluded, server_type_order
@ -51,47 +50,6 @@ firetray.UIOptions = {
targetNode.hidden = true;
},
insertMailAccountsExcluded: function(parentId) {
// the DOM parent where we do appendChild
let targetNode = document.getElementById(parentId);
let serverTypes = firetray.Utils.getObjPref('server_types');
let accounts = new firetray.Messaging.Accounts(true);
for (let accountServer in accounts) {
if (serverTypes[accountServer.type].excluded)
continue;
let nodeAccount = document.createElement("checkbox");
let accountServerKey = accountServer.key.toString();
nodeAccount.setAttribute('id', accountServerKey);
nodeAccount.setAttribute('label', accountServer.rootFolder.name);
nodeAccount.setAttribute('checked',
(firetray.Utils.getArrayPref('accounts_to_exclude').indexOf(accountServerKey) >= 0));
let that = this;
nodeAccount.addEventListener('command', function(e){
that.updateMailAccountsExcluded(that.accountBoxId);}, true);
targetNode.appendChild(nodeAccount);
}
// let disable_notify=prefManager.getIntPref("extensions.firetray.show_mail_notification")==0;
// this._disableGroup(targetNode,disable_notify);
},
updateMailAccountsExcluded: function(parentId) {
let targetNode = document.getElementById(parentId);
let prefValue = [];
for (let i=1; i < targetNode.childNodes.length; i++) {
if (targetNode.childNodes[i].checked)
prefValue.push(targetNode.childNodes[i].getAttribute('id'));
}
LOG("accounts_to_exclude:"+prefValue);
firetray.Utils.setArrayPref('accounts_to_exclude', prefValue);
firetray.Messaging.updateUnreadMsgCount();
},
_disableGroup: function(group, disableval) {
try {
for (let i=0; i< group.childNodes.length; i++)
@ -108,20 +66,26 @@ firetray.UIOptions = {
if (event.attrName == "label") LOG("label changed!");
if (event.attrName == "value") LOG("value changed!");
document.getElementById("pane1")
.userChangedValue(document.getElementById("ui_tree_server_types"));
.userChangedValue(document.getElementById("ui_tree_mail_accounts"));
},
/**
* NOTE: account exceptions for unread messages count are *stored* in
* preferences as excluded, but *shown* as "not included"
*/
populateTreeServerTypes: function() {
let that = this;
let prefPane = document.getElementById("pane1");
let prefStr = firetray.Utils.prefService.getCharPref("server_types");
let prefStr = firetray.Utils.prefService.getCharPref("mail_accounts");
LOG("PREF="+prefStr);
let serverTypes = JSON.parse(prefStr);
let mailAccounts = JSON.parse(prefStr);
let serverTypes = mailAccounts["serverTypes"];
let accountsExcluded = mailAccounts["excludedAccounts"];
let accountsByServerType = firetray.Messaging.accountsByServerType();
LOG(JSON.stringify(accountsByServerType));
let target = document.getElementById("ui_server_types");
let target = document.getElementById("ui_mail_accounts");
for (let serverTypeName in serverTypes) {
let name = serverTypes[serverTypeName];
@ -140,9 +104,8 @@ firetray.UIOptions = {
// server_type_excluded => checkbox
cell = document.createElement('treecell');
cell.setAttribute('value',serverTypes[serverTypeName].excluded);
// CAUTION: removeEventListener in onQuit()
cell.addEventListener(
cell.setAttribute('value',!serverTypes[serverTypeName].excluded);
cell.addEventListener( // CAUTION: removeEventListener in onQuit()
'DOMAttrModified', function(e) {
that._userChangeValueTreeServerTypes(e);
firetray.Messaging.updateUnreadMsgCount();
@ -152,7 +115,7 @@ firetray.UIOptions = {
// server_type_order
cell = document.createElement('treecell');
cell.setAttribute('label',serverTypes[serverTypeName].order);
cell.addEventListener(
cell.addEventListener( // CAUTION: removeEventListener in onQuit()
'DOMAttrModified', that._userChangeValueTreeServerTypes, true);
row.appendChild(cell);
@ -164,18 +127,26 @@ firetray.UIOptions = {
LOG("type: "+serverTypeName+", Accounts: "+JSON.stringify(typeAccounts));
if (typeof(typeAccounts) == "undefined")
continue;
for (let i=0; i<typeAccounts.length; i++) {
let subItem = document.createElement('treeitem');
let subRow = document.createElement('treerow');
// server_type_name
cell = document.createElement('treecell');
cell.setAttribute('id', typeAccounts[i].key);
cell.setAttribute('label',typeAccounts[i].name);
cell.setAttribute('editable',false);
subRow.appendChild(cell);
// server_type_excluded => checkbox
let cell = document.createElement('treecell');
cell.setAttribute('value',(accountsExcluded.indexOf(typeAccounts[i].key) < 0));
cell.addEventListener( // CAUTION: removeEventListener in onQuit()
'DOMAttrModified', function(e) {
that._userChangeValueTreeServerTypes(e);
firetray.Messaging.updateUnreadMsgCount();
}, true);
subRow.appendChild(cell);
// server_type_order - UNUSED (added for consistency)
@ -190,34 +161,47 @@ firetray.UIOptions = {
}
let tree = document.getElementById("ui_tree_server_types");
let tree = document.getElementById("ui_tree_mail_accounts");
tree.addEventListener("keypress", that.onKeyPressTreeServerTypes, true);
},
/*
* Save the "server_types" preference. This is called by the pref's system
* Save the "mail_accounts" preference. This is called by the pref's system
* when the GUI element is altered.
*/
saveTreeServerTypes: function() {
let tree = document.getElementById("ui_tree_server_types");
let tree = document.getElementById("ui_tree_mail_accounts");
LOG("VIEW="+ tree.view + ", rowCount="+tree.view.rowCount);
let prefObj = {};
let prefObj = {"serverTypes":{}, "excludedAccounts":[]};
for (let i=0; i < tree.view.rowCount; i++) {
if (tree.view.getLevel(i)>0)
continue;
// TODO: rename server_type_* to account_or_server_type
let serverTypeName = tree.view.getCellText(
i, tree.columns.getNamedColumn("server_type_name"));
let serverTypeExcluded = (
tree.view.getCellValue(
i, tree.columns.getNamedColumn("server_type_excluded"))
=== 'true');
let serverTypeName = tree.view.getCellText(
i, tree.columns.getNamedColumn("server_type_name"));
!== 'true');
let serverTypeOrder = parseInt(tree.view.getCellText(
i, tree.columns.getNamedColumn("server_type_order")));
LOG("SUPER: "+serverTypeName+", "+serverTypeExcluded);
prefObj[serverTypeName] =
{ order: serverTypeOrder, excluded: serverTypeExcluded };
if (tree.view.getLevel(i) === 0) { // serverTypes
prefObj["serverTypes"][serverTypeName] =
{ order: serverTypeOrder, excluded: serverTypeExcluded };
} else if (tree.view.getLevel(i) === 1) { // excludedAccounts
if (!serverTypeExcluded)
continue;
let rowNode = tree.view.getItemAtIndex(i).firstChild; // treerow
let rowCells = rowNode.getElementsByTagName('treecell');
let serverKey = rowCells[0].id;
prefObj["excludedAccounts"].push(serverKey);
} else
continue;
}
let prefStr = JSON.stringify(prefObj);
@ -229,7 +213,7 @@ firetray.UIOptions = {
onKeyPressTreeServerTypes: function(event) {
LOG("TREE KEYPRESS: "+event.originalTarget);
let tree = document.getElementById("ui_tree_server_types");
let tree = document.getElementById("ui_tree_mail_accounts");
let col = tree.editingColumn; // col.index
// only int allowed

View File

@ -4,7 +4,7 @@
<!DOCTYPE prefwindow SYSTEM "chrome://firetray/locale/options.dtd">
<prefwindow id="firetray-preferences"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&prefwindow.title;">
title="&prefwindow.title;" minwidth="360px">
<script type="application/x-javascript" src="options.js" />
@ -13,8 +13,8 @@
<preferences>
<preference id="pref_bool_close_hides"
name="extensions.firetray.close_hides" type="bool"/>
<preference id="pref_string_server_types"
name="extensions.firetray.server_types" type="string"/>
<preference id="pref_string_mail_accounts"
name="extensions.firetray.mail_accounts" type="string"/>
</preferences>
@ -42,38 +42,31 @@
<tabpanel id="mail_tabpanel">
<groupbox flex="1">
<caption label="&unread_count_account_exceptions;" />
<caption label="&unread_count_account_exceptions;"
tooltiptext="&unread_count_account_exceptions.tooltip;" />
<label value="&mail_account_types_exclude;" />
<tree id="ui_tree_server_types" flex="1" rows="6"
<tree id="ui_tree_mail_accounts" flex="1" rows="10"
seltype="single" editable="true"
preference-editable="true"
preference="pref_string_server_types"
preference="pref_string_mail_accounts"
onsynctopreference="return firetray.UIOptions.saveTreeServerTypes();">
<treecols>
<treecol id="server_type_name" editable="false" flex="2"
persist="width" primary="true" label="&server_type_name;"
tooltiptext="&server_type_name_tooltip;"/>
tooltiptext="&server_type_name.tooltip;"/>
<splitter class="tree-splitter" resizeafter="grow"/>
<treecol id="server_type_excluded" type="checkbox" editable="true"
label="&server_type_excluded;" flex="1" persist="width"
tooltiptext="&server_type_excluded_tooltip;"/>
tooltiptext="&server_type_excluded.tooltip;"/>
<splitter class="tree-splitter" resizeafter="grow"/>
<treecol id="server_type_order" editable="true"
persist="width"
flex="1" hidden= "true" label="&server_type_order;"
tooltiptext="&server_type_name_tooltip;"/>
tooltiptext="&server_type_name.tooltip;"/>
</treecols>
<treechildren id="ui_server_types" flex="1" />
<treechildren id="ui_mail_accounts" flex="1" />
</tree>
<separator class="thin" />
<label value="&mail_accounts_exclude;"/>
<vbox id="ui_accounts_box" /> <!-- firetray.UIOptions.accountBoxId -->
<!-- accounts are dynamically added here with insert_accounts_name()
functions, called at the bottom of this file -->
</groupbox>
</tabpanel>

View File

@ -8,14 +8,12 @@
<!ENTITY bool_close_hides.label "Closing windows hides to tray">
<!ENTITY bool_close_hides.accesskey "C">
<!ENTITY unread_count_account_exceptions "Exclude accounts from unread count">
<!ENTITY unread_count_account_exceptions "Included accounts">
<!ENTITY unread_count_account_exceptions.tooltip "Included accounts for unread message count">
<!ENTITY mail_account_types_exclude "Account types to exclude:">
<!ENTITY server_type_name "Account">
<!ENTITY server_type_name.tooltip "FIXME">
<!ENTITY server_type_excluded "Excluded">
<!ENTITY server_type_excluded_tooltip "FIXME">
<!ENTITY server_type_name "Type">
<!ENTITY server_type_name_tooltip "FIXME">
<!ENTITY server_type_excluded.tooltip "FIXME">
<!ENTITY server_type_order "Order">
<!ENTITY server_type_order_tooltip "FIXME">
<!ENTITY mail_accounts_exclude "Mail accounts to exclude:">
<!ENTITY server_type_order.tooltip "FIXME">

View File

@ -6,5 +6,5 @@ pref("browser.tabs.warnOnClose", false);
// Extension prefs
pref("extensions.firetray.close_hides", true);
pref("extensions.firetray.accounts_to_exclude", "[]"); // JSON
pref("extensions.firetray.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} }'); // JSON
// exposed in 1 tree, hence 2 branches: serverTypes, excludedAccounts
pref("extensions.firetray.mail_accounts", '{ "serverTypes": {"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}}, "excludedAccounts": [] }'); // JSON

View File

@ -78,14 +78,16 @@ firetray.Messaging = {
*/
updateUnreadMsgCount: function() {
LOG("unreadMsgCount");
let serverTypes = firetray.Utils.getObjPref('server_types');
let mailAccounts = firetray.Utils.getObjPref('mail_accounts');
let serverTypes = mailAccounts["serverTypes"];
let excludedAccounts = mailAccounts["excludedAccounts"];
this._unreadMsgCount = 0; // reset
try {
let accounts = new this.Accounts();
for (let accountServer in accounts) {
if ( (serverTypes[accountServer.type].excluded)
|| (firetray.Utils.getArrayPref('accounts_to_exclude').indexOf(accountServer.key) >= 0) )
|| (excludedAccounts.indexOf(accountServer.key) >= 0) )
continue;
let rootFolder = accountServer.rootFolder; // nsIMsgFolder
@ -152,7 +154,8 @@ firetray.Messaging.Accounts.prototype.__iterator__ = function() {
accountServers[i] = accountServer;
}
let serverTypes = firetray.Utils.getObjPref('server_types');
let mailAccounts = firetray.Utils.getObjPref('mail_accounts');
let serverTypes = mailAccounts["serverTypes"];
if (this.sortByTypeAndName) {
accountServers.sort(function(a,b) {
if (serverTypes[a.type].order
@ -176,7 +179,7 @@ firetray.Messaging.Accounts.prototype.__iterator__ = function() {
};
/**
* return accounts grouped by server_types.
* return accounts grouped by mail_accounts.
*
* ex: { movemail: {"server1", "server2"}, imap: {"server3"} }
*/

View File

@ -100,6 +100,18 @@ firetray.Utils = {
let protocolHandler = Cc["@mozilla.org/network/protocol;1?name=file"]
.createInstance(Ci.nsIFileProtocolHandler);
return protocolHandler.getFileFromURLSpec(aPath).path;
},
dumpObj: function(obj) {
let str = "";
for(i in obj) {
try {
str += "obj["+i+"]: " + obj[i] + "\n";
} catch(e) {
str += "obj["+i+"]: Unavailable\n";
}
}
LOG(str);
}
};