Changeset 6259
- Timestamp:
- 06/11/08 08:25:24 (4 months ago)
- Location:
- branches/qt4-gui_group/src
- Files:
-
- 12 modified
-
contactlist/contactgroup.cpp (modified) (3 diffs)
-
contactlist/contactgroup.h (modified) (4 diffs)
-
contactlist/contactlist.cpp (modified) (4 diffs)
-
contactlist/contactlist.h (modified) (2 diffs)
-
core/groupmenu.cpp (modified) (3 diffs)
-
core/groupmenu.h (modified) (1 diff)
-
core/licqgui.cpp (modified) (1 diff)
-
core/mainwin.cpp (modified) (1 diff)
-
core/systemmenu.cpp (modified) (1 diff)
-
core/usermenu.cpp (modified) (1 diff)
-
dialogs/editgrpdlg.cpp (modified) (5 diffs)
-
dialogs/editgrpdlg.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/qt4-gui_group/src/contactlist/contactgroup.cpp
r6200 r6259 36 36 { 37 37 if (myGroupId != 0) 38 { 39 mySortKey.sprintf("%10i", myGroupId); 40 } 38 mySortKey = myGroupId; 41 39 else 42 {43 40 // Put "Other Users" last when sorting 44 mySortKey = QString("9999999999"); 45 } 46 41 mySortKey = 65535; 42 43 update(); 44 45 for (int i = 0; i < 3; ++i) 46 myBars[i] = new ContactBar(static_cast<ContactListModel::SubGroupType>(i), this); 47 } 48 49 ContactGroup::ContactGroup(const LicqGroup* group) 50 : ContactItem(ContactListModel::GroupItem), 51 myGroupId(group->id()), 52 myName(group->name().c_str()), 53 mySortKey(group->sortIndex()), 54 myEvents(0), 55 myVisibleContacts(0) 56 { 47 57 for (int i = 0; i < 3; ++i) 48 58 myBars[i] = new ContactBar(static_cast<ContactListModel::SubGroupType>(i), this); … … 61 71 void ContactGroup::update() 62 72 { 63 GroupList* g = gUserManager.LockGroupList(LOCK_R); 64 myName = QString::fromLocal8Bit((*g)[myGroupId-1]); 65 gUserManager.UnlockGroupList(); 66 67 emit dataChanged(this); 73 // System groups and "Other users" aren't present in daemon group list 74 if (myGroupId == 0 || myGroupId >= ContactListModel::SystemGroupOffset) 75 return; 76 77 LicqGroup* g = gUserManager.FetchGroup(myGroupId, LOCK_R); 78 if (g == NULL) 79 return; 80 81 myName = QString::fromLocal8Bit(g->name().c_str()); 82 mySortKey = g->sortIndex(); 83 gUserManager.DropGroup(g); 84 85 emit dataChanged(this); 86 } 87 88 void ContactGroup::updateSortKey() 89 { 90 // System groups and "Other users" aren't present in daemon group list 91 if (myGroupId == 0 || myGroupId >= ContactListModel::SystemGroupOffset) 92 return; 93 94 LicqGroup* g = gUserManager.FetchGroup(myGroupId, LOCK_R); 95 if (g == NULL) 96 return; 97 98 mySortKey = g->sortIndex(); 99 gUserManager.DropGroup(g); 68 100 } 69 101 … … 214 246 215 247 // Don't save new name here, daemon will signal us when name has changed 216 gUserManager.RenameGroup(myGroupId, newName.toLocal8Bit() );248 gUserManager.RenameGroup(myGroupId, newName.toLocal8Bit().data()); 217 249 218 250 return true; -
branches/qt4-gui_group/src/contactlist/contactgroup.h
r6200 r6259 29 29 #include "contactlist.h" 30 30 31 class LicqGroup; 32 31 33 namespace LicqQtGui 32 34 { … … 50 52 * @param name Group name 51 53 */ 52 ContactGroup(unsigned short id, QString name); 54 ContactGroup(unsigned short id, QString name = QString()); 55 56 /** 57 * Constructor, creates an empty group 58 * 59 * @param group Group object from daemon 60 */ 61 ContactGroup(const LicqGroup* group); 53 62 54 63 /** … … 157 166 virtual bool setData(const QVariant& value, int role = ContactListModel::NameRole); 158 167 168 /** 169 * Update sort key for this group from daemon 170 */ 171 void updateSortKey(); 172 159 173 signals: 160 174 /** … … 171 185 unsigned short myGroupId; 172 186 QString myName; 173 QStringmySortKey;187 unsigned short mySortKey; 174 188 int myEvents; 175 189 QList<ContactUser*> myUsers; -
branches/qt4-gui_group/src/contactlist/contactlist.cpp
r6200 r6259 103 103 { 104 104 unsigned short gid = sig->Argument(); 105 106 GroupList* g = gUserManager.LockGroupList(LOCK_R); 107 ContactGroup* newGroup = createGroup(gid, QString::fromLocal8Bit((*g)[gid-1])); 108 gUserManager.UnlockGroupList(); 105 ContactGroup* newGroup = createGroup(gid); 109 106 110 107 beginInsertRows(QModelIndex(), myUserGroups.size(), myUserGroups.size()); … … 144 141 break; 145 142 } 143 144 case LIST_GROUP_REORDERED: 145 { 146 // Get new sort keys for all groups 147 for (int i = 0; i < myUserGroups.size(); ++i) 148 myUserGroups.at(i)->updateSortKey(); 149 150 // Send one changed signal for all groups 151 emit dataChanged(createIndex(0, 0, myUserGroups.at(0)), 152 createIndex(myUserGroups.size() + NUM_GROUPS_SYSTEM_ALL - 1, myColumnCount - 1, 153 mySystemGroups[NUM_GROUPS_SYSTEM_ALL-1])); 154 155 break; 156 } 146 157 } 147 158 } … … 250 261 251 262 // Add all groups 252 GroupList* g = gUserManager.LockGroupList(LOCK_R); 253 beginInsertRows(QModelIndex(), 0, g->size()); 263 beginInsertRows(QModelIndex(), 0, gUserManager.NumGroups() + 1); 254 264 255 265 ContactGroup* newGroup = createGroup(0, tr("Other Users")); 256 266 myUserGroups.append(newGroup); 257 267 258 for (unsigned short i = 0; i < g->size(); ++i) 259 { 260 newGroup = createGroup(i+1, QString::fromLocal8Bit((*g)[i])); 261 myUserGroups.append(newGroup); 262 } 268 FOR_EACH_GROUP_START(LOCK_R) 269 { 270 ContactGroup* group = new ContactGroup(pGroup); 271 connect(group, SIGNAL(dataChanged(ContactGroup*)), 272 SLOT(groupDataChanged(ContactGroup*))); 273 connect(group, SIGNAL(barDataChanged(ContactBar*, int)), 274 SLOT(barDataChanged(ContactBar*, int))); 275 myUserGroups.append(group); 276 } 277 FOR_EACH_GROUP_END 263 278 264 279 endInsertRows(); 265 gUserManager.UnlockGroupList();266 280 267 281 // Add all users … … 307 321 unsigned short gid = group->groupId(); 308 322 bool shouldBeMember = (gid != 0 && licqUser->GetInGroup(GROUPS_USER, gid)) || 309 (gid == 0 && licqUser->GetGroups( GROUPS_USER) == 0&& !licqUser->IgnoreList());323 (gid == 0 && licqUser->GetGroups().empty() && !licqUser->IgnoreList()); 310 324 updateUserGroup(user, group, i, shouldBeMember); 311 325 } -
branches/qt4-gui_group/src/contactlist/contactlist.h
r6197 r6259 74 74 ItemTypeRole = Qt::UserRole, // Type of item (one of enum ItemType) 75 75 NameRole, // Item name (alias for UserItems) 76 SortPrefixRole, // Primary sort index 77 SortRole, // S econdary sort index76 SortPrefixRole, // Primary sort index (UserItems only) 77 SortRole, // Sort index (secondary index for UserItems, only index for GroupItems) 78 78 UnreadEventsRole, // Number of unread events 79 79 EventSubCommandRole, // Type of event (UserItems only) … … 389 389 * 390 390 * @param id Id for the new group 391 * @param name Name for the new group 391 * @param name Name for the new group (only for non standard groups) 392 392 * @return The created group 393 393 */ 394 ContactGroup* createGroup(unsigned short id, QString name );394 ContactGroup* createGroup(unsigned short id, QString name = QString()); 395 395 396 396 /** -
branches/qt4-gui_group/src/core/groupmenu.cpp
r6200 r6259 89 89 delete a; 90 90 91 GroupList* g = gUserManager.LockGroupList(LOCK_R); 92 for (unsigned int i = 0; i < g->size(); ++i) 93 { 94 QString name = QString::fromLocal8Bit((*g)[i]); 91 FOR_EACH_GROUP_START_SORTED(LOCK_R) 92 { 93 QString name = QString::fromLocal8Bit(pGroup->name().c_str()); 95 94 96 95 a = myUserGroupActions->addAction(name); 97 a->setData( i + 1);96 a->setData(pGroup->id()); 98 97 99 98 myGroupsMenu->insertAction(myGroupSeparator, a); 100 99 } 101 gUserManager.UnlockGroupList();100 FOR_EACH_GROUP_END 102 101 103 102 // Add groups to menu … … 118 117 myMoveDownAction->setEnabled(!special && myGroupId < gUserManager.NumGroups()); 119 118 myRemoveGroupAction->setEnabled(!special); 119 120 mySortIndex = 0; 121 if (!special) 122 { 123 LicqGroup* group = gUserManager.FetchGroup(myGroupId, LOCK_R); 124 if (group != NULL) 125 { 126 mySortIndex = group->sortIndex(); 127 myGroupName = QString::fromLocal8Bit(group->name().c_str()); 128 gUserManager.DropGroup(group); 129 } 130 } 120 131 } 121 132 … … 133 144 void GroupMenu::moveGroupUp() 134 145 { 135 // Model uses group+1 so substract one before sending to daemon 136 gUserManager.SwapGroups(myGroupId, myGroupId - 1); 146 if (mySortIndex == 0) 147 return; 148 149 gUserManager.ModifyGroupSorting(myGroupId, mySortIndex - 1); 137 150 } 138 151 139 152 void GroupMenu::moveGroupDown() 140 153 { 141 // Model uses group+1 so substract one before sending to daemon 142 gUserManager.SwapGroups(myGroupId, myGroupId + 1); 154 gUserManager.ModifyGroupSorting(myGroupId, mySortIndex + 1); 143 155 } 144 156 145 157 void GroupMenu::removeGroup() 146 158 { 147 GroupList* g = gUserManager.LockGroupList(LOCK_R);148 159 QString warning(tr("Are you sure you want to remove the group '%1'?") 149 .arg(QString::fromLocal8Bit((*g)[myGroupId-1]))); 150 gUserManager.UnlockGroupList(); 160 .arg(myGroupName)); 151 161 if (!QueryYesNo(this, warning)) 152 162 return; -
branches/qt4-gui_group/src/core/groupmenu.h
r6153 r6259 102 102 // Current group 103 103 unsigned int myGroupId; 104 unsigned short mySortIndex; 105 QString myGroupName; 104 106 105 107 // Actions not in any sub menu -
branches/qt4-gui_group/src/core/licqgui.cpp
r6249 r6259 754 754 if (u == NULL) 755 755 return true; 756 GroupList* g = gUserManager.LockGroupList(LOCK_R); 756 LicqGroup* g = gUserManager.FetchGroup(group, LOCK_R); 757 if (g == NULL) 758 { 759 gUserManager.DropUser(u); 760 return true; 761 } 757 762 QString warning(tr("Are you sure you want to remove\n%1 (%2)\nfrom the '%3' group?") 758 763 .arg(QString::fromUtf8(u->GetAlias())) 759 .arg(u->IdString()).arg(QString::fromLocal8Bit( (*g)[group - 1])));760 gUserManager. UnlockGroupList();764 .arg(u->IdString()).arg(QString::fromLocal8Bit(g->name().c_str()))); 765 gUserManager.DropGroup(g); 761 766 gUserManager.DropUser(u); 762 767 if (QueryYesNo(parent, warning)) 763 768 { 764 769 gUserManager.RemoveUserFromGroup(id.toLatin1(), ppid, group); 765 766 // The daemon does not send an update when group membership changes767 // so tell the contactList it needs to update768 myContactList->updateUser(id, ppid);769 770 return true; 770 771 } -
branches/qt4-gui_group/src/core/mainwin.cpp
r6200 r6259 773 773 myUserGroupsBox->addItem(LicqStrings::getSystemGroupName(GROUP_ALL_USERS)); 774 774 775 GroupList* g = gUserManager.LockGroupList(LOCK_R); 776 for (unsigned short i = 0; i < g->size(); i++) 777 { 778 myUserGroupsBox->addItem(QString::fromLocal8Bit((*g)[i])); 779 } 780 gUserManager.UnlockGroupList(); 775 FOR_EACH_GROUP_START_SORTED(LOCK_R) 776 { 777 myUserGroupsBox->addItem(QString::fromLocal8Bit(pGroup->name().c_str())); 778 } 779 FOR_EACH_GROUP_END 781 780 782 781 for (unsigned short i = 1; i < NUM_GROUPS_SYSTEM_ALL; i++) -
branches/qt4-gui_group/src/core/systemmenu.cpp
r6152 r6259 302 302 delete a; 303 303 304 GroupList* g = gUserManager.LockGroupList(LOCK_R); 305 for (unsigned int i = 0; i < g->size(); ++i) 304 FOR_EACH_GROUP_START_SORTED(LOCK_R) 306 305 { 307 QString name = QString::fromLocal8Bit( (*g)[i]);306 QString name = QString::fromLocal8Bit(pGroup->name().c_str()); 308 307 309 308 a = myUserGroupActions->addAction(name); 310 a->setData( i + 1);309 a->setData(pGroup->id()); 311 310 a->setCheckable(true); 312 311 313 312 myGroupMenu->insertAction(myGroupSeparator, a); 314 313 } 315 gUserManager.UnlockGroupList();314 FOR_EACH_GROUP_END 316 315 } 317 316 -
branches/qt4-gui_group/src/core/usermenu.cpp
r6097 r6259 204 204 delete a; 205 205 206 GroupList* g = gUserManager.LockGroupList(LOCK_R); 207 for (unsigned int i = 0; i < g->size(); ++i) 208 { 209 QString name = QString::fromLocal8Bit((*g)[i]); 206 FOR_EACH_GROUP_START_SORTED(LOCK_R) 207 { 208 QString name = QString::fromLocal8Bit(pGroup->name().c_str()); 210 209 211 210 a = myUserGroupActions->addAction(name); 212 a->setData( i + 1);211 a->setData(pGroup->id()); 213 212 a->setCheckable(true); 214 213 215 214 a = myServerGroupActions->addAction(name); 216 a->setData( i + 1);215 a->setData(pGroup->id()); 217 216 a->setCheckable(true); 218 217 } 219 gUserManager.UnlockGroupList();218 FOR_EACH_GROUP_END 220 219 221 220 // Add groups to menu -
branches/qt4-gui_group/src/dialogs/editgrpdlg.cpp
r6210 r6259 127 127 } 128 128 129 unsigned short EditGrpDlg::currentGroupId() const 130 { 131 if (lstGroups->currentItem() == NULL) 132 return 0; 133 134 unsigned short groupId = lstGroups->currentItem()->data(Qt::UserRole).toUInt(); 135 return groupId; 136 } 137 138 void EditGrpDlg::setCurrentGroupId(unsigned short groupId) 139 { 140 for (int i = 0; i < lstGroups->count(); ++i) 141 if (lstGroups->item(i)->data(Qt::UserRole).toUInt() == groupId) 142 { 143 lstGroups->setCurrentRow(i); 144 break; 145 } 146 } 147 129 148 void EditGrpDlg::RefreshList() 130 149 { 150 unsigned short groupId = currentGroupId(); 131 151 lstGroups->clear(); 132 152 133 153 const QString allUsers = LicqStrings::getSystemGroupName(GROUP_ALL_USERS); 134 135 lstGroups->addItem(allUsers); 154 QListWidgetItem* item = new QListWidgetItem(allUsers); 155 item->setData(Qt::UserRole, 0); 156 lstGroups->addItem(item); 136 157 137 158 if (gUserManager.DefaultGroup() == GROUP_ALL_USERS) … … 141 162 nfoNewUser->setText(allUsers); 142 163 143 GroupList* g = gUserManager.LockGroupList(LOCK_R); 144 for (unsigned short i = 0; i < g->size(); i++) 164 FOR_EACH_GROUP_START_SORTED(LOCK_R) 145 165 { 146 lstGroups->addItem(QString::fromLocal8Bit((*g)[i])); 147 148 if (gUserManager.DefaultGroup() == i + 1) 149 nfoDefault->setText(QString::fromLocal8Bit((*g)[i])); 150 151 if (gUserManager.NewUserGroup() == i + 1) 152 nfoNewUser->setText(QString::fromLocal8Bit((*g)[i])); 166 QString name = QString::fromLocal8Bit(pGroup->name().c_str()); 167 item = new QListWidgetItem(name); 168 item->setData(Qt::UserRole, pGroup->id()); 169 lstGroups->addItem(item); 170 171 if (gUserManager.DefaultGroup() == pGroup->id()) 172 nfoDefault->setText(name); 173 174 if (gUserManager.NewUserGroup() == pGroup->id()) 175 nfoNewUser->setText(name); 153 176 } 154 gUserManager.UnlockGroupList(); 177 FOR_EACH_GROUP_END 178 179 setCurrentGroupId(groupId); 155 180 } 156 181 … … 162 187 case LIST_GROUP_REMOVED: 163 188 case LIST_GROUP_CHANGED: 189 case LIST_GROUP_REORDERED: 164 190 165 191 case LIST_INVALIDATE: … … 173 199 void EditGrpDlg::slot_add() 174 200 { 175 gUserManager.AddGroup(strdup(tr("noname").toLocal8Bit())); 176 RefreshList(); 177 lstGroups->setCurrentRow(lstGroups->count()-1); 178 slot_edit(); 179 } 180 181 182 void EditGrpDlg::slot_remove() 183 { 184 int n = lstGroups->currentRow(); 185 // don't allow the default group #0 "All Users" to be deleted 186 // don't try to delete if there is no current Item (currentItem() == -1) 187 if (n < 1) return; 188 189 GroupList* g = gUserManager.LockGroupList(LOCK_R); 190 QString warning(tr("Are you sure you want to remove\n" 191 "the group '%1'?").arg(QString::fromLocal8Bit((*g)[n-1]))); 192 gUserManager.UnlockGroupList(); 193 194 if (QueryYesNo(this, warning)) 195 { 196 gUserManager.RemoveGroup(n); 197 RefreshList(); 198 lstGroups->setCurrentRow(n - 1); 199 } 200 } 201 202 203 void EditGrpDlg::slot_up() 204 { 205 int n = lstGroups->currentRow() - 1; 206 if (n <= 0) return; 207 gUserManager.SwapGroups(n + 1, n); 208 RefreshList(); 209 lstGroups->setCurrentRow(n); 210 } 211 212 213 void EditGrpDlg::slot_down() 214 { 215 int n = lstGroups->currentRow() - 1; 216 if (n < 0 /* || n == max */) return; 217 gUserManager.SwapGroups(n + 1, n + 2); 218 RefreshList(); 219 if (n + 2 >= int(lstGroups->count())) 220 lstGroups->setCurrentRow(lstGroups->count() - 1); 221 else 222 lstGroups->setCurrentRow(n + 2); 223 } 224 225 226 void EditGrpDlg::slot_default() 227 { 228 int n = lstGroups->currentRow(); 229 if (n == -1) return; 230 gUserManager.SetDefaultGroup(n); 231 RefreshList(); 232 lstGroups->setCurrentRow(n); 233 } 234 235 void EditGrpDlg::slot_newuser() 236 { 237 int n = lstGroups->currentRow(); 238 if (n == -1 ) return; 239 gUserManager.SetNewUserGroup(n); 240 RefreshList(); 241 lstGroups->setCurrentRow(n); 242 } 243 244 void EditGrpDlg::slot_edit() 245 { 246 int n = lstGroups->currentRow() - 1; 247 if (n < 0) return; 201 // Don't add group until user has had a chance to set a name for it 202 myEditGroupId = 0; 203 lstGroups->setCurrentRow(-1); 204 248 205 btnSave->setEnabled(true); 249 206 btnDone->setEnabled(false); 250 207 edtName->setEnabled(true); 251 GroupList* g = gUserManager.LockGroupList(LOCK_R); 252 edtName->setText( QString::fromLocal8Bit((*g)[n]));208 209 edtName->setText(tr("noname")); 253 210 edtName->setFocus(); 254 gUserManager.UnlockGroupList();255 m_nEditGrp = n + 1;256 211 btnEdit->setText(tr("Cancel")); 257 212 disconnect(btnEdit, SIGNAL(clicked()), this, SLOT(slot_edit())); 258 213 connect(btnEdit, SIGNAL(clicked()), SLOT(slot_editcancel())); 259 214 lstGroups->setEnabled(false); 260 } 261 215 btnSave->setDefault(true); 216 } 217 218 void EditGrpDlg::slot_remove() 219 { 220 unsigned short groupId = currentGroupId(); 221 if (groupId == 0) 222 return; 223 224 QString warning(tr("Are you sure you want to remove\n" 225 "the group '%1'?").arg(lstGroups->currentItem()->text())); 226 227 if (QueryYesNo(this, warning)) 228 { 229 gUserManager.RemoveGroup(groupId); 230 RefreshList(); 231 } 232 } 233 234 void EditGrpDlg::moveGroup(int delta) 235 { 236 unsigned short groupId = currentGroupId(); 237 if (groupId == 0) 238 return; 239 240 LicqGroup* group = gUserManager.FetchGroup(groupId, LOCK_R); 241 if (group == NULL) 242 return; 243 unsigned short oldSortIndex = group->sortIndex(); 244 gUserManager.DropGroup(group); 245 246 if (delta + oldSortIndex < 0) 247 return; 248 249 gUserManager.ModifyGroupSorting(groupId, oldSortIndex + delta); 250 RefreshList(); 251 } 252 253 void EditGrpDlg::slot_up() 254 { 255 moveGroup(-1); 256 } 257 258 void EditGrpDlg::slot_down() 259 { 260 moveGroup(1); 261 } 262 263 void EditGrpDlg::slot_default() 264 { 265 gUserManager.SetDefaultGroup(currentGroupId()); 266 RefreshList(); 267 } 268 269 void EditGrpDlg::slot_newuser() 270 { 271 gUserManager.SetNewUserGroup(currentGroupId()); 272 RefreshList(); 273 } 274 275 void EditGrpDlg::slot_edit() 276 { 277 myEditGroupId = currentGroupId(); 278 if (myEditGroupId == 0) 279 return; 280 281 btnSave->setEnabled(true); 282 btnDone->setEnabled(false); 283 edtName->setEnabled(true); 284 285 edtName->setText(lstGroups->currentItem()->text()); 286 edtName->setFocus(); 287 btnEdit->setText(tr("Cancel")); 288 disconnect(btnEdit, SIGNAL(clicked()), this, SLOT(slot_edit())); 289 connect(btnEdit, SIGNAL(clicked()), SLOT(slot_editcancel())); 290 lstGroups->setEnabled(false); 291 btnSave->setDefault(true); 292 } 262 293 263 294 void EditGrpDlg::slot_editok() 264 295 { 265 int n = lstGroups->currentRow(); 266 gUserManager.RenameGroup(m_nEditGrp, edtName->text().toLocal8Bit()); 267 RefreshList(); 268 296 if (myEditGroupId == 0) 297 myEditGroupId = gUserManager.AddGroup(edtName->text().toLocal8Bit().data()); 298 else 299 gUserManager.RenameGroup(myEditGroupId, edtName->text().toLocal8Bit().data()); 300 RefreshList(); 301 setCurrentGroupId(myEditGroupId); 302 303 btnSave->setDefault(false); 269 304 lstGroups->setEnabled(true); 270 305 btnEdit->setText(tr("Edit Name")); … … 275 310 disconnect(btnEdit, SIGNAL(clicked()), this, SLOT(slot_editok())); 276 311 connect(btnEdit, SIGNAL(clicked()), SLOT(slot_edit())); 277 lstGroups->setCurrentRow(n); 278 } 279 312 } 280 313 281 314 void EditGrpDlg::slot_editcancel() 282 315 { 316 btnSave->setDefault(false); 283 317 lstGroups->setEnabled(true); 284 318 btnEdit->setText(tr("Edit Name")); -
branches/qt4-gui_group/src/dialogs/editgrpdlg.h
r6209
