Changeset 6200

Show
Ignore:
Timestamp:
05/25/08 06:25:18 (8 months ago)
Author:
flynd
Message:

Use new group subsignals from daemon. Removed some workarounds no longer needed.

Location:
trunk/qt4-gui/src
Files:
8 modified

Legend:

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

    r6150 r6200  
    2121#include "contactgroup.h" 
    2222 
     23#include <licq_user.h> 
     24 
    2325#include "contactbar.h" 
    2426#include "contactuser.h" 
     
    5557  for (int i = 0; i < 3; ++i) 
    5658    delete myBars[i]; 
     59} 
     60 
     61void ContactGroup::update() 
     62{ 
     63  GroupList* g = gUserManager.LockGroupList(LOCK_R); 
     64  myName = QString::fromLocal8Bit((*g)[myGroupId-1]); 
     65  gUserManager.UnlockGroupList(); 
     66 
     67  emit dataChanged(this); 
    5768} 
    5869 
     
    198209    return false; 
    199210 
    200   if (value.toString() == myName) 
     211  QString newName = value.toString(); 
     212  if (newName == myName) 
    201213    return true; 
    202214 
    203   myName = value.toString(); 
    204   gUserManager.RenameGroup(myGroupId, myName.toLocal8Bit()); 
    205  
    206   // Daemon doesn't signal when groups change so trigger update from here 
    207   emit dataChanged(this); 
     215  // Don't save new name here, daemon will signal us when name has changed 
     216  gUserManager.RenameGroup(myGroupId, newName.toLocal8Bit()); 
    208217 
    209218  return true; 
  • trunk/qt4-gui/src/contactlist/contactgroup.h

    r6150 r6200  
    5656   */ 
    5757  virtual ~ContactGroup(); 
     58 
     59  /** 
     60   * Group data in daemon has changed and needs to be refetched 
     61   */ 
     62  void update(); 
    5863 
    5964  /** 
  • trunk/qt4-gui/src/contactlist/contactlist.cpp

    r6198 r6200  
    5656} 
    5757 
    58 ContactListModel::~ContactListModel() 
    59 { 
    60   // Delete all users and groups 
    61   clear(); 
    62  
    63   // Delete the system groups 
    64   for (unsigned long i = 0; i < NUM_GROUPS_SYSTEM_ALL; ++i) 
    65     delete mySystemGroups[i]; 
    66 } 
    67  
    6858ContactGroup* ContactListModel::createGroup(unsigned short id, QString name) 
    6959{ 
     
    7666} 
    7767 
     68ContactListModel::~ContactListModel() 
     69{ 
     70  // Delete all users and groups 
     71  clear(); 
     72 
     73  // Delete the system groups 
     74  for (unsigned long i = 0; i < NUM_GROUPS_SYSTEM_ALL; ++i) 
     75    delete mySystemGroups[i]; 
     76} 
     77 
    7878void ContactListModel::listUpdated(CICQSignal* sig) 
    7979{ 
    8080  switch(sig->SubSignal()) 
    8181  { 
    82     case LIST_ALL: 
     82    case LIST_INVALIDATE: 
    8383      reloadAll(); 
    8484      break; 
    8585 
    86     case LIST_ADD: 
     86    case LIST_CONTACT_ADDED: 
    8787    { 
    8888      ICQUser* u = gUserManager.FetchUser(sig->Id(), sig->PPID(), LOCK_R); 
     
    9696      break; 
    9797    } 
    98     case LIST_REMOVE: 
     98    case LIST_CONTACT_REMOVED: 
    9999      removeUser(sig->Id(), sig->PPID()); 
    100100      break; 
     101 
     102    case LIST_GROUP_ADDED: 
     103    { 
     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(); 
     109 
     110      beginInsertRows(QModelIndex(), myUserGroups.size(), myUserGroups.size()); 
     111      myUserGroups.append(newGroup); 
     112      endInsertRows(); 
     113      break; 
     114    } 
     115 
     116    case LIST_GROUP_REMOVED: 
     117    { 
     118      unsigned short gid = sig->Argument(); 
     119 
     120      for (int i = 0; i < myUserGroups.size(); ++i) 
     121      { 
     122        ContactGroup* group = myUserGroups.at(i); 
     123        if (group->groupId() == gid) 
     124        { 
     125          beginRemoveRows(QModelIndex(), i, i); 
     126          myUserGroups.removeAll(group); 
     127          endRemoveRows(); 
     128          delete group; 
     129        } 
     130      } 
     131      break; 
     132    } 
     133 
     134    case LIST_GROUP_CHANGED: 
     135    { 
     136      unsigned short gid = sig->Argument(); 
     137 
     138      for (int i = 0; i < myUserGroups.size(); ++i) 
     139      { 
     140        ContactGroup* group = myUserGroups.at(i); 
     141        if (group->groupId() == gid) 
     142          group->update(); 
     143      } 
     144      break; 
     145    } 
    101146  } 
    102147} 
  • trunk/qt4-gui/src/core/groupmenu.cpp

    r6154 r6200  
    8989    delete a; 
    9090 
    91   ContactListModel* list = LicqGui::instance()->contactList(); 
    92   int groupCount = list->rowCount(QModelIndex()); 
     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]); 
    9395 
    94   for (int i = 0; i < groupCount; ++i) 
    95   { 
    96     QModelIndex groupIndex = list->index(i, 0, QModelIndex()); 
    97     unsigned int groupId = groupIndex.data(ContactListModel::GroupIdRole).toUInt(); 
     96    a = myUserGroupActions->addAction(name); 
     97    a->setData(i + 1); 
    9898 
    99     // Don't add system groups or other users group 
    100     if (groupId == 0 || groupId >= ContactListModel::SystemGroupOffset) 
    101       continue; 
    102  
    103     a = myUserGroupActions->addAction(groupIndex.data(ContactListModel::NameRole).toString()); 
    104     a->setData(groupId); 
     99    myGroupsMenu->insertAction(myGroupSeparator, a); 
    105100  } 
     101  gUserManager.UnlockGroupList(); 
    106102 
    107103  // Add groups to menu 
     
    139135  // Model uses group+1 so substract one before sending to daemon 
    140136  gUserManager.SwapGroups(myGroupId, myGroupId - 1); 
    141  
    142   // Daemon doesn't notify us when groups change so notify model from here 
    143   LicqGui::instance()->contactList()->reloadAll(); 
    144   LicqGui::instance()->mainWindow()->updateGroups(); 
    145137} 
    146138 
     
    149141  // Model uses group+1 so substract one before sending to daemon 
    150142  gUserManager.SwapGroups(myGroupId, myGroupId + 1); 
    151  
    152   // Daemon doesn't notify us when groups change so notify model from here 
    153   LicqGui::instance()->contactList()->reloadAll(); 
    154   LicqGui::instance()->mainWindow()->updateGroups(); 
    155143} 
    156144 
     
    165153 
    166154  gUserManager.RemoveGroup(myGroupId); 
    167  
    168   // Daemon doesn't notify us when groups change so notify model from here 
    169   LicqGui::instance()->contactList()->reloadAll(); 
    170   LicqGui::instance()->mainWindow()->updateGroups(); 
    171155} 
    172156 
  • trunk/qt4-gui/src/core/licqgui.cpp

    r6190 r6200  
    13891389  switch (sig->SubSignal()) 
    13901390  { 
    1391     case LIST_ALL: 
    1392       // Handled by ContactListModel 
    1393       break; 
    1394  
    13951391    case LIST_ADD: 
    13961392    { 
     
    14591455    } 
    14601456 
     1457    case LIST_ALL: 
     1458    case LIST_GROUP_ADDED: 
     1459    case LIST_GROUP_REMOVED: 
     1460    case LIST_GROUP_CHANGED: 
     1461      myMainWindow->updateGroups(); 
     1462      myUserMenu->updateGroups(); 
     1463      myGroupMenu->updateGroups(); 
     1464      break; 
    14611465  } 
    14621466} 
  • trunk/qt4-gui/src/core/mainwin.cpp

    r6188 r6200  
    765765  if (!initial) 
    766766  { 
    767     // Daemon does not send an update when groups change so tell contactList it 
    768     // needs to update 
    769     LicqGui::instance()->contactList()->reloadAll(); 
    770  
    771767    // update group list in user and system menus 
    772     LicqGui::instance()->userMenu()->updateGroups(); 
    773768    mySystemMenu->updateGroups(); 
    774769  } 
  • trunk/qt4-gui/src/dialogs/editgrpdlg.cpp

    r5892 r6200  
    115115  connect(btnNewUser, SIGNAL(clicked()), SLOT(slot_newuser())); 
    116116  connect(btnEdit, SIGNAL(clicked()), SLOT(slot_edit())); 
    117   connect(btnDone, SIGNAL(clicked()), SLOT(slot_done())); 
     117  connect(btnDone, SIGNAL(clicked()), SLOT(close())); 
    118118  connect(edtName, SIGNAL(returnPressed()), SLOT(slot_editok())); 
    119119  connect(btnSave, SIGNAL(clicked()), SLOT(slot_editok())); 
     
    269269  connect(btnEdit, SIGNAL(clicked()), SLOT(slot_edit())); 
    270270} 
    271  
    272  
    273 void EditGrpDlg::slot_done() 
    274 { 
    275   // Daemon doesn't notify when groups change so tell mainwin to update 
    276   gMainWindow->updateGroups(); 
    277  
    278   close(); 
    279 } 
  • trunk/qt4-gui/src/dialogs/editgrpdlg.h

    r5837 r6200  
    7070  void slot_default(); 
    7171  void slot_newuser(); 
    72   void slot_done(); 
    7372}; 
    7473