/*
 * BEGIN FLOCK GPL
 *
 * Copyright Flock Inc. 2005-2009
 * 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 "nsIRDFDataSource.idl"
#include "nsIRDFRemoteDataSource.idl"
#include "nsIDOMNode.idl"
#include "nsISimpleEnumerator.idl"
#include "nsIDOMDocument.idl"
#include "flockIError.idl"
#include "flockIPoller.idl"
#include "nsIWritablePropertyBag2.idl"


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

interface flockIMediaWebService;
interface flockIMediaItem;

[scriptable, uuid(416b0153-2376-4389-a199-a8a8f9069d4a)]
interface flockIPhotoUpload: nsISupports
{
  attribute string id;
  attribute AString fileName;
  attribute string originalFileSpec;
  attribute string originalFilePath;
  attribute string workingFilePath;
  attribute string workingFileSpec;
  attribute string previewFileSpec;
  attribute string previewFilePath;
  attribute string thumbFileSpec;
  attribute string thumbFilePath;
  attribute string mimetype;

  attribute AString title;
  attribute AString tags;
  attribute AString notes;
  attribute AString description;
  attribute AString privacy_use_batch;
  attribute string is_public;
  attribute string is_friend;
  attribute string is_family;

  attribute AString album;
  attribute string state;
  /*
   * states:
   *         (blank)
   *         uploading
   *         pending
   */
  attribute string rotation;
  attribute string crop;
};

/**
 * An observer to be set on the flockPhotoUploadService, an be notified
 * of upload-related events.
 *
 * @see flockIPhotoUploadService#addObserver
 * @see flockIPhotoUploadService#removeObserver
 */
[scriptable, uuid(0524f570-ec8d-4463-b828-bb611c9705ba)]
interface flockIUploadObserver: nsISupports
{
  /**
   * Called each time we receive progress information from the server.
   *
   * @param aCurrentProgress (in) the progress for the current photo.
   */
  void onUploadProgress(in PRUint32 aCurrentProgress);

  /**
   * Called right before the actual upload of a photo starts.
   *
   * @param aUpload (in) the photo being uploaded (metadata sent to the server)
   * @param aCount (in) how many photos have been uploaded in this batch (including this one)
   * @param aMax (in) the total number of photos in this batch
   */
  void onUploadStart(in flockIPhotoUpload aUpload, in long aCount, in long aMax);

  /**
   * Called after a photo has been successfully uploaded. Note that the metadata
   * may not be completely set; onUploadFinalized will be called at that time.
   *
   * @param aUpload (in) the photo successfully uploaded
   *    (metadata sent to the server)
   * @param aCount (in) how many photos have been uploaded in this batch (including this one)
   * @param aMax (in) the total number of photos in this batch
   */
  void onUpload(in flockIPhotoUpload aUpload, in long aCount, in long aMax);

  /**
   * Called when an error is caught during upload of a photo
   *
   * @param aUpload (in) the photo being uploaded when the error happened
   * @param aCount (in) how many photos have been uploaded in this batch (including this one)
   * @param aMax (in) the total number of photos in this batch
   * @param aError (in) the error returned
   */
  void onUploadError(in flockIPhotoUpload aUpload, in long aCount, in long aMax, in flockIError aError);

  /**
   * Called when the current batch operation is finished. The end of the process
   * may be due to a success, an error or the operation being cancelled by the
   * user.
   */
  void onUploadComplete();

  /**
   * Called after a photo is finalized. Finalized means that not only the photo
   * is uploaded, but the metadata has been set. For example, for Flickr the
   * album is set at that stage.
   *
   * @param aUpload (in) the metadata sent to the server
   * @param aMediaItem (in) the item newly created on the server,
   *    including the URL on the server, id as recognized by the server...
   */
  void onUploadFinalized(in flockIPhotoUpload aUpload,
                         in flockIMediaItem aMediaItem);

