// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | contact@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// Object is used to relay the notification information betweeen the C++ data objects and the QML interface
#include "notifierdataobject.h"
#include <QMessageBox>
#include <QApplication>

NotifierDataObject::NotifierDataObject(QObject *parent, BytranCore *inCore) : QObject(parent)
{
    // Passing in the core object
    core = inCore;
    m_visible = false;
    m_notification = "";

    // Creating actions
    createActions();

    // Updating the notification
    updateNotifications("Initializing bytran", 0, true, false);
}

NotifierDataObject::NotifierDataObject(const QString notification, const bool visible, QObject *parent)
    : QObject(parent), m_notification(notification), m_visible(visible)
{
    ;
}

void NotifierDataObject::createActions()
{
    connect(core, SIGNAL(notify(QString, double, bool, bool)), this, SLOT(updateNotifications(QString, double, bool, bool)));
}

// Slot to display a status notification
void NotifierDataObject::updateNotifications(QString message, double value, bool visible, bool cancelButtonVisible)
{
    m_notification = message;
    m_value = value;
    m_visible = visible;
    m_cancelButtonVisible = cancelButtonVisible;

    if (m_value == 0) { m_indeterminate = true; }
                 else { m_indeterminate = false; }

    emit visibleChanged();
    emit valueChanged();
    emit indeterminateChanged();
    emit notificationChanged();
    emit cancelButtonVisibleChanged();
    QApplication::processEvents();
}

QString NotifierDataObject::notification() const
{
    return m_notification;
}
void NotifierDataObject::setNotification(const QString &notification)
{
    if (notification != m_notification)
    {
        m_notification = notification;
        emit notificationChanged();
    }
}

// Makes the notification visible or hides it
bool NotifierDataObject::visible() const
{
    return m_visible;
}

void NotifierDataObject::setVisible(const bool &visible)
{
    if (visible != m_visible)
    {
        m_visible = visible;
        emit visibleChanged();
    }
}

double NotifierDataObject::value() const { return this->m_value; }
void NotifierDataObject::setValue(const double &value)
{
    if (value != m_value)
    {
        m_value = value;
        emit valueChanged();
    }
}

bool NotifierDataObject::indeterminate() const { return this->m_indeterminate; }
void NotifierDataObject::setIndeterminate(const bool &indeterminate)
{
    if (indeterminate != m_indeterminate)
    {
        m_indeterminate = indeterminate;
        emit indeterminateChanged();
    }
}

bool NotifierDataObject::cancelButtonVisible() const { return this->m_cancelButtonVisible; }
void NotifierDataObject::setCancelButtonVisible(const bool cancelButtonVisible)
{
    if (cancelButtonVisible != m_cancelButtonVisible)
    {
        m_cancelButtonVisible = cancelButtonVisible;
        emit cancelButtonVisibleChanged();
    }
}
