From 4de82a23ebe2a582bff1140d5becd61650aea72f Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Wed, 31 Jan 2018 14:26:46 -0500 Subject: [PATCH] 2018-02-01 Fred Gleason * Converted rdcheckcuts(1) to use RDApplication. --- ChangeLog | 2 + utils/rdcheckcuts/rdcheckcuts.cpp | 74 ++++++++++--------------------- utils/rdcheckcuts/rdcheckcuts.h | 7 +-- 3 files changed, 26 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ca22154..d499f385 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16619,3 +16619,5 @@ * Converted rdrepld(8) to use RDApplication. 2018-02-01 Fred Gleason * Moved command-switch processing into RDApplication. +2018-02-01 Fred Gleason + * Converted rdcheckcuts(1) to use RDApplication. diff --git a/utils/rdcheckcuts/rdcheckcuts.cpp b/utils/rdcheckcuts/rdcheckcuts.cpp index 7bfc6f13..9b5eb5f2 100644 --- a/utils/rdcheckcuts/rdcheckcuts.cpp +++ b/utils/rdcheckcuts/rdcheckcuts.cpp @@ -22,12 +22,11 @@ #include -#include -#include -#include +#include #include #include #include +#include #include @@ -38,36 +37,30 @@ MainObject::MainObject(QObject *parent) std::vector bad_cuts; QString sql; RDSqlQuery *q; + QString err_msg; + // + // Open the Database + // + rda=new RDApplication("rdcheckcuts","rdcheckcuts",RDCHECKCUTS_USAGE,this); + if(!rda->open(&err_msg)) { + fprintf(stderr,"rdcheckcuts: %s\n",(const char *)err_msg); + exit(1); + } + // // Read Command Options // - RDCmdSwitch *cmd= - new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdcheckcuts",RDCHECKCUTS_USAGE); - for(unsigned i=0;ikeys();i++) { - if(cmd->key(i)=="--group") { - group_names.push_back(cmd->value(i)); - cmd->setProcessed(i,true); + for(unsigned i=0;icmdSwitch()->keys();i++) { + if(rda->cmdSwitch()->key(i)=="--group") { + group_names.push_back(rda->cmdSwitch()->value(i)); + rda->cmdSwitch()->setProcessed(i,true); + } + if(!rda->cmdSwitch()->processed(i)) { + fprintf(stderr,"rdcheckcuts: unknown command option \"%s\"\n", + (const char *)rda->cmdSwitch()->key(i)); + exit(2); } - } - if(!cmd->allProcessed()) { - fprintf(stderr,"rdcheckcuts: unknown option\n"); - exit(256); - } - - // - // Open Configuration - // - cut_config=new RDConfig(); - cut_config->load(); - cut_config->setModuleName("rdcheckcuts"); - - // - // Open Database - // - if(!OpenDb()) { - fprintf(stderr,"rdcheckcuts: unable to open database\n"); - exit(256); } // @@ -121,8 +114,8 @@ bool MainObject::ValidateGroup(const QString &groupname, bool ret=true; QString sql; RDSqlQuery *q; - RDStation *station=new RDStation(cut_config->stationName()); - RDAudioInfo *info=new RDAudioInfo(station,cut_config); + // RDStation *station=new RDStation(rda->config()->stationName()); + RDAudioInfo *info=new RDAudioInfo(rda->station(),rda->config()); RDAudioInfo::ErrorCode err_code; sql=QString("select CUTS.CUT_NAME,CUTS.CART_NUMBER,CUTS.LENGTH ")+ @@ -153,32 +146,11 @@ bool MainObject::ValidateGroup(const QString &groupname, } } delete info; - delete station; return ret; } -bool MainObject::OpenDb() -{ - unsigned schema=0; - - QString err(tr("rdcheckcuts: ")); - QSqlDatabase *db=RDInitDb(&schema,&err); - if(!db) { - fprintf(stderr,err.ascii()); - return false; - } - return true; -} - - -void MainObject::CloseDb() -{ - QSqlDatabase::removeDatabase(cut_config->mysqlDbname()); -} - - int main(int argc,char *argv[]) { QApplication a(argc,argv,false); diff --git a/utils/rdcheckcuts/rdcheckcuts.h b/utils/rdcheckcuts/rdcheckcuts.h index 3bc93dcf..ed5dfb5e 100644 --- a/utils/rdcheckcuts/rdcheckcuts.h +++ b/utils/rdcheckcuts/rdcheckcuts.h @@ -2,7 +2,7 @@ // // Check Rivendell Cuts for Valid Audio // -// (C) Copyright 2012,2016 Fred Gleason +// (C) Copyright 2012,2016-2018 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 @@ -25,8 +25,6 @@ #include -#include - #define RDCHECKCUTS_USAGE "[options]\n\nCheck Rivendell cuts for valid audio\n\n--group=\n Name of group to scan. This option may be given multiple times.\n If no group is specified, then ALL groups will be scanned.\n" class MainObject : public QObject @@ -37,9 +35,6 @@ class MainObject : public QObject private: void RenderCut(const QString &cutname); bool ValidateGroup(const QString &groupname,std::vector *cutnames); - bool OpenDb(); - void CloseDb(); - RDConfig *cut_config; };