  /**
   * Called when a photo already imported is added to the upload queue.
   * This includes reorder (a reorder is a "remove" then an "add").
   * This method is called with aUpload == null before the photo is added,
   * then with aUpload != null after the photo is added.
   *
   * @param aUpload (in) the newly added photo upload (or null)
   */
  void onUploadAdd(in flockIPhotoUpload aUpload);

  /**
   * Called when a photo is removed from the upload queue.
   * This includes reorder (a reorder is a "remove" then an "add").
   */
  void onUploadRemove();

  /**
   * Called when an error happen when importing a photo from the disk to the
   * upload queue; for example, the photo file was corrupted and couldn't be
   * read.
   *
   * @param aFilename (in) the filename that caused an error at import
   */
  void onMediaImportError(in AString aFilename);

  void onError(in flockIError aError);

  /**
   * Called at the beginning of the process of importing a photo
   * from the disk to the upload queue.
   *
   * @param filename (in) the filename of the image file to import.
   * @param aNumInBatch (in) the number of the current photo in the import batch
   */
  void onMediaImportStart(in AString filename, in long aNumInBatch);

  /**
   * Called after a photo has been successfully imported
   * from the disk to the upload queue.
   *
   * @param aPhotoUpload (in) the metadata of the photo in the queue.
   * @param aCount (in) the number photos already imported in the current batch
   *    (including this one)
   */
  void onMediaImportFinish(in flockIPhotoUpload aPhotoUpload, in long aCount);

  /**
   * Called at the beginning of the process of importing a batch of photos
   * from the disk to the upload queue.
   *
   * @param aBatchSize (in) the number photos in the batch.
   */
  void onMediaBatchImportStart(in long aBatchSize);

  /**
   * Called at the end of the process of importing a batch of photos
   * from the disk to the upload queue.
   */
  void onMediaBatchImportFinish();
};

/**
 * A listener to use as callback about the upload of one photo.
 *
 * @see flockIMediaUploadWebService#upload
 * @see flockIFacebookAPI#uploadPhotosViaUploader
 */
[scriptable, uuid(2a470693-5a07-4a7a-bca9-3bf7b6841348)]
interface flockIPhotoUploadAPIListener: nsISupports
{
  void onProgress(in PRUint32 aCurrentProgress);
  void onUploadComplete(in flockIPhotoUpload aUpload);
  void onUploadFinalized(in flockIPhotoUpload aUpload,
                         in flockIMediaItem aMediaItem);
  void onError(in flockIError aError);
};

[scriptable, uuid(17f76f3c-57bd-4ba6-9c9c-a906c499c791)]
interface flockIPhotoUploadService: nsISupports
{
  boolean hasOnePhotoAccount();
  string getDefaultService();
  void setDefaultService(in string aServiceId);
  void promptForAccount();
  void launchUploader();

  void importSingleMediaItem(in flockIUploadObserver aUploadObserver,
                             in AString aFileName);
  void addMediaToImportQueue(in AString aUrl);
  void startImportQueue();
  void cancelImport();

  void upload(in flockIMediaWebService aAPI);
  void singleUpload(in flockIPhotoUploadAPIListener aUploadListener,
                    in flockIMediaWebService aAPI,
                    in flockIPhotoUpload aUpload);

  void cancelUpload();

  void addPhotoUpload(in flockIPhotoUpload aReference, in flockIPhotoUpload aUpload);
  void savePhotoUpload(in flockIPhotoUpload aUpload);
  void removePhotoUpload(in string aUploadId);
  flockIPhotoUpload getPhotoUpload(in AString aURI);
  void addObserver(in flockIUploadObserver aUploadObserver);
  void removeObserver(in flockIUploadObserver aUploadObserver);
  void cropPhotoUpload(in flockIPhotoUpload aUpload, in double aX1, in double aY1, in double aX2, in double aY2);
  void revertPhotoUpload(in flockIPhotoUpload aUpload);
  void rotatePhotoUpload(in flockIPhotoUpload aUpload, in PRInt32 aDegrees);
  void cleanPhotoUploadCache();

  readonly attribute boolean isUploading;
  readonly attribute boolean isImporting;
};
