]> git.vomp.tv Git - vompclient.git/commitdiff
Event class to std::string
authorChris Tallon <chris@vomp.tv>
Sun, 22 Mar 2020 23:23:36 +0000 (23:23 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 22 Mar 2020 23:23:36 +0000 (23:23 +0000)
event.cc
event.h
vepg.cc
vepgsettimer.cc
vepgsettimer.h
vepgsummary.cc
vepgsummary.h

index f8cbffd3fc43f21ad5d8b0914b1fa883101deb0a..930605cbe66af2ed372bb2bb343fda4ad7f710a2 100644 (file)
--- 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 <https://www.gnu.org/licenses/>.
 */
 
 #include "event.h"
 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 4473d7a5859e2faa60a8553366badf11ab6eba70..b436d001bac023d700a4ddf4e69fac72a4940102 100644 (file)
--- 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.
 
     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 <https://www.gnu.org/licenses/>.
 */
 
 #ifndef EVENT_H
 #define EVENT_H
 
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
+#include <string>
 
 #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 62705b348dac204baef007ddd17478a9d9911f19..72bd1f93f4ff9455dbf52e4f7bd444d3ed058df6 100644 (file)
--- 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);
index b6f71a3d558278a3fa1a873066ca3fd9e21abbdb..b9a009bb078740b5454fd4198a6adaf0a4b59979 100644 (file)
     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 <https://www.gnu.org/licenses/>.
 */
 
-#include "vepgsettimer.h"
+#include <time.h>
 
 #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];
index 2356677f13a43687421961bb8bdc80a2f5ec940d..943f27f9eeb5fdefc60bdc17a9f28b83d2ddac55 100644 (file)
     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 <https://www.gnu.org/licenses/>.
 */
 
 #ifndef VEPGSETTIMER_H
 #define VEPGSETTIMER_H
 
-#include <time.h>
-
 #include "tbboxx.h"
 #include "wbutton.h"
 
index 7fb795adc066b799c8664bf52a7693cfcc45f321..d56dae8a211771166d333b62c6c6efcf2586ae38 100644 (file)
     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 <https://www.gnu.org/licenses/>.
 */
 
-#include "vepgsummary.h"
+#include <string>
 
 #include "input.h"
 #include "vquestion.h"
@@ -38,7 +37,7 @@
 #include "wseriesview.h"
 #include "wpictureview.h"
 
-#include <string>
+#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<OsdVector*>(Osd::getInstance());
index 92ec74af1f63c42b5a1726f2dae42ff83def7dca..e7145b008e0a34259e813633befa50e77c3b045e 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
 */
 
 #ifndef VEPGSUMMARY_H