/*
 * LICENCE[[
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1/CeCILL 2.O
 *
 * 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 kelis.fr code.
 *
 * The Initial Developer of the Original Code is
 * antoine.pourchez@kelis.fr
 *
 * Portions created by the Initial Developer are Copyright (C) 2005
 * 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"),
 * or the CeCILL Licence Version 2.0 (http://www.cecill.info/licences.en.html),
 * in which case the provisions of the GPL, the LGPL or the CeCILL 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, the LGPL or the CeCILL, 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, the LGPL or the CeCILL. 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, the LGPL or the CeCILL.
 * ]]LICENCE
*/
 
const nsICollection = Components.interfaces.nsICollection;
const nsIConsoleService = Components.interfaces.nsIConsoleService;
const nsISupportsCString = Components.interfaces.nsISupportsCString;
const nsISupportsString = Components.interfaces.nsISupportsString;
const nsIPrefService = Components.interfaces.nsIPrefService;
 
 
const WSPOPTION_CONTRACTID = '@scenari.com/ui/wspOption;1';
const WSPOPTION_CID = Components.ID('{56A6270C-0B0F-4845-91A2-83A73D508102}');
const WSPOPTION_IID = Components.interfaces.scIWspOptionUi;

/* scWspOptionUi */
function scWspOptionUi() {
	this.fUiDom = "";
}

/* Definition du scSession */
scWspOptionUi.prototype = {
  /**
	* Initialisation
	*	@param <element wspPresUrl=""/>
	**/
	init : function(pUiDom) {
		try{
			this.fUiDom = pUiDom;
		}catch(e){
			debug("scWspOptionUi > init :: " + e);
		}
	},
  /**
	* Retourne le titre
	* 	@title
	**/
	getTitle : function() {
		try{
			if(this.fUiDom){
				return this.fUiDom.hasAttribute("title") ? this.fUiDom.getAttribute("title") : this.fUiDom.getAttribute("uri");
			}
			return null;
		}catch(e){
			debug("scWspOptionUi > getTitle :: " + e);
			return null;
		}
	},
  /**
	* Retourne l'URL d'une page XUL correspondant à une présentation de l'atelier
	* 	@wspPresUrl
	**/
	getWspPresUrl : function() {
		try{
			if(this.fUiDom && this.fUiDom.hasAttribute("wspPresUrl")){
				return this.fUiDom.getAttribute("wspPresUrl");
			}
			return null;
		}catch(e){
			debug("scWspOptionUi > getWspPresUrl :: " + e);
			return null;
		}
	},
	QueryInterface: function(pIId) {
        if (!pIId.equals(nsISupports) &&
            !pIId.equals(WSPOPTION_CID))
            throw Components.results.NS_ERROR_NO_INTERFACE;
        return this;
    }
}

/* Fonctions utilitaires */
function debug(pText){
	var vConsoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(nsIConsoleService);
	vConsoleService.logStringMessage(pText);
}
function listProperties (pObj){
	var vRes = "";
	var vProp = null;
	for (vProp in pObj) {
		try {
			vRes += vProp +'(' + pObj[vProp]+ ')'+ "\n";
		} catch(e){
			vRes += vProp +' -> toString in error\n';
		}
	}
	return vRes;
}


/* Module (for XPCOM registration) */
var scWspOptionUiModule = {
    registerSelf: function(compMgr, fileSpec, location, type) {
        compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
        compMgr.registerFactoryLocation(WSPOPTION_CID, 
                                        "scWspOptionUi JS component", 
                                        WSPOPTION_CONTRACTID, 
                                        fileSpec, 
                                        location,
                                        type);
                            	
    },

    getClassObject: function(compMgr, cid, iid) {
        if (!cid.equals(WSPOPTION_CID)) throw Components.results.NS_ERROR_NO_INTERFACE;
        if (!iid.equals(Components.interfaces.nsIFactory)) throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
        return scWspOptionUiFactory;
    },
    unregisterSelf : function mod_unreg(compMgr, location, type) {
  
  	},
    canUnload: function(compMgr) { return true; }
};

/* Class Factory */
var scWspOptionUiFactory = {
    createInstance: function(outer, iid) {
    	try{
	        if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
	        if (!iid.equals(WSPOPTION_IID) && !iid.equals(Components.interfaces.nsISupports))
	            throw Components.results.NS_ERROR_INVALID_ARG;
	      }catch(e){
	      	debug("scWspOptionFactory > createInstance :: " + e);
	      }finally{
	      	return new scWspOptionUi();
	      }
    }
}

/* Module initialisation */
function NSGetModule(comMgr, fileSpec) { return scWspOptionUiModule; }

