diff --git a/src/preferences/filetypes/FileTypesWindow.cpp b/src/preferences/filetypes/FileTypesWindow.cpp index eb81bce8b9..f924563294 100644 --- a/src/preferences/filetypes/FileTypesWindow.cpp +++ b/src/preferences/filetypes/FileTypesWindow.cpp @@ -87,14 +87,8 @@ class IconView : public BControl { #endif private: - enum { - kNoIcon = 0, - kOwnIcon, - kApplicationIcon, - kSupertypeIcon - }; BBitmap* fIcon; - int32 fIconSource; + icon_source fIconSource; }; class AttributeListView : public BListView { @@ -228,42 +222,7 @@ IconView::SetTo(BMimeType* type) B_CMAP8); } - if (type->GetIcon(fIcon, B_LARGE_ICON) == B_OK) - fIconSource = kOwnIcon; - - if (fIconSource == 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(), fIcon, - B_LARGE_ICON) == B_OK) - fIconSource = kApplicationIcon; - } - } - - if (fIconSource == kNoIcon) { - // check super type for an icon - - BMimeType superType; - if (type->GetSupertype(&superType) == B_OK) { - if (superType.GetIcon(fIcon, B_LARGE_ICON) == B_OK) - fIconSource = 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(), - fIcon, B_LARGE_ICON) == B_OK) - fIconSource = kSupertypeIcon; - } - } - } - } + icon_for_type(*type, *fIcon, B_LARGE_ICON, &fIconSource); } if (fIconSource == kNoIcon) { @@ -558,7 +517,7 @@ FileTypesWindow::FileTypesWindow(BRect frame) if (rect.right < 180) rect.right = 180; - fTypeListView = new MimeTypeListView(rect, "listview", NULL, false, false, + fTypeListView = new MimeTypeListView(rect, "typeview", NULL, false, false, B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); @@ -733,7 +692,12 @@ FileTypesWindow::FileTypesWindow(BRect frame) fRemoveAttributeButton = new BButton(innerRect, "remove attr", "Remove", new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT); box->AddChild(fRemoveAttributeButton); - +/* + innerRect.OffsetBy(0, innerRect.Height() + 4.0f); + button = new BButton(innerRect, "push attr", "Push Up", + new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT); + box->AddChild(button); +*/ innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; innerRect.left = 10.0f; innerRect.top = 8.0f + ceilf(fontHeight.ascent); diff --git a/src/preferences/filetypes/MimeTypeListView.cpp b/src/preferences/filetypes/MimeTypeListView.cpp index 69b233b7be..94e68a1032 100644 --- a/src/preferences/filetypes/MimeTypeListView.cpp +++ b/src/preferences/filetypes/MimeTypeListView.cpp @@ -12,6 +12,57 @@ // TODO: lazy type collecting (super types only at startup) +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; + return B_OK; + } + + 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) { @@ -86,7 +137,7 @@ MimeTypeItem::DrawItem(BView* owner, BRect frame, bool complete) BBitmap bitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_CMAP8); BMimeType mimeType(fType.String()); - if (mimeType.GetIcon(&bitmap, B_MINI_ICON) == B_OK) { + if (icon_for_type(mimeType, bitmap, B_MINI_ICON) == B_OK) { BPoint point(rect.left + 2.0f, rect.top + (rect.Height() - B_MINI_ICON) / 2.0f); diff --git a/src/preferences/filetypes/MimeTypeListView.h b/src/preferences/filetypes/MimeTypeListView.h index e2a458a087..7116d93e48 100644 --- a/src/preferences/filetypes/MimeTypeListView.h +++ b/src/preferences/filetypes/MimeTypeListView.h @@ -79,6 +79,15 @@ class MimeTypeListView : public BOutlineListView { bool fApplicationMode; }; -bool mimetype_is_application_signature(BMimeType& type); +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