mainbar.cpp 3.48 KB
Newer Older
Edric Milaret's avatar
Edric Milaret committed
1
/***************************************************************************
Edric Milaret's avatar
Edric Milaret committed
2
 * Copyright (C) 2015 by Savoir-faire Linux                                *
Edric Milaret's avatar
Edric Milaret committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
 *                                                                         *
 * This program is free software; you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License as published by    *
 * the Free Software Foundation; either version 3 of the License, or       *
 * (at your option) any later version.                                     *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License       *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 **************************************************************************/

#include "mainbar.h"
#include "ui_mainbar.h"

22 23 24 25 26
#include <QSettings>
#include <QMessageBox>

#include "settingskey.h"

Edric Milaret's avatar
Edric Milaret committed
27 28 29 30 31 32 33 34 35 36
#include "callmodel.h"
#include "aboutdialog.h"

MainBar::MainBar(QWidget *parent) :
    NavWidget(END, parent),
    ui(new Ui::MainBar),
    menu_(new QMenu())
{
    ui->setupUi(this);

37
    auto aboutAction = new QAction(tr("About"), this);
Edric Milaret's avatar
Edric Milaret committed
38 39 40
    menu_->addAction(aboutAction);
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutDialog()));

41
    auto exitAction = new QAction(tr("Exit"), this);
Edric Milaret's avatar
Edric Milaret committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    menu_->addAction(exitAction);
    connect(exitAction, SIGNAL(triggered()), this, SLOT(on_exitButton_clicked()));

    ui->logoToolButton->setMenu(menu_);
    ui->logoToolButton->setPopupMode(QToolButton::InstantPopup);
}

MainBar::~MainBar()
{
    delete ui;
}

void
MainBar::on_confButton_clicked()
{
    emit NavigationRequested(ScreenEnum::ConfScreen);
}

void
MainBar::on_callLineEdit_returnPressed()
{
    callAction();
}

void
MainBar::on_callButton_clicked()
{
    callAction();
}

void
MainBar::callAction() {
    if (ui->callLineEdit->text().isEmpty())
        return;
    auto outCall = CallModel::instance()->dialingCall(ui->callLineEdit->text());
    outCall->setDialNumber(ui->callLineEdit->text());
    outCall->performAction(Call::Action::ACCEPT);
}

void
MainBar::showAboutDialog() {
    AboutDialog *aboutDialog = new AboutDialog();

    aboutDialog->exec();

    delete aboutDialog;
}

void
MainBar::on_exitButton_clicked()
{
93 94 95 96 97 98 99 100 101 102 103
    QSettings settings;

    if (not settings.value(SettingsKey::closeOrMinimized).isValid()) {
        QMessageBox confirmationDialog;

        confirmationDialog.setText("Do you want to keep Ring minimized ?");
        confirmationDialog.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
        auto ret = confirmationDialog.exec();

        if (ret == QMessageBox::Ok)
            settings.setValue(SettingsKey::closeOrMinimized, true);
104 105
        else
            settings.setValue(SettingsKey::closeOrMinimized, false);
106 107 108 109 110
    }
    if (settings.value(SettingsKey::closeOrMinimized).toBool() == true)
        emit minimize();
    else
        QCoreApplication::exit();
Edric Milaret's avatar
Edric Milaret committed
111 112 113 114 115 116 117 118 119 120 121 122
}

void
MainBar::on_minimizeButton_clicked()
{
    emit minimize();
}

void
MainBar::atExit() {

}