Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

events.h

00001 /*
00002  * Events
00003  * ------
00004  *
00005  * The library signals everything that happens to the program through
00006  * calling the signal listeners that have been connected to the Signal
00007  * dispatchers in Client.
00008  *
00009  * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2.1 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00024  *
00025  */
00026 
00027 #ifndef EVENTS_H
00028 #define EVENTS_H
00029 
00030 #include <time.h>
00031 #include <string>
00032 
00033 #include <libicq2000/constants.h>
00034 
00035 #include <libicq2000/ContactList.h>
00036 
00037 using std::string;
00038 
00039 namespace ICQ2000 {
00040 
00041   class Contact;
00042 
00043   // ============================================================================
00044   //  Event Base class
00045   // ============================================================================
00046 
00051   class Event {
00052    protected:
00056     time_t m_time;
00057 
00058    public:
00059     Event();
00060     Event(time_t t);
00061 
00062     time_t getTime() const;
00063     void setTime(time_t t);
00064   };
00065 
00066   // ============================================================================
00067   //  SocketEvents
00068   // ============================================================================
00069 
00073   class SocketEvent : public Event {
00074    private:
00075     int m_fd;
00076 
00077    public:
00078     SocketEvent(int fd);
00079     virtual ~SocketEvent();
00080 
00081     int getSocketHandle() const;
00082 
00086     enum Mode {
00087       READ      = 1 << 0,
00088       WRITE     = 1 << 1,
00089       EXCEPTION = 1 << 2
00090     };
00091   };
00092 
00098   class AddSocketHandleEvent : public SocketEvent {
00099    private:
00100     Mode m_mode;
00101 
00102    public:
00103     AddSocketHandleEvent(int fd, Mode m);
00104     
00105     Mode getMode() const;
00106     bool isRead() const;
00107     bool isWrite() const;
00108     bool isException() const;
00109   };
00110 
00116   class RemoveSocketHandleEvent : public SocketEvent {
00117    public:
00118     RemoveSocketHandleEvent(int fd);
00119   };
00120 
00121   // ============================================================================
00122   //  ConnectedEvent
00123   // ============================================================================
00124 
00129   class ConnectedEvent : public Event {
00130    public:
00131     ConnectedEvent();
00132   };
00133 
00134   // ============================================================================
00135   //  DisconnectedEvent
00136   // ============================================================================
00137 
00143   class DisconnectedEvent : public Event {
00144    public:
00148     enum Reason {
00149       REQUESTED,
00150       FAILED_LOWLEVEL,
00151       FAILED_BADUSERNAME,
00152       FAILED_TURBOING,
00153       FAILED_BADPASSWORD,
00154       FAILED_MISMATCH_PASSWD,
00155       FAILED_DUALLOGIN,
00156       FAILED_UNKNOWN
00157     };
00158 
00159    private:
00160     Reason m_reason;
00161 
00162    public:
00163     DisconnectedEvent(Reason r);
00164 
00165     Reason getReason() const;
00166   };
00167 
00168   // ============================================================================
00169   //  LogEvents
00170   // ============================================================================
00171 
00175   class LogEvent : public Event {
00176    public:
00180     enum LogType {
00181       WARN,
00182       ERROR,
00183       INFO,
00184       PACKET,
00185       DIRECTPACKET
00186     };
00187 
00188    private:
00189     LogType m_type;
00190     string m_msg;
00191 
00192    public:
00193     LogEvent(LogType type, const string& msg);
00194 
00195     LogType getType() const;
00196     string getMessage() const;
00197   };
00198 
00199   // ============================================================================
00200   //  ContactListEvents (user added, user removed)
00201   // ============================================================================
00202 
00206   class ContactListEvent : public Event {
00207    public:
00211     enum EventType {
00212       UserAdded,
00213       UserRemoved
00214     };
00215     
00216    protected:
00220     ContactRef m_contact;
00221 
00222    public:
00223     ContactListEvent(ContactRef c);
00224     virtual ~ContactListEvent();
00225     
00226     ContactRef getContact() const;
00227     unsigned int getUIN() const;
00228 
00234     virtual EventType getType() const = 0;
00235   };
00236 
00240   class UserAddedEvent : public ContactListEvent {
00241    public:
00242     UserAddedEvent(ContactRef c);
00243     EventType getType() const;
00244   };
00245 
00249   class UserRemovedEvent : public ContactListEvent {
00250    public:
00251     UserRemovedEvent(ContactRef c);
00252     EventType getType() const;
00253   };
00254 
00255   // ============================================================================
00256   //  ContactEvents (queue changes, status change, user info change)
00257   // ============================================================================
00258 
00262   class ContactEvent : public Event {
00263    public:
00267     enum EventType {
00268       StatusChange,
00269       UserInfoChange,
00270     };
00271     
00272    protected:
00276     ContactRef m_contact;
00277 
00278    public:
00279     ContactEvent(ContactRef c);
00280     virtual ~ContactEvent();
00281     
00282     ContactRef getContact() const;
00283     unsigned int getUIN() const;
00284 
00290     virtual EventType getType() const = 0;
00291   };
00292 
00296   class UserInfoChangeEvent : public ContactEvent {
00297    private:
00298     bool m_is_transient_detail;
00299    public:
00300     UserInfoChangeEvent(ContactRef c, bool is_transient_detail);
00301     EventType getType() const;
00302     bool isTransientDetail() const;
00303   };
00304 
00308   class StatusChangeEvent : public ContactEvent {
00309    private:
00310     Status m_status;
00311     Status m_old_status;
00312     
00313    public:
00314     StatusChangeEvent(ContactRef contact, Status status, Status old_status);
00315 
00316     EventType getType() const;
00317     Status getStatus() const;
00318     Status getOldStatus() const;
00319   };
00320 
00321   // ============================================================================
00322   //  MessageEvents
00323   // ============================================================================
00324 
00329   class MessageEvent : public Event {
00330    public:
00334     enum MessageType {
00335       Normal,
00336       URL,
00337       SMS,
00338       SMS_Receipt,
00339       AuthReq,
00340       AuthAck,
00341       AwayMessage,
00342       EmailEx,
00343       UserAdd,
00344       Email
00345     };
00346 
00347     enum DeliveryFailureReason {
00348       Failed,                  // general failure
00349       Failed_NotConnected,     // you are not connected!
00350       Failed_ClientNotCapable, // remote client is not capable (away messages)
00351       Failed_Denied,           // denied outright
00352       Failed_Ignored,          // ignore completely - send no ACKs back either
00353       Failed_Occupied,         // resend as to contactlist/urgent
00354       Failed_DND,              // resend as to contactlist/urgent
00355       Failed_SMTP
00356     };
00357 
00358    protected:
00360     ContactRef m_contact; 
00362     bool m_finished;
00364     bool m_delivered;
00366     bool m_direct;
00367 
00368     DeliveryFailureReason m_failure_reason;
00369 
00370    public:
00371     MessageEvent(ContactRef c);
00372     virtual ~MessageEvent();
00373 
00379     virtual MessageType getType() const = 0;
00380     ContactRef getContact();
00381     
00382     bool isFinished()  const;
00383     bool isDelivered() const;
00384     bool isDirect()    const;
00385     
00386     void setFinished(bool f);
00387     void setDelivered(bool f);
00388     void setDirect(bool f);
00389 
00390     DeliveryFailureReason getDeliveryFailureReason() const;
00391     void setDeliveryFailureReason(DeliveryFailureReason d);
00392   };
00393 
00397   class ICQMessageEvent : public MessageEvent {
00398    private:
00399     bool m_urgent, m_tocontactlist, m_offline;
00400     std::string m_away_message;
00401     
00402    public:
00403     ICQMessageEvent(ContactRef c);
00404     
00405     bool isUrgent() const;
00406     void setUrgent(bool b);
00407     bool isToContactList() const;
00408     void setToContactList(bool b);
00409     bool isOfflineMessage() const;
00410     void setOfflineMessage(bool b);
00411     unsigned int getSenderUIN() const;
00412     std::string getAwayMessage() const;
00413     void setAwayMessage(const std::string& msg);
00414   };
00415 
00419   class NormalMessageEvent : public ICQMessageEvent {
00420    private:
00421     string m_message;
00422     bool m_multi;
00423     unsigned int m_foreground, m_background;
00424     
00425    public:
00426     NormalMessageEvent(ContactRef c, const string& msg, bool multi = false);
00427     NormalMessageEvent(ContactRef c, const string& msg, time_t t, bool multi);
00428     NormalMessageEvent(ContactRef c, const string& msg, unsigned int fg, unsigned int bg);
00429 
00430     string getMessage() const;
00431     MessageType getType() const;
00432     bool isMultiParty() const;
00433     unsigned int getForeground() const;
00434     unsigned int getBackground() const;
00435     void setForeground(unsigned int f);
00436     void setBackground(unsigned int b);
00437   };
00438   
00442   class URLMessageEvent : public ICQMessageEvent {
00443    private:
00444     string m_message, m_url;
00445     
00446    public:
00447     URLMessageEvent(ContactRef c, const string& msg, const string& url);
00448     URLMessageEvent(ContactRef c, const string& msg, const string& url, time_t t);
00449 
00450     string getMessage() const;
00451     string getURL() const;
00452     MessageType getType() const;
00453   };
00454   
00458   class SMSMessageEvent : public MessageEvent {
00459    private:
00460     string m_message, m_source, m_sender, m_senders_network;
00461     string m_smtp_from, m_smtp_to, m_smtp_subject;
00462     bool m_rcpt;
00463 
00464    public:
00465     SMSMessageEvent(ContactRef c, const string& msg, bool rcpt);
00466     SMSMessageEvent(ContactRef c, const string& msg, const string& source,
00467                     const string& senders_network, const string& time);
00468 
00469     string getMessage() const;
00470     MessageType getType() const;
00471     string getSource() const;
00472     string getSender() const;
00473     string getSenders_network() const;
00474     bool getRcpt() const;
00475 
00476     void setSMTPFrom(const string& from);
00477     string getSMTPFrom() const;
00478 
00479     void setSMTPTo(const string& to);
00480     string getSMTPTo() const;
00481 
00482     void setSMTPSubject(const string& subj);
00483     string getSMTPSubject() const;
00484   };
00485 
00489   class SMSReceiptEvent : public MessageEvent {
00490    private:
00491     string m_message, m_message_id, m_destination, m_submission_time, m_delivery_time;
00492     bool m_delivered;
00493     
00494    public:
00495     SMSReceiptEvent(ContactRef c, const string& msg, const string& message_id,
00496                     const string& submission_time, const string& delivery_time, bool del);
00497     
00498     MessageType getType() const;
00499     string getMessage() const;
00500     string getMessageId() const;
00501     string getDestination() const;
00502     string getSubmissionTime() const;
00503     string getDeliveryTime() const;
00504     bool delivered() const;
00505   };
00506 
00514   class AwayMessageEvent : public ICQMessageEvent {
00515    public:
00516     AwayMessageEvent(ContactRef c);
00517 
00518     MessageType getType() const;
00519   };
00520 
00524   class AuthReqEvent : public ICQMessageEvent {
00525    private:
00526     string m_message;
00527 
00528    public:
00529     AuthReqEvent(ContactRef c, const string& msg);
00530     AuthReqEvent(ContactRef c, const string& msg, time_t time);
00531 
00532     string getMessage() const;
00533     MessageType getType() const;
00534   };
00535   
00539   class AuthAckEvent : public ICQMessageEvent {
00540    private:
00541     string m_message;
00542     bool m_granted;
00543 
00544    public:
00545     AuthAckEvent(ContactRef c, bool granted);
00546     AuthAckEvent(ContactRef c, bool granted, time_t time);
00547     AuthAckEvent(ContactRef c, const string& msg, bool granted);
00548     AuthAckEvent(ContactRef c, const string& msg, bool granted, time_t time);
00549 
00550     string getMessage() const;
00551     MessageType getType() const;
00552     bool isGranted() const;
00553   };
00554 
00558   class EmailExEvent : public MessageEvent {
00559    private:
00560     string m_sender, m_email, m_message;
00561 
00562    public:
00563     EmailExEvent(ContactRef c, const string &email, const string &sender, const string &msg);
00564 
00565     string getMessage() const;
00566     string getEmail() const;
00567     string getSender() const;
00568 
00569     MessageType getType() const;
00570     unsigned int getSenderUIN() const;
00571   };
00572 
00576   class UserAddEvent : public ICQMessageEvent {
00577    public:
00578     UserAddEvent(ContactRef c);
00579 
00580     MessageType getType() const;
00581     unsigned int getSenderUIN() const;
00582   };
00583 
00587   class EmailMessageEvent : public MessageEvent {
00588    private:
00589     string m_message;
00590 
00591    public:
00592     EmailMessageEvent(ContactRef c, const string &msg);
00593 
00594     string getMessage() const;
00595 
00596     MessageType getType() const;
00597   };
00598 
00599   // ============================================================================
00600   //  Search Events
00601   // ============================================================================
00602 
00606   class SearchResultEvent : public Event {
00607    public:
00608     enum SearchType {
00609       ShortWhitepage,
00610       FullWhitepage,
00611       UIN,
00612       Keyword
00613     };
00614         
00615    private:
00616     bool m_finished, m_expired;
00617     SearchType m_searchtype;
00618     ContactList m_clist;
00619     ContactRef m_last_contact;
00620     unsigned int m_more_results;
00621     
00622    public:
00623     SearchResultEvent(SearchType t);
00624 
00625     SearchType getSearchType() const;
00626     ContactList& getContactList();
00627     ContactRef getLastContactAdded() const;
00628     void setLastContactAdded(ContactRef c);
00629     unsigned int getNumberMoreResults() const;
00630 
00631     bool isFinished() const;
00632     void setFinished(bool b);
00633     bool isExpired() const;
00634     void setExpired(bool b);
00635     void setNumberMoreResults(unsigned int m);
00636   };
00637 
00641   class ServerBasedContactEvent : public Event {
00642    private:
00643     ContactList m_clist;
00644    public:
00645     ServerBasedContactEvent(const ContactList& l);
00646     ContactList& getContactList();
00647   };
00648 
00649   // ============================================================================
00650   //  NewUINEvent
00651   // ============================================================================
00652 
00656   class NewUINEvent : public Event {
00657    private:
00658     unsigned int m_uin;
00659     bool m_success;       
00660 
00661    public:
00662     NewUINEvent(unsigned int uin, bool success=true);
00663     unsigned int getUIN() const;
00664     bool isSuccess() const;
00665   };
00666 
00670   class RateInfoChangeEvent : public Event {
00671    public:
00675     enum RateClass {
00676       RATE_CHANGE=1,
00677       RATE_WARNING,
00678       RATE_LIMIT,
00679       RATE_LIMIT_CLEARED
00680     };
00681     
00682    private:
00683     unsigned short m_code;      
00684     unsigned short m_rateclass; 
00685     unsigned int m_windowsize;
00686     unsigned int m_clear;
00687     unsigned int m_alert;
00688     unsigned int m_limit;
00689     unsigned int m_disconnect;
00690     unsigned int m_currentavg;
00691     unsigned int m_maxavg;
00692 
00693    public:
00694     RateInfoChangeEvent(unsigned short code, unsigned short rateclass, 
00695                         unsigned int windowsize,unsigned int clear,
00696                         unsigned int alert,unsigned int limit,
00697                         unsigned int disconnect,unsigned int currentavg,
00698                         unsigned int maxavg);
00699     
00701     unsigned short getCode() const { return m_code; }   
00703     unsigned short getRateClass() const { return m_rateclass; } 
00705     unsigned int getWindowSize() const { return m_windowsize; }
00707     unsigned int getClear() const { return m_clear; }
00709     unsigned int getAlert() const { return m_alert; }
00711     unsigned int getLimit() const { return m_limit; }
00713     unsigned int getDisconnect() const { return m_disconnect; }
00715     unsigned int getCurrentAvg() const { return m_currentavg; }
00717     unsigned int getMaxAvg() const { return m_maxavg; }
00718   };
00719 
00720 } 
00721 
00722 #endif

Generated on Fri Apr 26 23:48:14 2002 for libicq2000 by doxygen1.2.15