From 00cf1f4671a33520acd8a6eb937e0e2a83550b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 14 Nov 2006 18:26:10 +0000 Subject: [PATCH] Moved icon_for_type() to IconView.cpp. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19283 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/filetypes/FileTypesWindow.cpp | 1 + src/preferences/filetypes/IconView.cpp | 52 +++++++++++++++++++ src/preferences/filetypes/IconView.h | 10 ++++ .../filetypes/MimeTypeListView.cpp | 50 +----------------- src/preferences/filetypes/MimeTypeListView.h | 9 ---- 5 files changed, 64 insertions(+), 58 deletions(-) diff --git a/src/preferences/filetypes/FileTypesWindow.cpp b/src/preferences/filetypes/FileTypesWindow.cpp index 7cb0727ffc..858f8a6e30 100644 --- a/src/preferences/filetypes/FileTypesWindow.cpp +++ b/src/preferences/filetypes/FileTypesWindow.cpp @@ -9,6 +9,7 @@ #include "ExtensionWindow.h" #include "FileTypes.h" #include "FileTypesWindow.h" +#include "IconView.h" #include "MimeTypeListView.h" #include "NewFileTypeWindow.h" #include "PreferredAppMenu.h" diff --git a/src/preferences/filetypes/IconView.cpp b/src/preferences/filetypes/IconView.cpp index 7c14927b70..e8cdd658b4 100644 --- a/src/preferences/filetypes/IconView.cpp +++ b/src/preferences/filetypes/IconView.cpp @@ -26,6 +26,58 @@ #include +status_t +icon_for_type(BMimeType& type, BBitmap& bitmap, icon_size size, + icon_source* _source) +{ + icon_source source = kNoIcon; + + if (type.GetIcon(&bitmap, 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(), &bitmap, 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(&bitmap, 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(), + &bitmap, size) == B_OK) + source = kSupertypeIcon; + } + } + } + } + + if (_source) + *_source = source; + + return source != kNoIcon ? B_OK : B_ERROR; +} + + +// #pragma mark - + + Icon::Icon() : fLarge(NULL), diff --git a/src/preferences/filetypes/IconView.h b/src/preferences/filetypes/IconView.h index 8213a905a4..250c9891d3 100644 --- a/src/preferences/filetypes/IconView.h +++ b/src/preferences/filetypes/IconView.h @@ -111,4 +111,14 @@ static const uint32 kMsgRemoveIcon = 'icrm'; static const uint32 kMsgAddIcon = 'icad'; static const uint32 kMsgEditIcon = 'iced'; +enum icon_source { + kNoIcon = 0, + kOwnIcon, + kApplicationIcon, + kSupertypeIcon +}; + +extern status_t icon_for_type(BMimeType& type, BBitmap& bitmap, + icon_size size, icon_source* _source = NULL); + #endif // ICON_VIEW_H diff --git a/src/preferences/filetypes/MimeTypeListView.cpp b/src/preferences/filetypes/MimeTypeListView.cpp index b3e58be0ba..caf9533acf 100644 --- a/src/preferences/filetypes/MimeTypeListView.cpp +++ b/src/preferences/filetypes/MimeTypeListView.cpp @@ -4,6 +4,7 @@ */ +#include "IconView.h" #include "MimeTypeListView.h" #include @@ -16,55 +17,6 @@ const uint32 kMsgAddType = 'adtp'; -status_t -icon_for_type(BMimeType& type, BBitmap& bitmap, icon_size size, - icon_source* _source) -{ - icon_source source = kNoIcon; - - if (type.GetIcon(&bitmap, 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(), &bitmap, 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(&bitmap, 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(), - &bitmap, size) == B_OK) - source = kSupertypeIcon; - } - } - } - } - - if (_source) - *_source = source; - - return source != kNoIcon ? B_OK : B_ERROR; -} - - bool mimetype_is_application_signature(BMimeType& type) { diff --git a/src/preferences/filetypes/MimeTypeListView.h b/src/preferences/filetypes/MimeTypeListView.h index 9ada6a7770..ab10c60706 100644 --- a/src/preferences/filetypes/MimeTypeListView.h +++ b/src/preferences/filetypes/MimeTypeListView.h @@ -87,15 +87,6 @@ class MimeTypeListView : public BOutlineListView { bool fApplicationMode; }; -enum icon_source { - kNoIcon = 0, - kOwnIcon, - kApplicationIcon, - kSupertypeIcon -}; - -extern status_t icon_for_type(BMimeType& type, BBitmap& bitmap, icon_size size, - icon_source* _source = NULL); extern bool mimetype_is_application_signature(BMimeType& type); #endif // MIME_TYPE_LIST_VIEW_H