Changeset View
Changeset View
Standalone View
Standalone View
mobile/app/main.cpp
Show All 22 Lines | |||||
23 | #include <QFileInfo> | 23 | #include <QFileInfo> | ||
24 | #include <QDir> | 24 | #include <QDir> | ||
25 | #include <QStandardPaths> | 25 | #include <QStandardPaths> | ||
26 | #include <QQmlEngine> | 26 | #include <QQmlEngine> | ||
27 | #include <QQmlContext> | 27 | #include <QQmlContext> | ||
28 | #include <QQmlApplicationEngine> | 28 | #include <QQmlApplicationEngine> | ||
29 | #include <QCommandLineParser> | 29 | #include <QCommandLineParser> | ||
30 | #include <QIcon> | 30 | #include <QIcon> | ||
31 | #include <QTimer> | ||||
31 | 32 | | |||
32 | Q_DECL_EXPORT int main(int argc, char *argv[]) | | |||
33 | { | | |||
34 | #ifdef __ANDROID__ | 33 | #ifdef __ANDROID__ | ||
35 | qputenv("QT_QUICK_CONTROLS_STYLE", "material"); | 34 | #include <jni.h> | ||
35 | | ||||
36 | class URIHandler : public QObject { | ||||
37 | public: | ||||
38 | void openUri(const QString &uri) { | ||||
39 | m_lastUrl = uri; | ||||
40 | } | ||||
41 | | ||||
42 | QString m_lastUrl; | ||||
43 | } handler; | ||||
44 | | ||||
45 | extern "C" { | ||||
46 | | ||||
47 | JNIEXPORT void JNICALL | ||||
48 | Java_org_kde_something_FileClass_openUri(JNIEnv *env, | ||||
49 | jobject /*obj*/, | ||||
50 | jstring uri) | ||||
51 | { | ||||
52 | jboolean isCopy = false; | ||||
53 | const char* utf = env->GetStringUTFChars(uri, &isCopy); | ||||
54 | handler.openUri(QString::fromUtf8(utf)); | ||||
55 | env->ReleaseStringUTFChars(uri, utf); | ||||
56 | | ||||
57 | } | ||||
58 | | ||||
59 | } | ||||
60 | | ||||
61 | Q_DECL_EXPORT | ||||
36 | #endif | 62 | #endif | ||
63 | int main(int argc, char *argv[]) | ||||
64 | { | ||||
37 | QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | 65 | QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | ||
38 | QApplication app(argc, argv); | 66 | QApplication app(argc, argv); | ||
39 | app.setApplicationName(QStringLiteral("okularkirigami")); | 67 | app.setApplicationName(QStringLiteral("okularkirigami")); | ||
40 | 68 | | |||
41 | QCommandLineParser parser; | 69 | QCommandLineParser parser; | ||
42 | parser.addVersionOption(); | 70 | parser.addVersionOption(); | ||
43 | parser.addHelpOption(); | 71 | parser.addHelpOption(); | ||
44 | //parser.setApplicationDescription(i18n("Okular mobile")); | 72 | //parser.setApplicationDescription(i18n("Okular mobile")); | ||
45 | parser.process(app); | 73 | parser.process(app); | ||
46 | | ||||
47 | QQmlApplicationEngine engine; | 74 | QQmlApplicationEngine engine; | ||
75 | | ||||
76 | #ifdef __ANDROID__ | ||||
77 | const QString uri = handler.m_lastUrl; | ||||
78 | #else | ||||
79 | const QString uri = parser.positionalArguments().count() == 1 | ||||
80 | ? QUrl::fromUserInput(parser.positionalArguments().constFirst(), {}, QUrl::AssumeLocalFile).toString() | ||||
81 | : QString(); | ||||
82 | #endif | ||||
48 | engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); | 83 | engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); | ||
49 | engine.rootContext()->setContextProperty(QStringLiteral("commandlineArguments"), parser.positionalArguments()); | 84 | engine.rootContext()->setContextProperty(QStringLiteral("uri"), uri); | ||
50 | QVariantMap paths; | 85 | QVariantMap paths; | ||
51 | paths[QStringLiteral("desktop")] = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | 86 | paths[QStringLiteral("desktop")] = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | ||
52 | paths[QStringLiteral("documents")] = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); | 87 | paths[QStringLiteral("documents")] = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); | ||
53 | paths[QStringLiteral("music")] = QStandardPaths::writableLocation(QStandardPaths::MusicLocation); | 88 | paths[QStringLiteral("music")] = QStandardPaths::writableLocation(QStandardPaths::MusicLocation); | ||
54 | paths[QStringLiteral("movies")] = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation); | 89 | paths[QStringLiteral("movies")] = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation); | ||
55 | paths[QStringLiteral("pictures")] = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); | 90 | paths[QStringLiteral("pictures")] = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); | ||
56 | paths[QStringLiteral("home")] = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); | 91 | paths[QStringLiteral("home")] = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); | ||
57 | engine.rootContext()->setContextProperty(QStringLiteral("userPaths"), paths); | 92 | engine.rootContext()->setContextProperty(QStringLiteral("userPaths"), paths); | ||
58 | 93 | | |||
59 | engine.setBaseUrl(QUrl("qrc:/package/contents/ui/")); | 94 | engine.setBaseUrl(QUrl("qrc:/package/contents/ui/")); | ||
60 | engine.load(QUrl("qrc:/package/contents/ui/main.qml")); | 95 | engine.load(QUrl("qrc:/package/contents/ui/main.qml")); | ||
61 | return app.exec(); | 96 | return app.exec(); | ||
62 | } | 97 | } |