xref: /haiku/headers/private/locale/MutableLocaleRoster.h (revision 6fd2f4a0d14b45a316defe994e9790de062ff3ff)
138ac8defSOliver Tappe /*
238ac8defSOliver Tappe  * Copyright 2010, Haiku. All rights reserved.
338ac8defSOliver Tappe  * Distributed under the terms of the MIT license.
438ac8defSOliver Tappe  */
538ac8defSOliver Tappe #ifndef _MUTABLE_LOCALE_ROSTER_H_
638ac8defSOliver Tappe #define _MUTABLE_LOCALE_ROSTER_H_
738ac8defSOliver Tappe 
838ac8defSOliver Tappe 
938ac8defSOliver Tappe #include <Collator.h>
10*6fd2f4a0SOliver Tappe #include <FormattingConventions.h>
1138ac8defSOliver Tappe #include <image.h>
1238ac8defSOliver Tappe #include <Language.h>
1338ac8defSOliver Tappe #include <List.h>
145c3a3034SAdrien Destugues #include <Locale.h>
1538ac8defSOliver Tappe #include <Locker.h>
1638ac8defSOliver Tappe #include <LocaleRoster.h>
1738ac8defSOliver Tappe #include <Message.h>
18d1d8fda6SOliver Tappe #include <Resources.h>
1938ac8defSOliver Tappe #include <TimeZone.h>
2038ac8defSOliver Tappe 
2138ac8defSOliver Tappe 
2238ac8defSOliver Tappe class BLocale;
2338ac8defSOliver Tappe class BCatalog;
2438ac8defSOliver Tappe class BCatalogAddOn;
2538ac8defSOliver Tappe 
2638ac8defSOliver Tappe struct entry_ref;
2738ac8defSOliver Tappe 
2838ac8defSOliver Tappe 
2938ac8defSOliver Tappe namespace BPrivate {
3038ac8defSOliver Tappe 
3138ac8defSOliver Tappe 
3238ac8defSOliver Tappe class MutableLocaleRoster : public BLocaleRoster {
3338ac8defSOliver Tappe public:
3438ac8defSOliver Tappe 								MutableLocaleRoster();
3538ac8defSOliver Tappe 								~MutableLocaleRoster();
3638ac8defSOliver Tappe 
37*6fd2f4a0SOliver Tappe 			status_t			SetDefaultFormattingConventions(
38*6fd2f4a0SOliver Tappe 									const BFormattingConventions& conventions);
3938ac8defSOliver Tappe 			status_t			SetDefaultTimeZone(const BTimeZone& zone);
4038ac8defSOliver Tappe 
4138ac8defSOliver Tappe 			status_t			SetPreferredLanguages(const BMessage* message);
4238ac8defSOliver Tappe 									// the message contains one or more
4338ac8defSOliver Tappe 									// 'language'-string-fields which
4438ac8defSOliver Tappe 									// contain the language-name(s)
4538ac8defSOliver Tappe 
4638ac8defSOliver Tappe 			status_t			GetSystemCatalog(BCatalogAddOn** catalog) const;
4738ac8defSOliver Tappe 
4838ac8defSOliver Tappe 			BCatalogAddOn*		LoadCatalog(const char* signature,
4938ac8defSOliver Tappe 									const char* language = NULL,
5038ac8defSOliver Tappe 									int32 fingerprint = 0) const;
5138ac8defSOliver Tappe 			BCatalogAddOn*		LoadEmbeddedCatalog(entry_ref* appOrAddOnRef);
5238ac8defSOliver Tappe 			status_t			UnloadCatalog(BCatalogAddOn* addOn);
5338ac8defSOliver Tappe 
5438ac8defSOliver Tappe 			BCatalogAddOn*		CreateCatalog(const char* type,
5538ac8defSOliver Tappe 									const char* signature,
5638ac8defSOliver Tappe 									const char* language);
5738ac8defSOliver Tappe };
5838ac8defSOliver Tappe 
5938ac8defSOliver Tappe 
6034a79bffSOliver Tappe extern MutableLocaleRoster* gMutableLocaleRoster;
6138ac8defSOliver Tappe 
6238ac8defSOliver Tappe 
6338ac8defSOliver Tappe typedef BCatalogAddOn* (*InstantiateCatalogFunc)(const char* name,
6438ac8defSOliver Tappe 	const char* language, uint32 fingerprint);
6538ac8defSOliver Tappe 
6638ac8defSOliver Tappe typedef BCatalogAddOn* (*CreateCatalogFunc)(const char* name,
6738ac8defSOliver Tappe 	const char* language);
6838ac8defSOliver Tappe 
6938ac8defSOliver Tappe typedef BCatalogAddOn* (*InstantiateEmbeddedCatalogFunc)(
7038ac8defSOliver Tappe 	entry_ref* appOrAddOnRef);
7138ac8defSOliver Tappe 
7238ac8defSOliver Tappe typedef status_t (*GetAvailableLanguagesFunc)(BMessage*, const char*,
7338ac8defSOliver Tappe 	const char*, int32);
7438ac8defSOliver Tappe 
7538ac8defSOliver Tappe /*
7638ac8defSOliver Tappe  * info about a single catalog-add-on (representing a catalog type):
7738ac8defSOliver Tappe  */
7838ac8defSOliver Tappe struct CatalogAddOnInfo {
7938ac8defSOliver Tappe 			InstantiateCatalogFunc 			fInstantiateFunc;
8038ac8defSOliver Tappe 			InstantiateEmbeddedCatalogFunc	fInstantiateEmbeddedFunc;
8138ac8defSOliver Tappe 			CreateCatalogFunc				fCreateFunc;
8238ac8defSOliver Tappe 			GetAvailableLanguagesFunc 		fLanguagesFunc;
8338ac8defSOliver Tappe 
8438ac8defSOliver Tappe 			BString				fName;
8538ac8defSOliver Tappe 			BString				fPath;
8638ac8defSOliver Tappe 			image_id			fAddOnImage;
8738ac8defSOliver Tappe 			uint8				fPriority;
8838ac8defSOliver Tappe 			BList				fLoadedCatalogs;
8938ac8defSOliver Tappe 			bool				fIsEmbedded;
9038ac8defSOliver Tappe 									// an embedded add-on actually isn't an
9138ac8defSOliver Tappe 									// add-on, it is included as part of the
9238ac8defSOliver Tappe 									// library.
9338ac8defSOliver Tappe 									// The DefaultCatalog is such a beast!
9438ac8defSOliver Tappe 
9538ac8defSOliver Tappe 								CatalogAddOnInfo(const BString& name,
9638ac8defSOliver Tappe 									const BString& path, uint8 priority);
9738ac8defSOliver Tappe 								~CatalogAddOnInfo();
9838ac8defSOliver Tappe 
9938ac8defSOliver Tappe 			bool				MakeSureItsLoaded();
10038ac8defSOliver Tappe 			void				UnloadIfPossible();
10138ac8defSOliver Tappe };
10238ac8defSOliver Tappe 
10338ac8defSOliver Tappe 
10438ac8defSOliver Tappe /*
10538ac8defSOliver Tappe  * The global data that is shared between all roster-objects of a process.
10638ac8defSOliver Tappe  */
10738ac8defSOliver Tappe struct RosterData {
10838ac8defSOliver Tappe 			BLocker				fLock;
10938ac8defSOliver Tappe 			BList				fCatalogAddOnInfos;
11038ac8defSOliver Tappe 			BMessage			fPreferredLanguages;
11138ac8defSOliver Tappe 
1125c3a3034SAdrien Destugues 			BLocale				fDefaultLocale;
11338ac8defSOliver Tappe 			BTimeZone			fDefaultTimeZone;
11438ac8defSOliver Tappe 
115d1d8fda6SOliver Tappe 			bool				fAreResourcesLoaded;
116d1d8fda6SOliver Tappe 			BResources			fResources;
117d1d8fda6SOliver Tappe 
11838ac8defSOliver Tappe 								RosterData();
11938ac8defSOliver Tappe 								~RosterData();
12038ac8defSOliver Tappe 
12138ac8defSOliver Tappe 			void				InitializeCatalogAddOns();
12238ac8defSOliver Tappe 			void				CleanupCatalogAddOns();
12338ac8defSOliver Tappe 			status_t			Refresh();
12438ac8defSOliver Tappe 
12538ac8defSOliver Tappe 	static	int					CompareInfos(const void* left,
12638ac8defSOliver Tappe 									const void* right);
12738ac8defSOliver Tappe 
128*6fd2f4a0SOliver Tappe 			status_t			SetDefaultFormattingConventions(
129*6fd2f4a0SOliver Tappe 									const BFormattingConventions& convetions);
13038ac8defSOliver Tappe 			status_t			SetDefaultTimeZone(const BTimeZone& zone);
13138ac8defSOliver Tappe 			status_t			SetPreferredLanguages(const BMessage* msg);
13238ac8defSOliver Tappe private:
13338ac8defSOliver Tappe 			status_t			_LoadLocaleSettings();
13438ac8defSOliver Tappe 			status_t			_SaveLocaleSettings();
13538ac8defSOliver Tappe 
13638ac8defSOliver Tappe 			status_t			_LoadTimeSettings();
13738ac8defSOliver Tappe 			status_t			_SaveTimeSettings();
13838ac8defSOliver Tappe 
139*6fd2f4a0SOliver Tappe 			status_t			_SetDefaultFormattingConventions(
140*6fd2f4a0SOliver Tappe 									const BFormattingConventions& conventions);
14138ac8defSOliver Tappe 			status_t			_SetDefaultTimeZone(const BTimeZone& zone);
14238ac8defSOliver Tappe 			status_t			_SetPreferredLanguages(const BMessage* msg);
14338ac8defSOliver Tappe 
144*6fd2f4a0SOliver Tappe 			status_t			_AddDefaultFormattingConventionsToMessage(
14538ac8defSOliver Tappe 									BMessage* message) const;
14638ac8defSOliver Tappe 			status_t			_AddDefaultTimeZoneToMessage(
14738ac8defSOliver Tappe 									BMessage* message) const;
14838ac8defSOliver Tappe 			status_t			_AddPreferredLanguagesToMessage(
14938ac8defSOliver Tappe 									BMessage* message) const;
15038ac8defSOliver Tappe };
15138ac8defSOliver Tappe 
15238ac8defSOliver Tappe 
15338ac8defSOliver Tappe extern RosterData gRosterData;
15438ac8defSOliver Tappe 
15538ac8defSOliver Tappe 
15638ac8defSOliver Tappe }	// namespace BPrivate
15738ac8defSOliver Tappe 
15838ac8defSOliver Tappe 
15938ac8defSOliver Tappe #endif	// _MUTABLE_LOCALE_ROSTER_H_
160