2014-07-07 00:19:45 +08:00
|
|
|
/*
|
2016-11-28 21:33:38 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2014-07-07 00:19:45 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
2014-07-07 00:19:45 +08:00
|
|
|
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.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2014-07-07 00:19:45 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-07-07 00:19:45 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2014-07-07 00:19:45 +08:00
|
|
|
*/
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
#include "chatform.h"
|
|
|
|
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/audio/audio.h"
|
|
|
|
#include "src/chatlog/chatlinecontentproxy.h"
|
|
|
|
#include "src/chatlog/chatlog.h"
|
|
|
|
#include "src/chatlog/chatmessage.h"
|
|
|
|
#include "src/chatlog/content/filetransferwidget.h"
|
|
|
|
#include "src/chatlog/content/text.h"
|
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/core/coreav.h"
|
|
|
|
#include "src/core/cstring.h"
|
|
|
|
#include "src/friend.h"
|
|
|
|
#include "src/nexus.h"
|
|
|
|
#include "src/persistence/offlinemsgengine.h"
|
|
|
|
#include "src/persistence/profile.h"
|
|
|
|
#include "src/persistence/settings.h"
|
|
|
|
#include "src/video/camerasource.h"
|
|
|
|
#include "src/video/netcamview.h"
|
|
|
|
#include "src/video/videosource.h"
|
|
|
|
#include "src/widget/form/loadhistorydialog.h"
|
|
|
|
#include "src/widget/friendwidget.h"
|
|
|
|
#include "src/widget/maskablepixmapwidget.h"
|
|
|
|
#include "src/widget/style.h"
|
|
|
|
#include "src/widget/tool/callconfirmwidget.h"
|
|
|
|
#include "src/widget/tool/chattextedit.h"
|
|
|
|
#include "src/widget/tool/croppinglabel.h"
|
|
|
|
#include "src/widget/tool/flyoutoverlaywidget.h"
|
|
|
|
#include "src/widget/tool/screenshotgrabber.h"
|
|
|
|
#include "src/widget/translator.h"
|
|
|
|
#include "src/widget/widget.h"
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QBitmap>
|
2015-06-11 00:11:50 +08:00
|
|
|
#include <QBoxLayout>
|
2016-08-29 15:07:23 +08:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDragEnterEvent>
|
2014-09-11 21:44:34 +08:00
|
|
|
#include <QFileDialog>
|
2016-08-29 15:07:23 +08:00
|
|
|
#include <QFileInfo>
|
2014-09-11 21:44:34 +08:00
|
|
|
#include <QMessageBox>
|
2014-09-26 00:03:25 +08:00
|
|
|
#include <QMimeData>
|
2016-08-29 15:07:23 +08:00
|
|
|
#include <QPushButton>
|
2015-03-10 01:32:30 +08:00
|
|
|
#include <QScreen>
|
2016-08-29 15:07:23 +08:00
|
|
|
#include <QScrollBar>
|
2015-07-23 02:50:39 +08:00
|
|
|
#include <QSplitter>
|
2016-08-29 15:07:23 +08:00
|
|
|
#include <QStyle>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
|
2015-06-08 02:24:55 +08:00
|
|
|
#include <cassert>
|
2016-08-29 15:07:23 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2016-07-31 22:17:11 +08:00
|
|
|
const QString ChatForm::ACTION_PREFIX = QStringLiteral("/me ");
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
ChatForm::ChatForm(Friend* chatFriend)
|
2014-09-05 02:09:55 +08:00
|
|
|
: f(chatFriend)
|
2016-08-29 15:07:23 +08:00
|
|
|
, callDuration(new QLabel(this))
|
2016-06-23 06:47:44 +08:00
|
|
|
, isTyping(false)
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
nameLabel->setText(f->getDisplayedName());
|
2014-10-01 02:10:42 +08:00
|
|
|
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":/img/contact_dark.svg"));
|
2014-06-27 07:49:48 +08:00
|
|
|
|
2014-09-10 00:28:07 +08:00
|
|
|
statusMessageLabel = new CroppingLabel();
|
2014-10-10 03:20:06 +08:00
|
|
|
statusMessageLabel->setObjectName("statusLabel");
|
2014-10-01 02:10:42 +08:00
|
|
|
statusMessageLabel->setFont(Style::getFont(Style::Medium));
|
2014-10-24 03:53:45 +08:00
|
|
|
statusMessageLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize());
|
2015-02-27 22:05:03 +08:00
|
|
|
statusMessageLabel->setTextFormat(Qt::PlainText);
|
2016-04-24 12:15:54 +08:00
|
|
|
statusMessageLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-01-25 11:57:20 +08:00
|
|
|
callConfirm = nullptr;
|
2015-02-08 00:18:25 +08:00
|
|
|
offlineEngine = new OfflineMsgEngine(f);
|
|
|
|
|
2015-01-20 15:27:48 +08:00
|
|
|
typingTimer.setSingleShot(true);
|
2015-01-04 19:20:36 +08:00
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
callDurationTimer = nullptr;
|
2014-08-16 04:08:19 +08:00
|
|
|
|
2015-01-18 19:20:13 +08:00
|
|
|
chatWidget->setTypingNotification(ChatMessage::createTypingNotification());
|
2016-08-29 15:07:23 +08:00
|
|
|
chatWidget->setMinimumHeight(50);
|
2015-01-10 18:57:46 +08:00
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
headTextLayout->addWidget(statusMessageLabel);
|
2014-06-25 04:11:11 +08:00
|
|
|
headTextLayout->addStretch();
|
2014-11-03 09:51:56 +08:00
|
|
|
callDuration = new QLabel();
|
|
|
|
headTextLayout->addWidget(callDuration, 1, Qt::AlignCenter);
|
2015-01-03 21:08:04 +08:00
|
|
|
callDuration->hide();
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2015-06-06 03:37:01 +08:00
|
|
|
loadHistoryAction = menu.addAction(QString(), this, SLOT(onLoadHistory()));
|
2016-04-24 12:15:54 +08:00
|
|
|
copyStatusAction = statusMessageMenu.addAction(QString(), this, SLOT(onCopyStatusMessage()));
|
2014-10-11 00:22:57 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
const Core* core = Core::getInstance();
|
|
|
|
connect(core, &Core::fileReceiveRequested,
|
|
|
|
this, &ChatForm::onFileRecvRequest);
|
|
|
|
connect(core, &Core::friendAvatarChanged,
|
|
|
|
this, &ChatForm::onAvatarChange);
|
|
|
|
connect(core, &Core::friendAvatarRemoved,
|
|
|
|
this, &ChatForm::onAvatarRemoved);
|
|
|
|
connect(core, &Core::fileSendStarted,
|
|
|
|
this, &ChatForm::startFileSend);
|
|
|
|
connect(core, &Core::fileSendFailed,
|
|
|
|
this, &ChatForm::onFileSendFailed);
|
|
|
|
connect(core, &Core::receiptRecieved,
|
|
|
|
this, &ChatForm::onReceiptReceived);
|
|
|
|
connect(core, &Core::friendMessageReceived,
|
|
|
|
this, &ChatForm::onFriendMessageReceived);
|
|
|
|
connect(core, &Core::friendTypingChanged,
|
|
|
|
this, &ChatForm::onFriendTypingChanged);
|
2016-12-25 18:53:15 +08:00
|
|
|
connect(core, &Core::friendStatusChanged,
|
|
|
|
this, &ChatForm::onFriendStatusChanged);
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
|
|
|
|
const CoreAV* av = core->getAv();
|
|
|
|
connect(av, &CoreAV::avInvite, this, &ChatForm::onAvInvite);
|
|
|
|
connect(av, &CoreAV::avStart, this, &ChatForm::onAvStart);
|
|
|
|
connect(av, &CoreAV::avEnd, this, &ChatForm::onAvEnd);
|
|
|
|
|
|
|
|
connect(sendButton, &QPushButton::clicked,
|
|
|
|
this, &ChatForm::onSendTriggered);
|
|
|
|
connect(fileButton, &QPushButton::clicked,
|
|
|
|
this, &ChatForm::onAttachClicked);
|
|
|
|
connect(screenshotButton, &QPushButton::clicked,
|
|
|
|
this, &ChatForm::onScreenshotClicked);
|
|
|
|
connect(callButton, &QAbstractButton::clicked,
|
|
|
|
this, &ChatForm::onCallTriggered);
|
|
|
|
connect(videoButton, &QAbstractButton::clicked,
|
|
|
|
this, &ChatForm::onVideoCallTriggered);
|
|
|
|
connect(micButton, &QAbstractButton::clicked,
|
|
|
|
this, &ChatForm::onMicMuteToggle);
|
|
|
|
connect(volButton, &QAbstractButton::clicked,
|
|
|
|
this, &ChatForm::onVolMuteToggle);
|
|
|
|
|
|
|
|
connect(msgEdit, &ChatTextEdit::enterPressed,
|
|
|
|
this, &ChatForm::onSendTriggered);
|
|
|
|
connect(msgEdit, &ChatTextEdit::textChanged,
|
|
|
|
this, &ChatForm::onTextEditChanged);
|
|
|
|
connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested,
|
|
|
|
this, [&](const QPoint& pos) {
|
2016-07-07 17:55:53 +08:00
|
|
|
if (!statusMessageLabel->text().isEmpty())
|
2016-04-24 12:15:54 +08:00
|
|
|
{
|
2016-04-26 09:59:21 +08:00
|
|
|
QWidget* sender = static_cast<QWidget*>(this->sender());
|
2016-04-24 12:15:54 +08:00
|
|
|
statusMessageMenu.exec(sender->mapToGlobal(pos));
|
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(&typingTimer, &QTimer::timeout, this, [=] {
|
2016-08-22 05:30:07 +08:00
|
|
|
Core::getInstance()->sendTyping(f->getFriendId(), false);
|
2015-03-31 05:27:52 +08:00
|
|
|
isTyping = false;
|
2016-08-29 15:07:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(nameLabel, &CroppingLabel::editFinished,
|
|
|
|
this, [=](const QString& newName) {
|
2015-06-08 02:25:05 +08:00
|
|
|
nameLabel->setText(newName);
|
|
|
|
emit aliasChanged(newName);
|
2016-08-29 15:07:23 +08:00
|
|
|
});
|
2014-09-26 00:03:25 +08:00
|
|
|
|
2016-12-25 18:53:15 +08:00
|
|
|
updateCallButtons();
|
2014-09-26 00:03:25 +08:00
|
|
|
setAcceptDrops(true);
|
2015-06-06 03:37:01 +08:00
|
|
|
retranslateUi();
|
|
|
|
Translator::registerHandler(std::bind(&ChatForm::retranslateUi, this), this);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ChatForm::~ChatForm()
|
|
|
|
{
|
2015-06-06 03:37:01 +08:00
|
|
|
Translator::unregister(this);
|
2014-06-30 10:39:43 +08:00
|
|
|
delete netcam;
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::setStatusMessage(QString newMessage)
|
|
|
|
{
|
2014-09-05 02:09:55 +08:00
|
|
|
statusMessageLabel->setText(newMessage);
|
2016-08-29 15:07:23 +08:00
|
|
|
// for long messsages
|
|
|
|
statusMessageLabel->setToolTip(Qt::convertFromPlainText(newMessage, Qt::WhiteSpaceNormal));
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onSendTriggered()
|
|
|
|
{
|
2015-04-13 02:24:33 +08:00
|
|
|
SendMessageStr(msgEdit->toPlainText());
|
2014-06-25 04:11:11 +08:00
|
|
|
msgEdit->clear();
|
|
|
|
}
|
|
|
|
|
2015-01-04 19:20:36 +08:00
|
|
|
void ChatForm::onTextEditChanged()
|
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
Core* core = Core::getInstance();
|
2016-08-08 19:40:55 +08:00
|
|
|
if (!Settings::getInstance().getTypingNotification())
|
2015-02-11 12:43:25 +08:00
|
|
|
{
|
|
|
|
if (isTyping)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
|
|
|
core->sendTyping(f->getFriendId(), false);
|
|
|
|
}
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2015-02-11 12:43:25 +08:00
|
|
|
isTyping = false;
|
|
|
|
return;
|
|
|
|
}
|
2015-01-04 19:20:36 +08:00
|
|
|
|
2015-02-11 12:43:25 +08:00
|
|
|
if (msgEdit->toPlainText().length() > 0)
|
|
|
|
{
|
2015-01-20 15:27:48 +08:00
|
|
|
typingTimer.start(3000);
|
2015-02-11 12:43:25 +08:00
|
|
|
if (!isTyping)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
|
|
|
isTyping = true;
|
|
|
|
core->sendTyping(f->getFriendId(), isTyping);
|
|
|
|
}
|
2015-02-11 12:43:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
isTyping = false;
|
|
|
|
core->sendTyping(f->getFriendID(), isTyping);
|
2015-02-11 12:43:25 +08:00
|
|
|
}
|
2015-01-04 19:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 04:43:28 +08:00
|
|
|
void ChatForm::onAttachClicked()
|
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
QStringList paths = QFileDialog::getOpenFileNames(
|
|
|
|
this, tr("Send a file"), QDir::homePath(),
|
|
|
|
0, 0, QFileDialog::DontUseNativeDialog);
|
|
|
|
|
2014-10-17 20:29:48 +08:00
|
|
|
if (paths.isEmpty())
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2014-06-26 04:43:28 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
Core* core = Core::getInstance();
|
2014-10-17 20:29:48 +08:00
|
|
|
for (QString path : paths)
|
2014-08-29 01:06:51 +08:00
|
|
|
{
|
2014-10-17 20:29:48 +08:00
|
|
|
QFile file(path);
|
|
|
|
if (!file.exists() || !file.open(QIODevice::ReadOnly))
|
2014-11-28 01:42:04 +08:00
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
QString fileName = QFileInfo(path).fileName();
|
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Unable to open"),
|
|
|
|
tr("qTox wasn't able to open %1").arg(fileName));
|
2014-10-17 20:29:48 +08:00
|
|
|
continue;
|
2014-11-28 01:42:04 +08:00
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
|
2014-10-17 20:29:48 +08:00
|
|
|
if (file.isSequential())
|
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
QMessageBox::critical(
|
|
|
|
this, tr("Bad idea"),
|
|
|
|
tr("You're trying to send a sequential file,"
|
|
|
|
" which is not going to work!"));
|
2014-10-17 20:29:48 +08:00
|
|
|
file.close();
|
|
|
|
continue;
|
|
|
|
}
|
2016-12-25 17:45:25 +08:00
|
|
|
|
2016-06-23 06:47:44 +08:00
|
|
|
qint64 filesize = file.size();
|
2014-08-29 01:06:51 +08:00
|
|
|
file.close();
|
2014-10-17 20:29:48 +08:00
|
|
|
QFileInfo fi(path);
|
2014-06-26 04:43:28 +08:00
|
|
|
|
2016-08-22 05:30:07 +08:00
|
|
|
core->sendFile(f->getFriendId(), fi.fileName(), path, filesize);
|
2014-10-17 20:29:48 +08:00
|
|
|
}
|
2014-06-26 04:43:28 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 01:45:47 +08:00
|
|
|
void ChatForm::startFileSend(ToxFile file)
|
2014-06-26 06:30:24 +08:00
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
if (file.friendId != f->getFriendId())
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2014-06-26 07:35:30 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2014-11-03 01:36:27 +08:00
|
|
|
QString name;
|
2016-11-09 05:21:08 +08:00
|
|
|
const Core* core = Core::getInstance();
|
2016-12-30 06:14:48 +08:00
|
|
|
ToxPk self = core->getSelfId().getPublicKey();
|
2016-11-09 05:21:08 +08:00
|
|
|
if (previousId != self)
|
2014-11-03 01:36:27 +08:00
|
|
|
{
|
|
|
|
name = core->getUsername();
|
2016-11-09 05:21:08 +08:00
|
|
|
previousId = self;
|
2014-11-03 01:36:27 +08:00
|
|
|
}
|
2014-09-07 19:42:06 +08:00
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
insertChatMessage(ChatMessage::createFileTransferMessage(
|
|
|
|
name, file, true, QDateTime::currentDateTime()));
|
2015-06-13 00:52:41 +08:00
|
|
|
|
|
|
|
Widget::getInstance()->updateFriendActivity(f);
|
2014-06-27 01:45:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onFileRecvRequest(ToxFile file)
|
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
if (file.friendId != f->getFriendId())
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2014-06-27 01:45:47 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2015-06-24 00:54:00 +08:00
|
|
|
Widget::getInstance()->newFriendMessageAlert(file.friendId);
|
2014-09-06 03:27:26 +08:00
|
|
|
|
2014-11-03 01:36:27 +08:00
|
|
|
QString name;
|
2016-12-30 06:14:48 +08:00
|
|
|
ToxPk friendId = f->getPublicKey();
|
2014-11-03 01:36:27 +08:00
|
|
|
if (friendId != previousId)
|
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
name = f->getDisplayedName();
|
2014-11-03 01:36:27 +08:00
|
|
|
previousId = friendId;
|
|
|
|
}
|
2014-09-07 19:42:06 +08:00
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
ChatMessage::Ptr msg = ChatMessage::createFileTransferMessage(
|
|
|
|
name, file, false, QDateTime::currentDateTime());
|
2015-01-05 01:21:35 +08:00
|
|
|
insertChatMessage(msg);
|
2014-10-18 12:53:29 +08:00
|
|
|
|
2015-08-31 20:59:39 +08:00
|
|
|
ChatLineContentProxy* proxy = static_cast<ChatLineContentProxy*>(msg->getContent(1));
|
|
|
|
assert(proxy->getWidgetType() == ChatLineContentProxy::FileTransferWidgetType);
|
|
|
|
FileTransferWidget* tfWidget = static_cast<FileTransferWidget*>(proxy->getWidget());
|
|
|
|
|
2015-08-31 03:36:39 +08:00
|
|
|
// there is auto-accept for that conact
|
2016-12-30 06:14:48 +08:00
|
|
|
if (!Settings::getInstance().getAutoAcceptDir(f->getPublicKey()).isEmpty())
|
2014-12-14 04:11:03 +08:00
|
|
|
{
|
2016-12-30 06:14:48 +08:00
|
|
|
tfWidget->autoAcceptTransfer(Settings::getInstance().getAutoAcceptDir(f->getPublicKey()));
|
2015-08-31 03:36:39 +08:00
|
|
|
}
|
|
|
|
else if (Settings::getInstance().getAutoSaveEnabled())
|
2015-08-31 20:59:39 +08:00
|
|
|
{ //global autosave to global directory
|
2015-06-20 20:16:54 +08:00
|
|
|
tfWidget->autoAcceptTransfer(Settings::getInstance().getGlobalAutoAcceptDir());
|
2014-12-14 04:11:03 +08:00
|
|
|
}
|
2015-06-13 00:52:41 +08:00
|
|
|
|
|
|
|
Widget::getInstance()->updateFriendActivity(f);
|
2014-06-26 06:30:24 +08:00
|
|
|
}
|
2014-06-27 06:42:45 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onAvInvite(uint32_t friendId, bool video)
|
2014-06-27 06:42:45 +08:00
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
if (friendId != f->getFriendId())
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2014-06-27 08:08:33 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
callConfirm = new CallConfirmWidget(video ? videoButton : callButton, *f);
|
2016-12-25 17:45:25 +08:00
|
|
|
insertChatMessage(ChatMessage::createChatInfoMessage(
|
|
|
|
tr("%1 calling").arg(f->getDisplayedName()),
|
|
|
|
ChatMessage::INFO, QDateTime::currentDateTime()));
|
|
|
|
|
2016-06-26 03:03:52 +08:00
|
|
|
/* AutoAcceptCall is set for this friend */
|
2016-12-30 06:14:48 +08:00
|
|
|
if ((video && Settings::getInstance().getAutoAcceptCall(f->getPublicKey()).testFlag(Settings::AutoAcceptCall::Video)) ||
|
|
|
|
(!video && Settings::getInstance().getAutoAcceptCall(f->getPublicKey()).testFlag(Settings::AutoAcceptCall::Audio)))
|
2014-06-30 10:39:43 +08:00
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
uint32_t friendId = f->getFriendId();
|
2016-06-26 03:03:52 +08:00
|
|
|
qDebug() << "automatic call answer";
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* coreav = Core::getInstance()->getAv();
|
2016-12-25 17:45:25 +08:00
|
|
|
QMetaObject::invokeMethod(coreav, "answerCall", Qt::QueuedConnection,
|
|
|
|
Q_ARG(uint32_t, friendId));
|
2016-06-26 03:03:52 +08:00
|
|
|
onAvStart(friendId,video);
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
callConfirm->show();
|
2015-10-08 06:52:05 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
connect(callConfirm.data(), &CallConfirmWidget::accepted,
|
|
|
|
this, &ChatForm::onAnswerCallTriggered);
|
|
|
|
connect(callConfirm.data(), &CallConfirmWidget::rejected,
|
|
|
|
this, &ChatForm::onRejectCallTriggered);
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
insertChatMessage(ChatMessage::createChatInfoMessage(
|
|
|
|
tr("%1 calling").arg(f->getDisplayedName()),
|
|
|
|
ChatMessage::INFO,
|
|
|
|
QDateTime::currentDateTime()));
|
2014-07-01 03:14:51 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
Widget::getInstance()->newFriendMessageAlert(friendId, false);
|
2016-06-26 03:03:52 +08:00
|
|
|
Audio& audio = Audio::getInstance();
|
|
|
|
audio.startLoop();
|
2016-10-26 17:17:08 +08:00
|
|
|
audio.playMono16Sound(Audio::getSound(Audio::Sound::IncomingCall));
|
2016-06-26 03:03:52 +08:00
|
|
|
}
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
void ChatForm::onAvStart(uint32_t friendId, bool video)
|
2014-06-27 08:08:33 +08:00
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
if (friendId != f->getFriendId())
|
|
|
|
{
|
2014-06-27 08:08:33 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
if (video)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2015-05-10 04:35:58 +08:00
|
|
|
showNetcam();
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2014-06-30 10:39:43 +08:00
|
|
|
else
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2015-10-11 14:38:44 +08:00
|
|
|
hideNetcam();
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
updateCallButtons();
|
2014-11-03 09:51:56 +08:00
|
|
|
startCounter();
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
void ChatForm::onAvEnd(uint32_t friendId)
|
2015-10-08 02:11:19 +08:00
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
if (friendId != f->getFriendId())
|
|
|
|
{
|
2015-10-08 02:11:19 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2015-10-08 02:11:19 +08:00
|
|
|
|
|
|
|
delete callConfirm;
|
2016-08-29 15:07:23 +08:00
|
|
|
|
|
|
|
//Fixes an OS X bug with ending a call while in full screen
|
|
|
|
if (netcam && netcam->isFullScreen())
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
netcam->showNormal();
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2015-10-08 02:11:19 +08:00
|
|
|
|
2015-10-24 08:26:32 +08:00
|
|
|
Audio::getInstance().stopLoop();
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
updateCallButtons();
|
2015-10-08 02:11:19 +08:00
|
|
|
stopCounter();
|
|
|
|
hideNetcam();
|
|
|
|
}
|
|
|
|
|
2015-10-08 06:52:05 +08:00
|
|
|
void ChatForm::showOutgoingCall(bool video)
|
2015-03-29 22:36:43 +08:00
|
|
|
{
|
2014-06-30 10:39:43 +08:00
|
|
|
if (video)
|
|
|
|
{
|
|
|
|
videoButton->setObjectName("yellow");
|
2016-08-29 15:07:23 +08:00
|
|
|
videoButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/videoButton/videoButton.css")));
|
2015-02-23 03:37:00 +08:00
|
|
|
videoButton->setToolTip(tr("Cancel video call"));
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
callButton->setObjectName("yellow");
|
2016-08-29 15:07:23 +08:00
|
|
|
callButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/callButton/callButton.css")));
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip(tr("Cancel audio call"));
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-10-08 02:11:19 +08:00
|
|
|
addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()),
|
2015-08-31 03:36:39 +08:00
|
|
|
ChatMessage::INFO,
|
|
|
|
QDateTime::currentDateTime());
|
2015-06-13 00:52:41 +08:00
|
|
|
|
|
|
|
Widget::getInstance()->updateFriendActivity(f);
|
2014-06-27 09:06:56 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 08:08:33 +08:00
|
|
|
void ChatForm::onAnswerCallTriggered()
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
delete callConfirm;
|
2015-01-25 11:57:20 +08:00
|
|
|
|
2015-10-24 08:26:32 +08:00
|
|
|
Audio::getInstance().stopLoop();
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
updateCallButtons();
|
2015-10-08 02:11:19 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2016-08-22 05:30:07 +08:00
|
|
|
if (!av->answerCall(f->getFriendId()))
|
2015-10-08 06:52:05 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
updateCallButtons();
|
2015-10-08 06:52:05 +08:00
|
|
|
stopCounter();
|
|
|
|
hideNetcam();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-22 05:30:07 +08:00
|
|
|
onAvStart(f->getFriendId(), av->isCallVideoEnabled(f));
|
2014-06-27 06:42:45 +08:00
|
|
|
}
|
|
|
|
|
2015-01-25 11:57:20 +08:00
|
|
|
void ChatForm::onRejectCallTriggered()
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
delete callConfirm;
|
2015-01-25 11:57:20 +08:00
|
|
|
|
2015-10-24 08:26:32 +08:00
|
|
|
Audio::getInstance().stopLoop();
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2016-08-22 05:30:07 +08:00
|
|
|
av->cancelCall(f->getFriendId());
|
2015-01-25 11:57:20 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 06:42:45 +08:00
|
|
|
void ChatForm::onCallTriggered()
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
|
|
|
if (av->isCallActive(f))
|
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
av->cancelCall(f->getFriendId());
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (av->startCall(f->getFriendId(), false))
|
2016-08-29 15:07:23 +08:00
|
|
|
{
|
2015-10-08 06:52:05 +08:00
|
|
|
showOutgoingCall(false);
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
2014-06-27 09:06:56 +08:00
|
|
|
}
|
2014-06-27 06:42:45 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
void ChatForm::onVideoCallTriggered()
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
|
|
|
if (av->isCallActive(f))
|
|
|
|
{
|
|
|
|
// TODO: We want to activate video on the active call.
|
|
|
|
if (av->isCallVideoEnabled(f))
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
|
|
|
av->cancelCall(f->getFriendId());
|
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
2016-08-22 05:30:07 +08:00
|
|
|
else if (av->startCall(f->getFriendId(), true))
|
2016-08-29 15:07:23 +08:00
|
|
|
{
|
2015-10-25 23:16:42 +08:00
|
|
|
showOutgoingCall(true);
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
2015-01-26 06:19:25 +08:00
|
|
|
}
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::updateCallButtons()
|
2015-01-26 06:19:25 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2016-12-25 18:53:15 +08:00
|
|
|
bool audio = av->isCallActive(f);
|
|
|
|
bool video = av->isCallVideoEnabled(f);
|
|
|
|
callButton->setEnabled(audio && !video);
|
|
|
|
videoButton->setEnabled(video);
|
|
|
|
if (audio)
|
2016-08-29 15:07:23 +08:00
|
|
|
{
|
2016-12-25 18:53:15 +08:00
|
|
|
videoButton->setObjectName(video ? "red" : "");
|
|
|
|
videoButton->setToolTip(video ? tr("End video call") :
|
|
|
|
tr("Can't start video call"));
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2016-12-25 18:53:15 +08:00
|
|
|
callButton->setObjectName((audio && !video) ? "red" : "");
|
|
|
|
callButton->setToolTip((audio && !video) ? tr("End audio call") :
|
|
|
|
tr("Can't start audio call"));
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const Status fs = f->getStatus();
|
2016-12-25 18:53:15 +08:00
|
|
|
bool online = fs != Status::Offline;
|
|
|
|
callButton->setEnabled(online);
|
|
|
|
videoButton->setEnabled(online);
|
2015-10-08 06:52:05 +08:00
|
|
|
|
2016-12-25 18:53:15 +08:00
|
|
|
callButton->setObjectName(online ? "green" : "");
|
|
|
|
callButton->setToolTip(online ? tr("Start audio call") :
|
|
|
|
tr("Can't start audio call"));
|
2016-08-29 15:07:23 +08:00
|
|
|
|
2016-12-25 18:53:15 +08:00
|
|
|
videoButton->setObjectName(online ? "green" : "");
|
|
|
|
videoButton->setToolTip(online ? tr("Start video call") :
|
|
|
|
tr("Can't start audio call"));
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
callButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/callButton/callButton.css")));
|
|
|
|
videoButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/videoButton/videoButton.css")));
|
|
|
|
|
|
|
|
updateMuteMicButton();
|
|
|
|
updateMuteVolButton();
|
2015-01-26 06:19:25 +08:00
|
|
|
}
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onMicMuteToggle()
|
2015-01-26 06:19:25 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
av->toggleMuteCallInput(f);
|
|
|
|
updateMuteMicButton();
|
|
|
|
}
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onVolMuteToggle()
|
|
|
|
{
|
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2015-10-08 00:56:19 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
av->toggleMuteCallOutput(f);
|
|
|
|
updateMuteVolButton();
|
2015-10-08 00:56:19 +08:00
|
|
|
}
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onFileSendFailed(uint32_t friendId, const QString &fname)
|
2015-10-08 00:56:19 +08:00
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
if (friendId != f->getFriendId())
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2015-10-08 00:56:19 +08:00
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
addSystemInfoMessage(tr("Failed to send file \"%1\"").arg(fname),
|
|
|
|
ChatMessage::ERROR, QDateTime::currentDateTime());
|
2014-10-25 17:29:25 +08:00
|
|
|
}
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status)
|
2014-06-27 09:06:56 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
// Disable call buttons if friend is offline
|
2016-08-22 05:30:07 +08:00
|
|
|
if(friendId != f->getFriendId())
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
|
|
|
|
if (status == Status::Offline)
|
2016-07-03 16:15:17 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
// Hide the "is typing" message when a friend goes offline
|
|
|
|
setFriendTyping(false);
|
2016-07-03 16:15:17 +08:00
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
else
|
2014-08-19 23:20:20 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
QTimer::singleShot(250, this, SLOT(onDeliverOfflineMessages()));
|
2014-08-19 23:20:20 +08:00
|
|
|
}
|
2014-09-06 03:27:26 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
updateCallButtons();
|
|
|
|
|
|
|
|
if (Settings::getInstance().getStatusChangeNotificationEnabled())
|
2014-10-28 20:50:30 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
QString fStatus = "";
|
|
|
|
switch (status)
|
2015-02-23 03:37:00 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
case Status::Away:
|
|
|
|
fStatus = tr("away", "contact status"); break;
|
|
|
|
case Status::Busy:
|
|
|
|
fStatus = tr("busy", "contact status"); break;
|
|
|
|
case Status::Offline:
|
|
|
|
fStatus = tr("offline", "contact status"); break;
|
|
|
|
case Status::Online:
|
|
|
|
fStatus = tr("online", "contact status"); break;
|
2015-02-23 03:37:00 +08:00
|
|
|
}
|
2014-10-28 20:50:30 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"")
|
|
|
|
.arg(f->getDisplayedName()).arg(fStatus),
|
|
|
|
ChatMessage::INFO, QDateTime::currentDateTime());
|
2014-10-28 20:50:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onFriendTypingChanged(quint32 friendId, bool isTyping)
|
2014-09-24 00:52:06 +08:00
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
if (friendId == f->getFriendId())
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
setFriendTyping(isTyping);
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
2014-09-24 00:52:06 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onFriendNameChanged(const QString& name)
|
|
|
|
{
|
|
|
|
if (sender() == f)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
setName(name);
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2014-09-24 00:52:06 +08:00
|
|
|
}
|
2014-09-24 23:28:38 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onFriendMessageReceived(quint32 friendId, const QString& message,
|
|
|
|
bool isAction)
|
2016-07-03 16:15:17 +08:00
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
if (friendId != f->getFriendId())
|
|
|
|
{
|
2016-07-18 21:11:17 +08:00
|
|
|
return;
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2016-07-18 21:11:17 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
QDateTime timestamp = QDateTime::currentDateTime();
|
2016-12-30 06:14:48 +08:00
|
|
|
addMessage(f->getPublicKey(), message, isAction, timestamp, true);
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
2016-07-18 21:11:17 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onStatusMessage(const QString& message)
|
|
|
|
{
|
|
|
|
if (sender() == f)
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
setStatusMessage(message);
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
2016-07-18 21:11:17 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onReceiptReceived(quint32 friendId, int receipt)
|
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
if (friendId == f->getFriendId())
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
f->getChatForm()->getOfflineMsgEngine()->dischargeReceipt(receipt);
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2016-07-03 16:15:17 +08:00
|
|
|
}
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::onAvatarChange(uint32_t friendId, const QPixmap &pic)
|
2014-09-24 23:28:38 +08:00
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
if (friendId != f->getFriendId())
|
|
|
|
{
|
2014-09-24 23:28:38 +08:00
|
|
|
return;
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2014-09-24 23:28:38 +08:00
|
|
|
|
2014-09-26 22:39:29 +08:00
|
|
|
avatar->setPixmap(pic);
|
2014-09-24 23:28:38 +08:00
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
|
2015-08-19 01:40:11 +08:00
|
|
|
GenericNetCamView *ChatForm::createNetcam()
|
|
|
|
{
|
2015-10-11 14:38:44 +08:00
|
|
|
qDebug() << "creating netcam";
|
2016-08-22 05:30:07 +08:00
|
|
|
uint32_t friendId = f->getFriendId();
|
|
|
|
NetCamView* view = new NetCamView(friendId, this);
|
|
|
|
CoreAV* av = Core::getInstance()->getAv();
|
2016-12-25 17:45:25 +08:00
|
|
|
VideoSource* source = av->getVideoSourceFromCall(friendId);
|
|
|
|
view->show(source, f->getDisplayedName());
|
2015-08-19 01:40:11 +08:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
void ChatForm::dragEnterEvent(QDragEnterEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasUrls())
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2014-09-26 00:03:25 +08:00
|
|
|
ev->acceptProposedAction();
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::dropEvent(QDropEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasUrls())
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
Core* core = Core::getInstance();
|
2014-09-26 00:03:25 +08:00
|
|
|
for (QUrl url : ev->mimeData()->urls())
|
|
|
|
{
|
|
|
|
QFileInfo info(url.path());
|
2015-01-19 07:22:40 +08:00
|
|
|
QFile file(info.absoluteFilePath());
|
2016-12-25 17:45:25 +08:00
|
|
|
|
|
|
|
if (url.isValid() && !url.isLocalFile() &&
|
|
|
|
url.toString().length() < TOX_MAX_MESSAGE_LENGTH)
|
2015-04-13 02:24:33 +08:00
|
|
|
{
|
|
|
|
SendMessageStr(url.toString());
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
|
2015-01-19 07:22:40 +08:00
|
|
|
if (!file.exists() || !file.open(QIODevice::ReadOnly))
|
|
|
|
{
|
2015-03-28 07:07:05 +08:00
|
|
|
info.setFile(url.toLocalFile());
|
|
|
|
file.setFileName(info.absoluteFilePath());
|
|
|
|
if (!file.exists() || !file.open(QIODevice::ReadOnly))
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
QMessageBox::warning(this, tr("Unable to open"),
|
|
|
|
tr("qTox wasn't able to open %1")
|
|
|
|
.arg(info.fileName()));
|
2015-03-28 07:07:05 +08:00
|
|
|
continue;
|
|
|
|
}
|
2015-01-19 07:22:40 +08:00
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
|
2015-01-19 07:22:40 +08:00
|
|
|
if (file.isSequential())
|
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
QMessageBox::critical(0, tr("Bad idea"),
|
|
|
|
tr("You're trying to send a sequential"
|
|
|
|
" file, which is not going to work!"));
|
2015-01-19 07:22:40 +08:00
|
|
|
file.close();
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
|
2015-01-19 07:22:40 +08:00
|
|
|
file.close();
|
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
if (info.exists())
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
|
|
|
core->sendFile(f->getFriendId(), info.fileName(),
|
2016-08-29 15:07:23 +08:00
|
|
|
info.absoluteFilePath(), info.size());
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 03:23:20 +08:00
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
void ChatForm::onAvatarRemoved(uint32_t friendId)
|
2014-09-27 03:23:20 +08:00
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
if (friendId != f->getFriendId())
|
|
|
|
{
|
2014-09-27 03:23:20 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2014-09-27 03:23:20 +08:00
|
|
|
|
2016-01-21 11:47:26 +08:00
|
|
|
avatar->setPixmap(QPixmap(":/img/contact_dark.svg"));
|
2014-09-27 03:23:20 +08:00
|
|
|
}
|
2014-10-11 00:22:57 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::clearChatArea(bool notInForm)
|
|
|
|
{
|
|
|
|
GenericChatForm::clearChatArea(notInForm);
|
|
|
|
f->getChatForm()->getOfflineMsgEngine()->removeAllReceipts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onDeliverOfflineMessages()
|
|
|
|
{
|
|
|
|
f->getChatForm()->getOfflineMsgEngine()->deliverOfflineMsgs();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onLoadChatHistory()
|
|
|
|
{
|
|
|
|
if (sender() == f)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
loadHistory(QDateTime::currentDateTime().addDays(-7), true);
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
|
|
|
|
2016-11-09 05:21:08 +08:00
|
|
|
// TODO: Split on smaller methods (style)
|
2014-11-10 19:30:56 +08:00
|
|
|
void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
2014-10-11 00:22:57 +08:00
|
|
|
{
|
2015-02-16 23:48:22 +08:00
|
|
|
QDateTime now = historyBaselineDate.addMSecs(-1);
|
2014-10-11 00:22:57 +08:00
|
|
|
|
2014-11-09 05:43:33 +08:00
|
|
|
if (since > now)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2014-11-09 05:43:33 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2015-01-05 02:29:06 +08:00
|
|
|
if (!earliestMessage.isNull())
|
2014-11-09 05:43:33 +08:00
|
|
|
{
|
2015-01-05 02:29:06 +08:00
|
|
|
if (earliestMessage < since)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2014-10-11 01:32:10 +08:00
|
|
|
return;
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2015-01-05 02:29:06 +08:00
|
|
|
if (earliestMessage < now)
|
2014-10-11 01:32:10 +08:00
|
|
|
{
|
2015-01-05 02:29:06 +08:00
|
|
|
now = earliestMessage;
|
2014-11-09 05:43:33 +08:00
|
|
|
now = now.addMSecs(-1);
|
2014-10-11 01:32:10 +08:00
|
|
|
}
|
2014-11-09 05:43:33 +08:00
|
|
|
}
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
History* history = Nexus::getProfile()->getHistory();
|
|
|
|
QString pk = f->getToxId().getPublicKeyString();
|
|
|
|
QList<History::HistMessage> msgs = history->getChatHistory(pk, since, now);
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2016-12-30 06:14:48 +08:00
|
|
|
ToxPk storedPrevId = previousId;
|
|
|
|
ToxPk prevId;
|
2015-01-05 02:29:06 +08:00
|
|
|
|
2015-01-05 17:51:01 +08:00
|
|
|
QList<ChatLine::Ptr> historyMessages;
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2014-11-09 07:08:28 +08:00
|
|
|
QDate lastDate(1,0,0);
|
2014-11-09 05:43:33 +08:00
|
|
|
for (const auto &it : msgs)
|
|
|
|
{
|
2014-11-09 07:08:28 +08:00
|
|
|
// Show the date every new day
|
|
|
|
QDateTime msgDateTime = it.timestamp.toLocalTime();
|
|
|
|
QDate msgDate = msgDateTime.date();
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2014-11-09 07:08:28 +08:00
|
|
|
if (msgDate > lastDate)
|
|
|
|
{
|
|
|
|
lastDate = msgDate;
|
2016-11-09 05:21:08 +08:00
|
|
|
QString dateText = msgDate.toString(Settings::getInstance().getDateFormat());
|
2016-12-25 17:45:25 +08:00
|
|
|
auto msg = ChatMessage::createChatInfoMessage(dateText,
|
|
|
|
ChatMessage::INFO,
|
|
|
|
QDateTime());
|
|
|
|
historyMessages.append(msg);
|
2014-11-09 07:08:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show each messages
|
2016-11-09 05:21:08 +08:00
|
|
|
const Core* core = Core::getInstance();
|
2016-12-30 06:14:48 +08:00
|
|
|
ToxPk authorPk(ToxId(it.sender).getPublicKey());
|
2016-11-09 05:21:08 +08:00
|
|
|
QString authorStr;
|
2016-12-30 06:14:48 +08:00
|
|
|
bool isSelf = authorPk == core->getSelfId().getPublicKey();
|
2016-11-09 05:21:08 +08:00
|
|
|
|
|
|
|
if (!it.dispName.isEmpty())
|
|
|
|
{
|
|
|
|
authorStr = it.dispName;
|
|
|
|
}
|
|
|
|
else if (isSelf)
|
|
|
|
{
|
|
|
|
authorStr = core->getUsername();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-30 06:14:48 +08:00
|
|
|
authorStr = resolveToxId(authorPk);
|
2016-11-09 05:21:08 +08:00
|
|
|
}
|
2015-01-03 21:08:04 +08:00
|
|
|
|
2016-11-09 05:21:08 +08:00
|
|
|
bool isAction = it.message.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
|
|
|
|
bool needSending = !it.isSent && isSelf;
|
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
QString messageText = isAction ? it.message.mid(4) : it.message;
|
|
|
|
ChatMessage::MessageType type = isAction ? ChatMessage::ACTION : ChatMessage::NORMAL;
|
|
|
|
QDateTime dateTime = needSending ? QDateTime() : msgDateTime;
|
|
|
|
auto msg = ChatMessage::createChatMessage(
|
|
|
|
authorStr, messageText, type, isSelf, dateTime);
|
2015-01-05 02:29:06 +08:00
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
uint prev = prevMsgDateTime.secsTo(msgDateTime);
|
|
|
|
if (!isAction && prevId == authorId && prev < getChatLog()->repNameAfter)
|
|
|
|
{
|
2015-01-05 02:29:06 +08:00
|
|
|
msg->hideSender();
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2015-01-03 02:45:26 +08:00
|
|
|
|
2016-12-30 06:14:48 +08:00
|
|
|
prevId = authorPk;
|
2015-03-26 05:31:39 +08:00
|
|
|
prevMsgDateTime = msgDateTime;
|
2015-01-05 02:29:06 +08:00
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
if (needSending && processUndelivered)
|
2014-11-10 19:30:56 +08:00
|
|
|
{
|
2016-12-25 17:45:25 +08:00
|
|
|
Core* core = Core::getInstance();
|
|
|
|
uint32_t friendId = f->getFriendId();
|
|
|
|
int rec = isAction ? core->sendAction(friendId, msg->toString())
|
|
|
|
: core->sendMessage(friendId, msg->toString());
|
|
|
|
getOfflineMsgEngine()->registerReceipt(rec, it.id, msg);
|
2014-11-10 19:30:56 +08:00
|
|
|
}
|
2016-12-25 17:45:25 +08:00
|
|
|
|
2015-02-12 16:12:14 +08:00
|
|
|
historyMessages.append(msg);
|
2014-11-09 05:43:33 +08:00
|
|
|
}
|
|
|
|
|
2015-01-05 02:29:06 +08:00
|
|
|
previousId = storedPrevId;
|
2014-11-09 05:43:33 +08:00
|
|
|
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2015-01-05 02:29:06 +08:00
|
|
|
earliestMessage = since;
|
2014-10-14 13:49:27 +08:00
|
|
|
|
2015-01-05 17:51:01 +08:00
|
|
|
chatWidget->insertChatlineOnTop(historyMessages);
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2014-11-09 05:43:33 +08:00
|
|
|
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
|
|
|
|
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
|
|
|
|
}
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
void ChatForm::onScreenshotClicked()
|
2015-03-10 01:32:30 +08:00
|
|
|
{
|
2015-03-25 23:05:44 +08:00
|
|
|
doScreenshot();
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 23:05:44 +08:00
|
|
|
// Give the window manager a moment to open the fullscreen grabber window
|
2015-05-08 02:35:35 +08:00
|
|
|
QTimer::singleShot(500, this, SLOT(hideFileMenu()));
|
2015-03-25 21:43:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::doScreenshot()
|
|
|
|
{
|
2016-07-21 16:49:50 +08:00
|
|
|
// note: grabber is self-managed and will destroy itself when done
|
|
|
|
ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber;
|
2016-06-23 06:47:44 +08:00
|
|
|
|
|
|
|
connect(screenshotGrabber, &ScreenshotGrabber::screenshotTaken,
|
|
|
|
this, &ChatForm::onScreenshotTaken);
|
|
|
|
|
2015-03-25 21:43:40 +08:00
|
|
|
screenshotGrabber->showGrabber();
|
2016-06-23 06:47:44 +08:00
|
|
|
|
2015-05-26 06:33:10 +08:00
|
|
|
// Create dir for screenshots
|
2016-03-23 19:16:38 +08:00
|
|
|
QDir(Settings::getInstance().getAppDataDirPath()).mkpath("screenshots");
|
2015-03-10 01:32:30 +08:00
|
|
|
}
|
|
|
|
|
2015-03-25 21:51:14 +08:00
|
|
|
void ChatForm::onScreenshotTaken(const QPixmap &pixmap) {
|
2015-10-04 17:08:55 +08:00
|
|
|
// use ~ISO 8601 for screenshot timestamp, considering FS limitations
|
|
|
|
// https://en.wikipedia.org/wiki/ISO_8601
|
|
|
|
// Windows has to be supported, thus filename can't have `:` in it :/
|
|
|
|
// Format should be: `qTox_Screenshot_yyyy-MM-dd HH-mm-ss.zzz.png`
|
|
|
|
QString filepath = QString("%1screenshots%2qTox_Screenshot_%3.png")
|
2016-02-28 22:16:19 +08:00
|
|
|
.arg(Settings::getInstance().getAppDataDirPath())
|
2015-10-04 17:08:55 +08:00
|
|
|
.arg(QDir::separator())
|
|
|
|
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH-mm-ss.zzz"));
|
|
|
|
|
|
|
|
QFile file(filepath);
|
|
|
|
|
2016-07-21 16:51:50 +08:00
|
|
|
if (file.open(QFile::ReadWrite))
|
|
|
|
{
|
|
|
|
pixmap.save(&file, "PNG");
|
|
|
|
|
|
|
|
qint64 filesize = file.size();
|
|
|
|
file.close();
|
|
|
|
QFileInfo fi(file);
|
|
|
|
|
2016-08-22 05:30:07 +08:00
|
|
|
Core::getInstance()->sendFile(f->getFriendId(), fi.fileName(),
|
2016-08-29 15:07:23 +08:00
|
|
|
fi.filePath(), filesize);
|
2016-07-21 16:51:50 +08:00
|
|
|
}
|
|
|
|
else
|
2015-08-31 03:36:39 +08:00
|
|
|
{
|
2015-08-31 20:59:39 +08:00
|
|
|
QMessageBox::warning(this,
|
2016-08-22 05:30:07 +08:00
|
|
|
tr("Failed to open temporary file",
|
|
|
|
"Temporary file for screenshot"),
|
2015-08-31 03:36:39 +08:00
|
|
|
tr("qTox wasn't able to save the screenshot"));
|
|
|
|
}
|
2015-03-10 01:32:30 +08:00
|
|
|
}
|
|
|
|
|
2014-11-09 05:43:33 +08:00
|
|
|
void ChatForm::onLoadHistory()
|
|
|
|
{
|
2015-12-17 18:24:01 +08:00
|
|
|
if (!Nexus::getProfile()->isHistoryEnabled())
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2015-12-17 18:24:01 +08:00
|
|
|
return;
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2015-12-17 18:24:01 +08:00
|
|
|
|
2014-11-09 05:43:33 +08:00
|
|
|
LoadHistoryDialog dlg;
|
|
|
|
|
|
|
|
if (dlg.exec())
|
|
|
|
{
|
|
|
|
QDateTime fromTime = dlg.getFromDate();
|
|
|
|
loadHistory(fromTime);
|
2014-10-11 00:22:57 +08:00
|
|
|
}
|
|
|
|
}
|
2014-11-03 09:51:56 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::insertChatMessage(ChatMessage::Ptr msg)
|
2015-07-23 02:50:39 +08:00
|
|
|
{
|
2016-08-29 15:07:23 +08:00
|
|
|
GenericChatForm::insertChatMessage(msg);
|
|
|
|
|
2015-07-23 02:50:39 +08:00
|
|
|
if (netcam && bodySplitter->sizes()[1] == 0)
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2015-07-23 02:50:39 +08:00
|
|
|
netcam->setShowMessages(true, true);
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2015-07-23 02:50:39 +08:00
|
|
|
}
|
|
|
|
|
2016-04-24 12:15:54 +08:00
|
|
|
void ChatForm::onCopyStatusMessage()
|
|
|
|
{
|
2016-12-09 11:19:47 +08:00
|
|
|
// make sure to copy not truncated text directly from the friend
|
|
|
|
QString text = f->getStatusMessage();
|
2016-04-24 12:15:54 +08:00
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
|
|
|
|
if (clipboard)
|
|
|
|
{
|
|
|
|
clipboard->setText(text, QClipboard::Clipboard);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
void ChatForm::updateMuteMicButton()
|
|
|
|
{
|
|
|
|
const CoreAV* av = Core::getInstance()->getAv();
|
|
|
|
|
|
|
|
micButton->setEnabled(av->isCallActive(f));
|
|
|
|
if (micButton->isEnabled())
|
|
|
|
{
|
|
|
|
if (av->isCallInputMuted(f))
|
|
|
|
{
|
|
|
|
micButton->setObjectName("red");
|
|
|
|
micButton->setToolTip(tr("Unmute microphone"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->setToolTip(tr("Mute microphone"));
|
|
|
|
}
|
|
|
|
}
|
2016-08-29 21:48:38 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
micButton->setObjectName("");
|
|
|
|
micButton->setToolTip(tr("Microphone can be muted only during a call"));
|
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
|
2016-08-29 21:48:38 +08:00
|
|
|
QString stylePath = QStringLiteral(":/ui/micButton/micButton.css");
|
|
|
|
QString style = Style::getStylesheet(stylePath);
|
|
|
|
micButton->setStyleSheet(style);
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::updateMuteVolButton()
|
|
|
|
{
|
|
|
|
const CoreAV* av = Core::getInstance()->getAv();
|
|
|
|
|
|
|
|
volButton->setEnabled(av->isCallActive(f));
|
2016-08-29 21:48:38 +08:00
|
|
|
if (volButton->isEnabled())
|
2016-08-29 15:07:23 +08:00
|
|
|
{
|
|
|
|
if (av->isCallOutputMuted(f))
|
|
|
|
{
|
|
|
|
volButton->setObjectName("red");
|
|
|
|
volButton->setToolTip(tr("Unmute call"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->setToolTip(tr("Mute call"));
|
|
|
|
}
|
|
|
|
}
|
2016-08-29 21:42:56 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
volButton->setObjectName("");
|
|
|
|
volButton->setToolTip(tr("Sound can be disabled only during a call"));
|
|
|
|
}
|
2016-08-29 15:07:23 +08:00
|
|
|
|
2016-08-29 21:48:38 +08:00
|
|
|
QString stylePath = QStringLiteral(":/ui/volButton/volButton.css");
|
|
|
|
QString style = Style::getStylesheet(stylePath);
|
|
|
|
volButton->setStyleSheet(style);
|
2016-08-29 15:07:23 +08:00
|
|
|
}
|
|
|
|
|
2014-11-03 09:51:56 +08:00
|
|
|
void ChatForm::startCounter()
|
|
|
|
{
|
2015-01-26 06:19:25 +08:00
|
|
|
if (!callDurationTimer)
|
2014-11-03 09:51:56 +08:00
|
|
|
{
|
2015-01-26 06:19:25 +08:00
|
|
|
callDurationTimer = new QTimer();
|
2016-08-29 15:07:23 +08:00
|
|
|
connect(callDurationTimer, &QTimer::timeout,
|
|
|
|
this, &ChatForm::onUpdateTime);
|
2016-08-22 05:30:07 +08:00
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
callDurationTimer->start(1000);
|
2014-11-03 09:51:56 +08:00
|
|
|
timeElapsed.start();
|
|
|
|
callDuration->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::stopCounter()
|
|
|
|
{
|
2015-01-26 06:19:25 +08:00
|
|
|
if (callDurationTimer)
|
2014-11-03 09:51:56 +08:00
|
|
|
{
|
2016-08-22 05:30:07 +08:00
|
|
|
QString dhms = secondsToDHMS(timeElapsed.elapsed()/1000);
|
|
|
|
QString name = f->getDisplayedName();
|
|
|
|
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(name, dhms),
|
2015-01-05 01:21:35 +08:00
|
|
|
ChatMessage::INFO, QDateTime::currentDateTime());
|
2016-08-22 05:30:07 +08:00
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
callDurationTimer->stop();
|
2014-11-05 20:02:38 +08:00
|
|
|
callDuration->setText("");
|
2014-11-03 09:51:56 +08:00
|
|
|
callDuration->hide();
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
delete callDurationTimer;
|
2015-01-26 07:06:44 +08:00
|
|
|
callDurationTimer = nullptr;
|
2014-11-03 09:51:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
void ChatForm::onUpdateTime()
|
2014-11-03 09:51:56 +08:00
|
|
|
{
|
|
|
|
callDuration->setText(secondsToDHMS(timeElapsed.elapsed()/1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ChatForm::secondsToDHMS(quint32 duration)
|
|
|
|
{
|
|
|
|
QString res;
|
|
|
|
QString cD = tr("Call duration: ");
|
|
|
|
int seconds = (int) (duration % 60);
|
|
|
|
duration /= 60;
|
|
|
|
int minutes = (int) (duration % 60);
|
|
|
|
duration /= 60;
|
|
|
|
int hours = (int) (duration % 24);
|
|
|
|
int days = (int) (duration / 24);
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-12-04 22:51:10 +08:00
|
|
|
// I assume no one will ever have call longer than a month
|
|
|
|
if (days)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2015-12-04 22:51:10 +08:00
|
|
|
return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds);
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hours)
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds);
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minutes)
|
|
|
|
{
|
2015-12-04 22:51:10 +08:00
|
|
|
return cD + res.sprintf("%02dm %02ds", minutes, seconds);
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return cD + res.sprintf("%02ds", seconds);
|
2014-11-03 09:51:56 +08:00
|
|
|
}
|
2014-11-09 20:32:19 +08:00
|
|
|
|
2015-01-04 19:20:36 +08:00
|
|
|
void ChatForm::setFriendTyping(bool isTyping)
|
|
|
|
{
|
2015-01-10 18:57:46 +08:00
|
|
|
chatWidget->setTypingNotificationVisible(isTyping);
|
|
|
|
|
2015-06-08 02:24:55 +08:00
|
|
|
Text* text = static_cast<Text*>(chatWidget->getTypingNotification()->getContent(1));
|
2016-08-22 05:30:07 +08:00
|
|
|
QString name = f->getDisplayedName();
|
|
|
|
text->setText("<div class=typing>" + tr("%1 is typing").arg(name) + "</div>");
|
2015-01-04 19:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-06-17 02:25:19 +08:00
|
|
|
void ChatForm::show(ContentLayout* contentLayout)
|
2015-01-25 11:57:20 +08:00
|
|
|
{
|
2015-06-17 02:25:19 +08:00
|
|
|
GenericChatForm::show(contentLayout);
|
2015-01-25 11:57:20 +08:00
|
|
|
|
|
|
|
if (callConfirm)
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2015-01-25 11:57:20 +08:00
|
|
|
callConfirm->show();
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2015-01-25 11:57:20 +08:00
|
|
|
}
|
|
|
|
|
2015-06-07 03:26:09 +08:00
|
|
|
void ChatForm::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
if (callConfirm)
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2015-06-07 03:26:09 +08:00
|
|
|
callConfirm->show();
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2015-06-07 03:26:09 +08:00
|
|
|
|
|
|
|
GenericChatForm::showEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-04-05 05:06:06 +08:00
|
|
|
void ChatForm::hideEvent(QHideEvent* event)
|
2015-01-25 11:57:20 +08:00
|
|
|
{
|
|
|
|
if (callConfirm)
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2015-01-25 11:57:20 +08:00
|
|
|
callConfirm->hide();
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-04-05 05:06:06 +08:00
|
|
|
GenericChatForm::hideEvent(event);
|
2015-01-25 11:57:20 +08:00
|
|
|
}
|
2015-02-08 00:18:25 +08:00
|
|
|
|
|
|
|
OfflineMsgEngine *ChatForm::getOfflineMsgEngine()
|
|
|
|
{
|
|
|
|
return offlineEngine;
|
|
|
|
}
|
2015-04-13 02:24:33 +08:00
|
|
|
|
|
|
|
void ChatForm::SendMessageStr(QString msg)
|
|
|
|
{
|
|
|
|
if (msg.isEmpty())
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2015-04-13 02:24:33 +08:00
|
|
|
return;
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2015-04-13 02:24:33 +08:00
|
|
|
|
2016-07-31 22:17:11 +08:00
|
|
|
bool isAction = msg.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
|
2015-04-13 02:24:33 +08:00
|
|
|
if (isAction)
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2016-07-31 22:17:11 +08:00
|
|
|
msg.remove(0, ACTION_PREFIX.length());
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2015-04-13 02:24:33 +08:00
|
|
|
|
|
|
|
QList<CString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
|
|
|
|
QDateTime timestamp = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
for (CString& c_msg : splittedMsg)
|
|
|
|
{
|
|
|
|
QString qt_msg = CString::toString(c_msg.data(), c_msg.size());
|
|
|
|
QString qt_msg_hist = qt_msg;
|
|
|
|
if (isAction)
|
2016-08-22 05:30:07 +08:00
|
|
|
{
|
2016-07-31 22:17:11 +08:00
|
|
|
qt_msg_hist = ACTION_PREFIX + qt_msg;
|
2016-08-22 05:30:07 +08:00
|
|
|
}
|
2015-04-13 02:24:33 +08:00
|
|
|
|
|
|
|
bool status = !Settings::getInstance().getFauxOfflineMessaging();
|
|
|
|
|
2015-05-26 05:08:39 +08:00
|
|
|
ChatMessage::Ptr ma = addSelfMessage(qt_msg, isAction, timestamp, false);
|
2015-04-13 02:24:33 +08:00
|
|
|
|
2016-12-25 17:45:25 +08:00
|
|
|
Core* core = Core::getInstance();
|
|
|
|
uint32_t friendId = f->getFriendId();
|
|
|
|
int rec = isAction ? core->sendAction(friendId, qt_msg)
|
|
|
|
: core->sendMessage(friendId, qt_msg);
|
2015-12-31 21:36:12 +08:00
|
|
|
|
|
|
|
Profile* profile = Nexus::getProfile();
|
|
|
|
if (profile->isHistoryEnabled())
|
|
|
|
{
|
|
|
|
auto* offMsgEngine = getOfflineMsgEngine();
|
2016-12-25 17:45:25 +08:00
|
|
|
QString selfPk = Core::getInstance()->getSelfId().publicKey;
|
|
|
|
QString pk = f->getToxId().getPublicKeyString();
|
|
|
|
QString name = Core::getInstance()->getUsername();
|
|
|
|
profile->getHistory()->addNewMessage(
|
|
|
|
pk, qt_msg_hist, selfPk, timestamp, status,
|
|
|
|
name, [offMsgEngine, rec, ma](int64_t id)
|
2015-12-31 21:36:12 +08:00
|
|
|
{
|
|
|
|
offMsgEngine->registerReceipt(rec, id, ma);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
2015-12-17 18:24:01 +08:00
|
|
|
{
|
2016-08-15 17:00:06 +08:00
|
|
|
// TODO: Make faux-offline messaging work partially with the history disabled
|
2015-12-31 21:36:12 +08:00
|
|
|
ma->markAsSent(QDateTime::currentDateTime());
|
|
|
|
}
|
2015-04-13 02:24:33 +08:00
|
|
|
|
|
|
|
msgEdit->setLastMessage(msg); //set last message only when sending it
|
2015-06-12 03:27:54 +08:00
|
|
|
|
2015-06-12 21:53:44 +08:00
|
|
|
Widget::getInstance()->updateFriendActivity(f);
|
2015-04-13 02:24:33 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-10 04:35:58 +08:00
|
|
|
|
2015-06-06 03:37:01 +08:00
|
|
|
void ChatForm::retranslateUi()
|
|
|
|
{
|
2015-10-03 19:22:34 +08:00
|
|
|
QString volObjectName = volButton->objectName();
|
|
|
|
QString micObjectName = micButton->objectName();
|
2015-06-06 03:37:01 +08:00
|
|
|
loadHistoryAction->setText(tr("Load chat history..."));
|
2016-04-24 12:15:54 +08:00
|
|
|
copyStatusAction->setText(tr("Copy"));
|
2015-10-03 19:22:34 +08:00
|
|
|
|
2016-08-29 15:07:23 +08:00
|
|
|
updateMuteMicButton();
|
|
|
|
updateMuteVolButton();
|
2015-10-10 20:49:30 +08:00
|
|
|
|
2015-07-23 02:50:39 +08:00
|
|
|
if (netcam)
|
2016-12-25 17:45:25 +08:00
|
|
|
{
|
2015-07-23 02:50:39 +08:00
|
|
|
netcam->setShowMessages(chatWidget->isVisible());
|
2016-12-25 17:45:25 +08:00
|
|
|
}
|
2015-06-06 03:37:01 +08:00
|
|
|
}
|