diff --git a/mainwindow.cpp b/mainwindow.cpp
index 64095ab..d6903f8 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -5,7 +5,12 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, 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()
@@ -13,60 +18,93 @@ MainWindow::~MainWindow()
delete ui;
}
-void MainWindow::textBrowser_ausgabe(QString befehl){
- ausgabe=url + befehl + "\n";
- ui->textBrowser_ausgabe->clear();
- ui->textBrowser_ausgabe->insertPlainText(ausgabe);
+void MainWindow::holen_status(){
+ //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("
")[0]));
}
-void MainWindow::sende_befehl(QString befehl){
+bool MainWindow::sende_befehl(){
ausgabe=url + befehl;
manager = new QNetworkAccessManager(this);
QNetworkRequest request(ausgabe);
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){
- QByteArray response = reply->readAll();
- ui->textBrowser_ausgabe->insertPlainText(response+"\n");
- ui->statusbar->showMessage("Ok.");
- }else{ // handle error
- ui->textBrowser_ausgabe->insertPlainText(reply->errorString()+"\n");
- ui->statusbar->showMessage("Fehler.");
- }
- });
+ 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(){
- befehl=pause1;
- textBrowser_ausgabe(befehl);
- sende_befehl(befehl);
+ if(status_player1=="play"){
+ befehl=befehl_pause1;
+ sende_befehl();
- befehl=pause2;
- textBrowser_ausgabe(befehl);
- sende_befehl(befehl);
+ }else if(status_player2=="play"){
+ befehl=befehl_pause2;
+ sende_befehl();
+ }
}
void MainWindow::on_pushButton_play_clicked(){
- befehl=play1;
- textBrowser_ausgabe(befehl);
- sende_befehl(befehl);
-
- befehl=pause2;
- textBrowser_ausgabe(befehl);
- sende_befehl(befehl);
+ 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(){
- befehl=fade;
- textBrowser_ausgabe(befehl);
- sende_befehl(befehl);
+ if(status_player1=="play" || status_player2=="play"){
+ befehl=befehl_fade;
+ sende_befehl();
+ }
}
-
-void MainWindow::on_textBrowser_ausgabe_selectionChanged(){
- befehl=getfile;
- textBrowser_ausgabe(befehl);
- sende_befehl(befehl);
-}
-
diff --git a/mainwindow.h b/mainwindow.h
index 60e7984..32b7cb7 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -7,6 +7,8 @@
#include
#include
#include
+#include
+#include
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@@ -23,16 +25,13 @@ public:
private slots:
void on_pushButton_pause_clicked();
void on_pushButton_play_clicked();
-
void on_pushButton_fade_clicked();
-
- void on_textBrowser_ausgabe_selectionChanged();
+ void holen_status();
private:
Ui::MainWindow *ui;
- void textBrowser_ausgabe(QString);
- void sende_befehl(QString);
+ bool sende_befehl();
QNetworkAccessManager *manager;
@@ -40,11 +39,20 @@ private:
QString port="80";
QString url="http://" + ip + ":" + port + "/";
QString ausgabe;
+ QString status;
+ QString status_player1;
+ QString status_player2;
+ QString status_auto;
QString befehl;
- QString pause1="PAUSE1";
- QString pause2="PAUSE2";
- QString play1="PLAY1";
- QString fade="FADENOW";
- QString getfile="LIST_GETFILE";
+ QString befehl_getauto="getauto";
+ QString befehl_setauto="setauto1";
+ QString befehl_playstate1="getplaystate1";
+ QString befehl_playstate2="getplaystate2";
+ 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
diff --git a/mainwindow.ui b/mainwindow.ui
index 84a8698..168d23e 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -7,71 +7,72 @@
0
0
302
- 157
+ 115
BPM-Studio-Net-Client
+
+ background-color: rgb(119, 119, 119);
+
-
-
-
- 10
- 40
- 281
- 71
-
-
-
-
-
-
- 10
- 10
- 80
- 24
-
-
-
- background-color: rgb(255, 0, 0);
-
-
- Pause
-
-
-
-
-
- 110
- 10
- 80
- 24
-
-
-
- background-color: rgb(0, 255, 0);
-
-
- Play
-
-
-
-
-
- 210
- 10
- 80
- 24
-
-
-
- background-color: rgb(255, 255, 0);
-
-
- Fade
-
-
+
+ -
+
+
+ background-color: rgb(255, 0, 0);
+
+
+ Pause
+
+
+
+ -
+
+
+ background-color: rgb(0, 255, 0);
+
+
+ Play
+
+
+
+ -
+
+
+ background-color: rgb(255, 255, 0);
+
+
+ Fade
+
+
+
+ -
+
+
+ Player 1
+
+
+
+ -
+
+
+ Auto
+
+
+
+ -
+
+
+ Player 2
+
+
+
+ -
+
+
+