summaryrefslogtreecommitdiffstats
path: root/comm/calendar/base/src/CalFreeBusyService.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/calendar/base/src/CalFreeBusyService.jsm
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/calendar/base/src/CalFreeBusyService.jsm')
-rw-r--r--comm/calendar/base/src/CalFreeBusyService.jsm89
1 files changed, 89 insertions, 0 deletions
diff --git a/comm/calendar/base/src/CalFreeBusyService.jsm b/comm/calendar/base/src/CalFreeBusyService.jsm
new file mode 100644
index 0000000000..822f37acda
--- /dev/null
+++ b/comm/calendar/base/src/CalFreeBusyService.jsm
@@ -0,0 +1,89 @@
+/* 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 EXPORTED_SYMBOLS = ["CalFreeBusyService"];
+
+var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
+
+function CalFreeBusyListener(numOperations, finalListener) {
+ this.mFinalListener = finalListener;
+ this.mNumOperations = numOperations;
+
+ this.opGroup = new cal.data.OperationGroup(() => {
+ this.notifyResult(null);
+ });
+}
+CalFreeBusyListener.prototype = {
+ QueryInterface: ChromeUtils.generateQI(["calIGenericOperationListener"]),
+
+ mFinalListener: null,
+ mNumOperations: 0,
+ opGroup: null,
+
+ notifyResult(result) {
+ let listener = this.mFinalListener;
+ if (listener) {
+ if (!this.opGroup.isPending) {
+ this.mFinalListener = null;
+ }
+ listener.onResult(this.opGroup, result);
+ }
+ },
+
+ // calIGenericOperationListener:
+ onResult(aOperation, aResult) {
+ if (this.mFinalListener) {
+ if (!aOperation || !aOperation.isPending) {
+ --this.mNumOperations;
+ if (this.mNumOperations <= 0) {
+ this.opGroup.notifyCompleted();
+ }
+ }
+ let opStatus = aOperation ? aOperation.status : Cr.NS_OK;
+ if (Components.isSuccessCode(opStatus) && aResult && Array.isArray(aResult)) {
+ this.notifyResult(aResult);
+ } else {
+ this.notifyResult([]);
+ }
+ }
+ },
+};
+
+function CalFreeBusyService() {
+ this.wrappedJSObject = this;
+ this.mProviders = new Set();
+}
+CalFreeBusyService.prototype = {
+ QueryInterface: ChromeUtils.generateQI(["calIFreeBusyProvider", "calIFreeBusyService"]),
+ classID: Components.ID("{29c56cd5-d36e-453a-acde-0083bd4fe6d3}"),
+
+ mProviders: null,
+
+ // calIFreeBusyProvider:
+ getFreeBusyIntervals(aCalId, aRangeStart, aRangeEnd, aBusyTypes, aListener) {
+ let groupListener = new CalFreeBusyListener(this.mProviders.size, aListener);
+ if (this.mProviders.size == 0) {
+ groupListener.onResult(null, []);
+ }
+ for (let provider of this.mProviders.values()) {
+ let operation = provider.getFreeBusyIntervals(
+ aCalId,
+ aRangeStart,
+ aRangeEnd,
+ aBusyTypes,
+ groupListener
+ );
+ groupListener.opGroup.add(operation);
+ }
+ return groupListener.opGroup;
+ },
+
+ // calIFreeBusyService:
+ addProvider(aProvider) {
+ this.mProviders.add(aProvider.QueryInterface(Ci.calIFreeBusyProvider));
+ },
+ removeProvider(aProvider) {
+ this.mProviders.delete(aProvider.QueryInterface(Ci.calIFreeBusyProvider));
+ },
+};