This commit is contained in:
Thomas resiX 2025-02-15 12:17:02 +01:00
parent 6db8aa36ee
commit 42d8cb6d1a
3 changed files with 155 additions and 108 deletions

View file

@ -6,6 +6,11 @@ MainWindow::MainWindow(QWidget *parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
QTimer *timer = new QTimer(this);
timer->setInterval(1000);
connect(timer,&QTimer::timeout,this,&MainWindow::holen_status);
timer->start();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -13,60 +18,93 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::textBrowser_ausgabe(QString befehl){ void MainWindow::holen_status(){
ausgabe=url + befehl + "\n"; //Autoplay
ui->textBrowser_ausgabe->clear(); befehl=befehl_getauto;
ui->textBrowser_ausgabe->insertPlainText(ausgabe); sende_befehl();
if(status=="0"){
status_auto="aus";
}else{
status_auto="an";
}
//Player1
befehl=befehl_playstate1;
sende_befehl();
if(status=="0"){
status_player1="aus";
}else if(status=="1"){
status_player1="play";
}else if(status=="2"){
status_player1="pause";
}
//Player2
befehl=befehl_playstate2;
sende_befehl();
if(status=="0"){
status_player2="aus";
}else if(status=="1"){
status_player2="play";
}else if(status=="2"){
status_player2="pause";
}
//Anzeige
if(status_player1=="play") ui->checkBox_player1->setChecked(1); else ui->checkBox_player1->setChecked(0);
if(status_auto=="an") ui->checkBox_auto->setChecked(1); else ui->checkBox_auto->setChecked(0);
if(status_player2=="play") ui->checkBox_player2->setChecked(1); else ui->checkBox_player2->setChecked(0);
//Playlist
befehl=befehl_file;
sende_befehl();
ui->lineEdit_titel->setText((status.split("<br>")[0]));
} }
void MainWindow::sende_befehl(QString befehl){ bool MainWindow::sende_befehl(){
ausgabe=url + befehl; ausgabe=url + befehl;
manager = new QNetworkAccessManager(this); manager = new QNetworkAccessManager(this);
QNetworkRequest request(ausgabe); QNetworkRequest request(ausgabe);
QNetworkReply *reply = manager->get(request); QNetworkReply *reply = manager->get(request);
QEventLoop event_loop;
QObject::connect(reply, SIGNAL(finished()), &event_loop, SLOT(quit()));
event_loop.exec();
connect(reply, &QNetworkReply::finished, [=]() { if(reply->error() == QNetworkReply::NoError){
if(reply->error() == QNetworkReply::NoError){ QByteArray response = reply->readAll();
QByteArray response = reply->readAll(); ui->statusbar->showMessage("Ok.");
ui->textBrowser_ausgabe->insertPlainText(response+"\n"); status = response;
ui->statusbar->showMessage("Ok."); return 1;
}else{ // handle error }else{ // handle error
ui->textBrowser_ausgabe->insertPlainText(reply->errorString()+"\n"); ui->statusbar->showMessage(reply->errorString());
ui->statusbar->showMessage("Fehler."); status = reply->errorString();
} return 0;
}); }
} }
void MainWindow::on_pushButton_pause_clicked(){ void MainWindow::on_pushButton_pause_clicked(){
befehl=pause1; if(status_player1=="play"){
textBrowser_ausgabe(befehl); befehl=befehl_pause1;
sende_befehl(befehl); sende_befehl();
befehl=pause2; }else if(status_player2=="play"){
textBrowser_ausgabe(befehl); befehl=befehl_pause2;
sende_befehl(befehl); sende_befehl();
}
} }
void MainWindow::on_pushButton_play_clicked(){ void MainWindow::on_pushButton_play_clicked(){
befehl=play1; if(!(status_player1=="play") || !(status_player2=="play")){
textBrowser_ausgabe(befehl); if(status_player1=="aus" || status_player1=="pause"){
sende_befehl(befehl); befehl=befehl_play1;
sende_befehl();
befehl=pause2; }else if(status_player2=="aus" || status_player2=="pause"){
textBrowser_ausgabe(befehl); befehl=befehl_play2;
sende_befehl(befehl); sende_befehl();
}
}
} }
void MainWindow::on_pushButton_fade_clicked(){ void MainWindow::on_pushButton_fade_clicked(){
befehl=fade; if(status_player1=="play" || status_player2=="play"){
textBrowser_ausgabe(befehl); befehl=befehl_fade;
sende_befehl(befehl); sende_befehl();
}
} }
void MainWindow::on_textBrowser_ausgabe_selectionChanged(){
befehl=getfile;
textBrowser_ausgabe(befehl);
sende_befehl(befehl);
}

View file

@ -7,6 +7,8 @@
#include <QtNetwork/QNetworkRequest> #include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QPalette> #include <QPalette>
#include <QTimer>
#include <QThread>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
@ -23,16 +25,13 @@ public:
private slots: private slots:
void on_pushButton_pause_clicked(); void on_pushButton_pause_clicked();
void on_pushButton_play_clicked(); void on_pushButton_play_clicked();
void on_pushButton_fade_clicked(); void on_pushButton_fade_clicked();
void holen_status();
void on_textBrowser_ausgabe_selectionChanged();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
void textBrowser_ausgabe(QString); bool sende_befehl();
void sende_befehl(QString);
QNetworkAccessManager *manager; QNetworkAccessManager *manager;
@ -40,11 +39,20 @@ private:
QString port="80"; QString port="80";
QString url="http://" + ip + ":" + port + "/"; QString url="http://" + ip + ":" + port + "/";
QString ausgabe; QString ausgabe;
QString status;
QString status_player1;
QString status_player2;
QString status_auto;
QString befehl; QString befehl;
QString pause1="PAUSE1"; QString befehl_getauto="getauto";
QString pause2="PAUSE2"; QString befehl_setauto="setauto1";
QString play1="PLAY1"; QString befehl_playstate1="getplaystate1";
QString fade="FADENOW"; QString befehl_playstate2="getplaystate2";
QString getfile="LIST_GETFILE"; QString befehl_pause1="pause1";
QString befehl_pause2="pause2";
QString befehl_play1="play1";
QString befehl_play2="play2";
QString befehl_fade="fadenow";
QString befehl_file="list_getfile";
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View file

@ -7,71 +7,72 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>302</width> <width>302</width>
<height>157</height> <height>115</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>BPM-Studio-Net-Client</string> <string>BPM-Studio-Net-Client</string>
</property> </property>
<property name="styleSheet">
<string notr="true">background-color: rgb(119, 119, 119);</string>
</property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<widget class="QTextBrowser" name="textBrowser_ausgabe"> <layout class="QGridLayout" name="gridLayout">
<property name="geometry"> <item row="0" column="0">
<rect> <widget class="QPushButton" name="pushButton_pause">
<x>10</x> <property name="styleSheet">
<y>40</y> <string notr="true">background-color: rgb(255, 0, 0);</string>
<width>281</width> </property>
<height>71</height> <property name="text">
</rect> <string>Pause</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="pushButton_pause"> </item>
<property name="geometry"> <item row="0" column="1">
<rect> <widget class="QPushButton" name="pushButton_play">
<x>10</x> <property name="styleSheet">
<y>10</y> <string notr="true">background-color: rgb(0, 255, 0);</string>
<width>80</width> </property>
<height>24</height> <property name="text">
</rect> <string>Play</string>
</property> </property>
<property name="styleSheet"> </widget>
<string notr="true">background-color: rgb(255, 0, 0);</string> </item>
</property> <item row="0" column="2">
<property name="text"> <widget class="QPushButton" name="pushButton_fade">
<string>Pause</string> <property name="styleSheet">
</property> <string notr="true">background-color: rgb(255, 255, 0);</string>
</widget> </property>
<widget class="QPushButton" name="pushButton_play"> <property name="text">
<property name="geometry"> <string>Fade</string>
<rect> </property>
<x>110</x> </widget>
<y>10</y> </item>
<width>80</width> <item row="1" column="0">
<height>24</height> <widget class="QCheckBox" name="checkBox_player1">
</rect> <property name="text">
</property> <string>Player 1</string>
<property name="styleSheet"> </property>
<string notr="true">background-color: rgb(0, 255, 0);</string> </widget>
</property> </item>
<property name="text"> <item row="1" column="1">
<string>Play</string> <widget class="QCheckBox" name="checkBox_auto">
</property> <property name="text">
</widget> <string>Auto</string>
<widget class="QPushButton" name="pushButton_fade"> </property>
<property name="geometry"> </widget>
<rect> </item>
<x>210</x> <item row="1" column="2">
<y>10</y> <widget class="QCheckBox" name="checkBox_player2">
<width>80</width> <property name="text">
<height>24</height> <string>Player 2</string>
</rect> </property>
</property> </widget>
<property name="styleSheet"> </item>
<string notr="true">background-color: rgb(255, 255, 0);</string> <item row="2" column="0" colspan="3">
</property> <widget class="QLineEdit" name="lineEdit_titel"/>
<property name="text"> </item>
<string>Fade</string> </layout>
</property>
</widget>
</widget> </widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">
<property name="geometry"> <property name="geometry">