sailfish-safe

Sailfish frontend for safe(1)
git clone git://git.z3bra.org/sailfish-safe.git
Log | Files | Refs | README | LICENSE

main.cpp (2814B)


      1 /*
      2  *   Copyright (C) 2019  Daniel Vrátil <dvratil@kde.org>
      3  *                 2021  Willy Goiffon <contact@z3bra.org>
      4  *
      5  *   This program is free software: you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation, either version 3 of the License, or
      8  *   (at your option) any later version.
      9  *
     10  *   This program is distributed in the hope that it will be useful,
     11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  *   GNU General Public License for more details.
     14  *
     15  *   You should have received a copy of the GNU General Public License
     16  *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17  */
     18 
     19 #include "passwordsmodel.h"
     20 #include "passwordfiltermodel.h"
     21 #include "passwordsortproxymodel.h"
     22 #include "passwordgenerator.h"
     23 #include "imageprovider.h"
     24 #include "scopeguard.h"
     25 #include "settings.h"
     26 
     27 #include <QQuickView>
     28 #include <QQmlEngine>
     29 #include <QGuiApplication>
     30 #include <QScopedPointer>
     31 
     32 #include <sailfishapp.h>
     33 
     34 void addImageProvider(QQmlEngine *engine, const QString &id)
     35 {
     36     engine->addImageProvider(id, new ImageProvider(id));
     37 }
     38 
     39 int main(int argc, char *argv[])
     40 {
     41     QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
     42     app->setApplicationDisplayName(QObject::tr("Safe"));
     43     app->setApplicationName(QStringLiteral("safe"));
     44     app->setApplicationVersion(QStringLiteral(SAFE_VERSION));
     45     app->setOrganizationName(QObject::tr("Willy GOiffon"));
     46 
     47     QScopedPointer<QQuickView> view(SailfishApp::createView());
     48     const auto settingsGuard = scopeGuard([]() {
     49         Settings::destroy();
     50     });
     51 
     52     qmlRegisterType<PasswordsModel>("harbour.safe", 0, 1, "PasswordsModel");
     53     qmlRegisterType<PasswordFilterModel>("harbour.safe", 0, 1, "PasswordFilterModel");
     54     qmlRegisterType<PasswordSortProxyModel>("harbour.safe", 0, 1, "PasswordSortProxyModel");
     55     qmlRegisterSingletonType<Settings>("harbour.safe", 0, 1, "Settings",
     56                                        [](QQmlEngine *, QJSEngine *) -> QObject* {
     57                                             return Settings::self();
     58                                        });
     59     qmlRegisterSingletonType<PasswordGenerator>("harbour.safe", 0, 1, "PasswordGenerator",
     60                                                 [](QQmlEngine *, QJSEngine *) -> QObject* {
     61                                                     return new PasswordGenerator;
     62                                                 });
     63 
     64     addImageProvider(view->engine(), QStringLiteral("passIcon"));
     65     addImageProvider(view->engine(), QStringLiteral("passImage"));
     66     view->setSource(SailfishApp::pathToMainQml());
     67     view->show();
     68 
     69     return app->exec();
     70 }