Logo Search packages:      
Sourcecode: jabber-jit version File versions  Download package

events.h

/*
 * Events
 * ------
 *
 * The library signals everything that happens to the program through
 * calling the signal listeners that have been connected to the Signal
 * dispatchers in Client.
 *
 * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 */

#ifndef EVENTS_H
#define EVENTS_H

#include <time.h>
#include <string>

#include <libicq2000/constants.h>

#include <libicq2000/ContactList.h>

namespace ICQ2000 {

  class Contact;

  // ============================================================================
  //  Event Base class
  // ============================================================================

  /**
   *  The base class for all events.  Basic functionality of all
   *  events is timestamping, so you can tell when an event occurred.
   */
00049   class Event {
   protected:
    /**
     *  the time this event occurred
     */
00054     time_t m_time;

   public:
    Event();
    Event(time_t t);

    time_t getTime() const;
    void setTime(time_t t);
  };

  // ============================================================================
  //  ConnectingEvent
  // ============================================================================

  /**
   *  This event is signalled when the client is connecting to the ICQ network
   */
00071   class ConnectingEvent : public Event {
   public:
    ConnectingEvent();
  };

  // ============================================================================
  //  ConnectedEvent
  // ============================================================================

  /**
   *  This event is signalled when the client is connected properly to
   *  the ICQ network.
   */
00084   class ConnectedEvent : public Event {
   public:
    ConnectedEvent();
  };

  // ============================================================================
  //  DisconnectedEvent
  // ============================================================================

  /**
   *  This event is signalled when the client has been disconnected
   *  from the ICQ network.  This may happen even without having a
   *  ConnectedEvent, if for example you password fails at login and you are disconnected.
   */
00098   class DisconnectedEvent : public Event {
   public:
    /**
     *  enum for Reasons for disconnection
     */
00103     enum Reason {
      REQUESTED,
      FAILED_LOWLEVEL,
      FAILED_BADUSERNAME,
      FAILED_TURBOING,
      FAILED_BADPASSWORD,
      FAILED_MISMATCH_PASSWD,
      FAILED_DUALLOGIN,
      FAILED_UNKNOWN
    };

   private:
    Reason m_reason;

   public:
    DisconnectedEvent(Reason r);

    Reason getReason() const;
  };

  // ============================================================================
  //  LogEvents
  // ============================================================================

  /**
   *  This event is for any logging messages generated by the library.
   */
00130   class LogEvent : public Event {
   public:
    /**
     *  enum of different types of log messages
     */
00135     enum LogType {
      WARN,
      ERROR,
      INFO,
      PACKET,
      DIRECTPACKET
    };

   private:
    LogType m_type;
    std::string m_msg;

   public:
    LogEvent(LogType type, const std::string& msg);

    LogType getType() const;
    std::string getMessage() const;
  };

  // ============================================================================
  //  ContactListEvents (user added, user removed)
  // ============================================================================

  /**
   *  Base class for Contact List related events.
   */
00161   class ContactListEvent : public Event {
   public:
    /**
     *  An enum of the different contact list event types.
     */
00166     enum EventType {
      UserAdded,
      UserRemoved
    };
    
   protected:
    /**
     *  The contact this event refers to.
     */
00175     ContactRef m_contact;

   public:
    ContactListEvent(ContactRef c);
    virtual ~ContactListEvent();
    
    ContactRef getContact() const;
    unsigned int getUIN() const;

    /**
     *  get the type of ContactListEvent
     *
     * @return type of the ContactListEvent
     */
    virtual EventType getType() const = 0;
  };

  /**
   *  The event signalled when a user is added.
   */
00195   class UserAddedEvent : public ContactListEvent {
   public:
    UserAddedEvent(ContactRef c);
    EventType getType() const;
  };

  /**
   *  The event signalled when a user is about to be removed.
   */
00204   class UserRemovedEvent : public ContactListEvent {
   public:
    UserRemovedEvent(ContactRef c);
    EventType getType() const;
  };

  // ============================================================================
  //  ContactEvents (queue changes, status change, user info change)
  // ============================================================================

