1 /***************************************************************************** 2 ** QNapi 3 ** Copyright (C) 2008-2017 Piotr Krzemiński <pio.krzeminski@gmail.com> 4 ** 5 ** This program is free software; you can redistribute it and/or modify 6 ** it under the terms of the GNU General Public License as published by 7 ** the Free Software Foundation; either version 2 of the License, or 8 ** (at your option) any later version. 9 ** 10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12 ** 13 *****************************************************************************/ 14 15 #ifndef __FRMPROGRESS__H__ 16 #define __FRMPROGRESS__H__ 17 18 #include <QMutex> 19 20 #include "ui_frmprogress.h" 21 22 #include "frmsummary.h" 23 24 #include "config/qnapiconfig.h" 25 26 #include <Maybe.h> 27 #include "frmlistsubtitles.h" 28 #include "qnapi.h" 29 #include "qnapiopendialog.h" 30 #include "qnapithread.h" 31 #include "subtitleinfo.h" 32 33 class GetThread : public QNapiThread { 34 Q_OBJECT 35 36 public: 37 GetThread(); 38 39 signals: 40 void fileNameChange(const QString &newfileName); 41 void actionChange(const QString &newAction); 42 void progressChange(int current, int all, float stageProgress); 43 void criticalError(const QString &message); 44 void selectSubtitles(QString fileName, SubtitleInfoList subtitles); 45 46 private slots: setCriticalMessage(const QString & msg)47 void setCriticalMessage(const QString &msg) { criticalMessage = msg; } 48 void subtitlesSelected(int idx); 49 50 public: setSpecificEngine(Maybe<QString> engine)51 void setSpecificEngine(Maybe<QString> engine) { specificEngine = engine; } 52 setLanguages(QString language,QString languageBackup,bool languageBackupPassed)53 void setLanguages(QString language, QString languageBackup, 54 bool languageBackupPassed) { 55 lang = language; 56 langBackup = languageBackup; 57 langBackupPassed = languageBackupPassed; 58 } setConfig(const QNapiConfig & configuration)59 void setConfig(const QNapiConfig &configuration) { config = configuration; } 60 61 void run(); 62 63 QStringList queue; 64 Maybe<QString> specificEngine; 65 QList<SubtitleInfo> subStatusList; 66 QString lang, langBackup; 67 bool langBackupPassed; 68 int napiSuccess, napiFail; 69 QString criticalMessage; 70 QMutex waitForDlg; 71 int selIdx; 72 QNapiConfig config; 73 }; 74 75 class frmProgress : public QWidget { 76 Q_OBJECT 77 78 public: 79 frmProgress(QWidget *parent = 0, Qt::WindowFlags f = 0); 80 clearSpecificEngine()81 void clearSpecificEngine() { getThread.setSpecificEngine(nothing()); } setSpecificEngine(QString engine)82 void setSpecificEngine(QString engine) { 83 getThread.setSpecificEngine(just(engine)); 84 } 85 setBatchMode(bool value)86 void setBatchMode(bool value) { batchMode = value; } setBatchLanguages(QString lang,QString langBackup,bool langBackupPassed)87 void setBatchLanguages(QString lang, QString langBackup, 88 bool langBackupPassed) { 89 getThread.setLanguages(lang, langBackup, langBackupPassed); 90 } setTargetFormatOverride(QString value)91 void setTargetFormatOverride(QString value) { targetFormatOverride = value; } setTargetExtOverride(QString value)92 void setTargetExtOverride(QString value) { targetExtOverride = value; } isBatchMode()93 bool isBatchMode() { return batchMode; } 94 95 signals: 96 void subtitlesSelected(int idx); 97 98 public slots: 99 void receiveRequest(const QString &request); 100 void enqueueFile(const QString &file); 101 void enqueueFiles(const QStringList &fileList); 102 bool download(); 103 void updateProgress(int current, int all, float stageProgress); 104 void selectSubtitles(QString fileName, SubtitleInfoList subtitles); 105 void downloadFinished(); 106 107 private: 108 void closeEvent(QCloseEvent *event); 109 void dragEnterEvent(QDragEnterEvent *event); 110 void dropEvent(QDropEvent *event); 111 112 Ui::frmProgress ui; 113 GetThread getThread; 114 frmListSubtitles frmSelect; 115 frmSummary summary; 116 QString targetFormatOverride, targetExtOverride; 117 118 bool batchMode, showSummary, closeRequested; 119 QMutex mutex; 120 }; 121 122 #endif 123