diff --git a/YACReader/main.cpp b/YACReader/main.cpp index d5bbdfb5..c6f81e94 100644 --- a/YACReader/main.cpp +++ b/YACReader/main.cpp @@ -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." < 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 diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index ee3d148e..93d2d72d 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -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 & 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); diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 6b33c434..fb616c43 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -26,6 +26,7 @@ class YACReaderSliderAction; public slots: void open(); void open(QString path, ComicDB & comic, QList & siblings); + void open(QString path, qint64 comicId, qint64 libraryId); void openFolder(); void saveImage(); void toggleToolBars(); @@ -126,6 +127,7 @@ class YACReaderSliderAction; ComicDB currentComicDB; QList siblingComics; bool isClient; + QString startComicPath; quint64 libraryId; signals: void closed(); diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 66debab4..6a33ad31 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -1136,8 +1136,8 @@ void LibraryWindow::openComic() //Invoke YACReader comicPath comicId libraryId NO-->currentPage bookmark1 bookmark2 bookmark3 brightness contrast gamma bool yacreaderFound = false; #ifdef Q_OS_MAC - QString comicIdS = QString("%1").arg(comicId); - QString libraryIdS = QString("%1").arg(libraryId); + QString comicIdS = QString("--comicId=") + QString("%1").arg(comicId); + QString libraryIdS = QString("--libraryId=") + QString("%1").arg(libraryId); QString yacreaderPath = QDir::cleanPath(QCoreApplication::applicationDirPath()+"/../../../YACReader.app"); if(yacreaderFound = QFileInfo(yacreaderPath).exists()) QProcess::startDetached("open", QStringList() << "-n" << yacreaderPath << "--args" << path << comicIdS << libraryIdS ); /*<< page << bookmark1 << bookmark2 << bookmark3 << brightness << contrast << gamma*///,QStringList() << path); @@ -1145,12 +1145,12 @@ void LibraryWindow::openComic() #endif #ifdef Q_OS_WIN /* \"%4\" \"%5\" \"%6\" \"%7\" \"%8\" \"%9\" \"%10\" */ - yacreaderFound = QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+QString("/YACReader \"%1\" \"%2\" \"%3\"").arg(path).arg(comicId).arg(libraryId)/*.arg(page).arg(bookmark1).arg(bookmark2).arg(bookmark3).arg(brightness).arg(contrast).arg(gamma)*/,QStringList()); + yacreaderFound = QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+QString("/YACReader \"%1\" \"%2\" \"%3\"").arg(path).arg(QString("--comicId=") + QString::number(comicId))).arg(QString("--libraryId=") + QString::number(libraryId))/*.arg(page).arg(bookmark1).arg(bookmark2).arg(bookmark3).arg(brightness).arg(contrast).arg(gamma)*/,QStringList()); #endif #if defined Q_OS_UNIX && !defined Q_OS_MAC - QStringList parameters = QStringList() << path << QString::number(comicId) << QString::number(libraryId); - yacreaderFound = QProcess::startDetached(QString("YACReader"),parameters); + QStringList parameters = QStringList() << path << (QString("--comicId=") + QString::number(comicId)) << (QString("--libraryId=") + QString::number(libraryId)); + yacreaderFound = QProcess::startDetached(QString("YACReader"),parameters); #endif if(!yacreaderFound) QMessageBox::critical(this,tr("YACReader not found"),tr("YACReader not found, YACReader should be installed in the same folder as YACReaderLibrary.")); diff --git a/YACReaderLibrary/main.cpp b/YACReaderLibrary/main.cpp index 951356fb..a159acda 100644 --- a/YACReaderLibrary/main.cpp +++ b/YACReaderLibrary/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "yacreader_global.h" #include "startup.h" @@ -141,6 +142,31 @@ int main( int argc, char ** argv ) app.setApplicationName("YACReaderLibrary"); app.setOrganizationName("YACReader"); +//simple command line parser +//will be replaced by QCommandLineParser in the future +//TODO: --headless, --server=[on|off], support for file and directory arguments + if (argc > 1) + { + QTextStream parser(stdout); + QStringList optlist = QCoreApplication::arguments().filter(QRegExp ("^-{1,2}")); + 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:" << "\tYACReaderLibrary [Option]" << endl << endl; + parser << "Options:" << endl; + parser << " none\t\t\tStart YACReaderLibrary" << endl; + parser << " -h, --help\t\tDisplay help text and exit." << endl; + parser << " -v, --version\t\tDisplay version information and exit." << endl; + return 0; + } + parser << "Unsupported command line options. See YACReaderLibrary --help for further information." << endl; + return 0; + } + QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log"; QDir().mkpath(YACReader::getSettingsPath()); diff --git a/YACReaderLibrary/yacreader_local_server.cpp b/YACReaderLibrary/yacreader_local_server.cpp index a24c184f..34059522 100644 --- a/YACReaderLibrary/yacreader_local_server.cpp +++ b/YACReaderLibrary/yacreader_local_server.cpp @@ -51,6 +51,7 @@ void YACReaderLocalServer::sendResponse() connect(worker,SIGNAL(comicUpdated(quint64, ComicDB)),this,SIGNAL(comicUpdated(quint64, ComicDB))); connect(worker,SIGNAL(finished()),worker,SLOT(deleteLater())); worker->start(); + QLOG_INFO() << "connection incoming" << "Worker started"; } QLOG_INFO() << "connection incoming"; diff --git a/common/check_new_version.cpp b/common/check_new_version.cpp index e27c0562..6454c980 100644 --- a/common/check_new_version.cpp +++ b/common/check_new_version.cpp @@ -29,7 +29,7 @@ bool HttpVersionChecker::checkNewVersion(QString sourceContent) QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}win32.*"); #endif -#ifdef Q_OS_LINUX +#if defined Q_OS_UNIX && !defined Q_OS_MAC QRegExp rx(".*YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}X11.*"); #endif