xref: /haiku/src/preferences/filetypes/MimeTypeListView.h (revision 50a2f6d7b20e0c0b24b47f85622e445bf84e81a8)
1 /*
2  * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef MIME_TYPE_LIST_VIEW_H
6 #define MIME_TYPE_LIST_VIEW_H
7 
8 
9 #include <Mime.h>
10 #include <OutlineListView.h>
11 #include <String.h>
12 
13 
14 class MimeTypeItem : public BStringItem {
15 	public:
16 		MimeTypeItem(BMimeType& type, bool showIcon = false, bool flat = false);
17 		MimeTypeItem(const char* type, bool showIcon = false, bool flat = false);
18 		virtual ~MimeTypeItem();
19 
20 		virtual void DrawItem(BView* owner, BRect itemRect,
21 			bool drawEverything = false);
22 		virtual void Update(BView* owner, const BFont* font);
23 
Type()24 		const char* Type() const { return fType.String(); }
Subtype()25 		const char* Subtype() const { return fSubtype.String(); }
Supertype()26 		const char* Supertype() const { return fSupertype.String(); }
Description()27 		const char* Description() const { return fDescription.String(); }
IsSupertypeOnly()28 		bool IsSupertypeOnly() const { return fIsSupertype; }
29 
30 		void UpdateText();
31 		void AddSubtype();
32 
33 		void ShowIcon(bool showIcon);
34 		void SetApplicationMode(bool applicationMode);
35 
36 		static int Compare(const BListItem* a, const BListItem* b);
37 		static int CompareLabels(const BListItem* a, const BListItem* b);
38 
39 	private:
40 		void _SetTo(BMimeType& type);
41 
42 		BString		fSupertype;
43 		BString		fSubtype;
44 		BString		fType;
45 		BString		fDescription;
46 		float		fBaselineOffset;
47 		bool		fIsSupertype;
48 		bool		fFlat;
49 		bool		fShowIcon;
50 		bool		fApplicationMode;
51 };
52 
53 class MimeTypeListView : public BOutlineListView {
54 	public:
55 		MimeTypeListView(const char* name,
56 			const char* supertype = NULL, bool showIcons = false,
57 			bool applicationMode = false);
58 		virtual ~MimeTypeListView();
59 
60 		void SelectNewType(const char* type);
61 		bool SelectType(const char* type);
62 
63 		void SelectItem(MimeTypeItem* item);
64 		MimeTypeItem* FindItem(const char* type);
65 
66 		void UpdateItem(MimeTypeItem* item);
67 
68 		void ShowIcons(bool showIcons);
IsShowingIcons()69 		bool IsShowingIcons() const { return fShowIcons; }
70 
71 	protected:
72 		virtual void AttachedToWindow();
73 		virtual void DetachedFromWindow();
74 
75 		virtual void MessageReceived(BMessage* message);
76 
77 	private:
78 		void _CollectSubtypes(const char* supertype, MimeTypeItem* supertypeItem);
79 		void _CollectTypes();
80 		void _MakeTypesUnique(MimeTypeItem* underItem = NULL);
81 		void _AddNewType(const char* type);
82 
83 		BMimeType	fSupertype;
84 		BString		fSelectNewType;
85 		bool		fShowIcons;
86 		bool		fApplicationMode;
87 };
88 
89 extern bool mimetype_is_application_signature(BMimeType& type);
90 
91 #endif	// MIME_TYPE_LIST_VIEW_H
92