From ccc61842348d38003af0ad391aebaa106e18a139 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 8 Mar 2018 17:01:01 +0100 Subject: [PATCH] feat(file): add a FileExtractor component (in progress) --- CMakeLists.txt | 4 +- src/components/file/FileExtractor.cpp | 112 ++++++++++++++++++++++++++ src/components/file/FileExtractor.hpp | 81 +++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 src/components/file/FileExtractor.cpp create mode 100644 src/components/file/FileExtractor.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d41b5742a..c01c30e32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,7 @@ set(SOURCES src/components/core/CoreHandlers.cpp src/components/core/CoreManager.cpp src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.cpp + src/components/file/FileExtractor.cpp src/components/notifier/Notifier.cpp src/components/other/clipboard/Clipboard.cpp src/components/other/colors/Colors.cpp @@ -201,6 +202,7 @@ set(HEADERS src/components/core/CoreHandlers.hpp src/components/core/CoreManager.hpp src/components/core/messages-count-notifier/AbstractMessagesCountNotifier.hpp + src/components/file/FileExtractor.hpp src/components/notifier/Notifier.hpp src/components/other/clipboard/Clipboard.hpp src/components/other/colors/Colors.hpp @@ -218,8 +220,8 @@ set(HEADERS src/components/timeline/TimelineModel.hpp src/components/url-handlers/UrlHandlers.hpp src/utils/LinphoneUtils.hpp - src/utils/Utils.hpp src/utils/QExifImageHeader.h + src/utils/Utils.hpp ) set(TESTS diff --git a/src/components/file/FileExtractor.cpp b/src/components/file/FileExtractor.cpp new file mode 100644 index 000000000..38f3fe906 --- /dev/null +++ b/src/components/file/FileExtractor.cpp @@ -0,0 +1,112 @@ +/* + * FileExtractor.cpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * This program is free 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 2 + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: March 8, 2018 + * Author: Ronan Abhamon + */ + +#include +#include + +#include "FileExtractor.hpp" + +// ============================================================================= + +void FileExtractor::extract () { + // TODO. +} + +QString FileExtractor::getFile () const { + return mFile; +} + +void FileExtractor::setFile (const QString &file) { + if (mExtracting) { + qWarning() << QStringLiteral("Unable to set file, a file is extracting."); + return; + } + + if (mFile != file) { + mFile = file; + emit fileChanged(mFile); + } +} + +QString FileExtractor::getExtractFolder () const { + return mExtractFolder; +} + +void FileExtractor::setExtractFolder (const QString &extractFolder) { + if (mExtracting) { + qWarning() << QStringLiteral("Unable to set extract folder, a file is extracting."); + return; + } + + if (mExtractFolder != extractFolder) { + mExtractFolder = extractFolder; + emit extractFolderChanged(mExtractFolder); + } +} + +qint64 FileExtractor::getReadBytes () const { + return mReadBytes; +} + +void FileExtractor::setReadBytes (qint64 readBytes) { + if (mReadBytes != readBytes) { + mReadBytes = readBytes; + emit readBytesChanged(readBytes); + } +} + +qint64 FileExtractor::getTotalBytes () const { + return mTotalBytes; +} + +void FileExtractor::setTotalBytes (qint64 totalBytes) { + if (mTotalBytes != totalBytes) { + mTotalBytes = totalBytes; + emit totalBytesChanged(totalBytes); + } +} + +bool FileExtractor::getExtracting () const { + return mExtracting; +} + +void FileExtractor::setExtracting (bool extracting) { + if (mExtracting != extracting) { + mExtracting = extracting; + emit extractingChanged(extracting); + } +} + +void FileExtractor::handleReadyData () { + // TODO. +} + +void FileExtractor::handleExtractFinished () { + // TODO. + +} + +void FileExtractor::handleExtractProgress (qint64 readBytes, qint64 totalBytes) { + // TODO. + Q_UNUSED(readBytes); + Q_UNUSED(totalBytes); +} diff --git a/src/components/file/FileExtractor.hpp b/src/components/file/FileExtractor.hpp new file mode 100644 index 000000000..d7b530425 --- /dev/null +++ b/src/components/file/FileExtractor.hpp @@ -0,0 +1,81 @@ +/* + * FileExtractor.hpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * This program is free 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 2 + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: March 8, 2018 + * Author: Ronan Abhamon + */ + +#ifndef FILE_EXTRACTOR_H_ +#define FILE_EXTRACTOR_H_ + +#include + +// ============================================================================= + +class FileExtractor : public QObject { + Q_OBJECT; + + Q_PROPERTY(QString file READ getFile WRITE setFile NOTIFY fileChanged); + Q_PROPERTY(QString extractFolder READ getExtractFolder WRITE setExtractFolder NOTIFY extractFolderChanged); + Q_PROPERTY(qint64 readBytes READ getReadBytes NOTIFY readBytesChanged); + Q_PROPERTY(qint64 totalBytes READ getTotalBytes NOTIFY totalBytesChanged); + Q_PROPERTY(bool extracting READ getExtracting NOTIFY extractingChanged); + +public: + Q_INVOKABLE void extract (); + +signals: + void fileChanged (const QString &file); + void extractFolderChanged (const QString &extractFolder); + void readBytesChanged (qint64 readBytes); + void totalBytesChanged (qint64 totalBytes); + void extractingChanged (bool extracting); + void extractFinished (); + void extractFailed(); + +private: + QString getFile () const; + void setFile (const QString &file); + + QString getExtractFolder () const; + void setExtractFolder (const QString &extractFolder); + + qint64 getReadBytes () const; + void setReadBytes (qint64 readBytes); + + qint64 getTotalBytes () const; + void setTotalBytes (qint64 totalBytes); + + bool getExtracting () const; + void setExtracting (bool extracting); + + void handleReadyData (); + void handleExtractFinished (); + + void handleExtractProgress (qint64 readBytes, qint64 totalBytes); + + QString mFile; + QString mExtractFolder; + QFile mDestinationFile; + + qint64 mReadBytes = 0; + qint64 mTotalBytes = 0; + bool mExtracting = false; +}; + +#endif // FILE_EXTRACTOR_H_