1 /* 2 ** Distributed under the terms of the OpenBeOS License. 3 ** Copyright 2003-2004. All rights reserved. 4 ** 5 ** Authors: Axel Dörfler, axeld@pinc-software.de 6 ** Oliver Tappe, zooey@hirschkaefer.de 7 */ 8 9 #include <syslog.h> 10 11 #include <Application.h> 12 #include <Catalog.h> 13 #include <Locale.h> 14 #include <LocaleRoster.h> 15 #include <Node.h> 16 #include <Roster.h> 17 18 19 BCatalog* be_catalog = NULL; 20 // catalog used by translation macros 21 BCatalog* be_app_catalog = NULL; 22 // app-catalog (useful for accessing app's catalog from inside an add-on, 23 // since in an add-on, be_catalog will hold the add-on's catalog. 24 25 26 //#pragma mark - BCatalog 27 BCatalog::BCatalog() 28 : 29 fCatalog(NULL) 30 { 31 } 32 33 34 BCatalog::BCatalog(const entry_ref& catalogOwner, const char *language, 35 uint32 fingerprint) 36 { 37 // Unsupported - the build tools can't (and don't need to) load anything 38 // this way. 39 } 40 41 42 BCatalog::~BCatalog() 43 { 44 if (be_catalog == this) 45 be_app_catalog = be_catalog = NULL; 46 //be_locale_roster->UnloadCatalog(fCatalog); 47 } 48 49 50 const char * 51 BCatalog::GetString(const char *string, const char *context, const char *comment) 52 { 53 const char *translated; 54 for (BCatalogAddOn* cat = fCatalog; cat != NULL; cat = cat->fNext) { 55 translated = cat->GetString(string, context, comment); 56 if (translated) 57 return translated; 58 } 59 return string; 60 } 61 62 63 const char * 64 BCatalog::GetString(uint32 id) 65 { 66 const char *translated; 67 for (BCatalogAddOn* cat = fCatalog; cat != NULL; cat = cat->fNext) { 68 translated = cat->GetString(id); 69 if (translated) 70 return translated; 71 } 72 return ""; 73 } 74 75 76 status_t 77 BCatalog::GetData(const char *name, BMessage *msg) 78 { 79 if (!fCatalog) 80 return B_NO_INIT; 81 status_t res; 82 for (BCatalogAddOn* cat = fCatalog; cat != NULL; cat = cat->fNext) { 83 res = cat->GetData(name, msg); 84 if (res != B_NAME_NOT_FOUND && res != EOPNOTSUPP) 85 return res; 86 // return B_OK if found, or specific error-code 87 } 88 return B_NAME_NOT_FOUND; 89 } 90 91 92 status_t 93 BCatalog::GetData(uint32 id, BMessage *msg) 94 { 95 if (!fCatalog) 96 return B_NO_INIT; 97 status_t res; 98 for (BCatalogAddOn* cat = fCatalog; cat != NULL; cat = cat->fNext) { 99 res = cat->GetData(id, msg); 100 if (res != B_NAME_NOT_FOUND && res != EOPNOTSUPP) 101 return res; 102 // return B_OK if found, or specific error-code 103 } 104 return B_NAME_NOT_FOUND; 105 } 106 107 108 //#pragma mark - BCatalogAddOn 109 BCatalogAddOn::BCatalogAddOn(const char *signature, const char *language, 110 uint32 fingerprint) 111 : 112 fInitCheck(B_NO_INIT), 113 fSignature(signature), 114 fLanguageName(language), 115 fFingerprint(fingerprint), 116 fNext(NULL) 117 { 118 fLanguageName.ToLower(); 119 // canonicalize language-name to lowercase 120 } 121 122 123 BCatalogAddOn::~BCatalogAddOn() 124 { 125 } 126 127 128 void 129 BCatalogAddOn::UpdateFingerprint() 130 { 131 fFingerprint = 0; 132 // base implementation always yields the same fingerprint, 133 // which means that no version-mismatch detection is possible. 134 } 135 136 137 status_t 138 BCatalogAddOn::InitCheck() const 139 { 140 return fInitCheck; 141 } 142 143 144 bool 145 BCatalogAddOn::CanHaveData() const 146 { 147 return false; 148 } 149 150 151 status_t 152 BCatalogAddOn::GetData(const char *name, BMessage *msg) 153 { 154 return EOPNOTSUPP; 155 } 156 157 158 status_t 159 BCatalogAddOn::GetData(uint32 id, BMessage *msg) 160 { 161 return EOPNOTSUPP; 162 } 163 164 165 status_t 166 BCatalogAddOn::SetString(const char *string, const char *translated, 167 const char *context, const char *comment) 168 { 169 return EOPNOTSUPP; 170 } 171 172 173 status_t 174 BCatalogAddOn::SetString(int32 id, const char *translated) 175 { 176 return EOPNOTSUPP; 177 } 178 179 180 bool 181 BCatalogAddOn::CanWriteData() const 182 { 183 return false; 184 } 185 186 187 status_t 188 BCatalogAddOn::SetData(const char *name, BMessage *msg) 189 { 190 return EOPNOTSUPP; 191 } 192 193 194 status_t 195 BCatalogAddOn::SetData(uint32 id, BMessage *msg) 196 { 197 return EOPNOTSUPP; 198 } 199 200 201 status_t 202 BCatalogAddOn::ReadFromFile(const char *path) 203 { 204 return EOPNOTSUPP; 205 } 206 207 208 status_t 209 BCatalogAddOn::ReadFromAttribute(const entry_ref &appOrAddOnRef) 210 { 211 return EOPNOTSUPP; 212 } 213 214 215 status_t 216 BCatalogAddOn::ReadFromResource(const entry_ref &appOrAddOnRef) 217 { 218 return EOPNOTSUPP; 219 } 220 221 222 status_t 223 BCatalogAddOn::WriteToFile(const char *path) 224 { 225 return EOPNOTSUPP; 226 } 227 228 229 status_t 230 BCatalogAddOn::WriteToAttribute(const entry_ref &appOrAddOnRef) 231 { 232 return EOPNOTSUPP; 233 } 234 235 236 status_t 237 BCatalogAddOn::WriteToResource(const entry_ref &appOrAddOnRef) 238 { 239 return EOPNOTSUPP; 240 } 241 242 243 void BCatalogAddOn::MakeEmpty() 244 { 245 } 246 247 248 int32 249 BCatalogAddOn::CountItems() const 250 { 251 return 0; 252 } 253