]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Variable width channel numbers
authorChris Tallon <chris@vomp.tv>
Tue, 1 May 2007 21:36:24 +0000 (21:36 +0000)
committerChris Tallon <chris@vomp.tv>
Tue, 1 May 2007 21:36:24 +0000 (21:36 +0000)
vchannellist.cc
vchannelselect.cc
vchannelselect.h
vdr.cc
vdr.h
vlivebanner.cc
vvideolive.cc

index 54a2882c32fd7f05c82f9e85623af750dc4722aa..c6e4769fdc5a1ac92b45cc39ae788169db4d9753 100644 (file)
@@ -201,10 +201,11 @@ int VChannelList::handleCommand(int command)
     case Remote::EIGHT:
     case Remote::NINE:
     {
-      VChannelSelect* v = new VChannelSelect(this, command);
+      VChannelSelect* v = new VChannelSelect(this);
       v->draw();
       viewman->add(v);
       viewman->updateView(v);
+      v->handleCommand(command);
       return 2;
     }
     case Remote::OK:
index ad1351cfb6b4ff04bebed43531d03be030f3b3ed..b538de2479f311022cd89e63a6bb57b018958e92 100644 (file)
 // this class only works as it does because the remote command
 // values for the numbers are the numbers themselves !
 
-VChannelSelect::VChannelSelect(View* v, int command)
+VChannelSelect::VChannelSelect(View* v)
 {
-  create(53, 30);
-  setScreenPos(80, 60);
-
-  setBackgroundColour(Colour::VIEWBACKGROUND);
+  parent = v;
+  numGot = 0;
+  ignoreTimer = false;
 
-  first = -1;
-  second = -1;
-  third = command;
-  numGot = 1;
+  numWidth = (int)VDR::getInstance()->getChannelNumberWidth();
+  if (numWidth > 10) numWidth = 10;
+  for (int i = 0; i < numWidth; i++) input[i] = -1;
 
-  parent = v;
+  create((numWidth*10) + 22, 30); // 10 px = width of number chars in font
+  setScreenPos(80, 60);
+  setBackgroundColour(Colour::VIEWBACKGROUND);
 }
 
 VChannelSelect::~VChannelSelect()
@@ -43,87 +43,84 @@ VChannelSelect::~VChannelSelect()
   Timers::getInstance()->cancelTimer(this, 1);
 }
 
+void VChannelSelect::timercall(int clientReference)
+{
+  Log::getInstance()->log("VChannelSelect", Log::DEBUG, "Timer call");
+  if (ignoreTimer) return;
+  changeChannel(false);
+}
+
+void VChannelSelect::doInput(int number)
+{
+  for (int i = numGot - 1; i >= 0; i--)
+  {
+    input[i+1] = input[i];
+  }
+
+  input[0] = number;
+  numGot++;
+}
+
 void VChannelSelect::draw()
 {
   View::draw();
 
   // draw numbers
-
   char text[2];
 
-  switch(first)
+  for (int i = 0; i < numWidth; i++)
   {
-    case 0:
-    case 1:
-    case 2:
-    case 3:
-    case 4:
-    case 5:
-    case 6:
-    case 7:
-    case 8:
-    case 9:
+    if (input[i] == -1)
     {
-      sprintf(text, "%i", first);
-      drawText(text, 7, 5, Colour::LIGHTTEXT);
-      break;
+      drawText("_", 7 + ((numWidth - 1 - i) * 10), 5, Colour::LIGHTTEXT);
     }
-    case -1:
+    else
     {
-      drawText("_", 7, 5, Colour::LIGHTTEXT);
-      break;
+      sprintf(text, "%i", input[i]);
+      drawText(text, 7 + ((numWidth - 1 - i) * 10), 5, Colour::LIGHTTEXT);
     }
   }
+}
 
