diff --git a/src/TomahawkApp.cpp b/src/TomahawkApp.cpp index f98bce7b1..d95e24840 100644 --- a/src/TomahawkApp.cpp +++ b/src/TomahawkApp.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "Artist.h" #include "Album.h" @@ -129,6 +130,29 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) setApplicationVersion( QLatin1String( TOMAHAWK_VERSION ) ); registerMetaTypes(); + installTranslator(); +} + + +void +TomahawkApp::installTranslator() +{ + QString locale = QLocale::system().name(); + if ( locale == "C" ) + locale = "en"; + + QTranslator* translator = new QTranslator( this ); + if ( translator->load( QString( ":/lang/tomahawk_" ) + locale ) ) + { + tDebug() << "Using system locale:" << locale; + } + else + { + tDebug() << "Using default locale, system locale one not found:" << locale; + translator->load( QString( ":/lang/tomahawk_en" ) ); + } + + TOMAHAWK_APPLICATION::installTranslator( translator ); } diff --git a/src/TomahawkApp.h b/src/TomahawkApp.h index a1c6f0724..41cfae3a9 100644 --- a/src/TomahawkApp.h +++ b/src/TomahawkApp.h @@ -115,6 +115,7 @@ private slots: void accountManagerReady(); private: + void installTranslator(); void registerMetaTypes(); void printHelp(); diff --git a/src/main.cpp b/src/main.cpp index dfb01ff1c..870bded10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,8 +25,6 @@ #include "config.h" #include "utils/Logger.h" -#include - #ifdef Q_WS_MAC #include "TomahawkApp_Mac.h" #include @@ -38,50 +36,53 @@ #include "breakpad/BreakPad.h" #endif + #ifdef Q_OS_WIN // code from patch attached to QTBUG-19064 by Honglei Zhang -LRESULT QT_WIN_CALLBACK qt_LowLevelKeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam); +LRESULT QT_WIN_CALLBACK qt_LowLevelKeyboardHookProc( int nCode, WPARAM wParam, LPARAM lParam ); HHOOK hKeyboardHook; HINSTANCE hGuiLibInstance; -LRESULT QT_WIN_CALLBACK qt_LowLevelKeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) +LRESULT QT_WIN_CALLBACK qt_LowLevelKeyboardHookProc( int nCode, WPARAM wParam, LPARAM lParam ) { LPKBDLLHOOKSTRUCT kbHookStruct = reinterpret_cast(lParam); - switch(kbHookStruct->vkCode){ - case VK_VOLUME_MUTE: - case VK_VOLUME_DOWN: - case VK_VOLUME_UP: - case VK_MEDIA_NEXT_TRACK: - case VK_MEDIA_PREV_TRACK: - case VK_MEDIA_STOP: - case VK_MEDIA_PLAY_PAUSE: - case VK_LAUNCH_MEDIA_SELECT: - // send message - { - HWND hWnd = NULL; - foreach (QWidget *widget, QApplication::topLevelWidgets()) { - // relay message to each top level widgets(window) - // if the window has focus, we don't send a duplicate message - if(QApplication::activeWindow() == widget){ - continue; + switch(kbHookStruct->vkCode) + { + case VK_VOLUME_MUTE: + case VK_VOLUME_DOWN: + case VK_VOLUME_UP: + case VK_MEDIA_NEXT_TRACK: + case VK_MEDIA_PREV_TRACK: + case VK_MEDIA_STOP: + case VK_MEDIA_PLAY_PAUSE: + case VK_LAUNCH_MEDIA_SELECT: + // send message + { + HWND hWnd = NULL; + foreach ( QWidget *widget, QApplication::topLevelWidgets() ) + { + // relay message to each top level widgets(window) + // if the window has focus, we don't send a duplicate message + if ( QApplication::activeWindow() == widget ) + continue; + + hWnd = widget->winId(); + + // generate message and post it to the message queue + LPKBDLLHOOKSTRUCT pKeyboardHookStruct = reinterpret_cast(lParam); + WPARAM _wParam = pKeyboardHookStruct->vkCode; + LPARAM _lParam = MAKELPARAM( pKeyboardHookStruct->scanCode, pKeyboardHookStruct->flags ); + PostMessage( hWnd, wParam, _wParam, _lParam ); } - - hWnd = widget->winId(); - - // generate message and post it to the message queue - LPKBDLLHOOKSTRUCT pKeyboardHookStruct = reinterpret_cast(lParam); - WPARAM _wParam = pKeyboardHookStruct->vkCode; - LPARAM _lParam = MAKELPARAM(pKeyboardHookStruct->scanCode, pKeyboardHookStruct->flags); - PostMessage(hWnd, wParam, _wParam, _lParam); } - } - break; - default: - break; + break; + + default: + break; } - return CallNextHookEx(0, nCode, wParam, lParam); + return CallNextHookEx( 0, nCode, wParam, lParam ); } #include @@ -89,32 +90,29 @@ LRESULT QT_WIN_CALLBACK qt_LowLevelKeyboardHookProc(int nCode, WPARAM wParam, LP #define argv __argv // code taken from AbiWord, (c) AbiSource Inc. -int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, - PSTR szCmdLine, int iCmdShow) +int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow ) { hKeyboardHook = NULL; hGuiLibInstance = hInstance; - // setup keyboard hook to receive multimedia key events when application is at background - hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC) qt_LowLevelKeyboardHookProc, hGuiLibInstance, 0); + hKeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL,(HOOKPROC) qt_LowLevelKeyboardHookProc, hGuiLibInstance, 0 ); - if (fileno (stdout) != -1 && _get_osfhandle (fileno (stdout)) != -1) + if ( fileno( stdout ) != -1 && _get_osfhandle( fileno( stdout ) ) != -1 ) { /* stdout is fine, presumably redirected to a file or pipe */ } else { typedef BOOL (WINAPI * AttachConsole_t) (DWORD); + AttachConsole_t p_AttachConsole = (AttachConsole_t) GetProcAddress( GetModuleHandleW( L"kernel32.dll" ), "AttachConsole" ); - AttachConsole_t p_AttachConsole = (AttachConsole_t) GetProcAddress (GetModuleHandleW(L"kernel32.dll"), "AttachConsole"); - - if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS)) + if ( p_AttachConsole != NULL && p_AttachConsole( ATTACH_PARENT_PROCESS ) ) { - _wfreopen (L"CONOUT$", L"w", stdout); - dup2 (fileno (stdout), 1); - _wfreopen (L"CONOUT$", L"w", stderr); - dup2 (fileno (stderr), 2); + _wfreopen ( L"CONOUT$", L"w", stdout ); + dup2( fileno( stdout ), 1 ); + _wfreopen ( L"CONOUT$", L"w", stderr ); + dup2( fileno( stderr ), 2 ); } } #else // Q_OS_WIN @@ -145,7 +143,6 @@ main( int argc, char *argv[] ) new TomahawkSettingsGui( &a ); #endif - #ifndef ENABLE_HEADLESSs #ifdef WITH_BREAKPAD new BreakPad( QDir::tempPath(), TomahawkSettings::instance()->crashReporterEnabled() ); @@ -158,21 +155,6 @@ main( int argc, char *argv[] ) if ( guard.isPrimaryInstance() ) a.init(); - QString locale = QLocale::system().name(); - if ( locale == "C" ) - locale = "en"; - QTranslator translator; - if ( translator.load( QString( ":/lang/tomahawk_" ) + locale ) ) - { - tDebug() << "Using system locale:" << locale; - } - else - { - tDebug() << "Using default locale, system locale one not found:" << locale; - translator.load( QString( ":/lang/tomahawk_en" ) ); - } - a.installTranslator( &translator ); - if ( argc > 1 ) { QString arg = a.arguments()[ 1 ]; @@ -182,12 +164,13 @@ main( int argc, char *argv[] ) int returnCode = a.exec(); #ifdef Q_OS_WIN // clean up keyboard hook - if( hKeyboardHook ) + if ( hKeyboardHook ) { - UnhookWindowsHookEx(hKeyboardHook); + UnhookWindowsHookEx( hKeyboardHook ); hKeyboardHook = NULL; } #endif + return returnCode; }