Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

evafriendlist.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by yunfan                                          *
00003  *   yunfan_zg@163.com                                                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef LIBEVAFRIENDLIST_H
00021 #define LIBEVAFRIENDLIST_H
00022 #include <map>
00023 #include <list>
00024 #include "evadefines.h"
00025 #include "evafriend.h"
00026 #include "evaonlinestatus.h"
00027 #include "evauserinfo.h"
00028 #include "evalevel.h"
00029 #include "evamemo.h"
00030 
00031 
00032 #define BUDDY_INVALID_FIELD -1
00033 // class QQFriend try to encapculate all information about your buddies,
00034 // and provides enough methods to update them from time to time
00035 class QQFriend{
00036 public:
00037         QQFriend();
00038         QQFriend(const int qqid, short qqFace);
00039         QQFriend(const QQFriend &rhs);
00040         
00041         const int getQQ() const { return qqNum; }
00042         const short getFace() const { return face; }
00043         const char getAge() const { return age; }
00044         const char getGender() const { return gender; }
00045         const std::string &getNick() const { return nick; } 
00046         const char getExtFlag() const { return extFlag; }
00047         const char getCommonFlag() const { return commonFlag; }
00048         const long getLoginTime() const { return loginTime; }
00049         const long getIdleTime() const { return idleTime; }
00050         const long getLastRefreshTime() const { return lastRefreshTime; }
00051         
00052         void setAge(const char age) { this->age = age; }
00053         void setGender(const char gender) { this->gender = gender; }
00054         void setNick(const std::string nick) { this->nick = nick; }
00055         void setExtFlag(const char flag) { extFlag = flag; }
00056         void setCommonFlag(const char flag) {commonFlag = flag; }
00057         
00058         const bool isMember() const { return (commonFlag & 0x2) != 0; }
00059         const bool isBoy() const { return gender == QQ_FRIEND_GENDER_GG;}           // aboves from FriendItem
00060 
00061         const int getIP() const { return IP; }
00062         const short getPort() const { return port;}
00063         const char getStatus() const { return status;}
00064         const char getUnknown1_4() const { return unknown4;}    // bit 4
00065         const char getUnknown2_11() const { return unknown11;}   // bit 11
00066         const short getUnknown3_13_14() const { return unknown13_14;}  // bit 13-14
00067         const unsigned char * getUnknownKey() const { return unknownKey;}   
00068         const short getUnknown4_31_32() const { return unknown31_32; }
00069         const char getOnlineExtFlag() const { return onlineExtFlag; }
00070         const char getOnlineCommFlag() const { return onlineCommonFlag; }
00071         const short getUnknown5_35_36() const { return unknown35_36; }      // aboves from FriendOnlineEntry
00072         
00073         
00074         void setFace( const short faceCode ) { face = faceCode; } // these 7 funcs update status of a 
00075         void setIP( const int ip ) { IP = ip; }                  // buddy whenever her/him send msg 
00076         void setPort( const short p) { port = p; }                 // or change online status
00077         void setStatus( const char s) { status = s; }
00078         void setUnknown1_4( const char un) { unknown4 = un; }
00079         void setUnknown2_11( const char un) { unknown11 = un; }
00080         void setUnknown3_13_14( const short un) { unknown13_14 = un; }
00081         void setUnknownKey( const unsigned char *key) { memcpy(unknownKey, key, 16); }
00082         
00083         unsigned int getOnlineTime() const { return timeOnline;}     // the following 6 funs are about the level requst
00084         unsigned short getLevel() const { return level; }
00085         unsigned short getHoursToLevelUp() const { return hoursToLevelUp;}
00086         
00087         void setOnlineTime(const unsigned int time );
00088         void setLevel(const unsigned short l ) { level = l;}
00089         void setHoursToLevelUp(const unsigned short time ) { hoursToLevelUp = time;}
00090         
00091         const short getVersion() const { return clientVersion; }    
00092         void setVersion( const short version) { clientVersion = version; } // set it once got msg from buddy
00093         const unsigned char *getFileSessionKey() const { return fileSessionKey; }
00094         void setFileSessionKey( const unsigned char *key)                // set it once got msg from buddy
00095                 { memcpy(fileSessionKey, key, 16); }
00096         
00097         void setFriendItem( const FriendItem &item);               // when u get friend list, you set this
00098         void setFriendOnlineEntry( const FriendOnlineEntry &entry);  // when u get online friend you set this
00099         
00100         const ContactInfo &getUserInformation() const { return userInfo; }
00101         void setUserInformation( const ContactInfo &info);   // once got user info, set it and update some info
00102         
00103         void setGroupIndex( const int index) { groupIndex = index; }
00104         const int getGroupIndex() const { return groupIndex; }
00105         
00106         void setExtraInfo(const unsigned int info) { mExtraInfo = info; }
00107         const unsigned int getExtraInfo() const { return mExtraInfo; }
00108         const bool hasSignature() const { return mExtraInfo & QQ_EXTAR_INFO_SIGNATURE; }
00109         const bool hasQQTang() const { return mExtraInfo & QQ_EXTAR_INFO_TANG; }
00110         const bool hasQQAlbum() const { return mExtraInfo & QQ_EXTAR_INFO_ALBUM; }
00111         const bool hasPalEntry() const { return mExtraInfo & QQ_EXTAR_INFO_PAL; }
00112         const bool hasUserHead() const { return mExtraInfo & QQ_EXTAR_INFO_USER_HEAD; }
00113         
00114         void setSignature(const std::string sig, const unsigned int time) { mSignature = sig;  mSignatureModifyTime = time; }
00115         const std::string &getSignature() const { return mSignature; }
00116         const unsigned int getSignatureModifyTime() const { return mSignatureModifyTime; }
00117 
00118         void setMemo( const MemoItem &memo ) { m_Memo = memo; }
00119         const MemoItem &getMemo() const { return m_Memo; }
00120         
00121         enum sortItem { Sort_QQ, Sort_Nick, Sort_Status};
00122         static sortItem getSortField() { return field2Sort; }
00123         static void setSortField(const sortItem field) { field2Sort = field; }
00124         QQFriend &operator=(const QQFriend &rhs);
00125         int operator==(const QQFriend &rhs) const ; // note: we only test qqNum
00126         int operator<(const QQFriend &rhs) const ;
00127 
00128         void setSequence(const unsigned short seq) { m_Sequence = seq; }
00129         const unsigned short getSequence() const { return m_Sequence; }
00130         const unsigned short getNextSequence() { return ++m_Sequence; }
00131 
00132         const int getChatFontSize() const { return m_ChatFontSize; }
00133         const int getChatFontColor() const { return m_ChatFontColor; }
00134         const int getChatFontRed()     const { return (int)(( m_ChatFontColor>>16) & 0xff); }
00135         const int getChatFontGreen() const { return (int)(( m_ChatFontColor>>8) & 0xff); }
00136         const int getChatFontBlue()   const { return (int)(  m_ChatFontColor & 0xff); }
00137 
00138         void setChatFontSize( const int size) { m_ChatFontSize = size; }
00139         void setChatFontColor(  const int color) { m_ChatFontColor = color; }
00140         void setChatFontColor(const int red, const int green, const int blue) {
00141                         m_ChatFontColor = (( 0xff << 24) | ( ( red & 0xff) << 16) | ( (green & 0xff) << 8) | ( blue & 0xff) ); }
00142 private:
00143         int qqNum;
00144         short face;
00145         char age;
00146         char gender;
00147         std::string nick;       
00148         char extFlag;  // bit1: if has qqshow, the rest are unknown  
00149         char commonFlag;  //  bit1: memeber,   bit4: TCP mode,   bit5 : mobile QQ, 
00150                           //  bit6: mobile binding,   bit7: webcam
00151         long loginTime;
00152         long idleTime;
00153         long lastRefreshTime;
00154                 
00155         char unknown4;
00156         int IP;  // 4 bytes
00157         short port;
00158         char unknown11;
00159         char status;
00160         short unknown13_14;
00161         unsigned char unknownKey[QQ_KEY_LENGTH];
00162         short unknown31_32;
00163         char onlineExtFlag;
00164         char onlineCommonFlag;
00165         short unknown35_36;
00166         
00167         unsigned int timeOnline;
00168         unsigned short level;
00169         unsigned short hoursToLevelUp;
00170         
00171         short clientVersion;
00172         
00173         unsigned int mExtraInfo;
00174         std::string mSignature;
00175         unsigned int mSignatureModifyTime;
00176         
00177         unsigned char fileSessionKey[QQ_KEY_LENGTH];
00178         
00179         ContactInfo userInfo;
00180         
00181         static sortItem field2Sort;
00182         
00183         int groupIndex;  // 0: default "My Buddies",  maximum is "Black List", the last second is "Anonymous"
00184 
00185         unsigned short m_Sequence;
00186         MemoItem m_Memo;
00187         
00188         int m_ChatFontSize;
00189         int m_ChatFontColor;
00190 
00191         void initalizeBuddy(const int qqid = 0, short qqFace = 0);
00192 };
00193 
00194 class FriendList{
00195 public:
00196         FriendList() {}
00197         ~FriendList() { privateList.clear(); }  
00198         const bool hasFriend(const int id);
00199         QQFriend *getFriend(const int id);
00200         bool deleteFriend(const int id);
00201         void addFriend(const QQFriend &frd);
00202         void updateFriend( const QQFriend &frd);  // if frd dosen't exists, add a new one
00203         void clearFriendList() { privateList.clear(); }
00204         
00205         bool updateFriendIP(const int id, const int ip);
00206         bool updateFriendPort(const int id, const short p);
00207         bool updateFriendFace(const int id, const short face);
00208         bool updateFriendStatus(const int id, const char status);
00209         bool updateFriendFileSessionKey(const int id, const unsigned char *key); 
00210         bool updateFriendGroupIndex(const int id, const int index);
00211         
00212         bool updateFriendLevel(const int id, const unsigned int online, const unsigned short level, const unsigned short hours);
00213         
00214         bool addFriendItemTo( const int id, const FriendItem &item);
00215         bool addOnlineFriendEntryTo( const int id, const FriendOnlineEntry & entry);
00216         bool addContactInfoTo( const int id, const ContactInfo &info);
00217         
00218         const int numberOfFriends() const { return privateList.size(); }
00219         const int numberOfOnlines() ;
00220         std::list<QQFriend> getFriendsInGroupIndexOf( const int index);
00221         std::list<QQFriend> getAllFriends( const int myId = 0);
00222         std::map<int, QQFriend> getAllFriendsMap() { return privateList; }
00223         
00224         const std::map<int, QQFriend> &getFriendList() const { return privateList; }
00225         
00226         bool setExtraInfo(const int id, const short info);
00227         bool setSignature(const int id, const std::string sig, const unsigned int time);
00228         const std::map<int, int> getMemberSignatureList(const int start, const int myId, const bool hasSignature);
00229         const std::list<int> getUserHeadList(const int myId, const bool hasUserHead);
00230         bool setMemo(const int id, const MemoItem &memo);
00231         FriendList &operator=(const FriendList &rhs) { privateList = rhs.getFriendList(); return *this;}
00232 private:
00233         std::map<int, QQFriend> privateList;
00234         std::map<int, QQFriend>::iterator getFriendPosition(const int id);
00235 };
00236 
00237 #endif
00238 
00239 
00240  

Generated on Mon May 15 20:48:40 2006 for libeva by  doxygen 1.4.4