|
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 "cpphonelocalisation.h" |
|
18 #include "cppluginlogging.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 CpPhoneLocalisation |
|
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 CpPhoneLocalisation |
|
38 object is destructed. |
|
39 */ |
|
40 |
|
41 |
|
42 /*! |
|
43 CpPhoneLocalisation::CpPhoneLocalisation() |
|
44 */ |
|
45 CpPhoneLocalisation::CpPhoneLocalisation(QObject *parent) |
|
46 :QObject(parent) |
|
47 { |
|
48 DPRINT; |
|
49 } |
|
50 |
|
51 |
|
52 /*! |
|
53 CpPhoneLocalisation::~CpPhoneLocalisation() |
|
54 */ |
|
55 CpPhoneLocalisation::~CpPhoneLocalisation() |
|
56 { |
|
57 DPRINT << ":IN"; |
|
58 removeTranslators(); |
|
59 DPRINT << ":OUT"; |
|
60 } |
|
61 |
|
62 |
|
63 /*! |
|
64 CpPhoneLocalisation::installTranslator() |
|
65 */ |
|
66 bool CpPhoneLocalisation::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 break; |
|
85 } |
|
86 |
|
87 if (!fileName.isEmpty()) { |
|
88 QTranslator* translator = new QTranslator; |
|
89 translatorLoaded = translator->load( |
|
90 path + fileName + "_" + lang); |
|
91 if (translatorLoaded) { |
|
92 m_translators.append(translator); |
|
93 qApp->installTranslator(translator); |
|
94 DPRINT << ": translator installed: " << fileName; |
|
95 } else { |
|
96 delete translator; |
|
97 translator = NULL; |
|
98 DWARNING << ": WARNING! Translator not loaded!"; |
|
99 } |
|
100 } |
|
101 |
|
102 DPRINT << ": OUT"; |
|
103 return translatorLoaded; |
|
104 } |
|
105 |
|
106 |
|
107 /*! |
|
108 CpPhoneLocalisation::removeTranslators() |
|
109 */ |
|
110 void CpPhoneLocalisation::removeTranslators() |
|
111 { |
|
112 DPRINT << ": IN"; |
|
113 |
|
114 foreach (QTranslator *translator, m_translators) { |
|
115 qApp->removeTranslator(translator); |
|
116 } |
|
117 qDeleteAll(m_translators); |
|
118 m_translators.clear(); |
|
119 |
|
120 DPRINT << ": OUT"; |
|
121 } |
|
122 |
|
123 |
|
124 // End of File. |