blob: 4a0b231552b9219cc8ddff530d1d0cd30120d05d [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 "mainbar.h"
20#include "ui_mainbar.h"
21
Edric Milaretb25af972015-06-17 16:55:45 -040022#include <QSettings>
23#include <QMessageBox>
24
25#include "settingskey.h"
26
Edric Milaret627500d2015-03-27 16:41:40 -040027#include "callmodel.h"
28#include "aboutdialog.h"
29
30MainBar::MainBar(QWidget *parent) :
31 NavWidget(END, parent),
32 ui(new Ui::MainBar),
33 menu_(new QMenu())
34{
35 ui->setupUi(this);
36
Edric Milaret53ac6e52015-09-14 13:37:06 -040037 auto aboutAction = new QAction(tr("About"), this);
Edric Milaret627500d2015-03-27 16:41:40 -040038 menu_->addAction(aboutAction);
39 connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
40
Edric Milaret53ac6e52015-09-14 13:37:06 -040041 auto exitAction = new QAction(tr("Exit"), this);
Edric Milaret627500d2015-03-27 16:41:40 -040042 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
49MainBar::~MainBar()
50{
51 delete ui;
52}
53
54void
55MainBar::on_confButton_clicked()
56{
57 emit NavigationRequested(ScreenEnum::ConfScreen);
58}
59
60void
61MainBar::on_callLineEdit_returnPressed()
62{
63 callAction();
64}
65
66void
67MainBar::on_callButton_clicked()
68{
69 callAction();
70}
71
72void
73MainBar::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
81void
82MainBar::showAboutDialog() {
83 AboutDialog *aboutDialog = new AboutDialog();
84
85 aboutDialog->exec();
86
87 delete aboutDialog;
88}
89
90void
91MainBar::on_exitButton_clicked()
92{
Edric Milaretb25af972015-06-17 16:55:45 -040093 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 Milarete0bda412015-09-25 12:33:14 -0400104 else
105 settings.setValue(SettingsKey::closeOrMinimized, false);
Edric Milaretb25af972015-06-17 16:55:45 -0400106 }
107 if (settings.value(SettingsKey::closeOrMinimized).toBool() == true)
108 emit minimize();
109 else
110 QCoreApplication::exit();
Edric Milaret627500d2015-03-27 16:41:40 -0400111}
112
113void
114MainBar::on_minimizeButton_clicked()
115{
116 emit minimize();
117}
118
119void
120MainBar::atExit() {
121
122}