1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

* Fixed untranslatable strings issue.

This commit is contained in:
Christian Muehlhaeuser 2012-05-26 11:13:42 +02:00
parent cfa63049e2
commit da82f398be
3 changed files with 72 additions and 64 deletions

View File

@ -29,6 +29,7 @@
#include <QtNetwork/QNetworkReply>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QTranslator>
#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 );
}

View File

@ -115,6 +115,7 @@ private slots:
void accountManagerReady();
private:
void installTranslator();
void registerMetaTypes();
void printHelp();

View File

@ -25,8 +25,6 @@
#include "config.h"
#include "utils/Logger.h"
#include <QTranslator>
#ifdef Q_WS_MAC
#include "TomahawkApp_Mac.h"
#include </System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/Headers/AppleEvents.h>
@ -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<LPKBDLLHOOKSTRUCT>(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<LPKBDLLHOOKSTRUCT>(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<LPKBDLLHOOKSTRUCT>(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 <io.h>
@ -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;
}