  /**
   *  Base class for Contact events.
   */
00217   class ContactEvent : public Event {
   public:
    /**
     *  An enum of the different contact list event types.
     */
00222     enum EventType {
      StatusChange,
      UserInfoChange,
    };
    
   protected:
    /**
     *  The contact this event refers to.
     */
00231     ContactRef m_contact;

   public:
    ContactEvent(ContactRef c);
    virtual ~ContactEvent();
    
    ContactRef getContact() const;
    unsigned int getUIN() const;

    /**
     *  get the type of ContactEvent
     *
     * @return type of the ContactEvent
     */
    virtual EventType getType() const = 0;
  };

  /**
   *  The event signalled when user information changes.
   */
00251   class UserInfoChangeEvent : public ContactEvent {
   private:
    bool m_is_transient_detail;
   public:
    UserInfoChangeEvent(ContactRef c, bool is_transient_detail);
    EventType getType() const;
    bool isTransientDetail() const;
  };

  /**
   *  The event signalled when a user's status changes.
   */
00263   class StatusChangeEvent : public ContactEvent {
   private:
    Status m_status;
    Status m_old_status;
    
   public:
    StatusChangeEvent(ContactRef contact, Status status, Status old_status);

    EventType getType() const;
    Status getStatus() const;
    Status getOldStatus() const;
  };

  // ============================================================================
  //  MessageEvents
  // ============================================================================

  /**
   *  A message event.  MessageEvents are used for messages, URLs,
   *  SMSs, Authorisation request/responses and away messages.
   */
00284   class MessageEvent : public Event {
   public:
    /**
     *  enum of the type of the message
     */
00289     enum MessageType {
      Normal,
      URL,
      SMS,
      SMS_Receipt,
      AuthReq,
      AuthAck,
      AwayMessage,
      EmailEx,
      UserAdd,
      Email,
      WebPager
    };

    enum DeliveryFailureReason {
      Failed,                  // general failure
      Failed_NotConnected,     // you are not connected!
      Failed_ClientNotCapable, // remote client is not capable (away messages)
      Failed_Denied,           // denied outright
      Failed_Ignored,          // ignore completely - send no ACKs back either
      Failed_Occupied,         // resend as to contactlist/urgent
      Failed_DND,              // resend as to contactlist/urgent
      Failed_SMTP
    };

   protected:
    /// the contact related to the MessageEvent
00316     ContactRef m_contact; 
    /// whether the event is finished    
00318     bool m_finished;
    /// whether the event was delivered
00320     bool m_delivered;
    /// whether the event was sent direct
00322     bool m_direct;

    DeliveryFailureReason m_failure_reason;

   public:
    MessageEvent(ContactRef c);
    virtual ~MessageEvent();

    /**
     *  get the type of the MessageEvent
     *
     * @return the type of the message
     */
    virtual MessageType getType() const = 0;
    ContactRef getContact();
    
    bool isFinished()  const;
    bool isDelivered() const;
    bool isDirect()    const;
    
    void setFinished(bool f);
    void setDelivered(bool f);
    void setDirect(bool f);

    DeliveryFailureReason getDeliveryFailureReason() const;
    void setDeliveryFailureReason(DeliveryFailureReason d);
  };

  /**
   *  Base class for ICQ messages (not SMS)
   */
00353   class ICQMessageEvent : public MessageEvent {
   private:
    bool m_urgent, m_tocontactlist, m_offline;
    std::string m_away_message;
    
   public:
    ICQMessageEvent(ContactRef c);
    
    bool isUrgent() const;
    void setUrgent(bool b);
    bool isToContactList() const;
    void setToContactList(bool b);
    bool isOfflineMessage() const;
    void setOfflineMessage(bool b);
    unsigned int getSenderUIN() const;
    std::string getAwayMessage() const;
    void setAwayMessage(const std::string& msg);

    virtual ICQMessageEvent* copy() const = 0;
  };

  /**
   *  A normal message
   */
00377   class NormalMessageEvent : public ICQMessageEvent {
   private:
    std::string m_message;
    bool m_multi;
    unsigned int m_foreground, m_background;
    
   public:
    NormalMessageEvent(ContactRef c, const std::string& msg, bool multi = false);
    NormalMessageEvent(ContactRef c, const std::string& msg, time_t t, bool multi);
    NormalMessageEvent(ContactRef c, const std::string& msg, unsigned int fg, unsigned int bg);

    std::string getMessage() const;
    MessageType getType() const;
    bool isMultiParty() const;
    unsigned int getForeground() const;
    unsigned int getBackground() const;
    void setForeground(unsigned int f);
    void setBackground(unsigned int b);

    ICQMessageEvent* copy() const;
  };
  
