From 035f2c2a4d3d4a291620cab84f03d07f1a11a22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 15 Nov 2006 17:49:22 +0000 Subject: [PATCH] When dragging an icon into an icon view that gets its icon from its MIME type, the vector icon is now retrieved as well. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19296 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/filetypes/IconView.cpp | 82 ++++++++++++++++++++++++-- src/preferences/filetypes/IconView.h | 2 + 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/src/preferences/filetypes/IconView.cpp b/src/preferences/filetypes/IconView.cpp index e0e4aa24ed..2c7f063b09 100644 --- a/src/preferences/filetypes/IconView.cpp +++ b/src/preferences/filetypes/IconView.cpp @@ -28,6 +28,66 @@ using namespace std; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU +status_t +icon_for_type(BMimeType& type, uint8** _data, size_t* _size, + icon_source* _source) +{ + if (_data == NULL || _size == NULL) + return B_BAD_VALUE; + + icon_source source = kNoIcon; + uint8* data; + size_t size; + + if (type.GetIcon(&data, &size) == B_OK) + source = kOwnIcon; + + if (source == kNoIcon) { + // check for icon from preferred app + + char preferred[B_MIME_TYPE_LENGTH]; + if (type.GetPreferredApp(preferred) == B_OK) { + BMimeType preferredApp(preferred); + + if (preferredApp.GetIconForType(type.Type(), &data, &size) == B_OK) + source = kApplicationIcon; + } + } + + if (source == kNoIcon) { + // check super type for an icon + + BMimeType superType; + if (type.GetSupertype(&superType) == B_OK) { + if (superType.GetIcon(&data, &size) == B_OK) + source = kSupertypeIcon; + else { + // check the super type's preferred app + char preferred[B_MIME_TYPE_LENGTH]; + if (superType.GetPreferredApp(preferred) == B_OK) { + BMimeType preferredApp(preferred); + + if (preferredApp.GetIconForType(superType.Type(), + &data, &size) == B_OK) + source = kSupertypeIcon; + } + } + } + } + + if (source != kNoIcon) { + *_data = data; + *_size = size; + } + if (_source) + *_source = source; + + return source != kNoIcon ? B_OK : B_ERROR; +} +#endif + + status_t icon_for_type(BMimeType& type, BBitmap& bitmap, icon_size size, icon_source* _source) @@ -992,14 +1052,26 @@ IconView::_SetIcon(entry_ref* ref) if (info.GetType(type) != B_OK) return; - // TODO: vector icon support! BMimeType mimeType(type); - if (large != NULL && icon_for_type(mimeType, *large, B_LARGE_ICON) == B_OK) - hasLarge = true; - if (mini != NULL && icon_for_type(mimeType, *mini, B_MINI_ICON) == B_OK) - hasMini = true; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + if (icon_for_type(mimeType, &data, &size) != B_OK) { + // only try large/mini icons when there is no vector icon +#endif + if (large != NULL && icon_for_type(mimeType, *large, B_LARGE_ICON) == B_OK) + hasLarge = true; + if (mini != NULL && icon_for_type(mimeType, *mini, B_MINI_ICON) == B_OK) + hasMini = true; +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + } +#endif } +#ifdef HAIKU_TARGET_PLATFORM_HAIKU + if (data != NULL) { + _SetIcon(NULL, NULL, data, size); + free(data); + } else +#endif if (hasLarge || hasMini) _SetIcon(large, mini, NULL, 0); diff --git a/src/preferences/filetypes/IconView.h b/src/preferences/filetypes/IconView.h index 865b46cb59..19e19918bf 100644 --- a/src/preferences/filetypes/IconView.h +++ b/src/preferences/filetypes/IconView.h @@ -124,6 +124,8 @@ enum icon_source { kSupertypeIcon }; +extern status_t icon_for_type(BMimeType& type, uint8** _data, size_t* _size, + icon_source* _source = NULL); extern status_t icon_for_type(BMimeType& type, BBitmap& bitmap, icon_size size, icon_source* _source = NULL);