From 15ff31483d4e48038847fecad8ae79298be415c4 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 3 Aug 2021 20:44:58 -0400 Subject: [PATCH] 2021-08-03 Fred Gleason * Added 'SYSTEM.LONG_DATE_FORMAT', 'SYSTEM.SHORT_DATE_FORMAT' and 'SYSTEM.TIME_FORMAT' fields to the database. * Incremented the database version to 351. * Added 'RDSystem::longDateFormat()', 'RDSystem'setLongDateFormat()', 'RDSystem::shortDateFormat()', 'RDSystem::setShortDateFormat()', 'RDSystem::timeFormat()' and 'RDSystem::setTimeFormat()' methods. * Added a 'Date/Time Formats' section to the 'System-Wide Settings' dialog in rdadmin(1). Signed-off-by: Fred Gleason --- ChangeLog | 9 +++ docs/tables/system.txt | 3 + lib/dbversion.h | 4 +- lib/rd.h | 9 ++- lib/rdsystem.cpp | 39 +++++++++++++ lib/rdsystem.h | 8 ++- rdadmin/Makefile.am | 2 + rdadmin/edit_system.cpp | 101 ++++++++++++++++++++++++++++++--- rdadmin/edit_system.h | 14 +++++ rdadmin/rdadmin.pro | 2 + rdadmin/test_datetimes.cpp | 97 +++++++++++++++++++++++++++++++ rdadmin/test_datetimes.h | 60 ++++++++++++++++++++ utils/rddbmgr/revertschema.cpp | 10 ++++ utils/rddbmgr/schemamap.cpp | 2 +- utils/rddbmgr/updateschema.cpp | 27 ++++++++- 15 files changed, 373 insertions(+), 14 deletions(-) create mode 100644 rdadmin/test_datetimes.cpp create mode 100644 rdadmin/test_datetimes.h diff --git a/ChangeLog b/ChangeLog index 6918cbfc..ac37b957 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22149,3 +22149,12 @@ fails to find the specified log. 2021-08-03 Fred Gleason * Added Raspian support to the 'AR_GET_DISTRO()' autoconf macro. +2021-08-03 Fred Gleason + * Added 'SYSTEM.LONG_DATE_FORMAT', 'SYSTEM.SHORT_DATE_FORMAT' + and 'SYSTEM.TIME_FORMAT' fields to the database. + * Incremented the database version to 351. + * Added 'RDSystem::longDateFormat()', 'RDSystem'setLongDateFormat()', + 'RDSystem::shortDateFormat()', 'RDSystem::setShortDateFormat()', + 'RDSystem::timeFormat()' and 'RDSystem::setTimeFormat()' methods. + * Added a 'Date/Time Formats' section to the 'System-Wide Settings' + dialog in rdadmin(1). diff --git a/docs/tables/system.txt b/docs/tables/system.txt index 36b76c71..faa2889e 100644 --- a/docs/tables/system.txt +++ b/docs/tables/system.txt @@ -15,3 +15,6 @@ SHOW_USER_LIST enum('N','Y') NOTIFICATION_ADDRESS varchar(15) RSS_PROCESSOR_STATION varchar(64) ORIGIN_EMAIL_ADDRESS varchar(64) +LONG_DATE_FORMAT varchar(32) Default 'dddd, MMMM d yyyy' +SHORT_DATE_FORMAT varchar(32) Default 'MM/dd/yyyy' +TIME_FORMAT varchar(32) Default 'hh:mm:ss' diff --git a/lib/dbversion.h b/lib/dbversion.h index c36292c1..fa421e82 100644 --- a/lib/dbversion.h +++ b/lib/dbversion.h @@ -2,7 +2,7 @@ // // The Current Database Schema Version for Rivendell // -// (C) Copyright 2002-2020 Fred Gleason +// (C) Copyright 2002-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 @@ -24,7 +24,7 @@ /* * Current Database Version */ -#define RD_VERSION_DATABASE 350 +#define RD_VERSION_DATABASE 351 #endif // DBVERSION_H diff --git a/lib/rd.h b/lib/rd.h index e9cea2a2..eb2fdc44 100644 --- a/lib/rd.h +++ b/lib/rd.h @@ -2,7 +2,7 @@ // // System-Wide Values for Rivendell // -// (C) Copyright 2002-2020 Fred Gleason +// (C) Copyright 2002-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 @@ -649,5 +649,12 @@ #define RD_LISTWIDGET_ITEM_HEIGHT 25 #define RD_LISTWIDGET_ITEM_WIDTH_PADDING 20 +/* + * Default Date/Time Formats + */ +#define RD_DEFAULT_LONG_DATE_FORMAT "dddd, MMMM d yyyy" +#define RD_DEFAULT_SHORT_DATE_FORMAT "MM/dd/yy" +#define RD_DEFAULT_TIME_FORMAT "hh:mm:ss" + #endif // RD_H diff --git a/lib/rdsystem.cpp b/lib/rdsystem.cpp index 9932d1a3..5b663e5b 100644 --- a/lib/rdsystem.cpp +++ b/lib/rdsystem.cpp @@ -205,6 +205,42 @@ void RDSystem::setRssProcessorStation(const QString &str) const } +QString RDSystem::longDateFormat() const +{ + return GetValue("LONG_DATE_FORMAT").toString(); +} + + +void RDSystem::setLongDateFormat(const QString &str) +{ + SetRow("LONG_DATE_FORMAT",str); +} + + +QString RDSystem::shortDateFormat() const +{ + return GetValue("SHORT_DATE_FORMAT").toString(); +} + + +void RDSystem::setShortDateFormat(const QString &str) +{ + SetRow("SHORT_DATE_FORMAT",str); +} + + +QString RDSystem::timeFormat() const +{ + return GetValue("TIME_FORMAT").toString(); +} + + +void RDSystem::setTimeFormat(const QString &str) +{ + SetRow("TIME_FORMAT",str); +} + + QString RDSystem::xml() const { QString xml="\n"; @@ -214,6 +250,9 @@ QString RDSystem::xml() const xml+=RDXmlField("maxPostLength",maxPostLength()); xml+=RDXmlField("isciXreferencePath",isciXreferencePath()); xml+=RDXmlField("tempCartGroup",tempCartGroup()); + xml+=RDXmlField("longDateFormat",longDateFormat()); + xml+=RDXmlField("shortDateFormat",shortDateFormat()); + xml+=RDXmlField("timeFormat",timeFormat()); xml+="\n"; return xml; diff --git a/lib/rdsystem.h b/lib/rdsystem.h index 1fe15176..ee245aa6 100644 --- a/lib/rdsystem.h +++ b/lib/rdsystem.h @@ -2,7 +2,7 @@ // // System-wide Rivendell settings // -// (C) Copyright 2009,2016 Fred Gleason +// (C) Copyright 2009-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 @@ -48,6 +48,12 @@ class RDSystem void setNotificationAddress(const QHostAddress &addr); QString rssProcessorStation() const; void setRssProcessorStation(const QString &str=QString()) const; + QString longDateFormat() const; + void setLongDateFormat(const QString &str); + QString shortDateFormat() const; + void setShortDateFormat(const QString &str); + QString timeFormat() const; + void setTimeFormat(const QString &str); QString xml() const; private: diff --git a/rdadmin/Makefile.am b/rdadmin/Makefile.am index 5acf97f9..0cabab92 100644 --- a/rdadmin/Makefile.am +++ b/rdadmin/Makefile.am @@ -123,6 +123,7 @@ dist_rdadmin_SOURCES = add_feed.cpp add_feed.h\ rdadmin.cpp rdadmin.h\ rename_group.cpp rename_group.h\ test_import.cpp test_import.h\ + test_datetimes.cpp test_datetimes.h\ view_adapters.cpp view_adapters.h\ view_node_info.cpp view_node_info.h\ view_pypad_errors.cpp view_pypad_errors.h @@ -204,6 +205,7 @@ nodist_rdadmin_SOURCES = global_credits.c\ moc_rdadmin.cpp\ moc_rename_group.cpp\ moc_test_import.cpp\ + moc_test_datetimes.cpp\ moc_view_adapters.cpp\ moc_view_node_info.cpp\ moc_view_pypad_errors.cpp diff --git a/rdadmin/edit_system.cpp b/rdadmin/edit_system.cpp index 8a975074..06e19d89 100644 --- a/rdadmin/edit_system.cpp +++ b/rdadmin/edit_system.cpp @@ -50,6 +50,11 @@ EditSystem::EditSystem(QWidget *parent) edit_encoders_dialog=new ListEncoders(this); edit_station_list_model=new RDStationListModel(true,"",this); + // + // Dialogs + // + edit_test_datetimes_dialog=new TestDatetimes(this); + // // System Sample Rate // @@ -183,6 +188,45 @@ EditSystem::EditSystem(QWidget *parent) connect(edit_save_button,SIGNAL(clicked()),this,SLOT(saveData())); edit_save_button->hide(); + // + // Date/Time Formats + // + edit_datetime_group=new QGroupBox(tr("Date/Time Formats"),this); + edit_datetime_group->setFont(labelFont()); + + edit_long_date_label= + new QLabel(tr("Long Date Format")+":",edit_datetime_group); + edit_long_date_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit_long_date_label->setFont(labelFont()); + edit_long_date_edit=new QLineEdit(edit_datetime_group); + edit_long_date_edit->setFont(defaultFont()); + edit_long_date_edit->setMaxLength(32); + + edit_short_date_label= + new QLabel(tr("Short Date Format")+":",edit_datetime_group); + edit_short_date_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit_short_date_label->setFont(labelFont()); + edit_short_date_edit=new QLineEdit(edit_datetime_group); + edit_short_date_edit->setFont(defaultFont()); + edit_short_date_edit->setMaxLength(32); + + edit_time_label= + new QLabel(tr("Time Format")+":",edit_datetime_group); + edit_time_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit_time_label->setFont(labelFont()); + edit_time_edit=new QLineEdit(edit_datetime_group); + edit_time_edit->setFont(defaultFont()); + edit_time_edit->setMaxLength(32); + + edit_datetime_test_button=new QPushButton(tr("Test"),edit_datetime_group); + connect(edit_datetime_test_button,SIGNAL(clicked()), + this,SLOT(datetimeTestData())); + + edit_datetime_defaults_button= + new QPushButton(tr("Restore\nDefaults"),edit_datetime_group); + connect(edit_datetime_defaults_button,SIGNAL(clicked()), + this,SLOT(datetimeDefaultsData())); + // // Encoders Button // @@ -207,6 +251,9 @@ EditSystem::EditSystem(QWidget *parent) edit_cancel_button->setText(tr("Cancel")); connect(edit_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData())); + // + // Load Values + // edit_duplicate_carts_box->setChecked(edit_system->allowDuplicateCartTitles()); edit_fix_duplicate_carts_box-> setChecked(edit_system->fixDuplicateCartTitles()); @@ -217,8 +264,9 @@ EditSystem::EditSystem(QWidget *parent) edit_notification_address_edit-> setText(edit_system->notificationAddress().toString()); edit_show_user_list_box->setChecked(edit_system->showUserList()); - - + edit_long_date_edit->setText(edit_system->longDateFormat()); + edit_short_date_edit->setText(edit_system->shortDateFormat()); + edit_time_edit->setText(edit_system->timeFormat()); QString station=edit_system->rssProcessorStation(); for(int i=0;icount();i++) { @@ -246,12 +294,13 @@ EditSystem::~EditSystem() delete edit_duplicate_label; delete edit_duplicate_view; delete edit_duplicate_model; + delete edit_test_datetimes_dialog; } QSize EditSystem::sizeHint() const { - return QSize(500,306+y_pos); + return QSize(500,406+y_pos); } @@ -328,6 +377,29 @@ void EditSystem::encodersData() } +void EditSystem::datetimeTestData() +{ + edit_test_datetimes_dialog->exec(edit_long_date_edit->text(), + edit_short_date_edit->text(), + edit_time_edit->text()); +} + + +void EditSystem::datetimeDefaultsData() +{ + if(QMessageBox::warning(this,"RDAdmin - "+tr("Warning"), + tr("This will reset all date/time display formats to default values!")+ + "\n"+ + tr("Proceed?"), + QMessageBox::No,QMessageBox::Yes)!=QMessageBox::Yes) { + return; + } + edit_long_date_edit->setText(RD_DEFAULT_LONG_DATE_FORMAT); + edit_short_date_edit->setText(RD_DEFAULT_SHORT_DATE_FORMAT); + edit_time_edit->setText(RD_DEFAULT_TIME_FORMAT); +} + + void EditSystem::okData() { QString sql; @@ -439,14 +511,17 @@ void EditSystem::okData() else { edit_system->setRssProcessorStation(edit_rss_processor_box->currentText()); } + edit_system->setLongDateFormat(edit_long_date_edit->text()); + edit_system->setShortDateFormat(edit_short_date_edit->text()); + edit_system->setTimeFormat(edit_time_edit->text()); - done(0); + done(true); } void EditSystem::cancelData() { - done(-1); + done(false); } @@ -504,9 +579,19 @@ void EditSystem::resizeEvent(QResizeEvent *e) edit_rss_processor_label->setGeometry(10,207,235,20); edit_rss_processor_box->setGeometry(250,207,200,20); - edit_duplicate_hidden_label->setGeometry(15,229,size().width()-30,50); - edit_duplicate_view->setGeometry(10,277,size().width()-20,215); - edit_save_button->setGeometry(size().width()-85,497,70,25); + edit_datetime_group->setGeometry(10,229,size().width()-20,100); + edit_datetime_test_button->setGeometry(5,22,80,35); + edit_datetime_defaults_button->setGeometry(5,60,80,35); + edit_long_date_label->setGeometry(110,27,120,20); + edit_long_date_edit->setGeometry(235,27,edit_datetime_group->width()-240,20); + edit_short_date_label->setGeometry(110,49,120,20); + edit_short_date_edit->setGeometry(235,49,edit_datetime_group->width()-240,20); + edit_time_label->setGeometry(110,71,120,20); + edit_time_edit->setGeometry(235,71,edit_datetime_group->width()-240,20); + + edit_duplicate_hidden_label->setGeometry(15,329,size().width()-30,50); + edit_duplicate_view->setGeometry(10,377,size().width()-20,215); + edit_save_button->setGeometry(size().width()-85,597,70,25); edit_encoders_button->setGeometry(10,size().height()-60,120,50); edit_ok_button->setGeometry(size().width()-180,size().height()-60,80,50); diff --git a/rdadmin/edit_system.h b/rdadmin/edit_system.h index 9103eb82..e893db7a 100644 --- a/rdadmin/edit_system.h +++ b/rdadmin/edit_system.h @@ -22,6 +22,7 @@ #define EDIT_SYSTEM_H #include +#include #include #include #include @@ -37,6 +38,7 @@ #include #include "list_encoders.h" +#include "test_datetimes.h" class EditSystem : public RDDialog { @@ -52,6 +54,8 @@ class EditSystem : public RDDialog void duplicatesCheckedData(bool state); void saveData(); void encodersData(); + void datetimeTestData(); + void datetimeDefaultsData(); void okData(); void cancelData(); @@ -94,6 +98,16 @@ class EditSystem : public RDDialog ListEncoders *edit_encoders_dialog; int y_pos; RDStationListModel *edit_station_list_model; + QGroupBox *edit_datetime_group; + QLabel *edit_long_date_label; + QLineEdit *edit_long_date_edit; + QLabel *edit_short_date_label; + QLineEdit *edit_short_date_edit; + QLabel *edit_time_label; + QLineEdit *edit_time_edit; + QPushButton *edit_datetime_test_button; + QPushButton *edit_datetime_defaults_button; + TestDatetimes *edit_test_datetimes_dialog; }; diff --git a/rdadmin/rdadmin.pro b/rdadmin/rdadmin.pro index e238b5e7..ee39245d 100644 --- a/rdadmin/rdadmin.pro +++ b/rdadmin/rdadmin.pro @@ -82,6 +82,7 @@ x11 { SOURCES += rdadmin.cpp SOURCES += rename_group.cpp SOURCES += test_import.cpp + SOURCES += test_datetimes.cpp SOURCES += view_adapters.cpp SOURCES += view_pypad_errors.cpp SOURCES += xpm_info_banner1.cpp @@ -151,6 +152,7 @@ x11 { HEADERS += rdadmin.h HEADERS += rename_group.h HEADERS += test_import.h + HEADERS += test_datetimes.h HEADERS += view_adapters.h HEADERS += view_pypad_errors.h } diff --git a/rdadmin/test_datetimes.cpp b/rdadmin/test_datetimes.cpp new file mode 100644 index 00000000..a09633da --- /dev/null +++ b/rdadmin/test_datetimes.cpp @@ -0,0 +1,97 @@ +// test_datetimes.cpp +// +// Test Rivendell Date/Time Formats +// +// (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 "test_datetimes.h" + +TestDatetimes::TestDatetimes(QWidget *parent) + : RDDialog(parent) +{ + setWindowTitle("RDAdmin - "+tr("Test Date/Time Formats")); + + d_sample_datetime=QDateTime(QDate(2021,12,28),QTime(14,10,23)); + + d_sample_datetime_label_label=new QLabel(tr("Sample Date/Time")+":",this); + d_sample_datetime_label_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + d_sample_datetime_label_label->setFont(labelFont()); + d_sample_datetime_label=new QLabel(this); + d_sample_datetime_label-> + setText(d_sample_datetime.toString("dddd MMMM d yyyy - h:mm:ss AP")); + + d_long_date_label_label=new QLabel(tr("Long Date")+":",this); + d_long_date_label_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + d_long_date_label_label->setFont(labelFont()); + d_long_date_label=new QLabel(this); + + d_short_date_label_label=new QLabel(tr("Short Date")+":",this); + d_short_date_label_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + d_short_date_label_label->setFont(labelFont()); + d_short_date_label=new QLabel(this); + + d_time_label_label=new QLabel(tr("Time")+":",this); + d_time_label_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + d_time_label_label->setFont(labelFont()); + d_time_label=new QLabel(this); + + d_close_button=new QPushButton(tr("Close"),this); + d_close_button->setFont(buttonFont()); + connect(d_close_button,SIGNAL(clicked()),this,SLOT(closeData())); +} + + +QSize TestDatetimes::sizeHint() const +{ + return QSize(400,150); +} + + +int TestDatetimes::exec(const QString &long_date_fmt,\ + const QString &short_date_fmt, + const QString &time_fmt) +{ + d_long_date_label->setText(d_sample_datetime.toString(long_date_fmt)); + d_short_date_label->setText(d_sample_datetime.toString(short_date_fmt)); + d_time_label->setText(d_sample_datetime.toString(time_fmt)); + + return QDialog::exec(); +} + + +void TestDatetimes::closeData() +{ + done(true); +} + + +void TestDatetimes::resizeEvent(QResizeEvent *e) +{ + d_sample_datetime_label_label->setGeometry(10,2,120,20); + d_sample_datetime_label->setGeometry(135,2,size().width()-145,20); + + d_long_date_label_label->setGeometry(10,30,120,20); + d_long_date_label->setGeometry(135,30,size().width()-145,20); + + d_short_date_label_label->setGeometry(10,50,120,20); + d_short_date_label->setGeometry(135,50,size().width()-145,20); + + d_time_label_label->setGeometry(10,70,120,20); + d_time_label->setGeometry(135,70,size().width()-145,20); + + d_close_button->setGeometry(size().width()-90,size().height()-60,80,50); +} diff --git a/rdadmin/test_datetimes.h b/rdadmin/test_datetimes.h new file mode 100644 index 00000000..ad652eed --- /dev/null +++ b/rdadmin/test_datetimes.h @@ -0,0 +1,60 @@ +// test_datetimes.h +// +// Test Rivendell Date/Time Formats +// +// (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 TEST_DATETIMES_H +#define TEST_DATETIMES_H + +#include +#include + +#include + +class TestDatetimes : public RDDialog +{ + Q_OBJECT + public: + TestDatetimes(QWidget *parent=0); + QSize sizeHint() const; + + public slots: + int exec(const QString &long_date_fmt,const QString &short_date_fmt, + const QString &time_fmt); + + private slots: + void closeData(); + + protected: + void resizeEvent(QResizeEvent *e); + + private: + QDateTime d_sample_datetime; + QLabel *d_sample_datetime_label; + QLabel *d_sample_datetime_label_label; + QLabel *d_long_date_label; + QLabel *d_long_date_label_label; + QLabel *d_short_date_label; + QLabel *d_short_date_label_label; + QLabel *d_time_label; + QLabel *d_time_label_label; + QPushButton *d_close_button; +}; + + +#endif // TEST_DATETIMES_H diff --git a/utils/rddbmgr/revertschema.cpp b/utils/rddbmgr/revertschema.cpp index 7b816fe9..4aa1aecf 100644 --- a/utils/rddbmgr/revertschema.cpp +++ b/utils/rddbmgr/revertschema.cpp @@ -40,6 +40,16 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg) // NEW SCHEMA REVERSIONS GO HERE... + // + // Revert 351 + // + if((cur_schema==351)&&(set_schemacur_schema)) { + sql=QString("alter table `SYSTEM` ")+ + "add column `LONG_DATE_FORMAT` varchar(32) not null default 'dddd, MMMM d yyyy' "+ + "after `ORIGIN_EMAIL_ADDRESS`"; + if(!RDSqlQuery::apply(sql,err_msg)) { + return false; + } + + sql=QString("alter table `SYSTEM` ")+ + "add column `SHORT_DATE_FORMAT` varchar(32) not null default 'MM/dd/yy' "+ + "after `LONG_DATE_FORMAT`"; + if(!RDSqlQuery::apply(sql,err_msg)) { + return false; + } + + sql=QString("alter table `SYSTEM` ")+ + "add column `TIME_FORMAT` varchar(32) not null default 'hh:mm:ss' "+ + "after `SHORT_DATE_FORMAT`"; + if(!RDSqlQuery::apply(sql,err_msg)) { + return false; + } + + WriteSchemaVersion(++cur_schema); + } + // NEW SCHEMA UPDATES GO HERE...