cellular/psuinotes/src/psuilocalisation.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  
       
    15  *
       
    16  */
       
    17 #include "psuilocalisation.h"
       
    18 #include "psuilogging.h"
       
    19 #include <QTranslator>
       
    20 #include <QLocale>
       
    21 #include <QApplication>
       
    22 
       
    23 
       
    24 // Constant definitions 
       
    25 const char *TS_FILE_TELEPHONE_CP = "telephone_cp";
       
    26 const char *TS_FILE_COMMON = "common"; 
       
    27 
       
    28 /*!
       
    29     \class PsUiLocalisation
       
    30     \brief Localisation utility class for 
       
    31            Telephony control panel plugins. 
       
    32 
       
    33     Use installTranslator function for installing 
       
    34     needed translation files. 
       
    35     
       
    36     Takes ownership of the created QTranslator objects
       
    37     and destroys them when PsUiLocalisation 
       
    38     object is destructed. 
       
    39 */
       
    40 
       
    41 
       
    42 /*!
       
    43   PsUiLocalisation::PsUiLocalisation() 
       
    44  */
       
    45 PsUiLocalisation::PsUiLocalisation(QObject *parent)
       
    46  :QObject(parent)
       
    47 {
       
    48     DPRINT; 
       
    49 }
       
    50 
       
    51 
       
    52 /*!
       
    53   PsUiLocalisation::~PsUiLocalisation() 
       
    54 */
       
    55 PsUiLocalisation::~PsUiLocalisation()
       
    56 {
       
    57     DPRINT << ":IN"; 
       
    58     removeTranslators();
       
    59     DPRINT << ":OUT";
       
    60 }
       
    61 
       
    62 
       
    63 /*!
       
    64   PsUiLocalisation::installTranslator() 
       
    65 */
       
    66 bool PsUiLocalisation::installTranslator(
       
    67         TranslationFileId translationFileId)
       
    68 {
       
    69     DPRINT << ": IN";
       
    70    
       
    71     QString lang = QLocale::system().name();
       
    72     QString path = "z:/resource/qt/translations/";
       
    73     bool translatorLoaded(false);  
       
    74 
       
    75     QString fileName; 
       
    76     switch (translationFileId) {
       
    77         case TranslationFileTelephoneCp: 
       
    78             fileName = TS_FILE_TELEPHONE_CP; 
       
    79             break; 
       
    80         case TranslationFileCommon:
       
    81             fileName = TS_FILE_COMMON; 
       
    82             break;
       
    83         default: 
       
    84             DWARNING << ": Unknown enum value!";
       
    85             break; 
       
    86     }
       
    87 
       
    88     if (!fileName.isEmpty()) {
       
    89         QTranslator* translator = new QTranslator;
       
    90         translatorLoaded = translator->load(
       
    91                 path + fileName + "_" + lang);
       
    92         if (translatorLoaded) {
       
    93             m_translators.append(translator); 
       
    94             qApp->installTranslator(translator);
       
    95             DPRINT << ": translator installed: " << fileName; 
       
    96         } else {
       
    97             delete translator; 
       
    98             translator = NULL;
       
    99             DWARNING << ": Translator not loaded!";
       
   100         }
       
   101     }
       
   102 
       
   103     DPRINT << ": OUT";
       
   104     return translatorLoaded;
       
   105 }
       
   106 
       
   107 
       
   108 /*!
       
   109   PsUiLocalisation::removeTranslators()
       
   110 */
       
   111 void PsUiLocalisation::removeTranslators()
       
   112 {
       
   113     DPRINT << ": IN";
       
   114 
       
   115     foreach (QTranslator *translator, m_translators) {
       
   116         qApp->removeTranslator(translator);
       
   117     }    
       
   118     qDeleteAll(m_translators);
       
   119     m_translators.clear();
       
   120     
       
   121     DPRINT << ": OUT";
       
   122 }
       
   123 
       
   124 
       
   125 // End of File.