1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-11-17 22:35:02 -05:00

* Rely further on the preference system for options (leverage onsynctopreference)

* Fix listeners on ui_tree_mail_accounts.

This is for moving away from the instantApply=true assomption.
This commit is contained in:
foudfou 2014-03-09 10:42:39 +01:00
parent 3246da7624
commit c8985732e3
4 changed files with 59 additions and 67 deletions

View File

@ -1,13 +1,5 @@
/* -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* FIXME: instantApply pref defaults to false on Windows. But the Firetray pref
window was originaly crafted for instantApply platforms: some UI changes do
also change prefs programmaticaly. For a consistant behaviour across all
instantApply cases, we should probably not set prefs dynamically, that is leave
it all to the UI. See:
http://forums.mozillazine.org/viewtopic.php?f=19&t=2743643
https://groups.google.com/forum/#!topic/mozilla.dev.extensions/SBGIogdIiwE */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
@ -213,7 +205,7 @@ var firetrayUIOptions = {
if (val) iconNames.push(val);
}
log.debug("iconNames="+iconNames);
firetray.Utils.setArrayPref(prefIconNames, iconNames);
firetray.Utils.setArrayPref(prefIconNames, iconNames); // FIXME: should be a <preference>
},
disableIconTypeMaybe: function(appIconType) {
@ -234,7 +226,6 @@ var firetrayUIOptions = {
this.initMessageCountSettings();
this.initNotificationSettings();
this.initMailTrigger();
this.toggleNotifications(firetray.Utils.prefService.getBoolPref("mail_notification_enabled"));
},
@ -290,21 +281,14 @@ var firetrayUIOptions = {
return -1;
},
initMailTrigger: function() {
document.getElementById("ui_mail_change_trigger").value =
firetray.Utils.prefService.getCharPref("mail_change_trigger");
},
updateMailTrigger: function() {
let mailTrigger = document.getElementById("ui_mail_change_trigger").value.trim();
firetray.Utils.prefService.setCharPref("mail_change_trigger", mailTrigger);
saveMailChangeTrigger: function(uiElt) {
return uiElt.value.trim();
},
updateNotificationSettings: function() {
log.debug("updateNotificationSettings");
let radioMailNotify = document.getElementById("ui_radiogroup_mail_notification");
let mailNotificationType = +radioMailNotify.getItemAtIndex(radioMailNotify.selectedIndex).value;
firetray.Utils.prefService.setIntPref("mail_notification_type", mailNotificationType);
this.disableNotificationMaybe(mailNotificationType);
firetray.Messaging.updateIcon();
@ -316,12 +300,6 @@ var firetrayUIOptions = {
this.disableMessageCountMaybe(messageCountType);
},
updateChatBlinkSettings: function() {
let radioBlinkStyle = document.getElementById("ui_chat_icon_blink_style");
let blinkStyle = +radioBlinkStyle.getItemAtIndex(radioBlinkStyle.selectedIndex).value;
firetray.Utils.prefService.setIntPref("chat_icon_blink_style", blinkStyle);
},
disableNotificationMaybe: function(notificationSetting) {
log.debug("disableNotificationMaybe: "+notificationSetting);
@ -355,7 +333,6 @@ var firetrayUIOptions = {
let newMailIconNames = document.getElementById("newmail_icon_names");
this.disableNChildren(newMailIconNames, 2, false);
}
firetray.Utils.prefService.setIntPref("mail_notification_type", FIRETRAY_NOTIFICATION_NEWMAIL_ICON);
}
},
@ -434,44 +411,53 @@ var firetrayUIOptions = {
},
/**
* NOTE: folder exceptions for unread messages count are *stored* in
* preferences as excluded, but *shown* as "not included"
* NOTE: we store folder type *exceptions* for unread messages count. This is
* easier than storing all possible included folder types. The drawback is
* that we must inverse the selection in the UI: we show exceptions as "not
* included".
*/
populateExcludedFoldersList: function() {
let excludedFoldersList = document.getElementById('excluded_folders_list');
let prefExcludedFoldersFlags = firetray.Utils.prefService
.getIntPref("excluded_folders_flags");
log.debug("prefExcludedFoldersFlags="+prefExcludedFoldersFlags.toString(16));
for (let folderType in FLDRS_UNINTERESTING) {
let localizedFolderType = this.strings.getString(folderType);
let item = excludedFoldersList.appendItem(localizedFolderType, folderType);
let folderTypeVal = FLDRS_UNINTERESTING[folderType];
let item = excludedFoldersList.appendItem(localizedFolderType, folderTypeVal);
item.setAttribute("observes", "broadcaster-notification-disabled");
log.debug("folder: "+folderType);
if (!(FLDRS_UNINTERESTING[folderType] & prefExcludedFoldersFlags)) {
let folderTypeSet = (folderTypeVal & prefExcludedFoldersFlags);
log.debug("folder: "+folderType+" folderTypeVal="+folderTypeVal+" folderTypeSet="+folderTypeSet);
if (!folderTypeSet) {
excludedFoldersList.ensureElementIsVisible(item); // bug 326445
excludedFoldersList.addItemToSelection(item); // doesn't trigger onselect
excludedFoldersList.addItemToSelection(item); // does trigger onselect...
}
}
// ...so we add onselect handler after the listbox is populated
excludedFoldersList.addEventListener(
'select', function(e) { // select also on unselect
document.getElementById('pref-pane-mail').userChangedValue(excludedFoldersList);
}, true);
},
updateExcludedFoldersPref: function() {
let excludedFoldersList = document.getElementById('excluded_folders_list');
loadExcludedFoldersFlags: function(uiElt) {
// we can't do much here since onLoad() not yet applied at onsyncfrompreference...
},
log.debug("LAST SELECTED: "+excludedFoldersList.currentItem.label);
let excludedFoldersFlags = null;
for (let i = 0, len=excludedFoldersList.itemCount; i<len; ++i) {
let folder = excludedFoldersList.getItemAtIndex(i);
saveExcludedFoldersFlags: function(uiElt) {
log.debug("LAST SELECTED: "+uiElt.currentItem.label);
let excludedFoldersFlags = 0;
for (let i = 0, len=uiElt.itemCount; i<len; ++i) {
let folder = uiElt.getItemAtIndex(i);
if (folder.selected)
excludedFoldersFlags &= ~FLDRS_UNINTERESTING[folder.value];
excludedFoldersFlags &= ~folder.value; // clear
else
excludedFoldersFlags |= FLDRS_UNINTERESTING[folder.value];
excludedFoldersFlags |= folder.value; // set
}
log.debug("excluded folders flags: "+excludedFoldersFlags);
firetray.Utils.prefService.setIntPref("excluded_folders_flags",
excludedFoldersFlags);
firetray.Messaging.updateMsgCountWithCb();
log.debug("excluded folders flags: "+excludedFoldersFlags.toString(16));
return excludedFoldersFlags;
},
/**
@ -509,12 +495,11 @@ var firetrayUIOptions = {
* needed for triggering actual preference change and saving
*/
_userChangeValueTree: function(event) {
log.debug("_userChangeValueTree");
if (event.attrName == "label") log.debug("label changed!");
if (event.attrName == "value") log.debug("value changed!");
document.getElementById("pref-pane-mail")
.userChangedValue(document.getElementById("ui_tree_mail_accounts"));
firetray.Messaging.updateMsgCountWithCb();
},
_userChangeValueTreeServerTypes: function(event) {
@ -587,14 +572,16 @@ var firetrayUIOptions = {
let cellExcluded = document.createElement('treecell');
cellExcluded.setAttribute('value',!serverTypes[serverTypeName].excluded);
cellExcluded.addEventListener( // CAUTION: removeEventListener in onQuit()
'DOMAttrModified', that._userChangeValueTreeServerTypes, true);
'DOMAttrModified', function(e){that._userChangeValueTreeServerTypes(e);},
true);
typeRow.appendChild(cellExcluded);
// account_or_server_type_order
let cellOrder = document.createElement('treecell');
cellOrder.setAttribute('label',serverTypes[serverTypeName].order);
cellOrder.addEventListener( // CAUTION: removeEventListener in onQuit()
'DOMAttrModified', that._userChangeValueTreeServerTypes, true);
'DOMAttrModified', function(e){that._userChangeValueTreeServerTypes(e);},
true);
typeRow.appendChild(cellOrder);
target.appendChild(typeItem);
@ -701,7 +688,7 @@ var firetrayUIOptions = {
* Save the "mail_accounts" preference. This is called by the pref's system
* when the GUI element is altered.
*/
saveTreeAccountsOrServerTypes: function() {
saveTreeAccountsOrServerTypes: function() { // FIXME: broken ?
let tree = document.getElementById("ui_tree_mail_accounts");
log.debug("VIEW="+ tree.view + ", rowCount="+tree.view.rowCount);

View File

@ -129,13 +129,16 @@
<preferences>
<preference id="pref_mail_notification_enabled" name="extensions.firetray.mail_notification_enabled" type="bool" />
<preference id="pref_mail_notification_type" name="extensions.firetray.mail_notification_type" type="int" />
<preference id="pref_message_count_type" name="extensions.firetray.message_count_type" type="int" />
<preference id="pref_icon_text_color" name="extensions.firetray.icon_text_color" type="string" />
<preference id="pref_custom_mail_icon" name="extensions.firetray.custom_mail_icon" type="string" />
<preference id="pref_excluded_folders_flags" name="extensions.firetray.excluded_folders_flags" type="int" />
<preference id="pref_mail_change_trigger" name="extensions.firetray.mail_change_trigger" type="string"/>
<preference id="pref_mail_accounts" name="extensions.firetray.mail_accounts" type="string"/>
<preference id="pref_folder_count_recursive" name="extensions.firetray.folder_count_recursive" type="bool" />
<preference id="pref_only_favorite_folders" name="extensions.firetray.only_favorite_folders" type="bool" />
<preference id="pref_mail_change_trigger" name="extensions.firetray.mail_change_trigger" type="string" />
<preference id="pref_mail_get_attention" name="extensions.firetray.mail_get_attention" type="bool" />
</preferences>
@ -169,7 +172,7 @@
observes="broadcaster-notification-disabled" />
</caption>
<radiogroup id="ui_radiogroup_mail_notification">
<radiogroup id="ui_radiogroup_mail_notification" preference="pref_mail_notification_type">
<hbox id="ui_mail_notification_unread_count">
<radio id="ui_radio_mail_notification_unread_count" label="&mail_notification_unread_count.label;"
accesskey="&mail_notification_unread_count.accesskey;"
@ -238,7 +241,8 @@
<listbox id="excluded_folders_list" rows="7" flex="1" seltype="multiple"
tooltiptext="&excluded_folders_list.tooltip;"
onselect="firetrayUIOptions.updateExcludedFoldersPref()"
preference="pref_excluded_folders_flags"
onsynctopreference="return firetrayUIOptions.saveExcludedFoldersFlags(this);"
observes="broadcaster-notification-disabled" />
</groupbox>
@ -295,8 +299,9 @@
<label control="ui_mail_change_trigger" value="&mail_change_trigger.label;"
accesskey="&mail_change_trigger.accesskey;" />
<textbox id="ui_mail_change_trigger" size="18" placeholder="&mail_change_trigger.placeholder;"
onchange="firetrayUIOptions.updateMailTrigger();" flex="1"
tooltiptext="&mail_change_trigger.tooltip;"
tooltiptext="&mail_change_trigger.tooltip;" flex="1"
preference="pref_mail_change_trigger"
onsynctopreference="return firetrayUIOptions.saveMailChangeTrigger(this);"
observes="broadcaster-notification-disabled" />
</hbox>
@ -338,10 +343,8 @@
<label control="ui_chat_icon_blink_style" observes="broadcaster-chat-icon-disabled"
value="&chat_icon_blink_style.label;" accesskey="&chat_icon_blink_style.accesskey;" />
<radio id="ui_chat_icon_blink_style_normal" label="&chat_icon_blink_style_normal;"
oncommand="firetrayUIOptions.updateChatBlinkSettings()"
observes="broadcaster-chat-icon-disabled"/>
<radio id="ui_chat_icon_blink_style_fade" label="&chat_icon_blink_style_fade;"
oncommand="firetrayUIOptions.updateChatBlinkSettings()"
observes="broadcaster-chat-icon-disabled"/>
</hbox>
</radiogroup>

View File

@ -524,9 +524,11 @@ firetray.PrefListener = new PrefListener(
break;
case 'new_mail_icon_names':
firetray.StatusIcon.loadThemedIcons();
case 'only_favorite_folders':
case 'message_count_type':
case 'excluded_folders_flags':
case 'folder_count_recursive':
case 'mail_accounts':
case 'message_count_type':
case 'only_favorite_folders':
firetray.Messaging.updateMsgCountWithCb();
break;
case 'app_mail_icon_names':

View File

@ -13,14 +13,14 @@ Cu.import("resource://gre/modules/PluralForm.jsm");
Cu.import("resource://firetray/commons.js");
const FLDRS_UNINTERESTING = {
Archive: Ci.nsMsgFolderFlags.Archive,
Drafts: Ci.nsMsgFolderFlags.Drafts,
Junk: Ci.nsMsgFolderFlags.Junk,
Queue: Ci.nsMsgFolderFlags.Queue,
SentMail: Ci.nsMsgFolderFlags.SentMail,
Templates: Ci.nsMsgFolderFlags.Templates,
Trash: Ci.nsMsgFolderFlags.Trash,
Virtual: Ci.nsMsgFolderFlags.Virtual
Archive: Ci.nsMsgFolderFlags.Archive, // 0x00004000
Drafts: Ci.nsMsgFolderFlags.Drafts, // 0x00000400
Junk: Ci.nsMsgFolderFlags.Junk, // 0x40000000
Queue: Ci.nsMsgFolderFlags.Queue, // 0x00000800
SentMail: Ci.nsMsgFolderFlags.SentMail, // 0x00000200
Templates: Ci.nsMsgFolderFlags.Templates, // 0x00400000
Trash: Ci.nsMsgFolderFlags.Trash, // 0x00000100
Virtual: Ci.nsMsgFolderFlags.Virtual // 0x00000020
};
const ACCOUNTS_PREF_BRANCH = "mail.accountmanager.accounts";