[Kwintv] Patch to implement a sleep-timer TV function

Morten Brix Pedersen kwintv@mail.kde.org
Wed, 16 Oct 2002 22:57:20 +0200


--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

I don't know how other people use kwintv, but I prefer to watch TV from
my bed with my remote control.

I also like to fall asleep with the TV on, but I was missing the normal
TV sleep-function where the TV turns off after X minutes.

So this patch is a shot at implementing it. It's probably possible to do
better, but I'm not that acquainted with the qtvision sources yet.

The logic is as follows:

 * When the user presses T or a button on the remote control, the
   sleep-timeout value gets changed. It starts at 15 minutes, goes on to 30,
   60 and finally 120 minutes. When the same button is pressed while
   120-minutes is set, the sleeper gets disabled.


I need help with implementing the last function though:
QtVision::slotSleepTimerTimeout() which is supposed to close the
application. But I'm not sure how to do it correctly..

If this patch is going to be applied to CVS, you might want to change
some names in the source. I'm not sure whether "Sleep Timer" is the best
way to describe the functionality.

Thanks in advance.

  - Morten.


--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kwintv_sleeptimer.diff"

? changes.dif
? changes.diff
? qtvision/.lirc.cpp.swp
? qtvision/.lirc.h.swp
? qtvision/.qtvision.cpp.swp
? qtvision/.qtvision.h.swp
? qtvision/.qtvisioniface.h.swp
? qtvision/.qtvisionviewiface.h.swp
? qtvision/.qtvisionwidget.cpp.swp
? qtvision/.qtvisionwidget.h.swp
? qtvision/clients/.mainwindow.cpp.swp
? qtvision/clients/.mainwindow.h.swp
? qtvision/clients/.q.swp
? qtvision/clients/.qtvisionactions.cpp.swp
? qtvision/clients/.qtvisionactions.h.swp
? qtvision/plugins/mixer/oss/.qtvision_oss.cpp.swp
? qtvision/teletext/Makefile
Index: qtvision/qtvision.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/qtvision.cpp,v
retrieving revision 1.101
diff -u -r1.101 qtvision.cpp
--- qtvision/qtvision.cpp	16 Oct 2002 05:21:01 -0000	1.101
+++ qtvision/qtvision.cpp	16 Oct 2002 20:59:30 -0000
@@ -100,12 +100,16 @@
     
     // Restore the volume settings...
     _muted = _cfg->volumeMuted;    
+    _sleepdelay = 0;
     ChannelVolState.left = _cfg->volumeLeft;
     ChannelVolState.right = _cfg->volumeRight;    
 
     _keypresstimer = new QTimer(parent);
     connect(_keypresstimer, SIGNAL(timeout()), this, SLOT(slotKeyPressTimeout()));
 
+    _sleeptimer = new QTimer(parent);
+    connect(_sleeptimer, SIGNAL(timeout()), this, SLOT(slotSleepTimerTimeout()));
+
     // Load the other misc plugins
     MiscManager::self();
 
@@ -650,6 +654,42 @@
     emit volumeMuted (_muted);
 }
 
