/*****************************************************************************
 *
 * Testmanager - Graphical Automation and Visualisation Tool
 *
 * Copyright (C) 2023  Bjarne von Horn <vh@igh.de>
 *
 * This file is part of Testmanager.
 *
 * Testmanager 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.
 *
 * Testmanager 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 Testmanager. If not, see <http://www.gnu.org/licenses/>.
 *
 ****************************************************************************/

#include "SendBroadcastPlugin.h"

#include "DataSource.h"

#include <QtPdWidgets2/SendBroadcastWidget.h>

QString SendBroadcastPlugin::name() const
{
    return tr("Send Broadcast");
}

QIcon SendBroadcastPlugin::icon() const
{
    return QIcon(":/images/plugin-broadcast.svg");
}

void SendBroadcastPlugin::setDataSource(
        QWidget *w,
        void *data,
        DataSource *s) const
{
    Q_ASSERT(data && s);
    auto *obj = qobject_cast<Pd::SendBroadcastWidget *>(w);
    if (obj) {
        obj->setProcess(s ? &s->getProcess() : nullptr);
        *reinterpret_cast<QUrl *>(data) = s->getConnectUrl();
    }
}

QString SendBroadcastPlugin::getDataSource(
        QWidget *,
        const void *data) const
{
    return reinterpret_cast<const QUrl *>(data)->toString();
}

void *SendBroadcastPlugin::createPrivateData(QWidget *) const
{
    return new QUrl();
}

void SendBroadcastPlugin::deletePrivateData(QWidget *, void *qurl) const
{
    delete reinterpret_cast<QUrl *>(qurl);
}

QWidget *SendBroadcastPlugin::createWidget(QWidget *parent) const
{
    return new Pd::SendBroadcastWidget(parent);
}
