mainwindow.cpp 5.45 KB
Newer Older
1
/***************************************************************************
2
 * Copyright (C) 2015-2016 by Savoir-faire Linux                                *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * 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 "mainwindow.h"
#include "ui_mainwindow.h"

#include <QSizeGrip>
23 24 25

#include "media/text.h"
#include "media/textrecording.h"
26

27 28 29 30 31 32
#ifdef Q_OS_WIN32
#include <windows.h>
#include <QWinThumbnailToolBar>
#include <QWinThumbnailToolButton>
#endif

33 34 35
#include "aboutdialog.h"
#include "mainwindowtoolbar.h"

36 37 38 39
#ifdef ENABLE_AUTOUPDATE
#include "winsparkle.h"
#endif

40 41
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
42 43
    ui(new Ui::MainWindow),
    mwToolBar_(new MainWindowToolBar)
44 45 46
{
    ui->setupUi(this);

47
    QIcon icon(":images/ring.png");
48 49 50

    this->setWindowIcon(icon);

51 52 53 54 55 56 57 58 59 60 61 62
    GlobalSystemTray& sysIcon = GlobalSystemTray::instance();
    sysIcon.setIcon(icon);

    QMenu *menu = new QMenu();

    auto configAction = new QAction("Configuration", this);
    menu->addAction(configAction);

    sysIcon.setContextMenu(menu);
    sysIcon.show();

    connect(&sysIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
63 64
            this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));

Edric Milaret's avatar
Edric Milaret committed
65
    connect(&CallModel::instance(), SIGNAL(incomingCall(Call*)),
66 67
            this, SLOT(onIncomingCall(Call*)));

68
    navStack_ = new NavStack(ui->bar, ui->stackedWidgetView, this);
69 70 71
    connect(configAction, &QAction::triggered, [this]() {
        navStack_->onNavigationRequested(ScreenEnum::ConfScreen);
    });
72 73 74 75 76 77 78 79 80

#ifdef Q_OS_WIN32
    HMENU sysMenu = ::GetSystemMenu((HWND) winId(), FALSE);
    if (sysMenu != NULL) {
        ::AppendMenuA(sysMenu, MF_SEPARATOR, 0, 0);
        QString aboutTitle = tr("About");
        ::AppendMenuA(sysMenu, MF_STRING, IDM_ABOUTBOX, aboutTitle.toStdString().c_str());
    }
#endif
81 82 83 84 85 86 87 88 89 90 91 92 93

    resize(1054, 600);

    addToolBar(static_cast<QToolBar*>(mwToolBar_));

    auto callWidget = static_cast<CallWidget*>(navStack_->getNavWidget(ScreenEnum::CallScreen));

    connect(mwToolBar_->getSettingsButton(), &QAction::triggered,
            callWidget, &CallWidget::on_settingsButton_clicked);
    connect(mwToolBar_->getHistoryButton(), &QAction::triggered,
            callWidget, &CallWidget::on_historicButton_clicked);
    connect(mwToolBar_->getContactListButton(), &QAction::triggered,
            callWidget, &CallWidget::on_contactButton_clicked);
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

#ifdef ENABLE_AUTOUPDATE
    win_sparkle_set_appcast_url("http://gpl.savoirfairelinux.net/ring-download/windows/winsparkle-ring.xml");
    win_sparkle_set_app_details(L"Savoir-faire Linux", L"Ring", QString(NIGHTLY_VERSION).toStdWString().c_str());
    win_sparkle_set_shutdown_request_callback([]() {QCoreApplication::exit();});
    win_sparkle_init();

    if (win_sparkle_get_last_check_time() == -1) {
        win_sparkle_set_update_check_interval(7 * 86400);
    }

    QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, [=]() {
        win_sparkle_cleanup();
    });
#endif
109 110 111 112 113
}

MainWindow::~MainWindow()
{
    delete ui;
Edric Milaret's avatar
Edric Milaret committed
114
    delete navStack_;
115 116
}

117 118
bool
MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
119
{
120
    Q_UNUSED(eventType)
121

122 123 124 125 126 127 128 129 130 131 132 133
#ifdef Q_OS_WIN32
    MSG *msg = (MSG*) message;

    if (msg->message == WM_SYSCOMMAND) {
        if ((msg->wParam & 0xfff0) == IDM_ABOUTBOX) {
            *result = 0;

            AboutDialog aboutDialog;
            aboutDialog.exec();

            return true;
        }
134
    }
135 136
#endif
    return false;
137 138 139
}

void
140 141
MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason)
{
142 143 144
    if (reason != QSystemTrayIcon::ActivationReason::Context)
        this->show();
}
145

146
void
147 148
MainWindow::onIncomingCall(Call *call)
{
149 150 151
    Q_UNUSED(call);
    QWidget::showNormal();
}
152 153 154 155

void
MainWindow::createThumbBar()
{
156
#ifdef Q_OS_WIN32
157 158 159 160 161 162 163 164 165 166 167 168
    QWinThumbnailToolBar *thumbbar = new QWinThumbnailToolBar(this);
    thumbbar->setWindow(this->windowHandle());
    QWinThumbnailToolButton *settings = new QWinThumbnailToolButton(thumbbar);
    settings->setToolTip("Settings");
    QIcon icon(":/images/settings.png");
    settings->setIcon(icon);
    settings->setDismissOnClick(true);
    connect(settings, &QWinThumbnailToolButton::clicked, [this]() {
        navStack_->onNavigationRequested(ScreenEnum::ConfScreen);
    });

    thumbbar->addButton(settings);
169
#endif
170
}
171 172 173 174 175 176 177 178 179

void
MainWindow::switchNormalMaximize()
{
    if(isMaximized())
        showNormal();
    else
        showMaximized();
}