[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-multimedia
Subject:    Juk power inhibition
From:       James Daniel Smith <smithjd15 () gmail ! com>
Date:       2013-05-29 2:01:11
Message-ID: 2082288.UiMXk8lv4T () linux-ws1 ! site
[Download RAW message or body]

Sorry for the resend, a screenshot attachment got scrubbed.

After fixing the emit issue, I did a bit more work to polish the supress 
feature, including a config entry and a toolbar button etc. etc.

Attached is what I came up with for a revised toolbar for playback, 
including the supress button taking the place of a record button for a 
cassette deck. Record usually took play also to actually record, so I can 
see how that may have been arrived at. This button features the 
hibernate-suspend generic power management icon, and it hugs the 
volume slider.

I think the sunken part of the hibernate icon should look alright 
alongside the automatic graying playback state changer icons, though 
I don't know if this is a HIG concern or not. I also reversed the previous 
and next button icons to match a rather dated cassette deck that 
didn't have play-pause as its only method of playing back cassette 
tapes; the unit with simply play obviously had a record ability. For 
applications with only notably play-pause on one button perhaps  a 
consensus can be reached as far as purposefully leaving the buttons 
for previous / next doing just that, without any order reversal.

The model in question's (a tape deck on a combination CD / Tape 
player) controls were duplicated, including which order and purpose. 
Note the CD player has proper forward - back buttons, while the tape 
deck doesn't. For another model, a play-pause(cd player only), the 
controls match the old layout. 

Juk's separate play-pause just smack of a tape-deck. 

For the settings menu, there is also an option to allow to toggle the 
suspend mode.

Thanks!
James
["juksolidv7.diff" (juksolidv7.diff)]

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a3af05d..25fe108 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -142,7 +142,7 @@ if(NOT MSVC)
     set( LIBMATH m )
 endif(NOT MSVC)
 
-target_link_libraries(juk ${LIBMATH} ${KDE4_KHTML_LIBS} ${TAGLIB_LIBRARIES} ${KDE4_KDE3SUPPORT_LIBS} \
${KDE4_PHONON_LIBS}) +target_link_libraries(juk ${LIBMATH} ${KDE4_KHTML_LIBS} ${TAGLIB_LIBRARIES} \
${KDE4_KDE3SUPPORT_LIBS} ${KDE4_PHONON_LIBS} ${KDE4_SOLID_LIBS})  if(TUNEPIMP_FOUND)
 	target_link_libraries(juk ${TUNEPIMP_LIBRARIES})
 endif(TUNEPIMP_FOUND)
diff --git a/juk.cpp b/juk.cpp
index aa0f766..9b7627e 100644
--- a/juk.cpp
+++ b/juk.cpp
@@ -248,13 +248,13 @@ void JuK::setupActions()
     act->setText(i18n("&Stop"));
     act->setIcon(KIcon( QLatin1String( "media-playback-stop" )));
 
-    act = new KToolBarPopupAction(KIcon( QLatin1String( "media-skip-backward") ), i18nc("previous \
track", "Previous" ), collection); +    act = new KToolBarPopupAction(KIcon( QLatin1String( \
"media-skip-forward") ), i18nc("previous track", "Previous" ), collection);  \
collection->addAction("back", act);  connect(act, SIGNAL(triggered(bool)), m_player, SLOT(back()));
 
     act = collection->addAction("forward", m_player, SLOT(forward()));
     act->setText(i18nc("next track", "&Next"));
-    act->setIcon(KIcon( QLatin1String( "media-skip-forward" )));
+    act->setIcon(KIcon( QLatin1String( "media-skip-backward" )));
 
     act = collection->addAction("loopPlaylist");
     act->setText(i18n("&Loop Playlist"));
@@ -303,6 +303,11 @@ void JuK::setupActions()
     m_toggleSystemTrayAction->setText(i18n("&Dock in System Tray"));
     connect(m_toggleSystemTrayAction, SIGNAL(triggered(bool)), SLOT(slotToggleSystemTray(bool)));
 
