Add a method to ExtractDelegate for querying if the extraction has been cancelled.

This commit is contained in:
Luis Ángel San Martín
2018-01-06 07:41:27 +01:00
commit c766fedd45
1046 changed files with 103737 additions and 0 deletions

View File

@ -0,0 +1,161 @@
TEMPLATE = app
TARGET = YACReaderLibraryServer
QMAKE_TARGET_BUNDLE_PREFIX = "com.yacreader"
CONFIG += console
DEPENDPATH += ../YACReaderLibrary
INCLUDEPATH += ../YACReaderLibrary \
../common \
../YACReaderLibrary/server \
../YACReaderLibrary/db
DEFINES += SERVER_RELEASE NOMINMAX YACREADER_LIBRARY QT_NO_DEBUG_OUTPUT
QMAKE_MAC_SDK = macosx10.12
# load default build flags
# do a basic dependency check
include(headless_config.pri)
include(../dependencies/pdf_backend.pri)
win32 {
LIBS += -loleaut32 -lole32 -lshell32 -luser32
QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT /GL
QMAKE_LFLAGS_RELEASE += /LTCG
CONFIG -= embed_manifest_exe
}
macx {
LIBS += -framework Foundation -framework ApplicationServices -framework AppKit
CONFIG += objective_c
}
unix {
CONFIG += c++11
}
unix:haiku {
DEFINES += _BSD_SOURCE
LIBS += -lnetwork -lbsd
}
#CONFIG += release
CONFIG -= flat
QT += core sql network
# Source files
HEADERS += ../YACReaderLibrary/library_creator.h \
../YACReaderLibrary/package_manager.h \
../YACReaderLibrary/bundle_creator.h \
../YACReaderLibrary/db_helper.h \
../YACReaderLibrary/db/data_base_management.h \
../common/comic_db.h \
../common/folder.h \
../common/library_item.h \
../common/comic.h \
../common/pdf_comic.h \
../common/bookmarks.h \
../common/qnaturalsorting.h \
../common/yacreader_global.h \
../YACReaderLibrary/yacreader_local_server.h \
../YACReaderLibrary/comics_remover.h \
../common/http_worker.h \
../YACReaderLibrary/yacreader_libraries.h \
../YACReaderLibrary/comic_files_manager.h \
console_ui_library_creator.h
SOURCES += ../YACReaderLibrary/library_creator.cpp \
../YACReaderLibrary/package_manager.cpp \
../YACReaderLibrary/bundle_creator.cpp \
../YACReaderLibrary/db_helper.cpp \
../YACReaderLibrary/db/data_base_management.cpp \
../common/comic_db.cpp \
../common/folder.cpp \
../common/library_item.cpp \
../common/comic.cpp \
../common/bookmarks.cpp \
../common/qnaturalsorting.cpp \
../YACReaderLibrary/yacreader_local_server.cpp \
../YACReaderLibrary/comics_remover.cpp \
../common/http_worker.cpp \
../common/yacreader_global.cpp \
../YACReaderLibrary/yacreader_libraries.cpp \
../YACReaderLibrary/comic_files_manager.cpp \
console_ui_library_creator.cpp \
main.cpp
include(../YACReaderLibrary/server/server.pri)
CONFIG(7zip) {
include(../compressed_archive/wrapper.pri)
} else:CONFIG(unarr) {
include(../compressed_archive/unarr/unarr-wrapper.pri)
} else {
error(No compression backend specified. Did you mess with the build system?)
}
include(../QsLog/QsLog.pri)
TRANSLATIONS = yacreaderlibraryserver_es.ts \
yacreaderlibraryserver_ru.ts \
yacreaderlibraryserver_pt.ts \
yacreaderlibraryserver_fr.ts \
yacreaderlibraryserver_nl.ts \
yacreaderlibraryserver_tr.ts \
yacreaderlibraryserver_de.ts \
yacreaderlibraryserver_source.ts
RESOURCES += images.qrc
contains(QMAKE_TARGET.arch, x86_64) {
Release:DESTDIR = ../release64
Debug:DESTDIR = ../debug64
} else {
Release:DESTDIR = ../release
Debug:DESTDIR = ../debug
}
unix:!macx {
#set install prefix if it's empty
isEmpty(PREFIX) {
PREFIX = /usr
}
BINDIR = $$PREFIX/bin
LIBDIR = $$PREFIX/lib
DATADIR = $$PREFIX/share
DEFINES += "LIBDIR=\\\"$$LIBDIR\\\"" "DATADIR=\\\"$$DATADIR\\\"" "BINDIR=\\\"$$BINDIR\\\""
#make install
CONFIG(server_standalone) {
INSTALLS += bin server translation systemd
}
else:CONFIG(server_bundled) {
INSTALLS += bin systemd
}
else {
INSTALLS += bin server translation systemd
message("No build type specified. Defaulting to standalone server build (CONFIG+=server_standalone).")
message("If you wish to run YACReaderLibraryServer on a system with an existing install of YACReaderLibrary,\
please specify CONFIG+=server_bundled as an option when running qmake.")
}
bin.path = $$BINDIR
isEmpty(DESTDIR) {
bin.files = YACReaderLibraryServer
} else {
bin.files = $$DESTDIR/YACReaderLibraryServer
}
server.path = $$DATADIR/yacreader
server.files = ../release/server
systemd.path = $$LIBDIR/systemd/user
systemd.files = yacreaderlibraryserver.service
translation.path = $$DATADIR/yacreader/languages
translation.files = ../release/languages/yacreaderlibrary_*
# TODO: We need a manpage for yaclibserver
#manpage.path = $$DATADIR/man/man1
#manpage.files = ../YACReaderLibrary.1
}

