| 1 | /* |
| 2 | * Copyright (C) 2013-2015 Canonical Ltd. |
| 3 | * |
| 4 | * Contact: Alberto Mardegan <[email protected]> |
| 5 | * |
| 6 | * This file is part of lomiri-online-accounts-ui |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License version 3, as published |
| 10 | * by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <online-accounts-common/debug.h> |
| 22 | #include <online-accounts-common/globals.h> |
| 23 | #include <online-accounts-common/i18n.h> |
| 24 | #include "ui-server.h" |
| 25 | |
| 26 | #include <QGuiApplication> |
| 27 | #include <QLibrary> |
| 28 | #include <QProcessEnvironment> |
| 29 | #include <QSettings> |
| 30 | #include <sys/apparmor.h> |
| 31 | |
| 32 | using namespace OnlineAccountsUi; |
| 33 | |
| 34 | int main(int argc, char **argv) |
| 35 | { |
| 36 | QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); |
| 37 | QGuiApplication app(argc, argv); |
| 38 | |
| 39 | /* The testability driver is only loaded by QApplication but not by |
| 40 | * QGuiApplication. However, QApplication depends on QWidget which would |
| 41 | * add some unneeded overhead => Let's load the testability driver on our |
| 42 | * own. |
| 43 | */ |
| 44 | if (getenv("QT_LOAD_TESTABILITY")) { |
| 45 | QLibrary testLib(QStringLiteral("qttestability")); |
| 46 | if (testLib.load()) { |
| 47 | typedef void (*TasInitialize)(void); |
| 48 | TasInitialize initFunction = |
| 49 | (TasInitialize)testLib.resolve("qt_testability_init"); |
| 50 | if (initFunction) { |
| 51 | initFunction(); |
| 52 | } else { |
| 53 | qCritical("Library qttestability resolve failed!"); |
| 54 | } |
| 55 | } else { |
| 56 | qCritical("Library qttestability load failed!"); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | QSettings settings("lomiri-online-accounts-service"); |
| 61 | |
| 62 | /* read environment variables */ |
| 63 | QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); |
| 64 | if (environment.contains(QLatin1String("OAU_LOGGING_LEVEL"))) { |
| 65 | bool isOk; |
| 66 | int value = environment.value( |
| 67 | QLatin1String("OAU_LOGGING_LEVEL")).toInt(&isOk); |
| 68 | if (isOk) |
| 69 | setLoggingLevel(value); |
| 70 | } else { |
| 71 | setLoggingLevel(settings.value("LoggingLevel", 1).toInt()); |
| 72 | } |
| 73 | |
| 74 | initTr(LOA_I18N_DOMAIN, NULL); |
| 75 | |
| 76 | QString socket; |
| 77 | QString profile; |
| 78 | QStringList arguments = app.arguments(); |
| 79 | for (int i = 0; i < arguments.count(); i++) { |
| 80 | const QString &arg = arguments[i]; |
| 81 | if (arg == "--socket") { |
| 82 | socket = arguments.value(++i); |
| 83 | } else if (arg == "--profile") { |
| 84 | profile = arguments.value(++i); |
| 85 | } |
| 86 | } |
| 87 | if (Q_UNLIKELY(socket.isEmpty())) { |
| 88 | qWarning() << "Missing --socket argument"; |
| 89 | return EXIT_FAILURE; |
| 90 | } |
| 91 | |
| 92 | if (!profile.isEmpty()) { |
| 93 | aa_change_profile(profile.toUtf8().constData()); |
| 94 | } |
| 95 | |
| 96 | UiServer server(socket); |
| 97 | QObject::connect(&server, SIGNAL(finished()), |
| 98 | &app, SLOT(quit())); |
| 99 | if (Q_UNLIKELY(!server.init())) { |
| 100 | qWarning() << "Could not connect to socket"; |
| 101 | return EXIT_FAILURE; |
| 102 | } |
| 103 | |
| 104 | return app.exec(); |
| 105 | } |