-  switch(second)
-  {
-    case 0:
-    case 1:
-    case 2:
-    case 3:
-    case 4:
-    case 5:
-    case 6:
-    case 7:
-    case 8:
-    case 9:
-    {
-      sprintf(text, "%i", second);
-      drawText(text, 20, 5, Colour::LIGHTTEXT);
-      break;
-    }
-    case -1:
-    {
-      drawText("_", 20, 5, Colour::LIGHTTEXT);
-      break;
-    }
-  }
+void VChannelSelect::changeChannel(bool which)
+{
+  ignoreTimer = true;
+  Timers::getInstance()->cancelTimer(this, 1);
+
+  Message* m;
 
-  switch(third)
+  // Is there valid data? (is any number not-zero)
+  int i = 0;
+  for(i = 0; i < numWidth; i++) if (input[i]) break;
+
+  if (i < numWidth) // There is data
   {
-    case 0:
-    case 1:
-    case 2:
-    case 3:
-    case 4:
-    case 5:
-    case 6:
-    case 7:
-    case 8:
-    case 9:
-    {
-      sprintf(text, "%i", third);
-      drawText(text, 33, 5, Colour::LIGHTTEXT);
-      break;
-    }
-    case -1:
+    m = new Message();
+    m->from = this;
+    m->to = parent;
+    m->message = Message::CHANNEL_CHANGE;
+    m->parameter = 0;
+
+    for(i = numGot - 1; i >= 0; i--)
     {
-      drawText("_", 33, 5, Colour::LIGHTTEXT);
-      break;
+      m->parameter += input[i] * (ULONG)pow(10, i);
     }
+
+    if (which)
+      Command::getInstance()->postMessageNoLock(m);
+    else
+      Command::getInstance()->postMessageFromOuterSpace(m);
   }
 
-  Timers::getInstance()->setTimerD(this, 1, 3);
+  // Close me
+  m = new Message(); // Delete self
+  m->from = this;
+  m->to = ViewMan::getInstance();
+  m->message = Message::CLOSE_ME;
+  if (which)
+    Command::getInstance()->postMessageNoLock(m);
+  else
+    Command::getInstance()->postMessageFromOuterSpace(m);
 }
 
 int VChannelSelect::handleCommand(int command)
@@ -141,30 +138,11 @@ int VChannelSelect::handleCommand(int command)
     case Remote::EIGHT:
     case Remote::NINE:
     {
-      if (numGot == 2) first = second;
-      second = third;
-      third = command;
-      ++numGot;
-
+      doInput(command);
       draw();
       ViewMan::getInstance()->updateView(this);
-
-      if (numGot == 3)
-      {
-        // Is there valid data?
-        if ((first > 0) || (second > 0) || (third > 0))
-        {
-          Message* m = new Message();
-          m->from = this;
-          m->to = parent;
-          m->message = Message::CHANNEL_CHANGE;
-          m->parameter = (first * 100) + (second * 10) + third;
-          Command::getInstance()->postMessageNoLock(m);
-        }
-
-        return 4;
-      }
-
+      if (numGot == numWidth) changeChannel(true);
+      else Timers::getInstance()->setTimerD(this, 1, 3);
       return 2;
     }
   }
@@ -172,39 +150,3 @@ int VChannelSelect::handleCommand(int command)
   // allow command to drop through to other views
   return 0;
 }
-
-void VChannelSelect::timercall(int clientReference)
-{
-  Log::getInstance()->log("VChannelSelect", Log::DEBUG, "Timer call");
-
-  // Close me
-  Message* m = new Message(); // Delete self
-  m->from = this;
-  m->to = ViewMan::getInstance();
-  m->message = Message::CLOSE_ME;
-  Command::getInstance()->postMessageFromOuterSpace(m);
-
-  // Is there valid data?
-  if ((first > 0) || (second > 0) || (third > 0))
-  {
-    // Change channel
-
-    ULONG newChannel = 0;
-    switch(numGot)
-    {
-      case 3:
-        newChannel += first * 100;
-      case 2:
-        newChannel += second * 10;
-      case 1:
-        newChannel += third;
-    }
-
-    m = new Message(); // Must be done after this view deleted
-    m->from = this;
-    m->to = parent;
-    m->message = Message::CHANNEL_CHANGE;
-    m->parameter = newChannel;
-    Command::getInstance()->postMessageFromOuterSpace(m);
-  }
-}
index 814da3f70d1288bf9e302f7944639911b526abcf..9449e5f73754218b6ed203fda68975356500be0b 100644 (file)
@@ -38,7 +38,7 @@ class VVideoLive;
 class VChannelSelect : public View, public TimerReceiver
 {
   public:
-    VChannelSelect(View* v, int command);
+    VChannelSelect(View* v);
     ~VChannelSelect();
 
     void draw();
@@ -46,13 +46,15 @@ class VChannelSelect : public View, public TimerReceiver
     void timercall(int clientReference);
 
   private:
-    int first;
-    int second;
-    int third;
+    View* parent;
 
+    int input[10];
     int numGot;
+    int numWidth;
+    bool ignoreTimer;
 
-    View* parent;
+    void doInput(int number);
+    void changeChannel(bool which); // true = in lock, false out lock
 };
 
 #endif
