2014-11-16 19:58:43 +08:00
|
|
|
/*
|
2019-06-24 22:01:18 +08:00
|
|
|
Copyright © 2014-2019 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2014-11-16 19:58:43 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
2014-11-16 19:58:43 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2014-11-16 19:58:43 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-11-16 19:58:43 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-16 19:58:43 +08:00
|
|
|
*/
|
|
|
|
|
2020-05-03 20:44:08 +08:00
|
|
|
#pragma once
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2014-11-17 23:05:14 +08:00
|
|
|
#include <QTime>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QWidget>
|
2015-02-05 00:21:56 +08:00
|
|
|
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/chatlog/chatlinecontent.h"
|
2018-09-25 11:08:30 +08:00
|
|
|
#include "src/chatlog/toxfileprogress.h"
|
2017-10-27 20:02:43 +08:00
|
|
|
#include "src/core/toxfile.h"
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2020-07-08 03:44:39 +08:00
|
|
|
class CoreFile;
|
2015-01-18 01:17:40 +08:00
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
namespace Ui {
|
|
|
|
class FileTransferWidget;
|
|
|
|
}
|
|
|
|
|
2015-02-07 21:02:40 +08:00
|
|
|
class QVariantAnimation;
|
2014-11-17 23:05:14 +08:00
|
|
|
class QPushButton;
|
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
class FileTransferWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-07-08 03:44:39 +08:00
|
|
|
explicit FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file);
|
2014-11-12 21:11:25 +08:00
|
|
|
virtual ~FileTransferWidget();
|
2016-07-30 21:14:18 +08:00
|
|
|
bool isActive() const;
|
2019-05-23 01:48:23 +08:00
|
|
|
static QString getHumanReadableSize(qint64 size);
|
2014-12-14 04:11:03 +08:00
|
|
|
|
2019-05-26 08:11:44 +08:00
|
|
|
void onFileTransferUpdate(ToxFile file);
|
2014-11-17 23:05:14 +08:00
|
|
|
|
|
|
|
protected:
|
2018-09-25 11:08:30 +08:00
|
|
|
void updateWidgetColor(ToxFile const& file);
|
|
|
|
void updateWidgetText(ToxFile const& file);
|
|
|
|
void updateFileProgress(ToxFile const& file);
|
|
|
|
void updateSignals(ToxFile const& file);
|
|
|
|
void updatePreview(ToxFile const& file);
|
|
|
|
void setupButtons(ToxFile const& file);
|
2014-11-17 23:05:14 +08:00
|
|
|
void handleButton(QPushButton* btn);
|
2014-11-18 03:08:55 +08:00
|
|
|
void showPreview(const QString& filename);
|
2015-01-11 18:57:33 +08:00
|
|
|
void acceptTransfer(const QString& filepath);
|
2015-02-14 19:14:09 +08:00
|
|
|
void setBackgroundColor(const QColor& c, bool whiteFont);
|
|
|
|
void setButtonColor(const QColor& c);
|
2015-01-11 18:57:33 +08:00
|
|
|
|
2015-02-14 19:14:09 +08:00
|
|
|
bool drawButtonAreaNeeded() const;
|
2014-11-17 23:05:14 +08:00
|
|
|
|
2019-10-14 09:07:57 +08:00
|
|
|
void paintEvent(QPaintEvent*) final;
|
2015-01-26 18:09:21 +08:00
|
|
|
|
2014-11-17 23:05:14 +08:00
|
|
|
private slots:
|
2017-02-28 20:29:51 +08:00
|
|
|
void onLeftButtonClicked();
|
|
|
|
void onRightButtonClicked();
|
2016-02-14 23:20:11 +08:00
|
|
|
void onPreviewButtonClicked();
|
2014-11-17 03:01:37 +08:00
|
|
|
|
2016-04-15 02:19:18 +08:00
|
|
|
private:
|
2017-02-26 19:52:45 +08:00
|
|
|
static QPixmap scaleCropIntoSquare(const QPixmap& source, int targetSize);
|
2017-09-12 07:55:13 +08:00
|
|
|
static int getExifOrientation(const char* data, const int size);
|
|
|
|
static void applyTransformation(const int oritentation, QImage& image);
|
2018-10-31 09:06:05 +08:00
|
|
|
static bool tryRemoveFile(const QString &filepath);
|
2016-04-15 02:19:18 +08:00
|
|
|
|
2018-09-25 11:08:30 +08:00
|
|
|
void updateWidget(ToxFile const& file);
|
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
private:
|
2020-07-08 03:44:39 +08:00
|
|
|
CoreFile& coreFile;
|
2017-02-26 19:52:45 +08:00
|
|
|
Ui::FileTransferWidget* ui;
|
2018-09-25 11:08:30 +08:00
|
|
|
ToxFileProgress fileProgress;
|
2014-11-17 03:01:37 +08:00
|
|
|
ToxFile fileInfo;
|
2015-02-13 23:46:59 +08:00
|
|
|
QVariantAnimation* backgroundColorAnimation = nullptr;
|
2015-02-14 19:14:09 +08:00
|
|
|
QVariantAnimation* buttonColorAnimation = nullptr;
|
2015-02-13 23:46:59 +08:00
|
|
|
QColor backgroundColor;
|
|
|
|
QColor buttonColor;
|
2017-02-28 20:29:51 +08:00
|
|
|
QColor buttonBackgroundColor;
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2016-07-30 21:14:18 +08:00
|
|
|
bool active;
|
2018-09-25 11:08:30 +08:00
|
|
|
ToxFile::FileStatus lastStatus = ToxFile::INITIALIZING;
|
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
};
|