mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #4288
noavarice (3): refactor: removed unnecessary headers and updated copyright info refactor: slight refactoring of ChatForm class refactor: onTextEditChanged method refactoring
This commit is contained in:
commit
50a31bc507
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright © 2014-2015 by The qTox Project Contributors
|
Copyright © 2014-2017 by The qTox Project Contributors
|
||||||
|
|
||||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
|
@ -32,43 +32,82 @@
|
||||||
#include "src/persistence/offlinemsgengine.h"
|
#include "src/persistence/offlinemsgengine.h"
|
||||||
#include "src/persistence/profile.h"
|
#include "src/persistence/profile.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
#include "src/video/camerasource.h"
|
|
||||||
#include "src/video/netcamview.h"
|
#include "src/video/netcamview.h"
|
||||||
#include "src/video/videosource.h"
|
|
||||||
#include "src/widget/form/loadhistorydialog.h"
|
#include "src/widget/form/loadhistorydialog.h"
|
||||||
#include "src/widget/friendwidget.h"
|
|
||||||
#include "src/widget/maskablepixmapwidget.h"
|
#include "src/widget/maskablepixmapwidget.h"
|
||||||
#include "src/widget/style.h"
|
#include "src/widget/style.h"
|
||||||
#include "src/widget/tool/callconfirmwidget.h"
|
#include "src/widget/tool/callconfirmwidget.h"
|
||||||
#include "src/widget/tool/chattextedit.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/tool/screenshotgrabber.h"
|
||||||
#include "src/widget/translator.h"
|
#include "src/widget/translator.h"
|
||||||
#include "src/widget/widget.h"
|
#include "src/widget/widget.h"
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QBitmap>
|
|
||||||
#include <QBoxLayout>
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDebug>
|
|
||||||
#include <QDragEnterEvent>
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QScreen>
|
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QSplitter>
|
|
||||||
#include <QStyle>
|
|
||||||
#include <QTemporaryFile>
|
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
static const int CHAT_WIDGET_MIN_HEIGHT = 50;
|
||||||
|
static const int DELIVER_OFFLINE_MESSAGES_DELAY = 250;
|
||||||
|
static const int SCREENSHOT_GRABBER_OPENING_DELAY = 500;
|
||||||
|
static const int TYPING_NOTIFICATION_DURATION = 3000;
|
||||||
|
|
||||||
|
static const QString CALL_BTN_STYLESHEET = QStringLiteral(":/ui/callButton/callButton.css");
|
||||||
|
static const QString MIC_BTN_STYLESHEET = QStringLiteral(":/ui/micButton/micButton.css");
|
||||||
|
static const QString VIDEO_BTN_STYLESHEET = QStringLiteral(":/ui/videoButton/videoButton.css");
|
||||||
|
static const QString VOL_BTN_STYLESHEET = QStringLiteral(":/ui/volButton/volButton.css");
|
||||||
|
|
||||||
const QString ChatForm::ACTION_PREFIX = QStringLiteral("/me ");
|
const QString ChatForm::ACTION_PREFIX = QStringLiteral("/me ");
|
||||||
|
|
||||||
|
QString statusToString(const Status status)
|
||||||
|
{
|
||||||
|
QString result;
|
||||||
|
switch (status) {
|
||||||
|
case Status::Online: result = ChatForm::tr("online", "contact status");
|
||||||
|
break;
|
||||||
|
case Status::Away: result = ChatForm::tr("away", "contact status");
|
||||||
|
break;
|
||||||
|
case Status::Busy: result = ChatForm::tr("busy", "contact status");
|
||||||
|
break;
|
||||||
|
case Status::Offline: result = ChatForm::tr("offline", "contact status");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString secondsToDHMS(quint32 duration)
|
||||||
|
{
|
||||||
|
QString res;
|
||||||
|
QString cD = ChatForm::tr("Call duration: ");
|
||||||
|
quint32 seconds = duration % 60;
|
||||||
|
duration /= 60;
|
||||||
|
quint32 minutes = duration % 60;
|
||||||
|
duration /= 60;
|
||||||
|
quint32 hours = duration % 24;
|
||||||
|
quint32 days = duration / 24;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hours) {
|
||||||
|
return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minutes) {
|
||||||
|
return cD + res.sprintf("%02dm %02ds", minutes, seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cD + res.sprintf("%02ds", seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ChatForm::ChatForm(Friend* chatFriend)
|
ChatForm::ChatForm(Friend* chatFriend)
|
||||||
: f(chatFriend)
|
: f(chatFriend)
|
||||||
, callDuration(new QLabel(this))
|
, callDuration(new QLabel(this))
|
||||||
|
@ -93,7 +132,7 @@ ChatForm::ChatForm(Friend* chatFriend)
|
||||||
callDurationTimer = nullptr;
|
callDurationTimer = nullptr;
|
||||||
|
|
||||||
chatWidget->setTypingNotification(ChatMessage::createTypingNotification());
|
chatWidget->setTypingNotification(ChatMessage::createTypingNotification());
|
||||||
chatWidget->setMinimumHeight(50);
|
chatWidget->setMinimumHeight(CHAT_WIDGET_MIN_HEIGHT);
|
||||||
|
|
||||||
headTextLayout->addWidget(statusMessageLabel);
|
headTextLayout->addWidget(statusMessageLabel);
|
||||||
headTextLayout->addStretch();
|
headTextLayout->addStretch();
|
||||||
|
@ -132,12 +171,12 @@ ChatForm::ChatForm(Friend* chatFriend)
|
||||||
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
||||||
connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged);
|
connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged);
|
||||||
connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this,
|
connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this,
|
||||||
[&](const QPoint& pos) {
|
[&](const QPoint& pos) {
|
||||||
if (!statusMessageLabel->text().isEmpty()) {
|
if (!statusMessageLabel->text().isEmpty()) {
|
||||||
QWidget* sender = static_cast<QWidget*>(this->sender());
|
QWidget* sender = static_cast<QWidget*>(this->sender());
|
||||||
statusMessageMenu.exec(sender->mapToGlobal(pos));
|
statusMessageMenu.exec(sender->mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&typingTimer, &QTimer::timeout, this, [=] {
|
connect(&typingTimer, &QTimer::timeout, this, [=] {
|
||||||
Core::getInstance()->sendTyping(f->getFriendId(), false);
|
Core::getInstance()->sendTyping(f->getFriendId(), false);
|
||||||
|
@ -159,6 +198,7 @@ ChatForm::~ChatForm()
|
||||||
{
|
{
|
||||||
Translator::unregister(this);
|
Translator::unregister(this);
|
||||||
delete netcam;
|
delete netcam;
|
||||||
|
netcam = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::setStatusMessage(const QString& newMessage)
|
void ChatForm::setStatusMessage(const QString& newMessage)
|
||||||
|
@ -176,33 +216,33 @@ void ChatForm::onSendTriggered()
|
||||||
|
|
||||||
void ChatForm::onTextEditChanged()
|
void ChatForm::onTextEditChanged()
|
||||||
{
|
{
|
||||||
Core* core = Core::getInstance();
|
|
||||||
if (!Settings::getInstance().getTypingNotification()) {
|
if (!Settings::getInstance().getTypingNotification()) {
|
||||||
if (isTyping) {
|
if (isTyping) {
|
||||||
core->sendTyping(f->getFriendId(), false);
|
isTyping = false;
|
||||||
|
Core::getInstance()->sendTyping(f->getFriendId(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
isTyping = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
bool isTypingNow = !msgEdit->toPlainText().isEmpty();
|
||||||
if (msgEdit->toPlainText().length() > 0) {
|
if (isTyping != isTypingNow) {
|
||||||
typingTimer.start(3000);
|
Core::getInstance()->sendTyping(f->getFriendId(), isTypingNow);
|
||||||
if (!isTyping) {
|
if (isTypingNow) {
|
||||||
isTyping = true;
|
typingTimer.start(TYPING_NOTIFICATION_DURATION);
|
||||||
core->sendTyping(f->getFriendId(), isTyping);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
isTyping = false;
|
isTyping = isTypingNow;
|
||||||
core->sendTyping(f->getFriendId(), isTyping);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAttachClicked()
|
void ChatForm::onAttachClicked()
|
||||||
{
|
{
|
||||||
QStringList paths = QFileDialog::getOpenFileNames(this, tr("Send a file"), QDir::homePath(), 0,
|
QStringList paths = QFileDialog::getOpenFileNames(this,
|
||||||
0, QFileDialog::DontUseNativeDialog);
|
tr("Send a file"),
|
||||||
|
QDir::homePath(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
QFileDialog::DontUseNativeDialog);
|
||||||
if (paths.isEmpty()) {
|
if (paths.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -210,26 +250,25 @@ void ChatForm::onAttachClicked()
|
||||||
Core* core = Core::getInstance();
|
Core* core = Core::getInstance();
|
||||||
for (QString path : paths) {
|
for (QString path : paths) {
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
|
QString fileName = QFileInfo(path).fileName();
|
||||||
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
||||||
QString fileName = QFileInfo(path).fileName();
|
QMessageBox::warning(this,
|
||||||
QMessageBox::warning(this, tr("Unable to open"),
|
tr("Unable to open"),
|
||||||
tr("qTox wasn't able to open %1").arg(fileName));
|
tr("qTox wasn't able to open %1").arg(fileName));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
if (file.isSequential()) {
|
if (file.isSequential()) {
|
||||||
QMessageBox::critical(this, tr("Bad idea"),
|
QMessageBox::critical(this,
|
||||||
tr("You're trying to send a sequential file,"
|
tr("Bad idea"),
|
||||||
" which is not going to work!"));
|
tr("You're trying to send a sequential file, "
|
||||||
file.close();
|
"which is not going to work!"));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 filesize = file.size();
|
qint64 filesize = file.size();
|
||||||
file.close();
|
core->sendFile(f->getFriendId(), fileName, path, filesize);
|
||||||
QFileInfo fi(path);
|
|
||||||
|
|
||||||
core->sendFile(f->getFriendId(), fi.fileName(), path, filesize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,9 +286,10 @@ void ChatForm::startFileSend(ToxFile file)
|
||||||
previousId = self;
|
previousId = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
insertChatMessage(
|
insertChatMessage(ChatMessage::createFileTransferMessage(name,
|
||||||
ChatMessage::createFileTransferMessage(name, file, true, QDateTime::currentDateTime()));
|
file,
|
||||||
|
true,
|
||||||
|
QDateTime::currentDateTime()));
|
||||||
Widget::getInstance()->updateFriendActivity(f);
|
Widget::getInstance()->updateFriendActivity(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +300,6 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget::getInstance()->newFriendMessageAlert(file.friendId);
|
Widget::getInstance()->newFriendMessageAlert(file.friendId);
|
||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
ToxPk friendId = f->getPublicKey();
|
ToxPk friendId = f->getPublicKey();
|
||||||
if (friendId != previousId) {
|
if (friendId != previousId) {
|
||||||
|
@ -268,20 +307,24 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
||||||
previousId = friendId;
|
previousId = friendId;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMessage::Ptr msg =
|
ChatMessage::Ptr msg = ChatMessage::createFileTransferMessage(name,
|
||||||
ChatMessage::createFileTransferMessage(name, file, false, QDateTime::currentDateTime());
|
file,
|
||||||
|
false,
|
||||||
|
QDateTime::currentDateTime());
|
||||||
insertChatMessage(msg);
|
insertChatMessage(msg);
|
||||||
|
|
||||||
ChatLineContentProxy* proxy = static_cast<ChatLineContentProxy*>(msg->getContent(1));
|
ChatLineContentProxy* proxy = static_cast<ChatLineContentProxy*>(msg->getContent(1));
|
||||||
assert(proxy->getWidgetType() == ChatLineContentProxy::FileTransferWidgetType);
|
assert(proxy->getWidgetType() == ChatLineContentProxy::FileTransferWidgetType);
|
||||||
FileTransferWidget* tfWidget = static_cast<FileTransferWidget*>(proxy->getWidget());
|
FileTransferWidget* tfWidget = static_cast<FileTransferWidget*>(proxy->getWidget());
|
||||||
|
|
||||||
// there is auto-accept for that conact
|
const Settings& settings = Settings::getInstance();
|
||||||
if (!Settings::getInstance().getAutoAcceptDir(f->getPublicKey()).isEmpty()) {
|
QString autoAcceptDir = settings.getAutoAcceptDir(f->getPublicKey());
|
||||||
tfWidget->autoAcceptTransfer(Settings::getInstance().getAutoAcceptDir(f->getPublicKey()));
|
// there is auto-accept for that contact
|
||||||
} else if (Settings::getInstance().getAutoSaveEnabled()) { // global autosave to global
|
if (!autoAcceptDir.isEmpty()) {
|
||||||
// directory
|
tfWidget->autoAcceptTransfer(autoAcceptDir);
|
||||||
tfWidget->autoAcceptTransfer(Settings::getInstance().getGlobalAutoAcceptDir());
|
// global autosave to global directory
|
||||||
|
} else if (settings.getAutoSaveEnabled()) {
|
||||||
|
tfWidget->autoAcceptTransfer(settings.getGlobalAutoAcceptDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget::getInstance()->updateFriendActivity(f);
|
Widget::getInstance()->updateFriendActivity(f);
|
||||||
|
@ -294,35 +337,31 @@ void ChatForm::onAvInvite(uint32_t friendId, bool video)
|
||||||
}
|
}
|
||||||
|
|
||||||
callConfirm = new CallConfirmWidget(video ? videoButton : callButton, *f);
|
callConfirm = new CallConfirmWidget(video ? videoButton : callButton, *f);
|
||||||
insertChatMessage(ChatMessage::createChatInfoMessage(tr("%1 calling").arg(f->getDisplayedName()),
|
QString displayedName = f->getDisplayedName();
|
||||||
|
insertChatMessage(ChatMessage::createChatInfoMessage(tr("%1 calling").arg(displayedName),
|
||||||
ChatMessage::INFO,
|
ChatMessage::INFO,
|
||||||
QDateTime::currentDateTime()));
|
QDateTime::currentDateTime()));
|
||||||
|
|
||||||
/* AutoAcceptCall is set for this friend */
|
auto testedFlag = video ? Settings::AutoAcceptCall::Video : Settings::AutoAcceptCall::Audio;
|
||||||
if ((video
|
// AutoAcceptCall is set for this friend
|
||||||
&& Settings::getInstance().getAutoAcceptCall(f->getPublicKey()).testFlag(Settings::AutoAcceptCall::Video))
|
if (Settings::getInstance().getAutoAcceptCall(f->getPublicKey()).testFlag(testedFlag)) {
|
||||||
|| (!video
|
|
||||||
&& Settings::getInstance()
|
|
||||||
.getAutoAcceptCall(f->getPublicKey())
|
|
||||||
.testFlag(Settings::AutoAcceptCall::Audio))) {
|
|
||||||
uint32_t friendId = f->getFriendId();
|
uint32_t friendId = f->getFriendId();
|
||||||
qDebug() << "automatic call answer";
|
qDebug() << "automatic call answer";
|
||||||
CoreAV* coreav = Core::getInstance()->getAv();
|
CoreAV* coreav = Core::getInstance()->getAv();
|
||||||
QMetaObject::invokeMethod(coreav, "answerCall", Qt::QueuedConnection,
|
QMetaObject::invokeMethod(coreav,
|
||||||
|
"answerCall",
|
||||||
|
Qt::QueuedConnection,
|
||||||
Q_ARG(uint32_t, friendId));
|
Q_ARG(uint32_t, friendId));
|
||||||
onAvStart(friendId, video);
|
onAvStart(friendId, video);
|
||||||
} else {
|
} else {
|
||||||
callConfirm->show();
|
callConfirm->show();
|
||||||
|
CallConfirmWidget* confirmData = callConfirm.data();
|
||||||
connect(callConfirm.data(), &CallConfirmWidget::accepted, this,
|
connect(confirmData, &CallConfirmWidget::accepted, this, &ChatForm::onAnswerCallTriggered);
|
||||||
&ChatForm::onAnswerCallTriggered);
|
connect(confirmData, &CallConfirmWidget::rejected, this, &ChatForm::onRejectCallTriggered);
|
||||||
connect(callConfirm.data(), &CallConfirmWidget::rejected, this,
|
auto msg = ChatMessage::createChatInfoMessage(tr("%1 calling").arg(displayedName),
|
||||||
&ChatForm::onRejectCallTriggered);
|
ChatMessage::INFO,
|
||||||
|
QDateTime::currentDateTime());
|
||||||
insertChatMessage(
|
insertChatMessage(msg);
|
||||||
ChatMessage::createChatInfoMessage(tr("%1 calling").arg(f->getDisplayedName()),
|
|
||||||
ChatMessage::INFO, QDateTime::currentDateTime()));
|
|
||||||
|
|
||||||
Widget::getInstance()->newFriendMessageAlert(friendId, false);
|
Widget::getInstance()->newFriendMessageAlert(friendId, false);
|
||||||
Audio& audio = Audio::getInstance();
|
Audio& audio = Audio::getInstance();
|
||||||
audio.startLoop();
|
audio.startLoop();
|
||||||
|
@ -360,7 +399,6 @@ void ChatForm::onAvEnd(uint32_t friendId)
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio::getInstance().stopLoop();
|
Audio::getInstance().stopLoop();
|
||||||
|
|
||||||
updateCallButtons();
|
updateCallButtons();
|
||||||
stopCounter();
|
stopCounter();
|
||||||
hideNetcam();
|
hideNetcam();
|
||||||
|
@ -368,49 +406,37 @@ void ChatForm::onAvEnd(uint32_t friendId)
|
||||||
|
|
||||||
void ChatForm::showOutgoingCall(bool video)
|
void ChatForm::showOutgoingCall(bool video)
|
||||||
{
|
{
|
||||||
if (video) {
|
QPushButton* btn = video ? videoButton : callButton;
|
||||||
videoButton->setObjectName("yellow");
|
btn->setObjectName("yellow");
|
||||||
videoButton->setStyleSheet(
|
btn->setStyleSheet(Style::getStylesheet(video ? VIDEO_BTN_STYLESHEET : CALL_BTN_STYLESHEET));
|
||||||
Style::getStylesheet(QStringLiteral(":/ui/videoButton/videoButton.css")));
|
btn->setToolTip(video ? tr("Cancel video call") : tr("Cancel audio call"));
|
||||||
videoButton->setToolTip(tr("Cancel video call"));
|
addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()),
|
||||||
} else {
|
ChatMessage::INFO,
|
||||||
callButton->setObjectName("yellow");
|
|
||||||
callButton->setStyleSheet(
|
|
||||||
Style::getStylesheet(QStringLiteral(":/ui/callButton/callButton.css")));
|
|
||||||
callButton->setToolTip(tr("Cancel audio call"));
|
|
||||||
}
|
|
||||||
|
|
||||||
addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()), ChatMessage::INFO,
|
|
||||||
QDateTime::currentDateTime());
|
QDateTime::currentDateTime());
|
||||||
|
|
||||||
Widget::getInstance()->updateFriendActivity(f);
|
Widget::getInstance()->updateFriendActivity(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAnswerCallTriggered()
|
void ChatForm::onAnswerCallTriggered()
|
||||||
{
|
{
|
||||||
delete callConfirm;
|
delete callConfirm;
|
||||||
|
|
||||||
Audio::getInstance().stopLoop();
|
Audio::getInstance().stopLoop();
|
||||||
|
|
||||||
updateCallButtons();
|
updateCallButtons();
|
||||||
|
|
||||||
CoreAV* av = Core::getInstance()->getAv();
|
CoreAV* av = Core::getInstance()->getAv();
|
||||||
if (!av->answerCall(f->getFriendId())) {
|
uint32_t friendId = f->getFriendId();
|
||||||
|
if (!av->answerCall(friendId)) {
|
||||||
updateCallButtons();
|
updateCallButtons();
|
||||||
stopCounter();
|
stopCounter();
|
||||||
hideNetcam();
|
hideNetcam();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onAvStart(f->getFriendId(), av->isCallVideoEnabled(f));
|
onAvStart(friendId, av->isCallVideoEnabled(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onRejectCallTriggered()
|
void ChatForm::onRejectCallTriggered()
|
||||||
{
|
{
|
||||||
delete callConfirm;
|
delete callConfirm;
|
||||||
|
|
||||||
Audio::getInstance().stopLoop();
|
Audio::getInstance().stopLoop();
|
||||||
|
|
||||||
CoreAV* av = Core::getInstance()->getAv();
|
CoreAV* av = Core::getInstance()->getAv();
|
||||||
av->cancelCall(f->getFriendId());
|
av->cancelCall(f->getFriendId());
|
||||||
}
|
}
|
||||||
|
@ -418,9 +444,10 @@ void ChatForm::onRejectCallTriggered()
|
||||||
void ChatForm::onCallTriggered()
|
void ChatForm::onCallTriggered()
|
||||||
{
|
{
|
||||||
CoreAV* av = Core::getInstance()->getAv();
|
CoreAV* av = Core::getInstance()->getAv();
|
||||||
|
uint32_t friendId = f->getFriendId();
|
||||||
if (av->isCallStarted(f)) {
|
if (av->isCallStarted(f)) {
|
||||||
av->cancelCall(f->getFriendId());
|
av->cancelCall(friendId);
|
||||||
} else if (av->startCall(f->getFriendId(), false)) {
|
} else if (av->startCall(friendId, false)) {
|
||||||
showOutgoingCall(false);
|
showOutgoingCall(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -428,12 +455,13 @@ void ChatForm::onCallTriggered()
|
||||||
void ChatForm::onVideoCallTriggered()
|
void ChatForm::onVideoCallTriggered()
|
||||||
{
|
{
|
||||||
CoreAV* av = Core::getInstance()->getAv();
|
CoreAV* av = Core::getInstance()->getAv();
|
||||||
|
uint32_t friendId = f->getFriendId();
|
||||||
if (av->isCallStarted(f)) {
|
if (av->isCallStarted(f)) {
|
||||||
// TODO: We want to activate video on the active call.
|
// TODO: We want to activate video on the active call.
|
||||||
if (av->isCallVideoEnabled(f)) {
|
if (av->isCallVideoEnabled(f)) {
|
||||||
av->cancelCall(f->getFriendId());
|
av->cancelCall(friendId);
|
||||||
}
|
}
|
||||||
} else if (av->startCall(f->getFriendId(), true)) {
|
} else if (av->startCall(friendId, true)) {
|
||||||
showOutgoingCall(true);
|
showOutgoingCall(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,27 +477,24 @@ void ChatForm::updateCallButtons()
|
||||||
videoButton->setObjectName(video ? "red" : "");
|
videoButton->setObjectName(video ? "red" : "");
|
||||||
videoButton->setToolTip(video ? tr("End video call") : tr("Can't start video call"));
|
videoButton->setToolTip(video ? tr("End video call") : tr("Can't start video call"));
|
||||||
|
|
||||||
callButton->setObjectName((audio && !video) ? "red" : "");
|
callButton->setObjectName(!video ? "red" : "");
|
||||||
callButton->setToolTip((audio && !video) ? tr("End audio call")
|
callButton->setToolTip(!video ? tr("End audio call") : tr("Can't start audio call"));
|
||||||
: tr("Can't start audio call"));
|
|
||||||
} else {
|
} else {
|
||||||
const Status fs = f->getStatus();
|
const Status fs = f->getStatus();
|
||||||
bool online = fs != Status::Offline;
|
bool online = fs != Status::Offline;
|
||||||
callButton->setEnabled(online);
|
callButton->setEnabled(online);
|
||||||
videoButton->setEnabled(online);
|
videoButton->setEnabled(online);
|
||||||
|
|
||||||
callButton->setObjectName(online ? "green" : "");
|
QString color = online ? "green" : "";
|
||||||
|
callButton->setObjectName(color);
|
||||||
callButton->setToolTip(online ? tr("Start audio call") : tr("Can't start audio call"));
|
callButton->setToolTip(online ? tr("Start audio call") : tr("Can't start audio call"));
|
||||||
|
|
||||||
videoButton->setObjectName(online ? "green" : "");
|
videoButton->setObjectName(color);
|
||||||
videoButton->setToolTip(online ? tr("Start video call") : tr("Can't start video call"));
|
videoButton->setToolTip(online ? tr("Start video call") : tr("Can't start video call"));
|
||||||
}
|
}
|
||||||
|
|
||||||
callButton->setStyleSheet(
|
callButton->setStyleSheet(Style::getStylesheet(CALL_BTN_STYLESHEET));
|
||||||
Style::getStylesheet(QStringLiteral(":/ui/callButton/callButton.css")));
|
videoButton->setStyleSheet(Style::getStylesheet(VIDEO_BTN_STYLESHEET));
|
||||||
videoButton->setStyleSheet(
|
|
||||||
Style::getStylesheet(QStringLiteral(":/ui/videoButton/videoButton.css")));
|
|
||||||
|
|
||||||
updateMuteMicButton();
|
updateMuteMicButton();
|
||||||
updateMuteVolButton();
|
updateMuteVolButton();
|
||||||
}
|
}
|
||||||
|
@ -477,7 +502,6 @@ void ChatForm::updateCallButtons()
|
||||||
void ChatForm::onMicMuteToggle()
|
void ChatForm::onMicMuteToggle()
|
||||||
{
|
{
|
||||||
CoreAV* av = Core::getInstance()->getAv();
|
CoreAV* av = Core::getInstance()->getAv();
|
||||||
|
|
||||||
av->toggleMuteCallInput(f);
|
av->toggleMuteCallInput(f);
|
||||||
updateMuteMicButton();
|
updateMuteMicButton();
|
||||||
}
|
}
|
||||||
|
@ -485,7 +509,6 @@ void ChatForm::onMicMuteToggle()
|
||||||
void ChatForm::onVolMuteToggle()
|
void ChatForm::onVolMuteToggle()
|
||||||
{
|
{
|
||||||
CoreAV* av = Core::getInstance()->getAv();
|
CoreAV* av = Core::getInstance()->getAv();
|
||||||
|
|
||||||
av->toggleMuteCallOutput(f);
|
av->toggleMuteCallOutput(f);
|
||||||
updateMuteVolButton();
|
updateMuteVolButton();
|
||||||
}
|
}
|
||||||
|
@ -496,7 +519,8 @@ void ChatForm::onFileSendFailed(uint32_t friendId, const QString& fname)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addSystemInfoMessage(tr("Failed to send file \"%1\"").arg(fname), ChatMessage::ERROR,
|
addSystemInfoMessage(tr("Failed to send file \"%1\"").arg(fname),
|
||||||
|
ChatMessage::ERROR,
|
||||||
QDateTime::currentDateTime());
|
QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,32 +535,18 @@ void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status)
|
||||||
// Hide the "is typing" message when a friend goes offline
|
// Hide the "is typing" message when a friend goes offline
|
||||||
setFriendTyping(false);
|
setFriendTyping(false);
|
||||||
} else {
|
} else {
|
||||||
QTimer::singleShot(250, this, SLOT(onDeliverOfflineMessages()));
|
QTimer::singleShot(DELIVER_OFFLINE_MESSAGES_DELAY, this, SLOT(onDeliverOfflineMessages()));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCallButtons();
|
updateCallButtons();
|
||||||
|
|
||||||
if (Settings::getInstance().getStatusChangeNotificationEnabled()) {
|
if (Settings::getInstance().getStatusChangeNotificationEnabled()) {
|
||||||
QString fStatus = "";
|
QString fStatus = statusToString(status);
|
||||||
switch (status) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"")
|
addSystemInfoMessage(tr("%1 is now %2", "e.g. \"Dubslow is now online\"")
|
||||||
.arg(f->getDisplayedName())
|
.arg(f->getDisplayedName())
|
||||||
.arg(fStatus),
|
.arg(fStatus),
|
||||||
ChatMessage::INFO, QDateTime::currentDateTime());
|
ChatMessage::INFO,
|
||||||
|
QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,40 +617,44 @@ void ChatForm::dragEnterEvent(QDragEnterEvent* ev)
|
||||||
|
|
||||||
void ChatForm::dropEvent(QDropEvent* ev)
|
void ChatForm::dropEvent(QDropEvent* ev)
|
||||||
{
|
{
|
||||||
if (ev->mimeData()->hasUrls()) {
|
if (!ev->mimeData()->hasUrls()) {
|
||||||
Core* core = Core::getInstance();
|
return;
|
||||||
for (QUrl url : ev->mimeData()->urls()) {
|
}
|
||||||
QFileInfo info(url.path());
|
|
||||||
QFile file(info.absoluteFilePath());
|
|
||||||
|
|
||||||
if (url.isValid() && !url.isLocalFile()
|
Core* core = Core::getInstance();
|
||||||
&& url.toString().length() < TOX_MAX_MESSAGE_LENGTH) {
|
for (const QUrl& url : ev->mimeData()->urls()) {
|
||||||
SendMessageStr(url.toString());
|
QFileInfo info(url.path());
|
||||||
continue;
|
QFile file(info.absoluteFilePath());
|
||||||
}
|
|
||||||
|
|
||||||
|
QString urlString = url.toString();
|
||||||
|
if (url.isValid() && !url.isLocalFile() && urlString.length() < TOX_MAX_MESSAGE_LENGTH) {
|
||||||
|
SendMessageStr(urlString);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString fileName = info.fileName();
|
||||||
|
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
||||||
|
info.setFile(url.toLocalFile());
|
||||||
|
file.setFileName(info.absoluteFilePath());
|
||||||
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
||||||
info.setFile(url.toLocalFile());
|
QMessageBox::warning(this,
|
||||||
file.setFileName(info.absoluteFilePath());
|
tr("Unable to open"),
|
||||||
if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
|
tr("qTox wasn't able to open %1").arg(fileName));
|
||||||
QMessageBox::warning(this, tr("Unable to open"),
|
|
||||||
tr("qTox wasn't able to open %1").arg(info.fileName()));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.isSequential()) {
|
|
||||||
QMessageBox::critical(0, tr("Bad idea"), tr("You're trying to send a sequential"
|
|
||||||
" file, which is not going to work!"));
|
|
||||||
file.close();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
if (file.isSequential()) {
|
||||||
|
QMessageBox::critical(0,
|
||||||
|
tr("Bad idea"),
|
||||||
|
tr("You're trying to send a sequential file, "
|
||||||
|
"which is not going to work!"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (info.exists()) {
|
if (info.exists()) {
|
||||||
core->sendFile(f->getFriendId(), info.fileName(), info.absoluteFilePath(), info.size());
|
core->sendFile(f->getFriendId(), fileName, info.absoluteFilePath(), info.size());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -673,10 +687,9 @@ void ChatForm::onLoadChatHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Split on smaller methods (style)
|
// TODO: Split on smaller methods (style)
|
||||||
void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
||||||
{
|
{
|
||||||
QDateTime now = historyBaselineDate.addMSecs(-1);
|
QDateTime now = historyBaselineDate.addMSecs(-1);
|
||||||
|
|
||||||
if (since > now) {
|
if (since > now) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -731,7 +744,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
||||||
bool isAction = it.message.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
|
bool isAction = it.message.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
|
||||||
bool needSending = !it.isSent && isSelf;
|
bool needSending = !it.isSent && isSelf;
|
||||||
|
|
||||||
QString messageText = isAction ? it.message.mid(4) : it.message;
|
QString messageText = isAction ? it.message.mid(ACTION_PREFIX.length()) : it.message;
|
||||||
ChatMessage::MessageType type = isAction ? ChatMessage::ACTION : ChatMessage::NORMAL;
|
ChatMessage::MessageType type = isAction ? ChatMessage::ACTION : ChatMessage::NORMAL;
|
||||||
QDateTime dateTime = needSending ? QDateTime() : msgDateTime;
|
QDateTime dateTime = needSending ? QDateTime() : msgDateTime;
|
||||||
auto msg = ChatMessage::createChatMessage(authorStr, messageText, type, isSelf, dateTime);
|
auto msg = ChatMessage::createChatMessage(authorStr, messageText, type, isSelf, dateTime);
|
||||||
|
@ -747,43 +760,38 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
||||||
if (needSending && processUndelivered) {
|
if (needSending && processUndelivered) {
|
||||||
Core* core = Core::getInstance();
|
Core* core = Core::getInstance();
|
||||||
uint32_t friendId = f->getFriendId();
|
uint32_t friendId = f->getFriendId();
|
||||||
int rec = isAction ? core->sendAction(friendId, msg->toString())
|
QString stringMsg = msg->toString();
|
||||||
: core->sendMessage(friendId, msg->toString());
|
int receipt = isAction ? core->sendAction(friendId, stringMsg)
|
||||||
getOfflineMsgEngine()->registerReceipt(rec, it.id, msg);
|
: core->sendMessage(friendId, stringMsg);
|
||||||
|
getOfflineMsgEngine()->registerReceipt(receipt, it.id, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
historyMessages.append(msg);
|
historyMessages.append(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
previousId = storedPrevId;
|
previousId = storedPrevId;
|
||||||
int savedSliderPos =
|
|
||||||
chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
|
|
||||||
|
|
||||||
earliestMessage = since;
|
earliestMessage = since;
|
||||||
|
|
||||||
|
QScrollBar* verticalBar = chatWidget->verticalScrollBar();
|
||||||
|
int savedSliderPos = verticalBar->maximum() - verticalBar->value();
|
||||||
chatWidget->insertChatlineOnTop(historyMessages);
|
chatWidget->insertChatlineOnTop(historyMessages);
|
||||||
|
savedSliderPos = verticalBar->maximum() - savedSliderPos;
|
||||||
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
|
verticalBar->setValue(savedSliderPos);
|
||||||
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onScreenshotClicked()
|
void ChatForm::onScreenshotClicked()
|
||||||
{
|
{
|
||||||
doScreenshot();
|
doScreenshot();
|
||||||
|
|
||||||
// Give the window manager a moment to open the fullscreen grabber window
|
// Give the window manager a moment to open the fullscreen grabber window
|
||||||
QTimer::singleShot(500, this, SLOT(hideFileMenu()));
|
QTimer::singleShot(SCREENSHOT_GRABBER_OPENING_DELAY, this, SLOT(hideFileMenu()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::doScreenshot()
|
void ChatForm::doScreenshot()
|
||||||
{
|
{
|
||||||
// note: grabber is self-managed and will destroy itself when done
|
// note: grabber is self-managed and will destroy itself when done
|
||||||
ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber;
|
ScreenshotGrabber* grabber = new ScreenshotGrabber;
|
||||||
|
connect(grabber, &ScreenshotGrabber::screenshotTaken, this, &ChatForm::onScreenshotTaken);
|
||||||
connect(screenshotGrabber, &ScreenshotGrabber::screenshotTaken, this, &ChatForm::onScreenshotTaken);
|
grabber->showGrabber();
|
||||||
|
|
||||||
screenshotGrabber->showGrabber();
|
|
||||||
|
|
||||||
// Create dir for screenshots
|
// Create dir for screenshots
|
||||||
QDir(Settings::getInstance().getAppDataDirPath()).mkpath("screenshots");
|
QDir(Settings::getInstance().getAppDataDirPath()).mkpath("screenshots");
|
||||||
}
|
}
|
||||||
|
@ -798,16 +806,13 @@ void ChatForm::onScreenshotTaken(const QPixmap& pixmap)
|
||||||
.arg(Settings::getInstance().getAppDataDirPath())
|
.arg(Settings::getInstance().getAppDataDirPath())
|
||||||
.arg(QDir::separator())
|
.arg(QDir::separator())
|
||||||
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH-mm-ss.zzz"));
|
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH-mm-ss.zzz"));
|
||||||
|
|
||||||
QFile file(filepath);
|
QFile file(filepath);
|
||||||
|
|
||||||
if (file.open(QFile::ReadWrite)) {
|
if (file.open(QFile::ReadWrite)) {
|
||||||
pixmap.save(&file, "PNG");
|
pixmap.save(&file, "PNG");
|
||||||
|
|
||||||
qint64 filesize = file.size();
|
qint64 filesize = file.size();
|
||||||
file.close();
|
file.close();
|
||||||
QFileInfo fi(file);
|
QFileInfo fi(file);
|
||||||
|
|
||||||
Core::getInstance()->sendFile(f->getFriendId(), fi.fileName(), fi.filePath(), filesize);
|
Core::getInstance()->sendFile(f->getFriendId(), fi.fileName(), fi.filePath(), filesize);
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::warning(this,
|
QMessageBox::warning(this,
|
||||||
|
@ -823,7 +828,6 @@ void ChatForm::onLoadHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadHistoryDialog dlg;
|
LoadHistoryDialog dlg;
|
||||||
|
|
||||||
if (dlg.exec()) {
|
if (dlg.exec()) {
|
||||||
QDateTime fromTime = dlg.getFromDate();
|
QDateTime fromTime = dlg.getFromDate();
|
||||||
loadHistory(fromTime);
|
loadHistory(fromTime);
|
||||||
|
@ -833,7 +837,6 @@ void ChatForm::onLoadHistory()
|
||||||
void ChatForm::insertChatMessage(ChatMessage::Ptr msg)
|
void ChatForm::insertChatMessage(ChatMessage::Ptr msg)
|
||||||
{
|
{
|
||||||
GenericChatForm::insertChatMessage(msg);
|
GenericChatForm::insertChatMessage(msg);
|
||||||
|
|
||||||
if (netcam && bodySplitter->sizes()[1] == 0) {
|
if (netcam && bodySplitter->sizes()[1] == 0) {
|
||||||
netcam->setShowMessages(true, true);
|
netcam->setShowMessages(true, true);
|
||||||
}
|
}
|
||||||
|
@ -844,7 +847,6 @@ void ChatForm::onCopyStatusMessage()
|
||||||
// make sure to copy not truncated text directly from the friend
|
// make sure to copy not truncated text directly from the friend
|
||||||
QString text = f->getStatusMessage();
|
QString text = f->getStatusMessage();
|
||||||
QClipboard* clipboard = QApplication::clipboard();
|
QClipboard* clipboard = QApplication::clipboard();
|
||||||
|
|
||||||
if (clipboard) {
|
if (clipboard) {
|
||||||
clipboard->setText(text, QClipboard::Clipboard);
|
clipboard->setText(text, QClipboard::Clipboard);
|
||||||
}
|
}
|
||||||
|
@ -856,21 +858,15 @@ void ChatForm::updateMuteMicButton()
|
||||||
|
|
||||||
micButton->setEnabled(av->isCallActive(f));
|
micButton->setEnabled(av->isCallActive(f));
|
||||||
if (micButton->isEnabled()) {
|
if (micButton->isEnabled()) {
|
||||||
if (av->isCallInputMuted(f)) {
|
bool inputMuted = av->isCallInputMuted(f);
|
||||||
micButton->setObjectName("red");
|
micButton->setObjectName(inputMuted ? "red" : "green");
|
||||||
micButton->setToolTip(tr("Unmute microphone"));
|
micButton->setToolTip(inputMuted ? tr("Unmute microphone") : tr("Mute microphone"));
|
||||||
} else {
|
|
||||||
micButton->setObjectName("green");
|
|
||||||
micButton->setToolTip(tr("Mute microphone"));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
micButton->setObjectName("");
|
micButton->setObjectName("");
|
||||||
micButton->setToolTip(tr("Microphone can be muted only during a call"));
|
micButton->setToolTip(tr("Microphone can be muted only during a call"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString stylePath = QStringLiteral(":/ui/micButton/micButton.css");
|
micButton->setStyleSheet(Style::getStylesheet(MIC_BTN_STYLESHEET));
|
||||||
QString style = Style::getStylesheet(stylePath);
|
|
||||||
micButton->setStyleSheet(style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::updateMuteVolButton()
|
void ChatForm::updateMuteVolButton()
|
||||||
|
@ -879,50 +875,45 @@ void ChatForm::updateMuteVolButton()
|
||||||
|
|
||||||
volButton->setEnabled(av->isCallActive(f));
|
volButton->setEnabled(av->isCallActive(f));
|
||||||
if (volButton->isEnabled()) {
|
if (volButton->isEnabled()) {
|
||||||
if (av->isCallOutputMuted(f)) {
|
bool outputMuted = av->isCallOutputMuted(f);
|
||||||
volButton->setObjectName("red");
|
volButton->setObjectName(outputMuted ? "red" : "green");
|
||||||
volButton->setToolTip(tr("Unmute call"));
|
volButton->setToolTip(outputMuted ? tr("Unmute call") : tr("Mute call"));
|
||||||
} else {
|
|
||||||
volButton->setObjectName("green");
|
|
||||||
volButton->setToolTip(tr("Mute call"));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
volButton->setObjectName("");
|
volButton->setObjectName("");
|
||||||
volButton->setToolTip(tr("Sound can be disabled only during a call"));
|
volButton->setToolTip(tr("Sound can be disabled only during a call"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString stylePath = QStringLiteral(":/ui/volButton/volButton.css");
|
volButton->setStyleSheet(Style::getStylesheet(VOL_BTN_STYLESHEET));
|
||||||
QString style = Style::getStylesheet(stylePath);
|
|
||||||
volButton->setStyleSheet(style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::startCounter()
|
void ChatForm::startCounter()
|
||||||
{
|
{
|
||||||
if (!callDurationTimer) {
|
if (callDurationTimer) {
|
||||||
callDurationTimer = new QTimer();
|
return;
|
||||||
connect(callDurationTimer, &QTimer::timeout, this, &ChatForm::onUpdateTime);
|
|
||||||
|
|
||||||
callDurationTimer->start(1000);
|
|
||||||
timeElapsed.start();
|
|
||||||
callDuration->show();
|
|
||||||
}
|
}
|
||||||
|
callDurationTimer = new QTimer();
|
||||||
|
connect(callDurationTimer, &QTimer::timeout, this, &ChatForm::onUpdateTime);
|
||||||
|
callDurationTimer->start(1000);
|
||||||
|
timeElapsed.start();
|
||||||
|
callDuration->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::stopCounter()
|
void ChatForm::stopCounter()
|
||||||
{
|
{
|
||||||
if (callDurationTimer) {
|
if (!callDurationTimer) {
|
||||||
QString dhms = secondsToDHMS(timeElapsed.elapsed() / 1000);
|
return;
|
||||||
QString name = f->getDisplayedName();
|
|
||||||
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(name, dhms), ChatMessage::INFO,
|
|
||||||
QDateTime::currentDateTime());
|
|
||||||
|
|
||||||
callDurationTimer->stop();
|
|
||||||
callDuration->setText("");
|
|
||||||
callDuration->hide();
|
|
||||||
|
|
||||||
delete callDurationTimer;
|
|
||||||
callDurationTimer = nullptr;
|
|
||||||
}
|
}
|
||||||
|
QString dhms = secondsToDHMS(timeElapsed.elapsed() / 1000);
|
||||||
|
QString name = f->getDisplayedName();
|
||||||
|
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(name, dhms),
|
||||||
|
ChatMessage::INFO,
|
||||||
|
QDateTime::currentDateTime());
|
||||||
|
callDurationTimer->stop();
|
||||||
|
callDuration->setText("");
|
||||||
|
callDuration->hide();
|
||||||
|
|
||||||
|
delete callDurationTimer;
|
||||||
|
callDurationTimer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onUpdateTime()
|
void ChatForm::onUpdateTime()
|
||||||
|
@ -930,46 +921,18 @@ void ChatForm::onUpdateTime()
|
||||||
callDuration->setText(secondsToDHMS(timeElapsed.elapsed() / 1000));
|
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);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hours) {
|
|
||||||
return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minutes) {
|
|
||||||
return cD + res.sprintf("%02dm %02ds", minutes, seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cD + res.sprintf("%02ds", seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatForm::setFriendTyping(bool isTyping)
|
void ChatForm::setFriendTyping(bool isTyping)
|
||||||
{
|
{
|
||||||
chatWidget->setTypingNotificationVisible(isTyping);
|
chatWidget->setTypingNotificationVisible(isTyping);
|
||||||
|
|
||||||
Text* text = static_cast<Text*>(chatWidget->getTypingNotification()->getContent(1));
|
Text* text = static_cast<Text*>(chatWidget->getTypingNotification()->getContent(1));
|
||||||
|
QString typingDiv = "<div class=typing>%1</div>";
|
||||||
QString name = f->getDisplayedName();
|
QString name = f->getDisplayedName();
|
||||||
text->setText("<div class=typing>" + tr("%1 is typing").arg(name) + "</div>");
|
text->setText(typingDiv.arg(tr("%1 is typing").arg(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::show(ContentLayout* contentLayout)
|
void ChatForm::show(ContentLayout* contentLayout)
|
||||||
{
|
{
|
||||||
GenericChatForm::show(contentLayout);
|
GenericChatForm::show(contentLayout);
|
||||||
|
|
||||||
if (callConfirm) {
|
if (callConfirm) {
|
||||||
callConfirm->show();
|
callConfirm->show();
|
||||||
}
|
}
|
||||||
|
@ -1012,16 +975,14 @@ void ChatForm::SendMessageStr(QString msg)
|
||||||
QList<QString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
|
QList<QString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
|
||||||
QDateTime timestamp = QDateTime::currentDateTime();
|
QDateTime timestamp = QDateTime::currentDateTime();
|
||||||
|
|
||||||
for (QString& part : splittedMsg) {
|
for (const QString& part : splittedMsg) {
|
||||||
QString historyPart = part;
|
QString historyPart = part;
|
||||||
if (isAction) {
|
if (isAction) {
|
||||||
historyPart = ACTION_PREFIX + part;
|
historyPart = ACTION_PREFIX + part;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool status = !Settings::getInstance().getFauxOfflineMessaging();
|
bool status = !Settings::getInstance().getFauxOfflineMessaging();
|
||||||
|
|
||||||
ChatMessage::Ptr ma = addSelfMessage(part, isAction, timestamp, false);
|
ChatMessage::Ptr ma = addSelfMessage(part, isAction, timestamp, false);
|
||||||
|
|
||||||
Core* core = Core::getInstance();
|
Core* core = Core::getInstance();
|
||||||
uint32_t friendId = f->getFriendId();
|
uint32_t friendId = f->getFriendId();
|
||||||
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
|
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
|
||||||
|
@ -1041,8 +1002,8 @@ void ChatForm::SendMessageStr(QString msg)
|
||||||
ma->markAsSent(QDateTime::currentDateTime());
|
ma->markAsSent(QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
msgEdit->setLastMessage(msg); // set last message only when sending it
|
// set last message only when sending it
|
||||||
|
msgEdit->setLastMessage(msg);
|
||||||
Widget::getInstance()->updateFriendActivity(f);
|
Widget::getInstance()->updateFriendActivity(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
explicit ChatForm(Friend* chatFriend);
|
explicit ChatForm(Friend* chatFriend);
|
||||||
~ChatForm();
|
~ChatForm();
|
||||||
void setStatusMessage(const QString& newMessage);
|
void setStatusMessage(const QString& newMessage);
|
||||||
void loadHistory(QDateTime since, bool processUndelivered = false);
|
void loadHistory(const QDateTime& since, bool processUndelivered = false);
|
||||||
|
|
||||||
void dischargeReceipt(int receipt);
|
void dischargeReceipt(int receipt);
|
||||||
void setFriendTyping(bool isTyping);
|
void setFriendTyping(bool isTyping);
|
||||||
|
@ -103,7 +103,6 @@ private:
|
||||||
void showOutgoingCall(bool video);
|
void showOutgoingCall(bool video);
|
||||||
void startCounter();
|
void startCounter();
|
||||||
void stopCounter();
|
void stopCounter();
|
||||||
QString secondsToDHMS(quint32 duration);
|
|
||||||
void updateCallButtons();
|
void updateCallButtons();
|
||||||
void SendMessageStr(QString msg);
|
void SendMessageStr(QString msg);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user