mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
cleaning headless main file
This commit is contained in:
parent
1003fa0b26
commit
6c93c1e3c9
@ -1,13 +1,4 @@
|
|||||||
#include <QCoreApplication>
|
#include <QtCore>
|
||||||
#include <QTranslator>
|
|
||||||
#include <QSettings>
|
|
||||||
#include <QLocale>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QSysInfo>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QSettings>
|
|
||||||
#include <QLibrary>
|
|
||||||
#include <QTextStream>
|
|
||||||
|
|
||||||
#include "yacreader_global.h"
|
#include "yacreader_global.h"
|
||||||
#include "startup.h"
|
#include "startup.h"
|
||||||
@ -19,9 +10,6 @@
|
|||||||
#include "QsLog.h"
|
#include "QsLog.h"
|
||||||
#include "QsLogDest.h"
|
#include "QsLogDest.h"
|
||||||
|
|
||||||
//interfaz al servidor
|
|
||||||
Startup * s;
|
|
||||||
|
|
||||||
using namespace QsLogging;
|
using namespace QsLogging;
|
||||||
|
|
||||||
void logSystemAndConfig()
|
void logSystemAndConfig()
|
||||||
@ -97,7 +85,7 @@ void logSystemAndConfig()
|
|||||||
else
|
else
|
||||||
QLOG_ERROR() << "7z : not found";
|
QLOG_ERROR() << "7z : not found";
|
||||||
|
|
||||||
/*
|
/* TODO: qrencode could be helpfull for showing a qr code in the web client for client devices
|
||||||
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||||
if(QFileInfo(QString(BINDIR)+"/qrencode").exists())
|
if(QFileInfo(QString(BINDIR)+"/qrencode").exists())
|
||||||
#else
|
#else
|
||||||
@ -122,111 +110,102 @@ QCoreApplication* createApplication(int &argc, char *argv[])
|
|||||||
|
|
||||||
int main( int argc, char ** argv )
|
int main( int argc, char ** argv )
|
||||||
{
|
{
|
||||||
//fix for misplaced text in Qt4.8 and Mavericks
|
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
#if QT_VERSION < 0x050000
|
|
||||||
if(QSysInfo::MacintoshVersion > QSysInfo::MV_10_8)
|
|
||||||
QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
app->setApplicationName("YACReaderLibraryServer");
|
||||||
|
app->setOrganizationName("YACReader");
|
||||||
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
|
//simple command line parser
|
||||||
//QApplication app( argc, argv );
|
//will be replaced by QCommandLineParser in the future
|
||||||
|
//TODO: support for file and directory arguments
|
||||||
app->setApplicationName("YACReaderLibraryServer");
|
if (argc > 1)
|
||||||
app->setOrganizationName("YACReader");
|
{
|
||||||
//simple command line parser
|
QTextStream parser(stdout);
|
||||||
//will be replaced by QCommandLineParser in the future
|
QStringList optlist = QCoreApplication::arguments().filter(QRegExp ("^-{1,2}"));
|
||||||
//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"))
|
if (optlist.contains("--version") || optlist.contains("-v"))
|
||||||
{
|
{
|
||||||
parser << app->applicationName() << " " << QString(VERSION) << endl << "Copyright 2014 by Luis Angel San Martin Rodriguez" << endl;
|
parser << app->applicationName() << " " << QString(VERSION) << endl << "Copyright 2014 by Luis Angel San Martin Rodriguez" << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (optlist.contains("--help") || optlist.contains("-h"))
|
if (optlist.contains("--help") || optlist.contains("-h"))
|
||||||
{
|
{
|
||||||
parser << endl << "Usage:" << "\tYACReaderLibrary [Option]" << endl << endl;
|
parser << endl << "Usage:" << "\tYACReaderLibrary [Option]" << endl << endl;
|
||||||
parser << "Options:" << endl;
|
parser << "Options:" << endl;
|
||||||
parser << " none\t\t\tStart YACReaderLibrary" << endl;
|
parser << " none\t\t\tStart YACReaderLibrary" << endl;
|
||||||
parser << " -h, --help\t\tDisplay help text and exit." << endl;
|
parser << " -h, --help\t\tDisplay help text and exit." << endl;
|
||||||
parser << " -v, --version\t\tDisplay version information and exit." << endl;
|
parser << " -v, --version\t\tDisplay version information and exit." << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (optlist.contains("--no-gui"))
|
if (optlist.contains("--no-gui"))
|
||||||
{
|
{
|
||||||
parser << "You're running YACReaderLibrary in non-gui mode. Press Ctrl+C to exit." << endl;
|
parser << "You're running YACReaderLibrary in non-gui mode. Press Ctrl+C to exit." << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log";
|
QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log";
|
||||||
QDir().mkpath(YACReader::getSettingsPath());
|
QDir().mkpath(YACReader::getSettingsPath());
|
||||||
|
|
||||||
Logger& logger = Logger::instance();
|
Logger& logger = Logger::instance();
|
||||||
logger.setLoggingLevel(QsLogging::TraceLevel);
|
logger.setLoggingLevel(QsLogging::TraceLevel);
|
||||||
|
|
||||||
DestinationPtr fileDestination(DestinationFactory::MakeFileDestination(
|
DestinationPtr fileDestination(DestinationFactory::MakeFileDestination(
|
||||||
destLog, EnableLogRotation, MaxSizeBytes(1048576), MaxOldLogCount(2)));
|
destLog, EnableLogRotation, MaxSizeBytes(1048576), MaxOldLogCount(2)));
|
||||||
DestinationPtr debugDestination(DestinationFactory::MakeDebugOutputDestination());
|
DestinationPtr debugDestination(DestinationFactory::MakeDebugOutputDestination());
|
||||||
logger.addDestination(debugDestination);
|
logger.addDestination(debugDestination);
|
||||||
logger.addDestination(fileDestination);
|
logger.addDestination(fileDestination);
|
||||||
|
|
||||||
QTranslator translator;
|
QTranslator translator;
|
||||||
QString sufix = QLocale::system().name();
|
QString sufix = QLocale::system().name();
|
||||||
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||||
translator.load(QString(DATADIR)+"/yacreader/languages/yacreaderlibrary_"+sufix);
|
translator.load(QString(DATADIR)+"/yacreader/languages/yacreaderlibrary_"+sufix);
|
||||||
#else
|
#else
|
||||||
translator.load(QCoreApplication::applicationDirPath()+"/languages/yacreaderlibrary_"+sufix);
|
translator.load(QCoreApplication::applicationDirPath()+"/languages/yacreaderlibrary_"+sufix);
|
||||||
#endif
|
#endif
|
||||||
app->installTranslator(&translator);
|
app->installTranslator(&translator);
|
||||||
|
|
||||||
QTranslator viewerTranslator;
|
QTranslator viewerTranslator;
|
||||||
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||||
viewerTranslator.load(QString(DATADIR)+"/yacreader/languages/yacreader_"+sufix);
|
viewerTranslator.load(QString(DATADIR)+"/yacreader/languages/yacreader_"+sufix);
|
||||||
#else
|
#else
|
||||||
viewerTranslator.load(QCoreApplication::applicationDirPath()+"/languages/yacreader_"+sufix);
|
viewerTranslator.load(QCoreApplication::applicationDirPath()+"/languages/yacreader_"+sufix);
|
||||||
#endif
|
#endif
|
||||||
app->installTranslator(&viewerTranslator);
|
app->installTranslator(&viewerTranslator);
|
||||||
app->setApplicationName("YACReaderLibrary");
|
app->setApplicationName("YACReaderLibrary");
|
||||||
|
|
||||||
qRegisterMetaType<ComicDB>("ComicDB");
|
qRegisterMetaType<ComicDB>("ComicDB");
|
||||||
|
|
||||||
|
|
||||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci�n del fichero de config con el servidor
|
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci�n del fichero de config con el servidor
|
||||||
settings->beginGroup("libraryConfig");
|
settings->beginGroup("libraryConfig");
|
||||||
|
|
||||||
s = new Startup();
|
|
||||||
s->start();
|
|
||||||
|
|
||||||
QLOG_INFO() << "YACReaderLibraryServer attempting to start";
|
//server
|
||||||
|
Startup *s = new Startup();
|
||||||
|
s->start();
|
||||||
|
|
||||||
logSystemAndConfig();
|
QLOG_INFO() << "YACReaderLibraryServer attempting to start";
|
||||||
|
|
||||||
if(YACReaderLocalServer::isRunning()) //s�lo se permite una instancia de YACReaderLibrary
|
logSystemAndConfig();
|
||||||
{
|
|
||||||
QLOG_WARN() << "another instance of YACReaderLibrary is running";
|
|
||||||
QsLogging::Logger::destroyInstance();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
QLOG_INFO() << "YACReaderLibrary starting";
|
|
||||||
|
|
||||||
YACReaderLocalServer * localServer = new YACReaderLocalServer();
|
if(YACReaderLocalServer::isRunning()) //s�lo se permite una instancia de YACReaderLibrary
|
||||||
|
{
|
||||||
|
QLOG_WARN() << "another instance of YACReaderLibrary is running";
|
||||||
|
QsLogging::Logger::destroyInstance();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
QLOG_INFO() << "YACReaderLibrary starting";
|
||||||
|
|
||||||
int ret = app->exec();
|
YACReaderLocalServer * localServer = new YACReaderLocalServer();
|
||||||
|
|
||||||
QLOG_INFO() << "YACReaderLibrary closed with exit code :" << ret;
|
int ret = app->exec();
|
||||||
|
|
||||||
//shutdown
|
QLOG_INFO() << "YACReaderLibrary closed with exit code :" << ret;
|
||||||
s->stop();
|
|
||||||
delete s;
|
|
||||||
localServer->close();
|
|
||||||
delete localServer;
|
|
||||||
|
|
||||||
QsLogging::Logger::destroyInstance();
|
//shutdown
|
||||||
|
s->stop();
|
||||||
|
delete s;
|
||||||
|
localServer->close();
|
||||||
|
delete localServer;
|
||||||
|
|
||||||
return ret;
|
QsLogging::Logger::destroyInstance();
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user