| 1 | /***************************************************************************** |
| 2 | ** QNapi |
| 3 | ** Copyright (C) 2008-2017 Piotr KrzemiĆski <[email protected]> |
| 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 | #include <signal.h> |
| 16 | #include <QApplication> |
| 17 | #include <QFileInfo> |
| 18 | #include <QLibraryInfo> |
| 19 | #include <QMessageBox> |
| 20 | #include <QStringList> |
| 21 | #include <QSystemTrayIcon> |
| 22 | #include <QTextCodec> |
| 23 | #include <QTranslator> |
| 24 | #include "libqnapi.h"cxx . . $ `<file>/libqnapi/src/libqnapi.h`/ |
| 25 | #include "qnapiapp.h"cxx . . $ `<file>/gui/src/qnapiapp.h`/ |
| 26 | #include "qnapicli.h"cxx . . $ `<file>/gui/src/qnapicli.h`/ |
| 27 | |
| 28 | QStringListcxx . . $ QStringList# parseArgscxx . . $ parseArgs(e0e66eb8c380161e).(int argc, char **argv); |
| 29 | void regSignalcxx . . $ regSignal(49f6e7a06ebc5aa8).(); |
| 30 | void sigHandlercxx . . $ sigHandler(d4f767463ce0a6b3).(int); |
| 31 | |
| 32 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) { |
| 33 | LibQNapicxx . . $ LibQNapi#::initcxx . . $ LibQNapi#init(3520e46b33348bf6).(argvcxx . . $ QString#QString(85c52e162fed56f9).[0]); |
| 34 | |
| 35 | const QNapiConfigcxx . . $ QNapiConfig# config = LibQNapicxx . . $ LibQNapi#::loadConfigcxx . . $ LibQNapi#loadConfig(915c3b8a74517b7e).(); |
| 36 | |
| 37 | QStringcxx . . $ QString# uiLanguage = LibQNapicxx . . $ QString#QString(e1217c004a86c950).::uiLanguagecxx . . $ LibQNapi#uiLanguage(1f1a043c4222eea4).(config.generalConfigcxx . . $ QNapiConfig#generalConfig(e033123d5cc30136).()); |
| 38 | |
| 39 | bool isCliCall = QNapiClicxx . . $ QNapiCli#::isCliCallcxx . . $ QNapiCli#isCliCall(999dbd1e14140801).(argc, argv); |
| 40 | |
| 41 | QStringListcxx . . $ QStringList# parsedFilePaths = parseArgscxx . . $ parseArgs(e0e66eb8c380161e).(argc, argv); |
| 42 | |
| 43 | regSignalcxx . . $ regSignal(49f6e7a06ebc5aa8).(); |
| 44 | |
| 45 | bool quietBatch = config.generalConfigcxx . . $ QNapiConfig#generalConfig(e033123d5cc30136).().quietBatchcxx . . $ GeneralConfig#quietBatch(50ce9a9e25b4a850).(); |
| 46 | #ifdef Q_OS_MAC |
| 47 | quietBatch = false; |
| 48 | #endif |
| 49 | |
| 50 | bool useGui = !isCliCall && !(quietBatch && !parsedFilePaths.isEmptycxx . . $ QList#isEmpty(50ce9a9e25b4a850).()); |
| 51 | |
| 52 | if (useGui) { |
| 53 | QNapiAppcxx . . $ QNapiApp# appcxx . . $ QNapiApp#QNapiApp(75dd2bf67067255f).(argc, argv, true, "QNapi"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 54 | |
| 55 | QStringcxx . . $ QString# resourceDir = |
| 56 | QLibraryInfocxx . . $ QString#QString(e1217c004a86c950).::locationcxx . . $ QLibraryInfo#location(dd7ac78f10b8a525).(QLibraryInfocxx . . $ QLibraryInfo#::TranslationsPathcxx . . $ QLibraryInfo#TranslationsPath.); |
| 57 | |
| 58 | QTranslatorcxx . . $ QTranslator# qtTranslatorcxx . . $ QTranslator#QTranslator(749de1b6ae65bddd)., qnapiTranslatorcxx . . $ QTranslator#QTranslator(749de1b6ae65bddd).; |
| 59 | qtTranslator.loadcxx . . $ QTranslator#load(142924642d8b819d).("qt_" +cxx . . $ operator+(c75c3ae4eb9af1a8). uiLanguage, resourceDir); |
| 60 | app.installTranslatorcxx . . $ QCoreApplication#installTranslator(d376406de50edad7).(&qtTranslator); |
| 61 | |
| 62 | qnapiTranslator.loadcxx . . $ QTranslator#load(142924642d8b819d).("qnapi_" +cxx . . $ operator+(c75c3ae4eb9af1a8). uiLanguage, ":/translations"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 63 | app.installTranslatorcxx . . $ QCoreApplication#installTranslator(d376406de50edad7).(&qnapiTranslator); |
| 64 | |
| 65 | app.setQuitOnLastWindowClosedcxx . . $ QGuiApplication#setQuitOnLastWindowClosed(b45ddcbc8423892c).(false); |
| 66 | |
| 67 | if (app.argumentscxx . . $ QCoreApplication#arguments(669a05bc42dd57cc).().containscxx . . $ QStringList#contains(8cce4688c16f48f3).("-o"cxx . . $ QString#QString(85c52e162fed56f9).) || |
| 68 | app.argumentscxx . . $ QCoreApplication#arguments(669a05bc42dd57cc).().containscxx . . $ QStringList#contains(8cce4688c16f48f3).("--options"cxx . . $ QString#QString(85c52e162fed56f9).)) { |
| 69 | app.setQuitOnLastWindowClosedcxx . . $ QGuiApplication#setQuitOnLastWindowClosed(b45ddcbc8423892c).(true); |
| 70 | app.showSettingscxx . . $ QNapiApp#showSettings(49f6e7a06ebc5aa8).(); |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | if (!app.isInstanceAllowedcxx . . $ QSingleApplication#isInstanceAllowed(50ce9a9e25b4a850).()) { |
| 75 | for (int i = 0; i < parsedFilePaths.sizecxx . . $ QList#size(455f465bc33b4cdf).(); i++) { |
| 76 | QStringcxx . . $ QString# &fileName = parsedFilePaths[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i]; |
| 77 | QFileInfocxx . . $ QFileInfo# ficxx . . $ QFileInfo#QFileInfo(3520e46b33348bf6).(fileName); |
| 78 | app.sendRequestcxx . . $ QSingleApplication#sendRequest(3520e46b33348bf6).(fi.absoluteFilePathcxx . . $ QFileInfo#absoluteFilePath(6ef7b6c27b00b43d).()); |
| 79 | } |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | if (config.firstruncxx . . $ QNapiConfig#firstrun(50ce9a9e25b4a850).()) { |
| 84 | if (QMessageBoxcxx . . $ QMessageBox#::questioncxx . . $ QMessageBox#question(a9e3742e6f7b4147).(0, QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("First Run"), |
| 85 | QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("This is the first launch of the " |
| 86 | "program QNapi. Do you want to " |
| 87 | "configure it now?"), |
| 88 | QMessageBoxcxx . . $ QMessageBox#::Yescxx . . $ QMessageBox#Yes. |cxx . . $ `operator|`(9741a579ef5e058f). QMessageBoxcxx . . $ QMessageBox#::Nocxx . . $ QMessageBox#No.) == |
| 89 | QMessageBoxcxx . . $ QMessageBox#::Yescxx . . $ QMessageBox#Yes.) { |
| 90 | app.showSettingscxx . . $ QNapiApp#showSettings(49f6e7a06ebc5aa8).(); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Jesli podano parametry, ustawiamy tzw. batch mode |
| 95 | if (parsedFilePaths.sizecxx . . $ QList#size(455f465bc33b4cdf).() > 0) { |
| 96 | app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->setBatchModecxx . . $ frmProgress#setBatchMode(b45ddcbc8423892c).(true); |
| 97 | |
| 98 | QStringcxx . . $ QString# pcxx . . $ QString#QString(49f6e7a06ebc5aa8)., batchLangcxx . . $ QString#QString(49f6e7a06ebc5aa8)., batchLangBackupcxx . . $ QString#QString(49f6e7a06ebc5aa8).; |
| 99 | bool invalidLang = false, batchLangBackupPassed = false; |
| 100 | |
| 101 | for (int i = 1; i < argc; i++) { |
| 102 | p =cxx . . $ QString#`operator=`(d02845eef0c33901). argv[i]; |
| 103 | |
| 104 | if ((p ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "-l") || (p ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "--lang")) { |
| 105 | ++i; |
| 106 | if (i < argc) { |
| 107 | batchLang =cxx . . $ QString#`operator=`(7b76e6691bca1027). SubtitleLanguagecxx . . $ SubtitleLanguage#(argvcxx . . $ QString#QString(e1217c004a86c950).[i]).toTwoLettercxx . . $ SubtitleLanguage#toTwoLetter(4365c3963150523e).(); |
| 108 | if (batchLang.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) { |
| 109 | invalidLang = true; |
| 110 | } |
| 111 | } else { |
| 112 | invalidLang = true; |
| 113 | } |
| 114 | } else if ((p ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "-lb") || (p ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "--lang-backup")) { |
| 115 | ++i; |
| 116 | if (i < argc) { |
| 117 | batchLangBackup =cxx . . $ QString#`operator=`(7b76e6691bca1027). SubtitleLanguagecxx . . $ SubtitleLanguage#(argvcxx . . $ QString#QString(e1217c004a86c950).[i]).toTwoLettercxx . . $ SubtitleLanguage#toTwoLetter(4365c3963150523e).(); |
| 118 | batchLangBackupPassed = true; |
| 119 | } |
| 120 | break; |
| 121 | } else if ((p ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "--format") || (p ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "-f")) { |
| 122 | ++i; |
| 123 | if (i < argc) { |
| 124 | if (!LibQNapicxx . . $ LibQNapi#::subtitleFormatsRegistrycxx . . $ LibQNapi#subtitleFormatsRegistry(973e1e8926cdb00d).() |
| 125 | ->cxx . . $ QSharedPointer#`operator->`(5a2a78a048fb49a8).selectcxx . . $ SubtitleFormatsRegistry#select(849396506c5f6260).(argvcxx . . $ QString#QString(85c52e162fed56f9).[i]) |
| 126 | .isNullcxx . . $ QSharedPointer#isNull(50ce9a9e25b4a850).()) { |
| 127 | app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->setTargetFormatOverridecxx . . $ frmProgress#setTargetFormatOverride(7df51288a9ebd664).(argvcxx . . $ QString#QString(e1217c004a86c950).[i]); |
| 128 | } |
| 129 | } |
| 130 | } else if ((p ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "--extension") || (p ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "-e")) { |
| 131 | ++i; |
| 132 | if (i < argc) { |
| 133 | app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->setTargetExtOverridecxx . . $ frmProgress#setTargetExtOverride(7df51288a9ebd664).(argvcxx . . $ QString#QString(e1217c004a86c950).[i]); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if (invalidLang) { |
| 139 | if (QMessageBoxcxx . . $ QMessageBox#::questioncxx . . $ QMessageBox#question(a9e3742e6f7b4147).(0, "QNapi"cxx . . $ QString#QString(85c52e162fed56f9)., |
| 140 | "Invalid language code!\n"cxx . . $ QString#QString(85c52e162fed56f9). |
| 141 | "Do you want to download the subtitles in " |
| 142 | "the default language?", |
| 143 | QMessageBoxcxx . . $ QMessageBox#::Yescxx . . $ QMessageBox#Yes. |cxx . . $ `operator|`(9741a579ef5e058f). QMessageBoxcxx . . $ QMessageBox#::Nocxx . . $ QMessageBox#No.) != |
| 144 | QMessageBoxcxx . . $ QMessageBox#::Yescxx . . $ QMessageBox#Yes.) { |
| 145 | return 0; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->setBatchLanguagescxx . . $ frmProgress#setBatchLanguages(1262106ee45454b8).(batchLangcxx . . $ QString#QString(3520e46b33348bf6)., batchLangBackupcxx . . $ QString#QString(3520e46b33348bf6)., |
| 150 | batchLangBackupPassed); |
| 151 | |
| 152 | if (QFileInfocxx . . $ QFileInfo#(parsedFilePaths.atcxx . . $ QList#at(e2681f9bb6b2f357).(0)).isDircxx . . $ QFileInfo#isDir(50ce9a9e25b4a850).()) { |
| 153 | if (!app.showScanDialogcxx . . $ QNapiApp#showScanDialog(7dc6c9a0b6a7270f).(parsedFilePathscxx . . $ QString#QString(3520e46b33348bf6)..atcxx . . $ QList#at(e2681f9bb6b2f357).(0))) return 1; |
| 154 | } else { |
| 155 | app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->enqueueFilescxx . . $ frmProgress#enqueueFiles(631c0101495f0328).(parsedFilePaths); |
| 156 | if (!app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->downloadcxx . . $ frmProgress#download(c9857a73d68e59ba).()) return 1; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // Jesli nie dzialamy w trybie pobierania, mozemy ew. utworzyc ikone w |
| 161 | // tray-u badz pokazac okno wyboru plikow z filmami |
| 162 | if (!app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->isBatchModecxx . . $ frmProgress#isBatchMode(c9857a73d68e59ba).()) { |
| 163 | // Jesli nie ma traya, od razu wyswietlamy okienko z wyborem pliku |
| 164 | if (!QSystemTrayIconcxx . . $ QSystemTrayIcon#::isSystemTrayAvailablecxx . . $ QSystemTrayIcon#isSystemTrayAvailable(c9857a73d68e59ba).()) { |
| 165 | if (!app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->isBatchModecxx . . $ frmProgress#isBatchMode(c9857a73d68e59ba).()) { |
| 166 | app.progresscxx . . $ QNapiApp#progress(cdabfe46e21630f8).()->setBatchModecxx . . $ frmProgress#setBatchMode(b45ddcbc8423892c).(true); |
| 167 | if (!app.showOpenDialogcxx . . $ QNapiApp#showOpenDialog(7dc6c9a0b6a7270f).()) return 1; |
| 168 | } |
| 169 | } else // Jesli ikona w tray-u jest obsligiwana, tworzymy ja |
| 170 | { |
| 171 | app.createTrayIconcxx . . $ QNapiApp#createTrayIcon(49f6e7a06ebc5aa8).(); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return app.execcxx . . $ QSingleApplication#exec(b126dc7c1de90089).(); |
| 176 | } else { |
| 177 | QNapiClicxx . . $ QNapiCli# appcxx . . $ QNapiCli#QNapiCli(d3c44a1e90630249).(argc, argv, config, uiLanguage); |
| 178 | return app.execcxx . . $ QNapiCli#exec(b126dc7c1de90089).(); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | QStringListcxx . . $ QStringList# parseArgscxx . . $ parseArgs(e0e66eb8c380161e).(int argc, char **argv) { |
| 183 | QStringListcxx . . $ QStringList# parsedFilePathscxx . . $ QStringList#QStringList(49f6e7a06ebc5aa8).; |
| 184 | |
| 185 | for (int i = 1; i < argc; i++) { |
| 186 | #ifdef Q_OS_WIN |
| 187 | QString p = QString::fromLocal8Bit(argv[i]); |
| 188 | #else |
| 189 | QStringcxx . . $ QString# pcxx . . $ QString#QString(e1217c004a86c950). = argvcxx . . $ QString#QString(85c52e162fed56f9).[i]; |
| 190 | #endif |
| 191 | if (p.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("file://"cxx . . $ QString#QString(85c52e162fed56f9).)) p =cxx . . $ QString#`operator=`(6a89d0b7f4d2681c). p.removecxx . . $ QString#remove(6483560ce2afa901).(0, 7); |
| 192 | |
| 193 | if ((parsedFilePaths.sizecxx . . $ QList#size(455f465bc33b4cdf).() == 0) && QFileInfocxx . . $ QFileInfo#(p).isDircxx . . $ QFileInfo#isDir(50ce9a9e25b4a850).()) { |
| 194 | parsedFilePaths <<cxx . . $ QStringList#`operator<<`(85116071a693d053). p; |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | if (QFileInfocxx . . $ QFileInfo#(p).isFilecxx . . $ QFileInfo#isFile(50ce9a9e25b4a850).()) parsedFilePaths <<cxx . . $ QStringList#`operator<<`(85116071a693d053). p; |
| 199 | } |
| 200 | return parsedFilePaths; |
| 201 | } |
| 202 | |
| 203 | void regSignalcxx . . $ regSignal(49f6e7a06ebc5aa8).() { |
| 204 | #ifdef Q_OS_WIN |
| 205 | signal(SIGTERM, sigHandler); |
| 206 | signal(SIGINT, sigHandler); |
| 207 | #else |
| 208 | struct sigaction sa; |
| 209 | memset(&sa, 0, sizeof(struct sigaction)); |
| 210 | sigemptyset(&sa.sa_mask); |
| 211 | sa.sa_handlercxx . . $ `<external>/16635209305659446502/sigaction.h:39:10`! = sigHandlercxx . . $ sigHandler(d4f767463ce0a6b3).; |
| 212 | sigaction(SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!, &sa, 0); |
| 213 | sigaction(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, &sa, 0); |
| 214 | #endif |
| 215 | } |
| 216 | |
| 217 | void sigHandlercxx . . $ sigHandler(d4f767463ce0a6b3).(int sig) { |
| 218 | Q_UNUSEDcxx . . $ `<external>/15045578679651060896/qglobal.h:117:9`!(sig); |
| 219 | |
| 220 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9). |
| 221 | <<cxx . . $ std/`operator<<`(88df5bef833f7f83). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("QNapi: deleting temporary files...").toStdStringcxx . . $ QString#toStdString(219584694fe2b248).() |
| 222 | <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 223 | |
| 224 | const QNapiConfigcxx . . $ QNapiConfig# config = LibQNapicxx . . $ LibQNapi#::loadConfigcxx . . $ LibQNapi#loadConfig(915c3b8a74517b7e).(); |
| 225 | QStringcxx . . $ QString# tmpPath = configcxx . . $ QString#QString(e1217c004a86c950)..generalConfigcxx . . $ QNapiConfig#generalConfig(e033123d5cc30136).().tmpPathcxx . . $ GeneralConfig#tmpPath(6ef7b6c27b00b43d).(); |
| 226 | QDircxx . . $ QDir# tmpDircxx . . $ QDir#QDir(3520e46b33348bf6).(tmpPath); |
| 227 | |
| 228 | QStringListcxx . . $ QStringList# filterscxx . . $ QStringList#QStringList(49f6e7a06ebc5aa8).; |
| 229 | filters <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "QNapi-*-rc"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 230 | filters <<cxx . . $ QStringList#`operator<<`(85116071a693d053). "QNapi.*.tmp"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 231 | |
| 232 | QFileInfoListcxx . . $ QFileInfoList# files = tmpDircxx . . $ QList#QList(b1a5d2b9a710f6d1)..entryInfoListcxx . . $ QDir#entryInfoList(c27c6007baf71ed0).(filters); |
| 233 | |
| 234 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (QFileInfo file, files) { QFilecxx . . $ QFile#::removecxx . . $ QFile#remove(e1defb592416720d).(file.filePathcxx . . $ QFileInfo#filePath(6ef7b6c27b00b43d).()); } |
| 235 | |
| 236 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). QObjectcxx . . $ QObject#::trcxx . . $ QObject#tr(75d9f1c324b4579d).("QNapi: finished.").toStdStringcxx . . $ QString#toStdString(219584694fe2b248).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 237 | |
| 238 | exit(666); |
| 239 | } |