From 0d37df6412109893dd38e644010b97b7fc9d7ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 18 Aug 2008 11:50:08 +0000 Subject: [PATCH] * The old Be version of get_device_icon() now also supports retrieving the vector icon in case B_GET_ICON is not supported by the device anymore. (This makes B_GET_ICON deprecated API.) * Use B_BITMAP_NO_SERVER_LINK flag, as our bitmap is only used internally. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27036 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/storage/Mime.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/kits/storage/Mime.cpp b/src/kits/storage/Mime.cpp index 5a1a2a5e8a..741f9a78c4 100644 --- a/src/kits/storage/Mime.cpp +++ b/src/kits/storage/Mime.cpp @@ -177,7 +177,37 @@ get_device_icon(const char *device, void *icon, int32 size) device_icon iconData = {size, icon}; if (ioctl(fd, B_GET_ICON, &iconData) != 0) { + // legacy icon was not available, try vector icon close(fd); + + uint8* data; + size_t size; + type_code type; + status_t status = get_device_icon(device, &data, &size, &type); + if (status == B_OK) { + BBitmap* icon = new(std::nothrow) BBitmap( + BRect(0, 0, size - 1, size - 1), B_BITMAP_NO_SERVER_LINK, + B_RGBA32); + BBitmap* target = new(std::nothrow) BBitmap( + BRect(0, 0, size - 1, size - 1), B_BITMAP_NO_SERVER_LINK, + B_CMAP8); + if (icon == NULL || icon->InitCheck() != B_OK || target == NULL + || target->InitCheck() != B_OK) { + delete icon; + delete target; + return B_NO_MEMORY; + } + status = BIconUtils::GetVectorIcon(data, size, icon); + if (status == B_OK) + status = BIconUtils::ConvertToCMAP8(icon, target); + if (status == B_OK) + memcpy(icon, target->Bits(), target->BitsLength()); + + delete icon; + delete target; + delete[] data; + return status; + } return errno; } @@ -238,7 +268,8 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which) iconSize = B_LARGE_ICON; bitmap = new(std::nothrow) BBitmap( - BRect(0, 0, iconSize - 1, iconSize -1), B_CMAP8); + BRect(0, 0, iconSize - 1, iconSize -1), B_BITMAP_NO_SERVER_LINK, + B_CMAP8); if (bitmap == NULL || bitmap->InitCheck() != B_OK) { delete bitmap; return B_NO_MEMORY;