mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-22 00:42:04 +02:00
improved support for thumbnail buttons
This commit is contained in:
parent
5e0390bd87
commit
0e36f77dd4
@ -73,7 +73,6 @@
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <qtsparkle/Updater>
|
||||
#include <shobjidl.h>
|
||||
#ifndef THBN_CLICKED
|
||||
#define THBN_CLICKED 0x1800
|
||||
#endif
|
||||
@ -89,6 +88,7 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
|
||||
: QMainWindow( parent )
|
||||
#ifdef Q_OS_WIN
|
||||
, m_buttonCreatedID( RegisterWindowMessage( L"TaskbarButtonCreated" ) )
|
||||
, m_taskbarList(0)
|
||||
#endif
|
||||
, ui( new Ui::TomahawkWindow )
|
||||
, m_searchWidget( 0 )
|
||||
@ -103,6 +103,9 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
|
||||
connect( vm, SIGNAL( hideQueueRequested() ), SLOT( hideQueue() ) );
|
||||
connect( APP, SIGNAL( tomahawkLoaded() ), vm, SLOT( setTomahawkLoaded() ) ); // Pass loaded signal into libtomahawk so components in there can connect to ViewManager
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
connect(AudioEngine::instance(),SIGNAL(stateChanged(AudioState,AudioState)),this,SLOT(audioStateChanged(AudioState,AudioState)));
|
||||
#endif
|
||||
ui->setupUi( this );
|
||||
|
||||
ui->menuApp->insertAction( ui->actionCreatePlaylist, ActionCollection::instance()->getAction( "togglePrivacy" ) );
|
||||
@ -337,7 +340,6 @@ TomahawkWindow::setupWindowsButtons()
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
QPixmap play( RESPATH "images/play-rest.png" );
|
||||
QPixmap pause( RESPATH "images/pause-rest.png" );
|
||||
QPixmap back( RESPATH "images/back-rest.png" );
|
||||
QPixmap love( RESPATH "images/not-loved.png" );
|
||||
|
||||
@ -345,43 +347,50 @@ TomahawkWindow::setupWindowsButtons()
|
||||
transform.rotate( 180 );
|
||||
QPixmap next( back.transformed( transform ) );
|
||||
|
||||
THUMBBUTTON thumbButtons[5];
|
||||
THUMBBUTTONMASK dwMask = THUMBBUTTONMASK( THB_ICON | THB_TOOLTIP | THB_FLAGS );
|
||||
m_thumbButtons[0].dwMask = dwMask;
|
||||
m_thumbButtons[0].iId = PREVIOUS;
|
||||
m_thumbButtons[0].hIcon = back.toWinHICON();
|
||||
m_thumbButtons[0].dwFlags = THBF_ENABLED;
|
||||
m_thumbButtons[0].szTip[ tr( "Back" ).toWCharArray( m_thumbButtons[0].szTip ) ] = 0;
|
||||
|
||||
THUMBBUTTONMASK dwMask = THUMBBUTTONMASK( THB_ICON | THB_TOOLTIP );
|
||||
thumbButtons[0].dwMask = dwMask;
|
||||
thumbButtons[0].iId = 1;
|
||||
thumbButtons[0].hIcon = back.toWinHICON();
|
||||
thumbButtons[0].szTip[ tr( "Back" ).toWCharArray( thumbButtons[0].szTip ) ] = 0;
|
||||
m_thumbButtons[1].dwMask = dwMask;
|
||||
m_thumbButtons[1].iId = PLAY_PAUSE;
|
||||
m_thumbButtons[1].hIcon = play.toWinHICON();
|
||||
m_thumbButtons[1].dwFlags = THBF_ENABLED;
|
||||
m_thumbButtons[1].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[1].szTip ) ] = 0;
|
||||
|
||||
thumbButtons[1].dwMask = dwMask;
|
||||
thumbButtons[1].iId = 2;
|
||||
thumbButtons[1].hIcon = pause.toWinHICON();
|
||||
thumbButtons[1].szTip[ tr( "Pause" ).toWCharArray( thumbButtons[1].szTip ) ] = 0;
|
||||
|
||||
thumbButtons[2].dwMask = dwMask;
|
||||
thumbButtons[2].iId = 3;
|
||||
thumbButtons[2].hIcon = play.toWinHICON();
|
||||
thumbButtons[2].szTip[ tr( "Play" ).toWCharArray( thumbButtons[2].szTip ) ] = 0;
|
||||
m_thumbButtons[2].dwMask = dwMask;
|
||||
m_thumbButtons[2].iId = NEXT;
|
||||
m_thumbButtons[2].hIcon = next.toWinHICON();
|
||||
m_thumbButtons[2].dwFlags = THBF_ENABLED;
|
||||
m_thumbButtons[2].szTip[ tr( "Next" ).toWCharArray( m_thumbButtons[2].szTip ) ] = 0;
|
||||
|
||||
thumbButtons[3].dwMask = dwMask;
|
||||
thumbButtons[3].iId = 4;
|
||||
thumbButtons[3].hIcon = next.toWinHICON();
|
||||
thumbButtons[3].szTip[ tr( "Next" ).toWCharArray( thumbButtons[3].szTip ) ] = 0;
|
||||
m_thumbButtons[3].dwMask = dwMask;
|
||||
m_thumbButtons[3].iId = -1;
|
||||
m_thumbButtons[3].hIcon = 0;
|
||||
m_thumbButtons[3].dwFlags = THBF_NOBACKGROUND | THBF_DISABLED;
|
||||
m_thumbButtons[3].szTip[0] = 0;
|
||||
|
||||
thumbButtons[4].dwMask = dwMask;
|
||||
thumbButtons[4].iId = 5;
|
||||
thumbButtons[4].hIcon = love.toWinHICON();
|
||||
thumbButtons[4].szTip[ tr( "Love" ).toWCharArray( thumbButtons[4].szTip ) ] = 0;
|
||||
m_thumbButtons[4].dwMask = dwMask;
|
||||
m_thumbButtons[4].iId = LOVE;
|
||||
m_thumbButtons[4].hIcon = love.toWinHICON();
|
||||
m_thumbButtons[4].dwFlags = THBF_DISABLED;
|
||||
m_thumbButtons[4].szTip[ tr( "Love" ).toWCharArray( m_thumbButtons[4].szTip ) ] = 0;
|
||||
|
||||
ITaskbarList3 *taskbarList;
|
||||
if ( S_OK == CoCreateInstance( CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (void **)&taskbarList ) )
|
||||
if ( S_OK == CoCreateInstance( CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (void **)&m_taskbarList ) )
|
||||
{
|
||||
taskbarList->HrInit();
|
||||
hr = m_taskbarList->HrInit();
|
||||
if ( SUCCEEDED( hr ) )
|
||||
{
|
||||
hr = taskbarList->ThumbBarAddButtons( winId(), ARRAYSIZE( thumbButtons ), thumbButtons );
|
||||
hr = m_taskbarList->ThumbBarAddButtons( winId(), ARRAYSIZE( m_thumbButtons ), m_thumbButtons );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_taskbarList->Release();
|
||||
m_taskbarList = 0;
|
||||
}
|
||||
taskbarList->Release();
|
||||
}
|
||||
|
||||
return SUCCEEDED( hr );
|
||||
@ -571,29 +580,39 @@ TomahawkWindow::winEvent( MSG* msg, long* result )
|
||||
case WM_COMMAND:
|
||||
if ( HIWORD( msg->wParam ) == THBN_CLICKED )
|
||||
{
|
||||
switch( LOWORD( msg->wParam ) )
|
||||
switch( TB_STATES(LOWORD( msg->wParam )) )
|
||||
{
|
||||
case 1:
|
||||
case PREVIOUS:
|
||||
tLog() << TB_PRESSED << "Previous";
|
||||
AudioEngine::instance()->previous();
|
||||
break;
|
||||
case 2:
|
||||
tLog() << TB_PRESSED << "Pause";
|
||||
AudioEngine::instance()->pause();
|
||||
case PLAY_PAUSE:
|
||||
tLog() << TB_PRESSED << "Play/Pause";
|
||||
AudioEngine::instance()->playPause();
|
||||
break;
|
||||
case 3:
|
||||
tLog() << TB_PRESSED << "Play";
|
||||
AudioEngine::instance()->play();
|
||||
break;
|
||||
case 4:
|
||||
case NEXT:
|
||||
tLog() << TB_PRESSED << "Next";
|
||||
AudioEngine::instance()->next();
|
||||
break;
|
||||
case 5:
|
||||
case LOVE:
|
||||
tLog() << TB_PRESSED << "Love";
|
||||
if ( !AudioEngine::instance()->currentTrack().isNull() )
|
||||
{
|
||||
AudioEngine::instance()->currentTrack()->toQuery()->setLoved( true );
|
||||
AudioEngine::instance()->currentTrack()->toQuery()->setLoved( !AudioEngine::instance()->currentTrack()->toQuery()->loved() );
|
||||
if ( AudioEngine::instance()->currentTrack()->toQuery()->loved())
|
||||
{
|
||||
QPixmap loved( RESPATH "images/loved.png" );
|
||||
m_thumbButtons[4].hIcon = loved.toWinHICON();
|
||||
m_thumbButtons[4].szTip[ tr( "Unlove" ).toWCharArray( m_thumbButtons[4].szTip ) ] = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QPixmap not_loved( RESPATH "images/not-loved.png" );
|
||||
m_thumbButtons[4].hIcon = not_loved.toWinHICON();
|
||||
m_thumbButtons[4].szTip[ tr( "Love" ).toWCharArray( m_thumbButtons[4].szTip ) ] = 0;
|
||||
}
|
||||
m_taskbarList->ThumbBarUpdateButtons( winId(), ARRAYSIZE( m_thumbButtons ), m_thumbButtons );
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -607,9 +626,62 @@ TomahawkWindow::winEvent( MSG* msg, long* result )
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TomahawkWindow::audioStateChanged( AudioState newState, AudioState oldState )
|
||||
{
|
||||
if(m_taskbarList == 0)
|
||||
return;
|
||||
switch(newState){
|
||||
case AudioEngine::Playing:
|
||||
{
|
||||
QPixmap pause( RESPATH "images/pause-rest.png" );
|
||||
m_thumbButtons[1].hIcon = pause.toWinHICON();
|
||||
m_thumbButtons[1].szTip[ tr( "Pause" ).toWCharArray( m_thumbButtons[1].szTip ) ] = 0;
|
||||
|
||||
if ( !AudioEngine::instance()->currentTrack().isNull() && AudioEngine::instance()->currentTrack()->toQuery()->loved())
|
||||
{
|
||||
QPixmap loved( RESPATH "images/loved.png" );
|
||||
m_thumbButtons[4].hIcon = loved.toWinHICON();
|
||||
m_thumbButtons[4].szTip[ tr( "Unlove" ).toWCharArray( m_thumbButtons[4].szTip ) ] = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QPixmap not_loved( RESPATH "images/not-loved.png" );
|
||||
m_thumbButtons[4].hIcon = not_loved.toWinHICON();
|
||||
m_thumbButtons[4].szTip[ tr( "Love" ).toWCharArray( m_thumbButtons[4].szTip ) ] = 0;
|
||||
}
|
||||
m_thumbButtons[4].dwFlags = THBF_ENABLED;
|
||||
}
|
||||
break;
|
||||
case AudioEngine::Paused:
|
||||
{
|
||||
QPixmap play( RESPATH "images/play-rest.png" );
|
||||
m_thumbButtons[1].hIcon = play.toWinHICON();
|
||||
m_thumbButtons[1].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[1].szTip ) ] = 0;
|
||||
}
|
||||
break;
|
||||
case AudioEngine::Stopped:
|
||||
{
|
||||
QPixmap play( RESPATH "images/play-rest.png" );
|
||||
m_thumbButtons[1].hIcon = play.toWinHICON();
|
||||
m_thumbButtons[1].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[1].szTip ) ] = 0;
|
||||
|
||||
QPixmap not_loved( RESPATH "images/not-loved.png" );
|
||||
m_thumbButtons[4].hIcon = not_loved.toWinHICON();
|
||||
m_thumbButtons[4].dwFlags = THBF_DISABLED;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
m_taskbarList->ThumbBarUpdateButtons( winId(), ARRAYSIZE( m_thumbButtons ), m_thumbButtons );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void
|
||||
TomahawkWindow::onHistoryBackAvailable( bool avail )
|
||||
{
|
||||
|
@ -31,6 +31,10 @@
|
||||
#include "audio/AudioEngine.h"
|
||||
#include "utils/XspfLoader.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <shobjidl.h>
|
||||
#endif
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
namespace Accounts
|
||||
@ -138,6 +142,10 @@ private slots:
|
||||
|
||||
void crashNow();
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
void audioStateChanged( AudioState newState, AudioState oldState );
|
||||
#endif
|
||||
|
||||
private:
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
@ -151,6 +159,15 @@ private:
|
||||
#ifdef Q_OS_WIN
|
||||
bool setupWindowsButtons();
|
||||
const unsigned int m_buttonCreatedID;
|
||||
ITaskbarList3 *m_taskbarList;
|
||||
THUMBBUTTON m_thumbButtons[5];
|
||||
enum TB_STATES{
|
||||
PREVIOUS,
|
||||
PLAY_PAUSE,
|
||||
NEXT,
|
||||
LOVE
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Ui::TomahawkWindow* ui;
|
||||
|
Loading…
x
Reference in New Issue
Block a user