blob: 8190f7ccc01727b274d1d46482fb991a3c2a2b2d [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
Edric Milaret5f316da2015-09-28 11:57:42 -04002 * Copyright (C) 2015 by Savoir-faire Linux *
Edric Milaret627500d2015-03-27 16:41:40 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
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 <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include "mainwindow.h"
20#include "ui_mainwindow.h"
21
22#include <QSizeGrip>
Edric Milareted0b2802015-10-01 15:10:02 -040023#include "aboutdialog.h"
Edric Milaret2cf34292015-06-22 16:27:03 -040024
25#include "media/text.h"
26#include "media/textrecording.h"
Edric Milaret627500d2015-03-27 16:41:40 -040027
Edric Milareted0b2802015-10-01 15:10:02 -040028#ifdef Q_OS_WIN32
29#include <windows.h>
30#include <QWinThumbnailToolBar>
31#include <QWinThumbnailToolButton>
32#endif
33
Edric Milaret627500d2015-03-27 16:41:40 -040034MainWindow::MainWindow(QWidget *parent) :
35 QMainWindow(parent),
36 ui(new Ui::MainWindow)
37{
38 ui->setupUi(this);
39
Edric Milaret18e81842015-04-29 13:51:36 -040040 QIcon icon(":images/ring.png");
Edric Milaret627500d2015-03-27 16:41:40 -040041
42 this->setWindowIcon(icon);
43
Edric Milaret2cf34292015-06-22 16:27:03 -040044 GlobalSystemTray& sysIcon = GlobalSystemTray::instance();
45 sysIcon.setIcon(icon);
Edric Milaret627500d2015-03-27 16:41:40 -040046
Edric Milaret2cf34292015-06-22 16:27:03 -040047 QMenu *menu = new QMenu();
48
49 auto configAction = new QAction("Configuration", this);
50 menu->addAction(configAction);
51
52 auto exitAction = new QAction("Exit", this);
53 connect(exitAction, &QAction::triggered, []() {
54 QCoreApplication::exit();
55 });
56
57 menu->addAction(exitAction);
58
59 sysIcon.setContextMenu(menu);
60 sysIcon.show();
61
62 connect(&sysIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
Edric Milaret627500d2015-03-27 16:41:40 -040063 this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
64
Edric Milaret3a23e492015-04-29 14:23:48 -040065 connect(CallModel::instance(), SIGNAL(incomingCall(Call*)),
66 this, SLOT(onIncomingCall(Call*)));
67
Edric Milaret627500d2015-03-27 16:41:40 -040068 navStack_ = new NavStack(ui->bar, ui->stackedWidgetView, this);
Edric Milaret2cf34292015-06-22 16:27:03 -040069 connect(configAction, &QAction::triggered, [this]() {
70 navStack_->onNavigationRequested(ScreenEnum::ConfScreen);
71 });
Edric Milareted0b2802015-10-01 15:10:02 -040072
73#ifdef Q_OS_WIN32
74 HMENU sysMenu = ::GetSystemMenu((HWND) winId(), FALSE);
75 if (sysMenu != NULL) {
76 ::AppendMenuA(sysMenu, MF_SEPARATOR, 0, 0);
77 QString aboutTitle = tr("About");
78 ::AppendMenuA(sysMenu, MF_STRING, IDM_ABOUTBOX, aboutTitle.toStdString().c_str());
79 }
80#endif
Edric Milaret627500d2015-03-27 16:41:40 -040081}
82
83MainWindow::~MainWindow()
84{
85 delete ui;
Edric Milaret01f23842015-06-22 14:46:01 -040086 delete navStack_;
Edric Milaret627500d2015-03-27 16:41:40 -040087}
88
Edric Milareted0b2802015-10-01 15:10:02 -040089bool
90MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
Edric Milaret627500d2015-03-27 16:41:40 -040091{
Edric Milareted0b2802015-10-01 15:10:02 -040092 Q_UNUSED(eventType)
Edric Milaret627500d2015-03-27 16:41:40 -040093
Edric Milareted0b2802015-10-01 15:10:02 -040094#ifdef Q_OS_WIN32
95 MSG *msg = (MSG*) message;
96
97 if (msg->message == WM_SYSCOMMAND) {
98 if ((msg->wParam & 0xfff0) == IDM_ABOUTBOX) {
99 *result = 0;
100
101 AboutDialog aboutDialog;
102 aboutDialog.exec();
103
104 return true;
105 }
Edric Milaret627500d2015-03-27 16:41:40 -0400106 }
Edric Milareted0b2802015-10-01 15:10:02 -0400107#endif
108 return false;
Edric Milaret627500d2015-03-27 16:41:40 -0400109}
110
111void
Edric Milaret2cf34292015-06-22 16:27:03 -0400112MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason)
113{
Edric Milaret627500d2015-03-27 16:41:40 -0400114 if (reason != QSystemTrayIcon::ActivationReason::Context)
115 this->show();
116}
Edric Milaret3a23e492015-04-29 14:23:48 -0400117
Edric Milaret4bba46d2015-04-29 16:33:38 -0400118void
Edric Milaret2cf34292015-06-22 16:27:03 -0400119MainWindow::onIncomingCall(Call *call)
120{
Edric Milaret3a23e492015-04-29 14:23:48 -0400121 Q_UNUSED(call);
122 QWidget::showNormal();
123}
Edric Milaret2cf34292015-06-22 16:27:03 -0400124
125void
126MainWindow::createThumbBar()
127{
Edric Milareted0b2802015-10-01 15:10:02 -0400128#ifdef Q_OS_WIN32
Edric Milaret2cf34292015-06-22 16:27:03 -0400129 QWinThumbnailToolBar *thumbbar = new QWinThumbnailToolBar(this);
130 thumbbar->setWindow(this->windowHandle());
131 QWinThumbnailToolButton *settings = new QWinThumbnailToolButton(thumbbar);
132 settings->setToolTip("Settings");
133 QIcon icon(":/images/settings.png");
134 settings->setIcon(icon);
135 settings->setDismissOnClick(true);
136 connect(settings, &QWinThumbnailToolButton::clicked, [this]() {
137 navStack_->onNavigationRequested(ScreenEnum::ConfScreen);
138 });
139
140 thumbbar->addButton(settings);
Edric Milareted0b2802015-10-01 15:10:02 -0400141#endif
Edric Milaret2cf34292015-06-22 16:27:03 -0400142}