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.
9 #include <Application.h>
11 #include <CatalogData.h>
13 #include <MutableLocaleRoster.h>
18 using BPrivate::MutableLocaleRoster
;
21 //#pragma mark - BCatalog
30 BCatalog::BCatalog(const entry_ref
& catalogOwner
, const char* language
,
36 SetTo(catalogOwner
, language
, fingerprint
);
42 MutableLocaleRoster::Default()->UnloadCatalog(fCatalogData
);
47 BCatalog::GetString(const char* string
, const char* context
,
50 BAutolock
lock(&fLock
);
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
)
66 BCatalog::GetString(uint32 id
)
68 BAutolock
lock(&fLock
);
72 const char* translated
;
73 for (BCatalogData
* cat
= fCatalogData
; cat
!= NULL
; cat
= cat
->fNext
) {
74 translated
= cat
->GetString(id
);
75 if (translated
!= NULL
)
84 BCatalog::GetData(const char* name
, BMessage
* msg
)
86 BAutolock
lock(&fLock
);
90 if (fCatalogData
== NULL
)
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
;
105 BCatalog::GetData(uint32 id
, BMessage
* msg
)
107 BAutolock
lock(&fLock
);
108 if (!lock
.IsLocked())
111 if (fCatalogData
== NULL
)
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
;
126 BCatalog::GetSignature(BString
* sig
)
128 BAutolock
lock(&fLock
);
129 if (!lock
.IsLocked())
135 if (fCatalogData
== NULL
)
138 *sig
= fCatalogData
->fSignature
;
145 BCatalog::GetLanguage(BString
* lang
)
147 BAutolock
lock(&fLock
);
148 if (!lock
.IsLocked())
154 if (fCatalogData
== NULL
)
157 *lang
= fCatalogData
->fLanguageName
;
164 BCatalog::GetFingerprint(uint32
* fp
)
166 BAutolock
lock(&fLock
);
167 if (!lock
.IsLocked())
173 if (fCatalogData
== NULL
)
176 *fp
= fCatalogData
->fFingerprint
;
183 BCatalog::SetTo(const entry_ref
& catalogOwner
, const char* language
,
186 BAutolock
lock(&fLock
);
187 if (!lock
.IsLocked())
190 MutableLocaleRoster::Default()->UnloadCatalog(fCatalogData
);
191 fCatalogData
= MutableLocaleRoster::Default()->LoadCatalog(catalogOwner
,
192 language
, fingerprint
);
199 BCatalog::InitCheck() const
201 BAutolock
lock(&fLock
);
202 if (!lock
.IsLocked())
205 return fCatalogData
!= NULL
? fCatalogData
->InitCheck() : B_NO_INIT
;
210 BCatalog::CountItems() const
212 BAutolock
lock(&fLock
);
213 if (!lock
.IsLocked())
216 return fCatalogData
!= NULL
? fCatalogData
->CountItems() : 0;