RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / kits / locale / Catalog.cpp
blob25c2104755d11f8131ed2e13e45baca41bf248a0
1 /*
2 * Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de
3 * Copyright 2003-2004,2012, Oliver Tappe, zooey@hirschkaefer.de
4 * Distributed under the terms of the MIT License.
5 */
7 #include <Catalog.h>
9 #include <Application.h>
10 #include <Autolock.h>
11 #include <CatalogData.h>
12 #include <Locale.h>
13 #include <MutableLocaleRoster.h>
14 #include <Node.h>
15 #include <Roster.h>
18 using BPrivate::MutableLocaleRoster;
21 //#pragma mark - BCatalog
22 BCatalog::BCatalog()
24 fCatalogData(NULL),
25 fLock("Catalog")
30 BCatalog::BCatalog(const entry_ref& catalogOwner, const char* language,
31 uint32 fingerprint)
33 fCatalogData(NULL),
34 fLock("Catalog")
36 SetTo(catalogOwner, language, fingerprint);
40 BCatalog::~BCatalog()
42 MutableLocaleRoster::Default()->UnloadCatalog(fCatalogData);
46 const char*
47 BCatalog::GetString(const char* string, const char* context,
48 const char* comment)
50 BAutolock lock(&fLock);
51 if (!lock.IsLocked())
52 return string;
54 const char* translated;
55 for (BCatalogData* cat = fCatalogData; cat != NULL; cat = cat->fNext) {
56 translated = cat->GetString(string, context, comment);
57 if (translated != NULL)
58 return translated;
61 return string;
65 const char*
66 BCatalog::GetString(uint32 id)
68 BAutolock lock(&fLock);
69 if (!lock.IsLocked())
70 return "";
72 const char* translated;
73 for (BCatalogData* cat = fCatalogData; cat != NULL; cat = cat->fNext) {
74 translated = cat->GetString(id);
75 if (translated != NULL)
76 return translated;
79 return "";
83 status_t
84 BCatalog::GetData(const char* name, BMessage* msg)
86 BAutolock lock(&fLock);
87 if (!lock.IsLocked())
88 return B_ERROR;
90 if (fCatalogData == NULL)
91 return B_NO_INIT;
93 status_t res;
94 for (BCatalogData* cat = fCatalogData; cat != NULL; cat = cat->fNext) {
95 res = cat->GetData(name, msg);
96 if (res != B_NAME_NOT_FOUND && res != EOPNOTSUPP)
97 return res; // return B_OK if found, or specific error-code
100 return B_NAME_NOT_FOUND;
104 status_t
105 BCatalog::GetData(uint32 id, BMessage* msg)
107 BAutolock lock(&fLock);
108 if (!lock.IsLocked())
109 return B_ERROR;
111 if (fCatalogData == NULL)
112 return B_NO_INIT;
114 status_t res;
115 for (BCatalogData* cat = fCatalogData; cat != NULL; cat = cat->fNext) {
116 res = cat->GetData(id, msg);
117 if (res != B_NAME_NOT_FOUND && res != EOPNOTSUPP)
118 return res; // return B_OK if found, or specific error-code
121 return B_NAME_NOT_FOUND;
125 status_t
126 BCatalog::GetSignature(BString* sig)
128 BAutolock lock(&fLock);
129 if (!lock.IsLocked())
130 return B_ERROR;
132 if (sig == NULL)
133 return B_BAD_VALUE;
135 if (fCatalogData == NULL)
136 return B_NO_INIT;
138 *sig = fCatalogData->fSignature;
140 return B_OK;
144 status_t
145 BCatalog::GetLanguage(BString* lang)
147 BAutolock lock(&fLock);
148 if (!lock.IsLocked())
149 return B_ERROR;
151 if (lang == NULL)
152 return B_BAD_VALUE;
154 if (fCatalogData == NULL)
155 return B_NO_INIT;
157 *lang = fCatalogData->fLanguageName;
159 return B_OK;
163 status_t
164 BCatalog::GetFingerprint(uint32* fp)
166 BAutolock lock(&fLock);
167 if (!lock.IsLocked())
168 return B_ERROR;
170 if (fp == NULL)
171 return B_BAD_VALUE;
173 if (fCatalogData == NULL)
174 return B_NO_INIT;
176 *fp = fCatalogData->fFingerprint;
178 return B_OK;
182 status_t
183 BCatalog::SetTo(const entry_ref& catalogOwner, const char* language,
184 uint32 fingerprint)
186 BAutolock lock(&fLock);
187 if (!lock.IsLocked())
188 return B_ERROR;
190 MutableLocaleRoster::Default()->UnloadCatalog(fCatalogData);
191 fCatalogData = MutableLocaleRoster::Default()->LoadCatalog(catalogOwner,
192 language, fingerprint);
194 return B_OK;
198 status_t
199 BCatalog::InitCheck() const
201 BAutolock lock(&fLock);
202 if (!lock.IsLocked())
203 return B_ERROR;
205 return fCatalogData != NULL ? fCatalogData->InitCheck() : B_NO_INIT;
209 int32
210 BCatalog::CountItems() const
212 BAutolock lock(&fLock);
213 if (!lock.IsLocked())
214 return 0;
216 return fCatalogData != NULL ? fCatalogData->CountItems() : 0;