From c16450ac3ecfb70e89b49207fd268dff7767879c Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 22 Mar 2020 23:23:36 +0000 Subject: [PATCH] Event class to std::string --- event.cc | 108 ++++++++++++++---------------------------------- event.h | 49 +++++++++------------- vepg.cc | 28 ++++++------- vepgsettimer.cc | 13 +++--- vepgsettimer.h | 5 +-- vepgsummary.cc | 11 +++-- vepgsummary.h | 3 +- 7 files changed, 77 insertions(+), 140 deletions(-) diff --git a/event.cc b/event.cc index f8cbffd..930605c 100644 --- a/event.cc +++ b/event.cc @@ -1,5 +1,6 @@ /* Copyright 2004-2005 Chris Tallon + Copyright 2014 Marten Richter This file is part of VOMP. @@ -14,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #include "event.h" @@ -28,82 +28,34 @@ MovieInfo* Event::movieInfo = NULL; SeriesInfo* Event::seriesInfo = NULL; -Event::Event() -{ - id = 0; - time = 0; - duration = 0; - - title = NULL; - subtitle = NULL; - description = NULL; - index = -1; - movieID = 0; - seriesID =0; - epgImage = 0; -} - -Event::~Event() -{ - if (title) delete[] title; - if (subtitle) delete[] subtitle; - if (description) delete[] description; -} - -void Event::settitle(const char* s) -{ - delete title; - title = new char[strlen(s) + 1]; - strcpy(title, s); -} - -void Event::setdescription(const char* s) -{ - delete description; - description = new char[strlen(s) + 1]; - strcpy(description, s); -} - -void Event::setsubtitle(const char* s) -{ - delete subtitle; - subtitle = new char[strlen(s) + 1]; - strcpy(subtitle, s); -} - - void Event::loadinfos(UINT channelid) { - VDR *vdr=VDR::getInstance(); - if (movieInfo) delete movieInfo; - if (seriesInfo) delete seriesInfo; - - movieInfo = NULL; - seriesInfo = NULL; - - - if (movieID == 0 && seriesID == 0) { - vdr->getScraperEventType(channelid, id, movieID, seriesID, episodeID, epgImage); - Log::getInstance()->log("Event", Log::DEBUG, "Got Scraper EventType %d %d, %d %d %d %d", - id, channelid, - movieID, seriesID, episodeID); - } - - if (!vdr->isConnected()) Command::getInstance()->connectionLost(); - - if (movieID != 0) - { - movieInfo = vdr->getScraperMovieInfo(movieID); - Log::getInstance()->log("Event", Log::DEBUG, "Got Scraper MovieInfo "); - } - else if (seriesID != 0) - { - seriesInfo = vdr->getScraperSeriesInfo(seriesID, episodeID); - Log::getInstance()->log("Event", Log::DEBUG, "Got Scraper SeriesInfo "); - } - - - if (!vdr->isConnected()) Command::getInstance()->connectionLost(); + VDR* vdr = VDR::getInstance(); + if (movieInfo) delete movieInfo; + if (seriesInfo) delete seriesInfo; + + movieInfo = NULL; + seriesInfo = NULL; + + if (movieID == 0 && seriesID == 0) + { + vdr->getScraperEventType(channelid, id, movieID, seriesID, episodeID, epgImage); + Log::getInstance()->log("Event", Log::DEBUG, "Got Scraper EventType %d %d, %d %d %d %d", + id, channelid, movieID, seriesID, episodeID); + } + + if (!vdr->isConnected()) Command::getInstance()->connectionLost(); + + if (movieID != 0) + { + movieInfo = vdr->getScraperMovieInfo(movieID); + Log::getInstance()->log("Event", Log::DEBUG, "Got Scraper MovieInfo"); + } + else if (seriesID != 0) + { + seriesInfo = vdr->getScraperSeriesInfo(seriesID, episodeID); + Log::getInstance()->log("Event", Log::DEBUG, "Got Scraper SeriesInfo"); + } + + if (!vdr->isConnected()) Command::getInstance()->connectionLost(); } - - diff --git a/event.h b/event.h index 4473d7a..b436d00 100644 --- a/event.h +++ b/event.h @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,16 +14,13 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef EVENT_H #define EVENT_H -#include -#include -#include +#include #include "defines.h" @@ -33,41 +30,33 @@ class SeriesInfo; class Event { public: - Event(); - ~Event(); - - void settitle(const char* title); - void setsubtitle(const char* subtitle); - void setdescription(const char* description); - void loadinfos(UINT channelid); - ULONG id; + ULONG id{}; + ULONG time{}; + ULONG duration{}; - ULONG time; - ULONG duration; + std::string title; + std::string subtitle; + std::string description; - char* title; - char* subtitle; - char* description; + int index{-1}; - int index; + int movieID{}; + int seriesID{}; + int episodeID{}; + int epgImage{}; static MovieInfo *movieInfo; static SeriesInfo *seriesInfo; - int movieID; - int seriesID; - int episodeID; - int epgImage; }; -class EventSorter +struct EventSorter { - public: - bool operator()(const Event* e1, const Event* e2) - { - return e1->time < e2->time; - } + bool operator()(const Event* e1, const Event* e2) + { + return e1->time < e2->time; + } }; #endif diff --git a/vepg.cc b/vepg.cc index 62705b3..72bd1f9 100644 --- a/vepg.cc +++ b/vepg.cc @@ -214,7 +214,7 @@ void VEpg::setInfo(Event* event) time_t t; struct tm btime; // to hold programme start and end time char timeString[9]; // to hold programme start and end time - int length = strlen(event->title); // calculate length of programme title string + int length = strlen(event->title.c_str()); // calculate length of programme title string char* title = new char[length + 15]; // create string to hold start time, end time and programme title time_t eventtime = event->time; LOCALTIME_R(&eventtime, &btime); //get programme start time @@ -233,11 +233,11 @@ void VEpg::setInfo(Event* event) #endif strcat(title, timeString); // put it in our buffer - strcat(title, event->title); // then add the programme title + strcat(title, event->title.c_str()); // then add the programme title progTitle.setText(title); // sput this sring in our text box - length = strlen(event->description); + length = event->description.length(); char* info = new char[length + 1]; // create programme detail string - strcpy(info, event->description); + strcpy(info, event->description.c_str()); progInfo.setText(info); // show programme detail string // destroy dynamically allocated memory delete[] info; @@ -566,10 +566,10 @@ void VEpg::drawgrid() // redraws grid and select programme // TODO should the above two comditional statements be combined to avoid calling updateEventList() twice? Event* event; Event noevent; // an event to use if there are gaps in the epg - thisEvent.setdescription(tr("There are no programme details available for this period")); + thisEvent.description = tr("There are no programme details available for this period"); thisEvent.duration = window_width * 60; thisEvent.time = ltime; - thisEvent.settitle(tr("No programme details")); + thisEvent.title = tr("No programme details"); thisEvent.id = 0; bool swapColour = false; // alternate cell colour bool currentRow = false; @@ -584,14 +584,14 @@ void VEpg::drawgrid() // redraws grid and select programme currentRow = (listTop + (int)listIndex == chanListbox.getCurrentOption()); noevent.time = ltime; noevent.duration = window_width * 60; - noevent.settitle(""); + noevent.title = ""; paintCell(&noevent, y, DrawStyle::NOPROGRAMME, DrawStyle::LIGHTTEXT); // fill row with no programme colour to be painted ove with valid programmes if (currentRow) { - thisEvent.setdescription(tr("There are no programme details available for this period")); + thisEvent.description = tr("There are no programme details available for this period"); thisEvent.duration = window_width * 60; thisEvent.time = ltime; - thisEvent.settitle(tr("No programme details")); + thisEvent.title = tr("No programme details"); thisEvent.id = 0; } if (eventLista[listIndex]) @@ -614,10 +614,10 @@ void VEpg::drawgrid() // redraws grid and select programme if(event->time <= UINT(selTime) && end > UINT(selTime) && currentRow) { // this is the selected programme - thisEvent.setdescription(event->description); + thisEvent.description = event->description; thisEvent.duration = event->duration; thisEvent.time = event->time; - thisEvent.settitle(event->title); + thisEvent.title = event->title; thisEvent.id = event->id; if(thisEvent.id == 0) thisEvent.id = 1; @@ -651,7 +651,7 @@ void VEpg::drawgrid() // redraws grid and select programme { bg = DrawStyle::NOPROGRAMME; fg = DrawStyle::LIGHTTEXT; - noevent.settitle(tr("No programme details")); + noevent.title = tr("No programme details"); paintCell(&noevent, y, bg, fg); } } @@ -712,8 +712,8 @@ void VEpg::paintCell(Event* event, int yOffset, const DrawStyle& bg, const DrawS if (w > 155 + (int)window_width * MINUTE_SCALE - x) w = 155 + window_width * MINUTE_SCALE -x; // limit cells to RHS of window rectangle(x, y, w, h, bg); - char* tt = new char[strlen(event->title) + 1]; - strcpy (tt, event->title); + char* tt = new char[strlen(event->title.c_str()) + 1]; + strcpy (tt, event->title.c_str()); float textWidth = 0; unsigned int cur_length=1; unsigned int text_max=strlen(tt); diff --git a/vepgsettimer.cc b/vepgsettimer.cc index b6f71a3..b9a009b 100644 --- a/vepgsettimer.cc +++ b/vepgsettimer.cc @@ -14,11 +14,10 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ -#include "vepgsettimer.h" +#include #include "event.h" #include "channel.h" @@ -33,6 +32,8 @@ #include "input.h" #include "i18n.h" +#include "vepgsettimer.h" + VEpgSetTimer::VEpgSetTimer(Event* tevent, Channel* tchannel) { boxstack = BoxStack::getInstance(); @@ -141,8 +142,8 @@ char* VEpgSetTimer::genTimerString() } else strcpy(lifetime, "99"); - eventTitle = new char[strlen(event->title) + 1]; - strcpy(eventTitle, event->title); + eventTitle = new char[strlen(event->title.c_str()) + 1]; + strcpy(eventTitle, event->title.c_str()); for(UINT i=0; i < strlen(eventTitle); i++) if (eventTitle[i] == ':') eventTitle[i] = '|'; SNPRINTF(timerString, 1023, "%i:%lu:%s:%s:%s:%s:%s:%s:", @@ -174,7 +175,7 @@ void VEpgSetTimer::swap() void VEpgSetTimer::draw() { TBBoxx::draw(); - drawPara(event->title, 10, 40, DrawStyle::LIGHTTEXT); + drawPara(event->title.c_str(), 10, 40, DrawStyle::LIGHTTEXT); drawText(channel->name, 10, 40 + (2 * getFontHeight()), DrawStyle::LIGHTTEXT); char fullString[20]; diff --git a/vepgsettimer.h b/vepgsettimer.h index 2356677..943f27f 100644 --- a/vepgsettimer.h +++ b/vepgsettimer.h @@ -14,15 +14,12 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef VEPGSETTIMER_H #define VEPGSETTIMER_H -#include - #include "tbboxx.h" #include "wbutton.h" diff --git a/vepgsummary.cc b/vepgsummary.cc index 7fb795a..d56dae8 100644 --- a/vepgsummary.cc +++ b/vepgsummary.cc @@ -14,11 +14,10 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ -#include "vepgsummary.h" +#include #include "input.h" #include "vquestion.h" @@ -38,7 +37,7 @@ #include "wseriesview.h" #include "wpictureview.h" -#include +#include "vepgsummary.h" VEpgSummary::VEpgSummary(Event *tevent, Channel* tchannel) { @@ -60,7 +59,7 @@ VEpgSummary::VEpgSummary(Event *tevent, Channel* tchannel) setTitleBarOn(1); setBorderOn(1); - setTitleText(event->title); + setTitleText(event->title.c_str()); setTitleBarColour(DrawStyle::TITLEBARBACKGROUND); @@ -82,7 +81,7 @@ VEpgSummary::VEpgSummary(Event *tevent, Channel* tchannel) WTextbox * summary=new WTextbox(); summary->setParaMode(true); - std::string summary_text = std::string(event->subtitle)+ "\n" +std::string(event->description); + std::string summary_text = event->subtitle + "\n" + event->description; summary->setText(summary_text.c_str()); OsdVector *osdv=dynamic_cast(Osd::getInstance()); diff --git a/vepgsummary.h b/vepgsummary.h index 92ec74a..e7145b0 100644 --- a/vepgsummary.h +++ b/vepgsummary.h @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef VEPGSUMMARY_H -- 2.39.2