Moved JobObject as well as the remaining GUI functions into the MUtilities library.

This commit is contained in:
LoRd_MuldeR 2014-12-08 22:06:01 +01:00
parent f064187bb1
commit 3a582a028c
17 changed files with 46 additions and 740 deletions

View File

@ -319,7 +319,6 @@ copy /Y "$(SolutionDir)\..\Prerequisites\VisualLeakDetector\bin\Win32\*.manifest
<ClCompile Include="src\Global_Version.cpp" />
<ClCompile Include="src\Global_Win32.cpp" />
<ClCompile Include="src\Global_Tools.cpp" />
<ClCompile Include="src\JobObject.cpp" />
<ClCompile Include="src\LockedFile.cpp" />
<ClCompile Include="src\Main.cpp" />
<ClCompile Include="src\Model_Artwork.cpp" />
@ -576,7 +575,6 @@ copy /Y "$(SolutionDir)\..\Prerequisites\VisualLeakDetector\bin\Win32\*.manifest
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\$(ProjectName)\MOC_%(Filename).cpp;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release_Static|Win32'">$(SolutionDir)tmp\$(ProjectName)\MOC_%(Filename).cpp;%(Outputs)</Outputs>
</CustomBuild>
<ClInclude Include="src\JobObject.h" />
<ClInclude Include="src\Tools.h" />
<CustomBuild Include="src\Tool_WaveProperties.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\MOC_%(Filename).cpp" "%(FullPath)"</Command>

View File

@ -217,9 +217,6 @@
<ClCompile Include="src\Registry_Encoder.cpp">
<Filter>Source Files\Misc</Filter>
</ClCompile>
<ClCompile Include="src\JobObject.cpp">
<Filter>Source Files\Misc</Filter>
</ClCompile>
<ClCompile Include="src\Global_Tools.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -519,9 +516,6 @@
<ClInclude Include="src\Decoder_Opus.h">
<Filter>Header Files\Decoders</Filter>
</ClInclude>
<ClInclude Include="src\JobObject.h">
<Filter>Header Files\Misc</Filter>
</ClInclude>
<ClInclude Include="tmp\LameXP\UIC_WorkingBanner.h">
<Filter>Generated Files\UIC</Filter>
</ClInclude>

View File

@ -34,8 +34,8 @@
#define VER_LAMEXP_MINOR_HI 1
#define VER_LAMEXP_MINOR_LO 1
#define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 5
#define VER_LAMEXP_BUILD 1621
#define VER_LAMEXP_PATCH 7
#define VER_LAMEXP_BUILD 1624
#define VER_LAMEXP_CONFG 1558
///////////////////////////////////////////////////////////////////////////////

View File

@ -32,6 +32,7 @@
#include <MUtils/Global.h>
#include <MUtils/OSSupport.h>
#include <MUtils/Sound.h>
#include <MUtils/GUI.h>
#include <MUtils/Version.h>
//Qt
@ -157,7 +158,7 @@ AboutDialog::AboutDialog(SettingsModel *settings, QWidget *parent, bool firstSta
//Disable "X" button
if(firstStart)
{
lamexp_enable_close_button(this, false);
MUtils::GUI::enable_close_button(this, false);
}
//Init images

View File

@ -39,6 +39,7 @@
//MUtils
#include <MUtils/Global.h>
#include <MUtils/OSSupport.h>
#include <MUtils/GUI.h>
//Qt includes
#include <QFileInfo>
@ -255,7 +256,7 @@ void CueImportDialog::browseButtonClicked(void)
if(pos > 0) currentDir.left(pos - 1); else break;
}
if(lamexp_themes_enabled())
if(MUtils::GUI::themes_enabled())
{
newOutDir = QFileDialog::getExistingDirectory(this, tr("Choose Output Directory"), currentDir);
}

View File

@ -260,7 +260,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel_MetaInfo *me
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
//Add system menu
lamexp_append_sysmenu(this, IDM_ABOUTBOX, "About...");
MUtils::GUI::sysmenu_append(this, IDM_ABOUTBOX, "About...");
//Setup corner widget
QLabel *cornerWidget = new QLabel(ui->menubar);
@ -595,8 +595,8 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel_MetaInfo *me
ui->actionStyleWindowsXP->setData(3);
ui->actionStyleWindowsClassic->setData(4);
ui->actionStylePlastique->setChecked(true);
ui->actionStyleWindowsXP->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_XP && lamexp_themes_enabled());
ui->actionStyleWindowsVista->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_VISTA && lamexp_themes_enabled());
ui->actionStyleWindowsXP->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_XP && MUtils::GUI::themes_enabled());
ui->actionStyleWindowsVista->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_VISTA && MUtils::GUI::themes_enabled());
connect(m_styleActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(styleActionActivated(QAction*)));
styleActionActivated(NULL);
@ -831,14 +831,14 @@ void MainWindow::addFolder(const QString &path, bool recursive, bool delayed)
SHOW_BANNER(tr("Scanning folder(s) for files, please wait..."));
QApplication::processEvents();
lamexp_check_escape_state();
MUtils::OS::check_key_state_esc();
while(!folderInfoList.isEmpty())
{
if(lamexp_check_escape_state())
if(MUtils::OS::check_key_state_esc())
{
MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
qWarning("Operation cancelled by user!");
MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
fileList.clear();
break;
}
@ -1103,7 +1103,7 @@ void MainWindow::changeEvent(QEvent *e)
}
//Translate system menu
lamexp_update_sysmenu(this, IDM_ABOUTBOX, ui->buttonAbout->text());
MUtils::GUI::sysmenu_update(this, IDM_ABOUTBOX, ui->buttonAbout->text());
//Force resize event
QApplication::postEvent(this, new QResizeEvent(this->size(), QSize()));
@ -1263,7 +1263,7 @@ bool MainWindow::event(QEvent *e)
bool MainWindow::winEvent(MSG *message, long *result)
{
if(lamexp_check_sysmenu_msg(message, IDM_ABOUTBOX))
if(MUtils::GUI::sysmenu_check_msg(message, IDM_ABOUTBOX))
{
QTimer::singleShot(0, ui->buttonAbout, SLOT(click()));
*result = 0;
@ -2033,7 +2033,7 @@ void MainWindow::importCueSheetActionTriggered(bool checked)
int result = 0;
QString selectedCueFile;
if(lamexp_themes_enabled())
if(MUtils::GUI::themes_enabled())
{
selectedCueFile = QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
}
@ -2084,7 +2084,7 @@ void MainWindow::showDropBoxWidgetActionTriggered(bool checked)
QTimer::singleShot(2500, m_dropBox, SLOT(showToolTip()));
}
lamexp_blink_window(m_dropBox);
MUtils::GUI::blink_window(m_dropBox);
}
/*
@ -2267,7 +2267,7 @@ void MainWindow::addFilesButtonClicked(void)
TEMP_HIDE_DROPBOX
(
if(lamexp_themes_enabled())
if(MUtils::GUI::themes_enabled())
{
QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
QStringList selectedFiles = QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings->mostRecentInputPath(), fileTypeFilters.join(";;"));
@ -2309,7 +2309,7 @@ void MainWindow::openFolderActionActivated(void)
{
TEMP_HIDE_DROPBOX
(
if(lamexp_themes_enabled())
if(MUtils::GUI::themes_enabled())
{
selectedFolder = QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings->mostRecentInputPath());
}
@ -2612,7 +2612,7 @@ void MainWindow::exportCsvContextActionTriggered(void)
(
QString selectedCsvFile;
if(lamexp_themes_enabled())
if(MUtils::GUI::themes_enabled())
{
selectedCsvFile = QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
}
@ -2663,7 +2663,7 @@ void MainWindow::importCsvContextActionTriggered(void)
(
QString selectedCsvFile;
if(lamexp_themes_enabled())
if(MUtils::GUI::themes_enabled())
{
selectedCsvFile = QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
}
@ -3925,7 +3925,7 @@ void MainWindow::browseCustomTempFolderButtonClicked(void)
{
QString newTempFolder;
if(lamexp_themes_enabled())
if(MUtils::GUI::themes_enabled())
{
newTempFolder = QFileDialog::getExistingDirectory(this, QString(), m_settings->customTempPath());
}

View File

@ -378,7 +378,7 @@ void ProcessingDialog::showEvent(QShowEvent *event)
{
static const char *NA = " N/A";
lamexp_enable_close_button(this, false);
MUtils::GUI::enable_close_button(this, false);
ui->button_closeDialog->setEnabled(false);
ui->button_AbortProcess->setEnabled(false);
m_progressIndicator->start();
@ -752,7 +752,7 @@ void ProcessingDialog::doneEncoding(void)
}
}
lamexp_enable_close_button(this, true);
MUtils::GUI::enable_close_button(this, true);
ui->button_closeDialog->setEnabled(true);
ui->button_AbortProcess->setEnabled(false);
ui->checkBox_shutdownComputer->setEnabled(false);
@ -1064,7 +1064,7 @@ void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason rea
{
if(reason == QSystemTrayIcon::DoubleClick)
{
lamexp_bring_to_front(this);
MUtils::GUI::bring_to_front(this);
}
}

View File

@ -28,6 +28,7 @@
//MUtils
#include <MUtils/Global.h>
#include <MUtils/GUI.h>
//Qt
#include <QThread>
@ -79,7 +80,7 @@ SplashScreen::SplashScreen(QWidget *parent)
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateHandler()));
//Enable "sheet of glass" effect on splash screen
if(!lamexp_sheet_of_glass(this))
if(!MUtils::GUI::sheet_of_glass(this))
{
setStyleSheet("background-image: url(:/images/Background.jpg)");
}
@ -130,7 +131,7 @@ void SplashScreen::showSplash(QThread *thread)
//Wait for window to show
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
splashScreen->repaint(); lamexp_bring_to_front(splashScreen);
splashScreen->repaint(); MUtils::GUI::bring_to_front(splashScreen);
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
//Connect thread signals
@ -185,7 +186,7 @@ void SplashScreen::updateHandler(void)
else
{
setWindowOpacity(1.0);
lamexp_bring_to_front(this);
MUtils::GUI::bring_to_front(this);
m_timer->stop();
m_status = STATUS_WAIT;
}
@ -214,7 +215,7 @@ void SplashScreen::threadComplete(void)
{
m_timer->start(FADE_DELAY);
}
lamexp_bring_to_front(this);
MUtils::GUI::bring_to_front(this);
}
////////////////////////////////////////////////////////////

View File

@ -36,6 +36,7 @@
#include <MUtils/Version.h>
#include <MUtils/Exception.h>
#include <MUtils/Sound.h>
#include <MUtils/GUI.h>
#include <MUtils/OSSupport.h>
@ -97,7 +98,7 @@ UpdateDialog::UpdateDialog(SettingsModel *settings, QWidget *parent)
setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
//Disable "X" button
lamexp_enable_close_button(this, false);
MUtils::GUI::enable_close_button(this, false);
//Init animation
m_animator = new QMovie(":/images/Loading3.gif");
@ -220,7 +221,7 @@ bool UpdateDialog::event(QEvent *e)
{
if((e->type() == QEvent::ActivationChange) && (m_updaterProcess != NULL))
{
lamexp_bring_process_to_front(m_updaterProcess);
MUtils::GUI::bring_to_front(m_updaterProcess);
}
return QDialog::event(e);
}

View File

@ -29,6 +29,7 @@
//MUtils
#include <MUtils/Global.h>
#include <MUtils/GUI.h>
//Qt
#include <QThread>
@ -90,7 +91,7 @@ WorkingBanner::WorkingBanner(QWidget *parent)
setModal(true);
//Enable the "sheet of glass" effect
if(lamexp_sheet_of_glass(this))
if(MUtils::GUI::sheet_of_glass(this))
{
m_style = new QWindowsVistaStyle();
this->setStyle(m_style);
@ -289,7 +290,7 @@ void WorkingBanner::hideEvent(QHideEvent *event)
void WorkingBanner::windowShown(void)
{
lamexp_bring_to_front(this);
MUtils::GUI::bring_to_front(this);
}
void WorkingBanner::setText(const QString &text)

View File

@ -41,34 +41,13 @@ enum QtMsgType;
extern const char* LAMEXP_DEFAULT_LANGID;
extern const char* LAMEXP_DEFAULT_TRANSLATION;
///////////////////////////////////////////////////////////////////////////////
// TYPE DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
//System color types
typedef enum
{
lamexp_syscolor_text = 0,
lamexp_syscolor_background = 1,
lamexp_syscolor_caption = 2
}
lamexp_syscolor_t;
///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
const QIcon &lamexp_app_icon(void);
bool lamexp_append_sysmenu(const QWidget *win, const unsigned int identifier, const QString &text);
QStringList lamexp_available_codepages(bool noAliases = true);
void lamexp_blink_window(QWidget *poWindow, unsigned int count = 10, unsigned int delay = 150);
bool lamexp_block_window_move(void *message);
bool lamexp_bring_process_to_front(const unsigned long pid);
bool lamexp_bring_to_front(const QWidget *win);
bool lamexp_check_escape_state(void);
bool lamexp_check_sysmenu_msg(void *message, const unsigned int identifier);
bool lamexp_check_tool(const QString &toolName);
bool lamexp_enable_close_button(const QWidget *win, const bool bEnable = true);
void lamexp_finalization(void);
int lamexp_init_ipc(void);
bool lamexp_install_translator(const QString &language);
@ -80,11 +59,7 @@ const char *lamexp_mulders_url(void);
bool lamexp_portable_mode(void);
QStringList lamexp_query_translations(void);
void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0, const QString *tag = NULL);
bool lamexp_sheet_of_glass(QWidget *window);
bool lamexp_sheet_of_glass_update(QWidget *window);
QColor lamexp_system_color(const int color_id);
const char *lamexp_support_url(void);
bool lamexp_themes_enabled(void);
unsigned int lamexp_tool_version(const QString &toolName, QString *tag = NULL);
unsigned int lamexp_toolver_coreaudio(void);
unsigned int lamexp_toolver_fhgaacenc(void);
@ -96,7 +71,6 @@ bool lamexp_translation_init(void);
QString lamexp_translation_name(const QString &language);
bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country);
unsigned int lamexp_translation_sysid(const QString &langId);
bool lamexp_update_sysmenu(const QWidget *win, const unsigned int identifier, const QString &text);
const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText, const QString *tag = NULL);
unsigned int lamexp_version_build(void);
unsigned int lamexp_version_confg(void);

View File

@ -87,57 +87,6 @@ QStringList lamexp_available_codepages(bool noAliases)
return codecList;
}
/*
* Make a window blink (to draw user's attention)
*/
void lamexp_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay)
{
static QMutex blinkMutex;
const double maxOpac = 1.0;
const double minOpac = 0.3;
const double delOpac = 0.1;
if(!blinkMutex.tryLock())
{
qWarning("Blinking is already in progress, skipping!");
return;
}
try
{
const int steps = static_cast<int>(ceil(maxOpac - minOpac) / delOpac);
const int sleep = static_cast<int>(floor(static_cast<double>(delay) / static_cast<double>(steps)));
const double opacity = poWindow->windowOpacity();
for(unsigned int i = 0; i < count; i++)
{
for(double x = maxOpac; x >= minOpac; x -= delOpac)
{
poWindow->setWindowOpacity(x);
QApplication::processEvents();
MUtils::OS::sleep_ms(sleep);
}
for(double x = minOpac; x <= maxOpac; x += delOpac)
{
poWindow->setWindowOpacity(x);
QApplication::processEvents();
MUtils::OS::sleep_ms(sleep);
}
}
poWindow->setWindowOpacity(opacity);
QApplication::processEvents();
blinkMutex.unlock();
}
catch(...)
{
blinkMutex.unlock();
qWarning("Exception error while blinking!");
}
}
/*
* Computus according to H. Lichtenberg
*/

View File

@ -28,62 +28,6 @@
//Visual Leaks Detector
#include <vld.h>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <MMSystem.h>
#include <ShellAPI.h>
#include <SensAPI.h>
#include <Objbase.h>
#include <PowrProf.h>
#include <Psapi.h>
#include <dwmapi.h>
//Qt includes
#include <QApplication>
#include <QDate>
#include <QDir>
#include <QEvent>
#include <QIcon>
#include <QImageReader>
#include <QLibrary>
#include <QLibraryInfo>
#include <QMap>
#include <QMessageBox>
#include <QPlastiqueStyle>
#include <QProcess>
#include <QReadWriteLock>
#include <QRegExp>
#include <QSysInfo>
#include <QTextCodec>
#include <QTimer>
#include <QTranslator>
#include <QUuid>
#include <QResource>
//LameXP includes
#define LAMEXP_INC_CONFIG
#include "Resource.h"
#include "Config.h"
//MUtils
#include <MUtils/Global.h>
#include <MUtils/OSSupport.h>
#include <MUtils/Terminal.h>
//CRT includes
#include <cstdio>
#include <iostream>
#include <fstream>
#include <io.h>
#include <fcntl.h>
#include <intrin.h>
#include <cmath>
#include <ctime>
#include <process.h>
#include <csignal>
//Initialize static Qt plugins
#ifdef QT_NODLL
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
@ -95,402 +39,16 @@ Q_IMPORT_PLUGIN(QICOPlugin)
#endif
#endif
///////////////////////////////////////////////////////////////////////////////
// HELPER MACROS
///////////////////////////////////////////////////////////////////////////////
#define _LAMEXP_MAKE_STR(STR) #STR
#define LAMEXP_MAKE_STR(STR) _LAMEXP_MAKE_STR(STR)
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARS
///////////////////////////////////////////////////////////////////////////////
//Wine detection
static struct
{
bool bInitialized;
bool bIsWine;
QReadWriteLock lock;
}
g_lamexp_wine;
//Win32 Theme support
static struct
{
bool bInitialized;
bool bThemesEnabled;
QReadWriteLock lock;
}
g_lamexp_themes_enabled;
//Win32 DWM API functions
static struct
{
bool bInitialized;
HRESULT (__stdcall *dwmIsCompositionEnabled)(BOOL *bEnabled);
HRESULT (__stdcall *dwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS* pMarInset);
HRESULT (__stdcall *dwmEnableBlurBehindWindow)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind);
QLibrary *dwmapi_dll;
QReadWriteLock lock;
}
g_lamexp_dwmapi;
//Sound file cache
static struct
{
QHash<const QString, const unsigned char*> *sound_db;
QReadWriteLock lock;
}
g_lamexp_sounds;
//Main thread ID
static const DWORD g_main_thread_id = GetCurrentThreadId();
//Localization
const char* LAMEXP_DEFAULT_LANGID = "en";
const char* LAMEXP_DEFAULT_TRANSLATION = "LameXP_EN.qm";
///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
/*
* Check if visual themes are enabled (WinXP and later)
*/
bool lamexp_themes_enabled(void)
{
typedef int (WINAPI *IsAppThemedFun)(void);
QReadLocker readLock(&g_lamexp_themes_enabled.lock);
if(g_lamexp_themes_enabled.bInitialized)
{
return g_lamexp_themes_enabled.bThemesEnabled;
}
readLock.unlock();
QWriteLocker writeLock(&g_lamexp_themes_enabled.lock);
if(!g_lamexp_themes_enabled.bInitialized)
{
g_lamexp_themes_enabled.bThemesEnabled = false;
const MUtils::OS::Version::os_version_t &osVersion = MUtils::OS::os_version();
if(osVersion >= MUtils::OS::Version::WINDOWS_WINXP)
{
IsAppThemedFun IsAppThemedPtr = NULL;
QLibrary uxTheme(QString("%1/UxTheme.dll").arg(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER)));
if(uxTheme.load())
{
IsAppThemedPtr = (IsAppThemedFun) uxTheme.resolve("IsAppThemed");
}
if(IsAppThemedPtr)
{
g_lamexp_themes_enabled.bThemesEnabled = IsAppThemedPtr();
if(!g_lamexp_themes_enabled.bThemesEnabled)
{
qWarning("Theme support is disabled for this process!");
}
}
}
g_lamexp_themes_enabled.bInitialized = true;
}
return g_lamexp_themes_enabled.bThemesEnabled;
}
/*
* Insert entry to the window's system menu
*/
bool lamexp_append_sysmenu(const QWidget *win, const unsigned int identifier, const QString &text)
{
bool ok = false;
if(HMENU hMenu = GetSystemMenu(win->winId(), FALSE))
{
ok = (AppendMenuW(hMenu, MF_SEPARATOR, 0, 0) == TRUE);
ok = (AppendMenuW(hMenu, MF_STRING, identifier, MUTILS_WCHR(text)) == TRUE);
}
return ok;
}
/*
* Insert entry to the window's system menu
*/
bool lamexp_check_sysmenu_msg(void *message, const unsigned int identifier)
{
return (((MSG*)message)->message == WM_SYSCOMMAND) && ((((MSG*)message)->wParam & 0xFFF0) == identifier);
}
/*
* Update system menu entry
*/
bool lamexp_update_sysmenu(const QWidget *win, const unsigned int identifier, const QString &text)
{
bool ok = false;
if(HMENU hMenu = ::GetSystemMenu(win->winId(), FALSE))
{
ok = (ModifyMenu(hMenu, identifier, MF_STRING | MF_BYCOMMAND, identifier, MUTILS_WCHR(text)) == TRUE);
}
return ok;
}
/*
* Display the window's close button
*/
bool lamexp_enable_close_button(const QWidget *win, const bool bEnable)
{
bool ok = false;
if(HMENU hMenu = GetSystemMenu(win->winId(), FALSE))
{
ok = (EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (bEnable ? MF_ENABLED : MF_GRAYED)) == TRUE);
}
return ok;
}
/*
* Check whether ESC key has been pressed since the previous call to this function
*/
bool lamexp_check_escape_state(void)
{
return (GetAsyncKeyState(VK_ESCAPE) & 0x0001) != 0;
}
/*
* Bring the specifed window to the front
*/
bool lamexp_bring_to_front(const QWidget *window)
{
bool ret = false;
if(window)
{
for(int i = 0; (i < 5) && (!ret); i++)
{
ret = (SetForegroundWindow(window->winId()) != FALSE);
SwitchToThisWindow(window->winId(), TRUE);
}
LockSetForegroundWindow(LSFW_LOCK);
}
return ret;
}
/*
* Bring window of the specifed process to the front (callback)
*/
static BOOL CALLBACK lamexp_bring_process_to_front_helper(HWND hwnd, LPARAM lParam)
{
DWORD processId = *reinterpret_cast<WORD*>(lParam);
DWORD windowProcessId = NULL;
GetWindowThreadProcessId(hwnd, &windowProcessId);
if(windowProcessId == processId)
{
SwitchToThisWindow(hwnd, TRUE);
SetForegroundWindow(hwnd);
return FALSE;
}
return TRUE;
}
/*
* Bring window of the specifed process to the front
*/
bool lamexp_bring_process_to_front(const unsigned long pid)
{
return EnumWindows(lamexp_bring_process_to_front_helper, reinterpret_cast<LPARAM>(&pid)) == TRUE;
}
static void lamexp_init_dwmapi(void)
{
QReadLocker writeLock(&g_lamexp_dwmapi.lock);
//Not initialized yet?
if(g_lamexp_dwmapi.bInitialized)
{
return;
}
//Reset function pointers
g_lamexp_dwmapi.dwmIsCompositionEnabled = NULL;
g_lamexp_dwmapi.dwmExtendFrameIntoClientArea = NULL;
g_lamexp_dwmapi.dwmEnableBlurBehindWindow = NULL;
//Does OS support DWM?
const MUtils::OS::Version::os_version_t &osVersion = MUtils::OS::os_version();
if(osVersion >= MUtils::OS::Version::WINDOWS_VISTA)
{
//Load DWMAPI.DLL
g_lamexp_dwmapi.dwmapi_dll = new QLibrary("dwmapi.dll");
if(g_lamexp_dwmapi.dwmapi_dll->load())
{
//Initialize function pointers
g_lamexp_dwmapi.dwmIsCompositionEnabled = (HRESULT (__stdcall*)(BOOL*)) g_lamexp_dwmapi.dwmapi_dll->resolve("DwmIsCompositionEnabled");
g_lamexp_dwmapi.dwmExtendFrameIntoClientArea = (HRESULT (__stdcall*)(HWND, const MARGINS*)) g_lamexp_dwmapi.dwmapi_dll->resolve("DwmExtendFrameIntoClientArea");
g_lamexp_dwmapi.dwmEnableBlurBehindWindow = (HRESULT (__stdcall*)(HWND, const DWM_BLURBEHIND*)) g_lamexp_dwmapi.dwmapi_dll->resolve("DwmEnableBlurBehindWindow");
}
else
{
MUTILS_DELETE(g_lamexp_dwmapi.dwmapi_dll);
qWarning("Failed to load DWMAPI.DLL on a DWM-enabled system!");
}
}
g_lamexp_dwmapi.bInitialized = true;
}
/*
* Enable "sheet of glass" effect on the given Window
*/
bool lamexp_sheet_of_glass(QWidget *window)
{
QReadLocker readLock(&g_lamexp_dwmapi.lock);
//Initialize the DWM API
while(!g_lamexp_dwmapi.bInitialized)
{
readLock.unlock();
lamexp_init_dwmapi();
readLock.relock();
}
BOOL bCompositionEnabled = FALSE;
//Required functions available?
if((g_lamexp_dwmapi.dwmIsCompositionEnabled != NULL) && (g_lamexp_dwmapi.dwmExtendFrameIntoClientArea != NULL) && (g_lamexp_dwmapi.dwmEnableBlurBehindWindow != NULL))
{
//Check if composition is currently enabled
if(HRESULT hr = g_lamexp_dwmapi.dwmIsCompositionEnabled(&bCompositionEnabled))
{
qWarning("DwmIsCompositionEnabled function has failed! (error %d)", hr);
return false;
}
}
//All functions available *and* composition enabled?
if(!bCompositionEnabled)
{
return false;
}
//Enable the "sheet of glass" effect on this window
MARGINS margins = {-1, -1, -1, -1};
if(HRESULT hr = g_lamexp_dwmapi.dwmExtendFrameIntoClientArea(window->winId(), &margins))
{
qWarning("DwmExtendFrameIntoClientArea function has failed! (error %d)", hr);
return false;
}
//Create and populate the Blur Behind structure
DWM_BLURBEHIND bb;
memset(&bb, 0, sizeof(DWM_BLURBEHIND));
bb.fEnable = TRUE;
bb.dwFlags = DWM_BB_ENABLE;
if(HRESULT hr = g_lamexp_dwmapi.dwmEnableBlurBehindWindow(window->winId(), &bb))
{
qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
return false;
}
//Required for Qt
window->setAutoFillBackground(false);
window->setAttribute(Qt::WA_TranslucentBackground);
window->setAttribute(Qt::WA_NoSystemBackground);
return true;
}
/*
* Update "sheet of glass" effect on the given Window
*/
bool lamexp_sheet_of_glass_update(QWidget *window)
{
QReadLocker readLock(&g_lamexp_dwmapi.lock);
//Initialize the DWM API
while(!g_lamexp_dwmapi.bInitialized)
{
readLock.unlock();
lamexp_init_dwmapi();
readLock.relock();
}
BOOL bCompositionEnabled = FALSE;
//Required functions available?
if((g_lamexp_dwmapi.dwmIsCompositionEnabled != NULL) && (g_lamexp_dwmapi.dwmEnableBlurBehindWindow != NULL))
{
//Check if composition is currently enabled
if(HRESULT hr = g_lamexp_dwmapi.dwmIsCompositionEnabled(&bCompositionEnabled))
{
qWarning("DwmIsCompositionEnabled function has failed! (error %d)", hr);
return false;
}
}
//All functions available *and* composition enabled?
if(!bCompositionEnabled)
{
return false;
}
//Create and populate the Blur Behind structure
DWM_BLURBEHIND bb;
memset(&bb, 0, sizeof(DWM_BLURBEHIND));
bb.fEnable = TRUE;
bb.dwFlags = DWM_BB_ENABLE;
if(HRESULT hr = g_lamexp_dwmapi.dwmEnableBlurBehindWindow(window->winId(), &bb))
{
qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
return false;
}
return true;
}
/*
* Get system color info
*/
QColor lamexp_system_color(const int color_id)
{
int nIndex = -1;
switch(color_id)
{
case lamexp_syscolor_text:
nIndex = COLOR_WINDOWTEXT; /*Text in windows*/
break;
case lamexp_syscolor_background:
nIndex = COLOR_WINDOW; /*Window background*/
break;
case lamexp_syscolor_caption:
nIndex = COLOR_CAPTIONTEXT; /*Text in caption, size box, and scroll bar arrow box*/
break;
default:
qWarning("Unknown system color id (%d) specified!", color_id);
nIndex = COLOR_WINDOWTEXT;
}
const DWORD rgb = GetSysColor(nIndex);
QColor color(GetRValue(rgb), GetGValue(rgb), GetBValue(rgb));
return color;
}
///////////////////////////////////////////////////////////////////////////////
// INITIALIZATION
///////////////////////////////////////////////////////////////////////////////
extern "C" void _lamexp_global_init_win32(void)
{
//Zero *before* constructors are called
MUTILS_ZERO_MEMORY(g_lamexp_wine);
MUTILS_ZERO_MEMORY(g_lamexp_themes_enabled);
MUTILS_ZERO_MEMORY(g_lamexp_dwmapi);
MUTILS_ZERO_MEMORY(g_lamexp_sounds);
}
///////////////////////////////////////////////////////////////////////////////
@ -499,12 +57,4 @@ extern "C" void _lamexp_global_init_win32(void)
extern "C" void _lamexp_global_free_win32(void)
{
//Release DWM API
g_lamexp_dwmapi.dwmIsCompositionEnabled = NULL;
g_lamexp_dwmapi.dwmExtendFrameIntoClientArea = NULL;
g_lamexp_dwmapi.dwmEnableBlurBehindWindow = NULL;
MUTILS_DELETE(g_lamexp_dwmapi.dwmapi_dll);
//Clear sound cache
MUTILS_DELETE(g_lamexp_sounds.sound_db);
}

View File

@ -1,130 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// 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
///////////////////////////////////////////////////////////////////////////////
#include "JobObject.h"
#include "Global.h"
#include <QProcess>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <MMSystem.h>
#include <ShellAPI.h>
#include <WinInet.h>
JobObject::JobObject(void)
:
m_hJobObject(NULL)
{
HANDLE jobObject = CreateJobObject(NULL, NULL);
if((jobObject != NULL) && (jobObject != INVALID_HANDLE_VALUE))
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobExtendedLimitInfo;
memset(&jobExtendedLimitInfo, 0, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
memset(&jobExtendedLimitInfo.BasicLimitInformation, 0, sizeof(JOBOBJECT_BASIC_LIMIT_INFORMATION));
jobExtendedLimitInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION;
if(SetInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &jobExtendedLimitInfo, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)))
{
m_hJobObject = jobObject;
}
else
{
qWarning("Failed to set job object information!");
CloseHandle(jobObject);
}
}
else
{
qWarning("Failed to create the job object!");
}
}
JobObject::~JobObject(void)
{
if(m_hJobObject)
{
CloseHandle(m_hJobObject);
m_hJobObject = NULL;
}
}
bool JobObject::addProcessToJob(const QProcess *proc)
{
if(!m_hJobObject)
{
qWarning("Cannot assign process to job: No job bject available!");
return false;
}
if(Q_PID pid = proc->pid())
{
DWORD exitCode;
if(!GetExitCodeProcess(pid->hProcess, &exitCode))
{
qWarning("Cannot assign process to job: Failed to query process status!");
return false;
}
if(exitCode != STILL_ACTIVE)
{
qWarning("Cannot assign process to job: Process is not running anymore!");
return false;
}
if(!AssignProcessToJobObject(m_hJobObject, pid->hProcess))
{
qWarning("Failed to assign process to job object!");
return false;
}
return true;
}
else
{
qWarning("Cannot assign process to job: Process handle not available!");
return false;
}
}
bool JobObject::terminateJob(unsigned int exitCode)
{
if(m_hJobObject)
{
if(TerminateJobObject(m_hJobObject, exitCode))
{
return true;
}
else
{
qWarning("Failed to terminate job object!");
return false;
}
}
else
{
qWarning("Cannot assign process to job: No job bject available!");
return false;
}
}

View File

@ -1,38 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// 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
///////////////////////////////////////////////////////////////////////////////
#pragma once
class QProcess;
class JobObject
{
public:
JobObject(void);
~JobObject(void);
bool addProcessToJob(const QProcess *proc);
bool terminateJob(unsigned int exitCode);
private:
void *m_hJobObject;
};

View File

@ -24,11 +24,11 @@
//Internal
#include "Global.h"
#include "JobObject.h"
//MUtils
#include <MUtils/Global.h>
#include <MUtils/OSSupport.h>
#include <MUtils/JobObject.h>
//Qt
#include <QProcess>
@ -42,8 +42,8 @@
/*
* Static Objects
*/
QScopedPointer<JobObject> AbstractTool::s_jobObjectInstance;
QScopedPointer<QElapsedTimer> AbstractTool::s_startProcessTimer;
QScopedPointer<MUtils::JobObject> AbstractTool::s_jobObjectInstance;
QScopedPointer<QElapsedTimer> AbstractTool::s_startProcessTimer;
/*
* Synchronization
@ -73,7 +73,7 @@ AbstractTool::AbstractTool(void)
if(s_referenceCounter++ == 0)
{
s_jobObjectInstance.reset(new JobObject());
s_jobObjectInstance.reset(new MUtils::JobObject());
s_startProcessTimer.reset(new QElapsedTimer());
if(!MUtils::OS::setup_timer_resolution())
{

View File

@ -27,7 +27,11 @@
class QMutex;
class QProcess;
class QElapsedTimer;
class JobObject;
namespace MUtils
{
class JobObject;
}
class AbstractTool : public QObject
{
@ -48,8 +52,8 @@ protected:
static const int m_processTimeoutInterval = 600000;
private:
static QScopedPointer<JobObject> s_jobObjectInstance;
static QScopedPointer<QElapsedTimer> s_startProcessTimer;
static QScopedPointer<MUtils::JobObject> s_jobObjectInstance;
static QScopedPointer<QElapsedTimer> s_startProcessTimer;
static QMutex s_startProcessMutex;
static QMutex s_createObjectMutex;