From 1fd581a442924bbe3e4a26524542eb7f9cc0d7f9 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Sat, 12 Feb 2022 11:54:28 -0500 Subject: [PATCH] 2022-02-12 Fred Gleason * Added CSV generation routines in 'lib/rdcsv.[cpp|h]'. * Added a 'Log Listing (CSV)' report to rdlogedit(1). Signed-off-by: Fred Gleason --- ChangeLog | 3 + lib/Makefile.am | 3 +- lib/librd.pro | 4 +- lib/rdcsv.cpp | 50 +++++++++++++ lib/rdcsv.h | 31 ++++++++ rdlogedit/list_reports.cpp | 149 ++++++++++++++++++++++++++++++++++++- rdlogedit/list_reports.h | 3 +- 7 files changed, 237 insertions(+), 6 deletions(-) create mode 100644 lib/rdcsv.cpp create mode 100644 lib/rdcsv.h diff --git a/ChangeLog b/ChangeLog index 14d88e47..ad8ce4ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22881,3 +22881,6 @@ 2022-01-10 Fred Gleason * Fixed a bug that caused rdimport(1) to fail to apply the '' tag when processing RDXL metadata. +2022-02-12 Fred Gleason + * Added CSV generation routines in 'lib/rdcsv.[cpp|h]'. + * Added a 'Log Listing (CSV)' report to rdlogedit(1). diff --git a/lib/Makefile.am b/lib/Makefile.am index 6689e53d..1ee51c78 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2,7 +2,7 @@ ## ## Automake.am for rivendell/lib ## -## (C) Copyright 2002-2021 Fred Gleason +## (C) Copyright 2002-2022 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 @@ -98,6 +98,7 @@ dist_librd_la_SOURCES = dbversion.h\ rdconfig.cpp rdconfig.h\ rdcopyaudio.cpp rdcopyaudio.h\ rdcoreapplication.cpp rdcoreapplication.h\ + rdcsv.cpp rdcsv.h\ rdcueedit.cpp rdcueedit.h\ rdcueeditdialog.cpp rdcueeditdialog.h\ rdcut.cpp rdcut.h\ diff --git a/lib/librd.pro b/lib/librd.pro index a7a01d82..4f6342aa 100644 --- a/lib/librd.pro +++ b/lib/librd.pro @@ -2,7 +2,7 @@ # # The lib/ QMake project file for Rivendell. # -# (C) Copyright 2003-2021 Fred Gleason +# (C) Copyright 2003-2022 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 @@ -70,6 +70,7 @@ SOURCES += rdcombobox.cpp SOURCES += rdconf.cpp SOURCES += rdconfig.cpp SOURCES += rdcoreapplication.cpp +SOURCES += rdcsv.cpp SOURCES += rdcueedit.cpp SOURCES += rdcueeditdialog.cpp SOURCES += rdcut.cpp @@ -259,6 +260,7 @@ HEADERS += rdcombobox.h HEADERS += rdconf.h HEADERS += rdconfig.h HEADERS += rdcoreapplication.h +HEADERS += rdcsv.h HEADERS += rdcueedit.h HEADERS += rdcueeditdialog.h HEADERS += rdcut_dialog.h diff --git a/lib/rdcsv.cpp b/lib/rdcsv.cpp new file mode 100644 index 00000000..da5084f1 --- /dev/null +++ b/lib/rdcsv.cpp @@ -0,0 +1,50 @@ +// rdcsv.cpp +// +// Routines for generating CSV files +// +// (C) Copyright 2022 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library 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 "rdcsv.h" + + +QString RDCsvField(const QString &val,bool last) +{ + QString ret=val; + if(val.contains(",")||val.contains("\"")) { + ret="\""+ret.replace("\"","\"\"")+"\""; + } + if(last) { + ret+="\r\n"; + } + else { + ret+=","; + } + + return ret; +} + + +QString RDCsvField(int val,bool last) +{ + return RDCsvField(QString::asprintf("%d",val),last); +} + + +QString RDCsvField(unsigned val,bool last) +{ + return RDCsvField(QString::asprintf("%u",val),last); +} diff --git a/lib/rdcsv.h b/lib/rdcsv.h new file mode 100644 index 00000000..eaea3c77 --- /dev/null +++ b/lib/rdcsv.h @@ -0,0 +1,31 @@ +// rdcsv.h +// +// Routines for generating CSV files +// +// (C) Copyright 2022 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library 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 RDCSV_H +#define RDCSV_H + +#include + +QString RDCsvField(const QString &val="",bool last=false); +QString RDCsvField(int val,bool last=false); +QString RDCsvField(unsigned val,bool last=false); + + +#endif // RDCSV_H diff --git a/rdlogedit/list_reports.cpp b/rdlogedit/list_reports.cpp index 800ecc20..00235e19 100644 --- a/rdlogedit/list_reports.cpp +++ b/rdlogedit/list_reports.cpp @@ -2,7 +2,7 @@ // // List and Generate Log Reports // -// (C) Copyright 2002-2021 Fred Gleason +// (C) Copyright 2002-2022 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 @@ #include #include +#include #include #include #include @@ -57,7 +58,8 @@ ListReports::ListReports(const QString &logname,const QString &description, list_reports_box=new QComboBox(this); list_reports_box->setGeometry(50,10,sizeHint().width()-60,19); list_reports_box->insertItem(0,tr("Log Listing")); - list_reports_box->insertItem(1,tr("Log Exception Report")); + list_reports_box->insertItem(1,tr("Log Listing (CSV)")); + list_reports_box->insertItem(2,tr("Log Exception Report")); QLabel *list_reports_label=new QLabel(tr("Type:"),this); list_reports_label->setGeometry(10,10,35,19); list_reports_label->setFont(labelFont()); @@ -138,7 +140,11 @@ void ListReports::generateData() GenerateLogReport(&report); break; - case 1: // XLoad Report + case 1: // Event Report + GenerateLogCsvReport(&report); + break; + + case 2: // XLoad Report GenerateExceptionReport(&report,list_date_edit->date()); break; @@ -288,6 +294,143 @@ void ListReports::GenerateLogReport(QString *report) } +void ListReports::GenerateLogCsvReport(QString *report) +{ + RDLogLine *logline; + + // + // Column Names + // + *report+=RDCsvField("TYPE"); + *report+=RDCsvField("START_TIME"); + *report+=RDCsvField("TIME_TYPE"); + *report+=RDCsvField("TRANS_TYPE"); + *report+=RDCsvField("CART_NUMBER"); + *report+=RDCsvField("GROUP_NAME"); + *report+=RDCsvField("LENGTH"); + *report+=RDCsvField("TITLE"); + *report+=RDCsvField("ARTIST"); + *report+=RDCsvField("CLIENT"); + *report+=RDCsvField("AGENCY"); + *report+=RDCsvField("ALBUM"); + *report+=RDCsvField("LABEL"); + *report+=RDCsvField("CONDUCTOR"); + *report+=RDCsvField("COMPOSER"); + *report+=RDCsvField("PUBLISHER"); + *report+=RDCsvField("USER_DEFINED"); + *report+=RDCsvField("SONG_ID"); + *report+=RDCsvField("USAGE_CODE"); + *report+=RDCsvField("SOURCE"); + *report+=RDCsvField("EXT_DATA"); + *report+=RDCsvField("EXT_EVENT_ID"); + *report+=RDCsvField("EXT_ANNC_TYPE"); + *report+=RDCsvField("LINE_ID"); + *report+=RDCsvField("LINE",true); + + for(int i=0;ilineCount();i++) { + logline=list_model->logLine(i); + + // + // Event Type + // + *report+=RDCsvField(RDLogLine::typeText(logline->type())); + + // + // Time + // + if(logline->startTime(RDLogLine::Imported).isNull()|| + (logline->startTime(RDLogLine::Imported)==QTime(0,0,0,0))) { + *report+=RDCsvField(); + } + else { + *report+=RDCsvField(logline->startTime(RDLogLine::Imported). + toString("hh:mm:ss")); + } + if(logline->timeType()==RDLogLine::Hard) { + *report+=RDCsvField("Hard"); + } + else { + *report+=RDCsvField("Relative"); + } + + // + // Transition Type + // + *report+=RDCsvField(RDLogLine::transText(logline->transType())); + + switch(logline->type()) { + case RDLogLine::Cart: + case RDLogLine::Macro: + *report+=RDCsvField(logline->cartNumber()); + *report+=RDCsvField(logline->groupName()); + *report+=RDCsvField(RDGetTimeLength(logline->forcedLength(),false,false)); + *report+=RDCsvField(logline->title()); + *report+=RDCsvField(logline->artist()); + break; + + case RDLogLine::Marker: + case RDLogLine::Track: + *report+=RDCsvField(); + *report+=RDCsvField(); + *report+=RDCsvField(":00"); + *report+=RDCsvField(logline->markerComment()); + *report+=RDCsvField(); + break; + + case RDLogLine::TrafficLink: + *report+=RDCsvField(); + *report+=RDCsvField(); + *report+=RDCsvField(":00"); + *report+=RDCsvField(tr("Traffic Import")); + *report+=RDCsvField(); + break; + + case RDLogLine::MusicLink: + *report+=RDCsvField(); + *report+=RDCsvField(); + *report+=RDCsvField(":00"); + *report+=RDCsvField(tr("Music Import")); + *report+=RDCsvField(); + break; + + case RDLogLine::Chain: + *report+=RDCsvField(); + *report+=RDCsvField(); + *report+=RDCsvField(); + *report+=RDCsvField(logline->markerLabel()); + *report+=RDCsvField(); + break; + + case RDLogLine::OpenBracket: + case RDLogLine::CloseBracket: + case RDLogLine::UnknownType: + *report+=RDCsvField(); + *report+=RDCsvField(); + *report+=RDCsvField(); + *report+=RDCsvField(); + *report+=RDCsvField(); + break; + } + *report+=RDCsvField(logline->client()); + *report+=RDCsvField(logline->agency()); + *report+=RDCsvField(logline->album()); + *report+=RDCsvField(logline->label()); + *report+=RDCsvField(logline->conductor()); + *report+=RDCsvField(logline->composer()); + *report+=RDCsvField(logline->publisher()); + *report+=RDCsvField(logline->userDefined()); + *report+=RDCsvField(logline->songId()); + *report+=RDCsvField(RDCart::usageText(logline->usageCode())); + *report+=RDCsvField(RDLogLine::sourceText(logline->source())); + *report+=RDCsvField(logline->extData()); + *report+=RDCsvField(logline->extEventId()); + *report+=RDCsvField(logline->extAnncType()); + *report+=RDCsvField(logline->id()); + *report+=RDCsvField(i,true); + } +} + + void ListReports::GenerateExceptionReport(QString *report,const QDate &date) { int errs=list_model->validate(report,date); diff --git a/rdlogedit/list_reports.h b/rdlogedit/list_reports.h index 69a2ef53..ef9703e2 100644 --- a/rdlogedit/list_reports.h +++ b/rdlogedit/list_reports.h @@ -2,7 +2,7 @@ // // List and Generate Log Reports // -// (C) Copyright 2002-2021 Fred Gleason +// (C) Copyright 2002-2022 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 @@ -47,6 +47,7 @@ class ListReports : public RDDialog private: void GenerateLogReport(QString *report); + void GenerateLogCsvReport(QString *report); void GenerateExceptionReport(QString *report,const QDate &date); QComboBox *list_reports_box; QString list_log_name;