View File

@ -0,0 +1,148 @@
#include "console_ui_library_creator.h"
#include <iostream>
#include "library_creator.h"
#include "yacreader_libraries.h"
ConsoleUILibraryCreator::ConsoleUILibraryCreator(QObject *parent) :
QObject(parent), numComicsProcessed(0)
{
}
void ConsoleUILibraryCreator::createLibrary(const QString & name, const QString & path)
{
QEventLoop eventLoop;
LibraryCreator * libraryCreator = new LibraryCreator();
QDir pathDir(path);
if (!pathDir.exists())
{
std::cout << "Directory not found." << std::endl;
return;
}
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
YACReaderLibraries yacreaderLibraries;
yacreaderLibraries.load();
if (yacreaderLibraries.contains(name))
{
std::cout << "A Library named \"" << name.toUtf8().constData() << "\" already exists in database." << std::endl;
return;
}
libraryCreator->createLibrary(cleanPath,QDir::cleanPath(pathDir.absolutePath()+"/.yacreaderlibrary"));
connect(libraryCreator, &LibraryCreator::finished, this, &ConsoleUILibraryCreator::done);
connect(libraryCreator, &LibraryCreator::comicAdded, this, &ConsoleUILibraryCreator::newComic);
connect(libraryCreator, &LibraryCreator::failedCreatingDB, this, &ConsoleUILibraryCreator::manageCreatingError);
connect(libraryCreator, &LibraryCreator::finished, &eventLoop, &QEventLoop::quit);
std::cout << "Processing comics";
libraryCreator->start();
eventLoop.exec();
yacreaderLibraries.addLibrary(name, cleanPath);
yacreaderLibraries.save();
}
void ConsoleUILibraryCreator::updateLibrary(const QString & path)
{
QEventLoop eventLoop;
LibraryCreator * libraryCreator = new LibraryCreator();
QDir pathDir(path);
if (!pathDir.exists())
{
std::cout << "Directory not found." << std::endl;
return;
}
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
libraryCreator->updateLibrary(cleanPath,QDir::cleanPath(pathDir.absolutePath()+"/.yacreaderlibrary"));
connect(libraryCreator, &LibraryCreator::finished, this, &ConsoleUILibraryCreator::done);
connect(libraryCreator, &LibraryCreator::comicAdded, this, &ConsoleUILibraryCreator::newComic);
connect(libraryCreator, &LibraryCreator::failedOpeningDB, this, &ConsoleUILibraryCreator::manageUpdatingError);
connect(libraryCreator, &LibraryCreator::finished, &eventLoop, &QEventLoop::quit);
std::cout << "Processing comics";
libraryCreator->start();
eventLoop.exec();
}
void ConsoleUILibraryCreator::addExistingLibrary(const QString & name, const QString & path)
{
QDir pathDir(path);
if (!pathDir.exists())
{
std::cout << "Directory not found." << std::endl;
return;
}
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
if (!QDir(cleanPath + "/.yacreaderlibrary").exists())
{
std::cout << "No library database found in directory." << std::endl;
return;
}
YACReaderLibraries yacreaderLibraries;
yacreaderLibraries.load();
if (yacreaderLibraries.contains(name))
{
std::cout << "A Library named \"" << name.toUtf8().constData() << "\" already exists in the database." << std::endl;
return;
}
yacreaderLibraries.addLibrary(name, cleanPath);
yacreaderLibraries.save();
std::cout << "Library added : " << name.toUtf8().constData() << " at " << cleanPath.toUtf8().constData() << std::endl;
}
void ConsoleUILibraryCreator::removeLibrary(const QString & name)
{
//TODO add error handling
YACReaderLibraries yacreaderLibraries;
yacreaderLibraries.load();
if (!yacreaderLibraries.contains(name))
{
std::cout << "No Library named \"" << name.toUtf8().constData() << "\" in database." << std::endl;
return;
}
yacreaderLibraries.remove(name);
yacreaderLibraries.save();
std::cout << "Library removed : " << name.toUtf8().constData() << std::endl;
}
void ConsoleUILibraryCreator::newComic(const QString & /*relativeComicPath*/, const QString & /*coverPath*/)
{
numComicsProcessed++;
std::cout << ".";
}
void ConsoleUILibraryCreator::manageCreatingError(const QString & error)
{
std::cout << std::endl << "Error creating library! " << error.toUtf8().constData() << std::endl;
}
void ConsoleUILibraryCreator::manageUpdatingError(const QString & error)
{
std::cout << std::endl << "Error updating library! " << error.toUtf8().constData() << std::endl;
}
void ConsoleUILibraryCreator::done()
{
std::cout << "Done!" << std::endl;
if(numComicsProcessed > 0)
std::cout << "Number of comics processed = " << numComicsProcessed << std::endl;
}

