76e755b1310239daee88ad715c2d9bce506925b4
[apps/mixer.git] / app / main.cpp
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016,2017 Konsulko Group
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "paclient.h"
19 #include "pacontrolmodel.h"
20
21 #include <QtCore/QDebug>
22 #include <QtCore/QDir>
23 #include <QtCore/QStandardPaths>
24 #include <QtCore/QThread>
25 #include <QtGui/QGuiApplication>
26 #include <QtQml/QQmlApplicationEngine>
27 #include <QtQml/QQmlContext>
28 #include <QtQml/qqml.h>
29 #include <QtQuickControls2/QQuickStyle>
30 #include <QtQuick/qquickitem.h>
31 #include <QtQuick/qquickview.h>
32
33
34 #ifdef HAVE_LIBHOMESCREEN
35 #include <libhomescreen.hpp>
36 #endif
37
38 int main(int argc, char *argv[])
39 {
40 #ifdef HAVE_LIBHOMESCREEN
41         LibHomeScreen libHomeScreen;
42
43         if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
44                 qWarning() << "renderAppToAreaAllowed is denied";
45                 return -1;
46         }
47 #endif
48
49         QGuiApplication app(argc, argv);
50
51         QQuickStyle::setStyle("AGL");
52
53         // Fire up PA client QThread
54         QThread* pat = new QThread;
55         PaClient* client = new PaClient();
56         client->moveToThread(pat);
57         pat->start();
58
59         // Register the PA Control Model
60         qmlRegisterType<PaControlModel>("PaControlModel", 1, 0, "PaControlModel");
61
62         QQmlApplicationEngine engine;
63         engine.load(QUrl(QStringLiteral("qrc:/Mixer.qml")));
64
65         // Find the instantiated model QObject and connect the signals/slots
66         QList<QObject *> mobjs = engine.rootObjects();
67         PaControlModel *pacm = mobjs.first()->findChild<PaControlModel *>("pacm");
68         QObject::connect(client, SIGNAL(controlAdded(int, QString, int, int, const char *, int)),
69                          pacm, SLOT(addOneControl(int, QString, int, int, const char *, int)));
70         QObject::connect(pacm, SIGNAL(volumeChanged(uint32_t, uint32_t, uint32_t, uint32_t)),
71                         client, SLOT(setVolume(uint32_t, uint32_t, uint32_t, uint32_t)));
72
73         // Initalize PA client
74         client->init();
75
76         return app.exec();
77 }