Show
Ignore:
Timestamp:
06/11/08 08:25:24 (6 months ago)
Author:
eugene
Message:

Applied the latest version of flynd's qt4-gui patch.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/qt4-gui_group/src/dialogs/editgrpdlg.cpp

    r6210 r6259  
    127127} 
    128128 
     129unsigned 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 
     138void 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 
    129148void EditGrpDlg::RefreshList() 
    130149{ 
     150  unsigned short groupId = currentGroupId(); 
    131151  lstGroups->clear(); 
    132152 
    133153  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); 
    136157 
    137158  if (gUserManager.DefaultGroup() == GROUP_ALL_USERS) 
     
    141162    nfoNewUser->setText(allUsers); 
    142163 
    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) 
    145165  { 
    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); 
    153176  } 
    154   gUserManager.UnlockGroupList(); 
     177  FOR_EACH_GROUP_END 
     178 
     179  setCurrentGroupId(groupId); 
    155180} 
    156181 
     
    162187    case LIST_GROUP_REMOVED: 
    163188    case LIST_GROUP_CHANGED: 
     189    case LIST_GROUP_REORDERED: 
    164190 
    165191    case LIST_INVALIDATE: 
     
    173199void EditGrpDlg::slot_add() 
    174200{ 
    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 
    248205  btnSave->setEnabled(true); 
    249206  btnDone->setEnabled(false); 
    250207  edtName->setEnabled(true); 
    251   GroupList* g = gUserManager.LockGroupList(LOCK_R); 
    252   edtName->setText(QString::fromLocal8Bit((*g)[n])); 
     208 
     209  edtName->setText(tr("noname")); 
    253210  edtName->setFocus(); 
    254   gUserManager.UnlockGroupList(); 
    255   m_nEditGrp = n + 1; 
    256211  btnEdit->setText(tr("Cancel")); 
    257212  disconnect(btnEdit, SIGNAL(clicked()), this, SLOT(slot_edit())); 
    258213  connect(btnEdit, SIGNAL(clicked()), SLOT(slot_editcancel())); 
    259214  lstGroups->setEnabled(false); 
    260 } 
    261  
     215  btnSave->setDefault(true); 
     216} 
     217 
     218void 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 
     234void 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 
     253void EditGrpDlg::slot_up() 
     254{ 
     255  moveGroup(-1); 
     256} 
     257 
     258void EditGrpDlg::slot_down() 
     259{ 
     260  moveGroup(1); 
     261} 
     262 
     263void EditGrpDlg::slot_default() 
     264{ 
     265  gUserManager.SetDefaultGroup(currentGroupId()); 
     266  RefreshList(); 
     267} 
     268 
     269void EditGrpDlg::slot_newuser() 
     270{ 
     271  gUserManager.SetNewUserGroup(currentGroupId()); 
     272  RefreshList(); 
     273} 
     274 
     275void 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} 
    262293 
    263294void EditGrpDlg::slot_editok() 
    264295{ 
    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); 
    269304  lstGroups->setEnabled(true); 
    270305  btnEdit->setText(tr("Edit Name")); 
     
    275310  disconnect(btnEdit, SIGNAL(clicked()), this, SLOT(slot_editok())); 
    276311  connect(btnEdit, SIGNAL(clicked()), SLOT(slot_edit())); 
    277   lstGroups->setCurrentRow(n); 
    278 } 
    279  
     312} 
    280313 
    281314void EditGrpDlg::slot_editcancel() 
    282315{ 
     316  btnSave->setDefault(false); 
    283317  lstGroups->setEnabled(true); 
    284318  btnEdit->setText(tr("Edit Name"));