/* ***** 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 the Instantbird messenging client, released
 * 2007.
 *
 * The Initial Developer of the Original Code is
 * Florian QUEZE <florian@instantbird.org>.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either 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 "nsISimpleEnumerator.idl"
#include "purpleIConversation.idl"
#include "purpleIAccountsService.idl"
#include "purpleIProxy.idl"

//forward declarations
interface mozIStorageConnection;

/*
 * This is a proxy to the libpurple core
 */
[ptr] native PurpleNativeBuddy(PurpleBuddy);
[ptr] native purpleNativeProtocol(purpleProtocol);

[scriptable, uuid(b82583f1-307b-4034-b5c7-9f727fab7d8c)]
interface purpleICoreService: purpleIAccountsService {
  void init();
  void quit();
  readonly attribute AUTF8String version;

  // register a conversation. This will create a unique id for the
  // conversation and set it.
  void addConversation(in purpleIConversation aConversation);
  void removeConversation(in purpleIConversation aConversation);

  nsISimpleEnumerator getConversations();
  purpleIConversation getConversationById(in unsigned long aId);

  // returns an enumerator on a purpleIProtocol array
  nsISimpleEnumerator getProtocols();

  purpleIProtocol getProtocolById(in AUTF8String aProtocolId);

  /* Create a new proxy and store it in the preferences */
  purpleIProxy createProxy(in short aType, in AUTF8String aHost, in unsigned long aPort,
                           in AUTF8String aUsername, in AUTF8String aPassword);

  /* returns an enumerator on a purpleIProxy array */
  nsISimpleEnumerator getProxies();

  /* type of the global proxy used for connecting all accounts that
     don't have specific proxy settings.
  */
  attribute purpleIProxyInfo globalProxy;

  /* This attribute is set to AUTOLOGIN_ENABLED by default. It can be set to
     any other value before the initialization of this service to prevent
     accounts with autoLogin enabled from being connected when libpurple is
     initialized.
     Any value other than the ones listed below will disable autoLogin and
     display a generic message in the Account Manager. */
  attribute short autoLoginStatus;

  const short AUTOLOGIN_ENABLED = 0;
  const short AUTOLOGIN_USER_DISABLED = 1;
  const short AUTOLOGIN_SAFE_MODE = 2;
  const short AUTOLOGIN_CRASH = 3;
  const short AUTOLOGIN_START_OFFLINE = 4;

  /* The method should be used to connect all accounts with autoLogin enabled.
     Some use cases:
       - if the autologin was disabled at startup
       - after a loss of internet connectivity that disconnected all accounts.
  */
  void processAutoLogin();

  void notifyObservers(in nsISupports aObj, in string aEvent,
                       [optional] in wstring aData);

  /* buddy related event fired:
      - buddy-added: a new buddy has been added to the buddy list
      - buddy-signed-on: this buddy has just signed on
      - buddy-signed-off: this buddy has just signed off
      - buddy-removed: this buddy has been removed from the buddy list
   */

  // FIXME: this should really go in a purpleStorage service
  readonly attribute mozIStorageConnection storageConnection;

  const short STATUS_UNSET = 0;
  const short STATUS_OFFLINE = 1;
  const short STATUS_MOBILE = 2;
  const short STATUS_INVISIBLE = 3;
  const short STATUS_IDLE = 4;
  const short STATUS_AWAY = 5;
  const short STATUS_UNAVAILABLE = 6;
  const short STATUS_AVAILABLE = 7;

  readonly attribute AUTF8String currentStatusMessage;
  readonly attribute short currentStatusType;

  // Only works with STATUS_OFFLINE, STATUS_UNAVAILABLE, STATUS_AWAY,
  // STATUS_AVAILABLE and STATUS_INVISIBLE.  When called with the
  // status type STATUS_UNSET, only the status message will be
  // changed.  When called with STATUS_OFFLINE, the aMessage parameter
  // is ignored.
  void setStatus(in short aStatus, in AUTF8String aMessage);
};
