From 3c23f4aa7eeabff0382f7789cfb7ad0c3090615a Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 3 Oct 2013 14:24:48 -0300 Subject: Initial import. --- chrome/content/statusBar/statusBarOverlay.js | 94 +++++++++++++++++++++++++++ chrome/content/statusBar/statusBarOverlay.xul | 17 +++++ 2 files changed, 111 insertions(+) create mode 100644 chrome/content/statusBar/statusBarOverlay.js create mode 100644 chrome/content/statusBar/statusBarOverlay.xul (limited to 'chrome/content/statusBar') diff --git a/chrome/content/statusBar/statusBarOverlay.js b/chrome/content/statusBar/statusBarOverlay.js new file mode 100644 index 0000000..31ec16a --- /dev/null +++ b/chrome/content/statusBar/statusBarOverlay.js @@ -0,0 +1,94 @@ +/** + * statusBar.js + * Copyright (C) 2013 LEAP + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along + */ + + +Components.utils.import("resource:///modules/mailServices.js"); + +var accountNotConfigured = getStringBundle( + "chrome://bitmask/locale/statusBar.properties") + .GetStringFromName("account_not_configured"); +var accountConfigured = getStringBundle( + "chrome://bitmask/locale/statusBar.properties") + .GetStringFromName("account_configured"); + + +/***************************************************************************** + * Schedule initialization and update functions. + ****************************************************************************/ + +// run startUp() once when window loads +window.addEventListener("load", function(e) { + starUp(); +}, false); + +// run updatePanel() periodically +window.setInterval( + function() { + updatePanel(); + }, 10000); // update every ten seconds + + +/***************************************************************************** + * GUI maintenance functions. + ****************************************************************************/ + +function starUp() { + updatePanel(); + if (!isBitmaskAccountConfigured()) { + launchAccountWizard(); + } +} + +/** + * Update the status bar panel with information about bitmask accounts. + */ +function updatePanel() { + var statusBarPanel = document.getElementById("bitmask-status-bar"); + if (isBitmaskAccountConfigured()) + statusBarPanel.label = accountConfigured; + else + statusBarPanel.label = accountNotConfigured; +} + +/** + * Handle a click on the status bar panel. For now, just launch the new + * account wizard if there's no account configured. + */ +function handleStatusBarClick() { + if (!isBitmaskAccountConfigured()) + launchAccountWizard(); +} + + +/***************************************************************************** + * Account management functions + ****************************************************************************/ + +/** + * Return true if there exists an account with incoming server hostname equal + * to IMAP_HOST and port equal to IMAP_PORT. + * + * TODO: also verify for SMTP configuration? + */ +function isBitmaskAccountConfigured() { + var accountManager = Cc["@mozilla.org/messenger/account-manager;1"] + .getService(Ci.nsIMsgAccountManager); + var existing = accountManager.findRealServer( + "", IMAP_HOST, "imap", IMAP_PORT); + return !!existing; +} diff --git a/chrome/content/statusBar/statusBarOverlay.xul b/chrome/content/statusBar/statusBarOverlay.xul new file mode 100644 index 0000000..006ccb9 --- /dev/null +++ b/chrome/content/statusBar/statusBarOverlay.xul @@ -0,0 +1,17 @@ + + +