main.cpp 5.01 KB
Newer Older
armin's avatar
armin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QRect>
#include <QQmlContext>
#include <QSettings>
#include <QThread>
#include <QtMultimedia/QMediaRecorder>
#include <QtMultimedia/QAudioRecorder>
#include <QtMultimedia/QCamera>
#include <QtMultimedia/QVideoRendererControl>
#include <QImageReader>
#include <QImageReader>
#include <QQuickStyle>
#include <QDebug>
#include <QtGlobal>
#include "CustomModels/channelmodel.h"

#include "config.h"

#include "rocketchat.h"
#include "persistancelayer.h"
#include "rocketchatserver.h"
#include "notifications/notifications.h"
#include "CustomModels/usermodel.h"
25
#include "CustomModels/messagemodel.h"
armin's avatar
armin committed
26
#include "utils.h"
27
#include "serverselector.h"
armin's avatar
armin committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#ifdef Q_OS_ANDROID
    #include <signal.h>
    #include <stdio.h>
    #include <stdlib.h>

#endif

#ifdef Q_OS_WINRT

#endif


int main( int argc, char *argv[] )
{

armin's avatar
armin committed
44
45
    Q_INIT_RESOURCE(sql);

armin's avatar
armin committed
46
47
48
49
    QCoreApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
    QCoreApplication::setOrganizationName( ORGANIZATION );
    QCoreApplication::setOrganizationDomain( ORGANIZATIONDOMAIN );
    QCoreApplication::setApplicationName( APPLICATIONNAME );
armin's avatar
armin committed
50

armin's avatar
armin committed
51
52
53
    UserModel userModel;
    ChannelModel channelModel;
    ChannelModel groupsModel;
54
    MessagesModel messageModel;
armin's avatar
armin committed
55

armin's avatar
armin committed
56
57
58
    channelModel.moveToThread(QThread::currentThread());
    groupsModel.moveToThread(QThread::currentThread());
    userModel.moveToThread(QThread::currentThread());
59
    messageModel.moveToThread(QThread::currentThread());
armin's avatar
armin committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

    qDebug()<<"main thread: "<<QThread::currentThreadId();

    int result = EXIT_FAILURE;
    QGuiApplication app( argc, argv );

    PersistanceLayer *storage = PersistanceLayer::instance();

    QString cleanExit = storage->getSetting("cleanExit");
    if(cleanExit == "false"){
        qCritical()<<"app unclean exit last time";

        if(storage->getSetting("Error").length()){
            #ifdef Q_OS_ANDROID
            QAndroidJniObject errorStringJni = QAndroidJniObject::fromString(storage->getSetting("ERROR"));

76
            QAndroidJniObject::callStaticMethod<void>("com/osalliance/rocketchatMobile/MainActivity", "catchError","(Ljava/lang/String;)V",errorStringJni.object<jstring>());
armin's avatar
armin committed
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
            #endif
        }
    }
    storage->setSetting("cleanExit","false");
    storage->setSetting("ERROR","");

    QString language = QLocale::system().bcp47Name().split("-")[0].toLower();
    qDebug()<<"locale : "<<QLatin1String("qt_") + language;

    QTranslator myappTranslator;
    qDebug()<<"language code: "<<language;
    if(myappTranslator.load(QLatin1String(":/ucom_") + language)){
        qWarning()<<"loaded translation file: "<<"ucom_"+language;
        app.installTranslator(&myappTranslator);
    }else{
        qWarning()<<"could not open translation file: "<<"ucom_"+language;
    }

    QTranslator qtTranslator3;

    if(qtTranslator3.load(QLatin1String(":/translations/qtquickcontrols_") + language)){
        qWarning()<<"loaded translation file: "<<"qtquickcontrols_"+language;
        app.installTranslator(&qtTranslator3);
    }else{
        qWarning()<<"could not open translation file: "<<"qtquickcontrols_"+language;
    }
103

armin's avatar
armin committed
104
105
106
107
108
    QQmlApplicationEngine engine;

    QSharedPointer<RocketChatServerData> server(
                new RocketChatServerData( "testUcomServer", SERVERADRESS,
                                          "https://" + QString( SERVERADRESS ) + "/api/v1",
109
                                          userModel, channelModel, groupsModel, groupsModel,messageModel )
armin's avatar
armin committed
110
111
                );
    RocketChat rocketChat( &app );
112
113
114
    ServerSelector serverSelector(server);
    QObject::connect(&serverSelector,&ServerSelector::serverSelected,&rocketChat,&RocketChat::registerServer);
    //rocketChat.registerServer( server );
armin's avatar
armin committed
115
116
117
118
119
120
121

    QQmlContext *context = engine.rootContext();

    QString buildTime(__TIME__ );
    QString buildDate(__DATE__ );
    QString serverAdress(SERVERADRESS);
    context->setContextProperty( "rocketChatController", &rocketChat );
122
    context->setContextProperty( "serverSelector", &serverSelector );
armin's avatar
armin committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifdef QT_DEBUG
    context->setContextProperty( "debug", QVariant(true) );
#else
    context->setContextProperty( "debug", QVariant(false) );
#endif
    context->setContextProperty("buildTime",QVariant(buildTime));
    context->setContextProperty("userModel",&userModel);
    context->setContextProperty("channelModel",&channelModel);
    context->setContextProperty("groupsModel",&groupsModel);
    context->setContextProperty("directModel",&groupsModel);
    context->setContextProperty("buildDate",QVariant(buildDate));
    context->setContextProperty("version",QVariant(VERSION));
    context->setContextProperty("serverAdress",QVariant(serverAdress));
    context->setContextProperty("pathPrefix", Utils::getPathPrefix());
137
    context->setContextProperty("cmessagesModel", &messageModel);
armin's avatar
armin committed
138
139
140
141
142
143
144
145
146
147
148

    engine.load( QUrl( QLatin1String( "qrc:/qml/main.qml" ) ) );

    try {
        result =  app.exec();
        storage->setSetting("cleanExit","true");
    } catch (const std::exception &ex) {
        qCritical()<<ex.what();
    }
    return result;
}