mirror of
https://github.com/YACReader/yacreader
synced 2025-07-22 23:15:14 -04:00
Add minimal command line parser to YACReader and YACReaderLibrary.
Introduce new command line options --comicId and --libraryId for communication between Reader and Library. Support for standard command line options --help and --version.
This commit is contained in:
@ -80,7 +80,40 @@ int main(int argc, char * argv[])
|
||||
|
||||
app.setApplicationName("YACReader");
|
||||
app.setOrganizationName("YACReader");
|
||||
|
||||
|
||||
//simple command line parser
|
||||
//will be replaced by QCommandLineParser in the future
|
||||
QStringList optlist;
|
||||
QStringList arglist;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
//extract options and arguments
|
||||
optlist = QCoreApplication::arguments().filter(QRegExp ("^-{1,2}")); //options starting with "-"
|
||||
arglist = QCoreApplication::arguments().filter(QRegExp ("^(?!-{1,2})")); //positional arguments
|
||||
//deal with standard options
|
||||
if (!optlist.isEmpty())
|
||||
{
|
||||
QTextStream parser(stdout);
|
||||
if (optlist.contains("--version") | optlist.contains("-v"))
|
||||
{
|
||||
parser << app.applicationName() << " " << QString(VERSION) << endl << "Copyright 2014 by Luis Angel San Martin Rodriguez" << endl;
|
||||
return 0;
|
||||
}
|
||||
if (optlist.contains("--help") | optlist.contains("-h"))
|
||||
{
|
||||
parser << endl << "Usage: YACReader [File|Directory|Option]" << endl << endl;
|
||||
parser << "Options:" << endl;
|
||||
parser << " -h, --help\t\tDisplay this text and exit." << endl;
|
||||
parser << " -v, --version\t\tDisplay version information and exit." << endl << endl;
|
||||
parser << "Arguments:" << endl;
|
||||
parser << " file\t\t\tOpen comic file." <<endl;
|
||||
parser << " directory\t\tOpen comic directory." << endl << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString destLog = YACReader::getSettingsPath()+"/yacreader.log";
|
||||
QDir().mkpath(YACReader::getSettingsPath());
|
||||
|
||||
@ -101,8 +134,24 @@ int main(int argc, char * argv[])
|
||||
translator.load(QCoreApplication::applicationDirPath()+"/languages/yacreader_"+sufix);
|
||||
#endif
|
||||
app.installTranslator(&translator);
|
||||
|
||||
MainWindowViewer * mwv = new MainWindowViewer();
|
||||
//parser code for comic loading needs to be processed after MainWindowViewer creation
|
||||
//if we have a valid request, open it - if not, load normally
|
||||
if (argc > 1)
|
||||
{
|
||||
if (!optlist.filter("--comicId=").isEmpty() && !optlist.filter("--libraryId=").isEmpty())
|
||||
{
|
||||
if (arglist.count()>1)
|
||||
{
|
||||
mwv->open(arglist.at(1), optlist.filter("--comicId=").at(0).split("=").at(1).toULongLong(), optlist.filter("--libraryId=").at(0).split("=").at(1).toULongLong());
|
||||
}
|
||||
}
|
||||
else if ((arglist.count()>1))
|
||||
{
|
||||
//open first positional argument, silently ignore all following positional arguments
|
||||
mwv->openComicFromPath(arglist.at(1));
|
||||
}
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
app.setWindow(mwv);
|
||||
#endif
|
||||
|
@ -169,7 +169,7 @@ void MainWindowViewer::setupUI()
|
||||
|
||||
setWindowTitle("YACReader");
|
||||
|
||||
openFromArgv();
|
||||
//openFromArgv();
|
||||
|
||||
checkNewVersion();
|
||||
|
||||
@ -232,12 +232,16 @@ void MainWindowViewer::openFromArgv()
|
||||
open(pathFile+currentComicDB.path,currentComicDB,siblingComics);
|
||||
}
|
||||
else
|
||||
{isClient = false; QMessageBox::information(this,"Connection Error", "Unable to connect to YACReaderLibrary");/*error*/}
|
||||
{
|
||||
isClient = false;
|
||||
QMessageBox::information(this,"Connection Error", "Unable to connect to YACReaderLibrary");
|
||||
//error
|
||||
}
|
||||
|
||||
optionsDialog->setFilters(currentComicDB.info.brightness, currentComicDB.info.contrast, currentComicDB.info.gamma);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindowViewer::createActions()
|
||||
{
|
||||
openAction = new QAction(tr("&Open"),this);
|
||||
@ -649,6 +653,39 @@ void MainWindowViewer::open(QString path, ComicDB & comic, QList<ComicDB> & sibl
|
||||
openNextComicAction->setDisabled(true);
|
||||
}
|
||||
|
||||
void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId)
|
||||
{
|
||||
//QString pathFile = QCoreApplication::arguments().at(1);
|
||||
currentDirectory = path;
|
||||
//quint64 comicId = QCoreApplication::arguments().at(2).split("=").at(1).toULongLong();
|
||||
//libraryId = QCoreApplication::arguments().at(3).split("=").at(1).toULongLong();
|
||||
this->libraryId=libraryId;
|
||||
// this->path=path;
|
||||
|
||||
enableActions();
|
||||
|
||||
currentComicDB.id = comicId;
|
||||
YACReaderLocalClient client;
|
||||
int tries = 1;
|
||||
bool success = false;
|
||||
while(!(success = client.requestComicInfo(libraryId,currentComicDB,siblingComics)) && tries != 0)
|
||||
tries--;
|
||||
|
||||
if(success)
|
||||
{
|
||||
isClient = true;
|
||||
open(path+currentComicDB.path,currentComicDB,siblingComics);
|
||||
}
|
||||
else
|
||||
{
|
||||
isClient = false;
|
||||
QMessageBox::information(this,"Connection Error", "Unable to connect to YACReaderLibrary");
|
||||
//error
|
||||
}
|
||||
|
||||
optionsDialog->setFilters(currentComicDB.info.brightness, currentComicDB.info.contrast, currentComicDB.info.gamma);
|
||||
}
|
||||
|
||||
void MainWindowViewer::openComicFromPath(QString pathFile)
|
||||
{
|
||||
QFileInfo fi(pathFile);
|
||||
|
@ -26,6 +26,7 @@ class YACReaderSliderAction;
|
||||
public slots:
|
||||
void open();
|
||||
void open(QString path, ComicDB & comic, QList<ComicDB> & siblings);
|
||||
void open(QString path, qint64 comicId, qint64 libraryId);
|
||||
void openFolder();
|
||||
void saveImage();
|
||||
void toggleToolBars();
|
||||
@ -126,6 +127,7 @@ class YACReaderSliderAction;
|
||||
ComicDB currentComicDB;
|
||||
QList<ComicDB> siblingComics;
|
||||
bool isClient;
|
||||
QString startComicPath;
|
||||
quint64 libraryId;
|
||||
signals:
|
||||
void closed();
|
||||
|
Reference in New Issue
Block a user