summaryrefslogtreecommitdiffstats
path: root/comm/calendar/base/content/calendar-statusbar.js
blob: 8d463ffc67cf61e7ec2036fc272c3e52fc6bb067 (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
108
109
110
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");

/* exported gCalendarStatusFeedback */

/**
 * This code might change soon if we support Thunderbird's activity manager.
 * NOTE: The naming "Meteors" is historical.
 */
var gCalendarStatusFeedback = {
  mCalendarStep: 0,
  mCalendarCount: 0,
  mWindow: null,
  mStatusText: null,
  mStatusBar: null,
  mStatusProgressPanel: null,
  mThrobber: null,
  mProgressMode: Ci.calIStatusObserver.NO_PROGRESS,
  mCurIndex: 0,
  mInitialized: false,
  mCalendars: {},

  QueryInterface: ChromeUtils.generateQI(["calIStatusObserver"]),

  initialize(aWindow) {
    if (!this.mInitialized) {
      this.mWindow = aWindow;
      this.mStatusText = this.mWindow.document.getElementById("statusText");
      this.mStatusBar = this.mWindow.document.getElementById("statusbar-icon");
      this.mStatusProgressPanel = this.mWindow.document.getElementById("statusbar-progresspanel");
      this.mThrobber = this.mWindow.document.getElementById("navigator-throbber");
      this.mInitialized = true;
    }
  },

  showStatusString(status) {
    this.mStatusText.setAttribute("label", status);
  },

  get spinning() {
    return this.mProgressMode;
  },

  startMeteors(aProgressMode, aCalendarCount) {
    if (aProgressMode != Ci.calIStatusObserver.NO_PROGRESS) {
      if (!this.mInitialized) {
        console.error("StatusObserver has not been initialized!");
        return;
      }
      this.mCalendars = {};
      this.mCurIndex = 0;
      if (aCalendarCount) {
        this.mCalendarCount = this.mCalendarCount + aCalendarCount;
        this.mCalendarStep = Math.trunc(100 / this.mCalendarCount);
      }
      this.mProgressMode = aProgressMode;
      this.mStatusProgressPanel.removeAttribute("collapsed");
      if (this.mProgressMode == Ci.calIStatusObserver.DETERMINED_PROGRESS) {
        this.mStatusBar.value = 0;
        let commonStatus = cal.l10n.getCalString("gettingCalendarInfoCommon");
        this.showStatusString(commonStatus);
      }
      if (this.mThrobber) {
        this.mThrobber.setAttribute("busy", true);
      }
    }
  },

  stopMeteors() {
    if (!this.mInitialized) {
      return;
    }
    if (this.spinning != Ci.calIStatusObserver.NO_PROGRESS) {
      this.mProgressMode = Ci.calIStatusObserver.NO_PROGRESS;
      this.mStatusProgressPanel.collapsed = true;
      this.mStatusBar.value = 0;
      this.mCalendarCount = 0;
      this.showStatusString("");
      if (this.mThrobber) {
        this.mThrobber.setAttribute("busy", false);
      }
    }
  },

  calendarCompleted(aCalendar) {
    if (!this.mInitialized) {
      return;
    }
    if (this.spinning != Ci.calIStatusObserver.NO_PROGRESS) {
      if (this.spinning == Ci.calIStatusObserver.DETERMINED_PROGRESS) {
        if (!this.mCalendars[aCalendar.id] || this.mCalendars[aCalendar.id] === undefined) {
          this.mCalendars[aCalendar.id] = true;
          this.mStatusBar.value = parseInt(this.mStatusBar.value, 10) + this.mCalendarStep;
          this.mCurIndex++;
          let curStatus = cal.l10n.getCalString("gettingCalendarInfoDetail", [
            this.mCurIndex,
            this.mCalendarCount,
          ]);
          this.showStatusString(curStatus);
        }
      }
      if (this.mThrobber) {
        this.mThrobber.setAttribute("busy", true);
      }
    }
  },
};