CTranslationManagerComp.h
Go to the documentation of this file.
1 #ifndef iqt_CTranslationManagerComp_included
2 #define iqt_CTranslationManagerComp_included
3 
4 
5 // Qt includes
6 #include <QtCore/QMap>
7 #include <QtCore/QString>
8 #include <QtCore/QTranslator>
9 
10 // ACF includes
11 #include <istd/TSmartPtr.h>
12 #include <icomp/CComponentBase.h>
14 #include <iprm/ISelectionParam.h>
15 #include <iprm/IOptionsList.h>
17 #include <ilog/TLoggerCompWrap.h>
18 
19 
20 namespace iqt
21 {
22 
23 
31  virtual public iqt::ITranslationManager,
32  virtual public iprm::IOptionsList
33 {
34 public:
36 
37  I_BEGIN_COMPONENT(CTranslationManagerComp);
38  I_REGISTER_INTERFACE(iqt::ITranslationManager);
39  I_REGISTER_INTERFACE(iprm::IOptionsList);
40  I_ASSIGN(m_translationFilePathAttrPtr, "TranslationFilePath", "Base file path got translations", true, "");
41  I_ASSIGN(m_translationFilePrefixAttrPtr, "TranslationFilePrefix", "Prefix of the translation file", true, "");
42  I_ASSIGN_MULTI_0(m_languagesAttrPtr, "LanguageIds", "List of language IDs in ISO-format", true);
43  I_ASSIGN_MULTI_0(m_languageNamesAttrPtr, "LanguageNames", "List of language names according to 'LanguageIds' attribute", false);
44  I_ASSIGN(m_slaveTranslationManagerCompPtr, "SlaveTranslationManager", "Slave translation manager", false, "SlaveTranslationManager");
45  I_ASSIGN(m_languageSelectionCompPtr, "LanguageSelection", "Language selection provider", false, "LanguageSelection");
46  I_ASSIGN_TO(m_languageSelectionModelCompPtr, m_languageSelectionCompPtr, false);
47  I_END_COMPONENT;
48 
53 
54  // reimplemented (icomp:CComponentBase)
55  virtual void OnComponentCreated();
56  virtual void OnComponentDestroyed();
57 
58  // reimplemented (iqt::ITranslationManager)
59  virtual const iprm::IOptionsList& GetLanguagesInfo() const;
60  virtual int GetCurrentLanguageIndex() const;
61  virtual const QTranslator* GetLanguageTranslator(int languageIndex) const;
62  virtual const ITranslationManager* GetSlaveTranslationManager() const;
63  virtual void SwitchLanguage(int languageIndex);
64  virtual void SetSystemLanguage();
65 
66  // reimplemented (iprm::IOptionsList)
67  virtual int GetOptionsFlags() const;
68  virtual int GetOptionsCount() const;
69  virtual QString GetOptionName(int index) const;
70  virtual QString GetOptionDescription(int index) const;
71  virtual QByteArray GetOptionId(int index) const;
72  virtual bool IsOptionEnabled(int index) const;
73 
74 private:
79  class LanguageSelectionObserver: public imod::TSingleModelObserverBase<iprm::ISelectionParam>
80  {
81  public:
82  explicit LanguageSelectionObserver(CTranslationManagerComp& parent);
83 
84  protected:
85  // reimplemented (imod::CSingleModelObserverBase)
86  virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
87 
88  private:
89  CTranslationManagerComp& m_parent;
90  };
91 
92 private:
93  I_ATTR(QString, m_translationFilePathAttrPtr);
94  I_ATTR(QByteArray, m_translationFilePrefixAttrPtr);
95  I_MULTIATTR(QByteArray, m_languagesAttrPtr);
96  I_MULTITEXTATTR(m_languageNamesAttrPtr);
97  I_REF(iqt::ITranslationManager, m_slaveTranslationManagerCompPtr);
98  I_REF(iprm::ISelectionParam, m_languageSelectionCompPtr);
99  I_REF(imod::IModel, m_languageSelectionModelCompPtr);
100 
101  struct Translator
102  {
103  istd::TSmartPtr<QTranslator> translatorPtr;
104  QString languageName;
105  QByteArray languageId;
106  };
107 
108  typedef QVector<Translator> TranslatorsList;
109 
110  TranslatorsList m_translatorsList;
111 
112  LanguageSelectionObserver m_selectionObserver;
113 
114  int m_currentLanguageIndex;
115 };
116 
117 
118 } // namespace iqt
119 
120 
121 #endif // !iqt_CTranslationManagerComp_included
122 
123 
virtual QString GetOptionDescription(int index) const
Get human readable description for a option with the index index.
virtual void SwitchLanguage(int languageIndex)
Switch the current language to the language with the index languageIndex.
virtual const iprm::IOptionsList & GetLanguagesInfo() const
Get the list of supported languages given as a list of options.
virtual int GetCurrentLanguageIndex() const
Get current language index.
virtual void OnComponentCreated()
virtual QByteArray GetOptionId(int index) const
Get option ID.
virtual const QTranslator * GetLanguageTranslator(int languageIndex) const
Get Qt translator for a given language.
virtual bool IsOptionEnabled(int index) const
Return true if the option is enabled and can be selected.
virtual QString GetOptionName(int index) const
Get name of specified option.
virtual const ITranslationManager * GetSlaveTranslationManager() const
Get slave translation manager, if set.
Constraints of selection from set of possibilities.
Definition: IOptionsList.h:22
Basic implementation for a single model observer with binding to concrete data object interface...
Wrapper provider of log-functionality for component based implementations.
virtual void SetSystemLanguage()
Set default system's language.
virtual int GetOptionsFlags() const
Get constraints flags.
virtual void OnComponentDestroyed()
Common interface for the localization manager.
ilog::CLoggerComponentBase BaseClass
A translation manager component.
virtual int GetOptionsCount() const
Get number of managed options.
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
Set of change flags (its IDs).
Definition: IChangeable.h:30
Interface allowing to select single option from list of options.
CTranslationManagerComp()
Default constructor.

© 2007-2017 Witold Gantzke and Kirill Lepskiy