void CamStatusView::AttachedToWindow() { if (fController->LockLooper()) { fController->StartWatching(this, kMsgControllerCaptureStarted); fController->StartWatching(this, kMsgControllerCaptureStopped); fController->StartWatching(this, kMsgControllerCapturePaused); fController->StartWatching(this, kMsgControllerCaptureResumed); fController->StartWatching(this, kMsgControllerEncodeStarted); fController->StartWatching(this, kMsgControllerEncodeProgress); fController->StartWatching(this, kMsgControllerEncodeFinished); fController->UnlockLooper(); } if (Parent()) SetViewColor(Parent()->ViewColor()); BResources* resources = be_app->AppResources(); size_t size; const void* buffer = resources->LoadResource('VICN', "record_icon", &size); if (buffer != NULL) BIconUtils::GetVectorIcon((uint8*)buffer, size, fRecordingBitmap); buffer = resources->LoadResource('VICN', "pause_icon", &size); if (buffer != NULL) BIconUtils::GetVectorIcon((uint8*)buffer, size, fPauseBitmap); fBitmapView->SetBitmap(NULL); }
bool ResourceToAttribute(BFile &file, BResources &res,type_code code, const char *name) { if (!name) return false; int32 id; size_t length; if (res.GetResourceInfo(code,name,&id,&length)) { const void *buffer = res.LoadResource(code,name,&length); if (!buffer) { STRACE(2,("Resource %s exists, but couldn't be loaded\n",name)); return false; } file.WriteAttr(name,code,0,buffer,length); STRACE(2,("Successfully wrote attribute %s\n",name)); return true; } else { STRACE(2,("Resource %s doesn't exist\n",name)); } return false; }
BBitmap* MediaAlert::InitIcon() { // The alert icons are in the app_server resources BBitmap* icon = NULL; BPath path; if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) { path.Append("app_server"); BFile file; if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK) { BResources resources; if (resources.SetTo(&file) == B_OK) { // Which icon are we trying to load? const char* iconName = "warn"; // Load the raw icon data size_t size; const void* rawIcon = resources.LoadResource(B_VECTOR_ICON_TYPE, iconName, &size); if (rawIcon != NULL) { // Now build the bitmap icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32); if (BIconUtils::GetVectorIcon((const uint8*)rawIcon, size, icon) != B_OK) { delete icon; return NULL; } } } } } return icon; }
BBitmap * BitmapUtils::LoadFromResource(int32 id) { BArchivable *archivable; BResources resources; BMessage message; const void *data; BBitmap *bitmap; app_info info; BFile file; size_t len; if (be_app->GetAppInfo(&info) != B_OK) return NULL; if (file.SetTo(&(info.ref), B_READ_ONLY) != B_OK) return NULL; if (resources.SetTo(&file, false) != B_OK) return NULL; data = resources.LoadResource('BBMP', id, &len); if (data == NULL || len <= 0) return NULL; if (message.Unflatten((const char *)data) != B_OK) return NULL; archivable = BBitmap::Instantiate(&message); if (archivable == NULL) return NULL; bitmap = dynamic_cast<BBitmap*>(archivable); if (bitmap == NULL) { delete archivable; return NULL; } return bitmap; }
BBitmap* AlertView::InitIcon() { // This is how BAlert gets to its icon BBitmap* icon = NULL; BPath path; if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) { path.Append("app_server"); BResources resources; BFile file; if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK && resources.SetTo(&file) == B_OK) { size_t size; const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, "warn", &size); if (data) { icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32); if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon) != B_OK) { delete icon; icon = NULL; } } } } return icon; }
// --------------------------------------------------------------- // GetBitmap // // Returns a BBitmap object for the bitmap resource identified by // the type type with the resource id, id. // The user has to delete this object. // // Preconditions: // // Parameters: type, the type of resource to be loaded // id, the id for the resource to be loaded // roster, BTranslatorRoster used to do the translation // // Postconditions: // // Returns: NULL, if the resource couldn't be loaded or couldn't // be translated to a BBitmap // BBitmap * to the bitmap identified by type and id // --------------------------------------------------------------- BBitmap * BTranslationUtils::GetBitmap(uint32 type, int32 id, BTranslatorRoster *roster) { BResources *pResources = BApplication::AppResources(); // Remember: pResources must not be freed because // it belongs to the application if (pResources == NULL || pResources->HasResource(type, id) == false) return NULL; // Load the bitmap resource from the application file // pRawData should be NULL if the resource is an // unknown type or not available size_t bitmapSize = 0; const void *kpRawData = pResources->LoadResource(type, id, &bitmapSize); if (kpRawData == NULL || bitmapSize == 0) return NULL; BMemoryIO memio(kpRawData, bitmapSize); // Put the pointer to the raw image data into a BMemoryIO object // so that it can be used with BTranslatorRoster->Translate() in // the GetBitmap(BPositionIO *, BTranslatorRoster *) function return GetBitmap(&memio, roster); // Translate the data in memio using the BTranslatorRoster roster }
void IconView::ShowIconHeap(bool show) { if (show == (fHeapIcon != NULL)) return; if (show) { BResources* resources = be_app->AppResources(); if (resources != NULL) { const void* data = NULL; size_t size; data = resources->LoadResource('VICN', "icon heap", &size); if (data != NULL) { // got vector icon data fHeapIcon = Icon::AllocateBitmap(B_LARGE_ICON, B_RGBA32); if (BIconUtils::GetVectorIcon((const uint8*)data, size, fHeapIcon) != B_OK) { // bad data delete fHeapIcon; fHeapIcon = NULL; data = NULL; } } if (data == NULL) { // no vector icon or failed to get bitmap // try bitmap icon data = resources->LoadResource(B_LARGE_ICON_TYPE, "icon heap", NULL); if (data != NULL) { fHeapIcon = Icon::AllocateBitmap(B_LARGE_ICON, B_CMAP8); if (fHeapIcon != NULL) { memcpy(fHeapIcon->Bits(), data, fHeapIcon->BitsLength()); } } } } } else { delete fHeapIcon; fHeapIcon = NULL; } }
BBitmap* SharedBitmap::_CreateBitmapFromResource(int32 size) const { BResources resources; status_t status = get_app_resources(resources); if (status != B_OK) return NULL; size_t dataSize; const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, fResourceID, &dataSize); if (data != NULL) return _LoadIconFromBuffer(data, dataSize, size); data = resources.LoadResource(B_MESSAGE_TYPE, fResourceID, &dataSize); if (data != NULL) return _LoadBitmapFromBuffer(data, dataSize); return NULL; }
TreeView::TreeView (float left, float top, const char *name, rgb_color backColor, BMessage *expanded, BMessage *collapsed, BMessage *midway, int8 index) : BView (BRect (left, top, left + 13, top + 13), name, B_FOLLOW_LEFT, B_WILL_DRAW | B_SUBPIXEL_PRECISE), collapsedMsg (collapsed), expandedMsg (expanded), midwayMsg (midway) { indexID = index; SetViewColor (backColor); /* This index helps our caller to make their superitem implementation completely generic and not hardcoded */ collapsedMsg->AddInt8 ("item_index", indexID); expandedMsg->AddInt8 ("item_index", indexID); midwayMsg->AddInt8 ("item_index", indexID); /* Load all the bitmaps from the resource file - No error checking for speed */ BResources *appRes = be_app->AppResources(); size_t bmpSize; BMessage msg; char *buf; buf = (char*)appRes->LoadResource ('BBMP', "Image:Collapsed", &bmpSize); msg.Unflatten (buf); collapsedBitmap = new BBitmap (&msg); buf = (char*)appRes->LoadResource ('BBMP', "Image:MidWay", &bmpSize); msg.Unflatten (buf); midwayBitmap = new BBitmap (&msg); buf = (char*)appRes->LoadResource ('BBMP', "Image:Expanded", &bmpSize); msg.Unflatten (buf); expandedBitmap = new BBitmap (&msg); /* Initially set the state as collapsed */ isExpanded = false; isMidWay = false; }
status_t TaskFS::SetUpMimeTyp(void) { status_t err; //set the MimeType BMimeType mime(TASK_MIMETYPE); //later do better check bool valid = mime.IsInstalled(); if (!valid) { mime.Install(); mime.SetShortDescription(B_TRANSLATE_CONTEXT("Tasks", "Short mimetype description")); mime.SetLongDescription(B_TRANSLATE_CONTEXT("Tasks", "Long mimetype description")); //get the icon from our Ressources BResources* res = BApplication::AppResources(); if (res != NULL){ size_t size; const void* data = res->LoadResource(B_VECTOR_ICON_TYPE, "TASK_ICON", &size); if (data!=NULL) mime.SetIcon(reinterpret_cast<const uint8*>(data), size); } mime.SetPreferredApp(APP_SIG); // add default task fields to meta-mime type BMessage fields; for (int32 i = 0; sDefaultAttributes[i].attribute; i++) { fields.AddString("attr:public_name", sDefaultAttributes[i].name); fields.AddString("attr:name", sDefaultAttributes[i].attribute); fields.AddInt32("attr:type", sDefaultAttributes[i].type); fields.AddString("attr:display_as", sDefaultAttributes[i].displayAs); fields.AddBool("attr:viewable", sDefaultAttributes[i].isPublic); fields.AddBool("attr:editable", sDefaultAttributes[i].editable); fields.AddInt32("attr:width", sDefaultAttributes[i].width); fields.AddInt32("attr:alignment", B_ALIGN_LEFT); fields.AddBool("attr:extra", false); } mime.SetAttrInfo(&fields); // create indices on all volumes for the found attributes. int32 count = 8; BVolumeRoster volumeRoster; BVolume volume; while (volumeRoster.GetNextVolume(&volume) == B_OK) { for (int32 i = 0; i < count; i++) { if (sDefaultAttributes[i].isPublic == true) fs_create_index(volume.Device(), sDefaultAttributes[i].attribute, sDefaultAttributes[i].type, 0); } } } else err = B_OK; return err; }
BBitmap* LoadVectorIcon(const char* name, int32 size) { BResources* res = BApplication::AppResources(); size_t length = 0; const void* data = res->LoadResource(B_VECTOR_ICON_TYPE, name, &length); BBitmap* dest = new BBitmap(BRect(0, 0, size, size), B_RGBA32); if (data != NULL && BIconUtils::GetVectorIcon((uint8*)data, length, dest) == B_OK) return dest; delete dest; return NULL; }
// read_boot_code_data static uint8 * read_boot_code_data(const char* programPath) { // open our executable BFile executableFile; status_t error = executableFile.SetTo(programPath, B_READ_ONLY); if (error != B_OK) { fprintf(stderr, "Error: Failed to open my executable file (\"%s\": " "%s\n", programPath, strerror(error)); exit(1); } uint8 *bootCodeData = new uint8[kBootCodeSize]; // open our resources BResources resources; error = resources.SetTo(&executableFile); const void *resourceData = NULL; if (error == B_OK) { // read the boot block from the resources size_t resourceSize; resourceData = resources.LoadResource(B_RAW_TYPE, 666, &resourceSize); if (resourceData && resourceSize != (size_t)kBootCodeSize) { resourceData = NULL; printf("Warning: Something is fishy with my resources! The boot " "code doesn't have the correct size. Trying the attribute " "instead ...\n"); } } if (resourceData) { // found boot data in the resources memcpy(bootCodeData, resourceData, kBootCodeSize); } else { // no boot data in the resources; try the attribute ssize_t bytesRead = executableFile.ReadAttr("BootCode", B_RAW_TYPE, 0, bootCodeData, kBootCodeSize); if (bytesRead < 0) { fprintf(stderr, "Error: Failed to read boot code from resources " "or attribute.\n"); exit(1); } if (bytesRead != kBootCodeSize) { fprintf(stderr, "Error: Failed to read boot code from resources, " "and the boot code in the attribute has the wrong size!\n"); exit(1); } } return bootCodeData; }
void PanelView::LoadResources(void) //////////////////////////////////////////////////////////////////////// { entry_ref ref; app_info info; m_ParentIcon = NULL; m_UnknownIcon = NULL; if (be_app->GetAppInfo(&info)==B_OK) { BFile file(&info.ref, B_READ_ONLY); if (file.InitCheck()==B_OK) { BResources rsrcs; size_t len = 0; if (rsrcs.SetTo(&file)==B_OK) { const void *data; data = rsrcs.LoadResource('MICN',1,&len); if (data) { m_ParentIcon = new unsigned char[len]; memcpy(m_ParentIcon,data,len); } data = rsrcs.LoadResource('MICN',2,&len); if (data) { m_UnknownIcon = new unsigned char[len]; memcpy(m_UnknownIcon,data,len); } } } } }
BBitmap *LoadLargeIcon(const char *name) { BResources *res = BApplication::AppResources(); if (res != NULL) { size_t length; const void *bits = res->LoadResource(icon, name, &length); if ((bits != NULL) && (length == B_LARGE_ICON * B_LARGE_ICON)) { BRect rect(0, 0, B_LARGE_ICON-1, B_LARGE_ICON-1); BBitmap *bitmap = new BBitmap(rect, B_CMAP8); bitmap->SetBits(bits, B_LARGE_ICON * B_LARGE_ICON, 0, B_CMAP8); return bitmap; } } return NULL; }
BBitmap *LoadMiniIcon(int32 id) { BResources *res = BApplication::AppResources(); if (res != NULL) { size_t length; const void *bits = res->LoadResource(miniIcon, id, &length); if ((bits != NULL) && (length == B_MINI_ICON * B_MINI_ICON)) { BRect rect(0, 0, B_MINI_ICON-1, B_MINI_ICON-1); BBitmap *bitmap = new BBitmap(rect, B_CMAP8); bitmap->SetBits(bits, B_MINI_ICON * B_MINI_ICON, 0, B_CMAP8); return bitmap; } } return NULL; }
BBitmap *getIconFromResources(const char *icon_resname) { BBitmap *bmp = NULL; BResources *res = be_app->AppResources(); if (res->HasResource('BBMP',icon_resname)) { printf("has resource bitmap [%s]\n",icon_resname); BMessage msg; size_t len; char *buf; buf = (char *)res->LoadResource('BBMP', icon_resname, &len); // printf("loaded,len=%i\n",len); msg.Unflatten(buf); bmp = new BBitmap(&msg); } return bmp; }
BBitmap* BrowserToolbar::_RetrieveBitmap(const char *name) { BResources *resource = BApplication::AppResources(); size_t size = 0; const void *data = resource->LoadResource('TBBM', name, &size); if (!data) return NULL; BBitmap *bitmap = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32); if (BIconUtils::GetVectorIcon((const uint8 *)data, size, bitmap) != B_OK) return NULL; return bitmap; }
DeviceWatcher::DeviceWatcher() : BLooper("MIDI devices watcher"), fDeviceEndpointsMap(), fVectorIconData(NULL), fVectorIconDataSize(0), fLargeIcon(NULL), fMiniIcon(NULL) { // Load midi endpoint vector icon data app_info info; be_app->GetAppInfo(&info); BFile file(&info.ref, B_READ_ONLY); BResources resources; if (resources.SetTo(&file) == B_OK) { size_t dataSize; // Load MIDI port endpoint vector icon const uint8* data = (const uint8*)resources.LoadResource( B_VECTOR_ICON_TYPE, "endpoint_vector_icon", &dataSize); if (data != NULL && dataSize > 0) fVectorIconData = new(std::nothrow) uint8[dataSize]; if (fVectorIconData) { // data is own by resources local object: copy its content for // later use memcpy(fVectorIconData, data, dataSize); fVectorIconDataSize = dataSize; } } // Render 32x32 and 16x16 B_CMAP8 icons for R5 compatibility if (fVectorIconData != NULL) { fLargeIcon = new(std::nothrow) BBitmap(BRect(0, 0, 31, 31), B_CMAP8); fMiniIcon = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), B_CMAP8); if (BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconDataSize, fLargeIcon) != B_OK) { delete fLargeIcon; fLargeIcon = NULL; } if (BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconDataSize, fMiniIcon) != B_OK) { delete fMiniIcon; fMiniIcon = NULL; } } Start(); }
status_t XColorsTable::_LoadXColorsTable() { BResources* res = BApplication::AppResources(); if (res == NULL) return B_ERROR; size_t size = 0; fTable = (_XColorEntry*)res->LoadResource(B_RAW_TYPE, "XColorsTable", &size); if (fTable == NULL || size < sizeof(_XColorEntry)) { fTable = NULL; return B_ENTRY_NOT_FOUND; } fCount = size / sizeof(_XColorEntry); return B_OK; }
BBitmap *LoadBitmap(const char *name, uint32 type_code) { if (type_code == B_TRANSLATOR_BITMAP) { return BTranslationUtils::GetBitmap(type_code, name); } else { BResources *res = BApplication::AppResources(); if (res != NULL) { size_t length; const void *bits = res->LoadResource(type_code, name, &length); BMessage m; if (bits && B_OK == m.Unflatten((char*)bits)) { BBitmap* bitmap = (BBitmap*)BBitmap::Instantiate(&m); return bitmap; } } return NULL; } }
bool ResourceData::SetFromResource(const int32 &index, BResources &res) { char *name; if (!res.GetResourceInfo(index, (type_code*)&fType, &fID, (const char **)&name, &fLength)) { *this = ResourceData(); return false; } fName = name; fTypeString = MakeTypeString(fType); fIDString = ""; fIDString << fID; fAttr = false; char *data = (char *)res.LoadResource(fType,fID,&fLength); SetData(data,fLength); return true; }
status_t BLocaleRoster::GetFlagIconForLanguage(BBitmap* flagIcon, const char* languageCode) { if (languageCode == NULL || languageCode[0] == '\0' || languageCode[1] == '\0') return B_BAD_VALUE; BAutolock lock(fData->fLock); if (!lock.IsLocked()) return B_ERROR; BResources* resources; status_t status = fData->GetResources(&resources); if (status != B_OK) return status; // Normalize the language code: first two letters, lowercase char normalizedCode[3]; normalizedCode[0] = tolower(languageCode[0]); normalizedCode[1] = tolower(languageCode[1]); normalizedCode[2] = '\0'; size_t size; const void* buffer = resources->LoadResource(B_VECTOR_ICON_TYPE, normalizedCode, &size); if (buffer != NULL && size != 0) { return BIconUtils::GetVectorIcon(static_cast<const uint8*>(buffer), size, flagIcon); } // There is no language flag, try to get the default country's flag for // the language instead. BLanguage language(languageCode); const char* countryCode = country_code_for_language(language); if (countryCode == NULL) return B_NAME_NOT_FOUND; return GetFlagIconForCountry(flagIcon, countryCode); }
BBitmap* PrinterItem::_LoadVectorIcon(const char* resourceName, float iconSize) { size_t dataSize; BResources* resources = BApplication::AppResources(); const void* data = resources->LoadResource(B_VECTOR_ICON_TYPE, resourceName, &dataSize); if (data != NULL){ BBitmap *iconBitmap = new BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1), 0, B_RGBA32); if (BIconUtils::GetVectorIcon( reinterpret_cast<const uint8*>(data), dataSize, iconBitmap) == B_OK) return iconBitmap; else delete iconBitmap; }; return NULL; }
BBitmap* MainWindow::ResourceVectorToBitmap(const char *resName, float iconSize) { BResources res; size_t size; app_info appInfo; be_app->GetAppInfo(&appInfo); BFile appFile(&appInfo.ref, B_READ_ONLY); res.SetTo(&appFile); BBitmap *aBmp = NULL; const uint8* iconData = (const uint8*) res.LoadResource('VICN', resName, &size); if (size > 0 ) { aBmp = new BBitmap (BRect(0,0, iconSize, iconSize), 0, B_RGBA32); status_t result = BIconUtils::GetVectorIcon(iconData, size, aBmp); if (result != B_OK) { delete aBmp; aBmp = NULL; } } return aBmp; }
status_t DefaultCatalog::ReadFromResource(entry_ref *appOrAddOnRef) { BFile file; status_t res = file.SetTo(appOrAddOnRef, B_READ_ONLY); if (res != B_OK) { log_team(LOG_ERR, "couldn't find app or add-on (dev=%lu, dir=%Lu, name=%s)", appOrAddOnRef->device, appOrAddOnRef->directory, appOrAddOnRef->name); return B_ENTRY_NOT_FOUND; } log_team(LOG_DEBUG, "looking for embedded catalog-resource in app/add-on" "(dev=%lu, dir=%Lu, name=%s)", appOrAddOnRef->device, appOrAddOnRef->directory, appOrAddOnRef->name); BResources rsrc; res = rsrc.SetTo(&file); if (res != B_OK) { log_team(LOG_DEBUG, "file has no resources"); return res; } size_t sz; const void *buf = rsrc.LoadResource(B_MESSAGE_TYPE, BLocaleRoster::kEmbeddedCatResId, &sz); if (!buf) { log_team(LOG_DEBUG, "file has no catalog-resource"); return B_NAME_NOT_FOUND; } BMemoryIO memIO(buf, sz); res = Unflatten(&memIO); return res; }
// --------------------------------------------------------------- // GetBitmap // // Returns a BBitmap object for the bitmap resource identified by // the type type with the resource name, kName. // The user has to delete this object. Note that a resource type // and name does not uniquely identify a resource in a file. // // Preconditions: // // Parameters: type, the type of resource to be loaded // kName, the name of the resource to be loaded // roster, BTranslatorRoster used to do the translation // // Postconditions: // // Returns: NULL, if the resource couldn't be loaded or couldn't // be translated to a BBitmap // BBitmap * to the bitmap identified by type and kName // --------------------------------------------------------------- BBitmap * BTranslationUtils::GetBitmap(uint32 type, const char *kName, BTranslatorRoster *roster) { BResources *pResources = BApplication::AppResources(); // Remember: pResources must not be freed because // it belongs to the application if (pResources == NULL || pResources->HasResource(type, kName) == false) return NULL; // Load the bitmap resource from the application file size_t bitmapSize = 0; const void *kpRawData = pResources->LoadResource(type, kName, &bitmapSize); if (kpRawData == NULL || bitmapSize == 0) return NULL; BMemoryIO memio(kpRawData, bitmapSize); // Put the pointer to the raw image data into a BMemoryIO object so // that it can be used with BTranslatorRoster->Translate() return GetBitmap(&memio, roster); // Translate the data in memio using the BTranslatorRoster roster }
status_t DefaultCatalog::ReadFromResource(const entry_ref &appOrAddOnRef) { BFile file; status_t res = file.SetTo(&appOrAddOnRef, B_READ_ONLY); if (res != B_OK) return B_ENTRY_NOT_FOUND; BResources rsrc; res = rsrc.SetTo(&file); if (res != B_OK) return res; size_t sz; const void *buf = rsrc.LoadResource('CADA', fLanguageName, &sz); if (!buf) return B_NAME_NOT_FOUND; BMemoryIO memIO(buf, sz); res = Unflatten(&memIO); return res; }
void PowerStatusView::_NotifyLowBattery() { BBitmap* bitmap = NULL; BResources resources; resources.SetToImage((void*)&instantiate_deskbar_item); if (resources.InitCheck() == B_OK) { size_t resourceSize = 0; const void* resourceData = resources.LoadResource( B_VECTOR_ICON_TYPE, fHasBattery ? "battery_low" : "battery_critical", &resourceSize); if (resourceData != NULL) { BMemoryIO memoryIO(resourceData, resourceSize); bitmap = BTranslationUtils::GetBitmap(&memoryIO); } } BNotification notification( fHasBattery ? B_INFORMATION_NOTIFICATION : B_ERROR_NOTIFICATION); if (fHasBattery) { notification.SetTitle(B_TRANSLATE("Battery low")); notification.SetContent(B_TRANSLATE( "The battery level is getting low, please plug in the device.")); } else { notification.SetTitle(B_TRANSLATE("Battery critical")); notification.SetContent(B_TRANSLATE( "The battery level is critical, please plug in the device " "immediately.")); } notification.SetIcon(bitmap); notification.Send(); delete bitmap; }
status_t BLocaleRoster::GetFlagIconForCountry(BBitmap* flagIcon, const char* countryCode) { if (countryCode == NULL) return B_BAD_VALUE; BAutolock lock(fData->fLock); if (!lock.IsLocked()) return B_ERROR; BResources* resources; status_t status = fData->GetResources(&resources); if (status != B_OK) return status; // Normalize the country code: 2 letters uppercase // filter things out so that "pt_BR" gives the flag for brazil int codeLength = strlen(countryCode); if (codeLength < 2) return B_BAD_VALUE; char normalizedCode[3]; normalizedCode[0] = toupper(countryCode[codeLength - 2]); normalizedCode[1] = toupper(countryCode[codeLength - 1]); normalizedCode[2] = '\0'; size_t size; const void* buffer = resources->LoadResource(B_VECTOR_ICON_TYPE, normalizedCode, &size); if (buffer == NULL || size == 0) return B_NAME_NOT_FOUND; return BIconUtils::GetVectorIcon(static_cast<const uint8*>(buffer), size, flagIcon); }
TypeItem* TResourceSet::LoadResource(type_code type, int32 id, const char* name, TypeList** inOutList) { TypeItem* item = NULL; if (name) { BEntry entry; // If a named resource, first look in directories. fLock.Lock(); int32 count = fDirectories.CountItems(); for (int32 i = 0; item == 0 && i < count; i++) { BPath* dir = (BPath*)fDirectories.ItemAt(i); if (dir) { fLock.Unlock(); BPath path(dir->Path(), name); if (entry.SetTo(path.Path(), true) == B_OK ) { BFile file(&entry, B_READ_ONLY); if (file.InitCheck() == B_OK ) { item = new TypeItem(id, name, &file); item->SetSourceIsFile(true); } } fLock.Lock(); } } fLock.Unlock(); } #if USE_RESOURCES if (!item) { // Look through resource objects for data. fLock.Lock(); int32 count = fResources.CountItems(); for (int32 i = 0; item == 0 && i < count; i++ ) { BResources* resource = (BResources*)fResources.ItemAt(i); if (resource) { const void* data = NULL; size_t size = 0; if (id >= 0) data = resource->LoadResource(type, id, &size); else if (name != NULL) data = resource->LoadResource(type, name, &size); if (data && size) { item = new TypeItem(id, name, data, size); item->SetSourceIsFile(false); } } } fLock.Unlock(); } #endif if (item) { TypeList* list = inOutList ? *inOutList : NULL; if (!list) { // Don't currently have a list for this type -- check if there is // already one. list = FindTypeList(type); } BAutolock lock(&fLock); if (!list) { // Need to make a new list for this type. list = new TypeList(type); fTypes.AddItem(list); } if (inOutList) *inOutList = list; list->AddItem(item); } return item; }