+    m_togglePreventSleepWhilePlayingAction = collection->add<KToggleAction>("preventSleep");
+    m_togglePreventSleepWhilePlayingAction->setText(i18n("Enable Suspend &Inhibition"));
+    m_togglePreventSleepWhilePlayingAction->setIcon(KIcon( QLatin1String( "system-suspend-hibernate" \
))); +    connect(m_togglePreventSleepWhilePlayingAction, SIGNAL(triggered(bool)), m_player, \
SLOT(slotPreventSleepWhilePlaying(bool))); +
     m_toggleDockOnCloseAction = collection->add<KToggleAction>("dockOnClose");
     m_toggleDockOnCloseAction->setText(i18n("&Stay in System Tray on Close"));
 
@@ -454,6 +459,9 @@ void JuK::readConfig()
     bool dockOnClose = settingsConfig.readEntry("DockOnClose", true);
     m_toggleDockOnCloseAction->setChecked(dockOnClose);
 
+    bool preventSleep = settingsConfig.readEntry("PreventSleepWhilePlaying", false);
+    m_togglePreventSleepWhilePlayingAction->setChecked(preventSleep);
+
     bool showPopups = settingsConfig.readEntry("TrackPopup", false);
     m_togglePopupsAction->setChecked(showPopups);
 
@@ -493,6 +501,7 @@ void JuK::saveConfig()
     settingsConfig.writeEntry("ShowSplashScreen", m_toggleSplashAction->isChecked());
     settingsConfig.writeEntry("StartDocked", m_startDocked);
     settingsConfig.writeEntry("DockInSystemTray", m_toggleSystemTrayAction->isChecked());
+    settingsConfig.writeEntry("PreventSleepWhilePlaying", \
                m_togglePreventSleepWhilePlayingAction->isChecked());
     settingsConfig.writeEntry("DockOnClose", m_toggleDockOnCloseAction->isChecked());
     settingsConfig.writeEntry("TrackPopup", m_togglePopupsAction->isChecked());
 
diff --git a/juk.h b/juk.h
index 40c6140..26e0234 100644
--- a/juk.h
+++ b/juk.h
@@ -86,6 +86,7 @@ private:
 
     KToggleAction *m_randomPlayAction;
     KToggleAction *m_toggleSystemTrayAction;
+    KToggleAction *m_togglePreventSleepWhilePlayingAction;
     KToggleAction *m_toggleDockOnCloseAction;
     KToggleAction *m_togglePopupsAction;
     KToggleAction *m_toggleSplashAction;
diff --git a/jukui-rtl.rc b/jukui-rtl.rc
index 77c3b89..4af4880 100644
--- a/jukui-rtl.rc
+++ b/jukui-rtl.rc
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui>
-<kpartgui name="juk" version="12">
+<kpartgui name="juk" version="13">
 <MenuBar>
 	<Menu name="file" noMerge="1"><text>&amp;File</text>
 		<Action name="file_new"/>
@@ -69,6 +69,7 @@
 		<Action name="showSplashScreen" append="show_merge"/>
 		<Action name="toggleSystemTray" append="show_merge"/>
 		<Action name="dockOnClose" append="show_merge"/>
+                <Action name="preventSleep" append="show_merge"/>
 		<Action name="togglePopups" append="show_merge"/>
 		<!-- <Action name="saveUpcomingTracks" append="show_merge"/> -->
 		<Action name="tagGuesserConfig" append="save_merge"/>
@@ -97,17 +98,19 @@
 </ToolBar>
 
 <ToolBar name="playToolBar" noMerge="1"><text>Play Toolbar</text>
-
         <Action name="volumeAction"/>
 	<Action name="trackPositionAction"/>
