1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2012-2013 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef LICQ_ICQ_USER_H
21 #define LICQ_ICQ_USER_H
22 
23 #include "../contactlist/user.h"
24 
25 #include <map>
26 #include <string>
27 #include <vector>
28 
29 namespace LicqIcq
30 {
31 class User;
32 }
33 
34 namespace Licq
35 {
36 
37 enum IcqPluginStatus
38 {
39   IcqPluginInactive = 0,
40   IcqPluginActive = 1,
41   IcqPluginBusy = 2,
42 };
43 
44 enum IcqRandomChatGroups
45 {
46   IcqRandomChatGroupNone        = 0,
47   IcqRandomChatGroupGeneral     = 1,
48   IcqRandomChatGroupRomance     = 2,
49   IcqRandomChatGroupGames       = 3,
50   IcqRandomChatGroupStudents    = 4,
51   IcqRandomChatGroup20Some      = 6,
52   IcqRandomChatGroup30Some      = 7,
53   IcqRandomChatGroup40Some      = 8,
54   IcqRandomChatGroup50Plus      = 9,
55   IcqRandomChatGroupSeekF       = 10,
56   IcqRandomChatGroupSeekM       = 11,
57 };
58 
59 const unsigned short MAX_CATEGORY_SIZE  = 60;
60 const unsigned int MAX_CATEGORIES = 4;
61 
62 typedef enum
63 {
64   CAT_INTERESTS         = 0,
65   CAT_ORGANIZATION      = 1,
66   CAT_BACKGROUND        = 2,
67   CAT_MAX               = 3,
68 } UserCat;
69 
70 struct PhoneBookEntry
71 {
72   std::string description;
73   std::string areaCode;
74   std::string phoneNumber;
75   std::string extension;
76   std::string country;
77   unsigned long nActive;
78   unsigned long nType;
79   std::string gateway;
80   unsigned long nGatewayType;
81   unsigned long nSmsAvailable;
82   unsigned long nRemoveLeading0s;
83   unsigned long nPublish;
84 };
85 
86 const unsigned short MAX_DESCRIPTION_SIZE  = 16;
87 const unsigned short MAX_AREAxCODE_SIZE    =  5;
88 const unsigned short MAX_PHONExNUMBER_SIZE = 16;
89 const unsigned short MAX_EXTENSION_SIZE    = 20;
90 const unsigned short MAX_GATEWAY_SIZE      = 64;
91 const unsigned short MAX_PICTURE_SIZE      = 8081;
92 
93 enum EPhoneType
94 {
95   TYPE_PHONE            = 0,
96   TYPE_CELLULAR         = 1,
97   TYPE_CELLULARxSMS     = 2,
98   TYPE_FAX              = 3,
99   TYPE_PAGER            = 4,
100   TYPE_MAX              = 5
101 };
102 
103 enum EGatewayType
104 {
105   GATEWAY_BUILTIN = 1,
106   GATEWAY_CUSTOM = 2,
107 };
108 
109 enum EPublish
110 {
111   PUBLISH_ENABLE = 1,
112   PUBLISH_DISABLE = 2,
113 };
114 
115 
116 typedef std::vector<struct PhoneBookEntry> IcqPhoneBookVector;
117 
118 typedef std::map<unsigned int, std::string> UserCategoryMap;
119 
120 /**
121  * An ICQ protocol contact
122  */
123 class IcqUser : public virtual User
124 {
125 public:
126   //!Retrieves the user's interests
getInterests()127   UserCategoryMap& getInterests()               { return myInterests; }
getInterests()128   const UserCategoryMap& getInterests() const   { return myInterests; }
129   //!Retrieves the user's backgrounds
getBackgrounds()130   UserCategoryMap& getBackgrounds()             { return myBackgrounds; }
getBackgrounds()131   const UserCategoryMap& getBackgrounds() const { return myBackgrounds; }
132   //!Retrieves the user's organizations
getOrganizations()133   UserCategoryMap& getOrganizations()           { return myOrganizations; }
getOrganizations()134   const UserCategoryMap& getOrganizations() const { return myOrganizations; }
135 
136   //!Retrives the user's phone book
getPhoneBook()137   IcqPhoneBookVector& getPhoneBook()              { return myPhoneBook; }
getPhoneBook()138   const IcqPhoneBookVector& getPhoneBook() const  { return myPhoneBook; }
139 
phoneFollowMeStatus()140   unsigned phoneFollowMeStatus() const          { return myPhoneFollowMeStatus; }
icqPhoneStatus()141   unsigned icqPhoneStatus() const               { return myIcqPhoneStatus; }
sharedFilesStatus()142   unsigned sharedFilesStatus() const            { return mySharedFilesStatus; }
143 
144 protected:
145   /// Constructor
146   IcqUser(const UserId& id, bool temporary = false);
147 
148   /// Destructor
149   virtual ~IcqUser();
150 
151   unsigned myPhoneFollowMeStatus;
152   unsigned myIcqPhoneStatus;
153   unsigned mySharedFilesStatus;
154 
155   UserCategoryMap myInterests;
156   UserCategoryMap myBackgrounds;
157   UserCategoryMap myOrganizations;
158   IcqPhoneBookVector myPhoneBook;
159 };
160 
161 
162 /**
163  * Read mutex guard for Licq::IcqUser
164  */
165 class IcqUserReadGuard : public UserReadGuard
166 {
167 public:
168   // Derived costructors
169   IcqUserReadGuard(const UserId& userId, bool addUser = false, bool* retWasAdded = NULL)
UserReadGuard(userId,addUser,retWasAdded)170     : UserReadGuard(userId, addUser, retWasAdded)
171   { }
172   IcqUserReadGuard(const IcqUser* user, bool locked = false)
UserReadGuard(user,locked)173     : UserReadGuard(user, locked)
174   { }
IcqUserReadGuard(IcqUserReadGuard * guard)175   IcqUserReadGuard(IcqUserReadGuard* guard)
176     : UserReadGuard(guard)
177   { }
178 
179   // Access operators
180   const IcqUser* operator*() const
181   { return dynamic_cast<const IcqUser*>(UserReadGuard::operator*()); }
182   const IcqUser* operator->() const
183   { return dynamic_cast<const IcqUser*>(UserReadGuard::operator->()); }
184 };
185 
186 /**
187  * Write mutex guard for Licq::IcqUser
188  */
189 class IcqUserWriteGuard : public UserWriteGuard
190 {
191 public:
192   // Derived costructors
193   IcqUserWriteGuard(const UserId& userId, bool addUser = false, bool* retWasAdded = NULL)
UserWriteGuard(userId,addUser,retWasAdded)194     : UserWriteGuard(userId, addUser, retWasAdded)
195   { }
196   IcqUserWriteGuard(IcqUser* user, bool locked = false)
UserWriteGuard(user,locked)197     : UserWriteGuard(user, locked)
198   { }
IcqUserWriteGuard(IcqUserWriteGuard * guard)199   IcqUserWriteGuard(IcqUserWriteGuard* guard)
200     : UserWriteGuard(guard)
201   { }
202 
203   // Access operators
204   IcqUser* operator*() const
205   { return dynamic_cast<IcqUser*>(UserWriteGuard::operator*()); }
206   IcqUser* operator->() const
207   { return dynamic_cast<IcqUser*>(UserWriteGuard::operator->()); }
208 };
209 
210 } // namespace Licq
211 
212 #endif
213