| 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); |
| 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 | |
| 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 | } |