2014-07-07 00:19:45 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2014-09-11 21:44:34 +08:00
|
|
|
#include <QDebug>
|
2015-06-11 00:11:50 +08:00
|
|
|
#include <QBoxLayout>
|
2014-09-11 21:44:34 +08:00
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
2014-09-26 00:03:25 +08:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDragEnterEvent>
|
2014-09-26 22:39:29 +08:00
|
|
|
#include <QBitmap>
|
2015-03-10 01:32:30 +08:00
|
|
|
#include <QScreen>
|
|
|
|
#include <QTemporaryFile>
|
2016-04-24 12:15:54 +08:00
|
|
|
#include <QApplication>
|
2015-03-10 01:32:30 +08:00
|
|
|
#include <QGuiApplication>
|
2015-06-08 02:24:55 +08:00
|
|
|
#include <QStyle>
|
2015-07-23 02:50:39 +08:00
|
|
|
#include <QSplitter>
|
2016-04-24 12:15:54 +08:00
|
|
|
#include <QClipboard>
|
2015-06-08 02:24:55 +08:00
|
|
|
#include <cassert>
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "chatform.h"
|
2015-10-24 08:26:32 +08:00
|
|
|
#include "src/audio/audio.h"
|
2015-04-24 08:32:09 +08:00
|
|
|
#include "src/core/core.h"
|
2015-06-26 19:00:16 +08:00
|
|
|
#include "src/core/coreav.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/friend.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/widget/style.h"
|
|
|
|
#include "src/persistence/settings.h"
|
|
|
|
#include "src/core/cstring.h"
|
|
|
|
#include "src/widget/tool/callconfirmwidget.h"
|
2015-01-25 11:57:20 +08:00
|
|
|
#include "src/widget/friendwidget.h"
|
|
|
|
#include "src/widget/form/loadhistorydialog.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/widget/tool/chattextedit.h"
|
|
|
|
#include "src/widget/widget.h"
|
|
|
|
#include "src/widget/maskablepixmapwidget.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/widget/tool/croppinglabel.h"
|
2014-11-12 23:45:24 +08:00
|
|
|
#include "src/chatlog/chatmessage.h"
|
2014-12-14 04:11:03 +08:00
|
|
|
#include "src/chatlog/content/filetransferwidget.h"
|
2015-01-11 18:57:33 +08:00
|
|
|
#include "src/chatlog/chatlinecontentproxy.h"
|
2015-01-10 18:57:46 +08:00
|
|
|
#include "src/chatlog/content/text.h"
|
2015-01-05 01:21:35 +08:00
|
|
|
#include "src/chatlog/chatlog.h"
|
2015-08-19 01:40:11 +08:00
|
|
|
#include "src/video/netcamview.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/persistence/offlinemsgengine.h"
|
2015-03-10 01:32:30 +08:00
|
|
|
#include "src/widget/tool/screenshotgrabber.h"
|
2015-03-25 21:43:40 +08:00
|
|
|
#include "src/widget/tool/flyoutoverlaywidget.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/widget/translator.h"
|
2015-10-11 14:38:44 +08:00
|
|
|
#include "src/video/videosource.h"
|
|
|
|
#include "src/video/camerasource.h"
|
2015-12-17 18:24:01 +08:00
|
|
|
#include "src/nexus.h"
|
|
|
|
#include "src/persistence/profile.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
ChatForm::ChatForm(Friend* chatFriend)
|
2014-09-05 02:09:55 +08:00
|
|
|
: f(chatFriend)
|
2015-09-28 01:59:26 +08:00
|
|
|
, isTyping{false}
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2015-10-08 06:52:05 +08:00
|
|
|
Core* core = Core::getInstance();
|
|
|
|
coreav = core->getAv();
|
|
|
|
|
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;
|
|
|
|
disableCallButtonsTimer = nullptr;
|
2014-08-16 04:08:19 +08:00
|
|
|
|
2015-01-18 19:20:13 +08:00
|
|
|
chatWidget->setTypingNotification(ChatMessage::createTypingNotification());
|
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-07-23 02:50:39 +08:00
|
|
|
chatWidget->setMinimumHeight(160);
|
|
|
|
connect(this, &GenericChatForm::messageInserted, this, &ChatForm::onMessageInserted);
|
|
|
|
|
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
|
|
|
|
2015-10-08 06:52:05 +08:00
|
|
|
connect(core, &Core::fileSendStarted, this, &ChatForm::startFileSend);
|
2014-08-10 20:47:46 +08:00
|
|
|
connect(sendButton, &QPushButton::clicked, this, &ChatForm::onSendTriggered);
|
|
|
|
connect(fileButton, &QPushButton::clicked, this, &ChatForm::onAttachClicked);
|
2015-03-25 09:48:26 +08:00
|
|
|
connect(screenshotButton, &QPushButton::clicked, this, &ChatForm::onScreenshotClicked);
|
2014-08-10 20:47:46 +08:00
|
|
|
connect(callButton, &QPushButton::clicked, this, &ChatForm::onCallTriggered);
|
|
|
|
connect(videoButton, &QPushButton::clicked, this, &ChatForm::onVideoCallTriggered);
|
|
|
|
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
2015-01-04 19:20:36 +08:00
|
|
|
connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged);
|
2015-10-08 06:52:05 +08:00
|
|
|
connect(core, &Core::fileSendFailed, this, &ChatForm::onFileSendFailed);
|
2016-01-18 21:50:11 +08:00
|
|
|
connect(this, &ChatForm::chatAreaCleared, getOfflineMsgEngine(), &OfflineMsgEngine::removeAllReceipts);
|
2016-04-24 12:15:54 +08:00
|
|
|
connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this, [&](const QPoint& pos)
|
|
|
|
{
|
|
|
|
if(!statusMessageLabel->text().isEmpty())
|
|
|
|
{
|
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));
|
|
|
|
}
|
|
|
|
} );
|
2015-03-31 05:27:52 +08:00
|
|
|
connect(&typingTimer, &QTimer::timeout, this, [=]{
|
|
|
|
Core::getInstance()->sendTyping(f->getFriendID(), false);
|
|
|
|
isTyping = false;
|
|
|
|
} );
|
2015-06-08 02:25:05 +08:00
|
|
|
connect(nameLabel, &CroppingLabel::editFinished, this, [=](const QString& newName)
|
|
|
|
{
|
|
|
|
nameLabel->setText(newName);
|
|
|
|
emit aliasChanged(newName);
|
2015-01-02 20:04:59 +08:00
|
|
|
} );
|
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;
|
2015-01-25 11:57:20 +08:00
|
|
|
delete callConfirm;
|
2015-02-13 13:27:49 +08:00
|
|
|
delete offlineEngine;
|
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-02-28 19:53:15 +08:00
|
|
|
statusMessageLabel->setToolTip(Qt::convertFromPlainText(newMessage, Qt::WhiteSpaceNormal)); // for overlength messsages
|
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()
|
|
|
|
{
|
|
|
|
if (!Settings::getInstance().isTypingNotificationEnabled())
|
2015-02-11 12:43:25 +08:00
|
|
|
{
|
|
|
|
if (isTyping)
|
|
|
|
Core::getInstance()->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)
|
|
|
|
Core::getInstance()->sendTyping(f->getFriendID(), (isTyping = true));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Core::getInstance()->sendTyping(f->getFriendID(), (isTyping = false));
|
|
|
|
}
|
2015-01-04 19:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 04:43:28 +08:00
|
|
|
void ChatForm::onAttachClicked()
|
|
|
|
{
|
2015-08-31 03:36:39 +08:00
|
|
|
QStringList paths = QFileDialog::getOpenFileNames(this,
|
|
|
|
tr("Send a file"));
|
2014-10-17 20:29:48 +08:00
|
|
|
if (paths.isEmpty())
|
2014-06-26 04:43:28 +08:00
|
|
|
return;
|
2015-04-24 19:01:50 +08:00
|
|
|
|
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
|
|
|
{
|
2015-08-31 03:36:39 +08:00
|
|
|
QMessageBox::warning(this,
|
2015-08-31 20:59:39 +08:00
|
|
|
tr("Unable to open"),
|
2015-08-31 03:36:39 +08:00
|
|
|
tr("qTox wasn't able to open %1").arg(QFileInfo(path).fileName()));
|
2014-10-17 20:29:48 +08:00
|
|
|
continue;
|
2014-11-28 01:42:04 +08:00
|
|
|
}
|
2014-10-17 20:29:48 +08:00
|
|
|
if (file.isSequential())
|
|
|
|
{
|
2015-08-31 03:36:39 +08:00
|
|
|
QMessageBox::critical(this,
|
2015-08-31 20:59:39 +08:00
|
|
|
tr("Bad idea"),
|
2015-08-31 03:36:39 +08:00
|
|
|
tr("You're trying to send a special (sequential) file, that's not going to work!"));
|
2014-10-17 20:29:48 +08:00
|
|
|
file.close();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
long long 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
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
emit 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
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (file.friendId != f->getFriendID())
|
2014-06-26 07:35:30 +08:00
|
|
|
return;
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2014-11-03 01:36:27 +08:00
|
|
|
QString name;
|
2015-12-17 18:24:01 +08:00
|
|
|
if (!previousId.isSelf())
|
2014-11-03 01:36:27 +08:00
|
|
|
{
|
|
|
|
Core* core = Core::getInstance();
|
|
|
|
name = core->getUsername();
|
|
|
|
previousId = core->getSelfId();
|
|
|
|
}
|
2014-09-07 19:42:06 +08:00
|
|
|
|
2015-01-05 01:21:35 +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)
|
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (file.friendId != f->getFriendID())
|
2014-06-27 01:45:47 +08:00
|
|
|
return;
|
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;
|
2015-05-24 02:58:41 +08:00
|
|
|
ToxId friendId = f->getToxId();
|
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
|
|
|
|
2015-01-05 01:21:35 +08:00
|
|
|
ChatMessage::Ptr msg = ChatMessage::createFileTransferMessage(name, file, false, QDateTime::currentDateTime());
|
|
|
|
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
|
|
|
|
if (!Settings::getInstance().getAutoAcceptDir(f->getToxId()).isEmpty())
|
2014-12-14 04:11:03 +08:00
|
|
|
{
|
2015-06-08 02:24:55 +08:00
|
|
|
tfWidget->autoAcceptTransfer(Settings::getInstance().getAutoAcceptDir(f->getToxId()));
|
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
|
|
|
|
2015-09-28 01:59:26 +08:00
|
|
|
void ChatForm::onAvInvite(uint32_t FriendId, bool video)
|
2014-06-27 06:42:45 +08:00
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-06-27 08:08:33 +08:00
|
|
|
return;
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2015-09-28 01:59:26 +08:00
|
|
|
qDebug() << "onAvInvite";
|
2015-01-05 00:59:30 +08:00
|
|
|
|
2015-10-08 00:56:19 +08:00
|
|
|
disableCallButtons();
|
2014-06-30 10:39:43 +08:00
|
|
|
if (video)
|
|
|
|
{
|
2015-06-09 03:31:40 +08:00
|
|
|
callConfirm = new CallConfirmWidget(videoButton, *f);
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->setObjectName("yellow");
|
2015-02-23 03:44:05 +08:00
|
|
|
videoButton->setToolTip(tr("Accept video call"));
|
2015-10-08 06:52:05 +08:00
|
|
|
videoButton->style()->polish(videoButton);
|
2015-01-26 04:51:21 +08:00
|
|
|
connect(videoButton, &QPushButton::clicked, this, &ChatForm::onAnswerCallTriggered);
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-09 03:31:40 +08:00
|
|
|
callConfirm = new CallConfirmWidget(callButton, *f);
|
2014-06-30 10:39:43 +08:00
|
|
|
callButton->setObjectName("yellow");
|
2015-02-23 03:44:05 +08:00
|
|
|
callButton->setToolTip(tr("Accept audio call"));
|
2015-10-08 06:52:05 +08:00
|
|
|
callButton->style()->polish(callButton);
|
2015-01-26 04:51:21 +08:00
|
|
|
connect(callButton, &QPushButton::clicked, this, &ChatForm::onAnswerCallTriggered);
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
2015-06-24 00:54:00 +08:00
|
|
|
|
2015-10-08 06:52:05 +08:00
|
|
|
if (f->getFriendWidget()->chatFormIsSet(false))
|
|
|
|
callConfirm->show();
|
|
|
|
|
|
|
|
connect(callConfirm, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered);
|
|
|
|
connect(callConfirm, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered);
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-08-31 03:36:39 +08:00
|
|
|
insertChatMessage(ChatMessage::createChatInfoMessage(tr("%1 calling").arg(f->getDisplayedName()),
|
|
|
|
ChatMessage::INFO,
|
|
|
|
QDateTime::currentDateTime()));
|
2014-07-01 03:14:51 +08:00
|
|
|
|
2015-10-24 08:26:32 +08:00
|
|
|
Widget::getInstance()->newFriendMessageAlert(FriendId, false);
|
|
|
|
Audio& audio = Audio::getInstance();
|
|
|
|
audio.startLoop();
|
2015-11-15 09:38:16 +08:00
|
|
|
audio.playMono16Sound(QStringLiteral(":/audio/ToxicIncomingCall.pcm"));
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
2015-09-28 01:59:26 +08:00
|
|
|
void ChatForm::onAvStart(uint32_t FriendId, bool video)
|
2014-06-27 08:08:33 +08:00
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-06-27 08:08:33 +08:00
|
|
|
return;
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2015-09-28 01:59:26 +08:00
|
|
|
qDebug() << "onAvStart";
|
2015-01-05 00:59:30 +08:00
|
|
|
|
2014-08-30 01:28:22 +08:00
|
|
|
audioInputFlag = true;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = true;
|
2015-10-08 00:56:19 +08:00
|
|
|
disableCallButtons();
|
2015-01-03 21:08:04 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
if (video)
|
|
|
|
{
|
|
|
|
videoButton->setObjectName("red");
|
2015-02-23 03:37:00 +08:00
|
|
|
videoButton->setToolTip(tr("End video call"));
|
2015-10-08 02:11:19 +08:00
|
|
|
videoButton->style()->polish(videoButton);
|
2015-01-26 06:19:25 +08:00
|
|
|
connect(videoButton, SIGNAL(clicked()),
|
|
|
|
this, SLOT(onHangupCallTriggered()));
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2015-05-10 04:35:58 +08:00
|
|
|
showNetcam();
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
callButton->setObjectName("red");
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip(tr("End audio call"));
|
2015-10-08 02:11:19 +08:00
|
|
|
callButton->style()->polish(callButton);
|
2015-01-26 06:19:25 +08:00
|
|
|
connect(callButton, SIGNAL(clicked()),
|
|
|
|
this, SLOT(onHangupCallTriggered()));
|
2015-10-11 14:38:44 +08:00
|
|
|
hideNetcam();
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
2015-02-23 03:37:00 +08:00
|
|
|
|
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
micButton->setToolTip(tr("Mute microphone"));
|
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
|
|
|
volButton->setToolTip(tr("Mute call"));
|
|
|
|
|
|
|
|
connect(micButton, SIGNAL(clicked()),
|
|
|
|
this, SLOT(onMicMuteToggle()));
|
|
|
|
connect(volButton, SIGNAL(clicked()),
|
|
|
|
this, SLOT(onVolMuteToggle()));
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2014-11-03 09:51:56 +08:00
|
|
|
startCounter();
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 02:11:19 +08:00
|
|
|
void ChatForm::onAvEnd(uint32_t FriendId)
|
|
|
|
{
|
|
|
|
if (FriendId != f->getFriendID())
|
|
|
|
return;
|
|
|
|
|
|
|
|
qDebug() << "onAvEnd";
|
|
|
|
|
|
|
|
delete callConfirm;
|
|
|
|
callConfirm = nullptr;
|
|
|
|
|
2015-10-24 08:26:32 +08:00
|
|
|
Audio::getInstance().stopLoop();
|
|
|
|
|
2015-10-08 02:11:19 +08:00
|
|
|
enableCallButtons();
|
|
|
|
stopCounter();
|
|
|
|
hideNetcam();
|
|
|
|
}
|
|
|
|
|
2015-10-08 06:52:05 +08:00
|
|
|
void ChatForm::showOutgoingCall(bool video)
|
2015-03-29 22:36:43 +08:00
|
|
|
{
|
2015-10-08 06:52:05 +08:00
|
|
|
audioInputFlag = true;
|
|
|
|
audioOutputFlag = true;
|
2015-01-05 00:59:30 +08:00
|
|
|
|
2015-10-08 02:11:19 +08:00
|
|
|
disableCallButtons();
|
2014-06-30 10:39:43 +08:00
|
|
|
if (video)
|
|
|
|
{
|
|
|
|
videoButton->setObjectName("yellow");
|
|
|
|
videoButton->style()->polish(videoButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
videoButton->setToolTip(tr("Cancel video call"));
|
2015-10-08 06:52:05 +08:00
|
|
|
connect(videoButton, &QPushButton::clicked,
|
|
|
|
this, &ChatForm::onCancelCallTriggered);
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
callButton->setObjectName("yellow");
|
|
|
|
callButton->style()->polish(callButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip(tr("Cancel audio call"));
|
2015-10-08 06:52:05 +08:00
|
|
|
connect(callButton, &QPushButton::clicked,
|
|
|
|
this, &ChatForm::onCancelCallTriggered);
|
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()
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAnswerCallTriggered";
|
2015-01-25 11:57:20 +08:00
|
|
|
|
|
|
|
if (callConfirm)
|
|
|
|
{
|
|
|
|
delete callConfirm;
|
|
|
|
callConfirm = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-24 08:26:32 +08:00
|
|
|
Audio::getInstance().stopLoop();
|
|
|
|
|
2015-10-08 02:11:19 +08:00
|
|
|
disableCallButtons();
|
|
|
|
|
2015-10-08 06:52:05 +08:00
|
|
|
if (!coreav->answerCall(f->getFriendID()))
|
|
|
|
{
|
|
|
|
enableCallButtons();
|
|
|
|
stopCounter();
|
|
|
|
hideNetcam();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
onAvStart(f->getFriendID(), coreav->isCallVideoEnabled(f->getFriendID()));
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onHangupCallTriggered()
|
2015-01-05 00:59:30 +08:00
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onHangupCallTriggered";
|
2015-03-06 19:01:12 +08:00
|
|
|
|
|
|
|
//Fixes an OS X bug with ending a call while in full screen
|
2015-05-10 04:35:58 +08:00
|
|
|
if (netcam && netcam->isFullScreen())
|
2015-03-06 19:01:12 +08:00
|
|
|
netcam->showNormal();
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2014-08-30 00:16:16 +08:00
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2015-10-08 06:52:05 +08:00
|
|
|
coreav->cancelCall(f->getFriendID());
|
2015-01-26 07:06:44 +08:00
|
|
|
|
2015-09-28 01:59:26 +08:00
|
|
|
stopCounter();
|
2015-01-26 07:06:44 +08:00
|
|
|
enableCallButtons();
|
2015-10-08 06:52:05 +08:00
|
|
|
hideNetcam();
|
2014-06-27 06:42:45 +08:00
|
|
|
}
|
|
|
|
|
2015-01-25 11:57:20 +08:00
|
|
|
void ChatForm::onRejectCallTriggered()
|
|
|
|
{
|
|
|
|
qDebug() << "onRejectCallTriggered";
|
|
|
|
|
|
|
|
if (callConfirm)
|
|
|
|
{
|
|
|
|
delete callConfirm;
|
|
|
|
callConfirm = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-24 08:26:32 +08:00
|
|
|
Audio::getInstance().stopLoop();
|
|
|
|
|
2015-01-25 11:57:20 +08:00
|
|
|
audioInputFlag = false;
|
|
|
|
audioOutputFlag = false;
|
2015-10-08 06:52:05 +08:00
|
|
|
coreav->cancelCall(f->getFriendID());
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
enableCallButtons();
|
2015-10-08 00:56:19 +08:00
|
|
|
stopCounter();
|
2015-01-25 11:57:20 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 06:42:45 +08:00
|
|
|
void ChatForm::onCallTriggered()
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onCallTriggered";
|
2015-01-25 11:57:20 +08:00
|
|
|
|
2015-10-08 02:11:19 +08:00
|
|
|
disableCallButtons();
|
2015-10-08 06:52:05 +08:00
|
|
|
if (coreav->startCall(f->getFriendID(), false))
|
|
|
|
showOutgoingCall(false);
|
2015-10-24 08:40:56 +08:00
|
|
|
else
|
|
|
|
enableCallButtons();
|
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()
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onVideoCallTriggered";
|
2015-01-26 00:53:37 +08:00
|
|
|
|
2015-10-08 02:11:19 +08:00
|
|
|
disableCallButtons();
|
2015-10-08 06:52:05 +08:00
|
|
|
if (coreav->startCall(f->getFriendID(), true))
|
2015-10-25 23:16:42 +08:00
|
|
|
showOutgoingCall(true);
|
2015-10-25 04:55:18 +08:00
|
|
|
else
|
|
|
|
enableCallButtons();
|
2015-01-26 06:19:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onCancelCallTriggered()
|
|
|
|
{
|
|
|
|
qDebug() << "onCancelCallTriggered";
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2015-10-08 06:52:05 +08:00
|
|
|
if (!coreav->cancelCall(f->getFriendID()))
|
|
|
|
qWarning() << "Failed to cancel a call! Assuming we're not in call";
|
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
enableCallButtons();
|
2015-09-28 05:16:40 +08:00
|
|
|
stopCounter();
|
2015-05-10 04:35:58 +08:00
|
|
|
hideNetcam();
|
2015-01-26 06:19:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::enableCallButtons()
|
|
|
|
{
|
|
|
|
qDebug() << "enableCallButtons";
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2014-10-25 17:29:25 +08:00
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-10-08 00:56:19 +08:00
|
|
|
disableCallButtons();
|
|
|
|
|
|
|
|
if (disableCallButtonsTimer == nullptr)
|
|
|
|
{
|
|
|
|
disableCallButtonsTimer = new QTimer();
|
|
|
|
connect(disableCallButtonsTimer, SIGNAL(timeout()),
|
|
|
|
this, SLOT(onEnableCallButtons()));
|
|
|
|
disableCallButtonsTimer->start(1500); // 1.5sec
|
|
|
|
qDebug() << "timer started!!";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::disableCallButtons()
|
|
|
|
{
|
|
|
|
qDebug() << "disableCallButtons";
|
|
|
|
|
|
|
|
// Prevents race enable / disable / onEnable, when it should be disabled
|
|
|
|
if (disableCallButtonsTimer)
|
|
|
|
{
|
|
|
|
disableCallButtonsTimer->stop();
|
|
|
|
delete disableCallButtonsTimer;
|
|
|
|
disableCallButtonsTimer = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
micButton->setObjectName("grey");
|
|
|
|
micButton->style()->polish(micButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
micButton->setToolTip("");
|
2015-03-29 22:36:43 +08:00
|
|
|
micButton->disconnect();
|
2015-01-26 06:19:25 +08:00
|
|
|
volButton->setObjectName("grey");
|
|
|
|
volButton->style()->polish(volButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
volButton->setToolTip("");
|
2015-01-26 06:19:25 +08:00
|
|
|
volButton->disconnect();
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
callButton->setObjectName("grey");
|
|
|
|
callButton->style()->polish(callButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip("");
|
2014-10-25 17:29:25 +08:00
|
|
|
callButton->disconnect();
|
2015-01-26 06:19:25 +08:00
|
|
|
videoButton->setObjectName("grey");
|
|
|
|
videoButton->style()->polish(videoButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
videoButton->setToolTip("");
|
2014-10-25 17:29:25 +08:00
|
|
|
videoButton->disconnect();
|
|
|
|
}
|
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
void ChatForm::onEnableCallButtons()
|
2014-06-27 09:06:56 +08:00
|
|
|
{
|
2015-01-26 06:19:25 +08:00
|
|
|
qDebug() << "onEnableCallButtons";
|
2014-08-30 00:16:16 +08:00
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2015-02-23 03:37:00 +08:00
|
|
|
|
2014-06-28 13:14:38 +08:00
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
callButton->setToolTip(tr("Start audio call"));
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->setObjectName("green");
|
|
|
|
videoButton->style()->polish(videoButton);
|
2015-02-23 03:37:00 +08:00
|
|
|
videoButton->setToolTip(tr("Start video call"));
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
connect(callButton, SIGNAL(clicked()),
|
|
|
|
this, SLOT(onCallTriggered()));
|
|
|
|
connect(videoButton, SIGNAL(clicked()),
|
|
|
|
this, SLOT(onVideoCallTriggered()));
|
2015-02-23 03:37:00 +08:00
|
|
|
|
2015-01-26 06:19:25 +08:00
|
|
|
disableCallButtonsTimer->stop();
|
|
|
|
delete disableCallButtonsTimer;
|
2015-01-26 07:06:44 +08:00
|
|
|
disableCallButtonsTimer = nullptr;
|
2014-06-27 06:42:45 +08:00
|
|
|
}
|
2014-06-28 07:48:54 +08:00
|
|
|
|
2014-08-19 23:20:20 +08:00
|
|
|
void ChatForm::onMicMuteToggle()
|
|
|
|
{
|
2014-08-30 00:16:16 +08:00
|
|
|
if (audioInputFlag == true)
|
2014-08-19 23:20:20 +08:00
|
|
|
{
|
2015-10-08 06:52:05 +08:00
|
|
|
coreav->micMuteToggle(f->getFriendID());
|
2014-08-30 00:16:16 +08:00
|
|
|
if (micButton->objectName() == "red")
|
2015-02-23 03:37:00 +08:00
|
|
|
{
|
2014-08-30 00:16:16 +08:00
|
|
|
micButton->setObjectName("green");
|
2015-02-23 03:37:00 +08:00
|
|
|
micButton->setToolTip(tr("Mute microphone"));
|
|
|
|
}
|
2014-08-30 00:16:16 +08:00
|
|
|
else
|
2015-02-23 03:37:00 +08:00
|
|
|
{
|
2014-08-30 00:16:16 +08:00
|
|
|
micButton->setObjectName("red");
|
2015-02-23 03:37:00 +08:00
|
|
|
micButton->setToolTip(tr("Unmute microphone"));
|
|
|
|
}
|
2014-10-10 03:20:06 +08:00
|
|
|
|
|
|
|
Style::repolish(micButton);
|
2014-08-19 23:20:20 +08:00
|
|
|
}
|
|
|
|
}
|
2014-09-06 03:27:26 +08:00
|
|
|
|
2014-10-28 20:50:30 +08:00
|
|
|
void ChatForm::onVolMuteToggle()
|
|
|
|
{
|
|
|
|
if (audioOutputFlag == true)
|
|
|
|
{
|
2015-10-08 06:52:05 +08:00
|
|
|
coreav->volMuteToggle(f->getFriendID());
|
2014-10-28 20:50:30 +08:00
|
|
|
if (volButton->objectName() == "red")
|
2015-02-23 03:37:00 +08:00
|
|
|
{
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("green");
|
2015-02-23 03:37:00 +08:00
|
|
|
volButton->setToolTip(tr("Mute call"));
|
|
|
|
}
|
2014-10-28 20:50:30 +08:00
|
|
|
else
|
2015-02-23 03:37:00 +08:00
|
|
|
{
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("red");
|
2015-02-23 03:37:00 +08:00
|
|
|
volButton->setToolTip(tr("Unmute call"));
|
|
|
|
}
|
2014-10-28 20:50:30 +08:00
|
|
|
|
|
|
|
Style::repolish(volButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void ChatForm::onFileSendFailed(uint32_t FriendId, const QString &fname)
|
2014-09-24 00:52:06 +08:00
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-09-24 00:52:06 +08:00
|
|
|
return;
|
|
|
|
|
2015-01-05 01:21:35 +08:00
|
|
|
addSystemInfoMessage(tr("Failed to send file \"%1\"").arg(fname), ChatMessage::ERROR, QDateTime::currentDateTime());
|
2014-09-24 00:52:06 +08:00
|
|
|
}
|
2014-09-24 23:28:38 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void ChatForm::onAvatarChange(uint32_t FriendId, const QPixmap &pic)
|
2014-09-24 23:28:38 +08:00
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-09-24 23:28:38 +08:00
|
|
|
return;
|
|
|
|
|
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";
|
2015-08-19 01:40:11 +08:00
|
|
|
NetCamView* view = new NetCamView(f->getFriendID(), this);
|
2015-09-28 01:59:26 +08:00
|
|
|
view->show(Core::getInstance()->getAv()->getVideoSourceFromCall(f->getFriendID()), 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())
|
|
|
|
ev->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::dropEvent(QDropEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasUrls())
|
|
|
|
{
|
|
|
|
for (QUrl url : ev->mimeData()->urls())
|
|
|
|
{
|
|
|
|
QFileInfo info(url.path());
|
|
|
|
|
2015-01-19 07:22:40 +08:00
|
|
|
QFile file(info.absoluteFilePath());
|
2015-04-13 02:24:33 +08:00
|
|
|
if (url.isValid() && !url.isLocalFile() && (url.toString().length() < TOX_MAX_MESSAGE_LENGTH))
|
|
|
|
{
|
|
|
|
SendMessageStr(url.toString());
|
|
|
|
continue;
|
|
|
|
}
|
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))
|
|
|
|
{
|
2015-08-31 20:59:39 +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
|
|
|
}
|
|
|
|
if (file.isSequential())
|
|
|
|
{
|
2015-08-31 20:59:39 +08:00
|
|
|
QMessageBox::critical(0, tr("Bad idea"), tr("You're trying to send a special (sequential) file, that's not going to work!"));
|
2015-01-19 07:22:40 +08:00
|
|
|
file.close();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
if (info.exists())
|
2014-11-06 23:26:22 +08:00
|
|
|
Core::getInstance()->sendFile(f->getFriendID(), info.fileName(), info.absoluteFilePath(), info.size());
|
2014-09-26 00:03:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 03:23:20 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
void ChatForm::onAvatarRemoved(uint32_t FriendId)
|
2014-09-27 03:23:20 +08:00
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-09-27 03:23:20 +08:00
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
return;
|
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)
|
2014-10-11 01:32:10 +08:00
|
|
|
return;
|
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
|
|
|
|
2015-12-17 18:24:01 +08:00
|
|
|
auto msgs = Nexus::getProfile()->getHistory()->getChatHistory(f->getToxId().publicKey, since, now);
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2015-05-18 04:55:50 +08:00
|
|
|
ToxId storedPrevId = previousId;
|
|
|
|
ToxId 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;
|
2015-03-15 04:15:56 +08:00
|
|
|
historyMessages.append(ChatMessage::createChatInfoMessage(msgDate.toString(Settings::getInstance().getDateFormat()), ChatMessage::INFO, QDateTime()));
|
2014-11-09 07:08:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show each messages
|
2015-05-18 04:55:50 +08:00
|
|
|
ToxId authorId = ToxId(it.sender);
|
2015-12-17 18:24:01 +08:00
|
|
|
QString authorStr = !it.dispName.isEmpty() ? it.dispName : (authorId.isSelf() ? Core::getInstance()->getUsername() : resolveToxId(authorId));
|
2015-05-13 10:18:55 +08:00
|
|
|
bool isAction = it.message.startsWith("/me ", Qt::CaseInsensitive);
|
2016-01-21 13:19:30 +08:00
|
|
|
bool needSending = !it.isSent && authorId.isSelf();
|
2015-01-03 21:08:04 +08:00
|
|
|
|
2015-01-05 02:29:06 +08:00
|
|
|
ChatMessage::Ptr msg = ChatMessage::createChatMessage(authorStr,
|
2015-12-17 18:24:01 +08:00
|
|
|
isAction ? it.message.mid(4) : it.message,
|
2015-02-15 17:51:54 +08:00
|
|
|
isAction ? ChatMessage::ACTION : ChatMessage::NORMAL,
|
2015-12-17 18:24:01 +08:00
|
|
|
authorId.isSelf(),
|
2016-01-21 13:19:30 +08:00
|
|
|
needSending ? QDateTime() : msgDateTime);
|
2015-01-05 02:29:06 +08:00
|
|
|
|
2015-05-08 04:00:40 +08:00
|
|
|
if (!isAction && (prevId == authorId) && (prevMsgDateTime.secsTo(msgDateTime) < getChatLog()->repNameAfter) )
|
2015-01-05 02:29:06 +08:00
|
|
|
msg->hideSender();
|
2015-01-03 02:45:26 +08:00
|
|
|
|
2015-01-05 02:29:06 +08:00
|
|
|
prevId = authorId;
|
2015-03-26 05:31:39 +08:00
|
|
|
prevMsgDateTime = msgDateTime;
|
2015-01-05 02:29:06 +08:00
|
|
|
|
2016-01-21 13:19:30 +08:00
|
|
|
if (needSending)
|
2014-11-10 19:30:56 +08:00
|
|
|
{
|
|
|
|
if (processUndelivered)
|
|
|
|
{
|
|
|
|
int rec;
|
2015-01-03 02:45:26 +08:00
|
|
|
if (!isAction)
|
|
|
|
rec = Core::getInstance()->sendMessage(f->getFriendID(), msg->toString());
|
2014-11-10 19:30:56 +08:00
|
|
|
else
|
2015-01-03 02:45:26 +08:00
|
|
|
rec = Core::getInstance()->sendAction(f->getFriendID(), msg->toString());
|
2015-03-29 22:36:43 +08:00
|
|
|
|
2015-02-08 01:49:06 +08:00
|
|
|
getOfflineMsgEngine()->registerReceipt(rec, it.id, msg);
|
2014-11-10 19:30:56 +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()
|
|
|
|
{
|
2015-03-25 21:51:14 +08:00
|
|
|
ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber(this);
|
2015-03-10 01:32:30 +08:00
|
|
|
connect(screenshotGrabber, &ScreenshotGrabber::screenshotTaken, this, &ChatForm::onScreenshotTaken);
|
2015-03-25 21:43:40 +08:00
|
|
|
screenshotGrabber->showGrabber();
|
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);
|
|
|
|
|
|
|
|
if (!file.open(QFile::ReadWrite))
|
2015-08-31 03:36:39 +08:00
|
|
|
{
|
2015-08-31 20:59:39 +08:00
|
|
|
QMessageBox::warning(this,
|
|
|
|
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"));
|
|
|
|
return;
|
|
|
|
}
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-08-31 03:36:39 +08:00
|
|
|
pixmap.save(&file, "PNG");
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-08-31 03:36:39 +08:00
|
|
|
long long filesize = file.size();
|
|
|
|
file.close();
|
|
|
|
QFileInfo fi(file);
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-08-31 03:36:39 +08:00
|
|
|
emit sendFile(f->getFriendID(), fi.fileName(), fi.filePath(), filesize);
|
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())
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
2015-07-23 02:50:39 +08:00
|
|
|
void ChatForm::onMessageInserted()
|
|
|
|
{
|
|
|
|
if (netcam && bodySplitter->sizes()[1] == 0)
|
|
|
|
netcam->setShowMessages(true, true);
|
|
|
|
}
|
|
|
|
|
2016-04-24 12:15:54 +08:00
|
|
|
void ChatForm::onCopyStatusMessage()
|
|
|
|
{
|
|
|
|
QString text = statusMessageLabel->text();
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
|
|
|
|
if (clipboard)
|
|
|
|
{
|
|
|
|
clipboard->setText(text, QClipboard::Clipboard);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
connect(callDurationTimer, SIGNAL(timeout()), this, SLOT(onUpdateTime()));
|
|
|
|
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
|
|
|
{
|
2014-11-16 20:13:39 +08:00
|
|
|
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(f->getDisplayedName(),secondsToDHMS(timeElapsed.elapsed()/1000)),
|
2015-01-05 01:21:35 +08:00
|
|
|
ChatMessage::INFO, QDateTime::currentDateTime());
|
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)
|
|
|
|
return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds);
|
|
|
|
else if (hours)
|
2014-11-03 09:51:56 +08:00
|
|
|
return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds);
|
2015-12-04 22:51:10 +08:00
|
|
|
else if (minutes)
|
|
|
|
return cD + res.sprintf("%02dm %02ds", minutes, seconds);
|
|
|
|
else
|
|
|
|
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-04-23 06:04:31 +08:00
|
|
|
text->setText("<div class=typing>" + tr("%1 is typing").arg(f->getDisplayedName().toHtmlEscaped()) + "</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)
|
|
|
|
callConfirm->show();
|
|
|
|
}
|
|
|
|
|
2015-06-07 03:26:09 +08:00
|
|
|
void ChatForm::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
if (callConfirm)
|
|
|
|
callConfirm->show();
|
|
|
|
|
|
|
|
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)
|
|
|
|
callConfirm->hide();
|
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())
|
|
|
|
return;
|
|
|
|
|
2015-05-13 10:18:55 +08:00
|
|
|
bool isAction = msg.startsWith("/me ", Qt::CaseInsensitive);
|
2015-04-13 02:24:33 +08:00
|
|
|
if (isAction)
|
|
|
|
msg = msg = msg.right(msg.length() - 4);
|
|
|
|
|
|
|
|
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)
|
|
|
|
qt_msg_hist = "/me " + qt_msg;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
int rec;
|
|
|
|
if (isAction)
|
|
|
|
rec = Core::getInstance()->sendAction(f->getFriendID(), qt_msg);
|
|
|
|
else
|
|
|
|
rec = Core::getInstance()->sendMessage(f->getFriendID(), qt_msg);
|
|
|
|
|
2015-12-31 21:36:12 +08:00
|
|
|
|
|
|
|
Profile* profile = Nexus::getProfile();
|
|
|
|
if (profile->isHistoryEnabled())
|
|
|
|
{
|
|
|
|
auto* offMsgEngine = getOfflineMsgEngine();
|
|
|
|
profile->getHistory()->addNewMessage(f->getToxId().publicKey, qt_msg_hist,
|
|
|
|
Core::getInstance()->getSelfId().publicKey, timestamp, status, Core::getInstance()->getUsername(),
|
|
|
|
[offMsgEngine,rec,ma](int64_t id)
|
|
|
|
{
|
|
|
|
offMsgEngine->registerReceipt(rec, id, ma);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
2015-12-17 18:24:01 +08:00
|
|
|
{
|
2015-12-31 21:36:12 +08:00
|
|
|
/// TODO: Make faux-offline messaging work partially with the history disabled
|
|
|
|
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
|
|
|
|
|
|
|
if (volObjectName == QStringLiteral("green"))
|
|
|
|
volButton->setToolTip(tr("Mute call"));
|
|
|
|
else if (volObjectName == QStringLiteral("red"))
|
|
|
|
volButton->setToolTip(tr("Unmute call"));
|
|
|
|
|
|
|
|
if (micObjectName == QStringLiteral("green"))
|
|
|
|
micButton->setToolTip(tr("Mute microphone"));
|
|
|
|
else if (micObjectName == QStringLiteral("red"))
|
|
|
|
micButton->setToolTip(tr("Unmute microphone"));
|
2015-10-10 20:49:30 +08:00
|
|
|
|
2015-07-23 02:50:39 +08:00
|
|
|
if (netcam)
|
|
|
|
netcam->setShowMessages(chatWidget->isVisible());
|
2015-06-06 03:37:01 +08:00
|
|
|
}
|