xref: /haiku/src/apps/expander/ExpanderRules.h (revision 55a5a6bdfa5537e5422bf6ef0b1800537f981066)
1*55a5a6bdSJérôme Duval /*****************************************************************************/
2*55a5a6bdSJérôme Duval // Expander
3*55a5a6bdSJérôme Duval // Written by Jérôme Duval
4*55a5a6bdSJérôme Duval //
5*55a5a6bdSJérôme Duval // ExpanderRules.h
6*55a5a6bdSJérôme Duval //
7*55a5a6bdSJérôme Duval //
8*55a5a6bdSJérôme Duval // Copyright (c) 2004 OpenBeOS Project
9*55a5a6bdSJérôme Duval //
10*55a5a6bdSJérôme Duval // Permission is hereby granted, free of charge, to any person obtaining a
11*55a5a6bdSJérôme Duval // copy of this software and associated documentation files (the "Software"),
12*55a5a6bdSJérôme Duval // to deal in the Software without restriction, including without limitation
13*55a5a6bdSJérôme Duval // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14*55a5a6bdSJérôme Duval // and/or sell copies of the Software, and to permit persons to whom the
15*55a5a6bdSJérôme Duval // Software is furnished to do so, subject to the following conditions:
16*55a5a6bdSJérôme Duval //
17*55a5a6bdSJérôme Duval // The above copyright notice and this permission notice shall be included
18*55a5a6bdSJérôme Duval // in all copies or substantial portions of the Software.
19*55a5a6bdSJérôme Duval //
20*55a5a6bdSJérôme Duval // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21*55a5a6bdSJérôme Duval // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22*55a5a6bdSJérôme Duval // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23*55a5a6bdSJérôme Duval // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24*55a5a6bdSJérôme Duval // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25*55a5a6bdSJérôme Duval // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26*55a5a6bdSJérôme Duval // DEALINGS IN THE SOFTWARE.
27*55a5a6bdSJérôme Duval /*****************************************************************************/
28*55a5a6bdSJérôme Duval 
29*55a5a6bdSJérôme Duval #ifndef _ExpanderRules_h
30*55a5a6bdSJérôme Duval #define _ExpanderRules_h
31*55a5a6bdSJérôme Duval 
32*55a5a6bdSJérôme Duval #include <List.h>
33*55a5a6bdSJérôme Duval #include <File.h>
34*55a5a6bdSJérôme Duval #include <String.h>
35*55a5a6bdSJérôme Duval #include <MimeType.h>
36*55a5a6bdSJérôme Duval #include <FilePanel.h>
37*55a5a6bdSJérôme Duval 
38*55a5a6bdSJérôme Duval class ExpanderRule {
39*55a5a6bdSJérôme Duval 	public:
40*55a5a6bdSJérôme Duval 		ExpanderRule(BString mimetype, BString filenameExtension,
41*55a5a6bdSJérôme Duval 			BString listingCmd, BString expandCmd);
42*55a5a6bdSJérôme Duval 		ExpanderRule(const char*  mimetype, const char*  filenameExtension,
43*55a5a6bdSJérôme Duval 			const char*  listingCmd, const char* expandCmd);
44*55a5a6bdSJérôme Duval 		BMimeType	&MimeType() { return fMimeType;}
45*55a5a6bdSJérôme Duval 		BString		&FilenameExtension() { return fFilenameExtension;}
46*55a5a6bdSJérôme Duval 		BString		&ListingCmd() { return fListingCmd;}
47*55a5a6bdSJérôme Duval 		BString		&ExpandCmd() { return fExpandCmd;}
48*55a5a6bdSJérôme Duval 	private:
49*55a5a6bdSJérôme Duval 		BMimeType 	fMimeType;
50*55a5a6bdSJérôme Duval 		BString 	fFilenameExtension;
51*55a5a6bdSJérôme Duval 		BString 	fListingCmd;
52*55a5a6bdSJérôme Duval 		BString 	fExpandCmd;
53*55a5a6bdSJérôme Duval };
54*55a5a6bdSJérôme Duval 
55*55a5a6bdSJérôme Duval 
56*55a5a6bdSJérôme Duval class ExpanderRules {
57*55a5a6bdSJérôme Duval 	public:
58*55a5a6bdSJérôme Duval 		ExpanderRules();
59*55a5a6bdSJérôme Duval 		~ExpanderRules();
60*55a5a6bdSJérôme Duval 		ExpanderRule *MatchingRule(BString &fileName, const char *filetype);
61*55a5a6bdSJérôme Duval 		ExpanderRule *MatchingRule(const entry_ref *ref);
62*55a5a6bdSJérôme Duval 	private:
63*55a5a6bdSJérôme Duval 		status_t Open(BFile *file);
64*55a5a6bdSJérôme Duval 
65*55a5a6bdSJérôme Duval 		BList	fList;
66*55a5a6bdSJérôme Duval };
67*55a5a6bdSJérôme Duval 
68*55a5a6bdSJérôme Duval 
69*55a5a6bdSJérôme Duval class RuleRefFilter : public BRefFilter {
70*55a5a6bdSJérôme Duval 	public:
71*55a5a6bdSJérôme Duval 		RuleRefFilter(ExpanderRules &rules);
72*55a5a6bdSJérôme Duval 		bool Filter(const entry_ref *ref, BNode* node, struct stat *st,
73*55a5a6bdSJérôme Duval 			const char *filetype);
74*55a5a6bdSJérôme Duval 	protected:
75*55a5a6bdSJérôme Duval 		ExpanderRules &fRules;
76*55a5a6bdSJérôme Duval };
77*55a5a6bdSJérôme Duval 
78*55a5a6bdSJérôme Duval #endif /* _ExpanderRules_h */