1 /* |
1 /* |
2 * Hedgewars, a free turn based strategy game |
2 * Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com> |
3 * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com> |
4 * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
4 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
5 * |
5 * |
6 * This program is free software; you can redistribute it and/or modify |
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 |
7 * it under the terms of the GNU General Public License as published by |
8 * the Free Software Foundation; version 2 of the License |
8 * the Free Software Foundation; version 2 of the License |
9 * |
9 * |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 * GNU General Public License for more details. |
13 * GNU General Public License for more details. |
14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
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 |
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 |
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 */ |
18 */ |
19 |
19 |
20 #include <QDesktopServices> |
20 #include <QDesktopServices> |
21 #include <QTextBrowser> |
21 #include <QTextBrowser> |
22 #include <QAction> |
22 #include <QAction> |
177 mainLayout(this) |
177 mainLayout(this) |
178 { |
178 { |
179 this->gameSettings = NULL; |
179 this->gameSettings = NULL; |
180 this->notify = notify; |
180 this->notify = notify; |
181 |
181 |
|
182 m_usersModel = NULL; |
|
183 |
182 m_isAdmin = false; |
184 m_isAdmin = false; |
183 m_autoKickEnabled = false; |
185 m_autoKickEnabled = false; |
|
186 |
|
187 m_scrollToBottom = false; |
|
188 m_scrollBarPos = 0; |
184 |
189 |
185 QStringList vpList = |
190 QStringList vpList = |
186 QStringList() << "Classic" << "Default" << "Mobster" << "Russian"; |
191 QStringList() << "Classic" << "Default" << "Mobster" << "Russian"; |
187 |
192 |
188 foreach (const QString & vp, vpList) |
193 foreach (const QString & vp, vpList) |
404 } |
409 } |
405 |
410 |
406 void HWChatWidget::printChatString( |
411 void HWChatWidget::printChatString( |
407 const QString & nick, const QString & str, const QString & cssClassPart, bool highlight) |
412 const QString & nick, const QString & str, const QString & cssClassPart, bool highlight) |
408 { |
413 { |
409 QSortFilterProxyModel * playersSortFilterModel = qobject_cast<QSortFilterProxyModel *>(chatNicks->model()); |
414 if(!m_usersModel) |
410 if(!playersSortFilterModel) |
|
411 return; |
|
412 |
|
413 PlayersListModel * players = qobject_cast<PlayersListModel *>(playersSortFilterModel->sourceModel()); |
|
414 |
|
415 if(!players) |
|
416 return; |
415 return; |
417 |
416 |
418 // don't show chat lines that are from ignored nicks |
417 // don't show chat lines that are from ignored nicks |
419 if (players->isFlagSet(nick, PlayersListModel::Ignore)) |
418 if (m_usersModel->isFlagSet(nick, PlayersListModel::Ignore)) |
420 return; |
419 return; |
421 |
420 |
422 bool isFriend = (!nick.isEmpty()) && players->isFlagSet(nick, PlayersListModel::Friend); |
421 bool isFriend = (!nick.isEmpty()) && m_usersModel->isFlagSet(nick, PlayersListModel::Friend); |
423 |
422 |
424 QString cssClass = (isFriend ? "msg_Friend" : "msg_User") + cssClassPart; |
423 QString cssClass = (isFriend ? "msg_Friend" : "msg_User") + cssClassPart; |
425 |
424 |
426 addLine(cssClass, str, highlight); |
425 addLine(cssClass, str, highlight); |
|
426 } |
|
427 |
|
428 bool HWChatWidget::isInGame() { |
|
429 if (!m_usersModel) |
|
430 return false; |
|
431 |
|
432 return m_usersModel->isFlagSet(m_userNick, PlayersListModel::InGame); |
427 } |
433 } |
428 |
434 |
429 void HWChatWidget::addLine(const QString & cssClass, QString line, bool isHighlight) |
435 void HWChatWidget::addLine(const QString & cssClass, QString line, bool isHighlight) |
430 { |
436 { |
431 if (s_displayNone->contains(cssClass)) |
437 if (s_displayNone->contains(cssClass)) |
447 |
453 |
448 if (isHighlight) |
454 if (isHighlight) |
449 { |
455 { |
450 line = QString("<span class=\"highlight\">%1</span>").arg(line); |
456 line = QString("<span class=\"highlight\">%1</span>").arg(line); |
451 SDLInteraction::instance().playSoundFile(m_hilightSound); |
457 SDLInteraction::instance().playSoundFile(m_hilightSound); |
452 HWApplication::alert(this, 800); |
458 if (!isInGame()) |
|
459 HWApplication::alert(this, 800); |
453 } |
460 } |
454 |
461 |
455 chatStrings.append(line); |
462 chatStrings.append(line); |
456 |
463 |
457 chatText->setHtml("<html><body>"+chatStrings.join("<br>")+"</body></html>"); |
464 chatText->setHtml("<html><body>"+chatStrings.join("<br>")+"</body></html>"); |
542 m_highlights.clear(); |
549 m_highlights.clear(); |
543 |
550 |
544 QString hlRegExp("^(.* )?%1[^-a-z0-9_]*( .*)?$"); |
551 QString hlRegExp("^(.* )?%1[^-a-z0-9_]*( .*)?$"); |
545 QRegExp whitespace("\\s"); |
552 QRegExp whitespace("\\s"); |
546 |
553 |
547 m_highlights.append(QRegExp(hlRegExp.arg(m_userNick.toLower()))); |
554 if (!m_userNick.isEmpty()) |
|
555 m_highlights.append(QRegExp(hlRegExp.arg(QRegExp::escape(m_userNick.toLower())))); |
548 |
556 |
549 QFile file(cfgdir->absolutePath() + "/" + m_userNick.toLower() + "_highlight.txt"); |
557 QFile file(cfgdir->absolutePath() + "/" + m_userNick.toLower() + "_highlight.txt"); |
550 |
558 |
551 if (file.exists() && (file.open(QIODevice::ReadOnly | QIODevice::Text))) |
559 if (file.exists() && (file.open(QIODevice::ReadOnly | QIODevice::Text))) |
552 { |
560 { |
587 const QString & version, |
595 const QString & version, |
588 const QString & roomInfo) |
596 const QString & roomInfo) |
589 { |
597 { |
590 addLine("msg_PlayerInfo", QString(" >>> %1 - <span class=\"ipaddress\">%2</span> <span class=\"version\">%3</span> <span class=\"location\">%4</span>") |
598 addLine("msg_PlayerInfo", QString(" >>> %1 - <span class=\"ipaddress\">%2</span> <span class=\"version\">%3</span> <span class=\"location\">%4</span>") |
591 .arg(linkedNick(nick)) |
599 .arg(linkedNick(nick)) |
592 .arg(ip) |
600 .arg(Qt::escape(ip == "[]"?"":ip)) |
593 .arg(version) |
601 .arg(Qt::escape(version)) |
594 .arg(roomInfo)); |
602 .arg(Qt::escape(roomInfo)) |
|
603 ); |
595 } |
604 } |
596 |
605 |
597 void HWChatWidget::onKick() |
606 void HWChatWidget::onKick() |
598 { |
607 { |
599 QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
608 QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
715 |
724 |
716 |
725 |
717 void HWChatWidget::adminAccess(bool b) |
726 void HWChatWidget::adminAccess(bool b) |
718 { |
727 { |
719 chatNicks->removeAction(acKick); |
728 chatNicks->removeAction(acKick); |
720 chatNicks->removeAction(acBan); |
729 //chatNicks->removeAction(acBan); |
721 |
730 |
722 m_isAdmin = b; |
731 m_isAdmin = b; |
723 |
732 |
724 if(b) |
733 if(b) |
725 { |
734 { |
726 chatNicks->insertAction(0, acKick); |
735 chatNicks->insertAction(0, acKick); |
727 chatNicks->insertAction(0, acBan); |
736 //chatNicks->insertAction(0, acBan); |
728 } |
737 } |
729 } |
738 } |
730 |
739 |
731 void HWChatWidget::dragEnterEvent(QDragEnterEvent * event) |
740 void HWChatWidget::dragEnterEvent(QDragEnterEvent * event) |
732 { |
741 { |
846 { |
855 { |
847 chatNicks->selectionModel()->deleteLater(); |
856 chatNicks->selectionModel()->deleteLater(); |
848 |
857 |
849 chatNicks->setModel(model); |
858 chatNicks->setModel(model); |
850 chatNicks->setModelColumn(0); |
859 chatNicks->setModelColumn(0); |
|
860 |
|
861 QSortFilterProxyModel * sfpModel = qobject_cast<QSortFilterProxyModel *>(model); |
|
862 if (sfpModel) |
|
863 m_usersModel = qobject_cast<PlayersListModel*>(sfpModel->sourceModel()); |
|
864 else |
|
865 m_usersModel = qobject_cast<PlayersListModel*>(model); |
851 } |
866 } |
852 |
867 |
853 void HWChatWidget::nicksContextMenuRequested(const QPoint &pos) |
868 void HWChatWidget::nicksContextMenuRequested(const QPoint &pos) |
854 { |
869 { |
855 QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
870 QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |