From 823808b52bb5514961debc0558c26dbd51765b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 21 Oct 2009 09:47:26 +0000 Subject: [PATCH] * If you only want to search in text files, TextSearch will now guess the MIME type if a file doesn't have one yet (and set it), instead of ignoring it completely. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33694 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/text_search/FileIterator.cpp | 40 ++++++++++----------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/apps/text_search/FileIterator.cpp b/src/apps/text_search/FileIterator.cpp index e3b0ddfcea..b46e862d56 100644 --- a/src/apps/text_search/FileIterator.cpp +++ b/src/apps/text_search/FileIterator.cpp @@ -1,26 +1,11 @@ /* - * Copyright (c) 2008 Stephan Aßmus - * Copyright (c) 1998-2007 Matthijs Hollemans - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Copyright 2008, Stephan Aßmus . + * Copyright 1998-2007, Matthijs Hollemans. + * + * Distributed under the terms of the MIT License. */ + #include "FileIterator.h" #include @@ -30,7 +15,7 @@ #include -FileIterator::FileIterator() +FileIterator::FileIterator() { } @@ -52,16 +37,21 @@ FileIterator::_ExamineFile(BEntry& entry, char* buffer, bool textFilesOnly) if (!textFilesOnly) return true; + BMimeType mimeType; BNode node(&entry); BNodeInfo nodeInfo(&node); char mimeTypeString[B_MIME_TYPE_LENGTH]; - if (nodeInfo.GetType(mimeTypeString) != B_OK) - return false; + if (nodeInfo.GetType(mimeTypeString) != B_OK) { + // try to get a MIME type before failing + if (BMimeType::GuessMimeType(path.Path(), &mimeType) != B_OK) + return false; + + nodeInfo.SetType(mimeType.Type()); + } else + mimeType.SetTo(mimeTypeString); - BMimeType mimeType(mimeTypeString); BMimeType superType; - if (mimeType.GetSupertype(&superType) == B_OK) { if (strcmp("text", superType.Type()) == 0 || strcmp("message", superType.Type()) == 0) {