From b8bb19d6d1d255b83d8a2b53854151ea1e9536a5 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 16 Sep 2021 18:39:49 +0100 Subject: [PATCH] Fix a Boxx log line. Switch some WSelectList code to std::string/fmt::format --- boxx.cc | 2 +- boxx.h | 2 +- control.h | 4 ++-- vepglistadvanced.cc | 35 +++++++++++++++++------------------ vrecordinglistadvanced.cc | 15 +++++++-------- vrecordinglistclassic.cc | 17 ++++++++--------- wselectlist.cc | 14 ++++++++++++++ wselectlist.h | 1 + 8 files changed, 51 insertions(+), 39 deletions(-) diff --git a/boxx.cc b/boxx.cc index 79cafc8..bc7bdcb 100644 --- a/boxx.cc +++ b/boxx.cc @@ -30,7 +30,7 @@ static const char* TAG = "Boxx"; -char Boxx::numBoxxes = 0; +int Boxx::numBoxxes = 0; Boxx::Boxx() { diff --git a/boxx.h b/boxx.h index 54ba03e..da15523 100644 --- a/boxx.h +++ b/boxx.h @@ -158,7 +158,7 @@ class Boxx bool backgroundColourSet{}; bool visible{true}; - static char numBoxxes; + static int numBoxxes; }; #endif diff --git a/control.h b/control.h index 4c6a7bd..694d8cd 100644 --- a/control.h +++ b/control.h @@ -69,7 +69,7 @@ class Control : public MessageQueue void setAdvMenus(bool adv) { advMenus = adv; }; bool isAdvMenus() { return advMenus; }; int getLangPref(bool subtitle,const char* langcode); - void setSubDefault(int subon) { subdefault = subon; }; + void setSubDefault(int subon) { subdefault = subon; }; // NCONFIG int getSubDefault() { return subdefault; }; ASLPrefList &getASLList() { return langcodes; }; @@ -114,7 +114,7 @@ class Control : public MessageQueue bool advMenus{}; ASLPrefList langcodes; - int subdefault; + int subdefault; // NCONFIG void processMessage(Message* m); }; diff --git a/vepglistadvanced.cc b/vepglistadvanced.cc index a5dc8ef..c59b913 100644 --- a/vepglistadvanced.cc +++ b/vepglistadvanced.cc @@ -487,11 +487,11 @@ void VEpgListAdvanced::drawDataChannel(bool doIndexPop) int first = 1; - char tempA[300]; // FIXME this is guesswork! - char tempB[300]; // FIXME - char tempC[300]; // FIXME struct tm btime; + char startTimeStr[16]; + char endTimeStr[16]; + Event* currentEvent = NULL; EventList::iterator j; EventList* eventList = eventLista[0]; @@ -505,18 +505,17 @@ void VEpgListAdvanced::drawDataChannel(bool doIndexPop) time_t eventEndTime = static_cast(currentEvent->time + currentEvent->duration); LOCALTIME_R(&eventStartTime, &btime); - strftime(tempA, 300, "%d/%m/%y %H:%M ", &btime); + strftime(startTimeStr, 16, "%d/%m/%y %H:%M", &btime); LOCALTIME_R(&eventEndTime, &btime); - strftime(tempB, 300, "- %H:%M ", &btime); - int check = SNPRINTF(tempC, 300, "\t %s\n \t \t%s%s", currentEvent->title.c_str(), tempA, tempB); - - if ((check < 0) || (check > 299)) LogNT::getInstance()->debug(TAG, "String too big"); + strftime(endTimeStr, 16, "%H:%M", &btime); + std::string eventText = fmt::format("\t {}\n \t \t{} - {}", currentEvent->title, startTimeStr, endTimeStr); // New TVMedia stuff TVMediaInfo* info = new TVMediaInfo(); info->setPosterThumb(channelNumber, currentEvent->id); info->setStaticFallback(sa_defposter); - currentEvent->index = sl.addOption(tempC, reinterpret_cast(currentEvent->id), first, info); + + currentEvent->index = sl.addOption(eventText, reinterpret_cast(currentEvent->id), first, info); first = 0; } } @@ -545,9 +544,8 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop) int first = 1; - char tempA[300]; // FIXME this is guesswork! - char tempB[300]; // FIXME - char tempC[300]; // FIXME + char startTimeStr[16]; + char endTimeStr[16]; struct tm btime; Event* currentEvent = NULL; @@ -560,6 +558,8 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop) unsigned int chanlistsize = chanList->size(); + std::string eventText; + for (UINT listIndex = 0; listIndex < chanlistsize; listIndex++) { Channel* chan; @@ -576,16 +576,15 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop) time_t eventEndTime = static_cast(currentEvent->time + currentEvent->duration); LOCALTIME_R(&eventStartTime, &btime); - strftime(tempA, 300, "%H:%M ", &btime); + strftime(startTimeStr, 16, "%H:%M", &btime); LOCALTIME_R(&eventEndTime, &btime); - strftime(tempB, 300, "- %H:%M ", &btime); - int check = SNPRINTF(tempC, 300, "%s\n%s\t %s%s", currentEvent->title.c_str(), chan->name, tempA, tempB); + strftime(endTimeStr, 16, "%H:%M", &btime); - if ((check < 0) || (check > 299)) LogNT::getInstance()->debug(TAG, "String too big"); + eventText = fmt::format("{}\n{}\t{} - {}", currentEvent->title, chan->name, startTimeStr, endTimeStr); } else { - sprintf(tempC, "\n%s", chan->name); + eventText = fmt::format("\n{}", chan->name); } TVMediaInfo* info = new TVMediaInfo(); @@ -598,7 +597,7 @@ void VEpgListAdvanced::drawDataNowNext(bool next, bool doIndexPop) info->setChannelLogo((*chanList)[listIndex]->number); info->setStaticFallback(sa_tv); - int index = sl.addOption(tempC, reinterpret_cast(listIndex), first, info); + int index = sl.addOption(eventText, reinterpret_cast(listIndex), first, info); if (currentEvent) currentEvent->index = index; diff --git a/vrecordinglistadvanced.cc b/vrecordinglistadvanced.cc index 5b10daa..25be5e0 100644 --- a/vrecordinglistadvanced.cc +++ b/vrecordinglistadvanced.cc @@ -19,6 +19,7 @@ #include #include +#include #include "recman.h" #include "directory.h" @@ -93,8 +94,7 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) int first = 1; - char tempA[300]; // FIXME this is guesswork! - char tempB[300]; // FIXME + char timeString[16]; // "dd/mm/yy hh:mm" struct tm btime; Directory* currentSubDir; @@ -103,7 +103,7 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) for (i = dirList->begin(); i != dirList->end(); i++) { currentSubDir = *i; - SNPRINTF(tempA, 300, tr("\t%s \n \t %lu/%lu"), currentSubDir->name, currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings()); + std::string dirString = fmt::format("\t{} \n \t {}/{}", currentSubDir->name, currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings()); TVMediaInfo *info=new TVMediaInfo(); if (currentSubDir->recList.begin() != currentSubDir->recList.end()) @@ -113,7 +113,7 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) } else { info->setStaticArtwork(sa_recfolder); } - currentSubDir->index = sl.addOption(tempA, 0, first, info); + currentSubDir->index = sl.addOption(dirString, 0, first, info); first = 0; } @@ -127,15 +127,14 @@ void VRecordingListAdvanced::drawData(bool doIndexPop) currentRec = *j; time_t recStartTime = static_cast(currentRec->getStartTime()); LOCALTIME_R(&recStartTime, &btime); - strftime(tempA, 299, "%d/%m/%y %H:%M ", &btime); - int check = SNPRINTF(tempB, 300, "%c\t%s\n \t%s", (currentRec->getNew() ? '*': ' '), currentRec->getProgName(), tempA); - if ((check < 0) || (check > 299)) LogNT::getInstance()->error("VRecordingsListAdvanced", "String too big"); + strftime(timeString, 16, "%d/%m/%y %H:%M", &btime); + std::string fileString = fmt::format("{}\t{}\n \t{}", (currentRec->getNew() ? '*': ' '), currentRec->getProgName(), timeString); // New TVMedia stuff TVMediaInfo *info= new TVMediaInfo(); info->setPosterThumb(currentRec->getFileName()); info->setStaticFallback(sa_recording); - currentRec->index = sl.addOption(tempB, 0, first, info); + currentRec->index = sl.addOption(fileString, 0, first, info); first = 0; } diff --git a/vrecordinglistclassic.cc b/vrecordinglistclassic.cc index c43e626..a2f2396 100644 --- a/vrecordinglistclassic.cc +++ b/vrecordinglistclassic.cc @@ -17,6 +17,8 @@ along with VOMP. If not, see . */ +#include + #include "recman.h" #include "directory.h" #include "recording.h" @@ -73,8 +75,7 @@ void VRecordingListClassic::drawData(bool doIndexPop) int first = 1; - char tempA[300]; // FIXME this is guesswork! - char tempB[300]; // FIXME + char timeString[16]; // "dd/mm hh:mm" struct tm btime; Directory* currentSubDir; @@ -83,8 +84,8 @@ void VRecordingListClassic::drawData(bool doIndexPop) for (i = dirList->begin(); i != dirList->end(); i++) { currentSubDir = *i; - SNPRINTF(tempA, 300, tr(" %lu/%lu\t \t%s"), currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings(), currentSubDir->name); - currentSubDir->index = sl.addOption(tempA, 0, first); + std::string dirString = fmt::format(" {}/{}\t \t{}", currentSubDir->getNumNewRecordings(), currentSubDir->getNumRecordings(), currentSubDir->name); + currentSubDir->index = sl.addOption(dirString, 0, first); first = 0; } // FIXME convert the whole program to time_t's @@ -97,11 +98,9 @@ void VRecordingListClassic::drawData(bool doIndexPop) currentRec = *j; time_t recStartTime = static_cast(currentRec->getStartTime()); LOCALTIME_R(&recStartTime, &btime); - strftime(tempA, 300, "%d/%m %H:%M ", &btime); - int check = SNPRINTF(tempB, 300, "%s\t%c\t%s", tempA, (currentRec->getNew() ? '*': ' '), currentRec->getProgName()); - if ((check < 0) || (check > 299)) LogNT::getInstance()->error("VRecordingListClassic", "String too big"); - - currentRec->index = sl.addOption(tempB, 0, first); + strftime(timeString, 16, "%d/%m %H:%M", &btime); + std::string fileString = fmt::format("{} \t{}\t{}", timeString, (currentRec->getNew() ? '*': ' '), currentRec->getProgName()); + currentRec->index = sl.addOption(fileString, 0, first); first = 0; } diff --git a/wselectlist.cc b/wselectlist.cc index b618e6a..ba34cf7 100644 --- a/wselectlist.cc +++ b/wselectlist.cc @@ -85,6 +85,20 @@ int WSelectList::addOption(const char* text, void* data, int selected, TVMediaIn return thisNewOption; } +int WSelectList::addOption(const std::string& text, void* data, int selected, TVMediaInfo* pict) // FIXME convert WSelectList wslo to use std::string +{ + int thisNewOption = options.size(); + + wsloption wslo; + wslo.text = new char[text.length() + 1]; + strcpy(wslo.text, text.c_str()); + wslo.data = data; + wslo.pict = pict; + options.push_back(wslo); + if (selected) selectedOption = thisNewOption; + return thisNewOption; +} + void WSelectList::draw() { int fontHeight = getFontHeight(); diff --git a/wselectlist.h b/wselectlist.h index 526a438..f59775d 100644 --- a/wselectlist.h +++ b/wselectlist.h @@ -45,6 +45,7 @@ class WSelectList : public Boxx void setShowSelOption(bool set) { showseloption = set; } void setDarkSelOption(bool set) { darkseloption = set; } int addOption(const char* text, void* data, int selected, TVMediaInfo* pict = NULL); + int addOption(const std::string& text, void* data, int selected, TVMediaInfo* pict = NULL); void draw(); void setBackgroundColour(const DrawStyle& colour); void setLinesPerOption(float lines) { linesPerOption = lines; } -- 2.39.5