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"
|
2014-10-20 18:01:22 +08:00
|
|
|
#include "tabcompleter.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/group.h"
|
|
|
|
#include "src/widget/groupwidget.h"
|
|
|
|
#include "src/widget/tool/chattextedit.h"
|
|
|
|
#include "src/widget/croppinglabel.h"
|
|
|
|
#include "src/widget/maskablepixmapwidget.h"
|
|
|
|
#include "src/core.h"
|
|
|
|
#include "src/misc/style.h"
|
2014-09-11 21:44:34 +08:00
|
|
|
#include <QPushButton>
|
2014-09-26 00:03:25 +08:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QDragEnterEvent>
|
2014-10-12 18:24:05 +08:00
|
|
|
#include "src/historykeeper.h"
|
2014-11-02 17:41:58 +08:00
|
|
|
#include "src/misc/flowlayout.h"
|
2014-11-14 02:20:06 +08:00
|
|
|
#include <QDebug>
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
GroupChatForm::GroupChatForm(Group* chatGroup)
|
2014-11-13 20:11:23 +08:00
|
|
|
: group(chatGroup), inCall{false}
|
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
|
|
|
|
2014-10-20 18:01:22 +08:00
|
|
|
tabber = new TabCompleter(msgEdit, group);
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
fileButton->setEnabled(false);
|
2014-11-23 23:22:29 +08:00
|
|
|
if (group->isAvGroupchat())
|
2014-11-13 20:11:23 +08:00
|
|
|
{
|
|
|
|
videoButton->setEnabled(false);
|
|
|
|
videoButton->setObjectName("grey");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
videoButton->setVisible(false);
|
|
|
|
callButton->setVisible(false);
|
|
|
|
volButton->setVisible(false);
|
|
|
|
micButton->setVisible(false);
|
|
|
|
}
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-11-23 23:22:29 +08:00
|
|
|
nameLabel->setText(group->getGroupWidget()->getName());
|
2014-10-01 02:10:42 +08:00
|
|
|
|
|
|
|
nusersLabel->setFont(Style::getFont(Style::Medium));
|
2014-11-23 23:22:29 +08:00
|
|
|
nusersLabel->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->getPeersCount()));
|
2014-10-10 03:20:06 +08:00
|
|
|
nusersLabel->setObjectName("statusLabel");
|
2014-10-01 02:10:42 +08:00
|
|
|
|
|
|
|
avatar->setPixmap(QPixmap(":/img/group_dark.png"), Qt::transparent);
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-06-29 05:59:11 +08:00
|
|
|
msgEdit->setObjectName("group");
|
|
|
|
|
2014-11-02 17:41:58 +08:00
|
|
|
namesListLayout = new FlowLayout(0,5,0);
|
2014-11-23 23:22:29 +08:00
|
|
|
QStringList names(group->getPeerList());
|
2015-02-27 22:05:03 +08:00
|
|
|
QLabel *l;
|
|
|
|
|
2014-11-02 17:41:58 +08:00
|
|
|
for (const QString& name : names)
|
2015-02-27 22:05:03 +08:00
|
|
|
{
|
|
|
|
l = new QLabel(name);
|
|
|
|
l->setTextFormat(Qt::PlainText);
|
|
|
|
namesListLayout->addWidget(l);
|
|
|
|
}
|
|
|
|
|
2014-09-05 23:29:14 +08:00
|
|
|
headTextLayout->addWidget(nusersLabel);
|
2014-11-02 17:41:58 +08:00
|
|
|
headTextLayout->addLayout(namesListLayout);
|
2014-06-25 04:11:11 +08:00
|
|
|
headTextLayout->addStretch();
|
|
|
|
|
2014-10-24 06:18:48 +08:00
|
|
|
nameLabel->setMinimumHeight(12);
|
|
|
|
nusersLabel->setMinimumHeight(12);
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
|
|
|
|
connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered()));
|
2014-10-20 18:01:22 +08:00
|
|
|
connect(msgEdit, &ChatTextEdit::tabPressed, tabber, &TabCompleter::complete);
|
|
|
|
connect(msgEdit, &ChatTextEdit::keyPressed, tabber, &TabCompleter::reset);
|
2014-11-13 20:11:23 +08:00
|
|
|
connect(callButton, &QPushButton::clicked, this, &GroupChatForm::onCallClicked);
|
|
|
|
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
|
|
|
|
connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle()));
|
2014-11-15 09:29:14 +08:00
|
|
|
connect(nameLabel, &CroppingLabel::textChanged, this, [=](QString text, QString orig)
|
2014-11-23 23:22:29 +08:00
|
|
|
{if (text != orig) emit groupTitleChanged(group->getGroupId(), text.left(128));} );
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
setAcceptDrops(true);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onSendTriggered()
|
|
|
|
{
|
|
|
|
QString msg = msgEdit->toPlainText();
|
|
|
|
if (msg.isEmpty())
|
|
|
|
return;
|
2014-11-01 21:00:43 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
msgEdit->clear();
|
2014-11-01 21:00:43 +08:00
|
|
|
|
|
|
|
if (msg.startsWith("/me "))
|
|
|
|
{
|
|
|
|
msg = msg.right(msg.length() - 4);
|
2014-11-23 23:22:29 +08:00
|
|
|
emit sendAction(group->getGroupId(), msg);
|
2014-11-01 21:00:43 +08:00
|
|
|
} else {
|
2014-11-23 23:22:29 +08:00
|
|
|
emit sendMessage(group->getGroupId(), msg);
|
2014-11-01 21:00:43 +08:00
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onUserListChanged()
|
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
nusersLabel->setText(tr("%1 users in chat").arg(group->getPeersCount()));
|
2014-11-02 17:41:58 +08:00
|
|
|
|
|
|
|
QLayoutItem *child;
|
|
|
|
while ((child = namesListLayout->takeAt(0)))
|
|
|
|
{
|
|
|
|
child->widget()->hide();
|
|
|
|
delete child->widget();
|
|
|
|
delete child;
|
|
|
|
}
|
|
|
|
|
2014-11-23 23:22:29 +08:00
|
|
|
QStringList names(group->getPeerList());
|
2014-11-02 20:38:00 +08:00
|
|
|
unsigned nNames = names.size();
|
|
|
|
for (unsigned i=0; i<nNames; ++i)
|
2014-11-02 17:41:58 +08:00
|
|
|
{
|
|
|
|
QString nameStr = names[i];
|
2014-11-02 20:38:00 +08:00
|
|
|
if (i!=nNames-1)
|
2014-11-02 17:41:58 +08:00
|
|
|
nameStr+=", ";
|
|
|
|
QLabel* nameLabel = new QLabel(nameStr);
|
|
|
|
nameLabel->setObjectName("peersLabel");
|
2015-02-27 22:05:03 +08:00
|
|
|
nameLabel->setTextFormat(Qt::PlainText);
|
2014-11-02 17:41:58 +08:00
|
|
|
namesListLayout->addWidget(nameLabel);
|
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
|
|
|
|
void GroupChatForm::dragEnterEvent(QDragEnterEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasFormat("friend"))
|
|
|
|
ev->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::dropEvent(QDropEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasFormat("friend"))
|
|
|
|
{
|
|
|
|
int friendId = ev->mimeData()->data("friend").toInt();
|
2014-11-23 23:22:29 +08:00
|
|
|
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
|
2014-09-26 00:03:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:11:23 +08:00
|
|
|
void GroupChatForm::onMicMuteToggle()
|
|
|
|
{
|
|
|
|
if (audioInputFlag == true)
|
|
|
|
{
|
|
|
|
if (micButton->objectName() == "red")
|
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
Core::getInstance()->enableGroupCallMic(group->getGroupId());
|
2014-11-13 20:11:23 +08:00
|
|
|
micButton->setObjectName("green");
|
2015-02-23 03:37:00 +08:00
|
|
|
micButton->setToolTip(tr("Mute microphone"));
|
2014-11-13 20:11:23 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
Core::getInstance()->disableGroupCallMic(group->getGroupId());
|
2014-11-13 20:11:23 +08:00
|
|
|
micButton->setObjectName("red");
|
2015-02-23 03:37:00 +08:00
|
|
|
micButton->setToolTip(tr("Unmute microphone"));
|
2014-11-13 20:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Style::repolish(micButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onVolMuteToggle()
|
|
|
|
{
|
|
|
|
if (audioOutputFlag == true)
|
|
|
|
{
|
|
|
|
if (volButton->objectName() == "red")
|
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
Core::getInstance()->enableGroupCallVol(group->getGroupId());
|
2014-11-13 20:11:23 +08:00
|
|
|
volButton->setObjectName("green");
|
2015-02-23 03:37:00 +08:00
|
|
|
volButton->setToolTip(tr("Mute call"));
|
2014-11-13 20:11:23 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
Core::getInstance()->disableGroupCallVol(group->getGroupId());
|
2014-11-13 20:11:23 +08:00
|
|
|
volButton->setObjectName("red");
|
2015-02-23 03:37:00 +08:00
|
|
|
volButton->setToolTip(tr("Unmute call"));
|
2014-11-13 20:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Style::repolish(volButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupChatForm::onCallClicked()
|
|
|
|
{
|
|
|
|
if (!inCall)
|
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
Core::getInstance()->joinGroupCall(group->getGroupId());
|
2014-11-13 20:11:23 +08:00
|
|
|
audioInputFlag = true;
|
|
|
|
audioOutputFlag = true;
|
|
|
|
callButton->setObjectName("red");
|
|
|
|
callButton->style()->polish(callButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip(tr("End audio call"));
|
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
micButton->setToolTip(tr("Mute microphone"));
|
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
|
|
|
volButton->setToolTip(tr("Mute call"));
|
2014-11-13 20:11:23 +08:00
|
|
|
inCall = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
Core::getInstance()->leaveGroupCall(group->getGroupId());
|
2014-11-13 20:11:23 +08:00
|
|
|
audioInputFlag = false;
|
|
|
|
audioOutputFlag = false;
|
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip(tr("Start audio call"));
|
|
|
|
micButton->setObjectName("grey");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
micButton->setToolTip("");
|
|
|
|
volButton->setObjectName("grey");
|
|
|
|
volButton->style()->polish(volButton);
|
|
|
|
volButton->setToolTip("");
|
2014-11-13 20:11:23 +08:00
|
|
|
inCall = false;
|
|
|
|
}
|
|
|
|
}
|
2014-11-14 02:20:06 +08:00
|
|
|
|
|
|
|
void GroupChatForm::keyPressEvent(QKeyEvent* ev)
|
|
|
|
{
|
2014-12-06 20:49:04 +08:00
|
|
|
// Push to talk (CTRL+P)
|
|
|
|
if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall)
|
2014-11-14 02:20:06 +08:00
|
|
|
{
|
|
|
|
Core* core = Core::getInstance();
|
2014-11-23 23:22:29 +08:00
|
|
|
if (!core->isGroupCallMicEnabled(group->getGroupId()))
|
2014-11-14 02:20:06 +08:00
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
core->enableGroupCallMic(group->getGroupId());
|
2014-11-14 02:20:06 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
Style::repolish(micButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 03:32:09 +08:00
|
|
|
if (msgEdit->hasFocus())
|
|
|
|
return;
|
2014-12-06 20:59:19 +08:00
|
|
|
}
|
2014-11-14 03:32:09 +08:00
|
|
|
|
2014-12-06 20:59:19 +08:00
|
|
|
void GroupChatForm::keyReleaseEvent(QKeyEvent* ev)
|
|
|
|
{
|
2014-12-06 20:59:34 +08:00
|
|
|
// Push to talk (CTRL+P)
|
|
|
|
if (ev->key() == Qt::Key_P && (ev->modifiers() & Qt::ControlModifier) && inCall)
|
2014-11-14 02:20:06 +08:00
|
|
|
{
|
|
|
|
Core* core = Core::getInstance();
|
2014-11-23 23:22:29 +08:00
|
|
|
if (core->isGroupCallMicEnabled(group->getGroupId()))
|
2014-11-14 02:20:06 +08:00
|
|
|
{
|
2014-11-23 23:22:29 +08:00
|
|
|
core->disableGroupCallMic(group->getGroupId());
|
2014-11-14 02:20:06 +08:00
|
|
|
micButton->setObjectName("red");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
Style::repolish(micButton);
|
|
|
|
}
|
|
|
|
}
|
2014-12-06 20:59:19 +08:00
|
|
|
|
|
|
|
if (msgEdit->hasFocus())
|
|
|
|
return;
|
2014-11-14 02:20:06 +08:00
|
|
|
}
|