/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1999
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"
#include "MailNewsTypes2.idl"

interface nsIDBChangeAnnouncer;
interface nsIMsgDBHdr;
interface nsIMsgDatabase;

/**
 * These callbacks are provided to allow listeners to the message database
 * to update their status when changes occur.
 */
[scriptable, uuid(21c56d34-71b9-42bb-9606-331a6a5f8210)]

interface  nsIDBChangeListener : nsISupports {
  /**
   * Callback when message flags are changed.
   *
   * @param aHdrChanged The changed header.
   * @param aOldFlags   Message flags prior to change.
   * @param aNewFlags   Message flags after change.
   * @param aInstigator Object that initiated the change.
   */
  void onHdrFlagsChanged(in nsIMsgDBHdr aHdrChanged, in unsigned long aOldFlags,
                   in unsigned long aNewFlags, in nsIDBChangeListener aInstigator);

  /**
   * Callback when message is marked as deleted.
   *
   * @param aHdrChanged The message header that is going to be deleted.
   * @param aParentKey  Key of parent.
   * @param aFlags      Flags that message has before delete.
   * @param aInstigator Object that initiated the change. Can be null.
   */
  void onHdrDeleted(in nsIMsgDBHdr aHdrChanged, in nsMsgKey aParentKey, in long aFlags,
                    in nsIDBChangeListener aInstigator);

  /**
   * Callback when message is added.
   *
   * @param aHdrChanged The message header that is added.
   * @param aParentKey  Parent key of message.
   * @param aFlags      Flags that new message will have.
   * @param aInstigator Object that initiated the change. Can be null.
   */
  void onHdrAdded(in nsIMsgDBHdr aHdrChanged, in nsMsgKey aParentKey, in long aFlags,
                  in nsIDBChangeListener aInstigator);

  /**
   * Callback when message parrent is changed. Parent is changed when message is deleted or moved.
   *
   * @param aKeyChanged The message key that parent key was changed.
   * @param oldParent   Old parent key.
   * @param newParent   New parent key.
   * @param aInstigator Object that initiated the change. Can be null.
   */
  void onParentChanged(in nsMsgKey aKeyChanged, in nsMsgKey oldParent, in nsMsgKey newParent,
                       in nsIDBChangeListener aInstigator);

  /**
   * Callback when announcer is going away. This is good place to release strong pointers to announcer.
   *
   * @param instigator Object that initiated the change. Can be null.
   */
  void onAnnouncerGoingAway(in nsIDBChangeAnnouncer instigator);

  /**
   * Callback when read flag is changed.
   *
   * @param aInstigator Object that initiated the change. Can be null.
   */
  void onReadChanged(in nsIDBChangeListener aInstigator);

  /**
   * Callback used in case when "junkscore" property is changed.
   *
   * @param aInstigator Object that initiated the change. Can be null.
   */
  void onJunkScoreChanged(in nsIDBChangeListener aInstigator);

  /**
   * Callback used 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.
   *
   * @param aHdrToChange the message header that is changing.
   * @param aPreChange   true on first call before change, false on second call after change
   * @param aStatus      storage location provided by calling routine for status
   * @param aInstigator  object that initiated the change
   */   
  void onHdrPropertyChanged(in nsIMsgDBHdr aHdrToChange, in PRBool aPreChange, inout PRUint32 aStatus,
                       in nsIDBChangeListener aInstigator);

  /**
   * 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:
   * "DBOpened" - When a pending listener becomes real. This can happen when
   *              the existing db is force closed and a new one opened. Only
   *              registered pending listeners are notified.
   *
   * @param aDB      the db for this event.
   * @param aEvent   type of event. 
   *
   */
  void onEvent(in nsIMsgDatabase aDB, in string aEvent);
};

