From b9cd34df684943b137f7e6838a338738be8cf2a5 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 1 May 2007 21:36:24 +0000 Subject: [PATCH] Variable width channel numbers --- vchannellist.cc | 3 +- vchannelselect.cc | 200 ++++++++++++++++------------------------------ vchannelselect.h | 12 +-- vdr.cc | 19 +++++ vdr.h | 5 ++ vlivebanner.cc | 4 +- vvideolive.cc | 5 +- 7 files changed, 111 insertions(+), 137 deletions(-) diff --git a/vchannellist.cc b/vchannellist.cc index 54a2882..c6e4769 100644 --- a/vchannellist.cc +++ b/vchannellist.cc @@ -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: diff --git a/vchannelselect.cc b/vchannelselect.cc index ad1351c..b538de2 100644 --- a/vchannelselect.cc +++ b/vchannelselect.cc @@ -23,19 +23,19 @@ // 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); - } -} diff --git a/vchannelselect.h b/vchannelselect.h index 814da3f..9449e5f 100644 --- a/vchannelselect.h +++ b/vchannelselect.h @@ -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 1c0ee71..307f7c3 100644 --- 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 a35b3a8..2cb41e7 100644 --- 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 diff --git a/vlivebanner.cc b/vlivebanner.cc index ab790cd..6f1f835 100644 --- a/vlivebanner.cc +++ b/vlivebanner.cc @@ -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); diff --git a/vvideolive.cc b/vvideolive.cc index 3261115..aff2612 100644 --- a/vvideolive.cc +++ b/vvideolive.cc @@ -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 -- 2.39.5