/*! * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file VAlert.cpp * \author (last) Peter Lucia * \date (last) 30-Nov-2020 * \author (original) Peter Lucia * \date (original) 30-Nov-2020 * */ #include "VAlert.h" // Project using namespace View; VAlert::VAlert(QObject *parent) : QObject(parent) { // incoming connect(&_GuiController, SIGNAL(didAlertRequest(GuiAlertRequestData)), this, SLOT(onActionReceive(GuiAlertRequestData))); connect(this, SIGNAL(didRequestShowAlert()), this, SLOT(onUpdateAlertVisible())); connect(this, SIGNAL(didRequestShowAlert()), this, SLOT(onUpdateAlertVisible())); // outgoing connect(this, SIGNAL(didAlertResponse(GuiAlertResponseData)), &_GuiController, SLOT(doAlertResponse(GuiAlertResponseData))); startTimer(_timerInterval); } /*! * \brief VAlert::onUpdateAlertVisible * Updates the alert visible status */ void VAlert::onUpdateAlertVisible() { _alertVisible = true; } /*! * \brief VAlert::timerEvent * Repeatedly checks the queue for any new alerts to display * Displays the next alert in the queue if no alert is visible * \param event (QTimerEvent) - the timer event */ void VAlert::timerEvent(QTimerEvent *event) { Q_UNUSED(event) if (!_alertVisible && !_queue.isEmpty()) { showAlert(_queue.dequeue()); } } /*! * \brief VAlert::doUserAlertRequest * Called when an alert is closed as the user has made a request through * the alert dialog * \param confirmed - (bool) true if user confirms, false if they cancel */ void VAlert::doAlertResponse(const bool &confirmed) { _alertVisible = false; GuiAlertResponseData data; data.id = alertID(); data.confirmed = confirmed; emit didAlertResponse(data); } /*! * \brief VAlert::onActionReceive * Called when a new alert request to show has been received * \param request - (GuiAlertRequest) the alert data to be shown */ void VAlert::onActionReceive(const GuiAlertRequestData &request) { if (_queue.size() > _maxQueueSize) return; _queue.enqueue(request); } /*! * \brief VAlert::showAlert * Updates the alert with the specified information * \param request (GuiAlertRequestData) - the alert information */ void VAlert::showAlert(const GuiAlertRequestData &request) { alertID(request.id); title(request.title); description(request.description); acknowledgeOnly(request.acknowledgeOnly); didRequestShowAlert(); }