haiku/headers/private/locale/MutableLocaleRoster.h
Oliver Tappe 6fd2f4a0d1 One more monster commit (sorry ...) concerning the Locale Kit:
* extracted new class BFormattingConventions from BCountry, which
  manages the formatting conventions from a given locale and 
  allows to get/set the four different date/time formats supported
  by ICU-locales as well as number and monetary formats
* overhauled the Locale preflet:
  + drop editing features for all formats, since I don't think
    they do not make much sense to have in a prefs GUI - being
    able to select from the existing locales should be good
    enough. Please note that you can still change the formats
    programmatically in an application.
  + renamed the 'Countries' tab to 'Formatting'
  + the locale formatting conventions list in the 'Formatting'
    tab is now hierarchical for easier access (less scrolling)
  + fixed functionality of 'Revert' and 'Defaults' buttons
  + added support for using the month/day-names of your preferred
    language during date formatting
* adjusted BLocale to ask BFormattingConventions for the current
  formats when formatting dates and times and to offer 4
  different format styles (full, long, medium and short).
* adjust all classes formatting dates/times to pick the 
  appropriate format style
* BLocaleRoster no longer directly archives/unarchives the 
  individual formatting conventions but delegates that to
  BFormattingConventions
    

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39123 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-10-24 12:57:55 +00:00

160 lines
4.0 KiB
C++

/*
* Copyright 2010, Haiku. All rights reserved.
* Distributed under the terms of the MIT license.
*/
#ifndef _MUTABLE_LOCALE_ROSTER_H_
#define _MUTABLE_LOCALE_ROSTER_H_
#include <Collator.h>
#include <FormattingConventions.h>
#include <image.h>
#include <Language.h>
#include <List.h>
#include <Locale.h>
#include <Locker.h>
#include <LocaleRoster.h>
#include <Message.h>
#include <Resources.h>
#include <TimeZone.h>
class BLocale;
class BCatalog;
class BCatalogAddOn;
struct entry_ref;
namespace BPrivate {
class MutableLocaleRoster : public BLocaleRoster {
public:
MutableLocaleRoster();
~MutableLocaleRoster();
status_t SetDefaultFormattingConventions(
const BFormattingConventions& conventions);
status_t SetDefaultTimeZone(const BTimeZone& zone);
status_t SetPreferredLanguages(const BMessage* message);
// the message contains one or more
// 'language'-string-fields which
// contain the language-name(s)
status_t GetSystemCatalog(BCatalogAddOn** catalog) const;
BCatalogAddOn* LoadCatalog(const char* signature,
const char* language = NULL,
int32 fingerprint = 0) const;
BCatalogAddOn* LoadEmbeddedCatalog(entry_ref* appOrAddOnRef);
status_t UnloadCatalog(BCatalogAddOn* addOn);
BCatalogAddOn* CreateCatalog(const char* type,
const char* signature,
const char* language);
};
extern MutableLocaleRoster* gMutableLocaleRoster;
typedef BCatalogAddOn* (*InstantiateCatalogFunc)(const char* name,
const char* language, uint32 fingerprint);
typedef BCatalogAddOn* (*CreateCatalogFunc)(const char* name,
const char* language);
typedef BCatalogAddOn* (*InstantiateEmbeddedCatalogFunc)(
entry_ref* appOrAddOnRef);
typedef status_t (*GetAvailableLanguagesFunc)(BMessage*, const char*,
const char*, int32);
/*
* info about a single catalog-add-on (representing a catalog type):
*/
struct CatalogAddOnInfo {
InstantiateCatalogFunc fInstantiateFunc;
InstantiateEmbeddedCatalogFunc fInstantiateEmbeddedFunc;
CreateCatalogFunc fCreateFunc;
GetAvailableLanguagesFunc fLanguagesFunc;
BString fName;
BString fPath;
image_id fAddOnImage;
uint8 fPriority;
BList fLoadedCatalogs;
bool fIsEmbedded;
// an embedded add-on actually isn't an
// add-on, it is included as part of the
// library.
// The DefaultCatalog is such a beast!
CatalogAddOnInfo(const BString& name,
const BString& path, uint8 priority);
~CatalogAddOnInfo();
bool MakeSureItsLoaded();
void UnloadIfPossible();
};
/*
* The global data that is shared between all roster-objects of a process.
*/
struct RosterData {
BLocker fLock;
BList fCatalogAddOnInfos;
BMessage fPreferredLanguages;
BLocale fDefaultLocale;
BTimeZone fDefaultTimeZone;
bool fAreResourcesLoaded;
BResources fResources;
RosterData();
~RosterData();
void InitializeCatalogAddOns();
void CleanupCatalogAddOns();
status_t Refresh();
static int CompareInfos(const void* left,
const void* right);
status_t SetDefaultFormattingConventions(
const BFormattingConventions& convetions);
status_t SetDefaultTimeZone(const BTimeZone& zone);
status_t SetPreferredLanguages(const BMessage* msg);
private:
status_t _LoadLocaleSettings();
status_t _SaveLocaleSettings();
status_t _LoadTimeSettings();
status_t _SaveTimeSettings();
status_t _SetDefaultFormattingConventions(
const BFormattingConventions& conventions);
status_t _SetDefaultTimeZone(const BTimeZone& zone);
status_t _SetPreferredLanguages(const BMessage* msg);
status_t _AddDefaultFormattingConventionsToMessage(
BMessage* message) const;
status_t _AddDefaultTimeZoneToMessage(
BMessage* message) const;
status_t _AddPreferredLanguagesToMessage(
BMessage* message) const;
};
extern RosterData gRosterData;
} // namespace BPrivate
#endif // _MUTABLE_LOCALE_ROSTER_H_