121 lines
3.2 KiB
C++
121 lines
3.2 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
timer = new QTimer(this);
|
|
timer->setInterval(5000);
|
|
connect(timer,&QTimer::timeout,this,&MainWindow::holen_status);
|
|
timer->start();
|
|
|
|
manager = new QNetworkAccessManager();
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete timer;
|
|
delete manager;
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::holen_status(){
|
|
status_loop="ja";
|
|
//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]));
|
|
status_loop="nein";
|
|
}
|
|
|
|
bool MainWindow::sende_befehl(){
|
|
ausgabe=url + befehl;
|
|
|
|
QNetworkRequest request(ausgabe);
|
|
QNetworkReply *reply = manager->get(request);
|
|
QEventLoop event_loop;
|
|
QObject::connect(reply, SIGNAL(finished()), &event_loop, SLOT(quit()));
|
|
event_loop.exec();
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButton_pause_clicked(){
|
|
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();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButton_play_clicked(){
|
|
while(status_loop=="ja")
|
|
ui->statusbar->showMessage("~");
|
|
if(!(status_player1=="play") || !(status_player2=="play")){
|
|
if(status_player1=="aus" || status_player1=="pause"){
|
|
befehl=befehl_play1;
|
|
sende_befehl();
|
|
}else if(status_player2=="aus" || status_player2=="pause"){
|
|
befehl=befehl_play2;
|
|
sende_befehl();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButton_fade_clicked(){
|
|
while(status_loop=="ja")
|
|
ui->statusbar->showMessage("~");
|
|
if(status_player1=="play" || status_player2=="play"){
|
|
befehl=befehl_fade;
|
|
sende_befehl();
|
|
}
|
|
}
|