[Kwintv] Re: kdenonbeta/kwintv3/qtvision
Michael Kedl
kwintv@mail.kde.org
16 Oct 2002 08:55:48 -0400
I forgot about the case with total channels less than 10, but of course
you are right to extend the logic (I never have that few channels :-))
On Wed, 2002-10-16 at 08:38, Rizsanyi Zsolt wrote:
> On Wednesday 16 October 2002 06:05, George Staikos wrote:
> > On October 15, 2002 23:58, Dawit Alemayehu wrote:
> > > CVS commit by adawit:
> > >
> > > - Change the channel intelligently. Now the delayed change is activated
> > > iff the entered numbers are ambigous. It uses the highest configured
> > > channel to handle this as discussed.
>
> I think that the implementation has some inconsistencies/bugs.
> My main problems are:
> - you cant select a channel number less than 10 with one keypress even if you
> have only less 10 channels configured
> - you could not select channels less than 10 without delay with even a leading
> zero entered if the max channel is *10 bigger than the channel you want to
> enter
> - there is no way to select channels without delay, even if you enter leading
> zeros
> - it does not work with channels > 1000 :)
>
> Here is my implementation which should fix all those above issues. And the
> code is simpler too...
> Should I commit it, or somebody wants to veto me :)
>
> Basic description of usage:
> - you enter the number, and if by entering any more digits the number would be
> larger than the largest channel number, then the channel is changed without
> delay (else there is the usual delay)
> - if you enter leading zeroes then with every leading zero the max number to
> compare is divided by 10
>
> Here is how it works for the different max channel number:
> - max channel num < 20
> you enter the number and the channel is changed without delay
> there is no use to enter a leading zero (but you can)
> - max channel num < 200
> if you want to select channel > 20 you just enter the number
> if you want to select channel < 20, then you enter the number, and wait the
> delay OR you enter a leading zero and the channel is changed without delay
> - max channel num < 2000
> if you want to select channel > 200 you just enter the number
> if you want to select channel < 200 but > 20, then you enter the number, and
> wait the delay OR you enter a leading zero and the channel is changed without
> delay
> if you want to select channel < 20, then you enter the number, and wait the
> delay OR you enter TWO (2) leading zeros and the channel is changed without
> delay
>
>
> Huh. I took more to write this down than the code :)
> But I hope this will convince everybody :)
>
> Regards
> Zsolt
> ----
>
> Index: qtvision/qtvision.cpp
> ===================================================================
> RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/qtvision.cpp,v
> retrieving revision 1.101
> diff -u -p -r1.101 qtvision.cpp
> --- qtvision/qtvision.cpp 2002/10/16 05:21:01 1.101
> +++ qtvision/qtvision.cpp 2002/10/16 12:36:18
> @@ -1,4 +1,4 @@
> -/*
> +/* vim: sw=4 et
> *
> * Copyright (C) 2002 George Staikos <staikos@kde.org>
> *
> @@ -864,7 +864,7 @@ void QtVision::processNumberKeyEvent(int
> {
> if (_keypresstimer->isActive())
> _keypresstimer->stop();
> -
> +
> // key == -1 means ENTER was pressed. Simply force a
> // channel change and return...
> if (key == -1)
> @@ -872,68 +872,42 @@ void QtVision::processNumberKeyEvent(int
> slotKeyPressTimeout ();
> return;
> }
> -
> - switch (_number.length())
> - {
> - case 0:
> - {
> - _number = QString::number(key);
>
> - kdDebug() << "channelText(" << "--" << _number << ")" << endl;
> - emit channelText("--" + _number);
> -
> - _keypresstimer->start(2000, true); // start the count-down timer
> - break;
> - }
> - case 1:
> - {
> - Q_ASSERT (_cs == 0);
> -
> - // Get the highest channel number...
> - Channel * ch = _cs->channelAt (_cs->count()-1);
> -
> - Q_ASSERT (ch == 0);
> -
> - int chNumber = (_number.toInt()*100) + (key * 10);
> -
> - // If the numbers pressed so far equates to a value less than
> - // the highest channel number configured/detected, start a timer.
> - // Otherwise, simply tune to the channel.
> - if (chNumber < ch->number()) {
> - _number += QString::number(key);
> - kdDebug() << "channelText(" << "-" << _number << ")" << endl;
> - emit channelText("-" + _number);
> - _keypresstimer->start(2000, true); // start the count-down timer
> - } else {
> - _number += QString::number(key);
> - if (_number != "0") {
> - _keypresstimer->singleShot(0, this, SLOT(slotKeyPressTimeout()));
> - break;
> - } // if
> - } // else
> - break;
> - }
> - case 2:
> - {
> - _number = _number.append(QString::number(key));
> + Q_ASSERT (_cs);
>
> - kdDebug() << "channelText(" << _number << ")" << endl;
> - emit channelText(_number);
> + // Get the highest channel number...
> + Channel * ch = _cs->channelAt (_cs->count()-1);
> + Q_ASSERT (ch);
> + int maxChNum = ch->number();
> +
> + // For every '0' entered before the number lower the max channel by
> + // 10 times
> + for (int i = 0; i < _number.length() && _number[i] == '0'; i++)
> + maxChNum /= 10;
> +
> + _number += QString::number(key);
> +
> + // If by entering another digit you can get a number lesser than
> + // the highest channel number configured/detected, start a timer
> + // (wait for that next keypress).
> + // Otherwise, simply tune to the channel.
> + if (_number.toInt() * 10 < maxChNum) {
> + kdDebug() << "channelText(" << _number.rightJustify(3,'-') << ")" << endl;
> + emit channelText(_number.rightJustify(3,'-'));
> + _keypresstimer->start(2000, true); // start the count-down timer
> + } else {
> + if (_number != "0")
> _keypresstimer->singleShot(0, this, SLOT(slotKeyPressTimeout()));
> - break;
> - }
> - default:
> - break;
> - } // switch
> + } // else
> }// processNumberKeyEvent
>
>
> void QtVision::slotKeyPressTimeout()
> {
> - emit channelText(_number);
> -
> - kdDebug() << "QtVision: calling setChannel(" << _number << ")" << endl;
> - setChannel(_number.toInt());
> + if (_number != "0") {
> + kdDebug() << "QtVision: calling setChannel(" << _number << ")" << endl;
> + setChannel(_number.toInt());
> + }
>
> _number = "";
> return;