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