Additional parameter to WindowManager at application startup
[apps/homescreen.git] / homescreen / src / mainwindow.cpp
1 /*
2  * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "mainwindow.h"
18 #include "ui_mainwindow.h"
19 #include <include/daynightmode.hpp>
20
21 MainWindow::MainWindow(QWidget *parent) :
22     QMainWindow(parent),
23     mp_ui(new Ui::MainWindow),
24     mp_statusBarWidget(0),
25     mp_controlBarWidget(0),
26     mp_settingsWidget(0),
27     //mp_applauncherwidget(0),
28     mp_popupWidget(0),
29     mp_layoutHandler(new LayoutHandler()),
30     mp_dBusDayNightModeProxy(0),
31     mp_proximityAdaptor(0),
32     mp_homeScreenControlInterface(0)
33 {
34     // this has to be adopted to the system setup
35     mp_dBusDayNightModeProxy = new org::agl::daynightmode("org.agl.homescreen.simulator", //"org.agl.systeminfoprovider"
36                                                       "/",
37                                                       QDBusConnection::sessionBus(),
38                                                       0);
39     QObject::connect(mp_dBusDayNightModeProxy, SIGNAL(dayNightMode(int)), this, SLOT(dayNightModeSlot(int)));
40
41     mp_proximityAdaptor = new ProximityAdaptor((QObject*)this);
42
43     // dbus setup
44     QDBusConnection dbus = QDBusConnection::sessionBus();
45     dbus.registerObject("/Proximity", this);
46     dbus.registerService("org.agl.homescreen");
47
48     // no window decoration
49     setWindowFlags(Qt::FramelessWindowHint);
50
51     mp_ui->setupUi(this);
52
53     mp_statusBarWidget = new StatusBarWidget(this);
54     mp_statusBarWidget->raise();
55     // apply layout
56     mp_statusBarWidget->move(0, 0);
57
58     mp_controlBarWidget = new ControlBarWidget(this);
59     mp_controlBarWidget->raise();
60     // apply layout
61     mp_controlBarWidget->move(0, 1920-60);
62
63     mp_settingsWidget = new SettingsWidget(this);
64     mp_settingsWidget->raise();
65     // apply layout
66     mp_settingsWidget->move(0, 60);
67     //mp_settingsWidget->hide();
68
69     /*mp_applauncherwidget = new AppLauncherWidget(this);
70     mp_applauncherwidget->raise();
71     // apply layout
72     mp_applauncherwidget->move(0, 60);*/
73
74
75     mp_popupWidget = new PopupWidget();
76     mp_controlBarWidget->raise();
77     // apply layout
78     mp_popupWidget->move(0, 0);
79
80
81     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), this, SLOT(updateColorScheme()));
82     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), mp_statusBarWidget, SLOT(updateColorScheme()));
83     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), mp_controlBarWidget, SLOT(updateColorScheme()));
84     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), mp_settingsWidget, SLOT(updateColorScheme()));
85     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), mp_popupWidget, SLOT(updateColorScheme()));
86
87     QObject::connect(mp_controlBarWidget, SIGNAL(settingsButtonPressed()), mp_settingsWidget, SLOT(raise()));
88     //QObject::connect(mp_controlBarWidget, SIGNAL(homeButtonPressed()), mp_applauncherwidget, SLOT(raise()));
89     QObject::connect(mp_controlBarWidget, SIGNAL(hideAppLayer()), mp_layoutHandler, SLOT(hideAppLayer()));
90
91     //QObject::connect(mp_applauncherwidget, SIGNAL(newRequestsToBeVisibleApp(int)), mp_layoutHandler, SLOT(makeMeVisible(int)));
92     //QObject::connect(mp_applauncherwidget, SIGNAL(showAppLayer()), mp_layoutHandler, SLOT(showAppLayer()));
93
94
95     // apply color scheme
96     updateColorScheme();
97
98     // this is only useful during development and will be removed later
99     setWindowIcon(QIcon(":/icons/home_day.png"));
100
101    // mp_applauncherwidget->populateAppList();
102     //mp_layoutHandler->setUpLayouts();
103
104     mp_homeScreenControlInterface = new HomeScreenControlInterface(this);
105     //    QObject::connect(mp_homeScreenControlInterface, SIGNAL(newRequestGetAllSurfacesOfProcess(int)), mp_layoutHandler, SLOT(requestGetAllSurfacesOfProcess(int)));
106     QObject::connect(mp_homeScreenControlInterface, SIGNAL(newRequestGetSurfaceStatus(int)), mp_layoutHandler, SLOT(requestGetSurfaceStatus(int)));
107     QObject::connect(mp_homeScreenControlInterface, SIGNAL(newRequestsToBeVisibleApp(int)), mp_layoutHandler, SLOT(makeMeVisible(int)));
108     QObject::connect(mp_homeScreenControlInterface, SIGNAL(newRequestRenderSurfaceToArea(int, int)), mp_layoutHandler, SLOT(requestRenderSurfaceToArea(int,int)));
109     QObject::connect(mp_homeScreenControlInterface, SIGNAL(newRequestRenderSurfaceToAreaAllowed(int, int)), mp_layoutHandler, SLOT(requestRenderSurfaceToAreaAllowed(int,int)));
110     QObject::connect(mp_homeScreenControlInterface, SIGNAL(newRequestSurfaceIdToFullScreen(int)), mp_layoutHandler, SLOT(requestSurfaceIdToFullScreen(int)));
111
112     QObject::connect(mp_popupWidget, SIGNAL(comboBoxResult(QString)), mp_layoutHandler, SLOT(setLayoutByName(QString)));
113 }
114
115 MainWindow::~MainWindow()
116 {
117     delete mp_homeScreenControlInterface;
118
119     delete mp_dBusDayNightModeProxy;
120
121     delete mp_layoutHandler;
122
123     delete mp_popupWidget;
124     //delete mp_applauncherwidget;
125     delete mp_settingsWidget;
126     delete mp_controlBarWidget;
127     delete mp_statusBarWidget;
128     delete mp_proximityAdaptor;
129     delete mp_ui;
130 }
131
132 void MainWindow::dayNightModeSlot(int mode)
133 {
134     QSettings settings;
135     settings.setValue("systemsettings/daynightmode", mode);
136     // make sure that everything is written to the settings file before continuing
137     settings.sync();
138
139     updateColorScheme();
140 }
141
142 void MainWindow::setObjectDetected(bool detected)
143 {
144     qDebug("setObjectDetected %s", detected ? "true" : "false");
145     QSettings settings;
146     settings.setValue("systemsettings/proximityobjectdetected", detected);
147     // make sure that everything is written to the settings file before continuing
148     settings.sync();
149
150     updateColorScheme();
151 }
152
153 void MainWindow::updateColorScheme()
154 {
155     QSettings settings;
156     QSettings settings_cs(QApplication::applicationDirPath() +
157                           "/colorschemes/" +
158                           settings.value("systemsettings/colorscheme", "default").toString() +
159                           "/" +
160                           QString::number(settings.value("systemsettings/proximityobjectdetected", false).toBool()) +
161                           "/" +
162                           QString::number(settings.value("systemsettings/daynightmode", SystemDayNight::DAYNIGHTMODE_DAY).toInt()) +
163                           ".ini",
164                           QSettings::IniFormat);
165
166     mp_ui->widget_background->setStyleSheet(settings_cs.value("MainWindow/widget_background_css").toString());
167     mp_ui->widget_homeIcon->setStyleSheet(settings_cs.value("MainWindow/widget_homeIcon_css").toString());
168
169     // update children
170     mp_statusBarWidget->updateColorScheme();
171     mp_controlBarWidget->updateColorScheme();
172     mp_settingsWidget->updateColorScheme();
173     //mp_applauncherwidget->updateColorScheme();
174     mp_popupWidget->updateColorScheme();
175 }
176
177 void MainWindow::changeEvent(QEvent* event)
178 {
179     if (QEvent::LanguageChange == event->type())
180     {
181         mp_ui->retranslateUi(this);
182     }
183
184     QMainWindow::changeEvent(event);
185 }
186