  /**
   *  An URL message
   */
00402   class URLMessageEvent : public ICQMessageEvent {
   private:
    std::string m_message, m_url;
    
   public:
    URLMessageEvent(ContactRef c, const std::string& msg, const std::string& url);
    URLMessageEvent(ContactRef c, const std::string& msg, const std::string& url, time_t t);

    std::string getMessage() const;
    std::string getURL() const;
    MessageType getType() const;

    ICQMessageEvent* copy() const;
  };
  
  /**
   *  An SMS message
   */
00420   class SMSMessageEvent : public MessageEvent {
   private:
    std::string m_message, m_source, m_sender, m_senders_network;
    std::string m_smtp_from, m_smtp_to, m_smtp_subject;
    bool m_rcpt;

   public:
    SMSMessageEvent(ContactRef c, const std::string& msg, bool rcpt);
    SMSMessageEvent(ContactRef c, const std::string& msg, const std::string& source,
                const std::string& senders_network, const std::string& time);

    std::string getMessage() const;
    MessageType getType() const;
    std::string getSource() const;
    std::string getSender() const;
    std::string getSenders_network() const;
    bool getRcpt() const;

    void setSMTPFrom(const std::string& from);
    std::string getSMTPFrom() const;

    void setSMTPTo(const std::string& to);
    std::string getSMTPTo() const;

    void setSMTPSubject(const std::string& subj);
    std::string getSMTPSubject() const;
  };

  /**
   *  An SMS (delivery) receipt
   */
00451   class SMSReceiptEvent : public MessageEvent {
   private:
    std::string m_message, m_message_id, m_destination, m_submission_time, m_delivery_time;
00454     bool m_delivered;
    
   public:
    SMSReceiptEvent(ContactRef c, const std::string& msg, const std::string& message_id,
                const std::string& submission_time, const std::string& delivery_time, bool del);
    
    MessageType getType() const;
    std::string getMessage() const;
    std::string getMessageId() const;
    std::string getDestination() const;
    std::string getSubmissionTime() const;
    std::string getDeliveryTime() const;
    bool delivered() const;
  };

  /**
   *  An Away message. The way away messages work in ICQ is they are
   *  just sending a special blank message to the other end, and the
   *  away message comes back in the ACK, as it would for other
   *  messages when sent to someone who is away (N/A, etc..).
   *  
   */
00476   class AwayMessageEvent : public ICQMessageEvent {
   public:
    AwayMessageEvent(ContactRef c);

    MessageType getType() const;

    ICQMessageEvent* copy() const;
  };

  /**
   *  An Authorisation Request
   */
00488   class AuthReqEvent : public ICQMessageEvent {
   private:
    std::string m_message;

   public:
    AuthReqEvent(ContactRef c, const std::string& msg);
    AuthReqEvent(ContactRef c, const std::string& msg, time_t time);

    std::string getMessage() const;
    MessageType getType() const;

    ICQMessageEvent* copy() const;
  };
  
  /**
   *  An Authorisation Acknowledge (success/failure)
   */
00505   class AuthAckEvent : public ICQMessageEvent {
   private:
    std::string m_message;
    bool m_granted;

   public:
    AuthAckEvent(ContactRef c, bool granted);
    AuthAckEvent(ContactRef c, bool granted, time_t time);
    AuthAckEvent(ContactRef c, const std::string& msg, bool granted);
    AuthAckEvent(ContactRef c, const std::string& msg, bool granted, time_t time);

    std::string getMessage() const;
    MessageType getType() const;
    bool isGranted() const;

    ICQMessageEvent* copy() const;
  };

  /**
   *  An E-mail Express message
   */
00526   class EmailExEvent : public MessageEvent {
   private:
    std::string m_sender, m_email, m_message;

   public:
    EmailExEvent(ContactRef c, const std::string &email, const std::string &sender, const std::string &msg);

    std::string getMessage() const;
    std::string getEmail() const;
    std::string getSender() const;

    MessageType getType() const;
    unsigned int getSenderUIN() const;
  };

