The nsIDBChangeListener interface is used by components wanting to receive notification when the current database changes somehow.
Here is an example implementation of the listener (that does nothing):
var myListener = {
onHdrFlagsChanged: function(aHdrChanged, aOldFlags, aNewFlags, aInstigator) {},
onHdrDeleted: function(aHdrChanged, aParentKey, aFlags, aInstigator) {},
onHdrAdded: function(aHdrChanged, aParentKey, aFlags, aInstigator) {},
onParentChanged: function(aKeyChanged, oldParent, newParent, aInstigator) {},
onAnnouncerGoingAway: function(aInstigator) {},
onReadChanged: function(aInstigator) {},
onJunkScoreChanged: function(aInstigator) {},
onHdrPropertyChanged: function(aHdrToChange, aPreChange, aStatus, aInstigator) {},
onEvent: function(aDB, aEvent) {},
QueryInterface: function(aIID) {
if (!aIID.equals(Components.interfaces.nsIDBChangeListener) &&
!aIID.equals(Components.interfaces.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};
and to attach it in Thunderbird, we must call AddListener on a nsIDBChangeAnnouncer, typically through a nsIMsgDatabase. There are a couple of ways to access the message database: if you have a nsIMsgFolder, you can do this like so:
someFolder.msgDatabase.AddListener(myListener);
Alternately, you can access the message database through the nsIMsgDbView like so:
gFolderDisplay.view.dbView.db.AddListener(myListener);
void onHdrFlagsChanged(in nsIMsgDBHdr aHdrChanged, in unsigned long aOldFlags, in unsigned long aNewFlags, in nsIDBChangeListener aInstigator); |
void onHdrDeleted(in nsIMsgDBHdr aHdrChanged, in nsMsgKey aParentKey, in long aFlags, in nsIDBChangeListener aInstigator); |
void onHdrAdded(in nsIMsgDBHdr aHdrChanged, in nsMsgKey aParentKey, in long aFlags, in nsIDBChangeListener aInstigator); |
void onParentChanged(in nsMsgKey aKeyChanged, in nsMsgKey oldParent, in nsMsgKey newParent, in nsIDBChangeListener aInstigator); |
void onAnnouncerGoingAway(in nsIDBChangeAnnouncer instigator); |
void onReadChanged(in nsIDBChangeListener aInstigator); |
void onJunkScoreChanged(in nsIDBChangeListener aInstigator); |
void onHdrPropertyChanged(in nsIMsgDBHdr aHdrToChange, in unsigned long aOldFlags, in PRBool aPreChange, inout PRUint32 aStatus, in nsIDBChangeListener aInstigator); |
void onEvent(in nsIMsgDatabase aDB, in string aEvent); |
Called when a message's flags change.
void onHdrFlagsChanged(in nsIMsgDBHdr aHdrChanged,
in unsigned long aOldFlags,
in unsigned long aNewFlags,
in nsIDBChangeListener aInstigator);
aHdrChangednsIMsgDBHdr of the message that changed.aOldFlagsnsMsgMessageFlags.aNewFlagsnsMsgMessageFlags.aInstigatoraInstigator may also be null.Called when a header is deleted from the database.
void onHdrDeleted(in nsIMsgDBHdr aHdrChanged,
in nsMsgKey aParentKey,
in long aFlags,
in nsIDBChangeListener aInstigator);
aHdrChangednsIMsgDBHdr of the message that was removed.aParentKeykey of the parent folder for deleted header. The typedef of nsMsgKey is given in MailNewsTypes2.idl.aFlagsnsMsgMessageFlags.aInstigatoraInstigator may also be null.Called when a header is added to the database.
void onHdrAdded(in nsIMsgDBHdr aHdrChanged,
in nsMsgKey aParentKey,
in long aFlags,
in nsIDBChangeListener aInstigator);
aHdrChangednsIMsgDBHdr of the message that was added.aParentKeykey of the parent folder for new header. The typedef of nsMsgKey is given in MailNewsTypes2.idl.aFlagsnsMsgMessageFlags.aInstigatoraInstigator may also be null.Called when a message's parent is changing (i.e. most likely it is being moved).
void onParentChanged(in nsMsgKey aKeyChanged,
in nsMsgKey oldParent,
in nsMsgKey newParent,
in nsIDBChangeListener aInstigator);
aKeyChangedkey of the message that changed. The typedef of nsMsgKey is given in MailNewsTypes2.idl.oldParentkey of the old parent folder for the header. The typedef of nsMsgKey is given in MailNewsTypes2.idl.newParentkey of the new parent folder for the header. The typedef of nsMsgKey is given in MailNewsTypes2.idl.aInstigatoraInstigator may also be null.Called when an announcer is being deleted.
void onAnnouncerGoingAway(in nsIDBChangeAnnouncer aInstigator);
aInstigatornsIDBChangeAnnouncer that is being removed.Called when the read state of news messages changes. Only used by nsINewsDatabase databases. Others use the onHdrFlagsChanged() method.
void onReadChanged(in nsIDBChangeListener aInstigator);
aInstigatoraInstigator may also be null.Called when the junk score of a message has changed.
void onJunkScoreChanged(in nsIDBChangeListener aInstigator);
aInstigatoraInstigator may also be null.Called in the general case where any field may have changed. OnHdrPropertyChanged is called twice per change. On the first call, aPreChange is true, and aStatus is undefined. OnHdrPropertyChanged saves any required status in aStatus (such as a filter match). The calling function stores the value of aStatus, changes the header aHdrToChange, then calls OnHdrPropertyChanged again with aPreChange false. On this second call, the stored value of aStatus is provided, so that any changes may be noted.
void onHdrPropertyChanged(in nsIMsgDBHdr aHdrToChange,
in PRBool aPreChange,
inout PRUint32 aStatus,
in nsIDBChangeListener aInstigator);
aHdrToChangensIMsgDBHdr of the message that is changing.aPreChangeaStatusaInstigatoraInstigator may also be null.Generic notification for extensibility. Common events should be documented here so we have a hope of keeping the documentation up to date. Current events are:
void onEvent(in nsIMsgDatabase aDB,
in string aEvent);
aDBnsIMsgDatabase that is changing.aString