1 /* 2 * This file contains library initialization code. 3 * The required mimetypes and attribute-indices are created here. 4 */ 5 6 #include <fs_attr.h> 7 #include <fs_index.h> 8 #include <Volume.h> 9 #include <VolumeRoster.h> 10 11 #include <DefaultCatalog.h> 12 #include <MutableLocaleRoster.h> 13 #include <SystemCatalog.h> 14 15 16 namespace BPrivate { 17 18 BCatalog gSystemCatalog; 19 20 } 21 22 23 using BPrivate::DefaultCatalog; 24 using BPrivate::MutableLocaleRoster; 25 using BPrivate::gSystemCatalog; 26 27 28 // helper function that makes sure an attribute-index exists: 29 static void EnsureIndexExists(const char *attrName) 30 { 31 BVolume bootVol; 32 BVolumeRoster volRoster; 33 if (volRoster.GetBootVolume(&bootVol) != B_OK) 34 return; 35 struct index_info idxInfo; 36 if (fs_stat_index(bootVol.Device(), attrName, &idxInfo) != 0) 37 fs_create_index(bootVol.Device(), attrName, B_STRING_TYPE, 0); 38 } 39 40 41 /* 42 * prepares the system for use by the Locale Kit catalogs, 43 * it makes sure that the required indices and mimetype exist: 44 */ 45 static void 46 SetupCatalogBasics() 47 { 48 // make sure the indices required for catalog-traversal are there: 49 EnsureIndexExists(BLocaleRoster::kCatLangAttr); 50 EnsureIndexExists(BLocaleRoster::kCatSigAttr); 51 52 // install mimetype for default-catalog: 53 BMimeType mt; 54 status_t res = mt.SetTo(DefaultCatalog::kCatMimeType); 55 if (res == B_OK && !mt.IsInstalled()) { 56 // install supertype, if it isn't available 57 BMimeType supertype; 58 res = mt.GetSupertype(&supertype); 59 if (res == B_OK && !supertype.IsInstalled()) { 60 res = supertype.Install(); 61 } 62 63 if (res == B_OK) { 64 // info about the attributes of a catalog... 65 BMessage attrMsg; 66 // ...the catalog signature... 67 attrMsg.AddString("attr:public_name", "Signature"); 68 attrMsg.AddString("attr:name", BLocaleRoster::kCatSigAttr); 69 attrMsg.AddInt32("attr:type", B_STRING_TYPE); 70 attrMsg.AddBool("attr:editable", false); 71 attrMsg.AddBool("attr:viewable", true); 72 attrMsg.AddBool("attr:extra", false); 73 attrMsg.AddInt32("attr:alignment", 0); 74 attrMsg.AddInt32("attr:width", 140); 75 // ...the catalog language... 76 attrMsg.AddString("attr:public_name", "Language"); 77 attrMsg.AddString("attr:name", BLocaleRoster::kCatLangAttr); 78 attrMsg.AddInt32("attr:type", B_STRING_TYPE); 79 attrMsg.AddBool("attr:editable", false); 80 attrMsg.AddBool("attr:viewable", true); 81 attrMsg.AddBool("attr:extra", false); 82 attrMsg.AddInt32("attr:alignment", 0); 83 attrMsg.AddInt32("attr:width", 60); 84 // ...and the catalog fingerprint... 85 attrMsg.AddString("attr:public_name", "Fingerprint"); 86 attrMsg.AddString("attr:name", BLocaleRoster::kCatFingerprintAttr); 87 attrMsg.AddInt32("attr:type", B_INT32_TYPE); 88 attrMsg.AddBool("attr:editable", false); 89 attrMsg.AddBool("attr:viewable", true); 90 attrMsg.AddBool("attr:extra", false); 91 attrMsg.AddInt32("attr:alignment", 0); 92 attrMsg.AddInt32("attr:width", 70); 93 res = mt.SetAttrInfo(&attrMsg); 94 } 95 96 if (res == B_OK) { 97 // file extensions (.catalog): 98 BMessage extMsg; 99 extMsg.AddString("extensions", "catalog"); 100 res = mt.SetFileExtensions(&extMsg); 101 } 102 103 if (res == B_OK) { 104 // short and long descriptions: 105 mt.SetShortDescription("Translation Catalog"); 106 res = mt.SetLongDescription("Catalog with translated application resources"); 107 } 108 109 if (res == B_OK) 110 res = mt.Install(); 111 } 112 } 113 114 115 void 116 __initialize_locale_kit() 117 { 118 SetupCatalogBasics(); 119 120 MutableLocaleRoster::Default()->LoadSystemCatalog(&gSystemCatalog); 121 } 122