// 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()
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)
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;
}
}
// 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);
- }
-}
packetPos = 0;
packet = NULL;
connected = false;
+ maxChannelNumber = 0;
+ channelNumberWidth = 1;
}
VDR::~VDR()
int VDR::connect()
{
+ maxChannelNumber = 0;
+ channelNumberWidth = 1;
+
if (tcp) delete tcp;
tcp = new TCP();
if (tcp->connectTo(serverIP, 3024))
{
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
{
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;
}