diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index 68a7b4a..7912066 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -28,8 +28,6 @@ #include "quazip/quazip.h" #include #include -#include -#include #include #include "uchardet/uchardet.h" @@ -211,14 +209,12 @@ void FileUtils::loadHanziTable(const QString &fileName) return; } -QString FileUtils::getMimetype(QString &path, bool getsuffix) +QMimeType FileUtils::getMimetype(QString &path) { QMimeDatabase mdb; QMimeType type = mdb.mimeTypeForFile(path,QMimeDatabase::MatchContent); - if(getsuffix) - return type.name(); - else - return type.preferredSuffix(); + + return type; } //aborted @@ -559,7 +555,7 @@ void FileUtils::getTxtContent(QString &path, QString &textcontent) const char *codec = uchardet_get_charset(chardet); if(QTextCodec::codecForName(codec) == 0) - qWarning()<<"Unsupported Text encoding format"< #include #include +#include +#include #include "libsearch_global.h" //#define INITIAL_STATE 0 //#define CREATING_INDEX 1 @@ -59,7 +61,7 @@ public: static void loadHanziTable(const QString&); //parse text,docx..... - static QString getMimetype(QString &path, bool getsuffix = false); + static QMimeType getMimetype(QString &path); static void getDocxTextContent(QString &path, QString &textcontent); static void getTxtContent(QString &path, QString &textcontent); static size_t _max_index_count; diff --git a/libsearch/index/file-reader.cpp b/libsearch/index/file-reader.cpp index dfda8e1..eb0adb3 100644 --- a/libsearch/index/file-reader.cpp +++ b/libsearch/index/file-reader.cpp @@ -28,20 +28,21 @@ FileReader::FileReader(QObject *parent) : QObject(parent) void FileReader::getTextContent(QString path, QString &textContent) { - QString type =FileUtils::getMimetype(path,true); + QMimeType type = FileUtils::getMimetype(path); + QString name = type.name(); QFileInfo file(path); QString strsfx = file.suffix(); - if(type == "application/zip") + if(name== "application/zip") { if(strsfx.endsWith( "docx")) FileUtils::getDocxTextContent(path,textContent); } - else if(type == "text/plain") + else if(name == "text/plain") { if(strsfx.endsWith( "txt")) FileUtils::getTxtContent(path,textContent); } - else if(type == "application/x-ole-storage") + else if(type.inherits("application/msword")) { if (strsfx.endsWith("doc")) { @@ -49,6 +50,10 @@ void FileReader::getTextContent(QString path, QString &textContent) searchdata.RunParser(path,textContent); } } + else + { + qWarning()<<"Unsupport format:["<