Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | 5f316da | 2015-09-28 11:57:42 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015 by Savoir-faire Linux * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 3 | * 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 Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 23 | #include "aboutdialog.h" |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 24 | |
| 25 | #include "media/text.h" |
| 26 | #include "media/textrecording.h" |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 27 | |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 28 | #ifdef Q_OS_WIN32 |
| 29 | #include <windows.h> |
| 30 | #include <QWinThumbnailToolBar> |
| 31 | #include <QWinThumbnailToolButton> |
| 32 | #endif |
| 33 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 34 | MainWindow::MainWindow(QWidget *parent) : |
| 35 | QMainWindow(parent), |
| 36 | ui(new Ui::MainWindow) |
| 37 | { |
| 38 | ui->setupUi(this); |
| 39 | |
Edric Milaret | 18e8184 | 2015-04-29 13:51:36 -0400 | [diff] [blame] | 40 | QIcon icon(":images/ring.png"); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 41 | |
| 42 | this->setWindowIcon(icon); |
| 43 | |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 44 | GlobalSystemTray& sysIcon = GlobalSystemTray::instance(); |
| 45 | sysIcon.setIcon(icon); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 46 | |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 47 | 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 Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 63 | this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); |
| 64 | |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 65 | connect(CallModel::instance(), SIGNAL(incomingCall(Call*)), |
| 66 | this, SLOT(onIncomingCall(Call*))); |
| 67 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 68 | navStack_ = new NavStack(ui->bar, ui->stackedWidgetView, this); |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 69 | connect(configAction, &QAction::triggered, [this]() { |
| 70 | navStack_->onNavigationRequested(ScreenEnum::ConfScreen); |
| 71 | }); |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 72 | |
| 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 Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | MainWindow::~MainWindow() |
| 84 | { |
| 85 | delete ui; |
Edric Milaret | 01f2384 | 2015-06-22 14:46:01 -0400 | [diff] [blame] | 86 | delete navStack_; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 89 | bool |
| 90 | MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 91 | { |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 92 | Q_UNUSED(eventType) |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 93 | |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 94 | #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 Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 106 | } |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 107 | #endif |
| 108 | return false; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 112 | MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason) |
| 113 | { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 114 | if (reason != QSystemTrayIcon::ActivationReason::Context) |
| 115 | this->show(); |
| 116 | } |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 117 | |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 118 | void |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 119 | MainWindow::onIncomingCall(Call *call) |
| 120 | { |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 121 | Q_UNUSED(call); |
| 122 | QWidget::showNormal(); |
| 123 | } |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 124 | |
| 125 | void |
| 126 | MainWindow::createThumbBar() |
| 127 | { |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 128 | #ifdef Q_OS_WIN32 |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 129 | 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 Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame^] | 141 | #endif |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 142 | } |