Show
Ignore:
Timestamp:
06/14/08 03:47:03 (6 months ago)
Author:
flynd
Message:

Updated to work with and take advantage of new group handling. Contact list model is now properly updated from signals when groups change.

Location:
trunk/qt4-gui/src/contactlist
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/qt4-gui/src/contactlist/contactgroup.cpp

    r6200 r6283  
    3636{ 
    3737  if (myGroupId != 0) 
    38   { 
    39     mySortKey.sprintf("%10i", myGroupId); 
    40   } 
     38    mySortKey = myGroupId; 
    4139  else 
    42   { 
    4340    // 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 
     49ContactGroup::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{ 
    4757  for (int i = 0; i < 3; ++i) 
    4858    myBars[i] = new ContactBar(static_cast<ContactListModel::SubGroupType>(i), this); 
     
    6171void ContactGroup::update() 
    6272{ 
    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 
     88void 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); 
    68100} 
    69101 
     
    214246 
    215247  // 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()); 
    217249 
    218250  return true; 
  • trunk/qt4-gui/src/contactlist/contactgroup.h

    r6200 r6283  
    2929#include "contactlist.h" 
    3030 
     31class LicqGroup; 
     32 
    3133namespace LicqQtGui 
    3234{ 
     
    5052   * @param name Group name 
    5153   */ 
    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); 
    5362 
    5463  /** 
     
    157166  virtual bool setData(const QVariant& value, int role = ContactListModel::NameRole); 
    158167 
     168  /** 
     169   * Update sort key for this group from daemon 
     170   */ 
     171  void updateSortKey(); 
     172 
    159173signals: 
    160174  /** 
     
    171185  unsigned short myGroupId; 
    172186  QString myName; 
    173   QString mySortKey; 
     187  unsigned short mySortKey; 
    174188  int myEvents; 
    175189  QList<ContactUser*> myUsers; 
  • trunk/qt4-gui/src/contactlist/contactlist.cpp

    r6270 r6283  
    103103    { 
    104104      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); 
    109106 
    110107      beginInsertRows(QModelIndex(), myUserGroups.size(), myUserGroups.size()); 
     
    144141      break; 
    145142    } 
     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    } 
    146157  } 
    147158} 
     
    250261 
    251262  // Add all groups 
    252   GroupList* g = gUserManager.LockGroupList(LOCK_R); 
    253   beginInsertRows(QModelIndex(), 0, g->size()); 
     263  beginInsertRows(QModelIndex(), 0, gUserManager.NumGroups() + 1); 
    254264 
    255265  ContactGroup* newGroup = createGroup(0, tr("Other Users")); 
    256266  myUserGroups.append(newGroup); 
    257267 
    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 
    263278 
    264279  endInsertRows(); 
    265   gUserManager.UnlockGroupList(); 
    266280 
    267281  // Add all users 
     
    307321    unsigned short gid = group->groupId(); 
    308322    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()); 
    310324    updateUserGroup(user, group, i, shouldBeMember); 
    311325  } 
  • trunk/qt4-gui/src/contactlist/contactlist.h

    r6197 r6283  
    7474    ItemTypeRole = Qt::UserRole,        // Type of item (one of enum ItemType) 
    7575    NameRole,                           // Item name (alias for UserItems) 
    76     SortPrefixRole,                     // Primary sort index 
    77     SortRole,                           // Secondary sort index 
     76    SortPrefixRole,                     // Primary sort index (UserItems only) 
     77    SortRole,                           // Sort index (secondary index for UserItems, only index for GroupItems) 
    7878    UnreadEventsRole,                   // Number of unread events 
    7979    EventSubCommandRole,                // Type of event (UserItems only) 
     
    389389   * 
    390390   * @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) 
    392392   * @return The created group 
    393393   */ 
    394   ContactGroup* createGroup(unsigned short id, QString name); 
     394  ContactGroup* createGroup(unsigned short id, QString name = QString()); 
    395395 
    396396  /**