From c76c557ed1d5ed63d31e44b855dfabbcae2db1cb Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 22 Aug 2011 02:36:44 +0200 Subject: [PATCH] * Fixed tray-icon's play / pause states. --- src/tomahawktrayicon.cpp | 49 ++++++++++++++++++++++------------------ src/tomahawktrayicon.h | 9 ++++---- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/tomahawktrayicon.cpp b/src/tomahawktrayicon.cpp index 033ebbbbb..e7990921d 100644 --- a/src/tomahawktrayicon.cpp +++ b/src/tomahawktrayicon.cpp @@ -61,17 +61,17 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent ) m_quitAction = m_contextMenu->addAction( tr( "Quit" ) ); connect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), SLOT( setResult( Tomahawk::result_ptr ) ) ); + connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( enablePause() ) ); + connect( AudioEngine::instance(), SIGNAL( resumed() ), this, SLOT( enablePause() ) ); + connect( AudioEngine::instance(), SIGNAL( stopped() ), this, SLOT( enablePlay() ) ); + connect( AudioEngine::instance(), SIGNAL( paused() ), this, SLOT( enablePlay() ) ); + + connect( m_playPauseAction, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( playPause() ) ); + connect( m_stopAction, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( stop() ) ); + connect( m_prevAction, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( previous() ) ); + connect( m_nextAction, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( next() ) ); + connect( m_quitAction, SIGNAL( triggered() ), (QObject*)APP, SLOT( quit() ) ); - connect( m_playPauseAction, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( playPause() ) ); - connect( m_stopAction, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( stop() ) ); - connect( m_prevAction, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( previous() ) ); - connect( m_nextAction, SIGNAL( triggered() ), AudioEngine::instance(), SLOT( next() ) ); - connect( m_quitAction, SIGNAL( triggered() ), (QObject*)APP, SLOT( quit() ) ); - - connect( AudioEngine::instance(), SIGNAL( paused() ), this, SLOT( onPause() ) ); - connect( AudioEngine::instance(), SIGNAL( stopped()), this, SLOT( onPause() ) ); - connect( AudioEngine::instance(), SIGNAL( resumed()), this, SLOT( onResume() ) ); - connect( &m_animationTimer, SIGNAL( timeout() ), SLOT( onAnimationTimer() ) ); connect( this, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ), SLOT( onActivated( QSystemTrayIcon::ActivationReason ) ) ); @@ -84,6 +84,7 @@ TomahawkTrayIcon::~TomahawkTrayIcon() delete m_contextMenu; } + void TomahawkTrayIcon::setShowHideWindow( bool show ) { @@ -91,12 +92,16 @@ TomahawkTrayIcon::setShowHideWindow( bool show ) { m_showWindowAction->setText( tr( "Hide Tomahawk Window" ) ); m_showWindowAction->setData( show ); - } else { + } + else + { m_showWindowAction->setText( tr( "Show Tomahawk Window" ) ); } + m_showWindowAction->setData( show ); } + void TomahawkTrayIcon::showWindow() { @@ -106,12 +111,16 @@ TomahawkTrayIcon::showWindow() APP->mainWindow()->raise(); setShowHideWindow( true ); - } else { + } + else + { APP->mainWindow()->hide(); + setShowHideWindow( false ); } } + void TomahawkTrayIcon::setResult( const Tomahawk::result_ptr& result ) { @@ -151,14 +160,7 @@ TomahawkTrayIcon::refreshToolTip() void TomahawkTrayIcon::onAnimationTimer() { - /*if( m_animationPixmaps.isEmpty() ) - { - stopIpodScrobblingAnimation(); - Q_ASSERT( !"Animation should not be started without frames being loaded" ); - return; - } - - m_currentAnimationFrame++; +/* m_currentAnimationFrame++; if( m_currentAnimationFrame >= m_animationPixmaps.count() ) m_currentAnimationFrame = 0; @@ -194,18 +196,21 @@ TomahawkTrayIcon::onActivated( QSystemTrayIcon::ActivationReason reason ) } } + void -TomahawkTrayIcon::onPause() +TomahawkTrayIcon::enablePlay() { m_playPauseAction->setText( tr( "Play" ) ); } + void -TomahawkTrayIcon::onResume() +TomahawkTrayIcon::enablePause() { m_playPauseAction->setText( tr( "Pause" ) ); } + bool TomahawkTrayIcon::event( QEvent* e ) { diff --git a/src/tomahawktrayicon.h b/src/tomahawktrayicon.h index 548a8504c..3e0280d16 100644 --- a/src/tomahawktrayicon.h +++ b/src/tomahawktrayicon.h @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -41,10 +41,11 @@ public slots: private slots: void onAnimationTimer(); void onActivated( QSystemTrayIcon::ActivationReason reason ); - void onPause(); - void onResume(); void showWindow(); + void enablePlay(); + void enablePause(); + private: void refreshToolTip(); ~TomahawkTrayIcon(); @@ -54,7 +55,7 @@ private: QList m_animationPixmaps; int m_currentAnimationFrame; - + QMenu* m_contextMenu; QAction* m_playPauseAction; //QAction* m_pauseAction;