luna-sysmgr-common
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LocalePreferences.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 * Copyright (c) 2013 LG Electronics
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * LICENSE@@@ */
19 
20 #ifndef LOCALEPREFERENCES_H
21 #define LOCALEPREFERENCES_H
22 
23 #include "Common.h"
24 
25 #include <string>
26 #include <lunaservice.h>
27 
28 #include "Mutex.h"
29 #include "CustomEvents.h"
30 
31 #include <QObject>
32 #include <QHash>
33 
34 class LocalePreferences : public QObject
35 {
36  Q_OBJECT
37 
38 public:
39  struct LocaleInfo {
40  QHash<QString, QString> locales;
41  QString timezone;
42  QString clock;
43  };
44 
45  static LocalePreferences* instance();
46 
48  QString uiLocale() const;
49 
51  QString locale(const QString &name) const;
52 
54  QString timezone() const;
55 
57  QString clock() const;
58 
60  LocaleInfo locales() const;
61 
62  std::string locale() const;
63  std::string localeRegion() const;
64  std::string phoneRegion() const;
65  std::string timeFormat() const;
66 
67 Q_SIGNALS:
68  void prefsLocaleChanged(void);
69  void signalTimeFormatChanged(const char* format);
70  void localeInfoChanged();
71 
72 private:
73 
76 
77  void registerService();
78  void init();
79 
80  static bool serverConnectCallback(LSHandle *sh, LSMessage *message, void *ctx);
81  static bool getPreferencesCallback(LSHandle *sh, LSMessage *message, void *ctx);
82  static bool getLocaleInfoCallback(LSHandle *sh, LSMessage *message, void *ctx);
83 
84  LocaleInfo m_locales;
85 
86  std::string m_locale;
87  std::string m_localeRegion;
88  std::string m_phoneRegion;
89  std::string m_currentTimeFormat;
90 
91  mutable Mutex m_mutex;
92  LSHandle* m_lsHandle;
93  LSMessageToken m_serverStatusToken;
94 };
95 
96 
97 #endif // LOCALEPREFERENCES_H