From 64a6ebabe05817b79797f6d2b50af6b0668d8e2d Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Sat, 19 Jun 2021 08:53:30 -0400 Subject: [PATCH] 2021-06-19 Fred Gleason * Added an 'RDMainWindow' class. * Added 'RDMainWindow' to rdairplay(1). * Added 'RDMainWindow' to rdpanel(1). Signed-off-by: Fred Gleason --- ChangeLog | 4 ++ lib/Makefile.am | 2 + lib/lib.pro | 2 + lib/rdmainwindow.cpp | 143 ++++++++++++++++++++++++++++++++++++++++ lib/rdmainwindow.h | 55 ++++++++++++++++ rdairplay/rdairplay.cpp | 10 ++- rdairplay/rdairplay.h | 4 +- rdpanel/rdpanel.cpp | 11 ++-- rdpanel/rdpanel.h | 5 +- 9 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 lib/rdmainwindow.cpp create mode 100644 lib/rdmainwindow.h diff --git a/ChangeLog b/ChangeLog index 93bea911..335c77d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21919,3 +21919,7 @@ 2021-06-17 Fred Gleason * Fixed a regression in the build system that caused consolehelper(8) components to be installed incorrectly on RHEL. +2021-06-19 Fred Gleason + * Added an 'RDMainWindow' class. + * Added 'RDMainWindow' to rdairplay(1). + * Added 'RDMainWindow' to rdpanel(1). diff --git a/lib/Makefile.am b/lib/Makefile.am index 4e038cad..e063cc8e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -186,6 +186,7 @@ dist_librd_la_SOURCES = dbversion.h\ rdmacro.cpp rdmacro.h\ rdmacro_event.cpp rdmacro_event.h\ rdmacrocartmodel.cpp rdmacrocartmodel.h\ + rdmainwindow.cpp rdmainwindow.h\ rdmarker_bar.cpp rdmarker_bar.h\ rdmarkerdialog.cpp rdmarkerdialog.h\ rdmarkerplayer.cpp rdmarkerplayer.h\ @@ -364,6 +365,7 @@ nodist_librd_la_SOURCES = moc_rdadd_cart.cpp\ moc_rdlogplay.cpp\ moc_rdmacro_event.cpp\ moc_rdmacrocartmodel.cpp\ + moc_rdmainwindow.cpp\ moc_rdmarker_bar.cpp\ moc_rdmarkerdialog.cpp\ moc_rdmarkerplayer.cpp\ diff --git a/lib/lib.pro b/lib/lib.pro index 46d79b79..4a3162de 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -140,6 +140,7 @@ SOURCES += rdlogplay.cpp SOURCES += rdmacro.cpp SOURCES += rdmacro_event.cpp SOURCES += rdmacrocartmodel.cpp +SOURCES += rdmainwindow.cpp SOURCES += rdmarkerdialog.cpp SOURCES += rdmarkerplayer.cpp SOURCES += rdmarkerreadout.cpp @@ -319,6 +320,7 @@ HEADERS += rdlogplay.h HEADERS += rdmacro.h HEADERS += rdmacro_event.h HEADERS += rdmacrocartmodel.h +HEADERS += rdmainwindow.h HEADERS += rdmarkerdialog.h HEADERS += rdmarkerplayer.h HEADERS += rdmarkerreadout.h diff --git a/lib/rdmainwindow.cpp b/lib/rdmainwindow.cpp new file mode 100644 index 00000000..e143c613 --- /dev/null +++ b/lib/rdmainwindow.cpp @@ -0,0 +1,143 @@ +// rdmainwindow.cpp +// +// Top-level window for Rivendell GUI modules. +// +// (C) Copyright 2021 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 +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include + +#include + +#include "rdmainwindow.h" + +RDMainWindow::RDMainWindow(const QString &cmdname,Qt::WindowFlags f) + : RDWidget(NULL,f) +{ + d_command_name=cmdname; +} + + +RDMainWindow::RDMainWindow(const QString &cmdname,RDConfig *c, + Qt::WindowFlags f) + : RDWidget(c,NULL,f) +{ + d_command_name=cmdname; + + if(getenv("HOME")!=NULL) { + d_conf_dir=new QDir(QString(getenv("HOME"))+"/.rivendell"); + d_conf_path=d_conf_dir->path()+"/"+d_command_name+"rc"; + if(!d_conf_dir->mkpath(d_conf_dir->path())) { + delete d_conf_dir; + d_conf_dir=NULL; + } + } +} + + +RDMainWindow::~RDMainWindow() +{ + if(d_conf_dir!=NULL) { + delete d_conf_dir; + } +} + + +bool RDMainWindow::loadSettings(bool apply_geometry) +{ + RDProfile *p=NULL; + int x=0; + int y=0; + int w=0; + int h=0; + + if(d_conf_dir==NULL) { + return false; + } + p=new RDProfile(); + if(!p->setSource(d_conf_path)) { + delete p; + return false; + } + + // + // Set Geometry + // + if(apply_geometry) { + x=p->intValue(d_command_name,"X"); + y=p->intValue(d_command_name,"Y"); + w=p->intValue(d_command_name,"Width"); + h=p->intValue(d_command_name,"Height"); + if((x>=0)&&(y>=0)&&(w>0)&&(h>0)) { + setGeometry(x,y,w,h); + } + } + + loadLocalSettings(p); + + delete p; + + return true; +} + + +bool RDMainWindow::saveSettings() const +{ + if(d_conf_dir==NULL) { + return false; + } + + // + // Save Geometry + // + QString temppath=d_conf_path+"-TEMP"; + FILE *f=NULL; + + if((f=fopen(temppath.toUtf8(),"w"))==NULL) { + return false; + } + fprintf(f,"[%s]\n",d_command_name.toUtf8().constData()); + fprintf(f,"X=%d\n",geometry().x()); + fprintf(f,"Y=%d\n",geometry().y()); + fprintf(f,"Width=%d\n",geometry().width()); + fprintf(f,"Height=%d\n",geometry().height()); + + saveLocalSettings(f); + + fclose(f); + if(rename(temppath.toUtf8(),d_conf_path.toUtf8())!=0) { + unlink(temppath.toUtf8()); + return false; + } + + return true; +} + + +QString RDMainWindow::commandName() const +{ + return d_command_name; +} + + +void RDMainWindow::loadLocalSettings(RDProfile *p) +{ +} + + +void RDMainWindow::saveLocalSettings(FILE *f) const +{ +} diff --git a/lib/rdmainwindow.h b/lib/rdmainwindow.h new file mode 100644 index 00000000..4e705a51 --- /dev/null +++ b/lib/rdmainwindow.h @@ -0,0 +1,55 @@ +// rdmainwindow.h +// +// Top-level window for Rivendell GUI modules. +// +// (C) Copyright 2021 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 +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#ifndef RDMAINWINDOW_H +#define RDMAINWINDOW_H + +#include + +#include +#include + +#include +#include +#include + +class RDMainWindow : public RDWidget +{ + Q_OBJECT; + public: + RDMainWindow(const QString &cmdname,Qt::WindowFlags f=0); + RDMainWindow(const QString &cmdname,RDConfig *c,Qt::WindowFlags f=0); + ~RDMainWindow(); + bool loadSettings(bool apply_geometry); + bool saveSettings() const; + + protected: + QString commandName() const; + virtual void loadLocalSettings(RDProfile *p); + virtual void saveLocalSettings(FILE *f) const; + + private: + QString d_command_name; + QDir *d_conf_dir; + QString d_conf_path; +}; + + +#endif // RDWIDGET_H diff --git a/rdairplay/rdairplay.cpp b/rdairplay/rdairplay.cpp index c9f450f5..c59d3f3a 100644 --- a/rdairplay/rdairplay.cpp +++ b/rdairplay/rdairplay.cpp @@ -40,7 +40,7 @@ void SigHandler(int signo); MainWidget::MainWidget(RDConfig *config,QWidget *parent) - : RDWidget(config,parent) + : RDMainWindow("rdairplay",config) { QString str; int cards[3]; @@ -711,6 +711,10 @@ MainWidget::MainWidget(RDConfig *config,QWidget *parent) } rda->syslog(LOG_INFO,"RDAirPlay started"); + + if(!loadSettings(true)) { + showMaximized(); + } } @@ -1946,6 +1950,7 @@ void MainWidget::closeEvent(QCloseEvent *e) rda->airplayConf()->setExitCode(RDAirPlayConf::ExitClean); rda->syslog(LOG_INFO,"RDAirPlay exiting"); air_lock->unlock(); + saveSettings(); exit(0); } if(QMessageBox::question(this,"RDAirPlay",tr("Exit RDAirPlay?"), @@ -1960,6 +1965,7 @@ void MainWidget::closeEvent(QCloseEvent *e) rda->airplayConf()->setExitCode(RDAirPlayConf::ExitClean); rda->syslog(LOG_INFO,"RDAirPlay exiting"); air_lock->unlock(); + saveSettings(); exit(0); } @@ -2392,7 +2398,7 @@ int main(int argc,char *argv[]) RDConfig *config=new RDConfig(); config->load(); MainWidget *w=new MainWidget(config); - w->setGeometry(QRect(QPoint(0,0),w->sizeHint())); + // w->setGeometry(QRect(QPoint(0,0),w->sizeHint())); w->show(); return a.exec(); } diff --git a/rdairplay/rdairplay.h b/rdairplay/rdairplay.h index 26b268e3..cf7644fb 100644 --- a/rdairplay/rdairplay.h +++ b/rdairplay/rdairplay.h @@ -25,9 +25,9 @@ #include #include #include +#include #include #include -#include #include "button_log.h" #include "colors.h" @@ -54,7 +54,7 @@ #define MESSAGE_WIDGET_WIDTH 410 #define RDAIRPLAY_USAGE "[OPTIONS]\n" -class MainWidget : public RDWidget +class MainWidget : public RDMainWindow { Q_OBJECT public: diff --git a/rdpanel/rdpanel.cpp b/rdpanel/rdpanel.cpp index d7fcaeac..c68c9646 100644 --- a/rdpanel/rdpanel.cpp +++ b/rdpanel/rdpanel.cpp @@ -40,7 +40,7 @@ RDAudioPort *rdaudioport_conf; RDCartDialog *panel_cart_dialog; MainWidget::MainWidget(RDConfig *c,QWidget *parent) - : RDWidget(c,parent) + : RDMainWindow("rdpanel",c) { QPixmap panel_skin_pixmap; QString err_msg; @@ -48,10 +48,7 @@ MainWidget::MainWidget(RDConfig *c,QWidget *parent) // // Fix the Window Size // -#ifndef RESIZABLE setMinimumSize(sizeHint()); - // setMaximumSize(sizeHint()); -#endif // RESIZABLE // // Open the Database @@ -247,6 +244,10 @@ MainWidget::MainWidget(RDConfig *c,QWidget *parent) panel_empty_cart->hide(); } + if(!loadSettings(true)) { + showMaximized(); + } + rda->ripc()->connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password()); } @@ -345,6 +346,7 @@ void MainWidget::wheelEvent(QWheelEvent *e) void MainWidget::closeEvent(QCloseEvent *e) { panel_db->removeDatabase(rda->config()->mysqlDbname()); + saveSettings(); exit(0); } @@ -392,7 +394,6 @@ int main(int argc,char *argv[]) RDConfig *config=new RDConfig(); config->load(); MainWidget *w=new MainWidget(config); - w->setGeometry(QRect(QPoint(0,0),w->sizeHint())); w->show(); return a.exec(); } diff --git a/rdpanel/rdpanel.h b/rdpanel/rdpanel.h index f74344ca..ea41f34e 100644 --- a/rdpanel/rdpanel.h +++ b/rdpanel/rdpanel.h @@ -22,6 +22,7 @@ #define RDPANEL_H #include +#include #include #include #include @@ -31,11 +32,9 @@ // #define MASTER_TIMER_INTERVAL 100 #define METER_INTERVAL 50 -//#define RDPANEL_PANEL_BUTTON_ROWS 7 -//#define RDPANEL_PANEL_BUTTON_COLUMNS 9 #define RDPANEL_USAGE "\n" -class MainWidget : public RDWidget +class MainWidget : public RDMainWindow { Q_OBJECT public: