72 lines
2.7 KiB
C++
72 lines
2.7 KiB
C++
#include <QDebug>
|
|
#include <QGuiApplication>
|
|
#include <QLocale>
|
|
#include <QQuickView>
|
|
#include <QQmlContext>
|
|
#include <QTranslator>
|
|
#include <sailfishapp.h>
|
|
|
|
#include "apiclient.h"
|
|
#include "downloader.h"
|
|
#include "epub.h"
|
|
#include "settings.h"
|
|
|
|
Q_DECL_EXPORT int main(int argc, char *argv[])
|
|
{
|
|
QGuiApplication *app = SailfishApp::application(argc, argv);
|
|
|
|
// Identita' applicazione allineata al profilo X-Sailjail del desktop file:
|
|
// QStandardPaths::AppConfigLocation diventa ~/.config/harbour/calibreweb,
|
|
// l'unica zona config persistente della sandbox di Sailfish 5.1.
|
|
app->setOrganizationName(QStringLiteral("harbour"));
|
|
app->setApplicationName(QStringLiteral("calibreweb"));
|
|
|
|
Settings settings;
|
|
|
|
// User-chosen language (Settings -> Language). "system" = follow the
|
|
// Sailfish UI language. "en" = force English. "it" = force Italian.
|
|
// The .qm lives in the app data dir (the RPM validator rejects
|
|
// /usr/share/translations), so libsailfishapp's auto-load cannot be
|
|
// used: resolve the language here and install our own translator.
|
|
QString lang = settings.language();
|
|
if (lang == "system") {
|
|
const QString sys = QLocale::system().name();
|
|
lang = sys.startsWith(QLatin1String("it")) ? QStringLiteral("it")
|
|
: QStringLiteral("en");
|
|
}
|
|
if (lang == "en" || lang == "it") {
|
|
const QList<QTranslator *> trs = app->findChildren<QTranslator *>();
|
|
foreach (QTranslator *t, trs) {
|
|
app->removeTranslator(t);
|
|
t->deleteLater();
|
|
}
|
|
if (lang == "it") {
|
|
QTranslator *translator = new QTranslator(app);
|
|
if (translator->load(QStringLiteral("harbour-calibreweb_it"),
|
|
QStringLiteral("/usr/share/harbour-calibreweb/translations"))) {
|
|
app->installTranslator(translator);
|
|
} else {
|
|
qWarning() << "harbour-calibreweb: cannot load harbour-calibreweb_it.qm";
|
|
}
|
|
}
|
|
}
|
|
|
|
QQuickView *view = SailfishApp::createView();
|
|
|
|
qDebug() << "harbour-calibreweb v0.2.0 build" << __DATE__ << __TIME__;
|
|
|
|
qmlRegisterType<EpubBook>("harbour.calibreweb", 1, 0, "EpubBook");
|
|
|
|
ApiClient apiClient(&settings);
|
|
Downloader downloader(&settings);
|
|
|
|
view->rootContext()->setContextProperty(QStringLiteral("appSettings"), &settings);
|
|
view->rootContext()->setContextProperty(QStringLiteral("apiClient"), &apiClient);
|
|
view->rootContext()->setContextProperty(QStringLiteral("downloader"), &downloader);
|
|
|
|
view->setSource(SailfishApp::pathTo(QStringLiteral("qml/harbour-calibreweb.qml")));
|
|
view->show();
|
|
|
|
return app->exec();
|
|
}
|