| | 117 | |
| | 118 | #define FOR_EACH_GROUP_START(x) \ |
| | 119 | { \ |
| | 120 | LicqGroup* pGroup; \ |
| | 121 | GroupMap* _gl_ = gUserManager.LockGroupList(LOCK_R); \ |
| | 122 | for (GroupMap::iterator _i_ = _gl_->begin(); \ |
| | 123 | _i_ != _gl_->end(); ++_i_) \ |
| | 124 | { \ |
| | 125 | pGroup = _i_->second; \ |
| | 126 | pGroup->Lock(x); \ |
| | 127 | { |
| | 128 | |
| | 129 | #define FOR_EACH_GROUP_START_SORTED(x) \ |
| | 130 | { \ |
| | 131 | LicqGroup* pGroup; \ |
| | 132 | std::list<LicqGroup*> _sortedGroups_; \ |
| | 133 | FOR_EACH_GROUP_START(LOCK_R) \ |
| | 134 | _sortedGroups_.push_back(pGroup); \ |
| | 135 | } \ |
| | 136 | pGroup->Unlock(); \ |
| | 137 | } \ |
| | 138 | } \ |
| | 139 | _sortedGroups_.sort(compare_groups); \ |
| | 140 | for (std::list<LicqGroup*>::iterator _i_ = _sortedGroups_.begin(); \ |
| | 141 | _i_ != _sortedGroups_.end(); ++_i_) \ |
| | 142 | { \ |
| | 143 | pGroup = *_i_; \ |
| | 144 | pGroup->Lock(x); \ |
| | 145 | { |
| | 146 | |
| | 147 | #define FOR_EACH_GROUP_CONTINUE \ |
| | 148 | { \ |
| | 149 | pGroup->Unlock(); \ |
| | 150 | continue; \ |
| | 151 | } |
| | 152 | |
| | 153 | #define FOR_EACH_GROUP_BREAK \ |
| | 154 | { \ |
| | 155 | pGroup->Unlock(); \ |
| | 156 | break; \ |
| | 157 | } |
| | 158 | |
| | 159 | #define FOR_EACH_GROUP_END \ |
| | 160 | } \ |
| | 161 | pGroup->Unlock(); \ |
| | 162 | } \ |
| | 163 | gUserManager.UnlockGroupList(); \ |
| | 164 | } |
| | 165 | |
| 736 | | // Group functions |
| 737 | | unsigned long GetGroups(GroupType g) { return(m_nGroups[g]); } |
| 738 | | void SetGroups(GroupType g, unsigned long s) { m_nGroups[g] = s; SaveLicqInfo(); } |
| 739 | | bool GetInGroup(GroupType, unsigned short); |
| 740 | | void SetInGroup(GroupType, unsigned short, bool); |
| 741 | | void AddToGroup(GroupType, unsigned short); |
| 742 | | void RemoveFromGroup(GroupType, unsigned short); |
| | 791 | /** |
| | 792 | * Get user groups this user is member of |
| | 793 | * |
| | 794 | * @return List of groups |
| | 795 | */ |
| | 796 | const UserGroupList& GetGroups() const { return myGroups; } |
| | 797 | |
| | 798 | /** |
| | 799 | * Get system groups this user is member of |
| | 800 | * |
| | 801 | * @return Bitmask of server groups |
| | 802 | */ |
| | 803 | unsigned long GetSystemGroups() const { return mySystemGroups; } |
| | 804 | |
| | 805 | /** |
| | 806 | * Set user groups this user is member of |
| | 807 | * |
| | 808 | * @param groups List of groups |
| | 809 | */ |
| | 810 | void SetGroups(const UserGroupList& groups) { myGroups = groups; } |
| | 811 | |
| | 812 | /** |
| | 813 | * Set system groups this user is member of |
| | 814 | * |
| | 815 | * @param groups Bitmask of server groups |
| | 816 | */ |
| | 817 | void SetSystemGroups(unsigned long groups) { mySystemGroups = groups; } |
| | 818 | |
| | 819 | /** |
| | 820 | * Check if user is member of a group |
| | 821 | * |
| | 822 | * @param gtype Group type (GROUPS_SYSTEM or GROUPS_USER) |
| | 823 | * @param groupId Id of group to check |
| | 824 | * @return True if group exists and user is member |
| | 825 | */ |
| | 826 | bool GetInGroup(GroupType gtype, unsigned short groupId) const; |
| | 827 | |
| | 828 | /** |
| | 829 | * Convenience function to set membership of user for a group |
| | 830 | * |
| | 831 | * @param gtype Group type (GROUPS_SYSTEM or GROUPS_USER) |
| | 832 | * @param groupId Id of group |
| | 833 | * @param member True to add user to group, false to remove user from group |
| | 834 | */ |
| | 835 | void SetInGroup(GroupType gtype, unsigned short groupId, bool member); |
| | 836 | |
| | 837 | /** |
| | 838 | * Add user to a group |
| | 839 | * |
| | 840 | * @param gtype Group type (GROUPS_SYSTEM or GROUPS_USER) |
| | 841 | * @param groupId Id of group to add |
| | 842 | */ |
| | 843 | void AddToGroup(GroupType gtype, unsigned short groupId); |
| | 844 | |
| | 845 | /** |
| | 846 | * Remove user from a group |
| | 847 | * |
| | 848 | * @param gtype Group type (GROUPS_SYSTEM or GROUPS_USER) |
| | 849 | * @pram groupId Id of group to leave |
| | 850 | * @return True if group was valid and user was a member |
| | 851 | */ |
| | 852 | bool RemoveFromGroup(GroupType gtype, unsigned short groupId); |
| | 853 | |
| | 1187 | /** |
| | 1188 | * Class holding data for a user group in the contact list. |
| | 1189 | * System groups only exists as a bitmask in ICQUser. |
| | 1190 | * |
| | 1191 | * Note: LicqGroup objects should only be created, deleted or modified from the |
| | 1192 | * user manager. If set functions are called directly, plugins will not receive |
| | 1193 | * any signal notifying them of the change. |
| | 1194 | */ |
| | 1195 | class LicqGroup |
| | 1196 | { |
| | 1197 | public: |
| | 1198 | /** |
| | 1199 | * Constructor, creates a new user group |
| | 1200 | * |
| | 1201 | * @param id Group id, must be unique |
| | 1202 | * @param name Group name |
| | 1203 | */ |
| | 1204 | LicqGroup(unsigned short id, const std::string& name); |
| | 1205 | |
| | 1206 | /** |
| | 1207 | * Destructor |
| | 1208 | */ |
| | 1209 | virtual ~LicqGroup(); |
| | 1210 | |
| | 1211 | /** |
| | 1212 | * Get id for group. This is an id used locally by Licq and is persistant for |
| | 1213 | * each group. |
| | 1214 | * |
| | 1215 | * @return Group id |
| | 1216 | */ |
| | 1217 | unsigned short id() const { return myId; } |
| | 1218 | |
| | 1219 | /** |
| | 1220 | * Get name of group as should be displayed in the user interface |
| | 1221 | * |
| | 1222 | * @return Group name |
| | 1223 | */ |
| | 1224 | const std::string& name() const { return myName; } |
| | 1225 | |
| | 1226 | /** |
| | 1227 | * Get sorting index for the group. This is used by user interface plugins to |
| | 1228 | * determine sorting order for the groups. Lower numbers should be displayed |
| | 1229 | * higher in the list. |
| | 1230 | * |
| | 1231 | * @return Sorting index for this group |
| | 1232 | */ |
| | 1233 | unsigned short sortIndex() const { return mySortIndex; } |
| | 1234 | |
| | 1235 | /** |
| | 1236 | * Group id for this group in the ICQ server side list |
| | 1237 | * |
| | 1238 | * @return ICQ server group id or 0 if not set or not known |
| | 1239 | */ |
| | 1240 | unsigned short icqGroupId() const { return myIcqGroupId; } |
| | 1241 | |
| | 1242 | /** |
| | 1243 | * Set group name |
| | 1244 | * |
| | 1245 | * @param name New group name |
| | 1246 | */ |
| | 1247 | void setName(const std::string& name) { myName = name; } |
| | 1248 | |
| | 1249 | /** |
| | 1250 | * Set sorting index for group |
| | 1251 | * |
| | 1252 | * @param sortIndex Group sorting index |
| | 1253 | */ |
| | 1254 | void setSortIndex(unsigned short sortIndex) { mySortIndex = sortIndex; } |
| | 1255 | |
| | 1256 | /** |
| | 1257 | * Set group id in ICQ server side list |
| | 1258 | * |
| | 1259 | * @param icqGroupId ICQ server group id |
| | 1260 | */ |
| | 1261 | void setIcqGroupId(unsigned short icqGroupId) { myIcqGroupId = icqGroupId; } |
| | 1262 | |
| | 1263 | /** |
| | 1264 | * Lock group for access |
| | 1265 | * |
| | 1266 | * @param lockType Type of lock (LOCK_R or LOCK_W) |
| | 1267 | */ |
| | 1268 | void Lock(unsigned short lockType); |
| | 1269 | |
| | 1270 | /** |
| | 1271 | * Release current lock for group |
| | 1272 | */ |
| | 1273 | void Unlock(); |
| | 1274 | |
| | 1275 | private: |
| | 1276 | unsigned short myId; |
| | 1277 | std::string myName; |
| | 1278 | unsigned short mySortIndex; |
| | 1279 | unsigned short myIcqGroupId; |
| | 1280 | |
| | 1281 | pthread_rdwr_t myMutex; |
| | 1282 | unsigned short myLockType; |
| | 1283 | }; |
| | 1284 | |
| | 1285 | /** |
| | 1286 | * Helper function for sorting group list |
| | 1287 | * |
| | 1288 | * @param first Left hand group to compare |
| | 1289 | * @param second Right hand group to compare |
| | 1290 | * @return True if first has a lower sorting index than second |
| | 1291 | */ |
| | 1292 | bool compare_groups(const LicqGroup* first, const LicqGroup* second); |
| | 1293 | |
| 1114 | | bool AddGroup(char *, unsigned short = 0); |
| 1115 | | void RemoveGroup(unsigned short); |
| 1116 | | void RenameGroup(unsigned short, const char *, bool = true); |
| | 1343 | /** |
| | 1344 | * Find and lock a group |
| | 1345 | * After use, the lock must be released by calling DropGroup() |
| | 1346 | * |
| | 1347 | * @param groupId Id of group to fetch |
| | 1348 | * @param lockType Type of lock to get |
| | 1349 | * @return The group if found no NULL if groupId was invalid |
| | 1350 | */ |
| | 1351 | LicqGroup* FetchGroup(unsigned short groupId, unsigned short lockType); |
| | 1352 | |
| | 1353 | /** |
| | 1354 | * Release the lock for a group preivously returned by FetchGroup() |
| | 1355 | * |
| | 1356 | * @param group The group to unlock |
| | 1357 | */ |
| | 1358 | void DropGroup(LicqGroup* group); |
| | 1359 | |
| | 1360 | /** |
| | 1361 | * Add a user group |
| | 1362 | * |
| | 1363 | * @param name Group name, must be unique |
| | 1364 | * @param icqGroupId ICQ server group id |
| | 1365 | * @return Id of new group or zero if group could not be created |
| | 1366 | */ |
| | 1367 | unsigned short AddGroup(const std::string& name, unsigned short icqGroupId = 0); |
| | 1368 | |
| | 1369 | /** |
| | 1370 | * Remove a user group |
| | 1371 | * |
| | 1372 | * @param groupId Id of group to remove |
| | 1373 | */ |
| | 1374 | void RemoveGroup(unsigned short groupId); |
| | 1375 | |
| | 1376 | /** |
| | 1377 | * Rename a user group |
| | 1378 | * |
| | 1379 | * @param groupId Id of group to rename |
| | 1380 | * @param name New group name, must be unique |
| | 1381 | * @param sendUpdate True if server group should be updated |
| | 1382 | * @return True if group was successfully renamed |
| | 1383 | */ |
| | 1384 | bool RenameGroup(unsigned short groupId, const std::string& name, bool sendUpdate = true); |
| | 1385 | |
| | 1386 | /** |
| | 1387 | * Get number of user groups |
| | 1388 | * |
| | 1389 | * @return Number of user groups |
| | 1390 | */ |
| 1119 | | void SwapGroups(unsigned short g1, unsigned short g2); |
| 1120 | | |
| 1121 | | void AddGroupID(unsigned short); |
| 1122 | | void RemoveGroupID(unsigned short); |
| 1123 | | void ModifyGroupID(char *, unsigned short); |
| 1124 | | void SaveGroupIDs(); |
| 1125 | | unsigned short GetIDFromGroup(const char *); |
| 1126 | | unsigned short GetGroupFromID(unsigned short); |
| | 1398 | |
| | 1399 | /** |
| | 1400 | * Move sorting position for a group |
| | 1401 | * Sorting position for other groups may also be changed to make sure all |
| | 1402 | * groups have unique sorting indexes. |
| | 1403 | * |
| | 1404 | * @param groupId Id of group to move |
| | 1405 | * @param newIndex New sorting index where 0 is the top position |
| | 1406 | */ |
| | 1407 | void ModifyGroupSorting(unsigned short groupId, unsigned short newIndex); |
| | 1408 | |
| | 1409 | /** |
| | 1410 | * Change ICQ server group id for a user group |
| | 1411 | * |
| | 1412 | * @param name Name of group to change |
| | 1413 | * @param icqGroupId ICQ server group id to set |
| | 1414 | */ |
| | 1415 | void ModifyGroupID(const std::string& name, unsigned short icqGroupId); |
| | 1416 | |
| | 1417 | /** |
| | 1418 | * Change ICQ server group id for a user group |
| | 1419 | * |
| | 1420 | * @param groupId Id of group to change |
| | 1421 | * @param icqGroupId ICQ server group id to set |
| | 1422 | */ |
| | 1423 | void ModifyGroupID(unsigned short groupId, unsigned short icqGroupId); |
| | 1424 | |
| | 1425 | /** |
| | 1426 | * Get ICQ group id from group name |
| | 1427 | * |
| | 1428 | * @param name Group name |
| | 1429 | * @return Id for ICQ server group or 0 if not found |
| | 1430 | */ |
| | 1431 | unsigned short GetIDFromGroup(const std::string& name); |
| | 1432 | |
| | 1433 | /** |
| | 1434 | * Get ICQ group id from group |
| | 1435 | * |
| | 1436 | * @param groupId Group |
| | 1437 | * @return Id for iCQ server group or 0 if groupId was invalid |
| | 1438 | */ |
| | 1439 | unsigned short GetIDFromGroup(unsigned short groupId); |
| | 1440 | |
| | 1441 | /** |
| | 1442 | * Get group id from ICQ server group id |
| | 1443 | * |
| | 1444 | * @param icqGroupId ICQ server group id |
| | 1445 | * @return Id for group or 0 if not found |
| | 1446 | */ |
| | 1447 | unsigned short GetGroupFromID(unsigned short icqGroupId); |
| | 1448 | |
| | 1449 | /** |
| | 1450 | * Find id for group with a given name |
| | 1451 | * |
| | 1452 | * @param name Name of the group |
| | 1453 | * @return Id for the group or 0 if there is no group with that name |
| | 1454 | */ |
| | 1455 | unsigned short GetGroupFromName(const std::string& name); |
| 1191 | | unsigned short m_nDefaultGroup, m_nNewUserGroup, |
| 1192 | | m_nUserListLockType, m_nGroupListLockType, |
| 1193 | | m_nGroupIDListLockType, m_nOwnerListLockType; |
| | 1519 | unsigned short m_nDefaultGroup; |
| | 1520 | unsigned short m_nNewUserGroup; |
| | 1521 | unsigned short m_nUserListLockType; |
| | 1522 | unsigned short myGroupListLockType; |
| | 1523 | unsigned short m_nOwnerListLockType; |