+void QtVision::sleepTimer()
+{
+    if (_sleeptimer->isActive())
+        _sleeptimer->stop();
+
+    kdDebug() << "sleepTimer() called.." << endl;
+
+    if (_sleepdelay == 0) {
+        // Change to 15 minutes.
+        _sleepdelay = 900000;
+
+    } else if (_sleepdelay == 900000) {
+        // Change to 30 minutes.
+        _sleepdelay = 1800000;
+
+    } else if (_sleepdelay == 1800000) {
+        // Change to 60 minutes.
+        _sleepdelay = 3600000;
+
+    } else if (_sleepdelay == 3600000) {
+        // Change to 120 minutes.
+        _sleepdelay = 7200000;
+
+    } else {
+        // Remove sleep-delay
+        _sleepdelay = 0;
+    }
+
+    if (_sleepdelay)
+          _sleeptimer->start(_sleepdelay, true);  // start the count-down timer
+
+    // Display to the screen, how many minutes there are to the TV turns
+    // off.
+    emit sleepTimerDelay(QString::number(_sleepdelay / 1000 / 60));
+}
+
 void QtVision::setMuteVolume (bool mute)
 {
     if ( _am ) {
@@ -710,6 +750,7 @@
     connect(this, SIGNAL(volumeChanged(int,int)), _osd, SLOT(displayVolume(int,int)));
     connect(this, SIGNAL(volumeMuted(bool)), _osd, SLOT(displayMuted(bool)));
     connect(this, SIGNAL(channelText(const QString &)), _osd, SLOT(displayCC(const QString &)));
+    connect(this, SIGNAL(sleepTimerDelay(const QString &)), _osd, SLOT(displayCC(const QString &)));
 
     // Connect the _viewmanager's signals to the slots to propagate configuration _changes
     connect(_viewmng, SIGNAL(setFixedAspectRatio(bool, int)), _view,
@@ -927,6 +968,11 @@
     } // switch
 }// processNumberKeyEvent
 
+
+void QtVision::slotSleepTimerTimeout()
+{
+    kdDebug() << "QtVision: I was supposed to quit now, by the sleep timer." << endl;
+}
 
 void QtVision::slotKeyPressTimeout()
 {
Index: qtvision/qtvision.h
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/qtvision.h,v
retrieving revision 1.52
diff -u -r1.52 qtvision.h
--- qtvision/qtvision.h	16 Oct 2002 05:21:01 -0000	1.52
+++ qtvision/qtvision.h	16 Oct 2002 20:59:31 -0000
@@ -204,6 +204,11 @@
     virtual void volumeDown();
 
     /**
+     * Activates/deactivates sleep timer.
+     */
+    virtual void sleepTimer();
+
+    /**
      * Sets the volume
      */
     virtual void setVolume(int left, int right);
@@ -318,6 +323,11 @@
      */
     void channelText(const QString &);
 
+    /**
+     * Emitted when the "time to sleep before turning off" has been changed.
+     */
+    void sleepTimerDelay(const QString &);
+
 protected:
     void timerEvent (QTimerEvent *ev);
     
@@ -330,6 +340,7 @@
     void setMuteVolume (bool);
 
     void slotKeyPressTimeout();
+    void slotSleepTimerTimeout();
 
 private:
     ChannelStore *_cs;
@@ -345,12 +356,15 @@
     QPixmap grabPix;
     
     QTimer *_keypresstimer;
+    QTimer *_sleeptimer;
     QString _number;
     
     int _prevChannel;
     
     bool _muted;    // We have to keep track since some devices are broken    
     bool _quitting;
+
+    int _sleepdelay;
     
     struct { 
         int left; // Left volume
Index: qtvision/clients/mainwindow.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/clients/mainwindow.cpp,v
retrieving revision 1.48
diff -u -r1.48 mainwindow.cpp
--- qtvision/clients/mainwindow.cpp	4 Oct 2002 23:53:35 -0000	1.48
+++ qtvision/clients/mainwindow.cpp	16 Oct 2002 20:59:31 -0000
@@ -250,6 +250,7 @@
     (*lircKeyMap)["MUTE"] = "volume_mute";
     (*lircKeyMap)["QUIT"] = "file_quit";
     (*lircKeyMap)["POWER"] = "file_quit";
+    (*lircKeyMap)["MINIMIZE"] = "sleep_timer";
     //(*lircKeyMap)["FULL_SCREEN"] = "next_view_mode";
     //(*lircKeyMap)["FULLSCREEN"] = "next_view_mode";
     (*lircKeyMap)["FULL_SCREEN"] = "toggle_fullscreen";
Index: qtvision/clients/qtvisionactions.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/clients/qtvisionactions.cpp,v
retrieving revision 1.31
diff -u -r1.31 qtvisionactions.cpp
--- qtvision/clients/qtvisionactions.cpp	29 Sep 2002 06:09:11 -0000	1.31
+++ qtvision/clients/qtvisionactions.cpp	16 Oct 2002 20:59:32 -0000
@@ -88,6 +88,10 @@
                                  qtv, SLOT( volumeMute() ), acts, 
                                  "volume_mute" );
 
+    sleepTime = new KToggleAction( i18n("Sleep Timer"), "ktv_sleeptimer", Key_T,
+                                 qtv, SLOT( sleepTimer() ), acts, 
+                                 "sleep_timer" );
+
     volUp = new KAction( i18n("Volume Up"), "ktv_volup", Key_Right,
                          qtv, SLOT( volumeUp() ), acts, "volume_up" );
 
Index: qtvision/clients/qtvisionactions.h
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/clients/qtvisionactions.h,v
retrieving revision 1.19
diff -u -r1.19 qtvisionactions.h
--- qtvision/clients/qtvisionactions.h	29 Sep 2002 06:09:11 -0000	1.19
+++ qtvision/clients/qtvisionactions.h	16 Oct 2002 20:59:32 -0000
@@ -70,6 +70,7 @@
 
     SliderAction *volumeSlider() const { return volSlider; }
     KAction *volumeMute() const { return volMute; }
+    KAction *sleepTimer() const { return sleepTime; }
     KAction *volumeUp() const { return volUp; }
     KAction *volumeDown() const { return volDown; }
 
@@ -103,6 +104,7 @@
 
     SliderAction *volSlider;
     KToggleAction *volMute;
+    KToggleAction *sleepTime;
     KAction *volUp;
     KAction *volDown;
     KAction *prevChannel;

--wRRV7LY7NUeQGEoC--