  /**
   *  A Web Pager message
   */
00544   class WebPagerEvent : public MessageEvent {
   private:
    std::string m_sender, m_email, m_message;

   public:
    WebPagerEvent(ContactRef c, const std::string& email, const std::string& sender, const std::string& msg);

    std::string getMessage() const;
    std::string getEmail() const;
    std::string getSender() const;

    MessageType getType() const;
  };

  /**
   *  A "You were added" message
   */
00561   class UserAddEvent : public ICQMessageEvent {
   public:
    UserAddEvent(ContactRef c);

    MessageType getType() const;
    unsigned int getSenderUIN() const;

    ICQMessageEvent* copy() const;
  };

  /**
   *  An E-mail message, sent with SMTP
   */
00574   class EmailMessageEvent : public MessageEvent {
   private:
    std::string m_message;

   public:
    EmailMessageEvent(ContactRef c, const std::string &msg);

    std::string getMessage() const;

    MessageType getType() const;
  };

  // ============================================================================
  //  Search Events
  // ============================================================================

  /**
   *  The event signalled when a user-search result is received.
   */
00593   class SearchResultEvent : public Event {
   public:
    enum SearchType {
      ShortWhitepage,
      FullWhitepage,
      UIN,
      Keyword
    };
      
   private:
    bool m_finished, m_expired;
    SearchType m_searchtype;
    ContactList m_clist;
    ContactRef m_last_contact;
    unsigned int m_more_results;
    
   public:
    SearchResultEvent(SearchType t);

    SearchType getSearchType() const;
    ContactList& getContactList();
    ContactRef getLastContactAdded() const;
    void setLastContactAdded(ContactRef c);
    unsigned int getNumberMoreResults() const;

    bool isFinished() const;
    void setFinished(bool b);
    bool isExpired() const;
    void setExpired(bool b);
    void setNumberMoreResults(unsigned int m);
  };

  /**
   *  The event signalled when entries from the server-based contact list is received.
   */
00628   class ServerBasedContactEvent : public Event {
   private:
    ContactList m_clist;
   public:
    ServerBasedContactEvent(const ContactList& l);
    ContactList& getContactList();
  };

  // ============================================================================
  //  NewUINEvent
  // ============================================================================

  /**
   *  Registration of a new UIN
   */
00643   class NewUINEvent : public Event {
   private:
    unsigned int m_uin;
    bool m_success;       

   public:
    NewUINEvent(unsigned int uin, bool success=true);
    unsigned int getUIN() const;
    bool isSuccess() const;
  };

  /**
   *  Rate Information Changed
   */
00657   class RateInfoChangeEvent : public Event {
   public:
    /**
     * enum of the rate classes
     */
00662     enum RateClass {
      RATE_CHANGE=1,
      RATE_WARNING,
      RATE_LIMIT,
      RATE_LIMIT_CLEARED
    };
    
   private:
    unsigned short m_code;    
    unsigned short m_rateclass;     
    unsigned int m_windowsize;
    unsigned int m_clear;
    unsigned int m_alert;
    unsigned int m_limit;
    unsigned int m_disconnect;
    unsigned int m_currentavg;
    unsigned int m_maxavg;

   public:
    RateInfoChangeEvent(unsigned short code, unsigned short rateclass, 
                        unsigned int windowsize,unsigned int clear,
                        unsigned int alert,unsigned int limit,
                        unsigned int disconnect,unsigned int currentavg,
                        unsigned int maxavg);
    
    /// get the code
00688     unsigned short getCode() const { return m_code; } 
    /// get the rate class
00690     unsigned short getRateClass() const { return m_rateclass; }   
    /// get the size of the window
00692     unsigned int getWindowSize() const { return m_windowsize; }
    /// get clear (?)
00694     unsigned int getClear() const { return m_clear; }
    /// get alert (?)
00696     unsigned int getAlert() const { return m_alert; }
    /// get the limit
00698     unsigned int getLimit() const { return m_limit; }
    /// get disconnect (?)
00700     unsigned int getDisconnect() const { return m_disconnect; }
    /// get the current average
00702     unsigned int getCurrentAvg() const { return m_currentavg; }
    /// get the maximum average
00704     unsigned int getMaxAvg() const { return m_maxavg; }
  };

} 

#endif

Generated by  Doxygen 1.6.0   Back to index