2014-07-07 00:19:45 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
2014-09-11 21:44:34 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#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>
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "chatform.h"
|
2014-10-12 18:24:05 +08:00
|
|
|
#include "src/historykeeper.h"
|
|
|
|
#include "src/widget/form/loadhistorydialog.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/friend.h"
|
|
|
|
#include "src/widget/friendwidget.h"
|
|
|
|
#include "src/filetransferinstance.h"
|
|
|
|
#include "src/widget/netcamview.h"
|
|
|
|
#include "src/widget/tool/chattextedit.h"
|
|
|
|
#include "src/core.h"
|
|
|
|
#include "src/widget/widget.h"
|
|
|
|
#include "src/widget/maskablepixmapwidget.h"
|
|
|
|
#include "src/widget/croppinglabel.h"
|
|
|
|
#include "src/misc/style.h"
|
2014-10-18 12:53:29 +08:00
|
|
|
#include "src/misc/settings.h"
|
2014-11-09 20:32:19 +08:00
|
|
|
#include "src/misc/cstring.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"
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
ChatForm::ChatForm(Friend* chatFriend)
|
2014-09-05 02:09:55 +08:00
|
|
|
: f(chatFriend)
|
2014-10-10 03:20:06 +08:00
|
|
|
, audioInputFlag(false)
|
2014-10-28 20:50:30 +08:00
|
|
|
, audioOutputFlag(false)
|
2014-10-10 03:20:06 +08:00
|
|
|
, callId(0)
|
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
|
|
|
|
|
|
|
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
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());
|
2014-10-01 02:10:42 +08:00
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
netcam = new NetCamView();
|
2014-11-04 01:01:02 +08:00
|
|
|
timer = nullptr;
|
2014-08-16 04:08:19 +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);
|
|
|
|
callDuration->hide();
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-10-11 00:22:57 +08:00
|
|
|
menu.addAction(tr("Load History..."), this, SLOT(onLoadHistory()));
|
|
|
|
|
2014-09-11 21:44:34 +08:00
|
|
|
connect(Core::getInstance(), &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);
|
|
|
|
connect(callButton, &QPushButton::clicked, this, &ChatForm::onCallTriggered);
|
|
|
|
connect(videoButton, &QPushButton::clicked, this, &ChatForm::onVideoCallTriggered);
|
|
|
|
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
2014-08-19 23:20:20 +08:00
|
|
|
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
|
2014-10-28 20:50:30 +08:00
|
|
|
connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle()));
|
2014-09-24 00:52:06 +08:00
|
|
|
connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed);
|
2014-11-10 21:06:35 +08:00
|
|
|
connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts()));
|
2014-09-26 00:03:25 +08:00
|
|
|
|
|
|
|
setAcceptDrops(true);
|
2014-11-09 05:43:33 +08:00
|
|
|
|
|
|
|
if (Settings::getInstance().getEnableLogging())
|
2014-11-10 19:30:56 +08:00
|
|
|
loadHistory(QDateTime::currentDateTime().addDays(-7), true);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ChatForm::~ChatForm()
|
|
|
|
{
|
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);
|
|
|
|
statusMessageLabel->setToolTip(newMessage); // for overlength messsages
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onSendTriggered()
|
|
|
|
{
|
|
|
|
QString msg = msgEdit->toPlainText();
|
|
|
|
if (msg.isEmpty())
|
|
|
|
return;
|
2014-11-03 01:36:27 +08:00
|
|
|
|
2014-11-09 20:32:19 +08:00
|
|
|
bool isAction = msg.startsWith("/me ");
|
|
|
|
if (isAction)
|
|
|
|
msg = msg = msg.right(msg.length() - 4);
|
|
|
|
|
|
|
|
QList<CString> splittedMsg = Core::splitMessage(msg);
|
2014-10-14 13:49:27 +08:00
|
|
|
QDateTime timestamp = QDateTime::currentDateTime();
|
2014-10-14 22:36:17 +08:00
|
|
|
|
2014-11-09 20:32:19 +08:00
|
|
|
for (CString& c_msg : splittedMsg)
|
2014-10-02 15:00:06 +08:00
|
|
|
{
|
2014-11-09 20:32:19 +08:00
|
|
|
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;
|
|
|
|
|
2014-11-10 21:06:35 +08:00
|
|
|
bool status = !Settings::getInstance().getFauxOfflineMessaging();
|
2014-11-09 20:32:19 +08:00
|
|
|
|
2014-11-10 21:06:35 +08:00
|
|
|
int id = HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, qt_msg_hist,
|
|
|
|
Core::getInstance()->getSelfId().publicKey, timestamp, status);
|
2014-11-09 20:32:19 +08:00
|
|
|
|
2014-11-12 23:45:24 +08:00
|
|
|
|
|
|
|
ChatMessage* ma = addSelfMessage(msg, isAction, timestamp, false);
|
2014-11-10 00:07:15 +08:00
|
|
|
|
2014-11-09 20:32:19 +08:00
|
|
|
int rec;
|
|
|
|
if (isAction)
|
|
|
|
rec = Core::getInstance()->sendAction(f->getFriendID(), msg);
|
|
|
|
else
|
|
|
|
rec = Core::getInstance()->sendMessage(f->getFriendID(), msg);
|
|
|
|
|
2014-11-12 23:45:24 +08:00
|
|
|
registerReceipt(rec, id, ma);
|
2014-10-02 15:00:06 +08:00
|
|
|
}
|
2014-11-09 20:32:19 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
msgEdit->clear();
|
|
|
|
}
|
|
|
|
|
2014-06-26 04:43:28 +08:00
|
|
|
void ChatForm::onAttachClicked()
|
|
|
|
{
|
2014-10-17 20:29:48 +08:00
|
|
|
QStringList paths = QFileDialog::getOpenFileNames(0,tr("Send a file"));
|
|
|
|
if (paths.isEmpty())
|
2014-06-26 04:43:28 +08:00
|
|
|
return;
|
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))
|
|
|
|
continue;
|
|
|
|
if (file.isSequential())
|
|
|
|
{
|
2014-10-30 00:25:47 +08:00
|
|
|
QMessageBox::critical(0, tr("Bad Idea"), 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;
|
|
|
|
if (!previousId.isMine())
|
|
|
|
{
|
|
|
|
Core* core = Core::getInstance();
|
|
|
|
name = core->getUsername();
|
|
|
|
previousId = core->getSelfId();
|
|
|
|
}
|
2014-09-07 19:42:06 +08:00
|
|
|
|
2014-11-17 03:01:37 +08:00
|
|
|
|
|
|
|
chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), true);
|
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
|
|
|
|
2014-09-01 00:29:55 +08:00
|
|
|
Widget* w = Widget::getInstance();
|
2014-10-04 16:54:50 +08:00
|
|
|
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
|
2014-08-31 22:48:15 +08:00
|
|
|
{
|
2014-11-10 16:09:20 +08:00
|
|
|
w->newMessageAlert(f->getFriendWidget());
|
2014-11-06 23:26:22 +08:00
|
|
|
f->setEventFlag(true);
|
|
|
|
f->getFriendWidget()->updateStatusLight();
|
2014-08-31 22:48:15 +08:00
|
|
|
}
|
2014-09-06 03:27:26 +08:00
|
|
|
|
2014-11-03 01:36:27 +08:00
|
|
|
QString name;
|
|
|
|
ToxID friendId = f->getToxID();
|
|
|
|
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
|
|
|
|
2014-12-14 04:11:03 +08:00
|
|
|
ChatMessage* msg = chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), false);
|
|
|
|
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
|
|
|
|
|| Settings::getInstance().getAutoSaveEnabled())
|
|
|
|
{
|
|
|
|
FileTransferWidget* tfWidget = dynamic_cast<FileTransferWidget*>(msg->getContent(1));
|
|
|
|
if(tfWidget)
|
|
|
|
tfWidget->acceptTransfer(Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())));
|
|
|
|
}
|
2014-06-26 06:30:24 +08:00
|
|
|
}
|
2014-06-27 06:42:45 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
2014-06-27 06:42:45 +08:00
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvInvite";
|
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
|
|
|
|
2014-06-27 08:08:33 +08:00
|
|
|
callId = CallId;
|
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->disconnect();
|
|
|
|
if (video)
|
|
|
|
{
|
|
|
|
callButton->setObjectName("grey");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("yellow");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onAnswerCallTriggered()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
callButton->setObjectName("yellow");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("grey");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onAnswerCallTriggered()));
|
|
|
|
}
|
2014-11-05 20:02:38 +08:00
|
|
|
|
2014-12-14 04:11:03 +08:00
|
|
|
chatWidget->addSystemMessage(tr("%1 calling").arg(f->getDisplayedName()), QDateTime::currentDateTime());
|
2014-07-01 03:14:51 +08:00
|
|
|
|
|
|
|
Widget* w = Widget::getInstance();
|
2014-10-04 16:54:50 +08:00
|
|
|
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
|
2014-07-01 03:14:51 +08:00
|
|
|
{
|
2014-11-10 16:09:20 +08:00
|
|
|
w->newMessageAlert(f->getFriendWidget());
|
2014-11-06 23:26:22 +08:00
|
|
|
f->setEventFlag(true);
|
|
|
|
f->getFriendWidget()->updateStatusLight();
|
2014-07-01 03:14:51 +08:00
|
|
|
}
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
void ChatForm::onAvStart(int FriendId, int CallId, bool video)
|
2014-06-27 08:08:33 +08:00
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvStart";
|
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
|
|
|
|
|
|
|
audioInputFlag = true;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = true;
|
2014-06-27 08:08:33 +08:00
|
|
|
callId = CallId;
|
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->disconnect();
|
2014-11-03 09:51:56 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
if (video)
|
|
|
|
{
|
|
|
|
callButton->setObjectName("grey");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("red");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
callButton->setObjectName("red");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("grey");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
|
|
|
}
|
2014-11-03 09:51:56 +08:00
|
|
|
|
|
|
|
startCounter();
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onAvCancel(int FriendId, int)
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvCancel";
|
|
|
|
|
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
|
|
|
|
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2014-08-30 01:28:22 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
2014-06-27 08:08:33 +08:00
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->disconnect();
|
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("green");
|
|
|
|
videoButton->style()->polish(videoButton);
|
2014-06-27 08:08:33 +08:00
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
2014-06-30 10:39:43 +08:00
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
netcam->hide();
|
2014-11-05 20:02:38 +08:00
|
|
|
|
2014-11-16 20:13:39 +08:00
|
|
|
addSystemInfoMessage(tr("%1 stopped calling").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
2014-06-27 06:42:45 +08:00
|
|
|
|
2014-06-27 08:08:33 +08:00
|
|
|
void ChatForm::onAvEnd(int FriendId, int)
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvEnd";
|
|
|
|
|
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
|
|
|
|
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2014-08-30 01:28:22 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
2014-06-30 10:39:43 +08:00
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
2014-06-28 13:14:38 +08:00
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->setObjectName("green");
|
|
|
|
videoButton->style()->polish(videoButton);
|
2014-06-27 08:08:33 +08:00
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
2014-06-30 10:39:43 +08:00
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
netcam->hide();
|
2014-11-03 09:51:56 +08:00
|
|
|
|
|
|
|
stopCounter();
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
|
2014-11-03 09:51:56 +08:00
|
|
|
{
|
2014-11-05 20:02:38 +08:00
|
|
|
qDebug() << "onAvRinging";
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-06-27 09:06:56 +08:00
|
|
|
return;
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2014-06-27 09:06:56 +08:00
|
|
|
callId = CallId;
|
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->disconnect();
|
|
|
|
if (video)
|
|
|
|
{
|
|
|
|
callButton->setObjectName("grey");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("yellow");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onCancelCallTriggered()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
callButton->setObjectName("yellow");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("grey");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCancelCallTriggered()));
|
|
|
|
}
|
2014-11-05 20:02:38 +08:00
|
|
|
|
2014-11-16 20:13:39 +08:00
|
|
|
addSystemInfoMessage(tr("Calling to %1").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
|
2014-06-27 09:06:56 +08:00
|
|
|
}
|
|
|
|
|
2014-10-16 21:37:48 +08:00
|
|
|
void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
|
2014-06-27 09:06:56 +08:00
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvStarting";
|
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-06-27 09:06:56 +08:00
|
|
|
return;
|
2014-08-30 01:28:22 +08:00
|
|
|
|
2014-06-27 09:06:56 +08:00
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->disconnect();
|
|
|
|
if (video)
|
|
|
|
{
|
|
|
|
callButton->setObjectName("grey");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("red");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
callButton->setObjectName("red");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
videoButton->setObjectName("grey");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
|
|
|
|
}
|
2014-11-03 09:51:56 +08:00
|
|
|
|
|
|
|
startCounter();
|
2014-06-27 09:06:56 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 08:08:33 +08:00
|
|
|
void ChatForm::onAvEnding(int FriendId, int)
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvEnding";
|
|
|
|
|
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
|
|
|
|
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2014-08-30 01:28:22 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
2014-06-30 10:39:43 +08:00
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
2014-06-28 13:14:38 +08:00
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
2014-06-27 08:08:33 +08:00
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->setObjectName("green");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
videoButton->disconnect();
|
2014-06-27 08:08:33 +08:00
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
2014-06-30 10:39:43 +08:00
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
2014-11-03 05:07:41 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
netcam->hide();
|
2014-11-03 09:51:56 +08:00
|
|
|
|
|
|
|
stopCounter();
|
2014-06-27 08:08:33 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 09:06:56 +08:00
|
|
|
void ChatForm::onAvRequestTimeout(int FriendId, int)
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvRequestTimeout";
|
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-06-27 09:06:56 +08:00
|
|
|
return;
|
2014-08-30 01:28:22 +08:00
|
|
|
|
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2014-08-30 01:28:22 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
2014-06-30 10:39:43 +08:00
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
2014-06-28 13:14:38 +08:00
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
2014-06-27 09:06:56 +08:00
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->setObjectName("green");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
videoButton->disconnect();
|
2014-06-27 09:06:56 +08:00
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
2014-06-30 10:39:43 +08:00
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
netcam->hide();
|
2014-06-27 09:06:56 +08:00
|
|
|
}
|
|
|
|
|
2014-06-28 03:59:25 +08:00
|
|
|
void ChatForm::onAvPeerTimeout(int FriendId, int)
|
2014-11-02 19:47:42 +08:00
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvPeerTimeout";
|
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-11-02 19:47:42 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
audioInputFlag = false;
|
|
|
|
audioOutputFlag = false;
|
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->setObjectName("green");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
videoButton->disconnect();
|
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
|
|
|
|
|
|
|
netcam->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onAvRejected(int FriendId, int)
|
2014-06-28 03:59:25 +08:00
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvRejected";
|
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-06-28 03:59:25 +08:00
|
|
|
return;
|
2014-08-30 01:28:22 +08:00
|
|
|
|
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2014-08-30 01:28:22 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
2014-06-30 10:39:43 +08:00
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
2014-06-28 13:14:38 +08:00
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
2014-06-28 03:59:25 +08:00
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->setObjectName("green");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
videoButton->disconnect();
|
2014-06-28 03:59:25 +08:00
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
2014-06-30 10:39:43 +08:00
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
2014-11-03 05:07:41 +08:00
|
|
|
|
2014-12-14 04:11:03 +08:00
|
|
|
chatWidget->addSystemMessage(tr("Call rejected"), QDateTime::currentDateTime());
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
netcam->hide();
|
2014-06-28 03:59:25 +08:00
|
|
|
}
|
|
|
|
|
2014-10-16 21:37:48 +08:00
|
|
|
void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video)
|
2014-08-30 01:20:34 +08:00
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvMediaChange";
|
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID() || CallId != callId)
|
2014-10-19 17:32:31 +08:00
|
|
|
return;
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2014-08-30 01:20:34 +08:00
|
|
|
if (video)
|
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getDisplayedName());
|
2014-08-30 01:20:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
netcam->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 08:08:33 +08:00
|
|
|
void ChatForm::onAnswerCallTriggered()
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAnswerCallTriggered";
|
|
|
|
|
2014-08-30 00:16:16 +08:00
|
|
|
audioInputFlag = true;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = true;
|
2014-06-27 08:08:33 +08:00
|
|
|
emit answerCall(callId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onHangupCallTriggered()
|
2014-11-03 09:51:56 +08:00
|
|
|
{
|
|
|
|
qDebug() << "onHangupCallTriggered";
|
|
|
|
|
2014-08-30 00:16:16 +08:00
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2014-06-27 08:08:33 +08:00
|
|
|
emit hangupCall(callId);
|
2014-08-20 01:15:56 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
2014-06-27 06:42:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::onCallTriggered()
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onCallTriggered";
|
|
|
|
|
2014-10-28 20:50:30 +08:00
|
|
|
audioInputFlag = true;
|
|
|
|
audioOutputFlag = true;
|
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
2014-11-06 23:26:22 +08:00
|
|
|
emit startCall(f->getFriendID());
|
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";
|
|
|
|
|
2014-08-30 00:16:16 +08:00
|
|
|
audioInputFlag = true;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = true;
|
2014-06-30 10:39:43 +08:00
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
2014-11-06 23:26:22 +08:00
|
|
|
emit startVideoCall(f->getFriendID(), true);
|
2014-06-30 10:39:43 +08:00
|
|
|
}
|
|
|
|
|
2014-10-25 17:29:25 +08:00
|
|
|
void ChatForm::onAvCallFailed(int FriendId)
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onAvCallFailed";
|
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-10-25 17:29:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2014-10-25 17:29:25 +08:00
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
|
|
|
}
|
|
|
|
|
2014-06-27 09:06:56 +08:00
|
|
|
void ChatForm::onCancelCallTriggered()
|
|
|
|
{
|
2014-11-03 09:51:56 +08:00
|
|
|
qDebug() << "onCancelCallTriggered";
|
|
|
|
|
2014-08-30 00:16:16 +08:00
|
|
|
audioInputFlag = false;
|
2014-10-28 20:50:30 +08:00
|
|
|
audioOutputFlag = false;
|
2014-08-30 01:28:22 +08:00
|
|
|
micButton->setObjectName("green");
|
|
|
|
micButton->style()->polish(micButton);
|
2014-10-28 20:50:30 +08:00
|
|
|
volButton->setObjectName("green");
|
|
|
|
volButton->style()->polish(volButton);
|
2014-06-30 10:39:43 +08:00
|
|
|
callButton->disconnect();
|
|
|
|
videoButton->disconnect();
|
2014-06-28 13:14:38 +08:00
|
|
|
callButton->setObjectName("green");
|
|
|
|
callButton->style()->polish(callButton);
|
2014-06-27 09:06:56 +08:00
|
|
|
callButton->disconnect();
|
2014-06-30 10:39:43 +08:00
|
|
|
videoButton->setObjectName("green");
|
|
|
|
videoButton->style()->polish(videoButton);
|
|
|
|
videoButton->disconnect();
|
2014-06-27 09:06:56 +08:00
|
|
|
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
2014-06-30 10:39:43 +08:00
|
|
|
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
2014-10-16 21:37:48 +08:00
|
|
|
|
2014-06-30 10:39:43 +08:00
|
|
|
netcam->hide();
|
2014-11-06 23:26:22 +08:00
|
|
|
emit cancelCall(callId, f->getFriendID());
|
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
|
|
|
{
|
2014-08-30 00:16:16 +08:00
|
|
|
emit micMuteToggle(callId);
|
|
|
|
if (micButton->objectName() == "red")
|
|
|
|
micButton->setObjectName("green");
|
|
|
|
else
|
|
|
|
micButton->setObjectName("red");
|
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)
|
|
|
|
{
|
|
|
|
emit volMuteToggle(callId);
|
|
|
|
if (volButton->objectName() == "red")
|
|
|
|
volButton->setObjectName("green");
|
|
|
|
else
|
|
|
|
volButton->setObjectName("red");
|
|
|
|
|
|
|
|
Style::repolish(volButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 00:52:06 +08:00
|
|
|
void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
|
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-09-24 00:52:06 +08:00
|
|
|
return;
|
|
|
|
|
2014-11-16 20:13:39 +08:00
|
|
|
addSystemInfoMessage("File: \"" + fname + "\" failed to send.", "red", QDateTime::currentDateTime());
|
2014-09-24 00:52:06 +08:00
|
|
|
}
|
2014-09-24 23:28:38 +08:00
|
|
|
|
|
|
|
void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
void ChatForm::onAvatarRemoved(int FriendId)
|
|
|
|
{
|
2014-11-06 23:26:22 +08:00
|
|
|
if (FriendId != f->getFriendID())
|
2014-09-27 03:23:20 +08:00
|
|
|
return;
|
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
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
|
|
|
{
|
2014-11-09 05:43:33 +08:00
|
|
|
QDateTime now = QDateTime::currentDateTime();
|
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
|
|
|
|
2014-11-09 05:43:33 +08:00
|
|
|
if (earliestMessage)
|
|
|
|
{
|
|
|
|
if (*earliestMessage < since)
|
2014-10-11 01:32:10 +08:00
|
|
|
return;
|
2014-11-09 05:43:33 +08:00
|
|
|
if (*earliestMessage < now)
|
2014-10-11 01:32:10 +08:00
|
|
|
{
|
2014-11-09 05:43:33 +08:00
|
|
|
now = *earliestMessage;
|
|
|
|
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
|
|
|
|
2014-11-09 05:43:33 +08:00
|
|
|
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now);
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2014-11-09 05:43:33 +08:00
|
|
|
ToxID storedPrevId;
|
|
|
|
std::swap(storedPrevId, previousId);
|
2014-12-14 04:11:03 +08:00
|
|
|
QList<ChatMessage*> historyMessages;
|
|
|
|
|
|
|
|
//TODO: possibly broken
|
|
|
|
QDate lastDate(1,0,0);
|
|
|
|
for (const auto &it : msgs)
|
|
|
|
{
|
|
|
|
// Show the date every new day
|
|
|
|
QDateTime msgDateTime = it.timestamp.toLocalTime();
|
|
|
|
QDate msgDate = msgDateTime.date();
|
|
|
|
if (msgDate > lastDate)
|
|
|
|
{
|
|
|
|
lastDate = msgDate;
|
|
|
|
chatWidget->addSystemMessage(msgDate.toString(), QDateTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show each messages
|
|
|
|
ToxID id = ToxID::fromString(it.sender);
|
2014-12-31 20:42:06 +08:00
|
|
|
ChatMessage* msg = chatWidget->addChatMessage(Core::getInstance()->getPeerName(id), it.message, id.isMine(), false);
|
2014-12-14 04:11:03 +08:00
|
|
|
if (it.isSent)
|
|
|
|
{
|
|
|
|
msg->markAsSent(msgDateTime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (processUndelivered)
|
|
|
|
{
|
|
|
|
int rec = Core::getInstance()->sendMessage(f->getFriendID(), msg->toString());
|
|
|
|
registerReceipt(rec, it.id, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
historyMessages.append(msg);
|
|
|
|
}
|
|
|
|
std::swap(storedPrevId, previousId);
|
2014-11-12 21:11:25 +08:00
|
|
|
|
|
|
|
// int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
|
|
|
|
|
|
|
|
// if (earliestMessage != nullptr)
|
|
|
|
// *earliestMessage = since;
|
|
|
|
|
|
|
|
// chatWidget->insertMessagesTop(historyMessages);
|
|
|
|
|
|
|
|
// savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
|
|
|
|
// chatWidget->verticalScrollBar()->setValue(savedSliderPos);
|
2014-11-09 05:43:33 +08:00
|
|
|
}
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2014-11-09 05:43:33 +08:00
|
|
|
void ChatForm::onLoadHistory()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
void ChatForm::startCounter()
|
|
|
|
{
|
2014-11-04 01:01:02 +08:00
|
|
|
if(!timer)
|
2014-11-03 09:51:56 +08:00
|
|
|
{
|
|
|
|
timer = new QTimer();
|
|
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(updateTime()));
|
|
|
|
timer->start(1000);
|
|
|
|
timeElapsed.start();
|
|
|
|
callDuration->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::stopCounter()
|
|
|
|
{
|
|
|
|
if(timer)
|
|
|
|
{
|
2014-11-16 20:13:39 +08:00
|
|
|
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(f->getDisplayedName(),secondsToDHMS(timeElapsed.elapsed()/1000)),
|
|
|
|
"white", QDateTime::currentDateTime());
|
2014-11-03 09:51:56 +08:00
|
|
|
timer->stop();
|
2014-11-05 20:02:38 +08:00
|
|
|
callDuration->setText("");
|
2014-11-03 09:51:56 +08:00
|
|
|
callDuration->hide();
|
2014-11-04 01:01:02 +08:00
|
|
|
timer = nullptr;
|
2014-11-03 09:51:56 +08:00
|
|
|
delete timer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChatForm::updateTime()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if(minutes == 0)
|
|
|
|
return cD + res.sprintf("%02ds", seconds);
|
|
|
|
|
|
|
|
if(hours == 0 && days == 0)
|
|
|
|
return cD + res.sprintf("%02dm %02ds", minutes, seconds);
|
|
|
|
|
|
|
|
if (days == 0)
|
|
|
|
return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds);
|
|
|
|
//I assume no one will ever have call longer than ~30days
|
|
|
|
return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds);
|
|
|
|
}
|
2014-11-09 20:32:19 +08:00
|
|
|
|
2014-11-12 23:45:24 +08:00
|
|
|
void ChatForm::registerReceipt(int receipt, int messageID, ChatMessage* msg)
|
|
|
|
{
|
|
|
|
receipts[receipt] = messageID;
|
|
|
|
undeliveredMsgs[messageID] = msg;
|
|
|
|
}
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2014-11-12 23:45:24 +08:00
|
|
|
void ChatForm::dischargeReceipt(int receipt)
|
|
|
|
{
|
|
|
|
auto it = receipts.find(receipt);
|
|
|
|
if (it != receipts.end())
|
|
|
|
{
|
|
|
|
int mID = it.value();
|
|
|
|
auto msgIt = undeliveredMsgs.find(mID);
|
|
|
|
if (msgIt != undeliveredMsgs.end())
|
|
|
|
{
|
|
|
|
HistoryKeeper::getInstance()->markAsSent(mID);
|
|
|
|
msgIt.value()->markAsSent(QDateTime::currentDateTime());
|
|
|
|
undeliveredMsgs.erase(msgIt);
|
|
|
|
}
|
|
|
|
receipts.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2014-11-09 20:32:19 +08:00
|
|
|
|
|
|
|
void ChatForm::clearReciepts()
|
|
|
|
{
|
2014-11-14 01:27:32 +08:00
|
|
|
receipts.clear();
|
|
|
|
undeliveredMsgs.clear();
|
2014-11-09 20:32:19 +08:00
|
|
|
}
|
2014-11-10 19:30:56 +08:00
|
|
|
|
|
|
|
void ChatForm::deliverOfflineMsgs()
|
|
|
|
{
|
2014-11-14 01:27:32 +08:00
|
|
|
if (!Settings::getInstance().getFauxOfflineMessaging())
|
|
|
|
return;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2014-11-14 01:27:32 +08:00
|
|
|
QMap<int, ChatMessage*> msgs = undeliveredMsgs;
|
|
|
|
clearReciepts();
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2014-11-14 01:27:32 +08:00
|
|
|
for (auto iter = msgs.begin(); iter != msgs.end(); iter++)
|
|
|
|
{
|
|
|
|
QString messageText = iter.value()->toString();
|
|
|
|
int rec;
|
2014-12-14 04:11:03 +08:00
|
|
|
if (iter.value()->isAction())
|
|
|
|
rec = Core::getInstance()->sendAction(f->getFriendID(), messageText);
|
|
|
|
else
|
2014-11-14 01:27:32 +08:00
|
|
|
rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText);
|
|
|
|
registerReceipt(rec, iter.key(), iter.value());
|
|
|
|
}
|
2014-11-10 19:30:56 +08:00
|
|
|
}
|