/*
 * BEGIN FLOCK GPL
 *
 * Copyright Flock Inc. 2005-2008
 * http://flock.com
 *
 * This file may be used under the terms of the
 * GNU General Public License Version 2 or later (the "GPL"),
 * http://www.gnu.org/licenses/gpl.html
 *
 * 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.
 *
 * END FLOCK GPL
 */

#include "nsISupports.idl"
#include "nsISimpleEnumerator.idl"
#include "nsIStringEnumerator.idl"
#include "nsIDOMWindow.idl"
#include "flockIBlogWebService.idl"


[scriptable, uuid(8425e79d-6b5a-4ee8-af87-5fc5791261a3)]
interface flockIDetectListener: nsISupports {
  void onResult (in flockIBlogAccount api);
  void onError (in AString errorMsg);
};


[scriptable, uuid(62534b85-51a1-443d-b939-1f0a4b37d0bf)]
interface flockIBlogDraft: nsISupports {
  attribute long long id;
  attribute long long lastupdate;
  attribute AString title;
  attribute AString content;
  attribute AString tags;
};


[scriptable, uuid(094a6d1a-357a-466f-a854-484ed125ea03)]
interface flockIBlogService : nsISupports {
  readonly attribute nsISimpleEnumerator services;

  // API Catalog 
  /**
   * For custom blogs only: register a new blog API (ex: MetaWeblog, ATOM)
   * @param aAPI (in) the service providing the API
   * @param aShortname (in) a unique identifier for the API
   * @return nothing
   */
  void registerAPI(in flockICustomBlogWebService aAPI, in ACString aShortname);
  /**
   * For custom blogs only: returns the service identified by aShortname
   */
  flockICustomBlogWebService getAPIFromShortname(in ACString aShortname);
  AString getShortnameFromAPI(in flockICustomBlogWebService aAPI);
  /**
   * For custom blogs only: detect the supported API for a given URL (usually a Blog)
   * and return one accounts for one of the API; the de
   * The list is returned through the
   * listener, see flockIDetectListener for more information
   * @param aAPI (in) the service providing the API
   * @param aShortname (in) a unique identifier for the API
   * @return nothing
   */
  void getCandidatesAPI(in flockIDetectListener aListener, in AString aUrl);

  // Accounts management
  /**
   * Return the number of configured accounts that provide at least one blog
   */
  long accountCount ();
  /**
   * Return the list configured accounts that provide at least one blog
   * @return a nsISimpleEnumerator of flockIBlogAccount
   */
  nsISimpleEnumerator getAccountList ();
  /**
   * Return the list configured accounts that provide at least one blog
   * @param aBlogID (in) the URN of the blog
   * @return a flockIBlogAccount
   */
  flockIBlogAccount getAccount (in AString aBlogID);
  /**
   * Return true if there is already one blog of the given name.
   * It would work fine without having blog title being unique,
   * but as it is the way it is presented to the user we try to
   * keep it unique anyway
   * @param aTitle (in) the title of the blog as displayed to the user
   * @return true if an account of this name exists, false otherwise
   */
  boolean accountExists (in AString aTitle);
  /**
   * Save the account to flock-data, and the password in the password manager
   * @param aAccountID (in) the account to which the blog is attached
   * @param aBlogId (in) the id of the blog, relative to the account
   * @param aBlogAccount (in) 
   */
  void saveAccount (in AString aAccountID, in AString aBlogId, in flockIBlogAccount aBlogAccount);
  /**
   * Get the URN of the default blog (the blog to be preselected when the user
   * tries to publish a post)
   * @return the URN of the default blog 
   */
  AString getDefaultBlog ();
  /**
   * Set the default blog 
   */
  void setDefaultBlog (in AString aBlogID);
  void addCategory (in AString aBlogID, in AString aCategoryId, in AString aCategoryName);
  void flushCategories (in flockIBlogAccount aBlogAccount);

  // Editor
  /**
   * Open a given post in a new blog editor window. If the post is already open,
   * the existing window is focused and no new window is open.
   * @param aId (in) the URN of the post to open
   */
  void openPost(in AString aId);
  /**
   * Open a new blog editor window.
   * @param aTitle (in) the initial value of the title field. If this attribute is the empty string (""), a default is used ("Untitled" for English)
   * @param aContent (in) the initial value of the post content. It can be empty ("").
   * @param aTags (in) the initial value of the tags field. It can be empty but if it is not, tags must be separated by commas.
   */
  nsIDOMWindow openEditor(in AString aTitle, in AString aContent, in AString aTags);
  /**
   * Returns true if at least one blog editor window is open, false otherwise.
   */
  boolean editorIsOpen();

  // Blog drafts
  long long saveDraft(in long long aId, in AString aTitle, in AString aContent, in AString aTags);
  void removeDraft(in long long aId);
  void moveTo(in long long aId, in AString aFolderId);
  nsISimpleEnumerator getDraftsFrom(in AString aFolderId);
  flockIBlogDraft getDraft(in long long aDraftId);

  // Blog recovery
  string saveRecovery(in long long aId, in AString aTitle, in AString aContent, in AString aTags);
  void removeRecovery(in long long aId);
  nsISimpleEnumerator getAllRecovery();

  /**
   * Delete any existing recovery draft
   * @return nothing
   */
  void looseRecovery();

  // Notifications
  void addNotification (in AString aURL);
  void removeNotification (in AString aURL);
  nsIStringEnumerator getNotifications ();
};

