| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2009 by The qGo Project * |
| 3 | * * |
| 4 | * This file is part of qGo. * |
| 5 | * * |
| 6 | * qGo 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; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/> * |
| 18 | * or write to the Free Software Foundation, Inc., * |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | |
| 23 | #include "talk.h" |
| 24 | #include "networkconnection.h" |
| 25 | #include "gamedialog.h" |
| 26 | #include "messages.h" |
| 27 | #include "playergamelistings.h" |
| 28 | #include "connectionwidget.h" |
| 29 | #include "room.h" |
| 30 | /* I wonder if we could somehow generalize this class to handle |
| 31 | * all message/windows even if they're part of larger windows. |
| 32 | * We could even do it for the console, specifying a special |
| 33 | * "opponent" and for the room, with the room name as the |
| 34 | * opponent. And then it could handle all the sendText |
| 35 | * messages that would otherwise be spread around all |
| 36 | * the dispatches, cluttering up their otherwise |
| 37 | * specific calls.*/ |
| 38 | |
| 39 | Talk::Talk(NetworkConnection * conn, PlayerListing *player, Room * r) : TalkGui(), connection(conn), opponent(player), room(r) |
| 40 | { |
| 41 | qDebug("Creating Talk for %s", opponent->name.toLatin1().constData()); |
| 42 | ui.setupUi(this); |
| 43 | opponent->dialog_opened = true; |
| 44 | conversationOpened = false; |
| 45 | |
| 46 | /* |
| 47 | // do not add a button for shouts* or channels tab |
| 48 | if ( (name.find('*') != -1) || (!isplayer)) |
| 49 | { |
| 50 | delete pb_releaseTalkTab; |
| 51 | delete pb_match; |
| 52 | delete stats_layout; |
| 53 | } |
| 54 | */ |
| 55 | connect(ui.pb_releaseTalkTab, &QPushButton::pressed, this, &Talk::slot_pbRelTab); |
| 56 | connect(ui.pb_match, &QPushButton::pressed, this, &Talk::slot_match); |
| 57 | connect(ui.LineEdit1, &QLineEdit::returnPressed, this, &Talk::slot_returnPressed); |
| 58 | } |
| 59 | |
| 60 | Talk::~Talk() |
| 61 | { |
| 62 | qDebug("Talk destroyed"); |
| 63 | opponent->dialog_opened = false; |
| 64 | } |
| 65 | |
| 66 | void Talk::closeEvent(QCloseEvent *) |
| 67 | { |
| 68 | if(room) |
| 69 | room->closeTalk(opponent); |
| 70 | } |
| 71 | |
| 72 | QString Talk::get_name() const |
| 73 | { return opponent->name; } |
| 74 | |
| 75 | // release current Tab |
| 76 | void Talk::slot_pbRelTab() |
| 77 | { |
| 78 | room->closeTalk(opponent); |
| 79 | } |
| 80 | |
| 81 | void Talk::slot_returnPressed() |
| 82 | { |
| 83 | // read tab |
| 84 | QString txt = ui.LineEdit1->text(); |
| 85 | connection->sendMsg(opponent, txt); |
| 86 | ui.MultiLineEdit1->append(connection->getUsername() + ": " + txt); |
| 87 | ui.LineEdit1->clear(); |
| 88 | } |
| 89 | |
| 90 | void Talk::slot_match() |
| 91 | { |
| 92 | connection->sendMatchInvite(opponent); |
| 93 | } |
| 94 | |
| 95 | void Talk::recvTalk(QString text) |
| 96 | { |
| 97 | ui.MultiLineEdit1->append(opponent->name + ": " + text); |
| 98 | } |
| 99 | |
| 100 | void Talk::updatePlayerListing(void) |
| 101 | { |
| 102 | if (opponent == NULL) |
| 103 | return; |
| 104 | |
| 105 | ui.stats_rating->setText(opponent->rank); |
| 106 | ui.stats_info->setText(opponent->info); |
| 107 | ui.stats_default->setText(opponent->extInfo); |
| 108 | ui.stats_wins->setText(QString::number(opponent->wins) + " /"); |
| 109 | ui.stats_loss->setText(QString::number(opponent->losses) ); |
| 110 | ui.stats_country->setText(opponent->country); |
| 111 | ui.stats_playing->setText(QString::number(opponent->playing)); |
| 112 | //ui.stats_rated->setText(p->rated); |
| 113 | ui.stats_address->setText(opponent->email_address); |
| 114 | |
| 115 | // stored either idle time or last access |
| 116 | ui.stats_idle->setText(opponent->idletime); |
| 117 | if (!opponent->idletime.isEmpty()) |
| 118 | ui.Label_Idle->setText(opponent->idletime.at(0).isDigit() ? "Idle :": "Last log :"); |
| 119 | } |