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

Merge pull request #3563

Diadlo (2):
      refactor(filetransferwidget): Added ability to check activity
      fix(chatlog): Don't delete active transfer widget
This commit is contained in:
sudden6 2016-08-01 22:08:48 +02:00
commit 349a1ffb02
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
4 changed files with 43 additions and 1 deletions

View File

@ -20,6 +20,8 @@
#include "chatlog.h"
#include "chatmessage.h"
#include "chatlinecontent.h"
#include "chatlinecontentproxy.h"
#include "content/filetransferwidget.h"
#include "src/widget/translator.h"
#include <QDebug>
@ -560,11 +562,20 @@ void ChatLog::clear()
{
clearSelection();
QVector<ChatLine::Ptr> savedLines;
for (ChatLine::Ptr l : lines)
{
if (isActiveFileTransfer(l))
savedLines.push_back(l);
else
l->removeFromScene();
}
lines.clear();
visibleLines.clear();
for (ChatLine::Ptr l : savedLines)
insertChatlineAtBottom(l);
updateSceneRect();
}
@ -850,3 +861,22 @@ void ChatLog::retranslateUi()
copyAction->setText(tr("Copy"));
selectAllAction->setText(tr("Select all"));
}
bool ChatLog::isActiveFileTransfer(ChatLine::Ptr l)
{
int count = l->getColumnCount();
for (int i = 0; i < count; i++)
{
ChatLineContent *content = l->getContent(i);
ChatLineContentProxy *proxy = dynamic_cast<ChatLineContentProxy*>(content);
if (!proxy)
continue;
QWidget *widget = proxy->getWidget();
FileTransferWidget *transferWidget = dynamic_cast<FileTransferWidget*>(widget);
if (transferWidget && transferWidget->isActive())
return true;
}
return false;
}

View File

@ -106,6 +106,7 @@ private slots:
private:
void retranslateUi();
bool isActiveFileTransfer(ChatLine::Ptr l);
private:
enum SelectionMode {

View File

@ -47,6 +47,7 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
, lastTick(QTime::currentTime())
, backgroundColor(Style::getColor(Style::LightGrey))
, buttonColor(Style::getColor(Style::Yellow))
, active(true)
{
ui->setupUi(this);
@ -132,6 +133,11 @@ void FileTransferWidget::autoAcceptTransfer(const QString &path)
qWarning() << "Cannot write to " << filepath;
}
bool FileTransferWidget::isActive() const
{
return active;
}
void FileTransferWidget::acceptTransfer(const QString &filepath)
{
if (filepath.isEmpty())
@ -292,6 +298,7 @@ void FileTransferWidget::onFileTransferCancelled(ToxFile file)
return;
fileInfo = file;
active = false;
setBackgroundColor(Style::getColor(Style::Red), true);
@ -347,6 +354,7 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file)
return;
fileInfo = file;
active = false;
setBackgroundColor(Style::getColor(Style::Green), true);

View File

@ -42,6 +42,7 @@ public:
explicit FileTransferWidget(QWidget *parent, ToxFile file);
virtual ~FileTransferWidget();
void autoAcceptTransfer(const QString& path);
bool isActive() const;
protected slots:
void onFileTransferInfo(ToxFile file);
@ -88,6 +89,8 @@ private:
static const uint8_t TRANSFER_ROLLING_AVG_COUNT = 4;
uint8_t meanIndex = 0;
qreal meanData[TRANSFER_ROLLING_AVG_COUNT] = {0.0};
bool active;
};
#endif // FILETRANSFERWIDGET_H