diff --git a/vdr.cc b/vdr.cc
index 1c0ee71406e4d98ac8eeb5a120978ffee4a376aa..307f7c35f792114dd6736b9fc5956fe16d94d4a6 100644 (file)
--- a/vdr.cc
+++ b/vdr.cc
@@ -48,6 +48,8 @@ VDR::VDR()
   packetPos = 0;
   packet = NULL;
   connected = false;
+  maxChannelNumber = 0;
+  channelNumberWidth = 1;
 }
 
 VDR::~VDR()
@@ -154,6 +156,9 @@ void VDR::setServerIP(char* newIP)
 
 int VDR::connect()
 {
+  maxChannelNumber = 0;
+  channelNumberWidth = 1;
+
   if (tcp) delete tcp;
   tcp = new TCP();
   if (tcp->connectTo(serverIP, 3024))
@@ -507,6 +512,7 @@ ChannelList* VDR::getChannelsList(ULONG type)
     {
       chanList->push_back(chan);
       Log::getInstance()->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
+      if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
     }
     else
     {
@@ -517,6 +523,19 @@ ChannelList* VDR::getChannelsList(ULONG type)
   freePacket();
   MUTEX_UNLOCK(&mutex);
 
+  if (maxChannelNumber > 99999)
+    channelNumberWidth = 6;
+  else if (maxChannelNumber > 9999)
+    channelNumberWidth = 5;
+  else if (maxChannelNumber > 999)
+    channelNumberWidth = 4;
+  else if (maxChannelNumber > 99)
+    channelNumberWidth = 3;
+  else if (maxChannelNumber > 9)
+    channelNumberWidth = 2;
+  else
+    channelNumberWidth = 1;
+
   return chanList;
 }
 
diff --git a/vdr.h b/vdr.h
index a35b3a81fa90a261fd770cfb430d3558e9f75323..2cb41e72a9ac63a3f017d80d2206de4f93d4530f 100644 (file)
--- a/vdr.h
+++ b/vdr.h
@@ -91,6 +91,7 @@ class VDR
     int connect();
     void disconnect();
     bool isConnected() { return connected; }
+    ULONG getChannelNumberWidth() { return channelNumberWidth; }
 
     void setReceiveWindow(size_t size);
 
@@ -161,6 +162,10 @@ class VDR
     int port;
     char serverIP[16];
     bool connected;
+
+    ULONG maxChannelNumber;
+    ULONG channelNumberWidth;
+
 #ifndef WIN32
     pthread_mutex_t mutex;
 #else
index ab790cd1ef621283378ed5869a9221f01210aba6..6f1f835803e0fda3037a055cdd52c3b07b9956fb 100644 (file)
@@ -92,8 +92,10 @@ void VLiveBanner::setChannel(Channel* tChannel)
   currentChannel = tChannel;
   // get the data
 
+  int numberWidth = (int)VDR::getInstance()->getChannelNumberWidth();
+
   char ttitleText[100];
-  SNPRINTF(ttitleText, 99, "%03lu - %s", currentChannel->number, currentChannel->name);
+  SNPRINTF(ttitleText, 99, "%0*lu - %s", numberWidth, currentChannel->number, currentChannel->name);
 
   setTitleText(ttitleText);
   eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number);
index 32611152c0dd3d0ffe787b9a403817140d926781..aff2612ac3df2f6e9c4ad22109cd9132f8232dbd 100644 (file)
@@ -171,10 +171,13 @@ int VVideoLive::handleCommand(int command)
     case Remote::EIGHT:
     case Remote::NINE:
     {
-      VChannelSelect* v = new VChannelSelect(this, command);
+      VChannelSelect* v = new VChannelSelect(this);
       v->draw();
       viewman->add(v);
       viewman->updateView(v);
+
+      v->handleCommand(command);
+
       return 2;
     }
 #ifdef DEV