1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-19 15:37:01 +01:00

add Windows taskbar thumbbutton support

This commit is contained in:
Patrick von Reth 2012-07-06 11:04:48 +03:00
parent f6657845df
commit cefd96664b
3 changed files with 121 additions and 2 deletions

View File

@ -28,7 +28,7 @@ IF(CLucene_FIND_VERSION)
ELSEIF()
SET(CLUCENE_MIN_VERSION "0.9.23")
ENDIF(CLucene_FIND_VERSION)
message(STATUS ${PROJECT_CMAKE})
IF(EXISTS ${PROJECT_CMAKE}/CLuceneConfig.cmake)
INCLUDE(${PROJECT_CMAKE}/CLuceneConfig.cmake)
ENDIF(EXISTS ${PROJECT_CMAKE}/CLuceneConfig.cmake)

View File

@ -71,8 +71,12 @@
#include "TomahawkApp.h"
#include "LoadXSPFDialog.h"
#ifdef Q_WS_WIN
#ifdef Q_OS_WIN
#include <qtsparkle/Updater>
#include <shobjidl.h>
#ifndef THBN_CLICKED
# define THBN_CLICKED 0x1800
#endif
#endif
#include "utils/Logger.h"
@ -87,6 +91,9 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
, m_audioControls( new AudioControls( this ) )
, m_trayIcon( new TomahawkTrayIcon( this ) )
, m_audioRetryCounter( 0 )
#ifdef Q_OS_WIN
, m_buttonCreatedID(RegisterWindowMessage(L"TaskbarButtonCreated"))
#endif
{
setWindowIcon( QIcon( RESPATH "icons/tomahawk-icon-128x128.png" ) );
@ -320,6 +327,67 @@ TomahawkWindow::setupUpdateCheck()
#endif
}
#ifdef Q_OS_WIN
bool
TomahawkWindow::setupButtons()
{
const GUID IID_ITaskbarList3 = { 0xea1afb91,0x9e28,0x4b86,{0x90,0xe9,0x9e,0x9f,0x8a,0x5e,0xef,0xaf}};
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");
QTransform transform;
transform.rotate(180);
QPixmap next(back.transformed(transform));
THUMBBUTTON thumbButtons[5];
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;
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;
thumbButtons[3].dwMask = dwMask;
thumbButtons[3].iId = 4;
thumbButtons[3].hIcon = next.toWinHICON();
thumbButtons[3].szTip[tr("Next").toWCharArray(thumbButtons[3].szTip)] = 0;
thumbButtons[4].dwMask = dwMask;
thumbButtons[4].iId = 5;
thumbButtons[4].hIcon = love.toWinHICON();
thumbButtons[4].szTip[tr("Love").toWCharArray(thumbButtons[4].szTip)] = 0;
ITaskbarList3 *taskbarList;
if( S_OK == CoCreateInstance( CLSID_TaskbarList,NULL, CLSCTX_INPROC_SERVER,IID_ITaskbarList3,(void **)&taskbarList) )
{
taskbarList->HrInit();
if (SUCCEEDED(hr))
{
hr = taskbarList->ThumbBarAddButtons(winId(), ARRAYSIZE(thumbButtons), thumbButtons);
}
taskbarList->Release();
}
return SUCCEEDED(hr);
}
#endif
void
TomahawkWindow::setupSignals()
@ -491,6 +559,48 @@ TomahawkWindow::keyPressEvent( QKeyEvent* e )
QMainWindow::keyPressEvent( e );
}
#ifdef Q_OS_WIN
bool
TomahawkWindow::winEvent ( MSG * msg, long * result )
{
#define TB_PRESSED Q_FUNC_INFO << "Taskbar Button Pressed:"
switch(msg->message){
case WM_COMMAND:
if (HIWORD(msg->wParam) == THBN_CLICKED)
{
switch(LOWORD(msg->wParam))
{
case 1:
tLog()<<TB_PRESSED<<"Previous";
AudioEngine::instance()->previous();
break;
case 2:
tLog()<<TB_PRESSED<<"Pause";
AudioEngine::instance()->pause();
break;
case 3:
tLog()<<TB_PRESSED<<"Play";
AudioEngine::instance()->play();
break;
case 4:
tLog()<<TB_PRESSED<<"Next";
AudioEngine::instance()->next();
break;
case 5:
tLog()<<TB_PRESSED<<"Love";
// AudioEngine::instance()->
break;
}
return true;
}
break;
}
if ( msg->message == m_buttonCreatedID)
return setupButtons();
return false;
}
#endif
void
TomahawkWindow::onHistoryBackAvailable( bool avail )

View File

@ -74,6 +74,9 @@ protected:
void showEvent( QShowEvent* e );
void hideEvent( QHideEvent* e );
void keyPressEvent( QKeyEvent* e );
#ifdef Q_OS_WIN
bool winEvent ( MSG * message, long * result );
#endif
public slots:
void createAutomaticPlaylist( QString );
@ -141,6 +144,9 @@ private:
void setupToolBar();
void setupSideBar();
void setupUpdateCheck();
#ifdef Q_OS_WIN
bool setupButtons();
#endif
Ui::TomahawkWindow* ui;
QSearchField* m_searchWidget;
@ -159,6 +165,9 @@ private:
Tomahawk::result_ptr m_currentTrack;
QString m_windowTitle;
int m_audioRetryCounter;
#ifdef Q_OS_WIN
const uint m_buttonCreatedID;
#endif
};
#endif // TOMAHAWKWINDOW_H