1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 21:57:41 +02:00

Merge pull request #133 from TheOneRing/buttonfix2

fix for windows explorer.exe crash
This commit is contained in:
Christian Muehlhaeuser
2012-12-12 03:53:17 -08:00
2 changed files with 43 additions and 45 deletions

View File

@@ -446,30 +446,22 @@ TomahawkWindow::setupWindowsButtons()
const GUID IID_ITaskbarList3 = { 0xea1afb91,0x9e28,0x4b86, { 0x90,0xe9,0x9e,0x9f,0x8a,0x5e,0xef,0xaf } }; const GUID IID_ITaskbarList3 = { 0xea1afb91,0x9e28,0x4b86, { 0x90,0xe9,0x9e,0x9f,0x8a,0x5e,0xef,0xaf } };
HRESULT hr = S_OK; HRESULT hr = S_OK;
QPixmap play( RESPATH "images/play-rest.png" );
QPixmap back( RESPATH "images/back-rest.png" );
QPixmap love( RESPATH "images/not-loved.png" );
QTransform transform;
transform.rotate( 180 );
QPixmap next( back.transformed( transform ) );
THUMBBUTTONMASK dwMask = THUMBBUTTONMASK( THB_ICON | THB_TOOLTIP | THB_FLAGS ); THUMBBUTTONMASK dwMask = THUMBBUTTONMASK( THB_ICON | THB_TOOLTIP | THB_FLAGS );
m_thumbButtons[TP_PREVIOUS].dwMask = dwMask; m_thumbButtons[TP_PREVIOUS].dwMask = dwMask;
m_thumbButtons[TP_PREVIOUS].iId = TP_PREVIOUS; m_thumbButtons[TP_PREVIOUS].iId = TP_PREVIOUS;
m_thumbButtons[TP_PREVIOUS].hIcon = back.toWinHICON(); m_thumbButtons[TP_PREVIOUS].hIcon = thumbIcon(TomahawkUtils::PrevButton);
m_thumbButtons[TP_PREVIOUS].dwFlags = THBF_ENABLED; m_thumbButtons[TP_PREVIOUS].dwFlags = THBF_ENABLED;
m_thumbButtons[TP_PREVIOUS].szTip[ tr( "Back" ).toWCharArray( m_thumbButtons[TP_PREVIOUS].szTip ) ] = 0; m_thumbButtons[TP_PREVIOUS].szTip[ tr( "Back" ).toWCharArray( m_thumbButtons[TP_PREVIOUS].szTip ) ] = 0;
m_thumbButtons[TP_PLAY_PAUSE].dwMask = dwMask; m_thumbButtons[TP_PLAY_PAUSE].dwMask = dwMask;
m_thumbButtons[TP_PLAY_PAUSE].iId = TP_PLAY_PAUSE; m_thumbButtons[TP_PLAY_PAUSE].iId = TP_PLAY_PAUSE;
m_thumbButtons[TP_PLAY_PAUSE].hIcon = play.toWinHICON(); m_thumbButtons[TP_PLAY_PAUSE].hIcon = thumbIcon(TomahawkUtils::PlayButton);
m_thumbButtons[TP_PLAY_PAUSE].dwFlags = THBF_ENABLED; m_thumbButtons[TP_PLAY_PAUSE].dwFlags = THBF_ENABLED;
m_thumbButtons[TP_PLAY_PAUSE].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[TP_PLAY_PAUSE].szTip ) ] = 0; m_thumbButtons[TP_PLAY_PAUSE].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[TP_PLAY_PAUSE].szTip ) ] = 0;
m_thumbButtons[TP_NEXT].dwMask = dwMask; m_thumbButtons[TP_NEXT].dwMask = dwMask;
m_thumbButtons[TP_NEXT].iId = TP_NEXT; m_thumbButtons[TP_NEXT].iId = TP_NEXT;
m_thumbButtons[TP_NEXT].hIcon = next.toWinHICON(); m_thumbButtons[TP_NEXT].hIcon = thumbIcon(TomahawkUtils::NextButton);
m_thumbButtons[TP_NEXT].dwFlags = THBF_ENABLED; m_thumbButtons[TP_NEXT].dwFlags = THBF_ENABLED;
m_thumbButtons[TP_NEXT].szTip[ tr( "Next" ).toWCharArray( m_thumbButtons[TP_NEXT].szTip ) ] = 0; m_thumbButtons[TP_NEXT].szTip[ tr( "Next" ).toWCharArray( m_thumbButtons[TP_NEXT].szTip ) ] = 0;
@@ -481,7 +473,7 @@ TomahawkWindow::setupWindowsButtons()
m_thumbButtons[TP_LOVE].dwMask = dwMask; m_thumbButtons[TP_LOVE].dwMask = dwMask;
m_thumbButtons[TP_LOVE].iId = TP_LOVE; m_thumbButtons[TP_LOVE].iId = TP_LOVE;
m_thumbButtons[TP_LOVE].hIcon = love.toWinHICON(); m_thumbButtons[TP_LOVE].hIcon = thumbIcon(TomahawkUtils::NotLoved);
m_thumbButtons[TP_LOVE].dwFlags = THBF_DISABLED; m_thumbButtons[TP_LOVE].dwFlags = THBF_DISABLED;
m_thumbButtons[TP_LOVE].szTip[ tr( "Love" ).toWCharArray( m_thumbButtons[TP_LOVE].szTip ) ] = 0; m_thumbButtons[TP_LOVE].szTip[ tr( "Love" ).toWCharArray( m_thumbButtons[TP_LOVE].szTip ) ] = 0;
@@ -504,6 +496,18 @@ TomahawkWindow::setupWindowsButtons()
return false; return false;
#endif #endif
} }
HICON
TomahawkWindow::thumbIcon(TomahawkUtils::ImageType type)
{
static QMap<TomahawkUtils::ImageType,HICON> thumbIcons;
if(!thumbIcons.contains( type ) )
{
QPixmap pix ( TomahawkUtils::defaultPixmap(type , TomahawkUtils::Original, QSize( 20, 20 ) ) );
thumbIcons[type] = pix.toWinHICON();
}
return thumbIcons[type];
}
#endif #endif
@@ -723,46 +727,41 @@ TomahawkWindow::audioStateChanged( AudioState newState, AudioState oldState )
#ifdef HAVE_THUMBBUTTON #ifdef HAVE_THUMBBUTTON
if ( m_taskbarList == 0 ) if ( m_taskbarList == 0 )
return; return;
switch ( newState ) switch ( newState )
{ {
case AudioEngine::Playing: case AudioEngine::Playing:
{ {
QPixmap pause( RESPATH "images/pause-rest.png" ); m_thumbButtons[TP_PLAY_PAUSE].hIcon = thumbIcon(TomahawkUtils::PauseButton);
m_thumbButtons[TP_PLAY_PAUSE].hIcon = pause.toWinHICON(); m_thumbButtons[TP_PLAY_PAUSE].szTip[ tr( "Pause" ).toWCharArray( m_thumbButtons[TP_PLAY_PAUSE].szTip ) ] = 0;
m_thumbButtons[TP_PLAY_PAUSE].szTip[ tr( "Pause" ).toWCharArray( m_thumbButtons[TP_PLAY_PAUSE].szTip ) ] = 0; updateWindowsLoveButton();
updateWindowsLoveButton();
} }
break; break;
case AudioEngine::Paused: case AudioEngine::Paused:
{ {
QPixmap play( RESPATH "images/play-rest.png" ); m_thumbButtons[TP_PLAY_PAUSE].hIcon = thumbIcon(TomahawkUtils::PlayButton);
m_thumbButtons[TP_PLAY_PAUSE].hIcon = play.toWinHICON(); m_thumbButtons[TP_PLAY_PAUSE].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[TP_PLAY_PAUSE].szTip ) ] = 0;
m_thumbButtons[TP_PLAY_PAUSE].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[TP_PLAY_PAUSE].szTip ) ] = 0; }
}
break; break;
case AudioEngine::Stopped: case AudioEngine::Stopped:
{
if ( !AudioEngine::instance()->currentTrack().isNull() )
{ {
if ( !AudioEngine::instance()->currentTrack().isNull() ) disconnect( AudioEngine::instance()->currentTrack()->toQuery().data(), SIGNAL( socialActionsLoaded() ), this, SLOT( updateWindowsLoveButton() ) );
{
disconnect( AudioEngine::instance()->currentTrack()->toQuery().data(), SIGNAL( socialActionsLoaded() ), this, SLOT( updateWindowsLoveButton() ) );
}
QPixmap play( RESPATH "images/play-rest.png" );
m_thumbButtons[TP_PLAY_PAUSE].hIcon = play.toWinHICON();
m_thumbButtons[TP_PLAY_PAUSE].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[TP_PLAY_PAUSE].szTip ) ] = 0;
QPixmap not_loved( RESPATH "images/not-loved.png" );
m_thumbButtons[TP_LOVE].hIcon = not_loved.toWinHICON();
m_thumbButtons[TP_LOVE].dwFlags = THBF_DISABLED;
} }
m_thumbButtons[TP_PLAY_PAUSE].hIcon = thumbIcon(TomahawkUtils::PlayButton);
m_thumbButtons[TP_PLAY_PAUSE].szTip[ tr( "Play" ).toWCharArray( m_thumbButtons[TP_PLAY_PAUSE].szTip ) ] = 0;
m_thumbButtons[TP_LOVE].hIcon = thumbIcon(TomahawkUtils::NotLoved);
m_thumbButtons[TP_LOVE].dwFlags = THBF_DISABLED;
}
break; break;
default: default:
return; return;
} }
m_taskbarList->ThumbBarUpdateButtons( winId(), ARRAYSIZE( m_thumbButtons ), m_thumbButtons ); m_taskbarList->ThumbBarUpdateButtons( winId(), ARRAYSIZE( m_thumbButtons ), m_thumbButtons );
@@ -776,14 +775,12 @@ TomahawkWindow::updateWindowsLoveButton()
#ifdef HAVE_THUMBBUTTON #ifdef HAVE_THUMBBUTTON
if ( !AudioEngine::instance()->currentTrack().isNull() && AudioEngine::instance()->currentTrack()->toQuery()->loved() ) if ( !AudioEngine::instance()->currentTrack().isNull() && AudioEngine::instance()->currentTrack()->toQuery()->loved() )
{ {
QPixmap loved( RESPATH "images/loved.png" ); m_thumbButtons[TP_LOVE].hIcon = thumbIcon(TomahawkUtils::Loved);
m_thumbButtons[TP_LOVE].hIcon = loved.toWinHICON();
m_thumbButtons[TP_LOVE].szTip[ tr( "Unlove" ).toWCharArray( m_thumbButtons[TP_LOVE].szTip ) ] = 0; m_thumbButtons[TP_LOVE].szTip[ tr( "Unlove" ).toWCharArray( m_thumbButtons[TP_LOVE].szTip ) ] = 0;
} }
else else
{ {
QPixmap not_loved( RESPATH "images/not-loved.png" ); m_thumbButtons[TP_LOVE].hIcon = thumbIcon(TomahawkUtils::NotLoved);
m_thumbButtons[TP_LOVE].hIcon = not_loved.toWinHICON();
m_thumbButtons[TP_LOVE].szTip[ tr( "Love" ).toWCharArray( m_thumbButtons[TP_LOVE].szTip ) ] = 0; m_thumbButtons[TP_LOVE].szTip[ tr( "Love" ).toWCharArray( m_thumbButtons[TP_LOVE].szTip ) ] = 0;
} }

View File

@@ -167,6 +167,7 @@ private:
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
bool setupWindowsButtons(); bool setupWindowsButtons();
const unsigned int m_buttonCreatedID; const unsigned int m_buttonCreatedID;
HICON thumbIcon(TomahawkUtils::ImageType type);
#ifdef HAVE_THUMBBUTTON #ifdef HAVE_THUMBBUTTON
ITaskbarList3* m_taskbarList; ITaskbarList3* m_taskbarList;
THUMBBUTTON m_thumbButtons[5]; THUMBBUTTON m_thumbButtons[5];