Using the Tizen application manager to receive information about installed apps and...
[staging/HomeScreen.git] / HomeScreen / src / mainwindow.cpp
1 /*
2  * Copyright (C) 2016 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_dBusDayNightModeProxy(0),
30     mp_homeScreenControlInterface(0)
31 {
32     // this has to be adopted to the system setup
33     mp_dBusDayNightModeProxy = new org::agl::daynightmode("org.agl.homescreen.simulator", //"org.agl.systeminfoprovider"
34                                                       "/",
35                                                       QDBusConnection::sessionBus(),
36                                                       0);
37     QObject::connect(mp_dBusDayNightModeProxy, SIGNAL(dayNightMode(int)), this, SLOT(dayNightModeSlot(int)));
38
39     // dbus setup
40     QDBusConnection dbus = QDBusConnection::sessionBus();
41
42     dbus.registerObject("/MainWindow", this);
43     dbus.registerService("org.agl.homescreen");
44
45     // no window decoration
46     setWindowFlags(Qt::FramelessWindowHint);
47
48     mp_ui->setupUi(this);
49
50     mp_statusBarWidget = new StatusBarWidget(this);
51     mp_statusBarWidget->raise();
52     // apply layout
53     mp_statusBarWidget->move(0, 0);
54
55     mp_controlBarWidget = new ControlBarWidget(this);
56     mp_controlBarWidget->raise();
57     // apply layout
58     mp_controlBarWidget->move(0, 1920-60);
59
60     mp_settingsWidget = new SettingsWidget(this);
61     mp_settingsWidget->raise();
62     // apply layout
63     mp_settingsWidget->move(0, 60);
64     //mp_settingsWidget->hide();
65
66     mp_applauncherwidget = new AppLauncherWidget(this);
67     mp_applauncherwidget->raise();
68     // apply layout
69     mp_applauncherwidget->move(0, 60);
70
71     mp_popupWidget = new PopupWidget();
72     mp_controlBarWidget->raise();
73     // apply layout
74     mp_popupWidget->move(0, 0);
75
76
77     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), this, SLOT(updateColorScheme()));
78     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), mp_statusBarWidget, SLOT(updateColorScheme()));
79     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), mp_controlBarWidget, SLOT(updateColorScheme()));
80     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), mp_settingsWidget, SLOT(updateColorScheme()));
81     QObject::connect(mp_settingsWidget, SIGNAL(colorSchemeChanged()), mp_popupWidget, SLOT(updateColorScheme()));
82
83     QObject::connect(mp_controlBarWidget, SIGNAL(settingsButtonPressed()), mp_settingsWidget, SLOT(raise()));
84     QObject::connect(mp_controlBarWidget, SIGNAL(homeButtonPressed()), mp_applauncherwidget, SLOT(raise()));
85
86     // apply color scheme
87     updateColorScheme();
88     mp_statusBarWidget->updateColorScheme();
89     mp_controlBarWidget->updateColorScheme();
90     mp_settingsWidget->updateColorScheme();
91     mp_applauncherwidget->updateColorScheme();
92     mp_popupWidget->updateColorScheme();
93
94     // this is only useful during development and will be removed later
95     setWindowIcon(QIcon(":/icons/home_day.png"));
96
97     mp_homeScreenControlInterface = new HomeScreenControlInterface(this);
98 }
99
100 MainWindow::~MainWindow()
101 {
102     delete mp_homeScreenControlInterface;
103
104     delete mp_dBusDayNightModeProxy;
105     delete mp_popupWidget;
106     delete mp_applauncherwidget;
107     delete mp_settingsWidget;
108     delete mp_controlBarWidget;
109     delete mp_statusBarWidget;
110     delete mp_ui;
111 }
112
113 void MainWindow::dayNightModeSlot(int mode)
114 {
115     QSettings settings;
116     settings.setValue("systemsettings/daynightmode", mode);
117     // make sure that everything is written to the settings file before continuing
118     settings.sync();
119
120     updateColorScheme();
121
122     mp_statusBarWidget->updateColorScheme();
123     mp_controlBarWidget->updateColorScheme();
124     mp_settingsWidget->updateColorScheme();
125     mp_applauncherwidget->updateColorScheme();
126     mp_popupWidget->updateColorScheme();
127 }
128
129 void MainWindow::updateColorScheme()
130 {
131     QSettings settings;
132     QSettings settings_cs(QApplication::applicationDirPath() +
133                           "/colorschemes/" +
134                           settings.value("systemsettings/colorscheme", "default").toString() +
135                           "/" +
136                           QString::number(settings.value("systemsettings/daynightmode", SystemDayNight::DAYNIGHTMODE_DAY).toInt()) +
137                           ".ini",
138                           QSettings::IniFormat);
139
140     mp_ui->widget_Background->setStyleSheet(settings_cs.value("MainWindow/widget_Background").toString());
141     mp_ui->widget_Home_Icon->setStyleSheet(settings_cs.value("MainWindow/widget_Home_Icon").toString());
142 }
143
144 void MainWindow::changeEvent(QEvent* event)
145 {
146     if (QEvent::LanguageChange == event->type())
147     {
148         mp_ui->retranslateUi(this);
149     }
150
151     QMainWindow::changeEvent(event);
152 }
153
154 void MainWindow::on_pushButton_clicked()
155 {
156     // start app
157     QProcess process;
158         QString file = "vlc";
159         process.startDetached(file);
160     // manage ivi shell
161 }