View File

@ -0,0 +1,29 @@
#ifndef CONSOLE_UI_LIBRARY_CREATOR_H
#define CONSOLE_UI_LIBRARY_CREATOR_H
#include <QtCore>
class ConsoleUILibraryCreator : public QObject
{
Q_OBJECT
public:
explicit ConsoleUILibraryCreator(QObject *parent = 0);
void createLibrary(const QString & name, const QString & path);
void updateLibrary(const QString & path);
void addExistingLibrary(const QString & name, const QString & path);
void removeLibrary(const QString & name);
private:
uint numComicsProcessed;
signals:
public slots:
protected slots:
void newComic(const QString & relativeComicPath, const QString & coverPath);
void manageCreatingError(const QString & error);
void manageUpdatingError(const QString & error);
void done();
};
#endif // CONSOLE_UI_LIBRARY_CREATOR_H

View File

@ -0,0 +1,52 @@
#functions to automatically initialize some of YACReader's build options to
#default values if they're not set on build time
#for a more detailed description, see INSTALL.TXT
#check Qt version
QT_VERSION = $$[QT_VERSION]
QT_VERSION = $$split(QT_VERSION, ".")
QT_VER_MAJ = $$member(QT_VERSION, 0)
QT_VER_MIN = $$member(QT_VERSION, 1)
include (../config.pri)
unix {
!macx {
packagesExist(Qt5Core) {
message("Found Qt5Core")
}
else: {
message("Missing dependency: Qt5Core")
}
packagesExist(Qt5Gui) {
message("Found Qt5Gui")
}
else: {
message("Missing dependency: Qt5Gui")
}
packagesExist(poppler-qt5) {
message("Found poppler-qt5")
}
else: {
message("Missing dependency: poppler-qt5")
}
packagesExist(Qt5Network) {
message("Found Qt5Network")
}
else: {
message("Missing dependency: Qt5Network")
}
packagesExist(Qt5Sql) {
message("Found Qt5Sql")
}
else: {
message("Missing dependency: Qt5Sql")
}
packagesExist(sqlite3) {
message("Found sqlite3")
}
else: {
message("Missing dependency: sqlite3")
}
}
}

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>../images/f_overlayed.png</file>
<file>../images/f_overlayed_retina.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,321 @@
#include <QtCore>
#include "comic_db.h"
#include "db_helper.h"
#include "startup.h"
#include "yacreader_global.h"
#include "yacreader_libraries.h"
#include "yacreader_local_server.h"
#include "console_ui_library_creator.h"
#include "QsLog.h"
#include "QsLogDest.h"
using namespace QsLogging;
void logSystemAndConfig()
{
QLOG_INFO() << "---------- System & configuration ----------";
#if defined(Q_OS_WIN)
switch (QSysInfo::windowsVersion())
{
case QSysInfo::WV_NT:
QLOG_INFO() << "SO : Windows NT";
break;
case QSysInfo::WV_2000:
QLOG_INFO() << "SO : Windows 2000";
break;
case QSysInfo::WV_XP:
QLOG_INFO() << "SO : Windows XP";
break;
case QSysInfo::WV_2003:
QLOG_INFO() << "SO : Windows 2003";
break;
case QSysInfo::WV_VISTA:
QLOG_INFO() << "SO : Windows Vista";
break;
case QSysInfo::WV_WINDOWS7:
QLOG_INFO() << "SO : Windows 7";
break;
case QSysInfo::WV_WINDOWS8:
QLOG_INFO() << "SO : Windows 8";
break;
default:
QLOG_INFO() << "Windows (unknown version)";
break;
}
#elif defined(Q_OS_MAC)
switch (QSysInfo::MacVersion())
{
case QSysInfo::MV_SNOWLEOPARD:
QLOG_INFO() << "SO : MacOSX Snow Leopard";
break;
case QSysInfo::MV_LION:
QLOG_INFO() << "SO : MacOSX Lion";
break;
case QSysInfo::MV_MOUNTAINLION:
QLOG_INFO() << "SO : MacOSX Mountain Lion";
break;
#if QT_VERSION >= 0x050000
case QSysInfo::MV_MAVERICKS:
QLOG_INFO() << "SO : MacOSX Maverics";
break;
#endif
default:
QLOG_INFO() << "SO : MacOSX (unknown version)";
break;
}
#elif defined(Q_OS_LINUX)
QLOG_INFO() << "SO : Linux (unknown version)";
#else
QLOG_INFO() << "SO : Unknown";
#endif
#ifdef Q_OS_WIN
if(QLibrary::isLibrary(QCoreApplication::applicationDirPath()+"/utils/7z.dll"))
#elif defined Q_OS_UNIX && !defined Q_OS_MAC
if(QLibrary::isLibrary(QString(LIBDIR)+"/yacreader/7z.so") | QLibrary::isLibrary(QString(LIBDIR)+"/p7zip/7z.so"))
#else
if(QLibrary::isLibrary(QCoreApplication::applicationDirPath()+"/utils/7z.so"))
#endif
QLOG_INFO() << "7z : found";
else
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(QFileInfo(QString(BINDIR)+"/qrencode").exists())
#else
if(QFileInfo(QCoreApplication::applicationDirPath()+"/utils/qrencode.exe").exists() || QFileInfo("./util/qrencode").exists())
#endif
QLOG_INFO() << "qrencode : found";
else
QLOG_INFO() << "qrencode : not found";
*/
QLOG_INFO() << "Libraries: " << DBHelper::getLibraries().getLibraries();
QLOG_INFO() << "--------------------------------------------";
}
int main( int argc, char ** argv )
{
QCoreApplication *app = new QCoreApplication(argc, argv);
app->setApplicationName("YACReaderLibrary");
app->setOrganizationName("YACReader");
app->setApplicationVersion(VERSION);
QTextStream qout(stdout);
//general help
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::tr("\nYACReaderLibraryServer is the headless (no gui) version of YACReaderLibrary"));
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("command", "The command to execute. [start, create-library, update-library, add-library, remove-library, list-libraries]");
parser.parse(QCoreApplication::arguments());
const QStringList args = parser.positionalArguments();
const QString command = args.isEmpty() ? QString() : args.first();
if(command == "start")
{
QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log";
QDir().mkpath(YACReader::getSettingsPath());
Logger& logger = Logger::instance();
logger.setLoggingLevel(QsLogging::InfoLevel);
DestinationPtr fileDestination(DestinationFactory::MakeFileDestination(
destLog, EnableLogRotation, MaxSizeBytes(1048576), MaxOldLogCount(2)));
DestinationPtr debugDestination(DestinationFactory::MakeDebugOutputDestination());
logger.addDestination(debugDestination);
logger.addDestination(fileDestination);
QTranslator translator;
QString sufix = QLocale::system().name();
#if defined Q_OS_UNIX && !defined Q_OS_MAC
translator.load(QString(DATADIR)+"/yacreader/languages/yacreaderlibrary_"+sufix);
#else
translator.load(QCoreApplication::applicationDirPath()+"/languages/yacreaderlibrary_"+sufix);
#endif
app->installTranslator(&translator);
QTranslator viewerTranslator;
#if defined Q_OS_UNIX && !defined Q_OS_MAC
viewerTranslator.load(QString(DATADIR)+"/yacreader/languages/yacreader_"+sufix);
#else
viewerTranslator.load(QCoreApplication::applicationDirPath()+"/languages/yacreader_"+sufix);
#endif
app->installTranslator(&viewerTranslator);
qRegisterMetaType<ComicDB>("ComicDB");
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/"+QCoreApplication::applicationName()+".ini",QSettings::IniFormat);
settings->beginGroup("libraryConfig");
//server
Startup *s = new Startup();
s->start();
QLOG_INFO() << "YACReaderLibraryServer attempting to start";
logSystemAndConfig();
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";
YACReaderLocalServer * localServer = new YACReaderLocalServer();
int ret = app->exec();
QLOG_INFO() << "YACReaderLibrary closed with exit code :" << ret;
//shutdown
s->stop();
delete s;
localServer->close();
delete localServer;
QsLogging::Logger::destroyInstance();
return ret;
}
else if(command == "create-library")
{
QCommandLineParser parser;
parser.addHelpOption();
parser.parse(QCoreApplication::arguments());
parser.clearPositionalArguments();
parser.addPositionalArgument("create-library", "Creates a library named \"name\" in the specified destination <path>");
parser.addPositionalArgument("name", "Library name", "\"name\"");
parser.addPositionalArgument("path", "Path to the folder where the library will be created", "<path>");
parser.process(*app);
const QStringList args = parser.positionalArguments();
if(args.length() != 3)
{
parser.showHelp();
return 0;
}
const QStringList createArgs = parser.positionalArguments();
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
libraryCreatorUI->createLibrary(createArgs.at(1), createArgs.at(2));
return 0;
}
else if(command == "update-library")
{
QCommandLineParser parser;
parser.addHelpOption();
parser.parse(QCoreApplication::arguments());
parser.clearPositionalArguments();
parser.addPositionalArgument("update-library", "Updates an existing library at <path>");
parser.addPositionalArgument("path", "Path to the library to be updated", "<path>");
parser.process(*app);
const QStringList args = parser.positionalArguments();
if(args.length() != 2)
{
parser.showHelp();
return 0;
}
const QStringList updateArgs = parser.positionalArguments();
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
libraryCreatorUI->updateLibrary(updateArgs.at(1));
return 0;
}
else if(command == "add-library")
{
QCommandLineParser parser;
parser.addHelpOption();
parser.parse(QCoreApplication::arguments());
parser.clearPositionalArguments();
parser.addPositionalArgument("add-library", "Adds an exiting library named \"name\" at the specified origin <path>");
parser.addPositionalArgument("name", "Library name", "\"name\"");
parser.addPositionalArgument("path", "Path to the folder where the library is", "<path>");
parser.process(*app);
const QStringList args = parser.positionalArguments();
if(args.length() != 3)
{
parser.showHelp();
return 0;
}
const QStringList addArgs = parser.positionalArguments();
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
libraryCreatorUI->addExistingLibrary(addArgs.at(1), addArgs.at(2));
return 0;
}
else if(command == "remove-library")
{
QCommandLineParser parser;
parser.addHelpOption();
parser.parse(QCoreApplication::arguments());
parser.clearPositionalArguments();
parser.addPositionalArgument("remove-library", "Removes a library named \"name\" from the list of libraries");
parser.addPositionalArgument("name", "Library name", "\"name\"");
parser.process(*app);
const QStringList args = parser.positionalArguments();
if(args.length() != 2)
{
parser.showHelp();
return 0;
}
const QStringList removeArgs = parser.positionalArguments();
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
libraryCreatorUI->removeLibrary(removeArgs.at(1));
return 0;
}
else if(command == "list-libraries")
{
YACReaderLibraries libraries = DBHelper::getLibraries();
for(QString libraryName : libraries.getNames())
qout << libraryName << " : " << libraries.getPath(libraryName) << endl;
return 0;
}
else //error
{
parser.showHelp();
return 0;
}
}

View File

@ -0,0 +1,13 @@
1. change the path used in ExecStart so it points to the location your headless server binary resides, skip this step if yacreaderlibraryserver is in your path.
2. copy the service file to ~/.local/share/systemd/user
3. enable the service file by running:
"systemclt --user enable yacreaderlibraryserver"
4. start the server by running:
"systemctl --user start yacreaderlibraryserver"
5. check the server status by running:
systemctl --user status yacreaderlibraryserver

View File

@ -0,0 +1,11 @@
[Unit]
Description= YACReaderLibrary headless server
After=network.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/YACReaderLibraryServer start
[Install]
WantedBy=default.target