/*
 * Copyright (C) 2002  KylinSoft Co., Ltd.
 *
 * 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.
 */
#ifndef PAGE2_H
#define PAGE2_H

#define DARKTHEME "dark"
#define LIGHTTHEME "light"

#include <QWidget>
#include <QDebug>
#include <QPushButton>
#include <QLabel>
#include <QMovie>
#include <QProcess>
#include <QBoxLayout>
#include <QString>
#include <QFileInfo>
#include <QStorageInfo>
#include <QTimer>
#include <QPaintEvent>
#include <QPainter>
#include <QDBusConnection>
#include <QLabel>
#include "include/menumodule.h"
#include "page1.h"
#include "QRoundProgressBar.h"

class Page2 : public QWidget
{
    Q_OBJECT
public:
    explicit Page2(QWidget *parent = nullptr);
    qint64 getFileSize(QString filePath); //获取文件大小，返回单位mb
    void setThemeStyleDark();
    void setThemeStyleLight();
    QString uDiskPath = ""; //U盘路径
    QString usbpath;
    QString isopath;
    Page1 * page1;
     QTimer *diskRefreshDelay;
    QRoundProgressBar *round;
    QLabel *m_progress;
    QPushButton *returnPushButton=nullptr; // 回page1的按钮
    QPushButton *cancelbtn=nullptr;
    menuModule *menu;

   void getUdiskPathAndCap();
   QJsonArray QStringToJsonArray(const QString jsonString);
   void getUdiskName();
   void getStorageInfo();
   void playLoadingGif();

signals:
   void makeStart(QString sourcePath,QString targetPath); //make start
    void diskLabelRefresh(); //  已选中U盘刷新
    void makeFinish();
    void returnMain();
    void swToPage2();//
    void mainclose();

public slots:
    void makestar(QString path,QString sourcepath);
    void startMaking();
    void finishEvent();
    void allclose();
    void setIconchange();
    void dealWorkingProgress(int);
    void dealerrorstr(QString);
    void dealMakeFinish(QString);
private:
    enum typeMovieStatus {
        loading = 0,
        finish = 1,
        failed = 2
        } movieStatus;   //枚举类型的动画进度
  //  void playLoadingGif();
    void playFinishGif();
    void playErrorGif();
    bool isMakingSuccess(); //进度到100%之后检查制作是否成功
    void movieRefresh(); //切换主题时重新加载动画
    bool mountDevice(QString);
    QString themeStatus = LIGHTTHEME;
    QMovie *movieLoading_l=nullptr; //过程动画，黑白两套
    QMovie *movieFinish_l=nullptr;
    QMovie *movieLoading_d=nullptr;
    QMovie *movieFinish_d=nullptr;
    QPixmap errLabel;
    QLabel *lableMovie=nullptr;
    QLabel *lableText=nullptr;
    QLabel *lableNum=nullptr;
    QProcess *command_dd;

    int frameCount=0;
    qint64 sourceFileSize = 0;
    QTimer *timer;
};

#endif // PAGE2_H
