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);
aHdrChanged
nsIMsgDBHdr
of the message that changed.aOldFlags
nsMsgMessageFlags
.aNewFlags
nsMsgMessageFlags
.aInstigator
aInstigator
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);
aHdrChanged
nsIMsgDBHdr
of the message that was removed.aParentKey
key
of the parent folder for deleted header. The typedef of nsMsgKey
is given in MailNewsTypes2.idl.aFlags
nsMsgMessageFlags
.aInstigator
aInstigator
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);
aHdrChanged
nsIMsgDBHdr
of the message that was added.aParentKey
key
of the parent folder for new header. The typedef of nsMsgKey
is given in MailNewsTypes2.idl.aFlags
nsMsgMessageFlags
.aInstigator
aInstigator
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);
aKeyChanged
key
of the message that changed. The typedef of nsMsgKey
is given in MailNewsTypes2.idl.oldParent
key
of the old parent folder for the header. The typedef of nsMsgKey
is given in MailNewsTypes2.idl.newParent
key
of the new parent folder for the header. The typedef of nsMsgKey
is given in MailNewsTypes2.idl.aInstigator
aInstigator
may also be null
.Called when an announcer is being deleted.
void onAnnouncerGoingAway(in nsIDBChangeAnnouncer aInstigator);
aInstigator
nsIDBChangeAnnouncer
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);
aInstigator
aInstigator
may also be null
.Called when the junk score of a message has changed.
void onJunkScoreChanged(in nsIDBChangeListener aInstigator);
aInstigator
aInstigator
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);
aHdrToChange
nsIMsgDBHdr
of the message that is changing.aPreChange
aStatus
aInstigator
aInstigator
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);
aDB
nsIMsgDatabase
that is changing.aString