-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.cpp
138 lines (113 loc) · 4.61 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Copyright (c) 2013 - 2022 Jolla Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QApplication>
#include <QGuiApplication>
#include <qqmldebug.h>
#include <QtQml>
#include <QQuickView>
#include <QQmlError>
#include <QQmlEngine>
#include <QQuickItem>
#include <QDBusConnection>
#include <QTranslator>
#include <QLocale>
#include <QDebug>
#include <QLoggingCategory>
#include <MDeclarativeCache>
#include "config.h"
#include "models/filtermodel.h"
#include "models/documentlistmodel.h"
#include "models/trackerdocumentprovider.h"
#include "models/documentprovider.h"
#include "dbusadaptor.h"
namespace {
QSharedPointer<QApplication> createApplication(int &argc, char **argv)
{
auto app = QSharedPointer<QApplication>(new QApplication(argc, argv));
//FIXME: We should be able to use a pure QGuiApplication but currently too much of
//Calligra depends on QApplication.
//QSharedPointer<QGuiApplication>(MDeclarativeCache::qApplication(argc, argv));
QTranslator *engineeringEnglish = new QTranslator(app.data());
if (!engineeringEnglish->load("sailfish-office_eng_en", TRANSLATION_INSTALL_DIR))
qWarning("Could not load engineering english translation file!");
QCoreApplication::installTranslator(engineeringEnglish);
QTranslator *translator = new QTranslator(app.data());
if (!translator->load(QLocale::system(), "sailfish-office", "-", TRANSLATION_INSTALL_DIR))
qWarning() << "Could not load translations for" << QLocale::system().name().toLatin1();
QCoreApplication::installTranslator(translator);
return app;
}
QSharedPointer<QQuickView> createView(const QString &file)
{
qmlRegisterType<DocumentListModel>("Sailfish.Office.Files", 1, 0, "DocumentListModel");
qmlRegisterType<TrackerDocumentProvider>("Sailfish.Office.Files", 1, 0, "TrackerDocumentProvider");
qmlRegisterType<FilterModel>("Sailfish.Office.Files", 1, 0, "FilterModel");
qmlRegisterInterface<DocumentProvider>("DocumentProvider");
QSharedPointer<QQuickView> view(MDeclarativeCache::qQuickView());
view->setSource(QUrl::fromLocalFile(QML_INSTALL_DIR + file));
new DBusAdaptor(view.data());
if (!QDBusConnection::sessionBus().registerObject("/org/sailfishos/Office", view.data()))
qWarning() << "Could not register /org/sailfishos/Office D-Bus object.";
if (!QDBusConnection::sessionBus().registerService("org.sailfishos.Office"))
qWarning() << "Could not register org.sailfishos.Office D-Bus service.";
return view;
}
}
Q_DECL_EXPORT int main(int argc, char *argv[])
{
// TODO: start using Silica booster
QQuickWindow::setDefaultAlphaBuffer(true);
if (!qgetenv("QML_DEBUGGING_ENABLED").isEmpty()) {
QQmlDebuggingEnabler qmlDebuggingEnabler;
}
auto app = createApplication(argc, argv);
// Note, these must be said now, otherwise some plugins using QSettings
// will get terribly confused when they fail to load properly.
app->setOrganizationName("org.sailfishos");
app->setApplicationName("Office");
auto view = createView("Main.qml");
//% "Documents"
Q_UNUSED(QT_TRID_NOOP("sailfish-office-ap-name"))
bool preStart = false;
bool debug = false;
QString fileName;
for (int i = 1; i < argc; ++i) {
QString parameter(argv[i]);
if (parameter == QStringLiteral("-prestart")) {
preStart = true;
} else if (parameter == QStringLiteral("-d")) {
debug = true;
} else if (fileName.isEmpty()) {
fileName = parameter;
}
}
if (!debug) {
// calligra is quite noisy by default
QLoggingCategory::setFilterRules("calligra.*.debug=false");
}
int retn = 1;
if (view->errors().count() == 0) {
if (!fileName.isEmpty()) {
QVariant fileNameParameter(fileName);
QMetaObject::invokeMethod(view->rootObject(), "openFile", Q_ARG(QVariant, fileNameParameter));
} else if (!preStart) {
view->showFullScreen();
}
retn = app->exec();
}
return retn;
}