File indexing completed on 2024-04-21 05:48:33

0001 /*
0002     SPDX-FileCopyrightText: 2016 ROSA
0003     SPDX-License-Identifier: GPL-3.0-or-later
0004 */
0005 
0006 #ifndef IMAGEWRITER_H
0007 #define IMAGEWRITER_H
0008 
0009 ////////////////////////////////////////////////////////////////////////////////
0010 // ImageWriter is a class for writing image file to the USB flash disk
0011 
0012 
0013 #include <QObject>
0014 #include <QMutex>
0015 
0016 #include "usbdevice.h"
0017 
0018 class ImageWriter : public QObject
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     explicit ImageWriter(const QString& ImageFile, UsbDevice* Device, QObject *parent = nullptr);
0024 
0025 protected:
0026     // Information about the selected USB flash disk
0027     UsbDevice* m_Device;
0028     // Source image file (full path); if empty, zero-filled buffer of 1 MB is used
0029     QString m_ImageFile;
0030     // Flag used for cancelling the operation by user
0031     bool m_CancelWriting;
0032     // Mutex for synchronizing access to m_CancelWriting member
0033     QMutex m_Mutex;
0034 
0035 signals:
0036     // Emitted when writeImage is finished for any reason
0037     void finished();
0038     // Emitted on successful completion
0039     void success(QString msg);
0040     // Emitted when something wrong happened, <msg> is the error message
0041     void error(QString msg);
0042     // Emitted when processed the cancel request from user
0043     void cancelled();
0044     // Emitted as the progress percentage changes
0045     void progressChanged(int percent);
0046 
0047 public slots:
0048     // The main method that writes the image
0049     void writeImage();
0050     // Implements reaction to the cancel request from user
0051     void cancelWriting();
0052 };
0053 
0054 #endif // IMAGEWRITER_H