xref: /haiku/headers/private/interface/DecorInfo.h (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
1 /*
2  * Public domain source code.
3  *
4  * Author:
5  *		Joseph "looncraz" Groover <looncraz@satx.rr.com>
6  */
7 #ifndef DECOR_INFO_H
8 #define DECOR_INFO_H
9 
10 
11 #include <Entry.h>
12 #include <Locker.h>
13 #include <ObjectList.h>
14 #include <String.h>
15 
16 
17 class BWindow;
18 
19 
20 namespace BPrivate {
21 
22 
23 // NOTE: DecorInfo itself is not thread-safe
24 class DecorInfo {
25 public:
26 								DecorInfo();
27 								DecorInfo(const BString& path);
28 								DecorInfo(const entry_ref& ref);
29 								~DecorInfo();
30 
31 			status_t			SetTo(const entry_ref& ref);
32 			status_t			SetTo(BString path);
33 			status_t			InitCheck()	const;
34 			void				Unset();
35 
36 			bool				IsDefault()	const;
37 
38 			BString				Path()	const;
39 					// Returns "Default" for the default decorator
40 
41 			const entry_ref*	Ref() const;
42 				// Returns NULL if virtual (default) or InitCheck() != B_OK
43 				// The ref returned may NOT be the same as the one given to
44 				// SetTo or the constructor - we may have traversed a Symlink!
45 
46 			BString				Name() const;
47 			BString				ShortcutName() const;
48 
49 			BString				Authors() const;
50 			BString				ShortDescription() const;
51 			BString				LongDescription() const;
52 			BString				LicenseURL() const;
53 			BString				LicenseName() const;
54 			BString				SupportURL() const;
55 
56 			float				Version() const;
57 			time_t				ModificationTime() const;
58 
59 			bool				CheckForChanges(bool &deleted);
60 
61 private:
62 			void				_Init(bool is_update = false);
63 
64 private:
65 			entry_ref			fRef;
66 
67 			BString				fPath;
68 			BString				fName;
69 			BString				fAuthors;
70 			BString				fShortDescription;
71 			BString				fLongDescription;
72 			BString				fLicenseURL;
73 			BString				fLicenseName;
74 			BString				fSupportURL;
75 
76 			float				fVersion;
77 
78 			time_t				fModificationTime;
79 
80 			status_t			fInitStatus;
81 };
82 
83 
84 class DecorInfoUtility {
85 public:
86 								DecorInfoUtility(bool scanNow = true);
87 									// NOTE: When scanNow is passed false,
88 									// scanning will be performed lazily, such
89 									// as in CountDecorators() and other
90 									// methods.
91 
92 								~DecorInfoUtility();
93 
94 			status_t			ScanDecorators();
95 									// Can also be used to rescan for changes.
96 									// Warning: potentially destructive as we
97 									// will remove all DecorInfo objects which
98 									// no longer have a file system cousin.
99 									// TODO: Would a call-back mechanism be
100 									// worthwhile here?
101 
102 			int32				CountDecorators();
103 
104 			DecorInfo*			DecoratorAt(int32);
105 
106 			DecorInfo*			FindDecorator(const BString& string);
107 									// Checks for ref.name, path, fName, and
108 									// "Default," an empty-string returns the
109 									// current decorator NULL on match failure
110 
111 			DecorInfo*			CurrentDecorator();
112 			DecorInfo*			DefaultDecorator();
113 
114 			bool				IsCurrentDecorator(DecorInfo* decor);
115 
116 			status_t			SetDecorator(DecorInfo* decor);
117 			status_t			SetDecorator(int32);
118 
119 			status_t			Preview(DecorInfo* decor, BWindow* window);
120 
121 private:
122 			DecorInfo*			_FindDecor(const BString& path);
123 
124 private:
125 			BObjectList<DecorInfo> fList;
126 			BLocker				fLock;
127 			bool				fHasScanned;
128 };
129 
130 
131 }	// namespace BPrivate
132 
133 
134 using BPrivate::DecorInfo;
135 using BPrivate::DecorInfoUtility;
136 
137 
138 #endif	// DECOR_INFO_H
139