]> git.vomp.tv Git - vompclient.git/commitdiff
Convert WSelectList to std::string
authorChris Tallon <chris@vomp.tv>
Sun, 3 Oct 2021 17:06:37 +0000 (18:06 +0100)
committerChris Tallon <chris@vomp.tv>
Sun, 3 Oct 2021 17:06:37 +0000 (18:06 +0100)
vaudioselector.cc
vserverselect.cc
wremoteconfig.cc
wselectlist.cc
wselectlist.h

index f4bae22cfb98816effdd8d57bf5e94e2e48d510c..0c25eefb09536c1da349f49a7271310759e04d17 100644 (file)
@@ -221,7 +221,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, bool* availableMpegAudi
     {
       if (!ac.name.empty())
       {
-        asl.addOption(ac.name.c_str(), &ac, (ac.pestype == currentAudioChannel));
+        asl.addOption(ac.name, &ac, (ac.pestype == currentAudioChannel));
       }
       else
       {
@@ -231,7 +231,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, bool* availableMpegAudi
         else if (ac.type == 1) tempString = "ac3 " + std::to_string(ac.pestype - PES_AUDIO_AC3_START);
         else                   tempString = "unknown";
 
-        asl.addOption(tempString.c_str(), &ac, (ac.pestype == currentAudioChannel));
+        asl.addOption(tempString, &ac, (ac.pestype == currentAudioChannel));
       }
     }
   }
@@ -252,7 +252,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, bool* availableMpegAudi
 
       if (!sc.name.empty())
       {
-        ssl.addOption(sc.name.c_str(), &sc, selected);
+        ssl.addOption(sc.name, &sc, selected);
       }
       else
       {
@@ -261,7 +261,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, bool* availableMpegAudi
         if (sc.type == 0x10) tempString = std::to_string(sc.pestype - PES_DVBSUBTITLE_START);
         else                 tempString = "unknown";
 
-        ssl.addOption(tempString.c_str(), &sc, selected);
+        ssl.addOption(tempString, &sc, selected);
       }
     }
   }
@@ -365,7 +365,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, Channel* channel, int c
   {
     for (auto& ac : acl)
     {
-      asl.addOption(ac.name.c_str(), &ac, (ac.pestype == currentAudioChannel));
+      asl.addOption(ac.name, &ac, (ac.pestype == currentAudioChannel));
     }
   }
   else
@@ -381,7 +381,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, Channel* channel, int c
     {
       bool selected = false;
       if ((sc.type == currentSubtitletype) && (sc.pestype == currentSubtitleChannel)) selected = true;
-      ssl.addOption(sc.name.c_str(), &sc, selected);
+      ssl.addOption(sc.name, &sc, selected);
     }
   }
 
index 0f01528f979ce8e4b49b250be902350a6ce3d46c..99a8961aaae2194c16420fd59bb24c6369615035 100644 (file)
@@ -48,10 +48,10 @@ VServerSelect::VServerSelect(const VDPC& servers, MessageReceiver* treplyTo)
   sl.setSize(area.w - 20, area.h - 30 - 15);
   add(&sl);
 
-  sl.addOption(servers[0].name.c_str(), 0, 1);
+  sl.addOption(servers[0].name, 0, 1);
   for(UINT k = 1; k < servers.numServers(); k++)
   {
-    sl.addOption(servers[k].name.c_str(), 0, 0);
+    sl.addOption(servers[k].name, 0, 0);
   }
 
   replyTo = treplyTo;
index 5377d6148ba2673e16d958cbd2741f92b06a98ed..06029d8d01060cf1d53db6e17f123d1a00965fd0 100644 (file)
@@ -75,7 +75,7 @@ void WRemoteConfig::initSelectList(bool startup)
       line += inputMan->getHardCodedHardwareKeyNamesForVompKey(static_cast<UCHAR>(i));
       line += " \t"; // FIXME extra spaces for braindead strtok. Ditch strtok.
       line += inputMan->getAllHardwareKeyNamesAssignedToVompKey(static_cast<UCHAR>(i));
-      sl.addOption(line.c_str(), reinterpret_cast<void*>(i), 0);
+      sl.addOption(line, reinterpret_cast<void*>(i), 0);
     }
   }
 
index ba34cf773bee459f080db2360481a321e33f22a7..21381fe65e725d955c041c29bb1fcf629da5c600 100644 (file)
@@ -39,7 +39,6 @@ void WSelectList::clear()
   int vsize = options.size();
   for (int i = 0; i < vsize; i++)
   {
-    delete[] options[i].text;
     if (options[i].pict) delete options[i].pict;
   }
   options.clear();
@@ -76,8 +75,7 @@ int WSelectList::addOption(const char* text, void* data, int selected, TVMediaIn
   int thisNewOption = options.size();
 
   wsloption wslo;
-  wslo.text = new char[strlen(text) + 1];
-  strcpy(wslo.text, text);
+  wslo.text = text;
   wslo.data = data;
   wslo.pict = pict;
   options.push_back(wslo);
@@ -85,13 +83,12 @@ 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 WSelectList::addOption(const std::string& text, void* data, int selected, TVMediaInfo* pict)
 {
   int thisNewOption = options.size();
 
   wsloption wslo;
-  wslo.text = new char[text.length() + 1];
-  strcpy(wslo.text, text.c_str());
+  wslo.text = text;
   wslo.data = data;
   wslo.pict = pict;
   options.push_back(wslo);
@@ -150,7 +147,7 @@ int WSelectList::getColumn(int x)
   return columns[x];
 }
 
-void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict)
+void WSelectList::drawOptionLine(const std::string& text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict)
 {
   UINT curline = 0;
   UINT taboffset = 0;
@@ -170,12 +167,13 @@ void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, cons
 
   if (!numColumns && linesPerOption == 1)
   {
-    drawText(text, xpos, ypos, width, colour);
+    drawText(text.c_str(), xpos, ypos, width, colour);
   }
   else
   {
+    const char* ctext = text.c_str();
     char buffer[200];
-    strncpy(buffer, text, 199);
+    strncpy(buffer, ctext, 199);
     int currentColumn = taboffset;
     char* pointer;
     char* savepointer;
@@ -188,7 +186,7 @@ void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, cons
       pointer = STRTOKR(NULL, "\t\n", &savepointer);
       if (pointer)
       {
-        char delimiter = text[pointer - buffer - 1];
+        char delimiter = ctext[pointer - buffer - 1];
         if (delimiter == '\t') currentColumn++;
         else if (delimiter == '\n')
         {
index f59775d06c45e85f753cf4cc3a50d49401637f0e..a76a9a15d0a6348ec097461ac5d5e782d7c38cce 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef WSELECTLIST_H
 #define WSELECTLIST_H
 
+#include <string>
 #include <vector>
 
 #include "defines.h"
@@ -27,7 +28,7 @@
 
 typedef struct
 {
-  char* text;
+  std::string text;
   void* data;
   TVMediaInfo* pict;
 } wsloption;
@@ -70,7 +71,7 @@ class WSelectList : public Boxx
     virtual bool mouseAndroidScroll(int x, int y, int sx, int sy);
 
   private:
-    void drawOptionLine(char* text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict);
+    void drawOptionLine(const std::string& text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict);
     int getMouseLine(int x, int y);
 
     DrawStyle backgroundColour;