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 "mainbar.h" |
| 20 | #include "ui_mainbar.h" |
| 21 | |
Edric Milaret | b25af97 | 2015-06-17 16:55:45 -0400 | [diff] [blame] | 22 | #include <QSettings> |
| 23 | #include <QMessageBox> |
| 24 | |
| 25 | #include "settingskey.h" |
| 26 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 27 | #include "callmodel.h" |
| 28 | #include "aboutdialog.h" |
| 29 | |
| 30 | MainBar::MainBar(QWidget *parent) : |
| 31 | NavWidget(END, parent), |
| 32 | ui(new Ui::MainBar), |
| 33 | menu_(new QMenu()) |
| 34 | { |
| 35 | ui->setupUi(this); |
| 36 | |
Edric Milaret | 53ac6e5 | 2015-09-14 13:37:06 -0400 | [diff] [blame] | 37 | auto aboutAction = new QAction(tr("About"), this); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 38 | menu_->addAction(aboutAction); |
| 39 | connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutDialog())); |
| 40 | |
Edric Milaret | 53ac6e5 | 2015-09-14 13:37:06 -0400 | [diff] [blame] | 41 | auto exitAction = new QAction(tr("Exit"), this); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 42 | menu_->addAction(exitAction); |
| 43 | connect(exitAction, SIGNAL(triggered()), this, SLOT(on_exitButton_clicked())); |
| 44 | |
| 45 | ui->logoToolButton->setMenu(menu_); |
| 46 | ui->logoToolButton->setPopupMode(QToolButton::InstantPopup); |
| 47 | } |
| 48 | |
| 49 | MainBar::~MainBar() |
| 50 | { |
| 51 | delete ui; |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | MainBar::on_confButton_clicked() |
| 56 | { |
| 57 | emit NavigationRequested(ScreenEnum::ConfScreen); |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | MainBar::on_callLineEdit_returnPressed() |
| 62 | { |
| 63 | callAction(); |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | MainBar::on_callButton_clicked() |
| 68 | { |
| 69 | callAction(); |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | MainBar::callAction() { |
| 74 | if (ui->callLineEdit->text().isEmpty()) |
| 75 | return; |
| 76 | auto outCall = CallModel::instance()->dialingCall(ui->callLineEdit->text()); |
| 77 | outCall->setDialNumber(ui->callLineEdit->text()); |
| 78 | outCall->performAction(Call::Action::ACCEPT); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | MainBar::showAboutDialog() { |
| 83 | AboutDialog *aboutDialog = new AboutDialog(); |
| 84 | |
| 85 | aboutDialog->exec(); |
| 86 | |
| 87 | delete aboutDialog; |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | MainBar::on_exitButton_clicked() |
| 92 | { |
Edric Milaret | b25af97 | 2015-06-17 16:55:45 -0400 | [diff] [blame] | 93 | QSettings settings; |
| 94 | |
| 95 | if (not settings.value(SettingsKey::closeOrMinimized).isValid()) { |
| 96 | QMessageBox confirmationDialog; |
| 97 | |
| 98 | confirmationDialog.setText("Do you want to keep Ring minimized ?"); |
| 99 | confirmationDialog.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); |
| 100 | auto ret = confirmationDialog.exec(); |
| 101 | |
| 102 | if (ret == QMessageBox::Ok) |
| 103 | settings.setValue(SettingsKey::closeOrMinimized, true); |
Edric Milaret | e0bda41 | 2015-09-25 12:33:14 -0400 | [diff] [blame] | 104 | else |
| 105 | settings.setValue(SettingsKey::closeOrMinimized, false); |
Edric Milaret | b25af97 | 2015-06-17 16:55:45 -0400 | [diff] [blame] | 106 | } |
| 107 | if (settings.value(SettingsKey::closeOrMinimized).toBool() == true) |
| 108 | emit minimize(); |
| 109 | else |
| 110 | QCoreApplication::exit(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void |
| 114 | MainBar::on_minimizeButton_clicked() |
| 115 | { |
| 116 | emit minimize(); |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | MainBar::atExit() { |
| 121 | |
| 122 | } |