Vesna
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ApplicationLanguageSwitcher.h
Go to the documentation of this file.
1 #ifndef APPLICATIONLANGUAGESWITCHER_H
2 #define APPLICATIONLANGUAGESWITCHER_H
3 
4 #include <functional>
5 
6 #include "core/common/ESingleton.h"
8 
10 
15 {
16 public:
17  using OnLeavingScopeFunction = std::function<bool()>;
18 
19  OnLeavingScope( const OnLeavingScope & ) = delete; // prevent copying
20  OnLeavingScope &operator=( const OnLeavingScope & ) = delete;
21 
22  OnLeavingScope( const OnLeavingScopeFunction &f ) : mFunction( f ) {}
24  {
25  mFunction();
26  }
27 
28 private:
29  OnLeavingScopeFunction mFunction;
30 };
31 
36 class ApplicationLanguageSwitcher : public ESingleton <ApplicationLanguageSwitcher>
37 {
38 public:
46 
52 
53 private:
56  virtual ~ApplicationLanguageSwitcher();
57  bool SetApplicationLanguageManagerInstance( ApplicationLanguageManager *applicationLanguageManager ); // ApplicationLanguageManager is responsible for instance creation and correct initialization
58 
59  friend class ESingleton<ApplicationLanguageSwitcher>;
60  friend class ApplicationLanguageManager;
61 
62  class DataClass;
63  QScopedPointer<DataClass> d;
65 };
66 
67 // by using this define it is possible to set default (startup) language as temporary language without obligation to manually reset language to global language (reset to global language is called automatically, when usage of this define gets out of scope)
68 #define SET_DEFAULT_TEMPORARY_LANGUAGE_WHILE_IN_SCOPE \
69  ApplicationLanguageSwitcher::GetInstance().SetDefaultTemporaryLanguage(); \
70  OnLeavingScope scope( [](){ return ApplicationLanguageSwitcher::GetInstance().ResetTemporaryLanguageToGlobal(); } );
71 
72 #endif // APPLICATIONLANGUAGESWITCHER_H
Definition: ApplicationLanguageManager.h:9
std::function< bool()> OnLeavingScopeFunction
Definition: ApplicationLanguageSwitcher.h:17
OnLeavingScope & operator=(const OnLeavingScope &)=delete
The ApplicationLanguageSwitcher class - this class is used for temporary language changes...
Definition: ApplicationLanguageSwitcher.h:36
~OnLeavingScope()
Definition: ApplicationLanguageSwitcher.h:23
OnLeavingScope(const OnLeavingScopeFunction &f)
Definition: ApplicationLanguageSwitcher.h:22
bool ResetTemporaryLanguageToGlobal()
ResetTemporaryLanguageToGlobal - method resets previously set temporary language to global language...
Definition: ApplicationLanguageSwitcher.cpp:42
bool SetDefaultTemporaryLanguage()
SetDefaultTemporaryLanguage - this method is used to temporary change current language to default lan...
Definition: ApplicationLanguageSwitcher.cpp:32
Definition: ApplicationLanguageSwitcher.cpp:7
The OnLeavingScope class - class which purpose is call assigned function, when class instance leaves ...
Definition: ApplicationLanguageSwitcher.h:14
OnLeavingScope(const OnLeavingScope &)=delete