summaryrefslogtreecommitdiff
path: root/chrome/content/statusBar/statusBarOverlay.js
blob: c82b3f2acb7cf1d430fc2e7dac3efb106438e0c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
 * 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");
Components.utils.import("resource://gre/modules/Services.jsm");

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();
    } else {
        var server = getBitmaskServer();
        // TODO: add an alert that there exists a bitmask account with caching
        // enabled.
        //if (server.offlineDownload == true)
        //    alertPrompt('WARNING!');
    }
}

/**
 * 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() {
    return !!getBitmaskServer();
}

/**
 * Get a configured bitmask account
 */
function getBitmaskServer() {
    var accountManager = Cc["@mozilla.org/messenger/account-manager;1"]
                         .getService(Ci.nsIMsgAccountManager);
    return accountManager.findRealServer(
        "", IMAP_HOST, "imap", IMAP_PORT);
}