-	<Action name="forward"/>
+	<Action name="preventSleep"/>
+	<Action name="play"/>
+	
+	<Separator lineSeparator="false"/>
+	
 	<Action name="back"/>
-	<Separator lineSeparator="false"/>	
-
-
+	<Action name="forward"/>
+	
+	<Separator lineSeparator="false"/>
+	
 	<Action name="stop"/>
 	<Action name="pause"/>
-	<Action name="play"/>
-
 </ToolBar>
 </kpartgui>
diff --git a/jukui.rc b/jukui.rc
index 4a14d45..82a7d5e 100644
--- a/jukui.rc
+++ b/jukui.rc
@@ -1,7 +1,7 @@
 <!-- PLEASE UPDATE jukui-rtl.rc WHEN UPDATING THIS FILE -->
 
 <!DOCTYPE kpartgui>
-<kpartgui name="juk" version="12">
+<kpartgui name="juk" version="13">
 <MenuBar>
 	<Menu name="file" noMerge="1"><text>&amp;File</text>
 		<Action name="file_new"/>
@@ -71,6 +71,7 @@
 		<Action name="showSplashScreen" append="show_merge"/>
 		<Action name="toggleSystemTray" append="show_merge"/>
 		<Action name="dockOnClose" append="show_merge"/>
+                <Action name="preventSleep" append="show_merge"/>
 		<Action name="togglePopups" append="show_merge"/>
 		<!-- <Action name="saveUpcomingTracks" append="show_merge"/> -->
 		<Action name="tagGuesserConfig" append="save_merge"/>
@@ -99,14 +100,18 @@
 </ToolBar>
 
 <ToolBar name="playToolBar" noMerge="1"><text>Play Toolbar</text>
-	<Action name="play"/>
 	<Action name="pause"/>
 	<Action name="stop"/>
-
+	
 	<Separator lineSeparator="false"/>	
 
-	<Action name="back"/>
 	<Action name="forward"/>
+	<Action name="back"/>
+	
+	<Separator lineSeparator="false"/>
+	
+	<Action name="play"/>
+	<Action name="preventSleep"/>
 	<Action name="trackPositionAction"/>
 	<Action name="volumeAction"/>
 </ToolBar>
