1 /*
2  * Copyright (c) 2012-2018 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "networkproducerwidget.h"
19 #include "ui_networkproducerwidget.h"
20 #include "mltcontroller.h"
21 #include "util.h"
22 
NetworkProducerWidget(QWidget * parent)23 NetworkProducerWidget::NetworkProducerWidget(QWidget *parent) :
24     QWidget(parent),
25     ui(new Ui::NetworkProducerWidget)
26 {
27     ui->setupUi(this);
28     Util::setColorsToHighlight(ui->label_2);
29     ui->applyButton->hide();
30     ui->preset->saveDefaultPreset(getPreset());
31     ui->preset->loadPresets();
32 }
33 
~NetworkProducerWidget()34 NetworkProducerWidget::~NetworkProducerWidget()
35 {
36     delete ui;
37 }
38 
newProducer(Mlt::Profile & profile)39 Mlt::Producer* NetworkProducerWidget::newProducer(Mlt::Profile& profile)
40 {
41     Mlt::Producer* p = new Mlt::Producer(profile, ui->urlLineEdit->text().toUtf8().constData());
42     return p;
43 }
44 
getPreset() const45 Mlt::Properties NetworkProducerWidget::getPreset() const
46 {
47     Mlt::Properties p;
48     p.set("resource", ui->urlLineEdit->text().toUtf8().constData());
49     return p;
50 }
51 
loadPreset(Mlt::Properties & p)52 void NetworkProducerWidget::loadPreset(Mlt::Properties& p)
53 {
54     const char *resource = p.get("resource");
55     if (qstrcmp(resource, "<tractor>") && qstrcmp(resource, "<playlist>"))
56         ui->urlLineEdit->setText(resource);
57 }
58 
on_preset_selected(void * p)59 void NetworkProducerWidget::on_preset_selected(void* p)
60 {
61     Mlt::Properties* properties = (Mlt::Properties*) p;
62     loadPreset(*properties);
63     delete properties;
64 }
65 
on_preset_saveClicked()66 void NetworkProducerWidget::on_preset_saveClicked()
67 {
68     ui->preset->savePreset(getPreset());
69 }
70 
setProducer(Mlt::Producer * producer)71 void NetworkProducerWidget::setProducer(Mlt::Producer* producer)
72 {
73     ui->applyButton->show();
74     if (producer)
75         loadPreset(*producer);
76 }
77 
on_applyButton_clicked()78 void NetworkProducerWidget::on_applyButton_clicked()
79 {
80     MLT.setProducer(newProducer(MLT.profile()));
81     MLT.play();
82 }
83