I'm currently having trouble with writing my IRC client. When changing a user's channel status, and doing it my own self it updates fine. But when testing it with another client in a channel. Removing and adding statuses, the QListView model will not update the User's icons unless I move my mouse over the QListView. Currently I'm thinking the way I have it right now is just slow as hell and what not. Is there a better way of optimising the searching of a user?

Qt Code:
  1. void
  2. ChannelTab::slotOnMode(const QString &from, const QString &channel, const QString &mode, const QString &nick)
  3. {
  4. if (name() != channel) {
  5. return;
  6. }
  7.  
  8. enum {
  9. None,
  10. Give,
  11. Take
  12. };
  13. int state = None;
  14.  
  15. QModelIndex index;
  16. Aki::Irc::User *user = 0;
  17.  
  18. //Aki::Irc::User *user = d->userList->model()->data(d->userList->currentIndex(), NickListModel::IrcUserRole)
  19. // .value<Aki::Irc::User*>();
  20.  
  21. for (int i = 0; i < d->userList->count(); ++i) {
  22. index = d->userList->model()->index(i, 0);
  23. user = d->userList->model()->data(index, NickListModel::IrcUserRole).value<Aki::Irc::User*>();
  24. if (user->nick() == nick) {
  25. kDebug() << "found";
  26. break;
  27. }
  28. }
  29.  
  30. if (!user) {
  31. return;
  32. }
  33.  
  34. QString modes = user->modes();
  35. bool fromYou = from == d->socket->currentNick();
  36. bool toYou = nick == d->socket->currentNick();
  37.  
  38. foreach (QChar c, mode) {
  39. if (c == QChar('+')) {
  40. state = Give;
  41. kDebug() << "Give";
  42. } else if (c == QChar('-')) {
  43. state = Take;
  44. kDebug() << "Take";
  45. } else if (c == QChar('o')) {
  46. if (state == Give) {
  47. user->setModes(modes + c);
  48. d->userList->model()->setData(d->userList->currentIndex(),
  49. QVariant::fromValue<Aki::Irc::User*>(user),
  50. NickListModel::IrcUserRole);
  51. d->channelOutput->addMode(from, nick, c, toYou, fromYou);
  52. } else if (state == Take) {
  53. user->removeModes(c);
  54. d->userList->model()->setData(d->userList->currentIndex(),
  55. QVariant::fromValue<Aki::Irc::User*>(user),
  56. NickListModel::IrcUserRole);
  57. d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
  58. }
  59. } else if (c == QChar('v')) {
  60. if (state == Give) {
  61. user->setModes(modes + c);
  62. d->userList->model()->setData(d->userList->currentIndex(),
  63. QVariant::fromValue<Aki::Irc::User*>(user),
  64. NickListModel::IrcUserRole);
  65. d->channelOutput->addMode(from, nick, c, toYou, fromYou);
  66. } else if (state == Take) {
  67. user->removeModes(c);
  68. d->userList->model()->setData(d->userList->currentIndex(),
  69. QVariant::fromValue<Aki::Irc::User*>(user),
  70. NickListModel::IrcUserRole);
  71. d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
  72. }
  73. } else if (c == QChar('h')) {
  74. if (state == Give) {
  75. user->setModes(modes + c);
  76. d->userList->model()->setData(d->userList->currentIndex(),
  77. QVariant::fromValue<Aki::Irc::User*>(user),
  78. NickListModel::IrcUserRole);
  79. d->channelOutput->addMode(from, nick, c, toYou, fromYou);
  80. } else if (state == Take) {
  81. user->removeModes(c);
  82. d->userList->model()->setData(d->userList->currentIndex(),
  83. QVariant::fromValue<Aki::Irc::User*>(user),
  84. NickListModel::IrcUserRole);
  85. d->channelOutput->addRemoveMode(from, nick, c, toYou, fromYou);
  86. }
  87. }
  88. }
  89. }
To copy to clipboard, switch view to plain text mode