            $Date: 2005/09/28 17:08:07 $
   *                                                           $Author: mikael $
   * Purpose :
   * 
   * An simple class, that allows listners to QuickFind to register.
   *
   *************************************************************************************
   
  Methods on QFClient

  addListener( listener )
    Requires listener to be JS-object, with method callback ( sText ).
    
  addListenerFunc( listenerFunc )
    Adds the function listenerFunc as listener.

  removeListener( listener )
    Requires listener to be JS-object, with method callback ( sText ).
    
  disconnect
    Removes all listeners - regardless if it is an object or a function.
    If functions are used, then this should be used to remove it again.
   
*/

function CQFClient( )
{
  this.listeners = new Array();
}

CQFClient.useDummy = true;

if(NS)
{
  try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  
    CQFClient.prototype.callback   = Components.classes['@idm.fr/QuickFindCallback;1'].
                                     getService(Components.interfaces.nsIQFCallback);

    CQFClient.prototype.callbackJS = CQFClient.prototype.callback.wrappedJSObject;
    
    if( CQFClient.prototype.callbackJS )
    {
      CQFClient.prototype.addListener = function ( listener ) 
      {
        this.listeners.push( listener );
      
        if(listener && listener.callback)
          this.callbackJS.addlistener( listener );
        else
        {
          //alert("QFClient.AddListener called with object, that does not implement method callback");
          throw new Error ( );
        }
      };
      
      CQFClient.prototype.addListenerFunc = function ( listenerFunc )
      {
        var obj = new Object();
        obj.callback = listenerFunc;
        this.addListener ( obj );
      };
      
      CQFClient.prototype.removeListener = function ( listener )
      {
        if(listener && listener.callback)
          this.callbackJS.removelistener( listener );
        else
        {
          //alert("QFClient.RemoveListener called with object, that does not implement method callback");
          throw new Error ( );
        }
      };

      CQFClient.prototype.disconnect = function ( )
      {
        for(var n=0;n<this.listeners.length;n++)
          this.removeListener(this.listeners[n]);
        this.listeners = new Array();
      }
                
      CQFClient.useDummy = false;
    }
    
  } catch ( e ) { }
}

if(CQFClient.useDummy)
{
  CQFClient.prototype.AddListener = function ( listener ) 
  {
    if(!listener || !listener.callback)
    {
      //alert("QFClient.AddListener called with object, that does not implement method callback");
      throw new Error ( );
    }
  };
  
  CQFClient.prototype.addListenerFunc = function ( listenerFunc )
  {
  
  };
  
  CQFClient.prototype.RemoveListener = function ( listener )
  {
    if(!listener || !listener.callback)
    {
      //alert("QFClient.RemoveListener called with object, that does not implement method callback");
      throw new Error ( );
    }
  };
  
  CQFClient.prototype.disconnect = function ( )
  {
  
  };
  
};

var QFClient = new CQFClient( );


kD