1 /* 2 * This file is part of Licq, an instant messaging client for UNIX. 3 * Copyright (C) 2007-2011 Licq developers 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 CONTACTUSERDATA_H 21 #define CONTACTUSERDATA_H 22 23 #include <time.h> 24 25 #include <QList> 26 #include <QString> 27 #include <QTimer> 28 #include <QVariant> 29 30 #include "contactitem.h" 31 #include "contactlist.h" 32 33 class QImage; 34 35 36 namespace LicqQtGui 37 { 38 class ContactUser; 39 40 /** 41 * Data for a user, shared between all instances of ContactUser for a user 42 * 43 * This class is used internally by ContactList and should not be accessed from any other class 44 */ 45 class ContactUserData : public QObject 46 { 47 Q_OBJECT 48 49 public: 50 /** 51 * Constructor 52 * 53 * @param licqUser Licq user that this object will represent 54 * @param parent Object to use as parent for those objects that needs it 55 */ 56 ContactUserData(const Licq::User* licqUser, QObject* parent); 57 58 /** 59 * Destructor, will remove the user from all groups 60 */ 61 virtual ~ContactUserData(); 62 63 /** 64 * Update user information 65 * 66 * @param subSignal Sub signal telling what the change was 67 * @param argument Additional data, usage depend on sub signal type 68 */ 69 void update(unsigned long subSignal, int argument); 70 71 /** 72 * Update all data related to the gui configuration 73 */ 74 void configUpdated(); 75 76 /** 77 * Get licq user id 78 */ userId()79 const Licq::UserId& userId() const 80 { return myUserId; } 81 82 /** 83 * Get user status 84 */ status()85 unsigned status() const 86 { return myStatus; } 87 88 /** 89 * Get extended status bits 90 */ extendedStatus()91 unsigned extendedStatus() const 92 { return myExtendedStatus; } 93 94 /** 95 * Get current sub group 96 */ subGroup()97 ContactListModel::SubGroupType subGroup() const 98 { return mySubGroup; } 99 100 /** 101 * Get number of unread events 102 */ numEvents()103 int numEvents() const 104 { return myEvents; } 105 106 /** 107 * Get current visibility 108 */ visibility()109 bool visibility() const 110 { return myVisibility; } 111 112 /** 113 * Get a list of all the groups this user is a member of 114 * 115 * @return the list of all user instances belonging to this user 116 */ groupList()117 QList<ContactUser*> groupList() const 118 { return myUserInstances; } 119 120 /** 121 * Add this user from a group 122 * Note: Do not call this method directly, it should only be called from the user instance constructor. 123 * 124 * @param user The user instance to add 125 */ 126 void addGroup(ContactUser* user); 127 128 /** 129 * Remove this user from a group 130 * Note: Do not call this method directly, it should only be called from the user instance destructor. 131 * 132 * @param user The user instance to remove 133 */ 134 void removeGroup(ContactUser* user); 135 136 /** 137 * Get data for this user 138 * 139 * @param column A valid column in the contact list 140 * @param role The qt role to get data for 141 * @return Data for this user 142 */ 143 QVariant data(int column, int role) const; 144 145 /** 146 * Set data for this user 147 * Currently only alias may be change this way 148 * 149 * @param value New value to set 150 * @param role Must be ContactListModel::NameRole 151 * @return True if alias was changed 152 */ 153 virtual bool setData(const QVariant& value, int role = ContactListModel::NameRole); 154 155 signals: 156 /** 157 * Signal emitted when user data has changed 158 */ 159 void dataChanged(const ContactUserData* user); 160 161 /** 162 * Signal emitted when the user group memberships (may) have changed 163 */ 164 void updateUserGroups(ContactUserData* user, const Licq::User* licqUser); 165 166 private: 167 /** 168 * Update user information from daemon 169 * 170 * @param licqUser Licq user to read information from 171 * @param subSignal Information to update or 0 to update everything 172 */ 173 void update(const Licq::User* licqUser, unsigned long subSignal); 174 175 /** 176 * Update user picture 177 * 178 * @param u User to get picture from 179 */ 180 void updatePicture(const Licq::User* u); 181 182 /** 183 * Update user events 184 * 185 * @param u User to get events from 186 */ 187 void updateEvents(const Licq::User* u); 188 189 /** 190 * Update extended status bits 191 */ 192 void updateExtendedStatus(); 193 194 /** 195 * Update icons 196 */ 197 void updateIcons(); 198 199 /** 200 * Update sorting keys 201 */ 202 void updateSorting(); 203 204 /** 205 * Update the display text for the user 206 * 207 * @param licqUser Licq user to read information from 208 * @return True if any data was actually changed 209 */ 210 bool updateText(const Licq::User* licqUser); 211 212 /** 213 * Update visibility status 214 */ 215 void updateVisibility(); 216 217 /** 218 * Activate animation timer 219 */ 220 void startAnimation(); 221 222 /** 223 * Deactivate animation timer if it is no longer needed 224 */ 225 void stopAnimation(); 226 227 /** 228 * Generate a tooltip with user information 229 */ 230 QString tooltip() const; 231 232 private slots: 233 /** 234 * Refresh content that may contain timestamps 235 */ 236 void refresh(); 237 238 /** 239 * Cycle animations 240 */ 241 void animate(); 242 243 private: 244 Licq::UserId myUserId; 245 unsigned myStatus; 246 int myEvents; 247 bool myStatusInvisible, myStatusTyping, myCustomAR, mySecure, myFlash; 248 bool myBirthday, myPhone, myCellular, myGPGKey, myGPGKeyEnabled; 249 bool myNewUser, myNotInList, myAwaitingAuth; 250 bool myInIgnoreList, myInOnlineNotify, myInInvisibleList, myInVisibleList; 251 time_t myTouched; 252 unsigned short myNewMessages; 253 unsigned myEventType; 254 unsigned myPhoneFollowMeStatus, myIcqPhoneStatus, mySharedFilesStatus; 255 unsigned int myExtendedStatus; 256 ContactListModel::SubGroupType mySubGroup; 257 QString mySortKey; 258 bool myVisibility; 259 260 bool myFlashCounter; 261 int myOnlCounter, myCarCounter; 262 bool myAnimating; 263 264 QImage* myUserIcon; 265 bool myUrgent; 266 QString myText[4]; 267 QString myAlias; 268 QList<ContactUser*> myUserInstances; 269 270 static QTimer* myRefreshTimer; 271 static QTimer* myAnimateTimer; 272 static int myAnimatorCount; 273 }; 274 275 } // namespace LicqQtGui 276 277 #endif 278