xref: /haiku/src/apps/expander/ExpanderRules.h (revision 0c66734e4da3cdd60a0552014b0f46275a358796)
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 _EXPANDER_RULES_H
8 #define _EXPANDER_RULES_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& listingCommand,
22 									const BString& expandCommand);
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& listingCommand,
57 									const BString& expandCommand);
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* stat,
69 									const char* filetype);
70 
71 protected:
72 			ExpanderRules&		fRules;
73 };
74 
75 
76 #endif	// _EXPANDER_RULES_H
77