2018-08-01 Fred Gleason <fredg@paravelsystems.com>

* Modified as-played reports to work correctly with UTF-8 strings.
This commit is contained in:
Fred Gleason 2018-08-01 14:28:32 -04:00
parent 949b3f903c
commit 4e125e2de7
15 changed files with 436 additions and 440 deletions

View File

@ -17291,3 +17291,5 @@
* Refactored 'RDMacro' to handle UTF-8 strings correctly. * Refactored 'RDMacro' to handle UTF-8 strings correctly.
2018-07-31 Fred Gleason <fredg@paravelsystems.com> 2018-07-31 Fred Gleason <fredg@paravelsystems.com>
* Modified logging in caed(8) to use 'RDConfig::log()' method. * Modified logging in caed(8) to use 'RDConfig::log()' method.
2018-08-01 Fred Gleason <fredg@paravelsystems.com>
* Modified as-played reports to work correctly with UTF-8 strings.

View File

@ -20,6 +20,9 @@
#include <stdio.h> #include <stdio.h>
#include <qfile.h>
#include <qtextstream.h>
#include <rdcart.h> #include <rdcart.h>
#include <rddb.h> #include <rddb.h>
#include <rddatedecode.h> #include <rddatedecode.h>
@ -31,7 +34,6 @@ bool RDReport::ExportBmiEmr(const QString &filename,const QDate &startdate,
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
int records=0; int records=0;
QDateTime current_datetime= QDateTime current_datetime=
QDateTime(QDate::currentDate(),QTime::currentTime()); QDateTime(QDate::currentDate(),QTime::currentTime());
@ -39,6 +41,15 @@ bool RDReport::ExportBmiEmr(const QString &filename,const QDate &startdate,
QString usage_code; QString usage_code;
QString station_format=stationFormat(); QString station_format=stationFormat();
QFile *file=new QFile(filename);
if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen;
delete file;
return false;
}
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
// //
// Station Type // Station Type
// //
@ -56,10 +67,6 @@ bool RDReport::ExportBmiEmr(const QString &filename,const QDate &startdate,
break; break;
} }
if((f=fopen((const char *)filename,"wb"))==NULL) {
report_error_code=RDReport::ErrorCantOpen;
return false;
}
sql=QString("select ")+ sql=QString("select ")+
"EVENT_DATETIME,"+ // 00 "EVENT_DATETIME,"+ // 00
"TITLE,"+ // 01 "TITLE,"+ // 01
@ -76,9 +83,9 @@ bool RDReport::ExportBmiEmr(const QString &filename,const QDate &startdate,
// //
// Write HEDR Record // Write HEDR Record
// //
fprintf(f,"HEDRSTA%-25s%22sFMDT \x0d\x0a", *strm << QString("HEDRSTA")+LeftJustify(stationId(),25)+
(const char *)stationId().utf8(), LeftJustify(current_datetime.toString("yyyyMMddhhmmssyyyyMMdd"),22)+
(const char *)current_datetime.toString("yyyyMMddhhmmssyyyyMMdd")); "FMDT \x0d\x0a";
records++; records++;
// //
@ -86,48 +93,47 @@ bool RDReport::ExportBmiEmr(const QString &filename,const QDate &startdate,
// //
while(q->next()) { while(q->next()) {
switch((RDCart::UsageCode)q->value(6).toInt()) { switch((RDCart::UsageCode)q->value(6).toInt()) {
case RDCart::UsageFeature: case RDCart::UsageFeature:
usage_code="F1"; usage_code="F1";
break; break;
case RDCart::UsageOpen: case RDCart::UsageOpen:
usage_code="TO"; usage_code="TO";
break; break;
case RDCart::UsageClose: case RDCart::UsageClose:
usage_code="TC"; usage_code="TC";
break; break;
case RDCart::UsageTheme: case RDCart::UsageTheme:
usage_code="TT"; usage_code="TT";
break; break;
case RDCart::UsageBackground: case RDCart::UsageBackground:
usage_code="B "; usage_code="B ";
break; break;
case RDCart::UsagePromo: case RDCart::UsagePromo:
usage_code="JP"; usage_code="JP";
break; break;
default: default:
usage_code="F1"; usage_code="F1";
break; break;
} }
fprintf(f,"FMDT%-40s%2s%-25s%6s01%14s000000001%-40s%-40s%-40s%8s %12s%2s \x0d\x0a", *strm << QString("FMDT")+
(const char *)stationId().utf8(), LeftJustify(stationId(),40)+
(const char *)type_code.utf8(), type_code+
(const char *)station_format.utf8(), LeftJustify(station_format,25)+
(const char *)startdate.toString("yyyyMM"), startdate.toString("yyyyMM")+"01"+
(const char *)q->value(0).toDateTime(). LeftJustify(q->value(0).toDateTime().toString("yyyyMMddhh:mm:ss"),16)+
toString("yyyyMMddhh:mm:ss"), "000000001"+
(const char *)q->value(1).toString().utf8(), LeftJustify(q->value(1).toString(),40)+
(const char *)q->value(2).toString().utf8(), LeftJustify(q->value(2).toString(),40)+
(const char *)q->value(3).toString().utf8(), LeftJustify(q->value(3).toString(),40)+
(const char *)QTime().addMSecs(q->value(4).toInt()). QTime().addMSecs(q->value(4).toInt()).toString("hh:mm:ss")+" "+
toString("hh:mm:ss"), RightJustify(q->value(5).toString(),12)+
(const char *)q->value(5).toString().utf8(), usage_code+" \x0d\x0a";
(const char *)usage_code.utf8());
records++; records++;
} }
delete q; delete q;
@ -135,9 +141,11 @@ bool RDReport::ExportBmiEmr(const QString &filename,const QDate &startdate,
// //
// Write TRLR Record // Write TRLR Record
// //
fprintf(f,"TRLR%012d \x0d\x0a",++records); *strm << QString("TRLR")+
QString().sprintf("%012d \x0d\x0a",++records);
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -2,7 +2,7 @@
// //
// Export a Rivendell Cut Report. // Export a Rivendell Cut Report.
// //
// (C) Copyright 2002-2017 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2002-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -36,17 +36,19 @@ bool RDReport::ExportCutLog(const QString &filename,const QDate &startdate,
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
QString cut; QString cut;
QString str; QString str;
QString cart_fmt; QString cart_fmt;
QString cart_num; QString cart_num;
QFile file(filename); QFile *file=new QFile(filename);
if((f=fopen((const char *)filename,"w"))==NULL) { if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
if(useLeadingZeros()) { if(useLeadingZeros()) {
cart_fmt=QString().sprintf("%%0%uu",cartDigits()); cart_fmt=QString().sprintf("%%0%uu",cartDigits());
} }
@ -78,21 +80,16 @@ bool RDReport::ExportCutLog(const QString &filename,const QDate &startdate,
// Write File Header // Write File Header
// //
if(startdate==enddate) { if(startdate==enddate) {
fprintf(f," Rivendell RDAirPlay Cut Report for %s\n", *strm << Center(QString("Rivendell RDAirPlay Cut Report for ")+
(const char *)startdate.toString("MM/dd/yyyy")); startdate.toString("MM/dd/yyyy"),75);
} }
else { else {
fprintf(f," Rivendell RDAirPlay Cut Report for %s - %s\n", *strm << Center(QString("Rivendell RDAirPlay Cut Report for ")+
(const char *)startdate.toString("MM/dd/yyyy"), startdate.toString("MM/dd/yyyy")+" - "+
(const char *)enddate.toString("MM/dd/yyyy")); enddate.toString("MM/dd/yyyy"),75)+"\n";
} }
str=QString().sprintf("%s -- %s\n",(const char *)name(), *strm << Center(name()+" -- "+description(),75)+"\n";
(const char *)description()); *strm << "--Time-- -Cart- --Title---------------- Cut --Description------- -Len-\n";
for(unsigned i=0;i<(80-str.length())/2;i++) {
fprintf(f," ");
}
fprintf(f,"%s\n",(const char *)str);
fprintf(f,"--Time-- -Cart- --Title---------------- Cut --Description------- -Len-\n");
// //
// Write Data Rows // Write Data Rows
@ -115,18 +112,17 @@ bool RDReport::ExportCutLog(const QString &filename,const QDate &startdate,
if(desc.isEmpty()) { if(desc.isEmpty()) {
desc=" "; desc=" ";
} }
fprintf(f,"%8s %6s %-23s %3s %-20s %5s", *strm << q->value(2).toTime().toString("hh:mm:ss")+" ";
(const char *)q->value(2).toTime().toString("hh:mm:ss"), *strm << cart_num+" ";
(const char *)cart_num, *strm << LeftJustify(q->value(8).toString(),23)+" ";
(const char *)q->value(8).toString().left(23), *strm << cut+" ";
(const char *)cut, *strm << LeftJustify(desc,20)+" ";
(const char *)desc.left(20), *strm << RDGetTimeLength(q->value(9).toInt(),true,false).right(5);
(const char *)RDGetTimeLength(q->value(9).toInt(),true,false). *strm << "\n";
right(5));
fprintf(f,"\n");
} }
delete q; delete q;
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -25,30 +25,30 @@
#define CBSI_STATION_ID 1 #define CBSI_STATION_ID 1
#define CBSI_SCHED_FLAG "C" #define CBSI_SCHED_FLAG "C"
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rddb.h> #include "rddb.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdreport.h> #include "rdreport.h"
bool RDReport::ExportDeltaflex(const QString &filename,const QDate &startdate, bool RDReport::ExportDeltaflex(const QString &filename,const QDate &startdate,
const QDate &enddate,const QString &mixtable) const QDate &enddate,const QString &mixtable)
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
QString air_fmt; QString air_fmt;
QFile file(filename); QFile *file=new QFile(filename);
if((f=fopen((const char *)filename,"wb"))==NULL) { if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
if(useLeadingZeros()) { if(useLeadingZeros()) {
air_fmt=QString().sprintf("%%0%uu",cartDigits()); air_fmt=QString().sprintf("%%0%uu",cartDigits());
} }
@ -80,12 +80,12 @@ bool RDReport::ExportDeltaflex(const QString &filename,const QDate &startdate,
if(station_id>99) { if(station_id>99) {
station_id=0; station_id=0;
} }
fprintf(f,"Air Log for CBSI %03d|%s|%02u|%05d|%s|\x0d\x0a", *strm << QString("Air Log for CBSI ");
CBSI_DELTAFLEX_VERSION, *strm << QString().sprintf("%03d|",CBSI_DELTAFLEX_VERSION);
(const char *)startdate.toString("yy/MM/dd"), *strm << startdate.toString("yy/MM/dd");
station_id, *strm << QString().sprintf("|%02u|",station_id);
q->size(), *strm << QString().sprintf("%05d|",q->size());
CBSI_SCHED_FLAG); *strm << QString(CBSI_SCHED_FLAG)+"|\x0d\x0a";
// //
// Write Data Rows // Write Data Rows
@ -151,21 +151,21 @@ bool RDReport::ExportDeltaflex(const QString &filename,const QDate &startdate,
air_cartnum=QString().sprintf(air_fmt,q->value(1).toUInt()); air_cartnum=QString().sprintf(air_fmt,q->value(1).toUInt());
tfc_cartnum=q->value(10).toString(); tfc_cartnum=q->value(10).toString();
fprintf(f,"%s|%4s|%-29s|%-12s|%-12s|%s|%s|%8s|%-3s| | |%4s|\x0d\x0a", *strm << q->value(2).toDateTime().toString("hhmm")+"|";
(const char *)q->value(2).toDateTime().toString("hhmm"), *strm << LeftJustify(tfc_time,4)+"|";
(const char *)tfc_time, *strm << LeftJustify(cart_title,29)+"|";
(const char *)cart_title, *strm << LeftJustify(air_cartnum,12)+"|";
(const char *)air_cartnum, *strm << LeftJustify(tfc_cartnum,12)+"|";
(const char *)tfc_cartnum, *strm << play_length+"|";
(const char *)play_length, *strm << tfc_length+"|";
(const char *)tfc_length, *strm << LeftJustify(ext_data,8)+"|";
(const char *)ext_data, *strm << LeftJustify(q->value(8).toString(),3)+"| | |";
(const char *)q->value(8).toString(), *strm << LeftJustify(q->value(7).toString(),4)+"|\x0d\x0a";
(const char *)q->value(7).toString());
} }
delete q; delete q;
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -2,7 +2,7 @@
// //
// Export a Rivendell Classical Music Playout report // Export a Rivendell Classical Music Playout report
// //
// (C) Copyright 2014,2016-2017 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2014,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -18,18 +18,17 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rdairplay_conf.h> #include "rdairplay_conf.h"
#include <rdconf.h> #include "rdconf.h"
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rddb.h> #include "rddb.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdlog_line.h> #include "rdlog_line.h"
#include <rdreport.h> #include "rdreport.h"
bool RDReport::ExportMusicClassical(const QString &filename, bool RDReport::ExportMusicClassical(const QString &filename,
const QDate &startdate,const QDate &enddate, const QDate &startdate,const QDate &enddate,
@ -37,17 +36,19 @@ bool RDReport::ExportMusicClassical(const QString &filename,
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f; // FILE *f;
QString cut; QString cut;
QString str; QString str;
QString cart_fmt; QString cart_fmt;
QString cart_num; QString cart_num;
QFile *file=new QFile(filename);
QFile file(filename); if(!file->open(IO_WriteOnly|IO_Truncate)) {
if((f=fopen((const char *)filename,"w"))==NULL) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
if(useLeadingZeros()) { if(useLeadingZeros()) {
cart_fmt=QString().sprintf("%%0%uu",cartDigits()); cart_fmt=QString().sprintf("%%0%uu",cartDigits());
} }
@ -72,21 +73,16 @@ bool RDReport::ExportMusicClassical(const QString &filename,
// Write File Header // Write File Header
// //
if(startdate==enddate) { if(startdate==enddate) {
fprintf(f," Rivendell RDAirPlay Classical Music Playout Report for %s\n", *strm << Center(QString("Rivendell RDAirPlay Classical Music Playout Report for ")+
(const char *)startdate.toString("MM/dd/yyyy")); startdate.toString("MM/dd/yyyy"),120)+"\n";
} }
else { else {
fprintf(f," Rivendell RDAirPlay Music Playout Report for %s - %s\n", *strm << Center(QString("Rivendell RDAirPlay Classical Music Playout Report for ")+
(const char *)startdate.toString("MM/dd/yyyy"), startdate.toString("MM/dd/yyyy")+" - "+
(const char *)enddate.toString("MM/dd/yyyy")); enddate.toString("MM/dd/yyyy"),120)+"\n";
} }
str=QString().sprintf("%s -- %s\n",(const char *)name(), *strm << Center(name()+" -- "+description(),120)+"\n";
(const char *)description()); *strm << "Time -Len- --Title----------------------- --Composer-------------------- --Label / Spine #-------- Lib # Cart #\n";
for(unsigned i=0;i<(120-str.length())/2;i++) {
fprintf(f," ");
}
fprintf(f,"%s\n",(const char *)str);
fprintf(f,"Time -Len- --Title----------------------- --Composer-------------------- --Label / Spine #-------- Lib # Cart #\n");
// //
// Write Data Rows // Write Data Rows
@ -105,18 +101,17 @@ bool RDReport::ExportMusicClassical(const QString &filename,
} }
} }
cart_num=QString().sprintf(cart_fmt,q->value(1).toUInt()); cart_num=QString().sprintf(cart_fmt,q->value(1).toUInt());
fprintf(f,"%4s %5s %-30s %-30s %-25s %-5s %06u\n", *strm << q->value(2).toDateTime().time().toString("hhmm")+" ";
(const char *)q->value(2).toDateTime().time().toString("hhmm"), *strm << RDGetTimeLength(q->value(0).toInt(),true,false).right(5)+" ";
(const char *)RDGetTimeLength(q->value(0).toInt(),true,false). *strm << LeftJustify(q->value(3).toString(),30)+" ";
right(5), *strm << LeftJustify(q->value(5).toString(),30)+" ";
(const char *)StringField(q->value(3).toString().left(30)), *strm << LeftJustify(q->value(4).toString(),25)+" ";
(const char *)StringField(q->value(5).toString().left(30)), *strm << LeftJustify(q->value(6).toString(),5)+" ";
(const char *)StringField(q->value(4).toString().left(25)), * strm << QString().sprintf("%06u",q->value(1).toUInt())+"\n";
(const char *)StringField(q->value(6).toString().left(5)),
q->value(1).toUInt());
} }
delete q; delete q;
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;

View File

@ -18,18 +18,17 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rdairplay_conf.h> #include "rdairplay_conf.h"
#include <rdconf.h> #include "rdconf.h"
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rddb.h> #include "rddb.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdlog_line.h> #include "rdlog_line.h"
#include <rdreport.h> #include "rdreport.h"
bool RDReport::ExportMusicPlayout(const QString &filename, bool RDReport::ExportMusicPlayout(const QString &filename,
const QDate &startdate,const QDate &enddate, const QDate &startdate,const QDate &enddate,
@ -37,17 +36,19 @@ bool RDReport::ExportMusicPlayout(const QString &filename,
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
QString cut; QString cut;
QString str; QString str;
QString cart_fmt; QString cart_fmt;
QString cart_num; QString cart_num;
QFile file(filename); QFile *file=new QFile(filename);
if((f=fopen((const char *)filename,"w"))==NULL) { if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
if(useLeadingZeros()) { if(useLeadingZeros()) {
cart_fmt=QString().sprintf("%%0%uu",cartDigits()); cart_fmt=QString().sprintf("%%0%uu",cartDigits());
} }
@ -74,21 +75,16 @@ bool RDReport::ExportMusicPlayout(const QString &filename,
// Write File Header // Write File Header
// //
if(startdate==enddate) { if(startdate==enddate) {
fprintf(f," Rivendell RDAirPlay Music Playout Report for %s\n", *strm << Center(QString("Rivendell RDAirPlay Music Playout Report for ")+
(const char *)startdate.toString("MM/dd/yyyy")); startdate.toString("MM/dd/yyyy"),144)+"\n";
} }
else { else {
fprintf(f," Rivendell RDAirPlay Music Playout Report for %s - %s\n", *strm << Center(QString("Rivendell RDAirPlay Music Playout Report for ")+
(const char *)startdate.toString("MM/dd/yyyy"), startdate.toString("MM/dd/yyyy")+" - "+
(const char *)enddate.toString("MM/dd/yyyy")); enddate.toString("MM/dd/yyyy"),144)+"\n";
} }
str=QString().sprintf("%s -- %s\n",(const char *)name(), *strm << Center(name()+" -- "+description(),144)+"\n";
(const char *)description()); *strm << "--Time-- -Cart- Cut A-Len --Title----------------------- --Artist---------------------- --Album------------------ --Label-------------\n";
for(unsigned i=0;i<(180-str.length())/2;i++) {
fprintf(f," ");
}
fprintf(f,"%s\n",(const char *)str);
fprintf(f,"--Time-- -Cart- Cut A-Len --Title----------------------- --Artist---------------------- --Album------------------ --Label-------------\n");
// //
// Write Data Rows // Write Data Rows
@ -107,19 +103,18 @@ bool RDReport::ExportMusicPlayout(const QString &filename,
} }
} }
cart_num=QString().sprintf(cart_fmt,q->value(1).toUInt()); cart_num=QString().sprintf(cart_fmt,q->value(1).toUInt());
fprintf(f,"%8s %6s %3s %5s %-30s %-30s %-25s %-20s\n", *strm << q->value(2).toDateTime().time().toString("hh:mm:ss")+" ";
(const char *)q->value(2).toDateTime().time().toString("hh:mm:ss"), *strm << cart_num+" ";
(const char *)cart_num, *strm << cut+" ";
(const char *)cut, *strm << RDGetTimeLength(q->value(0).toInt(),true,false).right(5)+" ";
(const char *)RDGetTimeLength(q->value(0).toInt(),true,false). *strm << LeftJustify(q->value(4).toString(),30)+" ";
right(5), *strm << LeftJustify(q->value(6).toString(),30)+" ";
(const char *)StringField(q->value(4).toString().left(30)), *strm << LeftJustify(q->value(7).toString(),25)+" ";
(const char *)StringField(q->value(6).toString().left(30)), *strm << LeftJustify(q->value(8).toString(),20)+"\n";
(const char *)StringField(q->value(7).toString().left(25)),
(const char *)StringField(q->value(8).toString().left(20)));
} }
delete q; delete q;
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;

View File

@ -18,19 +18,17 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rdairplay_conf.h> #include "rdairplay_conf.h"
#include <rdconf.h> #include "rdconf.h"
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rddb.h> #include "rddb.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdlog_line.h> #include "rdlog_line.h"
#include <rdreport.h> #include "rdreport.h"
bool RDReport::ExportMusicSummary(const QString &filename, bool RDReport::ExportMusicSummary(const QString &filename,
const QDate &startdate,const QDate &enddate, const QDate &startdate,const QDate &enddate,
@ -38,15 +36,17 @@ bool RDReport::ExportMusicSummary(const QString &filename,
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
QString cut; QString cut;
QString str; QString str;
QFile file(filename); QFile *file=new QFile(filename);
if((f=fopen((const char *)filename,"w"))==NULL) { if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
sql=QString("select ")+ sql=QString("select ")+
"ELR_LINES.ARTIST,"+ // 00 "ELR_LINES.ARTIST,"+ // 00
"ELR_LINES.TITLE,"+ // 01 "ELR_LINES.TITLE,"+ // 01
@ -61,36 +61,32 @@ bool RDReport::ExportMusicSummary(const QString &filename,
// Write File Header // Write File Header
// //
if(startdate==enddate) { if(startdate==enddate) {
fprintf(f," Rivendell RDAirPlay Music Summary Report for %s\n", *strm << Center(QString("Rivendell RDAirPlay Music Summary Report for ")+
(const char *)startdate.toString("MM/dd/yyyy")); startdate.toString("MM/dd/yyyy"),75)+"\n";
} }
else { else {
fprintf(f," Rivendell RDAirPlay Music Summary Report for %s - %s\n", *strm << Center(QString("Rivendell RDAirPlay Music Summary Report for ")+
(const char *)startdate.toString("MM/dd/yyyy"), startdate.toString("MM/dd/yyyy")+" - "+
(const char *)enddate.toString("MM/dd/yyyy")); enddate.toString("MM/dd/yyyy"),75)+"\n";
} }
str=QString().sprintf("%s -- %s\n",(const char *)name(), *strm << Center(name()+" -- "+description(),75)+"\n";
(const char *)description());
for(unsigned i=0;i<(80-str.length())/2;i++) {
fprintf(f," ");
}
fprintf(f,"%s\n",(const char *)str);
// //
// Write Data Rows // Write Data Rows
// //
while(q->next()) { while(q->next()) {
if(!q->value(0).toString().isEmpty()) { if(!q->value(0).toString().isEmpty()) {
fprintf(f,"%s - ",(const char *)q->value(0).toString()); *strm << q->value(0).toString()+" - ";
} }
fprintf(f,"%s",(const char *)q->value(1).toString()); *strm << q->value(1).toString();
if(!q->value(2).toString().isEmpty()) { if(!q->value(2).toString().isEmpty()) {
fprintf(f," [%s]",(const char *)q->value(2).toString()); *strm << QString("[")+q->value(2).toString()+"]";
} }
fprintf(f,"\n"); *strm << "\n";
} }
delete q; delete q;
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -18,18 +18,17 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rdairplay_conf.h> #include "rdairplay_conf.h"
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rddb.h> #include "rddb.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdget_ath.h> #include "rdget_ath.h"
#include <rdlog_line.h> #include "rdlog_line.h"
#include <rdreport.h> #include "rdreport.h"
// //
// This implements a National Public Radio (NPR) standard. // This implements a National Public Radio (NPR) standard.
@ -42,7 +41,6 @@ bool RDReport::ExportNprSoundEx(const QString &filename,const QDate &startdate,
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f=NULL;
QString artist; QString artist;
QString title; QString title;
QString album; QString album;
@ -51,15 +49,19 @@ bool RDReport::ExportNprSoundEx(const QString &filename,const QDate &startdate,
QString trans_category=stationFormat(); QString trans_category=stationFormat();
QString channel_name=stationId(); QString channel_name=stationId();
if((f=fopen(filename,"wb"))==NULL) { QFile *file=new QFile(filename);
if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
// //
// Generate Header // Generate Header
// //
fprintf(f,"Start Time\tEnd Time\tTitle\tArtist\tAlbum\tLabel\x0d\x0a"); *strm << QString("Start Time\tEnd Time\tTitle\tArtist\tAlbum\tLabel\x0d\x0a");
// //
// Roll Up Records // Roll Up Records
@ -76,17 +78,17 @@ bool RDReport::ExportNprSoundEx(const QString &filename,const QDate &startdate,
"order by EVENT_DATETIME"; "order by EVENT_DATETIME";
q=new RDSqlQuery(sql); q=new RDSqlQuery(sql);
while(q->next()) { while(q->next()) {
fprintf(f,"%s\t",(const char *)q->value(0).toDateTime(). *strm << q->value(0).toDateTime().toString("MM/dd/yyyy hh:mm:ss")+"\t";
toString("MM/dd/yyyy hh:mm:ss")); *strm << q->value(0).toDateTime().addSecs(q->value(1).toInt()/1000).
fprintf(f,"%s\t",(const char *)q->value(0).toDateTime(). toString("MM/dd/yyyy hh:mm:ss")+"\t";
addSecs(q->value(1).toInt()/1000). *strm << q->value(2).toString()+"\t";
toString("MM/dd/yyyy hh:mm:ss")); *strm << q->value(3).toString()+"\t";
fprintf(f,"%s\t",(const char *)StringField(q->value(2).toString())); *strm << q->value(4).toString()+"\t";
fprintf(f,"%s\t",(const char *)StringField(q->value(3).toString())); *strm << q->value(5).toString()+"\x0d\x0a";
fprintf(f,"%s\t",(const char *)StringField(q->value(4).toString()));
fprintf(f,"%s\x0d\x0a",(const char *)StringField(q->value(5).toString()));
} }
fclose(f); delete q;
delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -18,16 +18,15 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rddb.h> #include "rddb.h"
#include <rdconf.h> #include "rdconf.h"
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdreport.h> #include "rdreport.h"
bool RDReport::ExportRadioTraffic(const QString &filename, bool RDReport::ExportRadioTraffic(const QString &filename,
const QDate &startdate,const QDate &enddate, const QDate &startdate,const QDate &enddate,
@ -35,15 +34,16 @@ bool RDReport::ExportRadioTraffic(const QString &filename,
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
QString air_fmt; QString air_fmt;
QFile file(filename); QFile *file=new QFile(filename);
if((f=fopen((const char *)filename,"wb"))==NULL) { if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
if(useLeadingZeros()) { if(useLeadingZeros()) {
air_fmt=QString().sprintf("%%0%uu ",cartDigits()); air_fmt=QString().sprintf("%%0%uu ",cartDigits());
} }
@ -72,37 +72,29 @@ bool RDReport::ExportRadioTraffic(const QString &filename,
// Write Data Rows // Write Data Rows
// //
while(q->next()) { while(q->next()) {
fprintf(f,"%s ",(const char *)q->value(4).toTime().toString("hh:mm:ss")); *strm << q->value(4).toTime().toString("hh:mm:ss")+" ";
fprintf(f,"%s ",(const char *)q->value(2).toDateTime(). *strm << q->value(2).toDateTime().toString("hh:mm:ss")+" ";
toString("hh:mm:ss"));
if(q->value(5).toInt()>0) { if(q->value(5).toInt()>0) {
fprintf(f,"0%s ",(const char *)RDGetTimeLength(q->value(5).toInt(), *strm << RDGetTimeLength(q->value(5).toInt(),true,false)+" ";
true,false));
} }
else { else {
fprintf(f,"00:00:00 "); *strm << "00:00:00 ";
} }
if(q->value(0).toInt()>0) { if(q->value(0).toInt()>0) {
fprintf(f,"0%s ",(const char *)RDGetTimeLength(q->value(0).toInt(), *strm << QString("0")+RDGetTimeLength(q->value(0).toInt(),true,false)+" ";
true,false));
} }
else { else {
fprintf(f,"00:00:00 "); *strm << "00:00:00 ";
} }
fprintf(f,air_fmt,q->value(1).toUInt()); *strm << QString().sprintf(air_fmt,q->value(1).toUInt());
fprintf(f,"%-34s ",(const char *)q->value(9).toString().left(34)); *strm << LeftJustify(q->value(9).toString(),34)+" ";
if(q->value(6).toString().isEmpty()) { *strm << LeftJustify(q->value(6).toString(),32);
fprintf(f," "); *strm << "\x0d\x0a";
}
else {
fprintf(f,"%-32s",(const char *)q->value(6).toString().left(32).
stripWhiteSpace());
}
fprintf(f,"\x0d\x0a");
} }
delete q; delete q;
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;

View File

@ -18,25 +18,23 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rdairplay_conf.h> #include "rdairplay_conf.h"
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rddb.h> #include "rddb.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdget_ath.h> #include "rdget_ath.h"
#include <rdlog_line.h> #include "rdlog_line.h"
#include <rdreport.h> #include "rdreport.h"
bool RDReport::ExportSoundEx(const QString &filename,const QDate &startdate, bool RDReport::ExportSoundEx(const QString &filename,const QDate &startdate,
const QDate &enddate,const QString &mixtable) const QDate &enddate,const QString &mixtable)
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
unsigned cartnum=0; unsigned cartnum=0;
QString artist; QString artist;
QString title; QString title;
@ -58,15 +56,19 @@ bool RDReport::ExportSoundEx(const QString &filename,const QDate &startdate,
return false; return false;
} }
if((f=fopen((const char *)filename,"w"))==NULL) { QFile *file=new QFile(filename);
if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
// //
// Generate Header // Generate Header
// //
fprintf(f,"\"NAME_OF_SERVICE\",\"TRANSMISSION_CATEGORY\",\"FEATURED_ARTIST\",\"SOUND_RECORDING_TITLE\",\"ISRC\",\"ALBUM_TITLE\",\"MARKETING_LABEL\",\"ACTUAL_TOTAL_PERFORMANCES\",\"AGGREGATE_TUNING_HOURS\",\"CHANNEL_OR_PROGRAM_NAME\",\"PLAY_FREQUENCY\"\r\n"); *strm << "\"NAME_OF_SERVICE\",\"TRANSMISSION_CATEGORY\",\"FEATURED_ARTIST\",\"SOUND_RECORDING_TITLE\",\"ISRC\",\"ALBUM_TITLE\",\"MARKETING_LABEL\",\"ACTUAL_TOTAL_PERFORMANCES\",\"AGGREGATE_TUNING_HOURS\",\"CHANNEL_OR_PROGRAM_NAME\",\"PLAY_FREQUENCY\"\r\n";
// //
// Roll Up Records // Roll Up Records
@ -88,18 +90,17 @@ bool RDReport::ExportSoundEx(const QString &filename,const QDate &startdate,
} }
else { else {
if(cartnum!=0) { if(cartnum!=0) {
fprintf(f, *strm << QString("\"")+service_name+"\",";
"\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",,%9.2lf,\"%s\",%d\n", *strm << QString("\"")+trans_category+"\",";
(const char *)service_name, *strm << QString("\"")+artist+"\",";
(const char *)trans_category, *strm << QString("\"")+title+"\",";
(const char *)artist, *strm << QString("\"")+isrc+"\",";
(const char *)title, *strm << QString("\"")+album+"\",";
(const char *)isrc, *strm << QString("\"")+label+"\",,";
(const char *)album, *strm << QString().sprintf("%9.2f,",ath);
(const char *)label, *strm << QString("\"")+channel_name+"\",";
ath, *strm << QString().sprintf("%d",plays);
(const char *)channel_name, *strm << "\n";
plays);
} }
plays=1; plays=1;
if(q->value(1).isNull()) { if(q->value(1).isNull()) {
@ -132,20 +133,20 @@ bool RDReport::ExportSoundEx(const QString &filename,const QDate &startdate,
} }
delete q; delete q;
if(cartnum!=0) { if(cartnum!=0) {
fprintf(f, *strm << QString("\"")+service_name+"\",";
"\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",,%9.2lf,\"%s\",%d\n", *strm << QString("\"")+trans_category+"\",";
(const char *)service_name, *strm << QString("\"")+artist+"\",";
(const char *)trans_category, *strm << QString("\"")+title+"\",";
(const char *)artist, *strm << QString("\"")+isrc+"\",";
(const char *)title, *strm << QString("\"")+album+"\",";
(const char *)isrc, *strm << QString("\"")+label+"\",,";
(const char *)album, *strm << QString().sprintf("%9.2f,",ath);
(const char *)label, *strm << QString("\"")+channel_name+"\",";
ath, *strm << QString().sprintf("%d",plays);
(const char *)channel_name, *strm << "\n";
plays);
} }
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -18,27 +18,25 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <map> #include <map>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rdairplay_conf.h> #include "rdairplay_conf.h"
#include <rdconf.h> #include "rdconf.h"
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rddb.h> #include "rddb.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdlog_line.h> #include "rdlog_line.h"
#include <rdreport.h> #include "rdreport.h"
bool RDReport::ExportSpinCount(const QString &filename,const QDate &startdate, bool RDReport::ExportSpinCount(const QString &filename,const QDate &startdate,
const QDate &enddate,const QString &mixtable) const QDate &enddate,const QString &mixtable)
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
QString cut; QString cut;
QString str; QString str;
QString cart_fmt; QString cart_fmt;
@ -49,11 +47,14 @@ bool RDReport::ExportSpinCount(const QString &filename,const QDate &startdate,
std::map<unsigned,QString> labels; std::map<unsigned,QString> labels;
std::map<unsigned,QString> albums; std::map<unsigned,QString> albums;
QFile file(filename); QFile *file=new QFile(filename);
if((f=fopen((const char *)filename,"w"))==NULL) { if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
if(useLeadingZeros()) { if(useLeadingZeros()) {
cart_fmt=QString().sprintf("%%0%uu",cartDigits()); cart_fmt=QString().sprintf("%%0%uu",cartDigits());
} }
@ -86,36 +87,31 @@ bool RDReport::ExportSpinCount(const QString &filename,const QDate &startdate,
// Write File Header // Write File Header
// //
if(startdate==enddate) { if(startdate==enddate) {
fprintf(f," Rivendell Spin Count Report for %s\n", *strm << Center(QString("Rivendell Spin Count Report for ")+
(const char *)startdate.toString("MM/dd/yyyy")); startdate.toString("MM/dd/yyyy"),132)+"\n";
} }
else { else {
fprintf(f," Rivendell Spin Count Report for %s - %s\n", *strm << Center(QString("Rivendell Spin Count Report for ")+
(const char *)startdate.toString("MM/dd/yyyy"), startdate.toString("MM/dd/yyyy")+" - "+
(const char *)enddate.toString("MM/dd/yyyy")); enddate.toString("MM/dd/yyyy"),132)+"\n";
} }
str=QString().sprintf("%s -- %s\n",(const char *)name(), *strm << Center(name()+" -- "+description(),132)+"\n";
(const char *)description()); *strm << "--Title------------------------ --Artist----------------------- --Album------------------------ --Label----------------------- Spins\n";
for(unsigned i=0;i<(132-str.length())/2;i++) {
fprintf(f," ");
}
fprintf(f,"%s\n",(const char *)str);
// fprintf(f,"------------------------------------------------------------------------------------------------------------------------------------\n");
fprintf(f,"--Title------------------------ --Artist----------------------- --Album------------------------ --Label----------------------- Spins\n");
// //
// Write Data Rows // Write Data Rows
// //
for(std::map<unsigned,unsigned>::const_iterator it=carts.begin(); for(std::map<unsigned,unsigned>::const_iterator it=carts.begin();
it!=carts.end();it++) { it!=carts.end();it++) {
fprintf(f,"%-30s %-30s %-30s %-29s %5u\n", *strm << LeftJustify(titles[it->first],30)+" ";
(const char *)titles[it->first], *strm << LeftJustify(artists[it->first],30)+" ";
(const char *)artists[it->first], *strm << LeftJustify(albums[it->first],30)+" ";
(const char *)albums[it->first], *strm << LeftJustify(labels[it->first],29)+" ";
(const char *)labels[it->first], *strm << QString().sprintf("%5u",it->second);
it->second); *strm << "\n";
} }
fclose(f); delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -18,18 +18,15 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qtextstream.h>
#include <rdairplay_conf.h> #include "rdairplay_conf.h"
#include <rdconf.h> #include "rdconf.h"
#include <rddatedecode.h> #include "rddb.h"
#include <rddb.h> #include "rdescape_string.h"
#include <rdescape_string.h> #include "rdlog_line.h"
#include <rdlog_line.h> #include "rdreport.h"
#include <rdreport.h>
bool RDReport::ExportTechnical(const QString &filename,const QDate &startdate, bool RDReport::ExportTechnical(const QString &filename,const QDate &startdate,
const QDate &enddate,bool incl_hdr,bool incl_crs, const QDate &enddate,bool incl_hdr,bool incl_crs,
@ -37,7 +34,6 @@ bool RDReport::ExportTechnical(const QString &filename,const QDate &startdate,
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
QString cut; QString cut;
QString str; QString str;
QString cart_fmt; QString cart_fmt;
@ -48,11 +44,14 @@ bool RDReport::ExportTechnical(const QString &filename,const QDate &startdate,
strcpy(eol,"\r\n"); strcpy(eol,"\r\n");
} }
QFile file(filename); QFile *file=new QFile(filename);
if((f=fopen((const char *)filename,"w"))==NULL) { if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
if(useLeadingZeros()) { if(useLeadingZeros()) {
cart_fmt=QString().sprintf("%%0%uu",cartDigits()); cart_fmt=QString().sprintf("%%0%uu",cartDigits());
} }
@ -86,21 +85,16 @@ bool RDReport::ExportTechnical(const QString &filename,const QDate &startdate,
// //
if(incl_hdr) { if(incl_hdr) {
if(startdate==enddate) { if(startdate==enddate) {
fprintf(f," Rivendell RDAirPlay Technical Playout Report for %s%s", *strm << Center("Rivendell RDAirPlay Technical Playout Report for "+
(const char *)startdate.toString("MM/dd/yyyy"),eol); startdate.toString("MM/dd/yyyy"),96)+eol;
} }
else { else {
fprintf(f," Rivendell RDAirPlay Technical Playout Report for %s - %s%s", *strm << Center("Rivendell RDAirPlay Technical Playout Report for "+
(const char *)startdate.toString("MM/dd/yyyy"), startdate.toString("MM/dd/yyyy")+" - "+
(const char *)enddate.toString("MM/dd/yyyy"),eol); enddate.toString("MM/dd/yyyy"),96)+eol;
} }
str=QString().sprintf("%s -- %s%s",(const char *)name(), *strm << Center(name()+" -- "+description(),96)+eol;
(const char *)description(),eol); *strm << QString("--Time-- -Cart- Cut --Title---------------- A-Len N-Len --Host---- Srce StartedBy OnAir")+eol;
for(unsigned i=0;i<(80-str.length())/2;i++) {
fprintf(f," ");
}
fprintf(f,"%s%s",(const char *)str,eol);
fprintf(f,"--Time-- -Cart- Cut --Title---------------- A-Len N-Len --Host---- Srce StartedBy OnAir%s",eol);
} }
// //
@ -120,53 +114,51 @@ bool RDReport::ExportTechnical(const QString &filename,const QDate &startdate,
} }
} }
cart_num=QString().sprintf(cart_fmt,q->value(1).toUInt()); cart_num=QString().sprintf(cart_fmt,q->value(1).toUInt());
fprintf(f,"%8s %6s %3s %-23s %5s %5s %-10s ", *strm << q->value(2).toTime().toString("hh:mm:ss")+" ";
(const char *)q->value(2).toTime().toString("hh:mm:ss"), *strm << cart_num+" ";
(const char *)cart_num, *strm << cut+" ";
(const char *)cut, *strm << LeftJustify(q->value(8).toString(),23)+" ";
(const char *)q->value(8).toString().left(23), *strm << RDGetTimeLength(q->value(0).toInt(),true,false).right(5)+" ";
(const char *)RDGetTimeLength(q->value(0).toInt(),true,false). *strm << RDGetTimeLength(q->value(9).toInt(),true,false).right(5)+" ";
right(5), *strm << LeftJustify(q->value(10).toString(),10)+" ";
(const char *)RDGetTimeLength(q->value(9).toInt(),true,false).
right(5),
(const char *)q->value(10).toString());
switch((RDLogLine::PlaySource)q->value(11).toInt()) { switch((RDLogLine::PlaySource)q->value(11).toInt()) {
case RDLogLine::MainLog: case RDLogLine::MainLog:
fprintf(f,"Main "); *strm << "Main ";
break; break;
case RDLogLine::AuxLog1: case RDLogLine::AuxLog1:
fprintf(f,"Aux1 "); *strm << "Aux1 ";
break; break;
case RDLogLine::AuxLog2: case RDLogLine::AuxLog2:
fprintf(f,"Aux2 "); *strm << "Aux2 ";
break; break;
case RDLogLine::SoundPanel: case RDLogLine::SoundPanel:
fprintf(f,"SPnl "); *strm << "SPnl ";
break; break;
case RDLogLine::CartSlot: case RDLogLine::CartSlot:
fprintf(f,"Slot "); *strm << "Slot ";
break; break;
default: default:
fprintf(f," "); *strm << " ";
break; break;
} }
fprintf(f,"%-7s ",(const char *)RDLogLine:: *strm << LeftJustify(RDLogLine::startSourceText((RDLogLine::StartSource)q->value(13).toInt()),7)+" ";
startSourceText((RDLogLine::StartSource)q->value(13).toInt()));
if(q->value(14).toString()=="Y") { if(q->value(14).toString()=="Y") {
fprintf(f," Yes "); *strm << " Yes ";
} }
else { else {
fprintf(f," No "); *strm << " No ";
} }
fprintf(f,"%s",eol); *strm << eol;
} }
delete q; delete q;
fclose(f);
delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -1,6 +1,6 @@
// export_textlog.cpp // export_textlog.cpp
// //
// Export a Rivendell Report to an ASCII Text File. // Export a Rivendell Report to an Text File.
// //
// (C) Copyright 2002-2005,2016-2018 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2002-2005,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
@ -18,35 +18,36 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// //
#include <stdio.h>
#include <qfile.h> #include <qfile.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qtextstream.h>
#include <rdairplay_conf.h> #include "rdairplay_conf.h"
#include <rdconf.h> #include "rdconf.h"
#include <rddatedecode.h> #include "rddatedecode.h"
#include <rddb.h> #include "rddb.h"
#include <rdescape_string.h> #include "rdescape_string.h"
#include <rdlog_line.h> #include "rdlog_line.h"
#include <rdreport.h> #include "rdreport.h"
bool RDReport::ExportTextLog(const QString &filename,const QDate &startdate, bool RDReport::ExportTextLog(const QString &filename,const QDate &startdate,
const QDate &enddate,const QString &mixtable) const QDate &enddate,const QString &mixtable)
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
FILE *f;
QString cut; QString cut;
QString str; QString str;
QString cart_fmt; QString cart_fmt;
QString cart_num; QString cart_num;
QFile file(filename); QFile *file=new QFile(filename);
if((f=fopen((const char *)filename,"w"))==NULL) { if(!file->open(IO_WriteOnly|IO_Truncate)) {
report_error_code=RDReport::ErrorCantOpen; report_error_code=RDReport::ErrorCantOpen;
delete file;
return false; return false;
} }
QTextStream *strm=new QTextStream(file);
strm->setEncoding(QTextStream::UnicodeUTF8);
if(useLeadingZeros()) { if(useLeadingZeros()) {
cart_fmt=QString().sprintf("%%0%uu",cartDigits()); cart_fmt=QString().sprintf("%%0%uu",cartDigits());
} }
@ -77,21 +78,16 @@ bool RDReport::ExportTextLog(const QString &filename,const QDate &startdate,
// Write File Header // Write File Header
// //
if(startdate==enddate) { if(startdate==enddate) {
fprintf(f," Rivendell RDAirPlay Playout Report for %s\n", *strm << Center(QString("Rivendell RDAirPlay Playout Report for ")+
(const char *)startdate.toString("MM/dd/yyyy")); startdate.toString("MM/dd/yyyy"),78)+"\n";
} }
else { else {
fprintf(f," Rivendell RDAirPlay Playout Report for %s - %s\n", *strm << Center(QString("Rivendell RDAirPlay Playout Report for ")+
(const char *)startdate.toString("MM/dd/yyyy"), startdate.toString("MM/dd/yyyy")+" - "+
(const char *)enddate.toString("MM/dd/yyyy")); enddate.toString("MM/dd/yyyy"),78)+"\n";
} }
str=QString().sprintf("%s -- %s\n",(const char *)name(), *strm << Center(name()+" -- "+description(),78)+"\n";
(const char *)description()); *strm << "--Time-- -Cart- Cut --Title---------------- A-Len N-Len --Host---- Srce\n";
for(unsigned i=0;i<(80-str.length())/2;i++) {
fprintf(f," ");
}
fprintf(f,"%s\n",(const char *)str);
fprintf(f,"--Time-- -Cart- Cut --Title---------------- A-Len N-Len --Host---- Srce\n");
// //
// Write Data Rows // Write Data Rows
@ -110,45 +106,44 @@ bool RDReport::ExportTextLog(const QString &filename,const QDate &startdate,
} }
} }
cart_num=QString().sprintf(cart_fmt,q->value(1).toUInt()); cart_num=QString().sprintf(cart_fmt,q->value(1).toUInt());
fprintf(f,"%8s %6s %3s %-23s %5s %5s %-10s ", *strm << q->value(2).toTime().toString("hh:mm:ss")+" ";
(const char *)q->value(2).toTime().toString("hh:mm:ss"), *strm << RightJustify(cart_num,6)+" ";
(const char *)cart_num, *strm << cut+" ";
(const char *)cut, *strm << LeftJustify(q->value(8).toString(),23)+" ";
(const char *)q->value(8).toString().left(23), *strm << RDGetTimeLength(q->value(0).toInt(),true,false).right(5)+" ";
(const char *)RDGetTimeLength(q->value(0).toInt(),true,false). *strm << RDGetTimeLength(q->value(8).toInt(),true,false).right(5)+" ";
right(5), *strm << LeftJustify(q->value(10).toString(),10)+" ";
(const char *)RDGetTimeLength(q->value(9).toInt(),true,false).
right(5),
(const char *)q->value(10).toString());
switch((RDLogLine::PlaySource)q->value(11).toInt()) { switch((RDLogLine::PlaySource)q->value(11).toInt()) {
case RDLogLine::MainLog: case RDLogLine::MainLog:
fprintf(f,"Main"); *strm << "Main";
break; break;
case RDLogLine::AuxLog1: case RDLogLine::AuxLog1:
fprintf(f,"Aux1"); *strm << "Aux1";
break; break;
case RDLogLine::AuxLog2: case RDLogLine::AuxLog2:
fprintf(f,"Aux2"); *strm << "Aux2";
break; break;
case RDLogLine::SoundPanel: case RDLogLine::SoundPanel:
fprintf(f,"SPnl"); *strm << "SPnl";
break; break;
case RDLogLine::CartSlot: case RDLogLine::CartSlot:
fprintf(f,"Slot"); *strm << "Slot";
break; break;
default: default:
fprintf(f," "); *strm << " ";
break; break;
} }
fprintf(f,"\n"); *strm << "\n";
} }
delete q; delete q;
fclose(f);
delete strm;
delete file;
report_error_code=RDReport::ErrorOk; report_error_code=RDReport::ErrorOk;
return true; return true;
} }

View File

@ -848,18 +848,42 @@ QString RDReport::errorText(RDReport::ErrorCode code)
} }
QString RDReport::StringField(const QString &str,const QString &null_text) const QString RDReport::LeftJustify(const QString &str,int width) const
{ {
QString ret=null_text; QString ret=str.left(width);
if(!str.isEmpty()) { while(ret.length()<(unsigned)width) {
ret=str; ret+=" ";
} }
return ret; return ret;
} }
QString RDReport::RightJustify(const QString &str,int width) const
{
QString ret=str.left(width);
while(ret.length()<(unsigned)width) {
ret=" "+ret;
}
return ret;
}
QString RDReport::Center(const QString &str,int width) const
{
QString ret=str.left(width);
int margin=(width-ret.length())/2;
for(int i=0;i<margin;i++) {
ret=" "+ret;
}
return ret;
}
void RDReport::SetRow(const QString &param,const QString &value) const void RDReport::SetRow(const QString &param,const QString &value) const
{ {
RDSqlQuery *q; RDSqlQuery *q;

View File

@ -95,6 +95,9 @@ class RDReport
static QString errorText(RDReport::ErrorCode code); static QString errorText(RDReport::ErrorCode code);
private: private:
QString LeftJustify(const QString &str,int width) const;
QString RightJustify(const QString &str,int width) const;
QString Center(const QString &str,int width) const;
bool ExportDeltaflex(const QString &filename,const QDate &startdate, bool ExportDeltaflex(const QString &filename,const QDate &startdate,
const QDate &enddate,const QString &mixtable); const QDate &enddate,const QString &mixtable);
bool ExportTextLog(const QString &filename,const QDate &startdate, bool ExportTextLog(const QString &filename,const QDate &startdate,
@ -120,7 +123,6 @@ class RDReport
const QDate &enddate,const QString &mixtable); const QDate &enddate,const QString &mixtable);
bool ExportCutLog(const QString &filename,const QDate &startdate, bool ExportCutLog(const QString &filename,const QDate &startdate,
const QDate &enddate,const QString &mixtable); const QDate &enddate,const QString &mixtable);
QString StringField(const QString &str,const QString &null_text="") const;
void SetRow(const QString &param,const QString &value) const; void SetRow(const QString &param,const QString &value) const;
void SetRow(const QString &param,int value) const; void SetRow(const QString &param,int value) const;
void SetRow(const QString &param,unsigned value) const; void SetRow(const QString &param,unsigned value) const;