1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2010-2014 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_CONTACTLIST_OWNER_H
21 #define LICQ_CONTACTLIST_OWNER_H
22 
23 #include "user.h"
24 
25 namespace Licq
26 {
27 
28 /**
29  * A protocol account including all user information for that account
30  *
31  * Inherits LicqUser to hold all user information associated with the account.
32  */
33 class Owner : public virtual User
34 {
35 public:
36   // Owner specific functions
password()37   const std::string& password() const           { return myPassword; }
setPassword(const std::string & s)38   void setPassword(const std::string& s)        { myPassword = s; save(SaveOwnerInfo); }
SetSavePassword(bool b)39   void SetSavePassword(bool b) {  m_bSavePassword = b; save(SaveOwnerInfo); }
SavePassword()40   bool SavePassword() const                     { return m_bSavePassword; }
41 
42   /**
43    * Get status to change to at startup
44    */
startupStatus()45   unsigned startupStatus() const
46   { return myStartupStatus; }
47 
48   /**
49    * Set status to change to at startup
50    */
setStartupStatus(unsigned status)51   void setStartupStatus(unsigned status)
52   { myStartupStatus = status; }
53 
54   /// Get if global status will be applied to this user
useGlobalStatus()55   bool useGlobalStatus() const                  { return myUseGlobalStatus; }
56 
57   /// Set if global status will be applied to this user
setUseGlobalStatus(bool b)58   void setUseGlobalStatus(bool b)               { myUseGlobalStatus = b; }
59 
60   /// Get server to connect to
serverHost()61   const std::string& serverHost() const         { return myServerHost; }
62 
63   /// Get server port to connect to
serverPort()64   int serverPort() const                        { return myServerPort; }
65 
66   /**
67    * Set server to use when connecting
68    *
69    * @param host Host to connect to
70    * @param port Port to connect to
71    */
setServer(const std::string & host,int port)72   void setServer(const std::string& host, int port)
73   { myServerHost = host; myServerPort = port; save(SaveOwnerInfo); }
74 
75   void SetPicture(const char *f);
76 
77 protected:
78   /// Constructor
79   Owner(const UserId& id);
80 
81   /// Destructor
82   virtual ~Owner();
83 
84   virtual void saveOwnerInfo();
85 
86   std::string myPassword;
87   unsigned myStartupStatus;
88   std::string myServerHost;
89   int myServerPort;
90   bool m_bSavePassword;
91   bool myUseGlobalStatus;
92 
93 private:
94 
95   // Allow the user manager to access private members
96   friend class LicqDaemon::UserManager;
97 };
98 
99 /**
100  * Read mutex guard for Licq::Owner
101  */
102 class OwnerReadGuard : public ReadMutexGuard<Owner>
103 {
104 public:
105   /**
106    * Constructor, will fetch and lock an owner based on user id
107    * Note: Always check that the owner was actually fetched before using
108    *
109    * @param userId Id of owner to fetch
110    */
111   OwnerReadGuard(const UserId& userId);
112 
113   // Derived constructors
114   OwnerReadGuard(const Owner* owner, bool locked = false)
115     : ReadMutexGuard<Owner>(owner, locked)
116   { }
OwnerReadGuard(ReadMutexGuard<Owner> * guard)117   OwnerReadGuard(ReadMutexGuard<Owner>* guard)
118     : ReadMutexGuard<Owner>(guard)
119   { }
120 };
121 
122 /**
123  * Write mutex guard for Licq::Owner
124  */
125 class OwnerWriteGuard : public WriteMutexGuard<Owner>
126 {
127 public:
128   /**
129    * Constructor, will fetch and lock an owner based on user id
130    * Note: Always check that the owner was actually fetched before using
131    *
132    * @param userId Id of owner to fetch
133    */
134   OwnerWriteGuard(const UserId& userId);
135 
136   // Derived constructors
137   OwnerWriteGuard(Owner* owner, bool locked = false)
138     : WriteMutexGuard<Owner>(owner, locked)
139   { }
OwnerWriteGuard(WriteMutexGuard<Owner> * guard)140   OwnerWriteGuard(WriteMutexGuard<Owner>* guard)
141     : WriteMutexGuard<Owner>(guard)
142   { }
143 };
144 
145 } // namespace Licq
146 
147 #endif // LICQ_CONTACTLIST_OWNER_H
148