diff --git a/MUtilities_VS2013.vcxproj b/MUtilities_VS2013.vcxproj index 36ba503..b8a2f87 100644 --- a/MUtilities_VS2013.vcxproj +++ b/MUtilities_VS2013.vcxproj @@ -31,6 +31,7 @@ + @@ -47,6 +48,7 @@ + diff --git a/MUtilities_VS2013.vcxproj.filters b/MUtilities_VS2013.vcxproj.filters index 2b0c53f..3778c5d 100644 --- a/MUtilities_VS2013.vcxproj.filters +++ b/MUtilities_VS2013.vcxproj.filters @@ -84,6 +84,9 @@ Source Files\3rd Party + + Source Files + @@ -143,6 +146,9 @@ Header Files\3rd Party + + Public Headers + diff --git a/include/MUtils/Taskbar7.h b/include/MUtils/Taskbar7.h new file mode 100644 index 0000000..bbd35fe --- /dev/null +++ b/include/MUtils/Taskbar7.h @@ -0,0 +1,62 @@ +/////////////////////////////////////////////////////////////////////////////// +// MuldeR's Utilities for Qt +// Copyright (C) 2004-2014 LoRd_MuldeR +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// +// http://www.gnu.org/licenses/lgpl-2.1.txt +////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +class QWidget; +class QIcon; + +namespace MUtils +{ + class MUTILS_API Taskbar7_Private; + + class MUTILS_API Taskbar7 + { + public: + //Taskbar states + typedef enum + { + TASKBAR_STATE_NONE = 0, + TASKBAR_STATE_NORMAL = 1, + TASKBAR_STATE_INTERMEDIATE = 2, + TASKBAR_STATE_PAUSED = 3, + TASKBAR_STATE_ERROR = 4 + } + taskbarState_t; + + //Constructor + Taskbar7(QWidget *const window); + ~Taskbar7(void); + + //Public interface + bool setTaskbarState(const taskbarState_t &state); + bool setTaskbarProgress(const quint64 ¤tValue, const quint64 &maximumValue); + bool setOverlayIcon(const QIcon *const icon, const QString &info = QString()); + + private: + Taskbar7_Private *const p; + QWidget *const m_window; + + inline bool initialize(void); + }; +} diff --git a/src/Taskbar7_Win32.cpp b/src/Taskbar7_Win32.cpp new file mode 100644 index 0000000..d95abab --- /dev/null +++ b/src/Taskbar7_Win32.cpp @@ -0,0 +1,182 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2014 LoRd_MuldeR +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version, but always including the *additional* +// restrictions defined in the "License.txt" file. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// http://www.gnu.org/licenses/gpl-2.0.txt +/////////////////////////////////////////////////////////////////////////////// + +//Internal +#include +#include + +//Qt +#include +#include + +//Windows includes +#define NOMINMAX +#define WIN32_LEAN_AND_MEAN 1 +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +// UNTILITIES +/////////////////////////////////////////////////////////////////////////////// + +#define INITIALIZE_TASKBAR() do \ +{ \ + if(!initialize()) \ + { \ + qWarning("Taskbar initialization failed!"); \ + return false; \ + } \ +} \ +while(0) + +/////////////////////////////////////////////////////////////////////////////// +// PRIVATE DATA +/////////////////////////////////////////////////////////////////////////////// + +namespace MUtils +{ + class Taskbar7_Private + { + friend class Taskbar7; + + protected: + ITaskbarList3 *taskbarList; + volatile bool initialized; + }; +} + +/////////////////////////////////////////////////////////////////////////////// +// CONSTRUCTOR & DESTRUCTOR +/////////////////////////////////////////////////////////////////////////////// + +MUtils::Taskbar7::Taskbar7(QWidget *const window) +: + p(new Taskbar7_Private()), + m_window(window) +{ + p->taskbarList = NULL; + p->initialized = false; + + if(!m_window) + { + MUTILS_THROW("Taskbar7: Window pointer must not be NULL!"); + } +} + +MUtils::Taskbar7::~Taskbar7(void) +{ + if(p->taskbarList) + { + p->taskbarList->Release(); + p->taskbarList = NULL; + } + + delete p; +} + +/////////////////////////////////////////////////////////////////////////////// +// PUBLIC INTERFACE +/////////////////////////////////////////////////////////////////////////////// + +bool MUtils::Taskbar7::setTaskbarState(const taskbarState_t &state) +{ + INITIALIZE_TASKBAR(); + HRESULT result = HRESULT(-1); + + switch(state) + { + case TASKBAR_STATE_NONE: + result = p->taskbarList->SetProgressState(reinterpret_cast(m_window->winId()), TBPF_NOPROGRESS); + break; + case TASKBAR_STATE_NORMAL: + result = p->taskbarList->SetProgressState(reinterpret_cast(m_window->winId()), TBPF_NORMAL); + break; + case TASKBAR_STATE_INTERMEDIATE: + result = p->taskbarList->SetProgressState(reinterpret_cast(m_window->winId()), TBPF_INDETERMINATE); + break; + case TASKBAR_STATE_PAUSED: + result = p->taskbarList->SetProgressState(reinterpret_cast(m_window->winId()), TBPF_ERROR); + break; + case TASKBAR_STATE_ERROR: + result = p->taskbarList->SetProgressState(reinterpret_cast(m_window->winId()), TBPF_PAUSED); + break; + default: + MUTILS_THROW("Taskbar7: Invalid taskbar state specified!"); + } + + return SUCCEEDED(result); +} + +bool MUtils::Taskbar7::setTaskbarProgress(const quint64 ¤tValue, const quint64 &maximumValue) +{ + INITIALIZE_TASKBAR(); + const HRESULT result = p->taskbarList->SetProgressValue(reinterpret_cast(m_window->winId()), currentValue, maximumValue); + return SUCCEEDED(result); +} + +bool MUtils::Taskbar7::setOverlayIcon(const QIcon *const icon, const QString &info) +{ + INITIALIZE_TASKBAR(); + const HRESULT result = p->taskbarList->SetOverlayIcon(m_window->winId(), (icon ? icon->pixmap(16,16).toWinHICON() : NULL), MUTILS_WCHR(info)); + return SUCCEEDED(result); +} + +/////////////////////////////////////////////////////////////////////////////// +// INTERNAL +/////////////////////////////////////////////////////////////////////////////// + +bool MUtils::Taskbar7::initialize(void) +{ + while(!p->taskbarList) + { + ITaskbarList3 *ptbl = NULL; + const HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ptbl)); + if(!SUCCEEDED(hr)) + { + qWarning("ITaskbarList3 could not be created!"); + return false; + } + p->taskbarList = ptbl; + } + + while(!p->initialized) + { + bool okay = false; + for(int i = 0; i < 8; i++) + { + if(SUCCEEDED(p->taskbarList->HrInit())) + { + okay = true; + break; + } + Sleep(1); + } + if(!okay) + { + qWarning("ITaskbarList3::HrInit() has failed!"); + return false; + } + p->initialized = true; + } + + return true; +}