xref: /haiku/src/apps/expander/ExpanderRules.h (revision 04a0e9c7b68cbe3a43d38e2bca8e860fd80936fb)
1 /*
2  * Copyright 2004-2006, Jérôme Duval. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #ifndef _ExpanderRules_h
8 #define _ExpanderRules_h
9 
10 #include <File.h>
11 #include <FilePanel.h>
12 #include <List.h>
13 #include <Mime.h>
14 #include <String.h>
15 
16 
17 class ExpanderRule {
18 public:
19 								ExpanderRule(const char* mimetype,
20 									const BString& filenameExtension,
21 									const BString& listingCmd,
22 									const BString& expandCmd);
23 
24 			const BMimeType&	MimeType() const
25 									{ return fMimeType; }
26 			const BString&		FilenameExtension() const
27 									{ return fFilenameExtension; }
28 			const BString&		ListingCmd() const
29 									{ return fListingCmd; }
30 			const BString&		ExpandCmd() const
31 									{ return fExpandCmd; }
32 
33 private:
34 			BMimeType 			fMimeType;
35 			BString 			fFilenameExtension;
36 			BString 			fListingCmd;
37 			BString 			fExpandCmd;
38 };
39 
40 
41 class ExpanderRules {
42 public:
43 								ExpanderRules();
44 								~ExpanderRules();
45 
46 			ExpanderRule*		MatchingRule(BString& fileName,
47 									const char* filetype);
48 			ExpanderRule*		MatchingRule(const entry_ref* ref);
49 
50 private:
51 			void				_LoadRulesFiles();
52 			void				_LoadRulesFile(const char* path);
53 
54 			bool				_AddRule(const char* mimetype,
55 									const BString& filenameExtension,
56 									const BString& listingCmd,
57 									const BString& expandCmd);
58 
59 private:
60 			BList				fList;
61 };
62 
63 
64 class RuleRefFilter : public BRefFilter {
65 public:
66 								RuleRefFilter(ExpanderRules& rules);
67 			bool				Filter(const entry_ref* ref, BNode* node,
68 									struct stat_beos* st, const char* filetype);
69 protected:
70 			ExpanderRules&		fRules;
71 };
72 
73 
74 #endif /* _ExpanderRules_h */
75