-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial draft of separate cli application * reorganize main.cpp in cli a bit, towards real commands parser impl (still wip) * parsing command line arguments in new CLI * console obj with quiet logic extracted; config checking in CLI implemented * move QNapi class to libqnapi; implementing subtitles downloading in CLI (wip) * more informative error formatting * ported CLI functionality to a separated binary * updating translations for new CLI (wip) * improving translation * err codes as constants, not magic numbers; more rational downloading loop break * qmake option to disable building cli/gui targets * install mediainfo (to be present in pkgconfig) for macx cli build * hide ssl warnings from printing to console * fix asking for input in quiet mode * win32 deploy commands supporting both qnapic.exe/qnapi.exe * updated input for doxygen doc (added cli sources) * install pkgconfig for brew * add no_cli/no_gui note to README.md * not install pkgconfig for brew (seems to be already present) * fix pkgconfig issue on macx * get rid of cat * further refactoring * implementing gui command parser (wip), improving cli command parser * abstractios CliArgParser/CliArgParsersExecutor prototyped * QNapiCommand + ShowHelpArgParser * ShowHelpLanguages arg parser * QuietBatch arg parser * ShowList / DontShowList arg parsers * fixed parsers executor * lang arg parser * backup lang arg parser * format arg parser * extension arg parser * download subtitles arg parser * bug fixes in arg parsers * replace old cli arg parsers with new design in CLI * show options args parser, run cli app args parser * use parsers in GUI; wip * scan directory arg parser * improved error message about CLI binary not found * removed QNapiCli from gui app * replace close button & manual alignment with dialog button box (frmAbout) * Console extracted to libqnapi / utils * formatting arg switches help based on cli arg data (wip, cleanup needed) * renaming * removed obsolete CLI help text * translations updated * fixed tr functions to show valid help text translations * display gui help in dialog * show gui help about -c, small code cleanup * code cleanup * extracting help text producing logic to libqnapi * translations updated * init napisy24SubMenu in constructor * memory release * removed qt@5.7 on osx * fix .travis.yml formatting * added NsProcess.zip binary * add qt 5.9 and 5.10.0 on appveyor * add help languages msgbox with translation * use Qt 5.6.3 instead of 5.6.2 on Travis * add linux qt 5.10.1 build on travis * 10.8 mac minimal version
- Loading branch information
Showing
78 changed files
with
3,483 additions
and
1,512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ debug | |
release | ||
Makefile* | ||
qnapi | ||
qnapic | ||
*.a | ||
win32/out/* | ||
win32/*.exe | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
TEMPLATE = app | ||
|
||
CONFIG += warn_on qt resources silent c++11 console | ||
|
||
QT += core network xml | ||
QT -= gui | ||
|
||
SOURCES += src/main.cpp \ | ||
src/clisubtitlesdownloader.cpp \ | ||
src/climain.cpp | ||
|
||
HEADERS += \ | ||
src/clisubtitlesdownloader.h \ | ||
src/climain.h | ||
|
||
RESOURCES += res/resources.qrc | ||
|
||
MOC_DIR = tmp | ||
RCC_DIR = tmp | ||
OBJECTS_DIR = tmp | ||
INCLUDEPATH = src | ||
|
||
include(../libqnapi/libqnapi.pri) | ||
|
||
unix { | ||
TARGET = qnapic | ||
DESTDIR = ../ | ||
CONFIG += link_pkgconfig | ||
PKGCONFIG += libmediainfo | ||
} | ||
|
||
macx { | ||
QT_CONFIG -= no-pkg-config | ||
CONFIG -= app_bundle | ||
LIBS += -framework CoreFoundation | ||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8 | ||
QMAKE_CXXFLAGS_X86_64 = -mmacosx-version-min=10.8 | ||
} | ||
|
||
win32 { | ||
CONFIG += nostrip | ||
RC_FILE = ../win32/qnapi.rc | ||
TARGET = qnapic | ||
target.path = ../win32/out | ||
INSTALLS += target | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<RCC> | ||
<qresource prefix="/translations"> | ||
<file alias="qnapi_it.qm">../../translations/qnapi_it.qm</file> | ||
<file alias="qnapi_pl.qm">../../translations/qnapi_pl.qm</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/***************************************************************************** | ||
** QNapi | ||
** Copyright (C) 2008-2017 Piotr Krzemiński <pio.krzeminski@gmail.com> | ||
** | ||
** 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 file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
** | ||
*****************************************************************************/ | ||
|
||
#include "climain.h" | ||
#include "clisubtitlesdownloader.h" | ||
#include "libqnapi.h" | ||
#include "qnapicommand.h" | ||
#include "subtitlelanguage.h" | ||
#include "utils/helphelper.h" | ||
|
||
#include <signal.h> | ||
#include <QDir> | ||
#include <QTranslator> | ||
#include <iostream> | ||
|
||
namespace CliMain { | ||
|
||
void installTranslation(QCoreApplication &app, QTranslator *translator, | ||
const QNapiConfig &config) { | ||
QString uiLanguage = LibQNapi::uiLanguage(config.generalConfig()); | ||
translator->load("qnapi_" + uiLanguage, ":/translations"); | ||
app.installTranslator(translator); | ||
} | ||
|
||
void printHeader(const Console &c) { | ||
c.printLine(tr("QNapi %1 (Qt version %2), %3") | ||
.arg(LibQNapi::displayableVersion()) | ||
.arg(qVersion()) | ||
.arg(LibQNapi::webpageUrl())); | ||
c.printLine(); | ||
} | ||
|
||
void printHelp(const Console &c, | ||
const QList<QSharedPointer<CliArgParser>> &cliArgParsers) { | ||
auto helpLines = HelpHelper::formatHelpLinesText(cliArgParsers); | ||
foreach (auto helpLine, helpLines) { c.printLine(helpLine); } | ||
} | ||
|
||
void printHelpLanguages(const Console &c, const QNapiConfig &config) { | ||
c.printLine( | ||
tr("List of languages recognized by QNapi, including corresponding")); | ||
c.printLine(tr("two-letter language codes:")); | ||
c.printLine(); | ||
|
||
SubtitleLanguage L, LB; | ||
QStringList langs = L.listLanguages(); | ||
|
||
foreach (QString lang, langs) { | ||
L.setLanguage(lang); | ||
c.printLine(QString(" %1 - %2").arg(L.toTwoLetter()).arg(lang)); | ||
} | ||
|
||
L.setLanguage(config.generalConfig().language()); | ||
LB.setLanguage(config.generalConfig().backupLanguage()); | ||
|
||
c.printLine(); | ||
c.printLine(tr("Current default subtitles language: %1 (%2)") | ||
.arg(L.toFullName()) | ||
.arg(L.toTwoLetter())); | ||
|
||
if (LB.toFullName().isEmpty()) { | ||
c.printLine(tr("No alternative subtitles language has been set")); | ||
} else { | ||
c.printLine(tr("Current alternative subtitles language: %1 (%2)") | ||
.arg(LB.toFullName()) | ||
.arg(LB.toTwoLetter())); | ||
} | ||
} | ||
|
||
int processCommand(QVariant cliCommand, const QNapiConfig &config, | ||
const QList<QSharedPointer<CliArgParser>> &cliArgParsers) { | ||
const Console c(config.generalConfig().quietBatch()); | ||
|
||
printHeader(c); | ||
|
||
using namespace QNapiCommand; | ||
if (cliCommand.canConvert<DownloadSubtitles>()) { | ||
QStringList movieFilePaths = | ||
cliCommand.value<DownloadSubtitles>().movieFilePaths; | ||
return CliSubtitlesDownloader::downloadSubtitlesFor(c, movieFilePaths, | ||
config); | ||
} else if (cliCommand.canConvert<ShowHelpLanguages>()) { | ||
printHelpLanguages(c, config); | ||
return 0; | ||
} else { | ||
printHelp(c, cliArgParsers); | ||
return 0; | ||
} | ||
} | ||
|
||
void sigHandler(int sig) { | ||
Q_UNUSED(sig); | ||
|
||
std::cout << std::endl | ||
<< tr("QNapi: deleting temporary files...").toStdString() | ||
<< std::endl; | ||
|
||
const QNapiConfig config = LibQNapi::loadConfig(); | ||
QString tmpPath = config.generalConfig().tmpPath(); | ||
QDir tmpDir(tmpPath); | ||
|
||
QStringList filters; | ||
filters << "QNapi-*-rc"; | ||
filters << "QNapi.*.tmp"; | ||
|
||
QFileInfoList files = tmpDir.entryInfoList(filters); | ||
|
||
foreach (QFileInfo file, files) { QFile::remove(file.filePath()); } | ||
|
||
std::cout << tr("QNapi: finished.").toStdString() << std::endl; | ||
|
||
exit(666); | ||
} | ||
|
||
void regSignal() { | ||
#ifdef Q_OS_WIN | ||
signal(SIGTERM, sigHandler); | ||
signal(SIGINT, sigHandler); | ||
#else | ||
struct sigaction sa; | ||
memset(&sa, 0, sizeof(struct sigaction)); | ||
sigemptyset(&sa.sa_mask); | ||
sa.sa_handler = sigHandler; | ||
sigaction(SIGTERM, &sa, 0); | ||
sigaction(SIGINT, &sa, 0); | ||
#endif | ||
} | ||
|
||
} // namespace CliMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/***************************************************************************** | ||
** QNapi | ||
** Copyright (C) 2008-2017 Piotr Krzemiński <pio.krzeminski@gmail.com> | ||
** | ||
** 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 file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
** | ||
*****************************************************************************/ | ||
|
||
#ifndef CLIMAIN_H | ||
#define CLIMAIN_H | ||
|
||
#include "config/qnapiconfig.h" | ||
#include "parser/cliargparser.h" | ||
#include "parser/cliargparsersexecutor.h" | ||
#include "tr.h" | ||
#include "utils/console.h" | ||
|
||
namespace CliMain { | ||
|
||
Q_DECLARE_NAMESPACE_TR(CliMain) | ||
|
||
void installTranslation(QCoreApplication &app, QTranslator *translator, | ||
const QNapiConfig &config); | ||
void printHeader(const Console &c); | ||
void printHelp(const Console &c, | ||
const QList<QSharedPointer<CliArgParser>> &cliArgParsers); | ||
void printHelpLanguages(const Console &c, const QNapiConfig &config); | ||
int processCommand(QVariant cliCommand, const QNapiConfig &config, | ||
const QList<QSharedPointer<CliArgParser>> &cliArgParsers); | ||
void sigHandler(int sig); | ||
void regSignal(); | ||
|
||
} // namespace CliMain | ||
|
||
#endif // CLIMAIN_H |
Oops, something went wrong.