Moved Taskbar progress into MUtilities library.
This commit is contained in:
parent
cef4994b34
commit
a90d30c71e
@ -31,6 +31,7 @@
|
||||
<ClCompile Include="src\OSSupport_Win32.cpp" />
|
||||
<ClCompile Include="src\Sound_Win32.cpp" />
|
||||
<ClCompile Include="src\Startup.cpp" />
|
||||
<ClCompile Include="src\Taskbar7_Win32.cpp" />
|
||||
<ClCompile Include="src\Terminal_Win32.cpp" />
|
||||
<ClCompile Include="src\UpdateChecker.cpp" />
|
||||
<ClCompile Include="src\Version.cpp" />
|
||||
@ -47,6 +48,7 @@
|
||||
<ClInclude Include="include\MUtils\OSSupport.h" />
|
||||
<ClInclude Include="include\MUtils\Sound.h" />
|
||||
<ClInclude Include="include\MUtils\Startup.h" />
|
||||
<ClInclude Include="include\MUtils\Taskbar7.h" />
|
||||
<ClInclude Include="include\MUtils\Terminal.h" />
|
||||
<ClInclude Include="src\3rd_party\adler32\include\adler32.h" />
|
||||
<ClInclude Include="src\3rd_party\keccak\include\keccak_impl.h" />
|
||||
|
@ -84,6 +84,9 @@
|
||||
<ClCompile Include="src\3rd_party\adler32\src\adler32.cpp">
|
||||
<Filter>Source Files\3rd Party</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Taskbar7_Win32.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\CriticalSection_Win32.h">
|
||||
@ -143,6 +146,9 @@
|
||||
<ClInclude Include="src\3rd_party\adler32\include\adler32.h">
|
||||
<Filter>Header Files\3rd Party</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\MUtils\Taskbar7.h">
|
||||
<Filter>Public Headers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="include\Mutils\UpdateChecker.h">
|
||||
|
62
include/MUtils/Taskbar7.h
Normal file
62
include/MUtils/Taskbar7.h
Normal file
@ -0,0 +1,62 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// MuldeR's Utilities for Qt
|
||||
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
|
||||
//
|
||||
// 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 <MUtils/Global.h>
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
182
src/Taskbar7_Win32.cpp
Normal file
182
src/Taskbar7_Win32.cpp
Normal file
@ -0,0 +1,182 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// LameXP - Audio Encoder Front-End
|
||||
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
|
||||
//
|
||||
// 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 <MUtils/Taskbar7.h>
|
||||
#include <MUtils/Exception.h>
|
||||
|
||||
//Qt
|
||||
#include <QWidget>
|
||||
#include <QIcon>
|
||||
|
||||
//Windows includes
|
||||
#define NOMINMAX
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#include <Windows.h>
|
||||
#include <ShObjIdl.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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<HWND>(m_window->winId()), TBPF_NOPROGRESS);
|
||||
break;
|
||||
case TASKBAR_STATE_NORMAL:
|
||||
result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(m_window->winId()), TBPF_NORMAL);
|
||||
break;
|
||||
case TASKBAR_STATE_INTERMEDIATE:
|
||||
result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(m_window->winId()), TBPF_INDETERMINATE);
|
||||
break;
|
||||
case TASKBAR_STATE_PAUSED:
|
||||
result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(m_window->winId()), TBPF_ERROR);
|
||||
break;
|
||||
case TASKBAR_STATE_ERROR:
|
||||
result = p->taskbarList->SetProgressState(reinterpret_cast<HWND>(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<HWND>(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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user