1 /* 2 * Contact (model) 3 * A contact on the contact list 4 * 5 * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk> 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * 21 */ 22 23 #ifndef CONTACT_H 24 #define CONTACT_H 25 26 #include <list> 27 #include <string> 28 29 #include <libicq2000/sigslot.h> 30 31 #include <libicq2000/constants.h> 32 #include <libicq2000/userinfoconstants.h> 33 34 #include <libicq2000/ref_ptr.h> 35 36 namespace ICQ2000 37 { 38 /* predeclare classes */ 39 class Capabilities; 40 class MessageEvent; 41 class StatusChangeEvent; 42 class UserInfoChangeEvent; 43 44 // -- Status Codes Flags -- 45 const unsigned short STATUS_FLAG_ONLINE = 0x0000; 46 const unsigned short STATUS_FLAG_AWAY = 0x0001; 47 const unsigned short STATUS_FLAG_DND = 0x0002; 48 const unsigned short STATUS_FLAG_NA = 0x0004; 49 const unsigned short STATUS_FLAG_OCCUPIED = 0x0010; 50 const unsigned short STATUS_FLAG_FREEFORCHAT = 0x0020; 51 const unsigned short STATUS_FLAG_INVISIBLE = 0x0100; 52 53 class Contact 54 { 55 public: 56 // reference count 57 unsigned int count; 58 59 // Inner classes for various sections of Contact details 60 61 class MainHomeInfo 62 { 63 std::string cellular, normalised_cellular; 64 // cellular private - access must be through 65 // get/setMobileNo for consistency 66 67 void normaliseMobileNo(); 68 69 public: 70 MainHomeInfo(); 71 72 std::string alias, firstname, lastname, email, city, state, phone, fax, street, zip; 73 Country country; 74 Timezone timezone; 75 76 Country getCountry() const; 77 std::string getMobileNo() const; 78 void setMobileNo(const std::string& s); 79 80 std::string getNormalisedMobileNo() const; 81 }; 82 83 class HomepageInfo 84 { 85 public: 86 HomepageInfo(); 87 88 unsigned char age; 89 Sex sex; 90 Language lang1, lang2, lang3; 91 92 std::string homepage; 93 unsigned short birth_year; 94 unsigned char birth_month, birth_day; 95 96 std::string getBirthDate() const; 97 Language getLanguage(int l) const; 98 }; 99 100 class EmailInfo 101 { 102 public: 103 typedef std::list<std::string> EmailList; 104 EmailList emails; 105 106 EmailInfo(); 107 108 void addEmailAddress(const std::string&); 109 }; 110 111 class WorkInfo 112 { 113 public: 114 WorkInfo(); 115 116 std::string city, state, street, zip; 117 unsigned short country; 118 std::string company_name, company_dept, company_position, company_web; 119 }; 120 121 class BackgroundInfo 122 { 123 public: 124 typedef std::pair<unsigned short, std::string> School; 125 typedef std::list<School> SchoolList; 126 SchoolList schools; // school names 127 128 BackgroundInfo(); 129 130 void addSchool(unsigned short cat, const std::string& s); 131 }; 132 133 class PersonalInterestInfo 134 { 135 public: 136 typedef std::pair<unsigned short, std::string> Interest; 137 typedef std::list<Interest> InterestList; 138 InterestList interests; 139 140 PersonalInterestInfo(); 141 142 void addInterest(unsigned short cat, const std::string& s); 143 }; 144 145 private: 146 void Init(); 147 bool m_icqcontact; 148 bool m_virtualcontact; 149 150 // static fields 151 unsigned int m_uin; 152 153 // dynamic fields - updated when they come online 154 unsigned char m_tcp_version; 155 unsigned int m_dc_cookie; 156 Status m_status; 157 bool m_invisible; 158 bool m_authreq, m_authawait; 159 bool m_direct; 160 bool m_bday; // Birthday Flag 161 bool m_server_based; 162 unsigned int m_ext_ip, m_lan_ip; 163 unsigned short m_ext_port, m_lan_port, m_group_id, m_tag_id; 164 Capabilities * m_capabilities; 165 unsigned int m_signon_time, m_last_online_time, m_last_status_change_time; 166 unsigned int m_last_message_time, m_last_away_msg_check_time; 167 168 static unsigned int imag_uin; 169 170 // other fields 171 unsigned short m_seqnum; 172 173 // detailed fields 174 MainHomeInfo m_main_home_info; 175 HomepageInfo m_homepage_info; 176 EmailInfo m_email_info; 177 WorkInfo m_work_info; 178 PersonalInterestInfo m_personal_interest_info; 179 BackgroundInfo m_background_info; 180 std::string m_about; 181 182 public: 183 Contact(); 184 185 Contact(unsigned int uin); 186 Contact(const std::string& a); 187 188 ~Contact(); 189 190 unsigned int getUIN() const; 191 void setUIN(unsigned int uin); 192 std::string getStringUIN() const; 193 std::string getMobileNo() const; 194 std::string getNormalisedMobileNo() const; 195 std::string getAlias() const; 196 std::string getFirstName() const; 197 std::string getLastName() const; 198 std::string getEmail() const; 199 200 std::string getNameAlias() const; 201 202 Status getStatus() const; 203 bool isInvisible() const; 204 bool getAuthReq() const; 205 bool getAuthAwait() const; 206 bool getServerBased() const; 207 208 unsigned int getExtIP() const; 209 unsigned int getLanIP() const; 210 unsigned short getExtPort() const; 211 unsigned short getLanPort() const; 212 unsigned char getTCPVersion() const; 213 unsigned int getDCCookie() const; 214 bool get_accept_adv_msgs() const; 215 Capabilities get_capabilities() const; 216 217 unsigned int get_signon_time() const; 218 unsigned int get_last_online_time() const; 219 unsigned int get_last_status_change_time() const; 220 unsigned int get_last_message_time() const; 221 unsigned int get_last_away_msg_check_time() const; 222 223 void setMobileNo(const std::string& mn); 224 void setAlias(const std::string& al); 225 void setFirstName(const std::string& fn); 226 void setLastName(const std::string& ln); 227 void setEmail(const std::string& em); 228 void setAuthReq(bool b); 229 void setAuthAwait(bool b); 230 void setServerBased(bool b); 231 232 bool getDirect() const; 233 void setDirect(bool b); 234 235 bool getBirthday() const; 236 void setBirthday(bool b); 237 238 void setStatus(Status st, bool i); 239 void setStatus(Status st); 240 void setInvisible(bool i); 241 void setExtIP(unsigned int ip); 242 void setLanIP(unsigned int ip); 243 void setExtPort(unsigned short port); 244 void setLanPort(unsigned short port); 245 void setTCPVersion(unsigned char v); 246 void setDCCookie(unsigned int cookie); 247 void set_capabilities(const Capabilities& c); 248 249 void setServerSideInfo(unsigned short group_id, unsigned short tag_id); 250 unsigned short getServerSideGroupID() const; 251 unsigned short getServerSideID() const; 252 253 void set_signon_time(unsigned int t); 254 void set_last_online_time(unsigned int t); 255 void set_last_status_change_time(unsigned int t); 256 void set_last_message_time(unsigned int t); 257 void set_last_away_msg_check_time(unsigned int t); 258 259 void setMainHomeInfo(const MainHomeInfo& m); 260 void setHomepageInfo(const HomepageInfo& s); 261 void setEmailInfo(const EmailInfo &e); 262 void setWorkInfo(const WorkInfo &w); 263 void setInterestInfo(const PersonalInterestInfo& p); 264 void setBackgroundInfo(const BackgroundInfo& b); 265 void setAboutInfo(const std::string& about); 266 267 MainHomeInfo& getMainHomeInfo(); 268 HomepageInfo& getHomepageInfo(); 269 EmailInfo& getEmailInfo(); 270 WorkInfo& getWorkInfo(); 271 BackgroundInfo& getBackgroundInfo(); 272 PersonalInterestInfo& getPersonalInterestInfo(); 273 const std::string& getAboutInfo() const; 274 275 bool isICQContact() const; 276 bool isVirtualContact() const; 277 278 bool isSMSable() const; 279 280 unsigned short nextSeqNum(); 281 282 sigslot::signal1<StatusChangeEvent*> status_change_signal; 283 sigslot::signal1<UserInfoChangeEvent*> userinfo_change_signal; 284 285 void userinfo_change_emit(); 286 void userinfo_change_emit(bool is_transient_detail); 287 288 static std::string UINtoString(unsigned int uin); 289 static unsigned int StringtoUIN(const std::string& s); 290 291 static unsigned short MapStatusToICQStatus(Status st, bool inv); 292 static Status MapICQStatusToStatus(unsigned short st); 293 static bool MapICQStatusToInvisible(unsigned short st); 294 295 static unsigned int nextImaginaryUIN(); 296 }; 297 298 typedef ref_ptr<Contact> ContactRef; 299 300 class Sbl_item { 301 public: Sbl_item()302 Sbl_item() { uin = 0; tag_id = 0; } Sbl_item(ContactRef & cont,unsigned short tag_id,std::string group_name)303 Sbl_item(ContactRef& cont, unsigned short tag_id, std::string group_name) { 304 this->uin = cont->getUIN(); this->tag_id = tag_id; this->group_name = group_name; 305 this->nickname = cont->getAlias(); this->awaitAuth = cont->getAuthAwait(); 306 if (this->nickname.size() == 0) 307 this->nickname = Contact::UINtoString(this->uin); 308 } 309 Sbl_item(Sbl_item & item,unsigned short tag_id,std::string group_name)310 Sbl_item(Sbl_item &item, unsigned short tag_id, std::string group_name) { 311 this->uin = item.uin; this->tag_id = tag_id; this->group_name = group_name; 312 this->nickname = item.nickname; this->awaitAuth = item.awaitAuth; 313 } 314 Sbl_item(unsigned short group_id,std::string group_name)315 Sbl_item(unsigned short group_id, std::string group_name) { 316 this->tag_id = group_id; 317 this->group_name = group_name; 318 } 319 320 unsigned int uin; 321 unsigned short tag_id; 322 std::string group_name; 323 unsigned char type; 324 std::string nickname; 325 bool awaitAuth; 326 }; 327 328 class Sbl_group { 329 public: Sbl_group()330 Sbl_group() { group_id = 0; } Sbl_group(std::string name,unsigned short group_id)331 Sbl_group(std::string name, unsigned short group_id) { 332 this->name = name; 333 this->group_id = group_id; 334 } 335 336 std::string name; 337 unsigned short group_id; 338 std::set<unsigned short> buddies; 339 }; 340 341 } 342 #endif 343