1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/src/widget/form/chatform.cpp

686 lines
22 KiB
C++
Raw Normal View History

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>
#include <QBitmap>
2014-06-25 04:11:11 +08:00
#include "chatform.h"
#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/tool/chatactions/filetransferaction.h"
#include "src/widget/netcamview.h"
#include "src/widget/chatareawidget.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-06-25 04:11:11 +08:00
ChatForm::ChatForm(Friend* chatFriend)
: 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
{
nameLabel->setText(f->getName());
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");
statusMessageLabel->setFont(Style::getFont(Style::Medium));
statusMessageLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize());
netcam = new NetCamView();
headTextLayout->addWidget(statusMessageLabel);
2014-06-25 04:11:11 +08:00
headTextLayout->addStretch();
menu.addAction(tr("Load History..."), this, SLOT(onLoadHistory()));
2014-09-11 21:44:34 +08:00
connect(Core::getInstance(), &Core::fileSendStarted, this, &ChatForm::startFileSend);
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-11 21:44:34 +08:00
connect(chatWidget, &ChatAreaWidget::onFileTranfertInterract, this, &ChatForm::onFileTansBtnClicked);
2014-09-24 00:52:06 +08:00
connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed);
2014-09-26 00:03:25 +08:00
setAcceptDrops(true);
2014-06-25 04:11:11 +08:00
}
ChatForm::~ChatForm()
{
delete netcam;
2014-06-25 04:11:11 +08:00
}
void ChatForm::setStatusMessage(QString newMessage)
{
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-10-14 13:49:27 +08:00
QDateTime timestamp = QDateTime::currentDateTime();
HistoryKeeper::getInstance()->addChatEntry(f->userId, msg, Core::getInstance()->getSelfId().publicKey, timestamp);
if (msg.startsWith("/me "))
{
msg = msg.right(msg.length() - 4);
addSelfMessage(msg, true, timestamp);
emit sendAction(f->friendId, msg);
}
else
{
addSelfMessage(msg, false, timestamp);
emit sendMessage(f->friendId, msg);
}
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-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();
file.close();
2014-10-17 20:29:48 +08:00
QFileInfo fi(path);
2014-06-26 04:43:28 +08:00
2014-10-17 20:29:48 +08:00
emit sendFile(f->friendId, fi.fileName(), path, filesize);
}
2014-06-26 04:43:28 +08:00
}
void ChatForm::startFileSend(ToxFile file)
2014-06-26 06:30:24 +08:00
{
if (file.friendId != f->friendId)
return;
2014-09-06 03:27:26 +08:00
FileTransferInstance* fileTrans = new FileTransferInstance(file);
ftransWidgets.insert(fileTrans->getId(), fileTrans);
2014-09-11 21:44:34 +08:00
connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile)));
connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection)));
connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool)));
connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool)));
2014-09-06 03:27:26 +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
chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name),
QTime::currentTime().toString("hh:mm"), true)));
}
void ChatForm::onFileRecvRequest(ToxFile file)
{
if (file.friendId != f->friendId)
return;
2014-09-06 03:27:26 +08:00
FileTransferInstance* fileTrans = new FileTransferInstance(file);
ftransWidgets.insert(fileTrans->getId(), fileTrans);
2014-09-11 21:44:34 +08:00
connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile)));
connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection)));
connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool)));
connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool)));
Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{
w->newMessageAlert();
f->hasNewEvents=true;
f->widget->updateStatusLight();
}
2014-09-06 03:27:26 +08:00
QString name;
ToxID friendId = f->getToxID();
if (friendId != previousId)
{
name = f->getName();
previousId = friendId;
}
2014-09-07 19:42:06 +08:00
chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name),
QTime::currentTime().toString("hh:mm"), false)));
2014-10-18 12:53:29 +08:00
2014-10-20 12:25:52 +08:00
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->friendId)).isEmpty()
|| !Settings::getInstance().getGlobalAutoAcceptDir().isEmpty())
2014-10-18 12:53:29 +08:00
fileTrans->pressFromHtml("btnB");
2014-06-26 06:30:24 +08:00
}
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
{
if (FriendId != f->friendId)
return;
callId = CallId;
callButton->disconnect();
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-07-01 03:14:51 +08:00
Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
2014-07-01 03:14:51 +08:00
{
w->newMessageAlert();
f->hasNewEvents=true;
f->widget->updateStatusLight();
2014-07-01 03:14:51 +08:00
}
}
void ChatForm::onAvStart(int FriendId, int CallId, bool video)
{
if (FriendId != f->friendId)
return;
audioInputFlag = true;
2014-10-28 20:50:30 +08:00
audioOutputFlag = true;
callId = CallId;
callButton->disconnect();
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
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
}
else
{
callButton->setObjectName("red");
callButton->style()->polish(callButton);
videoButton->setObjectName("grey");
videoButton->style()->polish(videoButton);
connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
}
}
void ChatForm::onAvCancel(int FriendId, int)
{
if (FriendId != f->friendId)
return;
audioInputFlag = false;
2014-10-28 20:50:30 +08:00
audioOutputFlag = false;
micButton->setObjectName("green");
micButton->style()->polish(micButton);
2014-10-28 20:50:30 +08:00
volButton->setObjectName("green");
volButton->style()->polish(volButton);
callButton->disconnect();
videoButton->disconnect();
callButton->setObjectName("green");
callButton->style()->polish(callButton);
videoButton->setObjectName("green");
videoButton->style()->polish(videoButton);
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
2014-10-16 21:37:48 +08:00
netcam->hide();
}
void ChatForm::onAvEnd(int FriendId, int)
{
if (FriendId != f->friendId)
return;
audioInputFlag = false;
2014-10-28 20:50:30 +08:00
audioOutputFlag = false;
micButton->setObjectName("green");
micButton->style()->polish(micButton);
2014-10-28 20:50:30 +08:00
volButton->setObjectName("green");
volButton->style()->polish(volButton);
callButton->disconnect();
videoButton->disconnect();
2014-06-28 13:14:38 +08:00
callButton->setObjectName("green");
callButton->style()->polish(callButton);
videoButton->setObjectName("green");
videoButton->style()->polish(videoButton);
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
2014-10-16 21:37:48 +08:00
netcam->hide();
}
void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
2014-06-27 09:06:56 +08:00
{
if (FriendId != f->friendId)
return;
2014-06-27 09:06:56 +08:00
callId = CallId;
callButton->disconnect();
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-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
{
if (FriendId != f->friendId)
return;
2014-06-27 09:06:56 +08:00
callButton->disconnect();
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
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
}
else
{
callButton->setObjectName("red");
callButton->style()->polish(callButton);
videoButton->setObjectName("grey");
videoButton->style()->polish(videoButton);
connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
}
2014-06-27 09:06:56 +08:00
}
void ChatForm::onAvEnding(int FriendId, int)
{
if (FriendId != f->friendId)
return;
audioInputFlag = false;
2014-10-28 20:50:30 +08:00
audioOutputFlag = false;
micButton->setObjectName("green");
micButton->style()->polish(micButton);
2014-10-28 20:50:30 +08:00
volButton->setObjectName("green");
volButton->style()->polish(volButton);
callButton->disconnect();
videoButton->disconnect();
2014-06-28 13:14:38 +08:00
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()));
2014-10-16 21:37:48 +08:00
netcam->hide();
}
2014-06-27 09:06:56 +08:00
void ChatForm::onAvRequestTimeout(int FriendId, int)
{
if (FriendId != f->friendId)
return;
audioInputFlag = false;
2014-10-28 20:50:30 +08:00
audioOutputFlag = false;
micButton->setObjectName("green");
micButton->style()->polish(micButton);
2014-10-28 20:50:30 +08:00
volButton->setObjectName("green");
volButton->style()->polish(volButton);
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();
videoButton->setObjectName("green");
videoButton->style()->polish(videoButton);
videoButton->disconnect();
2014-06-27 09:06:56 +08:00
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
2014-10-16 21:37:48 +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
{
if (FriendId != f->friendId)
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
{
if (FriendId != f->friendId)
return;
audioInputFlag = false;
2014-10-28 20:50:30 +08:00
audioOutputFlag = false;
micButton->setObjectName("green");
micButton->style()->polish(micButton);
2014-10-28 20:50:30 +08:00
volButton->setObjectName("green");
volButton->style()->polish(volButton);
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();
videoButton->setObjectName("green");
videoButton->style()->polish(videoButton);
videoButton->disconnect();
2014-06-28 03:59:25 +08:00
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
2014-10-16 21:37:48 +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)
{
if (FriendId != f->friendId || CallId != callId)
return;
2014-10-16 21:37:48 +08:00
if (video)
{
2014-10-16 21:37:48 +08:00
netcam->show(Core::getInstance()->getVideoSourceFromCall(CallId), f->getName());
}
else
{
netcam->hide();
}
}
void ChatForm::onAnswerCallTriggered()
{
2014-08-30 00:16:16 +08:00
audioInputFlag = true;
2014-10-28 20:50:30 +08:00
audioOutputFlag = true;
emit answerCall(callId);
}
void ChatForm::onHangupCallTriggered()
{
2014-08-30 00:16:16 +08:00
audioInputFlag = false;
2014-10-28 20:50:30 +08:00
audioOutputFlag = false;
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);
}
void ChatForm::onCallTriggered()
{
2014-10-28 20:50:30 +08:00
audioInputFlag = true;
audioOutputFlag = true;
callButton->disconnect();
videoButton->disconnect();
emit startCall(f->friendId);
2014-06-27 09:06:56 +08:00
}
void ChatForm::onVideoCallTriggered()
{
2014-08-30 00:16:16 +08:00
audioInputFlag = true;
2014-10-28 20:50:30 +08:00
audioOutputFlag = true;
callButton->disconnect();
videoButton->disconnect();
emit startVideoCall(f->friendId, true);
}
2014-10-25 17:29:25 +08:00
void ChatForm::onAvCallFailed(int FriendId)
{
if (FriendId != f->friendId)
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-08-30 00:16:16 +08:00
audioInputFlag = false;
2014-10-28 20:50:30 +08:00
audioOutputFlag = false;
micButton->setObjectName("green");
micButton->style()->polish(micButton);
2014-10-28 20:50:30 +08:00
volButton->setObjectName("green");
volButton->style()->polish(volButton);
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();
videoButton->setObjectName("green");
videoButton->style()->polish(videoButton);
videoButton->disconnect();
2014-06-27 09:06:56 +08:00
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
2014-10-16 21:37:48 +08:00
netcam->hide();
2014-06-27 09:06:56 +08:00
emit cancelCall(callId, f->friendId);
}
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-06 03:27:26 +08:00
void ChatForm::onFileTansBtnClicked(QString widgetName, QString buttonName)
{
uint id = widgetName.toUInt();
auto it = ftransWidgets.find(id);
if (it != ftransWidgets.end())
it.value()->pressFromHtml(buttonName);
else
qDebug() << "no filetransferwidget: " << id;
}
2014-09-24 00:52:06 +08:00
void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
{
if (FriendId != f->friendId)
return;
2014-10-14 13:49:27 +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)
{
if (FriendId != f->friendId)
return;
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())
Core::getInstance()->sendFile(f->friendId, info.fileName(), info.absoluteFilePath(), info.size());
}
}
}
2014-09-27 03:23:20 +08:00
void ChatForm::onAvatarRemoved(int FriendId)
{
if (FriendId != f->friendId)
return;
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
2014-09-27 03:23:20 +08:00
}
void ChatForm::onLoadHistory()
{
LoadHistoryDialog dlg;
if (dlg.exec())
{
QDateTime fromTime = dlg.getFromDate();
2014-10-11 01:32:10 +08:00
QDateTime toTime = QDateTime::currentDateTime();
if (fromTime > toTime)
return;
if (earliestMessage)
{
if (*earliestMessage < fromTime)
return;
if (*earliestMessage < toTime)
2014-10-14 13:49:27 +08:00
{
2014-10-11 01:32:10 +08:00
toTime = *earliestMessage;
2014-10-14 13:49:27 +08:00
toTime = toTime.addMSecs(-1);
}
2014-10-11 01:32:10 +08:00
}
2014-10-22 22:14:42 +08:00
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->userId, fromTime, toTime);
2014-10-11 01:32:10 +08:00
ToxID storedPrevId;
std::swap(storedPrevId, previousId);
QList<ChatActionPtr> historyMessages;
2014-10-11 01:32:10 +08:00
for (const auto &it : msgs)
{
ChatActionPtr ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, it.timestamp.toLocalTime());
2014-10-11 01:32:10 +08:00
historyMessages.append(ca);
}
std::swap(storedPrevId, previousId);
2014-10-11 01:32:10 +08:00
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
2014-10-14 13:49:27 +08:00
if (earliestMessage != nullptr)
*earliestMessage = fromTime;
2014-10-11 01:32:10 +08:00
chatWidget->insertMessagesTop(historyMessages);
2014-10-11 01:32:10 +08:00
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
}
}