2014-07-07 00:19:45 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "groupchatform.h"
|
|
|
|
#include "group.h"
|
2014-06-27 06:42:45 +08:00
|
|
|
#include "widget/groupwidget.h"
|
|
|
|
#include "widget/widget.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
GroupChatForm::GroupChatForm(Group* chatGroup)
|
2014-09-05 02:09:55 +08:00
|
|
|
: group(chatGroup)
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2014-09-05 23:29:14 +08:00
|
|
|
nusersLabel = new QLabel();
|
2014-09-05 02:09:55 +08:00
|
|
|
namesList = new QLabel();
|
|
|
|
|
|
|
|
fileButton->setEnabled(false);
|
|
|
|
callButton->setVisible(false);
|
|
|
|
videoButton->setVisible(false);
|
|
|
|
volButton->setVisible(false);
|
|
|
|
micButton->setVisible(false);
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
QFont small;
|
|
|
|
small.setPixelSize(10);
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
nameLabel->setText(group->widget->name.text());
|
2014-09-05 23:29:14 +08:00
|
|
|
nusersLabel->setFont(small);
|
|
|
|
nusersLabel->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size()));
|
2014-09-05 02:09:55 +08:00
|
|
|
avatarLabel->setPixmap(QPixmap(":/img/group_dark.png"));
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
QString names;
|
|
|
|
for (QString& s : group->peers)
|
|
|
|
names.append(s+", ");
|
|
|
|
names.chop(2);
|
|
|
|
namesList->setText(names);
|
|
|
|
namesList->setFont(small);
|
|
|
|
|
2014-06-29 05:59:11 +08:00
|
|
|
msgEdit->setObjectName("group");
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
mainChatLayout->setColumnStretch(1,1);
|
|
|
|
mainChatLayout->setHorizontalSpacing(10);
|
|
|
|
|
2014-09-05 23:29:14 +08:00
|
|
|
headTextLayout->addWidget(nusersLabel);
|
2014-06-25 04:11:11 +08:00
|
|
|
headTextLayout->addWidget(namesList);
|
|
|
|
headTextLayout->setMargin(0);
|
|
|
|
headTextLayout->setSpacing(0);
|
|
|
|
headTextLayout->addStretch();
|
|
|
|
|
|
|
|
connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
|
|
|
|
connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered()));
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupChatForm::~GroupChatForm()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onSendTriggered()
|
|
|
|
{
|
|
|
|
QString msg = msgEdit->toPlainText();
|
|
|
|
if (msg.isEmpty())
|
|
|
|
return;
|
|
|
|
msgEdit->clear();
|
|
|
|
emit sendMessage(group->groupId, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::addGroupMessage(QString message, int peerId)
|
|
|
|
{
|
2014-09-05 23:24:29 +08:00
|
|
|
QString msgAuthor;
|
2014-06-25 04:11:11 +08:00
|
|
|
if (group->peers.contains(peerId))
|
2014-09-05 23:24:29 +08:00
|
|
|
msgAuthor = group->peers[peerId];
|
2014-06-25 04:11:11 +08:00
|
|
|
else
|
2014-09-05 23:24:29 +08:00
|
|
|
msgAuthor = tr("<Unknown>");
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-09-05 23:24:29 +08:00
|
|
|
addMessage(msgAuthor, message);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onUserListChanged()
|
|
|
|
{
|
2014-09-05 23:29:14 +08:00
|
|
|
nusersLabel->setText(tr("%1 users in chat").arg(group->nPeers));
|
2014-06-25 04:11:11 +08:00
|
|
|
QString names;
|
|
|
|
for (QString& s : group->peers)
|
|
|
|
names.append(s+", ");
|
|
|
|
names.chop(2);
|
|
|
|
namesList->setText(names);
|
|
|
|
}
|