xref: /haiku/src/apps/text_search/FileIterator.cpp (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
1 /*
2  * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 1998-2007, Matthijs Hollemans.
4  *
5  * Distributed under the terms of the MIT License.
6  */
7 
8 
9 #include "FileIterator.h"
10 
11 #include <string.h>
12 
13 #include <Entry.h>
14 #include <NodeInfo.h>
15 #include <Path.h>
16 
17 
18 FileIterator::FileIterator()
19 {
20 }
21 
22 
23 FileIterator::~FileIterator()
24 {
25 }
26 
27 
28 bool
29 FileIterator::_ExamineFile(BEntry& entry, char* buffer, bool textFilesOnly)
30 {
31 	BPath path;
32 	if (entry.GetPath(&path) != B_OK)
33 		return false;
34 
35 	strcpy(buffer, path.Path());
36 
37 	if (!textFilesOnly)
38 		return true;
39 
40 	BMimeType mimeType;
41 	BNode node(&entry);
42 	BNodeInfo nodeInfo(&node);
43 	char mimeTypeString[B_MIME_TYPE_LENGTH];
44 
45 	if (nodeInfo.GetType(mimeTypeString) != B_OK) {
46 		// try to get a MIME type before failing
47 		if (BMimeType::GuessMimeType(path.Path(), &mimeType) != B_OK)
48 			return false;
49 
50 		nodeInfo.SetType(mimeType.Type());
51 	} else
52 		mimeType.SetTo(mimeTypeString);
53 
54 	BMimeType superType;
55 	if (mimeType.GetSupertype(&superType) == B_OK) {
56 		if (strcmp("text", superType.Type()) == 0
57 			|| strcmp("message", superType.Type()) == 0) {
58 			return true;
59 		}
60 	}
61 
62 	return false;
63 }
64 
65