Show
Ignore:
Timestamp:
04/13/08 23:18:08 (8 months ago)
Author:
flynd
Message:

Allow editing contact alias and group names directly in the contact list.

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

Legend:

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

    r5885 r6148  
    161161      break; 
    162162 
     163    case Qt::EditRole: 
     164      return myName; 
     165 
    163166    case ContactListModel::ItemTypeRole: 
    164167      return ContactListModel::GroupItem; 
     
    185188  return QVariant(); 
    186189} 
     190 
     191bool ContactGroup::setData(const QVariant& value, int role) 
     192{ 
     193  if (role != Qt::EditRole || !value.isValid()) 
     194    return false; 
     195 
     196  // Don't allow system groups or "Other users" to be renamed this way 
     197  if (myGroupId == 0 || myGroupId >= ContactListModel::SystemGroupOffset) 
     198    return false; 
     199 
     200  if (value.toString() == myName) 
     201    return true; 
     202 
     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); 
     208 
     209  return true; 
     210} 
  • trunk/qt4-gui/src/contactlist/contactgroup.h

    r5885 r6148  
    143143  QVariant data(int column, int role) const; 
    144144 
     145  /** 
     146   * Set data for this group 
     147   * 
     148   * @param value New value to set 
     149   * @param role Role to set 
     150   * @return True if any data was changed 
     151   */ 
     152  virtual bool setData(const QVariant& value, int role = Qt::EditRole); 
     153 
    145154signals: 
    146155  /** 
  • trunk/qt4-gui/src/contactlist/contactitem.cpp

    r5837 r6148  
    2727{ 
    2828} 
     29 
     30bool ContactItem::setData(const QVariant& /* value */, int /* role */) 
     31{ 
     32  return false; 
     33} 
  • trunk/qt4-gui/src/contactlist/contactitem.h

    r5837 r6148  
    6666  virtual QVariant data(int column, int role) const = 0; 
    6767 
     68  /** 
     69   * Set data for this item 
     70   * 
     71   * @param value New value to set 
     72   * @param role Role to set 
     73   * @return True if any data was changed 
     74   */ 
     75  virtual bool setData(const QVariant& value, int role = Qt::EditRole); 
     76 
    6877private: 
    6978  ContactListModel::ItemType myItemType; 
  • trunk/qt4-gui/src/contactlist/contactlist.cpp

    r5892 r6148  
    402402    return Qt::ItemIsEnabled; 
    403403 
    404   return Qt::ItemIsEnabled | Qt::ItemIsSelectable; 
     404  Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable; 
     405 
     406  ItemType itemType = static_cast<ContactItem*>(index.internalPointer())->itemType(); 
     407 
     408  // Only editing of alias for contacts 
     409  if (itemType == UserItem && Config::ContactList::instance()->columnFormat(index.column()) == "%a") 
     410    f |= Qt::ItemIsEditable; 
     411 
     412  // Group names are editable in first column unless it's a system group 
     413  if (itemType == GroupItem && index.column() == 0 && index.row() != 0 && index.row() < myUserGroups.size()) 
     414    f |= Qt::ItemIsEditable; 
     415 
     416  return f; 
    405417} 
    406418 
     
    449461  return QModelIndex(); 
    450462} 
     463 
     464bool ContactListModel::setData(const QModelIndex& index, const QVariant& value, int role) 
     465{ 
     466  return static_cast<ContactItem*>(index.internalPointer())->setData(value, role); 
     467} 
  • trunk/qt4-gui/src/contactlist/contactlist.h

    r5885 r6148  
    291291 
    292292  /** 
     293   * Set item data 
     294   * 
     295   * @param index Index for the item to update 
     296   * @param value Value to set 
     297   * @param role Role to update 
     298   */ 
     299  virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); 
     300 
     301  /** 
    293302   * Get index for a specific user 
    294303   * 
  • trunk/qt4-gui/src/contactlist/contactuser.cpp

    r5837 r6148  
    5252  return myUserData->data(column, role); 
    5353} 
     54 
     55bool ContactUser::setData(const QVariant& value, int role) 
     56{ 
     57  return myUserData->setData(value, role); 
     58} 
  • trunk/qt4-gui/src/contactlist/contactuser.h

    r5885 r6148  
    9999  QVariant data(int column, int role) const; 
    100100 
     101  /** 
     102   * Set data for this user 
     103   * 
     104   * @param value New value to set 
     105   * @param role Role to set 
     106   * @return True if any data was changed 
     107   */ 
     108  virtual bool setData(const QVariant& value, int role = Qt::EditRole); 
     109 
    101110private: 
    102111  ContactUserData* myUserData; 
  • trunk/qt4-gui/src/contactlist/contactuserdata.cpp

    r6132 r6148  
    400400  bool hasChanged = false; 
    401401 
     402  myAlias = QString::fromUtf8(licqUser->GetAlias()); 
     403 
    402404  for (unsigned short i = 0; i < Config::ContactList::instance()->columnCount(); i++) 
    403405  { 
     
    410412    free(temp); 
    411413 
    412     temp = licqUser->usprintf("%a"); 
    413     QString alias = QString::fromUtf8(temp); 
    414     free(temp); 
    415  
    416     newStr.replace("@_USER_ALIAS_@", alias); 
     414    newStr.replace("@_USER_ALIAS_@", myAlias); 
    417415 
    418416    if (newStr != myText[i]) 
     
    471469} 
    472470 
     471bool ContactUserData::setData(const QVariant& value, int role) 
     472{ 
     473  if (role != Qt::EditRole || !value.isValid()) 
     474    return false; 
     475 
     476  if (value.toString() == myAlias) 
     477    return true; 
     478 
     479  ICQUser* u = gUserManager.FetchUser(myId.toLatin1(), myPpid, LOCK_R); 
     480  if (u == NULL) 
     481    return false; 
     482 
     483  myAlias = value.toString(); 
     484  u->SetAlias(myAlias.toUtf8()); 
     485  u->SetKeepAliasOnUpdate(true); 
     486 
     487  // Daemon dosen't send signal when alias is changed so trigger update from here 
     488  updateText(u); 
     489  updateSorting(); 
     490 
     491  gUserManager.DropUser(u); 
     492 
     493  emit dataChanged(this); 
     494  return true; 
     495} 
     496 
    473497void ContactUserData::refresh() 
    474498{ 
     
    558582        return myText[column]; 
    559583      break; 
     584 
     585    case Qt::EditRole: 
     586      return myAlias; 
    560587 
    561588    case Qt::ToolTipRole: 
  • trunk/qt4-gui/src/contactlist/contactuserdata.h

    r5955 r6148  
    148148   */ 
    149149  QVariant data(int column, int role) const; 
     150 
     151  /** 
     152   * Set data for this user 
     153   * Currently only alias may be change this way 
     154   * 
     155   * @param value New value to set 
     156   * @param role Must be Qt::EditRole 
     157   * @return True if alias was changed 
     158   */ 
     159  virtual bool setData(const QVariant& value, int role = Qt::EditRole); 
    150160 
    151161signals: 
     
    241251  bool myUrgent; 
    242252  QString myText[4]; 
     253  QString myAlias; 
    243254  QList<ContactUser*> myUserInstances; 
    244255