From 4d72f09122fdb74e96d4e9f52e14a635f7e86890 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 18 Nov 2021 16:42:05 +0000 Subject: [PATCH] Switch Channel to std::string --- boxx.cc | 28 ++++++++++++++++++++++++++++ boxx.h | 5 +++++ channel.cc | 10 ---------- channel.h | 8 ++------ demuxerts.cc | 1 - vchannellist.cc | 7 ++++--- vepglistadvanced.cc | 2 +- wtextbox.cc | 5 +++++ wtextbox.h | 1 + 9 files changed, 46 insertions(+), 21 deletions(-) diff --git a/boxx.cc b/boxx.cc index 342f64c..3736249 100644 --- a/boxx.cc +++ b/boxx.cc @@ -449,6 +449,34 @@ void Boxx::drawTextCentre(const char* text, int x, int y, const DrawStyle& colou if (parent) parent->drawTextCentre(text, area.x + x, area.y + y, colour); else surface->drawTextCentre(text, x, y, colour); } + +// std::string versions - the switch back to const char* is currently here + +void Boxx::drawText(const std::string& text, int x, int y, const DrawStyle& colour) +{ + if (parent) parent->drawText(text.c_str(), area.x + x, area.y + y, colour); + else surface->drawText(text.c_str(), x, y, colour); +} + +void Boxx::drawText(const std::string& text, int x, int y, int width, const DrawStyle& colour) +{ + if (parent) parent->drawText(text.c_str(), area.x + x, area.y + y, width, colour); + else surface->drawText(text.c_str(), x, y, width, colour); +} + +void Boxx::drawTextRJ(const std::string& text, int x, int y, const DrawStyle& colour) +{ + if (parent) parent->drawTextRJ(text.c_str(), area.x + x, area.y + y, colour); + else surface->drawTextRJ(text.c_str(), x, y, colour); +} + +void Boxx::drawTextCentre(const std::string& text, int x, int y, const DrawStyle& colour) +{ + if (parent) parent->drawTextCentre(text.c_str(), area.x + x, area.y + y, colour); + else surface->drawTextCentre(text.c_str(), x, y, colour); +} + + // Now deprecated /* void Boxx::drawPixelAlpha(UINT x, UINT y, const Colour& colour,bool fastdraw) diff --git a/boxx.h b/boxx.h index da15523..0c1b216 100644 --- a/boxx.h +++ b/boxx.h @@ -101,6 +101,11 @@ class Boxx void drawText(const char* text, int x, int y, int width, const DrawStyle& colour); void drawTextRJ(const char* text, int x, int y, const DrawStyle& colour); void drawTextCentre(const char* text, int x, int y, const DrawStyle& colour); + // std::string versions + void drawText(const std::string& text, int x, int y, const DrawStyle& colour); + void drawText(const std::string& text, int x, int y, int width, const DrawStyle& colour); + void drawTextRJ(const std::string& text, int x, int y, const DrawStyle& colour); + void drawTextCentre(const std::string& text, int x, int y, const DrawStyle& colour); //Now deprecated //void drawPixel(UINT x, UINT y, const Colour& colour, bool fastdraw=false); void drawBitmap(UINT x, UINT y, const Bitmap& bm, const DisplayRegion& region); diff --git a/channel.cc b/channel.cc index 148f4e9..8e6f22f 100644 --- a/channel.cc +++ b/channel.cc @@ -25,16 +25,6 @@ static const char* TAG = "Channel"; -Channel::Channel() -{ -} - -Channel::~Channel() -{ - if (name) delete[] name; - index = -1; // just in case -} - void Channel::loadPids() { // Clear the list if this is a reload diff --git a/channel.h b/channel.h index d6d3326..1825400 100644 --- a/channel.h +++ b/channel.h @@ -20,8 +20,8 @@ #ifndef CHANNEL_H #define CHANNEL_H -#include #include +#include #include "defines.h" @@ -41,17 +41,13 @@ typedef std::vector APidList; class Channel { public: - Channel(); - ~Channel(); - void loadPids(); int index{-1}; ULONG number{}; ULONG type{}; UCHAR vstreamtype{2}; //Mpeg2 - char* name{}; - + std::string name; ULONG vpid{}; ULONG numAPids{}; diff --git a/demuxerts.cc b/demuxerts.cc index 3aff0c1..be4a0ca 100644 --- a/demuxerts.cc +++ b/demuxerts.cc @@ -378,7 +378,6 @@ int DemuxerTS::processTS(UCHAR* buf) new_channelinfo.numSPids=0; new_channelinfo.number=0; new_channelinfo.type=VDR::RADIO; - new_channelinfo.name=NULL; new_channelinfo.tpid=0xFFFFF; //unused, check this new_channelinfo.vpid=0xFFFFF; //unused, check this new_channelinfo.index=0; diff --git a/vchannellist.cc b/vchannellist.cc index 4783434..3061fd3 100644 --- a/vchannellist.cc +++ b/vchannellist.cc @@ -81,7 +81,6 @@ VChannelList::~VChannelList() void VChannelList::setList(std::shared_ptr tlist) { - char str[500]; OsdVector *osdv=dynamic_cast(Osd::getInstance()); sl.addColumn(0); @@ -98,7 +97,9 @@ void VChannelList::setList(std::shared_ptr tlist) for (UINT i = 0; i < chanList->size(); i++) { chan = (*chanList)[i]; - sprintf(str, "%lu\t%s", chan->number, chan->name); + //sprintf(str, "%lu\t%s", chan->number, chan->name); + std::ostringstream os; + os << chan->number << '\t' << chan->name; TVMediaInfo *info=NULL; if (osdv) { info= new TVMediaInfo(); @@ -106,7 +107,7 @@ void VChannelList::setList(std::shared_ptr tlist) if (type == VDR::VIDEO) info->setStaticFallback(sa_tv); else info->setStaticFallback(sa_radio); } - chan->index = sl.addOption(str, chan, first, info); + chan->index = sl.addOption(os.str(), chan, first, info); first = 0; } } diff --git a/vepglistadvanced.cc b/vepglistadvanced.cc index d57c296..dea8b6b 100644 --- a/vepglistadvanced.cc +++ b/vepglistadvanced.cc @@ -639,7 +639,7 @@ void VEpgListAdvanced::draw(bool doIndexPop) if (chan->number == channelNumber) break; } - sprintf(tempA, tr("Schedule - %s"), (*chanList)[listIndex]->name); + sprintf(tempA, tr("Schedule - %s"), (*chanList)[listIndex]->name.c_str()); setTitleText(tempA); break; } diff --git a/wtextbox.cc b/wtextbox.cc index 33464b1..8640c21 100644 --- a/wtextbox.cc +++ b/wtextbox.cc @@ -48,6 +48,11 @@ void WTextbox::setText(const char* takeText) text = takeText; } +void WTextbox::setText(const std::string& takeText) +{ + text = takeText; +} + void WTextbox::setForegroundColour(const DrawStyle& fcolour) { foreColour = fcolour; diff --git a/wtextbox.h b/wtextbox.h index c9b256d..d499108 100644 --- a/wtextbox.h +++ b/wtextbox.h @@ -32,6 +32,7 @@ class WTextbox : public Boxx public: WTextbox(const char* ttext = NULL); void setText(const char* text); + void setText(const std::string& text); void draw(); void setForegroundColour(const DrawStyle& fcolour); void setTextPos(int x, int y); // optional -- 2.39.2