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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
* This file is part of TbSync.
*
* 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/.
*/
"use strict";
/**
*
*/
var EventLogInfo = class {
/**
* An EventLogInfo instance is used when adding entries to the
* :ref:`TbSyncEventLog`. The information given here will be added as a
* header to the actual event.
*
* @param {string} provider ``Optional`` A provider ID (also used as
* provider namespace).
* @param {string} accountname ``Optional`` An account name. Can be
* arbitrary but should match the accountID
* (if provided).
* @param {string} accountID ``Optional`` An account ID. Used to filter
* events for a given account.
* @param {string} foldername ``Optional`` A folder name.
*
*/
constructor(provider, accountname = "", accountID = "", foldername = "") {
this._provider = provider;
this._accountname = accountname;
this._accountID = accountID;
this._foldername = foldername;
}
/**
* Getter/Setter for the provider ID of this EventLogInfo.
*/
get provider() {return this._provider};
/**
* Getter/Setter for the account ID of this EventLogInfo.
*/
get accountname() {return this._accountname};
/**
* Getter/Setter for the account name of this EventLogInfo.
*/
get accountID() {return this._accountID};
/**
* Getter/Setter for the folder name of this EventLogInfo.
*/
get foldername() {return this._foldername};
set provider(v) {this._provider = v};
set accountname(v) {this._accountname = v};
set accountID(v) {this._accountID = v};
set foldername(v) {this._foldername = v};
}
/**
* The TbSync event log
*/
var eventlog = {
/**
* Adds an entry to the TbSync event log
*
* @param {StatusDataType} type One of the types defined in
* :class:`StatusData`
* @param {EventLogInfo} eventInfo EventLogInfo for this event.
* @param {string} message The event message.
* @param {string} details ``Optional`` The event details.
*
*/
add: function (type, eventInfo, message, details = null) {
let entry = {
timestamp: Date.now(),
message: message,
type: type,
link: null,
//some details are just true, which is not a useful detail, ignore
details: details === true ? null : details,
provider: "",
accountname: "",
foldername: "",
};
if (eventInfo) {
if (eventInfo.accountID) entry.accountID = eventInfo.accountID;
if (eventInfo.provider) entry.provider = eventInfo.provider;
if (eventInfo.accountname) entry.accountname = eventInfo.accountname;
if (eventInfo.foldername) entry.foldername = eventInfo.foldername;
}
let localized = "";
let link = "";
if (entry.provider) {
localized = TbSync.getString("status." + message, entry.provider);
link = TbSync.getString("helplink." + message, entry.provider);
} else {
//try to get localized string from message from TbSync
localized = TbSync.getString("status." + message);
link = TbSync.getString("helplink." + message);
}
//can we provide a localized version of the event msg?
if (localized != "status."+message) {
entry.message = localized;
}
//is there a help link?
if (link != "helplink." + message) {
entry.link = link;
}
//dump the non-localized message into debug log
TbSync.dump("EventLog", message + (entry.details !== null ? "\n" + entry.details : ""));
this.events.push(entry);
if (this.events.length > 100) this.events.shift();
Services.obs.notifyObservers(null, "tbsync.observer.eventlog.update", null);
},
events: null,
eventLogWindow: null,
load: async function () {
this.clear();
},
unload: async function () {
if (this.eventLogWindow) {
this.eventLogWindow.close();
}
},
get: function (accountID = null) {
if (accountID) {
return this.events.filter(e => e.accountID == accountID);
} else {
return this.events;
}
},
clear: function () {
this.events = [];
},
open: function (accountID = null, folderID = null) {
this.eventLogWindow = TbSync.manager.prefWindowObj.open("chrome://tbsync/content/manager/eventlog/eventlog.xhtml", "TbSyncEventLog", "centerscreen,chrome,resizable");
},
}
|