aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-mediaplayer/PianoBarProcess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils/lumina-mediaplayer/PianoBarProcess.cpp')
-rw-r--r--src-qt5/desktop-utils/lumina-mediaplayer/PianoBarProcess.cpp63
1 files changed, 53 insertions, 10 deletions
diff --git a/src-qt5/desktop-utils/lumina-mediaplayer/PianoBarProcess.cpp b/src-qt5/desktop-utils/lumina-mediaplayer/PianoBarProcess.cpp
index 55c85a33..88abce82 100644
--- a/src-qt5/desktop-utils/lumina-mediaplayer/PianoBarProcess.cpp
+++ b/src-qt5/desktop-utils/lumina-mediaplayer/PianoBarProcess.cpp
@@ -28,6 +28,10 @@ PianoBarProcess::~PianoBarProcess(){
}
}
+PianoBarProcess::State PianoBarProcess::currentState(){
+ return cState;
+}
+
// ===== PUBLIC ======
//Interaction functions
bool PianoBarProcess::isSetup(){ //email/password already saved for use or not
@@ -51,7 +55,7 @@ void PianoBarProcess::closePianoBar(){ //"q"
sendToProcess("q");
}
-QString PianoBarProcess::currentStation(){ return cstation; }
+QString PianoBarProcess::currentStation(){ return cstation.simplified(); }
QStringList PianoBarProcess::stations(){ return stationList; }
void PianoBarProcess::setCurrentStation(QString station){
cstation = station;
@@ -70,11 +74,13 @@ void PianoBarProcess::deleteCurrentStation(){ //"d" -> "y"
void PianoBarProcess::createStationFromCurrentSong(){ //"v" -> "s"
sendToProcess("v");
sendToProcess("s",true);
+ setCurrentStation("<NEW>"); //internal definition for auto-switching to a new station
}
void PianoBarProcess::createStationFromCurrentArtist(){ //"v" -> "a"
sendToProcess("v");
sendToProcess("a",true);
+ setCurrentStation("<NEW>"); //internal definition for auto-switching to a new station
}
//Settings Manipulation
@@ -116,9 +122,21 @@ void PianoBarProcess::play(){
PROC->start();
}else{
sendToProcess("P");
+ cState = PianoBarProcess::Running;
+ emit currentStateChanged(cState);
}
}
+void PianoBarProcess::pause(){
+ sendToProcess("S");
+ cState = PianoBarProcess::Paused;
+ emit currentStateChanged(cState);
+}
+
+void PianoBarProcess::skipSong(){
+ sendToProcess("n");
+}
+
// ====== PRIVATE ======
void PianoBarProcess::GenerateSettings(){
currentSettings << "audio_quality = medium";
@@ -187,6 +205,8 @@ void PianoBarProcess::setupProcess(){
LUtils::isValidBinary(bin); //will change "bin" to the full path
PROC->setProgram(bin);
connect(PROC, SIGNAL(readyRead()), this, SLOT(ProcUpdate()) );
+ connect(PROC, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(ProcStateChanged(QProcess::ProcessState)) );
+ cState = PianoBarProcess::Stopped;
}
void PianoBarProcess::sendToProcess(QString txt, bool withreturn){
@@ -218,7 +238,7 @@ void PianoBarProcess::ProcUpdate(){
//Now playing line (station, or song)
QStringList data = info[i].section(">",1,-1).simplified().split("::::"); //Make sure to chop the line prefix off first
if(data.length()==2){ //station
- cstation = data[0]; //save the name for later
+ cstation = data[0].simplified(); //save the name for later
emit NowPlayingStation(data[0], data[1]);
if(stationList.isEmpty()){
//Need to prompt to list all the available stations
@@ -231,23 +251,40 @@ void PianoBarProcess::ProcUpdate(){
}else if(data.length()==6){ //song
emit NowPlayingSong( data[0]=="<3", data[1], data[2], data[3], data[4], data[5] );
}
+ //If a new song/station is detected, ensure that the state is set to "Running"
+ if(cState!=PianoBarProcess::Running){
+ cState = PianoBarProcess::Running;
+ emit currentStateChanged(cState);
+ }
}else if(info[i].startsWith("(i) ")){ //informational line
emit NewInformation(info[i].section(" ",1,-1));
}else if(info[i].startsWith("[?] ")){ //waiting for reply to question
- qDebug() << "Got Question:" << info[i] << infoList;
+ //qDebug() << "Got Question:" << info[i] << infoList;
if(info[i].contains("Select station:")){
- qDebug() << "Change to Station:" << cstation;
+ //qDebug() << "Change to Station:" << cstation;
+ //Clean up the station list a bit first (remove the quickmix-status)
+ for(int j=0; j<infoList.length(); j++){
+ infoList[j] = infoList[j].simplified();
+ if(infoList[j].startsWith("q ")){ infoList[j] = infoList[j].section("q ",1,-1); }
+ if(infoList[j].startsWith("Q ")){ infoList[j] = infoList[j].section("Q ",1,-1); }
+ }
+ if(cstation=="<NEW>"){
+ //Compare the new list to the previous list and switch to the new one automatically
+ for(int j=0; j<infoList.length(); j++){
+ if(!stationList.contains(infoList[j])){ cstation = infoList[j]; break; }
+ }
+ }
stationList = infoList; //save this list for later
infoList.clear();
emit StationListChanged(stationList);
//Find the station number which corresponds to the cstation variable/name
- for(int i=0; i<stationList.length(); i++){
- if(stationList[i].endsWith(cstation) ){
- qDebug() << "Activate Station:" << stationList[i];
- sendToProcess(QString::number(i), true);
+ for(int j=0; j<stationList.length(); j++){
+ if(stationList[j].endsWith(cstation) ){
+ //qDebug() << "Activate Station:" << stationList[i];
+ sendToProcess(QString::number(j), true);
break;
- }else if(i==stationList.length()-1){
- qDebug() << "Activate Last Station:" << stationList[i];
+ }else if(j==stationList.length()-1){
+ //qDebug() << "Activate Last Station:" << stationList[i];
sendToProcess(QString::number(stationList.length()-1), true);
}
}
@@ -263,3 +300,9 @@ void PianoBarProcess::ProcUpdate(){
}
}
}
+
+void PianoBarProcess::ProcStateChanged(QProcess::ProcessState stat){
+ if(stat == QProcess::NotRunning){ cState = PianoBarProcess::Stopped; }
+ else{ cState = PianoBarProcess::Paused; }
+ emit currentStateChanged(cState);
+}
bgstack15