160f75e90SOliver Tappe /* 260f75e90SOliver Tappe * This file contains library initialization code. 360f75e90SOliver Tappe * The required mimetypes and attribute-indices are created here. 460f75e90SOliver Tappe */ 560f75e90SOliver Tappe 660f75e90SOliver Tappe #include <fs_attr.h> 760f75e90SOliver Tappe #include <fs_index.h> 860f75e90SOliver Tappe #include <Volume.h> 960f75e90SOliver Tappe #include <VolumeRoster.h> 1060f75e90SOliver Tappe 1160f75e90SOliver Tappe #include <DefaultCatalog.h> 1260f75e90SOliver Tappe #include <MutableLocaleRoster.h> 1360f75e90SOliver Tappe #include <SystemCatalog.h> 1460f75e90SOliver Tappe 1560f75e90SOliver Tappe 1660f75e90SOliver Tappe namespace BPrivate { 1760f75e90SOliver Tappe 18eaa5e093SOliver Tappe BCatalog gSystemCatalog; 1960f75e90SOliver Tappe 2060f75e90SOliver Tappe } 2160f75e90SOliver Tappe 2260f75e90SOliver Tappe 235ac65b7fSOliver Tappe using BPrivate::DefaultCatalog; 245ac65b7fSOliver Tappe using BPrivate::MutableLocaleRoster; 255ac65b7fSOliver Tappe using BPrivate::gSystemCatalog; 265ac65b7fSOliver Tappe 275ac65b7fSOliver Tappe 2860f75e90SOliver Tappe // helper function that makes sure an attribute-index exists: 2960f75e90SOliver Tappe static void EnsureIndexExists(const char *attrName) 3060f75e90SOliver Tappe { 3160f75e90SOliver Tappe BVolume bootVol; 3260f75e90SOliver Tappe BVolumeRoster volRoster; 3360f75e90SOliver Tappe if (volRoster.GetBootVolume(&bootVol) != B_OK) 3460f75e90SOliver Tappe return; 3560f75e90SOliver Tappe struct index_info idxInfo; 36*93b5e561SOliver Tappe if (fs_stat_index(bootVol.Device(), attrName, &idxInfo) != 0) 37*93b5e561SOliver Tappe fs_create_index(bootVol.Device(), attrName, B_STRING_TYPE, 0); 3860f75e90SOliver Tappe } 3960f75e90SOliver Tappe 4060f75e90SOliver Tappe 4160f75e90SOliver Tappe /* 4260f75e90SOliver Tappe * prepares the system for use by the Locale Kit catalogs, 4360f75e90SOliver Tappe * it makes sure that the required indices and mimetype exist: 4460f75e90SOliver Tappe */ 4560f75e90SOliver Tappe static void 4660f75e90SOliver Tappe SetupCatalogBasics() 4760f75e90SOliver Tappe { 4860f75e90SOliver Tappe // make sure the indices required for catalog-traversal are there: 4960f75e90SOliver Tappe EnsureIndexExists(BLocaleRoster::kCatLangAttr); 5060f75e90SOliver Tappe EnsureIndexExists(BLocaleRoster::kCatSigAttr); 5160f75e90SOliver Tappe 5260f75e90SOliver Tappe // install mimetype for default-catalog: 5360f75e90SOliver Tappe BMimeType mt; 5460f75e90SOliver Tappe status_t res = mt.SetTo(DefaultCatalog::kCatMimeType); 5560f75e90SOliver Tappe if (res == B_OK && !mt.IsInstalled()) { 5660f75e90SOliver Tappe // install supertype, if it isn't available 5760f75e90SOliver Tappe BMimeType supertype; 5860f75e90SOliver Tappe res = mt.GetSupertype(&supertype); 5960f75e90SOliver Tappe if (res == B_OK && !supertype.IsInstalled()) { 6060f75e90SOliver Tappe res = supertype.Install(); 6160f75e90SOliver Tappe } 6260f75e90SOliver Tappe 6360f75e90SOliver Tappe if (res == B_OK) { 6460f75e90SOliver Tappe // info about the attributes of a catalog... 6560f75e90SOliver Tappe BMessage attrMsg; 6660f75e90SOliver Tappe // ...the catalog signature... 6760f75e90SOliver Tappe attrMsg.AddString("attr:public_name", "Signature"); 6860f75e90SOliver Tappe attrMsg.AddString("attr:name", BLocaleRoster::kCatSigAttr); 6960f75e90SOliver Tappe attrMsg.AddInt32("attr:type", B_STRING_TYPE); 7060f75e90SOliver Tappe attrMsg.AddBool("attr:editable", false); 7160f75e90SOliver Tappe attrMsg.AddBool("attr:viewable", true); 7260f75e90SOliver Tappe attrMsg.AddBool("attr:extra", false); 7360f75e90SOliver Tappe attrMsg.AddInt32("attr:alignment", 0); 7460f75e90SOliver Tappe attrMsg.AddInt32("attr:width", 140); 7560f75e90SOliver Tappe // ...the catalog language... 7660f75e90SOliver Tappe attrMsg.AddString("attr:public_name", "Language"); 7760f75e90SOliver Tappe attrMsg.AddString("attr:name", BLocaleRoster::kCatLangAttr); 7860f75e90SOliver Tappe attrMsg.AddInt32("attr:type", B_STRING_TYPE); 7960f75e90SOliver Tappe attrMsg.AddBool("attr:editable", false); 8060f75e90SOliver Tappe attrMsg.AddBool("attr:viewable", true); 8160f75e90SOliver Tappe attrMsg.AddBool("attr:extra", false); 8260f75e90SOliver Tappe attrMsg.AddInt32("attr:alignment", 0); 8360f75e90SOliver Tappe attrMsg.AddInt32("attr:width", 60); 8460f75e90SOliver Tappe // ...and the catalog fingerprint... 8560f75e90SOliver Tappe attrMsg.AddString("attr:public_name", "Fingerprint"); 8660f75e90SOliver Tappe attrMsg.AddString("attr:name", BLocaleRoster::kCatFingerprintAttr); 8760f75e90SOliver Tappe attrMsg.AddInt32("attr:type", B_INT32_TYPE); 8860f75e90SOliver Tappe attrMsg.AddBool("attr:editable", false); 8960f75e90SOliver Tappe attrMsg.AddBool("attr:viewable", true); 9060f75e90SOliver Tappe attrMsg.AddBool("attr:extra", false); 9160f75e90SOliver Tappe attrMsg.AddInt32("attr:alignment", 0); 9260f75e90SOliver Tappe attrMsg.AddInt32("attr:width", 70); 9360f75e90SOliver Tappe res = mt.SetAttrInfo(&attrMsg); 9460f75e90SOliver Tappe } 9560f75e90SOliver Tappe 9660f75e90SOliver Tappe if (res == B_OK) { 9760f75e90SOliver Tappe // file extensions (.catalog): 9860f75e90SOliver Tappe BMessage extMsg; 9960f75e90SOliver Tappe extMsg.AddString("extensions", "catalog"); 10060f75e90SOliver Tappe res = mt.SetFileExtensions(&extMsg); 10160f75e90SOliver Tappe } 10260f75e90SOliver Tappe 10360f75e90SOliver Tappe if (res == B_OK) { 10460f75e90SOliver Tappe // short and long descriptions: 10560f75e90SOliver Tappe mt.SetShortDescription("Translation Catalog"); 10660f75e90SOliver Tappe res = mt.SetLongDescription("Catalog with translated application resources"); 10760f75e90SOliver Tappe } 10860f75e90SOliver Tappe 10960f75e90SOliver Tappe if (res == B_OK) 11060f75e90SOliver Tappe res = mt.Install(); 11160f75e90SOliver Tappe } 11260f75e90SOliver Tappe } 11360f75e90SOliver Tappe 11460f75e90SOliver Tappe 11560f75e90SOliver Tappe void 11660f75e90SOliver Tappe __initialize_locale_kit() 11760f75e90SOliver Tappe { 11860f75e90SOliver Tappe SetupCatalogBasics(); 11960f75e90SOliver Tappe 1205ac65b7fSOliver Tappe MutableLocaleRoster::Default()->LoadSystemCatalog(&gSystemCatalog); 12160f75e90SOliver Tappe } 122