diff --git a/ChangeLog b/ChangeLog index dcf2e845..dd049e80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24688,3 +24688,5 @@ * Fixed a bug in the PAD subsystem that caused meta-events to be included in the update events. * Refactored the PAD subsystem to use native Qt JSON methods. +2024-04-02 Fred Gleason + * Modified the Sound Panel classes to use native Qt JSON methods. diff --git a/lib/rdbutton_panel.cpp b/lib/rdbutton_panel.cpp index e3ff96a8..89b1d124 100644 --- a/lib/rdbutton_panel.cpp +++ b/lib/rdbutton_panel.cpp @@ -2,7 +2,7 @@ // // Component class for sound panel widgets // -// (C) Copyright 2002-2023 Fred Gleason +// (C) Copyright 2002-2024 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -19,15 +19,19 @@ // #include +#include +#include #include "rdbutton_dialog.h" #include "rdbutton_panel.h" RDButtonPanel::RDButtonPanel(RDAirPlayConf::PanelType type,int number, - QWidget *parent) + const QString &title,QWidget *parent) : RDWidget(parent) { + panel_type=type; panel_number=number; + panel_title=title; panel_button_mapper=new QSignalMapper(this); connect(panel_button_mapper,SIGNAL(mapped(int)), @@ -161,25 +165,23 @@ void RDButtonPanel::setActionMode(RDAirPlayConf::ActionMode mode) default: for(int i=0;icart()!=0) { - if(panel_button[i][j]->playDeck()!=NULL) { - if(panel_button[i][j]->playDeck()->state()==RDPlayDeck::Paused) { - panel_button[i][j]->setColor(RDPANEL_PAUSED_BACKGROUND_COLOR); - } - else { - panel_button[i][j]->setColor(RDPANEL_PLAY_BACKGROUND_COLOR); - } - } + for(int j=0;jplayDeck()!=NULL) { + if(panel_button[i][j]->playDeck()->state()==RDPlayDeck::Paused) { + panel_button[i][j]->setColor(RDPANEL_PAUSED_BACKGROUND_COLOR); + } else { - if(panel_button[i][j]->state()) { - panel_button[i][j]->setColor(RDPANEL_PAUSED_BACKGROUND_COLOR); - } - else { - panel_button[i][j]->reset(); - } - } -// } + panel_button[i][j]->setColor(RDPANEL_PLAY_BACKGROUND_COLOR); + } + } + else { + if(panel_button[i][j]->state()) { + panel_button[i][j]->setColor(RDPANEL_PAUSED_BACKGROUND_COLOR); + } + else { + panel_button[i][j]->reset(); + } + } } } break; @@ -217,41 +219,33 @@ void RDButtonPanel::clear() } -QString RDButtonPanel::json(int padding,bool final) const +QJsonValue RDButtonPanel::json() const { - QString ret; - - // - // Get Button Count - // - int count=0; - for(int i=0;iisEmpty()) { - count++; - } - } - } - - ret+=RDJsonPadding(padding)+"\"panel\": {\r\n"; - ret+=RDJsonField("number",panel_number,4+padding); - ret+=RDJsonField("title",panel_title,4+padding,count==0); + QJsonArray ja0; for(int i=0;iisEmpty()) { - count--; - ret+=panel_button[i][j]->json(4+padding,count==0); + ja0.insert(ja0.count(),panel_button[i][j]->json()); } } } - ret+=RDJsonPadding(padding)+"}"; - if(!final) { - ret+=","; + QJsonObject jo0; + if(panel_type==RDAirPlayConf::UserPanel) { + jo0.insert("owner",rda->user()->name()); } - ret+="\r\n"; + else { + jo0.insert("owner",QJsonValue()); + } + if(panel_title.isEmpty()) { + jo0.insert("title",QJsonValue()); + } + else { + jo0.insert("title",panel_title); + } + jo0.insert("buttons",ja0); - return ret; + return jo0; } diff --git a/lib/rdbutton_panel.h b/lib/rdbutton_panel.h index a10d39d4..4bae68a3 100644 --- a/lib/rdbutton_panel.h +++ b/lib/rdbutton_panel.h @@ -2,7 +2,7 @@ // // Component class for sound panel widgets // -// (C) Copyright 2002-2023 Fred Gleason +// (C) Copyright 2002-2024 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -22,6 +22,7 @@ #define RDBUTTON_PANEL_H #include +#include #include #include @@ -30,7 +31,6 @@ #include #include #include -#include #include // @@ -43,7 +43,8 @@ class RDButtonPanel : public RDWidget { Q_OBJECT; public: - RDButtonPanel(RDAirPlayConf::PanelType type,int number,QWidget *parent); + RDButtonPanel(RDAirPlayConf::PanelType type,int number,const QString &title, + QWidget *parent); ~RDButtonPanel(); QSize sizeHint() const; QSizePolicy sizePolicy() const; @@ -55,7 +56,7 @@ class RDButtonPanel : public RDWidget void setAllowDrags(bool state); void setAcceptDrops(bool state); void clear(); - QString json(int padding=0,bool final=false) const; + QJsonValue json() const; public slots: void setVisible(bool state); @@ -75,6 +76,7 @@ class RDButtonPanel : public RDWidget QString panel_title; QSignalMapper *panel_button_mapper; RDPanelButton *panel_button[PANEL_MAX_BUTTON_ROWS][PANEL_MAX_BUTTON_COLUMNS]; + RDAirPlayConf::PanelType panel_type; }; #endif // RDBUTTON_PANEL_H diff --git a/lib/rdpanel_button.cpp b/lib/rdpanel_button.cpp index 0a23cb50..97125339 100644 --- a/lib/rdpanel_button.cpp +++ b/lib/rdpanel_button.cpp @@ -2,7 +2,7 @@ // // Component class for sound panel widgets. // -// (C) Copyright 2002-2023 Fred Gleason +// (C) Copyright 2002-2024 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -19,6 +19,7 @@ // #include +#include #include #include @@ -348,41 +349,31 @@ bool RDPanelButton::isActive() const } -QString RDPanelButton::json(int padding,bool final) +QJsonValue RDPanelButton::json() const { - QString ret; + QJsonObject jo0; - ret+=RDJsonPadding(padding)+"\"button\": {\r\n"; - ret+=RDJsonField("column",button_col,4+padding); - ret+=RDJsonField("row",button_row,4+padding); + jo0.insert("column",button_col); + jo0.insert("row",button_row); if(isEmpty()) { - ret+=RDJsonNullField("cart",4+padding); - ret+=RDJsonNullField("defaultColor",4+padding); - ret+=RDJsonNullField("length",4+padding); - ret+=RDJsonNullField("hookLength",4+padding); - ret+=RDJsonNullField("label",4+padding,true); + jo0.insert("cart",QJsonValue()); + jo0.insert("defaultColor",QJsonValue()); + jo0.insert("length",QJsonValue()); + jo0.insert("hookLength",QJsonValue()); + jo0.insert("label",QJsonValue()); } else { - ret+=RDJsonField("cart",button_cart,4+padding); - ret+=RDJsonField("defaultColor",button_default_color.name(),4+padding); - ret+=RDJsonField("length",RDGetTimeLength(button_length[0],true,false), - 4+padding); - ret+=RDJsonField("hookLength",RDGetTimeLength(button_length[1],true,false), - 4+padding); - ret+=RDJsonField("label",button_text,4+padding,true); + jo0.insert("cart",(int)button_cart); + jo0.insert("defaultColor",button_default_color.name()); + jo0.insert("length",RDGetTimeLength(button_length[0],true,false)); + jo0.insert("hookLength",RDGetTimeLength(button_length[1],true,false)); + jo0.insert("label",button_text); } - ret+=RDJsonPadding(padding)+"}"; - if(!final) { - ret+=","; - } - ret+="\r\n"; - return ret; + return jo0; } - - void RDPanelButton::setVisible(bool state) { RDPushButton::setVisible(state); diff --git a/lib/rdpanel_button.h b/lib/rdpanel_button.h index 2520fad4..de543f8c 100644 --- a/lib/rdpanel_button.h +++ b/lib/rdpanel_button.h @@ -2,7 +2,7 @@ // // Component class for sound panel widgets. // -// (C) Copyright 2002-2023 Fred Gleason +// (C) Copyright 2002-2024 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -23,7 +23,6 @@ #include #include -#include // // Widget Settings @@ -79,7 +78,7 @@ class RDPanelButton : public RDPushButton void resetCounter(); bool isEmpty() const; bool isActive() const; - QString json(int padding=0,bool final=false); + QJsonValue json() const; void setVisible(bool state); signals: diff --git a/lib/rdsound_panel.cpp b/lib/rdsound_panel.cpp index 7ae8f3a5..9df303f3 100644 --- a/lib/rdsound_panel.cpp +++ b/lib/rdsound_panel.cpp @@ -1,8 +1,8 @@ // rdsound_panel.cpp // -// The sound panel widget for RDAirPlay +// The sound panel widget. // -// (C) Copyright 2002-2023 Fred Gleason +// (C) Copyright 2002-2024 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -18,6 +18,10 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // +#include +#include +#include + #include "rdapplication.h" #include "rdbutton_dialog.h" #include "rdcut.h" @@ -28,7 +32,6 @@ #include "rdlog_line.h" #include "rdmacro.h" #include "rdsound_panel.h" -#include "rdweb.h" RDSoundPanel::RDSoundPanel(int station_panels,int user_panels,bool flash, const QString &caption,const QString &label_template, @@ -164,8 +167,8 @@ RDSoundPanel::RDSoundPanel(int station_panels,int user_panels,bool flash, // QString sql; sql=QString("select ")+ - "`PANEL_NO`,"+ - "`NAME` "+ + "`PANEL_NO`,"+ // 00 + "`NAME` "+ // 01 "from "+panel_name_tablename+" where "+ QString::asprintf("(`TYPE`=%d)&&",RDAirPlayConf::StationPanel)+ "(`OWNER`='"+RDEscapeString(rda->station()->name())+"') "+ @@ -470,42 +473,25 @@ RDAirPlayConf::PanelType RDSoundPanel::currentType() const } -QString RDSoundPanel::json(const QString &owner,int padding,bool final) const +QByteArray RDSoundPanel::json(const QString &owner) const { - QString ret; - QList panels=panel_arrays.value(owner); + QJsonArray ja0; - ret+=RDJsonPadding(padding)+"\"array\": {\r\n"; - ret+=RDJsonField("owner",owner,4+padding); - - for(int i=0;i<(panels.size()-1);i++) { - ret+=panels.at(i)->json(4+padding); + QList panels=panel_arrays.value(""); + for(int i=0;ijson()); } - if(panels.size()>0) { - ret+=panels.last()->json(4+padding,true); + panels=panel_arrays.value(rda->user()->name()); + for(int i=0;ijson()); } + QJsonObject jo0; + jo0.insert("panels",ja0); - ret+=RDJsonPadding(padding)+"}"; - if(!final) { - ret+=","; - } - ret+="\r\n"; + QJsonDocument jdoc; + jdoc.setObject(jo0); - return ret; -} - - -QString RDSoundPanel::json(int padding) const -{ - QString ret; - - int count=0; - for(QMap >::const_iterator it=panel_arrays. - begin();it!=panel_arrays.end();it++) { - ret+=json(it.key(),4,++count==panel_arrays.size()); - } - - return ret; + return jdoc.toJson(); } @@ -592,7 +578,8 @@ void RDSoundPanel::changeUser() panel_config_panels=rda->user()->configPanels(); UpdatePanels(rda->user()->name()); if(panel_dump_panel_updates) { - printf("{\r\n%s}\r\n",json(4).toUtf8().constData()); + printf("%s\n",json(rda->user()->name()).constData()); + // printf("{\r\n%s}\r\n",json(4).toUtf8().constData()); } // @@ -1349,7 +1336,7 @@ void RDSoundPanel::UpdatePanels(const QString &username) list=panel_arrays.value(username); } for(int i=panel_arrays.value(username).size();isetGeometry(0,0,size().width()-5,size().height()-60); connect(panel,SIGNAL(buttonClicked(int,int,int)), this,SLOT(buttonClickedData(int,int,int))); @@ -1779,6 +1766,34 @@ QString RDSoundPanel::PanelOwner(RDAirPlayConf::PanelType type) } +QString RDSoundPanel::PanelName(RDAirPlayConf::PanelType type,int panel_num) +{ + QString ret; + + QString sql=QString("select ")+ + "`NAME` "+ // 00 + "from "+panel_name_tablename+" where "+ + QString::asprintf("`TYPE`=%u && ",type)+ + QString::asprintf("`PANEL_NO`=%d ",panel_num); + switch(type) { + case RDAirPlayConf::StationPanel: + sql+="&& `OWNER`='"+RDEscapeString(rda->station()->name())+"' "; + break; + + case RDAirPlayConf::UserPanel: + sql+="&& `OWNER`='"+RDEscapeString(rda->user()->name())+"' "; + break; + } + RDSqlQuery *q=new RDSqlQuery(sql); + if(q->first()) { + ret=q->value(0).toString(); + } + delete q; + + return ret; +} + + RDPanelButton *RDSoundPanel::GetVisibleButton(int row,int col) const { return NULL; diff --git a/lib/rdsound_panel.h b/lib/rdsound_panel.h index 2902029f..2c1c8bb3 100644 --- a/lib/rdsound_panel.h +++ b/lib/rdsound_panel.h @@ -2,7 +2,7 @@ // // The sound panel widget // -// (C) Copyright 2002-2023 Fred Gleason +// (C) Copyright 2002-2024 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -21,6 +21,7 @@ #ifndef RDSOUND_PANEL_H #define RDSOUND_PANEL_H +#include #include #include #include @@ -86,8 +87,7 @@ class RDSoundPanel : public RDWidget void setPauseEnabled(bool state); int currentNumber() const; RDAirPlayConf::PanelType currentType() const; - QString json(const QString &owner,int padding=0,bool final=false) const; - QString json(int padding=0) const; + QByteArray json(const QString &owner) const; public slots: void setButton(RDAirPlayConf::PanelType type,int panel,int row,int col, @@ -152,6 +152,7 @@ class RDSoundPanel : public RDWidget void ClearReset(); QString PanelTag(int index); QString PanelOwner(RDAirPlayConf::PanelType type); + QString PanelName(RDAirPlayConf::PanelType type,int panel_num); RDPanelButton *GetVisibleButton(int row,int col) const; QString ButtonSqlFields() const; void ApplyButtonFields(RDPanelButton *button,RDSqlQuery *q);