QTfrontend/chatwidget.cpp
branchhedgeroid
changeset 6224 42b256eca362
parent 6055 88cfcd9161d3
parent 6223 cc3eb9b7230f
child 6226 3106add9a5bf
equal deleted inserted replaced
6055:88cfcd9161d3 6224:42b256eca362
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com>
       
     4  * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com>
       
     5  *
       
     6  * This program is free software; you can redistribute it and/or modify
       
     7  * it under the terms of the GNU General Public License as published by
       
     8  * the Free Software Foundation; version 2 of the License
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    18  */
       
    19 
       
    20 #include <QDesktopServices>
       
    21 #include <QTextBrowser>
       
    22 #include <QLineEdit>
       
    23 #include <QAction>
       
    24 #include <QTextDocument>
       
    25 #include <QDir>
       
    26 #include <QSettings>
       
    27 #include <QFile>
       
    28 #include <QTextStream>
       
    29 #include <QMenu>
       
    30 #include <QCursor>
       
    31 #include <QScrollBar>
       
    32 #include <QItemSelectionModel>
       
    33 #include <QStringList>
       
    34 
       
    35 #include "hwconsts.h"
       
    36 #include "SDLs.h"
       
    37 #include "gameuiconfig.h"
       
    38 #include "chatwidget.h"
       
    39 
       
    40 ListWidgetNickItem::ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored) : QListWidgetItem(nick)
       
    41 {
       
    42     this->aFriend = isFriend;
       
    43     this->isIgnored = isIgnored;
       
    44 }
       
    45 
       
    46 void ListWidgetNickItem::setFriend(bool isFriend)
       
    47 {
       
    48     this->aFriend = isFriend;
       
    49 }
       
    50 
       
    51 void ListWidgetNickItem::setIgnored(bool isIgnored)
       
    52 {
       
    53     this->isIgnored = isIgnored;
       
    54 }
       
    55 
       
    56 bool ListWidgetNickItem::isFriend()
       
    57 {
       
    58     return aFriend;
       
    59 }
       
    60 
       
    61 bool ListWidgetNickItem::ignored()
       
    62 {
       
    63     return isIgnored;
       
    64 }
       
    65 
       
    66 bool ListWidgetNickItem::operator< (const QListWidgetItem & other) const
       
    67 {
       
    68     // case in-sensitive comparison of the associated strings
       
    69     // chars that are no letters are sorted at the end of the list
       
    70 
       
    71     ListWidgetNickItem otherNick = const_cast<ListWidgetNickItem &>(dynamic_cast<const ListWidgetNickItem &>(other));
       
    72 
       
    73     // ignored always down
       
    74     if (isIgnored != otherNick.ignored())
       
    75         return !isIgnored;
       
    76 
       
    77     // friends always up
       
    78     if (aFriend != otherNick.isFriend())
       
    79         return aFriend;
       
    80 
       
    81     QString txt1 = text().toLower();
       
    82     QString txt2 = other.text().toLower();
       
    83 
       
    84     bool firstIsShorter = (txt1.size() < txt2.size());
       
    85     int len = firstIsShorter?txt1.size():txt2.size();
       
    86 
       
    87     for (int i = 0; i < len; i++)
       
    88     {
       
    89         if (txt1[i] == txt2[i])
       
    90             continue;
       
    91         if (txt1[i].isLetter() != txt2[i].isLetter())
       
    92             return txt1[i].isLetter();
       
    93         return (txt1[i] < txt2[i]);
       
    94     }
       
    95 
       
    96     return firstIsShorter;
       
    97 }
       
    98 
       
    99 const char* HWChatWidget::STYLE = 
       
   100 "\
       
   101 a { color:#c8c8ff; }\
       
   102 .nick { text-decoration: none; }\
       
   103 .UserChat .nick { color:#ffec20; }\
       
   104 .FriendChat { color: #08e008; }\
       
   105 .FriendChat .nick { color: #20ff20; }\
       
   106 .UserJoin { color: #c0c0c0; }\
       
   107 .UserJoin .nick { color: #d0d0d0; }\
       
   108 .FriendJoin { color: #c0e0c0; }\
       
   109 .FriendJoin .nick { color: #d0f0d0; }\
       
   110 .UserAction { color: #ff80ff; }\
       
   111 .UserAction .nick { color: #ffa0ff; }\
       
   112 .FriendAction { color: #ff00ff; }\
       
   113 .FriendAction .nick { color: #ff30ff; }\
       
   114 .Error { color: #ff0000 }\
       
   115 .Warning { color: #ff8000 }\
       
   116 .Notice { color: #fefefe }\
       
   117 ";
       
   118 
       
   119 HWChatWidget::HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify) :
       
   120   QWidget(parent),
       
   121   mainLayout(this)
       
   122 {
       
   123     this->gameSettings = gameSettings;
       
   124     this->sdli = sdli;
       
   125     this->notify = notify;
       
   126     if(notify && gameSettings->value("frontend/sound", true).toBool()) {
       
   127         QFile tmpfile;
       
   128         sdli->SDLMusicInit();
       
   129         for(int i=0;i<4;i++) {
       
   130             tmpfile.setFileName(cfgdir->absolutePath() + "/Data/Sounds/voices/Classic/Hello.ogg");
       
   131             if (tmpfile.exists()) sound[i] = Mix_LoadWAV(QFileInfo(tmpfile).absoluteFilePath().toLocal8Bit().constData());
       
   132             else sound[i] = Mix_LoadWAV(QString(datadir->absolutePath() + 
       
   133                 "/Sounds/voices/Classic/Hello.ogg").toLocal8Bit().constData());
       
   134         }
       
   135     }
       
   136 
       
   137     mainLayout.setSpacing(1);
       
   138     mainLayout.setMargin(1);
       
   139     mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
       
   140     mainLayout.setColumnStretch(0, 76);
       
   141     mainLayout.setColumnStretch(1, 24);
       
   142 
       
   143     chatEditLine = new QLineEdit(this);
       
   144     chatEditLine->setMaxLength(300);
       
   145     connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
       
   146 
       
   147     mainLayout.addWidget(chatEditLine, 2, 0);
       
   148 
       
   149     chatText = new QTextBrowser(this);
       
   150     chatText->document()->setDefaultStyleSheet(STYLE);
       
   151     chatText->setMinimumHeight(20);
       
   152     chatText->setMinimumWidth(10);
       
   153     chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   154     chatText->setOpenLinks(false);
       
   155     connect(chatText, SIGNAL(anchorClicked(const QUrl&)),
       
   156         this, SLOT(linkClicked(const QUrl&)));
       
   157     mainLayout.addWidget(chatText, 0, 0, 2, 1);
       
   158 
       
   159     chatNicks = new QListWidget(this);
       
   160     chatNicks->setMinimumHeight(10);
       
   161     chatNicks->setMinimumWidth(10);
       
   162     chatNicks->setSortingEnabled(true);
       
   163     chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   164     chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
       
   165     connect(chatNicks, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
       
   166         this, SLOT(chatNickDoubleClicked(QListWidgetItem *)));
       
   167     connect(chatNicks, SIGNAL(currentRowChanged(int)),
       
   168         this, SLOT(chatNickSelected(int)));
       
   169 
       
   170     mainLayout.addWidget(chatNicks, 0, 1, 3, 1);
       
   171 
       
   172     acInfo = new QAction(QAction::tr("Info"), chatNicks);
       
   173     acInfo->setIcon(QIcon(":/res/info.png"));
       
   174     connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo()));
       
   175     acKick = new QAction(QAction::tr("Kick"), chatNicks);
       
   176     acKick->setIcon(QIcon(":/res/kick.png"));
       
   177     connect(acKick, SIGNAL(triggered(bool)), this, SLOT(onKick()));
       
   178     acBan = new QAction(QAction::tr("Ban"), chatNicks);
       
   179     acBan->setIcon(QIcon(":/res/ban.png"));
       
   180     connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onBan()));
       
   181     acFollow = new QAction(QAction::tr("Follow"), chatNicks);
       
   182     acFollow->setIcon(QIcon(":/res/follow.png"));
       
   183     connect(acFollow, SIGNAL(triggered(bool)), this, SLOT(onFollow()));
       
   184     acIgnore = new QAction(QAction::tr("Ignore"), chatNicks);
       
   185     acIgnore->setIcon(QIcon(":/res/ignore.png"));
       
   186     connect(acIgnore, SIGNAL(triggered(bool)), this, SLOT(onIgnore()));
       
   187     acFriend = new QAction(QAction::tr("Add friend"), chatNicks);
       
   188     acFriend->setIcon(QIcon(":/res/addfriend.png"));
       
   189     connect(acFriend, SIGNAL(triggered(bool)), this, SLOT(onFriend()));
       
   190 
       
   191     chatNicks->insertAction(0, acFriend);
       
   192     chatNicks->insertAction(0, acInfo);
       
   193     chatNicks->insertAction(0, acIgnore);
       
   194 
       
   195     showReady = false;
       
   196     setShowFollow(true);
       
   197 }
       
   198 
       
   199 void HWChatWidget::linkClicked(const QUrl & link)
       
   200 {
       
   201     if (link.scheme() == "http")
       
   202         QDesktopServices::openUrl(link);
       
   203     if (link.scheme() == "hwnick")
       
   204     {
       
   205         // decode nick
       
   206         const QString& nick = QString::fromUtf8(QByteArray::fromBase64(link.encodedQuery()));
       
   207         QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
       
   208         if (items.size() < 1)
       
   209             return;
       
   210         QMenu * popup = new QMenu(this);
       
   211         // selecting an item will automatically scroll there, so let's save old position
       
   212         QScrollBar * scrollBar = chatNicks->verticalScrollBar();
       
   213         int oldScrollPos = scrollBar->sliderPosition();
       
   214         // select the nick which we want to see the actions for
       
   215         chatNicks->setCurrentItem(items[0], QItemSelectionModel::Clear);
       
   216         // selecting an item will automatically scroll there, so let's save old position
       
   217         scrollBar->setSliderPosition(oldScrollPos);
       
   218         // load actions
       
   219         popup->addActions(chatNicks->actions());
       
   220         // display menu popup at mouse cursor position
       
   221         popup->popup(QCursor::pos());
       
   222     }
       
   223 }
       
   224 
       
   225 void HWChatWidget::setShowFollow(bool enabled)
       
   226 {
       
   227     if (enabled) {
       
   228         if (!(chatNicks->actions().contains(acFollow)))
       
   229             chatNicks->insertAction(acFriend, acFollow);
       
   230     }
       
   231     else {
       
   232         if (chatNicks->actions().contains(acFollow))
       
   233             chatNicks->removeAction(acFollow);
       
   234     }
       
   235 }
       
   236 
       
   237 void HWChatWidget::loadList(QStringList & list, const QString & file)
       
   238 {
       
   239     list.clear();
       
   240     QFile txt(cfgdir->absolutePath() + "/" + file);
       
   241     if(!txt.open(QIODevice::ReadOnly))
       
   242         return;
       
   243     QTextStream stream(&txt);
       
   244     stream.setCodec("UTF-8");
       
   245 
       
   246     while(!stream.atEnd())
       
   247     {
       
   248         QString str = stream.readLine();
       
   249         if(str.startsWith(";") || str.length() == 0)
       
   250             continue;
       
   251         list << str.trimmed();
       
   252     }
       
   253     //readd once we require newer Qt than 4.4
       
   254     //list.removeDuplicates();
       
   255     txt.close();
       
   256 }
       
   257 
       
   258 void HWChatWidget::saveList(QStringList & list, const QString & file)
       
   259 {
       
   260     QFile txt(cfgdir->absolutePath() + "/" + file);
       
   261     if(!txt.open(QIODevice::WriteOnly | QIODevice::Truncate))
       
   262         return;
       
   263     QTextStream stream(&txt);
       
   264     stream.setCodec("UTF-8");
       
   265 
       
   266     stream << "; this list is used by Hedgewars - do not edit it unless you know what you're doing!" << endl;
       
   267     for(int i = 0; i < list.size(); i++)
       
   268         stream << list[i] << endl;
       
   269     txt.close();
       
   270 }
       
   271 
       
   272 void HWChatWidget::updateNickItem(QListWidgetItem *nickItem)
       
   273 {
       
   274     QString nick = nickItem->text();
       
   275     ListWidgetNickItem * item = dynamic_cast<ListWidgetNickItem*>(nickItem);
       
   276 
       
   277     item->setFriend(friendsList.contains(nick, Qt::CaseInsensitive));
       
   278     item->setIgnored(ignoreList.contains(nick, Qt::CaseInsensitive));
       
   279 
       
   280     if(item->ignored())
       
   281     {
       
   282         item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_ignore_on.png" : ":/res/chat_ignore_off.png") : ":/res/chat_ignore.png"));
       
   283         item->setForeground(Qt::gray);
       
   284     }
       
   285     else if(item->isFriend())
       
   286     {
       
   287         item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_friend_on.png" : ":/res/chat_friend_off.png") : ":/res/chat_friend.png"));
       
   288         item->setForeground(Qt::green);
       
   289     }
       
   290     else
       
   291     {
       
   292         item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_default_on.png" : ":/res/chat_default_off.png") : ":/res/chat_default.png"));
       
   293         item->setForeground(QBrush(QColor(0xff, 0xcc, 0x00)));
       
   294     }
       
   295 }
       
   296 
       
   297 void HWChatWidget::updateNickItems()
       
   298 {
       
   299     for(int i = 0; i < chatNicks->count(); i++)
       
   300         updateNickItem(chatNicks->item(i));
       
   301 
       
   302     chatNicks->sortItems();
       
   303 }
       
   304 
       
   305 void HWChatWidget::loadLists(const QString & nick)
       
   306 {
       
   307     loadList(ignoreList, nick.toLower() + "_ignore.txt");
       
   308     loadList(friendsList, nick.toLower() + "_friends.txt");
       
   309     updateNickItems();
       
   310 }
       
   311 
       
   312 void HWChatWidget::saveLists(const QString & nick)
       
   313 {
       
   314     saveList(ignoreList, nick.toLower() + "_ignore.txt");
       
   315     saveList(friendsList, nick.toLower() + "_friends.txt");
       
   316 }
       
   317 
       
   318 void HWChatWidget::returnPressed()
       
   319 {
       
   320     QStringList lines = chatEditLine->text().split('\n');
       
   321     chatEditLine->clear();
       
   322     foreach (const QString &line, lines)
       
   323         emit chatLine(line);
       
   324 }
       
   325 
       
   326 
       
   327 void HWChatWidget::onChatString(const QString& str)
       
   328 {
       
   329     onChatString("", str);
       
   330 }
       
   331 
       
   332 const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http://)?(www\\.)?(hedgewars\\.org(/[^ ]*)?)");
       
   333 
       
   334 void HWChatWidget::onChatString(const QString& nick, const QString& str)
       
   335 {
       
   336     bool isFriend = false;
       
   337 
       
   338     if (!nick.isEmpty()) {
       
   339         // don't show chat lines that are from ignored nicks
       
   340         if (ignoreList.contains(nick, Qt::CaseInsensitive))
       
   341             return;
       
   342         // friends will get special treatment, of course
       
   343         isFriend = friendsList.contains(nick, Qt::CaseInsensitive);
       
   344     }
       
   345 
       
   346     QString formattedStr = Qt::escape(str.mid(1));
       
   347     // make hedgewars.org urls actual links
       
   348     formattedStr = formattedStr.replace(URLREGEXP, "<a href=\"http://\\3\">\\3</a>");
       
   349 
       
   350     // "link" nick, but before that encode it in base64 to make sure it can't intefere with html/url syntax
       
   351     // the nick is put as querystring as putting it as host would convert it to it's lower case variant
       
   352     if(!nick.isEmpty())
       
   353         formattedStr.replace("|nick|",QString("<a href=\"hwnick://?%1\" class=\"nick\">%2</a>").arg(QString(nick.toUtf8().toBase64())).arg(nick));
       
   354 
       
   355     QString cssClass("UserChat");
       
   356 
       
   357     // check first character for color code and set color properly
       
   358     switch (str[0].toAscii()) {
       
   359         case 3:
       
   360             cssClass = (isFriend ? "FriendJoin" : "UserJoin");
       
   361             break;
       
   362         case 2:
       
   363             cssClass = (isFriend ? "FriendAction" : "UserAction");
       
   364             break;
       
   365         default:
       
   366             if (isFriend)
       
   367                 cssClass = "FriendChat";
       
   368     }
       
   369 
       
   370     addLine(cssClass,formattedStr);
       
   371 }
       
   372 
       
   373 void HWChatWidget::addLine(const QString& cssClass, QString line)
       
   374 {
       
   375     if (chatStrings.size() > 250)
       
   376         chatStrings.removeFirst();
       
   377 
       
   378     line = QString("<span class=\"%2\">%1</span>").arg(line).arg(cssClass);
       
   379 
       
   380     chatStrings.append(line);
       
   381 
       
   382     chatText->setHtml(chatStrings.join("<br>"));
       
   383 
       
   384     chatText->moveCursor(QTextCursor::End);
       
   385 }
       
   386 
       
   387 void HWChatWidget::onServerMessage(const QString& str)
       
   388 {
       
   389     if (chatStrings.size() > 250)
       
   390         chatStrings.removeFirst();
       
   391 
       
   392     chatStrings.append("<hr>" + str + "<hr>");
       
   393 
       
   394     chatText->setHtml(chatStrings.join("<br>"));
       
   395 
       
   396     chatText->moveCursor(QTextCursor::End);
       
   397 }
       
   398 
       
   399 void HWChatWidget::nickAdded(const QString& nick, bool notifyNick)
       
   400 {
       
   401     QListWidgetItem * item = new ListWidgetNickItem(nick, friendsList.contains(nick, Qt::CaseInsensitive), ignoreList.contains(nick, Qt::CaseInsensitive));
       
   402     updateNickItem(item);
       
   403     chatNicks->addItem(item);
       
   404 
       
   405     emit nickCountUpdate(chatNicks->count());
       
   406 
       
   407     if(notifyNick && notify && gameSettings->value("frontend/sound", true).toBool()) {
       
   408        Mix_PlayChannel(-1, sound[rand()%4], 0);
       
   409     }
       
   410 }
       
   411 
       
   412 void HWChatWidget::nickRemoved(const QString& nick)
       
   413 {
       
   414     foreach(QListWidgetItem * item, chatNicks->findItems(nick, Qt::MatchExactly))
       
   415         chatNicks->takeItem(chatNicks->row(item));
       
   416 
       
   417     emit nickCountUpdate(chatNicks->count());
       
   418 }
       
   419 
       
   420 void HWChatWidget::clear()
       
   421 {
       
   422     chatText->clear();
       
   423     chatStrings.clear();
       
   424     chatNicks->clear();
       
   425 }
       
   426 
       
   427 void HWChatWidget::onKick()
       
   428 {
       
   429     QListWidgetItem * curritem = chatNicks->currentItem();
       
   430     if (curritem)
       
   431         emit kick(curritem->text());
       
   432 }
       
   433 
       
   434 void HWChatWidget::onBan()
       
   435 {
       
   436     QListWidgetItem * curritem = chatNicks->currentItem();
       
   437     if (curritem)
       
   438         emit ban(curritem->text());
       
   439 }
       
   440 
       
   441 void HWChatWidget::onInfo()
       
   442 {
       
   443     QListWidgetItem * curritem = chatNicks->currentItem();
       
   444     if (curritem)
       
   445         emit info(curritem->text());
       
   446 }
       
   447 
       
   448 void HWChatWidget::onFollow()
       
   449 {
       
   450     QListWidgetItem * curritem = chatNicks->currentItem();
       
   451     if (curritem)
       
   452         emit follow(curritem->text());
       
   453 }
       
   454 
       
   455 void HWChatWidget::onIgnore()
       
   456 {
       
   457     QListWidgetItem * curritem = chatNicks->currentItem();
       
   458     if(!curritem)
       
   459         return;
       
   460 
       
   461     if(ignoreList.contains(curritem->text(), Qt::CaseInsensitive)) // already on list - remove him
       
   462     {
       
   463         ignoreList.removeAll(curritem->text().toLower());
       
   464         onChatString(HWChatWidget::tr("%1 *** %2 has been removed from your ignore list").arg('\x03').arg(curritem->text()));
       
   465     }
       
   466     else // not on list - add
       
   467     {
       
   468         // don't consider ignored people friends
       
   469         if(friendsList.contains(curritem->text(), Qt::CaseInsensitive))
       
   470             emit onFriend();
       
   471 
       
   472         // scroll down on first ignore added so that people see where that nick went to
       
   473         if (ignoreList.isEmpty())
       
   474             chatNicks->scrollToBottom();
       
   475 
       
   476         ignoreList << curritem->text().toLower();
       
   477         onChatString(HWChatWidget::tr("%1 *** %2 has been added to your ignore list").arg('\x03').arg(curritem->text()));
       
   478     }
       
   479     updateNickItem(curritem); // update icon/sort order/etc
       
   480     chatNicks->sortItems();
       
   481     chatNickSelected(0); // update context menu
       
   482 }
       
   483 
       
   484 void HWChatWidget::onFriend()
       
   485 {
       
   486     QListWidgetItem * curritem = chatNicks->currentItem();
       
   487     if(!curritem)
       
   488         return;
       
   489 
       
   490     if(friendsList.contains(curritem->text(), Qt::CaseInsensitive)) // already on list - remove him
       
   491     {
       
   492         friendsList.removeAll(curritem->text().toLower());
       
   493         onChatString(HWChatWidget::tr("%1 *** %2 has been removed from your friends list").arg('\x03').arg(curritem->text()));
       
   494     }
       
   495     else // not on list - add
       
   496     {
       
   497         // don't ignore the new friend
       
   498         if(ignoreList.contains(curritem->text(), Qt::CaseInsensitive))
       
   499             emit onIgnore();
       
   500 
       
   501         // scroll up on first friend added so that people see where that nick went to
       
   502         if (friendsList.isEmpty())
       
   503             chatNicks->scrollToTop();
       
   504 
       
   505         friendsList << curritem->text().toLower();
       
   506         onChatString(HWChatWidget::tr("%1 *** %2 has been added to your friends list").arg('\x03').arg(curritem->text()));
       
   507     }
       
   508     updateNickItem(curritem); // update icon/sort order/etc
       
   509     chatNicks->sortItems();
       
   510     chatNickSelected(0); // update context menu
       
   511 }
       
   512 
       
   513 void HWChatWidget::chatNickDoubleClicked(QListWidgetItem * item)
       
   514 {
       
   515     Q_UNUSED(item);
       
   516 
       
   517     QList<QAction *> actions = chatNicks->actions();
       
   518     actions.first()->activate(QAction::Trigger);
       
   519 }
       
   520 
       
   521 void HWChatWidget::chatNickSelected(int index)
       
   522 {
       
   523     Q_UNUSED(index);
       
   524 
       
   525     QListWidgetItem* item = chatNicks->currentItem();
       
   526     if (!item)
       
   527         return;
       
   528 
       
   529     // update context menu labels according to possible action
       
   530     if(ignoreList.contains(item->text(), Qt::CaseInsensitive))
       
   531     {
       
   532         acIgnore->setText(QAction::tr("Unignore"));
       
   533         acIgnore->setIcon(QIcon(":/res/unignore.png"));
       
   534     }
       
   535     else
       
   536     {
       
   537         acIgnore->setText(QAction::tr("Ignore"));
       
   538         acIgnore->setIcon(QIcon(":/res/ignore.png"));
       
   539     }
       
   540 
       
   541     if(friendsList.contains(item->text(), Qt::CaseInsensitive))
       
   542     {
       
   543         acFriend->setText(QAction::tr("Remove friend"));
       
   544         acFriend->setIcon(QIcon(":/res/remfriend.png"));
       
   545     }
       
   546     else
       
   547     {
       
   548         acFriend->setText(QAction::tr("Add friend"));
       
   549         acFriend->setIcon(QIcon(":/res/addfriend.png"));
       
   550     }
       
   551 }
       
   552 
       
   553 void HWChatWidget::setShowReady(bool s)
       
   554 {
       
   555     showReady = s;
       
   556 }
       
   557 
       
   558 void HWChatWidget::setReadyStatus(const QString & nick, bool isReady)
       
   559 {
       
   560     QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
       
   561     if (items.size() != 1)
       
   562     {
       
   563         qWarning("Bug: cannot find user in chat");
       
   564         return;
       
   565     }
       
   566 
       
   567     items[0]->setData(Qt::UserRole, isReady); // bulb status
       
   568     updateNickItem(items[0]);
       
   569 
       
   570     // ensure we're still showing the status bulbs
       
   571     showReady = true;
       
   572 }
       
   573 
       
   574 void HWChatWidget::adminAccess(bool b)
       
   575 {
       
   576     chatNicks->removeAction(acKick);
       
   577     chatNicks->removeAction(acBan);
       
   578 
       
   579     if(b)
       
   580     {
       
   581         chatNicks->insertAction(0, acKick);
       
   582 //      chatNicks->insertAction(0, acBan);
       
   583     }
       
   584 }