diff --git a/main.cpp b/main.cpp
index a9f02e9..eaa792d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -45,6 +45,7 @@ static const char laurent[]     = I18N_NOOP("Porting to KDE 4 when no one else w
 static const char giorgos[]     = I18N_NOOP("Badly-needed tag editor bugfixes.");
 static const char sandsmark[]   = I18N_NOOP("Last.fm scrobbling support, lyrics, prepping for KDE \
Frameworks.");  static const char sho[]         = I18N_NOOP("MPRIS2 Interface implementation.");
+static const char james[]       = I18N_NOOP("Solid/KDE power suppression implementation.");
 
 int main(int argc, char *argv[])
 {
@@ -74,6 +75,7 @@ int main(int argc, char *argv[])
     aboutData.addCredit(ki18n("Georg Grabler"), ki18n(georg), "georg@grabler.net");
     aboutData.addCredit(ki18n("Martin Sandsmark"), ki18n(sandsmark), "martin.sandsmark@kde.org");
     aboutData.addCredit(ki18n("Eike Hein"), ki18n(sho), "hein@kde.org");
+    aboutData.addCredit(ki18n("James Smith"), ki18n(james), "smithjd15@gmail.com");
 
     KCmdLineArgs::init(argc, argv, &aboutData);
 
diff --git a/playermanager.cpp b/playermanager.cpp
index abb29c4..29200a6 100644
--- a/playermanager.cpp
+++ b/playermanager.cpp
@@ -32,6 +32,7 @@
 #include <Phonon/AudioOutput>
 #include <Phonon/MediaObject>
 #include <Phonon/VolumeFaderEffect>
+#include <Solid/PowerManagement>
 
 #include <QPixmap>
 #include <QTimer>
@@ -63,7 +64,8 @@ PlayerManager::PlayerManager() :
     m_statusLabel(0),
     m_setup(false),
     m_crossfadeTracks(true),
-    m_curOutputPath(0)
+    m_curOutputPath(0),
+    m_sleepInhibitCookie(-1)
 {
 // This class is the first thing constructed during program startup, and
 // therefore has no access to the widgets needed by the setup() method.
@@ -79,7 +81,7 @@ PlayerManager::PlayerManager() :
 
 PlayerManager::~PlayerManager()
 {
-
+    m_sleepInhibitCookie = -1;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -538,6 +540,11 @@ void PlayerManager::slotStateChanged(Phonon::State newstate, Phonon::State oldst
 
         JuK::JuKInstance()->setWindowTitle(i18n("JuK"));
         
+        // Avert Doomsday only if other state appendulates that suppression is already 
+        // well-enabled. Disables suppression when Phonon state is not playing and also 
+        // while inhibition is also enabled.
+        if(action<KToggleAction>("preventSleep")->isChecked())
+            emit slotPowerUninhibit();
         emit signalStop();
     }
     else if(newstate == Phonon::PlayingState) {
@@ -554,9 +561,15 @@ void PlayerManager::slotStateChanged(Phonon::State newstate, Phonon::State oldst
             "%1 - %2 :: JuK", 
             m_file.tag()->artist(), 
             m_file.tag()->title()));
-        
+        // Only invade other states if sleep inhibition is enabled.
+        if(action<KToggleAction>("preventSleep")->isChecked())
+            emit slotPreventSleepWhilePlaying(true);
         emit signalPlay();
     }
+    else if(newstate == Phonon::PausedState) {
+        if(action<KToggleAction>("preventSleep")->isChecked())
+            emit slotPowerUninhibit();
+    }
 }
 
 void PlayerManager::slotSeekableChanged(bool isSeekable)
@@ -729,6 +742,20 @@ void PlayerManager::setRandomPlayMode(const QString &randomMode)
         action<KToggleAction>("disableRandomPlay")->setChecked(true);
 }
 
+void PlayerManager::slotPreventSleepWhilePlaying(bool enabled)
+{
+    if (enabled && (m_sleepInhibitCookie == -1 || m_sleepInhibitCookie == 0) && playing())
+        m_sleepInhibitCookie = Solid::PowerManagement::beginSuppressingSleep(i18n("Playback sleep \
inhibit")); +    else if (!enabled && playing())
+        emit slotPowerUninhibit();
+}
+void PlayerManager::slotPowerUninhibit()
+{
+    if (m_sleepInhibitCookie != -1)
+        emit Solid::PowerManagement::stopSuppressingSleep(m_sleepInhibitCookie);
+        m_sleepInhibitCookie = 0;
+}
+
 #include "playermanager.moc"
 
 // vim: set et sw=4 tw=0 sta:
diff --git a/playermanager.h b/playermanager.h
index c16ab22..294fce7 100644
--- a/playermanager.h
+++ b/playermanager.h
@@ -138,6 +138,9 @@ private slots:
     void slotSeekableChanged(bool);
     void slotMutedChanged(bool);
     void slotVolumeChanged(qreal);
+    void slotPreventSleepWhilePlaying(bool enabled);
+    void slotPowerUninhibit();
+
 
 private:
     FileHandle m_file;
@@ -151,6 +154,7 @@ private:
     static const int m_pollInterval = 800;
 
     int m_curOutputPath; ///< Either 0 or 1 depending on which output path is in use.
+    int m_sleepInhibitCookie;
     Phonon::AudioOutput *m_output[2];
     Phonon::Path m_audioPath[2];
     Phonon::MediaObject *m_media[2];



_______________________________________________
kde-multimedia mailing list
kde-multimedia@kde.org
https://mail.kde.org/mailman/listinfo/kde-multimedia


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic