diff --git a/LameXP_VS2013.vcxproj b/LameXP_VS2013.vcxproj index 12b6c8b8..aad0d53a 100644 --- a/LameXP_VS2013.vcxproj +++ b/LameXP_VS2013.vcxproj @@ -319,7 +319,6 @@ copy /Y "$(SolutionDir)\..\Prerequisites\VisualLeakDetector\bin\Win32\*.manifest - @@ -576,7 +575,6 @@ copy /Y "$(SolutionDir)\..\Prerequisites\VisualLeakDetector\bin\Win32\*.manifest $(SolutionDir)tmp\$(ProjectName)\MOC_%(Filename).cpp;%(Outputs) $(SolutionDir)tmp\$(ProjectName)\MOC_%(Filename).cpp;%(Outputs) - "$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\$(ProjectName)\MOC_%(Filename).cpp" "%(FullPath)" diff --git a/LameXP_VS2013.vcxproj.filters b/LameXP_VS2013.vcxproj.filters index 2628b3ad..7e142e5c 100644 --- a/LameXP_VS2013.vcxproj.filters +++ b/LameXP_VS2013.vcxproj.filters @@ -217,9 +217,6 @@ Source Files\Misc - - Source Files\Misc - Source Files @@ -519,9 +516,6 @@ Header Files\Decoders - - Header Files\Misc - Generated Files\UIC diff --git a/src/Config.h b/src/Config.h index fa220993..bd15d8d5 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Dialog_About.cpp b/src/Dialog_About.cpp index bc36406b..5e7d11e5 100644 --- a/src/Dialog_About.cpp +++ b/src/Dialog_About.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include //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 diff --git a/src/Dialog_CueImport.cpp b/src/Dialog_CueImport.cpp index ccb61972..f9d25e6b 100644 --- a/src/Dialog_CueImport.cpp +++ b/src/Dialog_CueImport.cpp @@ -39,6 +39,7 @@ //MUtils #include #include +#include //Qt includes #include @@ -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); } diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index e7dd8170..2083a5d4 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -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()); } diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index 3f7f6fca..d1d9769c 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -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); } } diff --git a/src/Dialog_SplashScreen.cpp b/src/Dialog_SplashScreen.cpp index 7c5dc6b7..6d8d274b 100644 --- a/src/Dialog_SplashScreen.cpp +++ b/src/Dialog_SplashScreen.cpp @@ -28,6 +28,7 @@ //MUtils #include +#include //Qt #include @@ -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); } //////////////////////////////////////////////////////////// diff --git a/src/Dialog_Update.cpp b/src/Dialog_Update.cpp index 544f88f8..7717672b 100644 --- a/src/Dialog_Update.cpp +++ b/src/Dialog_Update.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -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); } diff --git a/src/Dialog_WorkingBanner.cpp b/src/Dialog_WorkingBanner.cpp index a3713465..abfff8fb 100644 --- a/src/Dialog_WorkingBanner.cpp +++ b/src/Dialog_WorkingBanner.cpp @@ -29,6 +29,7 @@ //MUtils #include +#include //Qt #include @@ -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) diff --git a/src/Global.h b/src/Global.h index 07f90ce9..c5eae796 100644 --- a/src/Global.h +++ b/src/Global.h @@ -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); diff --git a/src/Global_Utils.cpp b/src/Global_Utils.cpp index 79c0535f..54e22bb1 100644 --- a/src/Global_Utils.cpp +++ b/src/Global_Utils.cpp @@ -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(ceil(maxOpac - minOpac) / delOpac); - const int sleep = static_cast(floor(static_cast(delay) / static_cast(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 */ diff --git a/src/Global_Win32.cpp b/src/Global_Win32.cpp index 91a69ed2..b4584d9e 100644 --- a/src/Global_Win32.cpp +++ b/src/Global_Win32.cpp @@ -28,62 +28,6 @@ //Visual Leaks Detector #include -//Windows includes -#define NOMINMAX -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -#include -#include -#include -#include -#include - -//Qt includes -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//LameXP includes -#define LAMEXP_INC_CONFIG -#include "Resource.h" -#include "Config.h" - -//MUtils -#include -#include -#include - -//CRT includes -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - //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 *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(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(&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); } diff --git a/src/JobObject.cpp b/src/JobObject.cpp deleted file mode 100644 index 899d644b..00000000 --- a/src/JobObject.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// 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 -/////////////////////////////////////////////////////////////////////////////// - -#include "JobObject.h" - -#include "Global.h" - -#include - -//Windows includes -#define NOMINMAX -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -#include - -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; - } -} diff --git a/src/JobObject.h b/src/JobObject.h deleted file mode 100644 index 8f1ca964..00000000 --- a/src/JobObject.h +++ /dev/null @@ -1,38 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// 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 -/////////////////////////////////////////////////////////////////////////////// - -#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; -}; diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp index 2d7a9bbb..9b3b9561 100644 --- a/src/Tool_Abstract.cpp +++ b/src/Tool_Abstract.cpp @@ -24,11 +24,11 @@ //Internal #include "Global.h" -#include "JobObject.h" //MUtils #include #include +#include //Qt #include @@ -42,8 +42,8 @@ /* * Static Objects */ -QScopedPointer AbstractTool::s_jobObjectInstance; -QScopedPointer AbstractTool::s_startProcessTimer; +QScopedPointer AbstractTool::s_jobObjectInstance; +QScopedPointer 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()) { diff --git a/src/Tool_Abstract.h b/src/Tool_Abstract.h index d54b413e..9b373fd7 100644 --- a/src/Tool_Abstract.h +++ b/src/Tool_Abstract.h @@ -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 s_jobObjectInstance; - static QScopedPointer s_startProcessTimer; + static QScopedPointer s_jobObjectInstance; + static QScopedPointer s_startProcessTimer; static QMutex s_startProcessMutex; static QMutex s_createObjectMutex;