1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
24 #include <MUtils/Taskbar7.h>
25 #include <MUtils/Exception.h>
33 #define WIN32_LEAN_AND_MEAN 1
37 ///////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
41 #define INITIALIZE_TASKBAR() do \
45 qWarning("Taskbar initialization failed!"); \
51 ///////////////////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////////////////
57 class Taskbar7_Private
59 friend class Taskbar7;
62 ITaskbarList3 *taskbarList;
63 volatile bool initialized;
67 ///////////////////////////////////////////////////////////////////////////////
68 // CONSTRUCTOR & DESTRUCTOR
69 ///////////////////////////////////////////////////////////////////////////////
71 MUtils::Taskbar7::Taskbar7(QWidget *const window)
73 p(new Taskbar7_Private()),
76 p->taskbarList = NULL;
77 p->initialized = false;
81 MUTILS_THROW("Taskbar7: Window pointer must not be NULL!");
85 MUtils::Taskbar7::~Taskbar7(void)
89 p->taskbarList->Release();
90 p->taskbarList = NULL;
96 ///////////////////////////////////////////////////////////////////////////////
98 ///////////////////////////////////////////////////////////////////////////////
100 bool MUtils::Taskbar7::setTaskbarState(const taskbarState_t &state)
102 INITIALIZE_TASKBAR();
103 HRESULT result = HRESULT(-1);
107 case TASKBAR_STATE_NONE:
108 result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(m_window->winId()), TBPF_NOPROGRESS);
110 case TASKBAR_STATE_NORMAL:
111 result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(m_window->winId()), TBPF_NORMAL);
113 case TASKBAR_STATE_INTERMEDIATE:
114 result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(m_window->winId()), TBPF_INDETERMINATE);
116 case TASKBAR_STATE_PAUSED:
117 result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(m_window->winId()), TBPF_ERROR);
119 case TASKBAR_STATE_ERROR:
120 result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(m_window->winId()), TBPF_PAUSED);
123 MUTILS_THROW("Taskbar7: Invalid taskbar state specified!");
126 return SUCCEEDED(result);
129 bool MUtils::Taskbar7::setTaskbarProgress(const quint64 ¤tValue, const quint64 &maximumValue)
131 INITIALIZE_TASKBAR();
132 const HRESULT result = p->taskbarList->SetProgressValue(reinterpret_cast<HWND>(m_window->winId()), currentValue, maximumValue);
133 return SUCCEEDED(result);
136 bool MUtils::Taskbar7::setOverlayIcon(const QIcon *const icon, const QString &info)
138 INITIALIZE_TASKBAR();
139 HRESULT result = HRESULT(-1);
142 if(const HICON hIcon = icon->pixmap(16,16).toWinHICON())
144 result = p->taskbarList->SetOverlayIcon(m_window->winId(), hIcon, MUTILS_WCHR(info));
150 result = p->taskbarList->SetOverlayIcon(m_window->winId(), NULL, MUTILS_WCHR(info));
152 return SUCCEEDED(result);
155 ///////////////////////////////////////////////////////////////////////////////
157 ///////////////////////////////////////////////////////////////////////////////
159 bool MUtils::Taskbar7::initialize(void)
161 while(!p->taskbarList)
163 ITaskbarList3 *ptbl = NULL;
164 const HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ptbl));
167 qWarning("ITaskbarList3 could not be created!");
170 p->taskbarList = ptbl;
173 while(!p->initialized)
176 for(int i = 0; i < 8; i++)
178 if(SUCCEEDED(p->taskbarList->HrInit()))
187 qWarning("ITaskbarList3::HrInit() has failed!");
190 p->initialized = true;