BPM-Studio-Net-Client/mainwindow.cpp

130 lines
3.4 KiB
C++
Raw Permalink Normal View History

2025-02-15 12:16:34 +01:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
2025-02-15 12:17:02 +01:00
ui->setupUi(this);
2025-02-15 12:17:30 +01:00
timer = new QTimer(this);
timer->setInterval(5000);
2025-02-15 12:17:02 +01:00
connect(timer,&QTimer::timeout,this,&MainWindow::holen_status);
timer->start();
2025-02-15 12:17:30 +01:00
manager = new QNetworkAccessManager();
2025-02-15 12:16:34 +01:00
}
MainWindow::~MainWindow()
{
2025-02-15 12:17:30 +01:00
delete timer;
delete manager;
2025-02-15 12:16:34 +01:00
delete ui;
}
2025-02-15 12:17:02 +01:00
void MainWindow::holen_status(){
2025-02-15 12:17:30 +01:00
status_loop="ja";
2025-02-15 12:17:02 +01:00
//Autoplay
befehl=befehl_getauto;
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]));
2025-02-15 12:17:30 +01:00
status_loop="nein";
2025-02-15 12:16:34 +01:00
}
2025-02-15 12:17:02 +01:00
bool MainWindow::sende_befehl(){
2025-02-15 12:16:34 +01:00
ausgabe=url + befehl;
QNetworkRequest request(ausgabe);
QNetworkReply *reply = manager->get(request);
2025-02-15 12:17:02 +01:00
QEventLoop event_loop;
QObject::connect(reply, SIGNAL(finished()), &event_loop, SLOT(quit()));
event_loop.exec();
2025-02-15 12:16:34 +01:00
2025-02-15 12:17:02 +01:00
if(reply->error() == QNetworkReply::NoError){
QByteArray response = reply->readAll();
ui->statusbar->showMessage("Ok.");
status = response;
return 1;
}else{ // handle error
ui->statusbar->showMessage(reply->errorString());
status = reply->errorString();
return 0;
}
2025-02-15 12:16:34 +01:00
}
void MainWindow::on_pushButton_pause_clicked(){
2025-02-15 12:19:09 +01:00
if(status_auto=="an"){
while(status_loop=="ja")
ui->statusbar->showMessage("~");
if(status_player1=="play"){
befehl=befehl_pause1;
sende_befehl();
}else if(status_player2=="play"){
befehl=befehl_pause2;
sende_befehl();
}
2025-02-15 12:17:02 +01:00
}
2025-02-15 12:16:34 +01:00
}
void MainWindow::on_pushButton_play_clicked(){
2025-02-15 12:19:09 +01:00
if(status_auto=="an"){
while(status_loop=="ja")
ui->statusbar->showMessage("~");
if(!(status_player1=="play") || !(status_player2=="play")){
if(status_player1=="pause"){
befehl=befehl_play1;
sende_befehl();
}else if(status_player2=="pause"){
befehl=befehl_play2;
sende_befehl();
}else{
befehl=befehl_play1;
sende_befehl();
}
2025-02-15 12:17:02 +01:00
}
}
2025-02-15 12:16:34 +01:00
}
void MainWindow::on_pushButton_fade_clicked(){
2025-02-15 12:19:09 +01:00
if(status_auto=="an"){
while(status_loop=="ja")
ui->statusbar->showMessage("~");
if(status_player1=="play" || status_player2=="play"){
befehl=befehl_fade;
sende_befehl();
}
2025-02-15 12:17:02 +01:00
}
2025-02-15 12:16:34 +01:00
}