Inherit from calStorageCalendar
"john.bieling--- via dev-apps-calendar" <[email protected]> Wed, 26 Apr 2017 11:40:44 -0700 (PDT)
| Newsgroups | gmane.comp.mozilla.devel.calendar |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I am developing an AddOn, that creates calendars using:
let newCalendar = calManager.createCalendar("storage", cal.makeURL('moz-storage-calendar://'));
These calendars depend on external sources, at the moment they are only updated during load. I also would like to trigger an update, if the user clicks on the big lightning synchronize button.
If I understood correctly, I have to create a custom provider which returns true for canRefresh and implements refresh().
I have three questions:
1. How do I generate a unique ID for my provider, can I just pick one?
2. How do I inherit my custom provider from calStorageCalendar? I do not want to implement all the methods by myself, I want to use everything from the default StorageCalender. So if something changes in future versions of Thunderbird, I do not have to catch up.
3. Do I have to choose a different URL schema, or can I use "moz-storage-calendar://" as well?
This is what I use at the moment in my Manifest:
component {B99A6D64-2C89-11DC-9698-529656D89593} components/calMyCustomProvider.js
contract @mozilla.org/calendar/calendar;1?type=mycustomprovider {B99A6D64-2C89-11DC-9698-529656D89593}
And this is calMyCustomProvider.js:
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://calendar/modules/calUtils.jsm");
function calMyCustomProvider() {
this.initProviderBase();
}
calMyCustomProvider.prototype = {
__proto__: cal.ProviderBase.prototype,
classDescription: "My Custom Calendar Provider",
contractID: "@mozilla.org/calendar/calendar;1?type=mycustomprovider",
classID: Components.ID("{B99A6D64-2C89-11DC-9698-529656D89593}"),
QueryInterface: function cTBS_QueryInterface(aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.calICalendar)) {
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
},
get type() {
return "mycustomprovider";
},
get canRefresh() {
return true;
},
refresh: function cTBS_refresh() {
// DO SOMETHING HERE
// tell observers to reload everything
this.mObservers.notify("onLoad", [this]);
}
};
However, creating a calendar with:
let newCalendar = calManager.createCalendar("mycustomprovider", cal.makeURL('moz-storage-calendar://'));
gives a fatal error on calendar creation. Any hint on what I am doing wrong would be great.
Thanks,
John