shared: Move textfile detector to common

This commit is contained in:
2022-05-30 20:03:40 +02:00
джерело aed0ca31f7
коміт 26c7cdbc5f
3 змінених файлів з 28 додано та 14 видалено

@ -7,6 +7,7 @@
#include <QSqlError>
#include <QTextStream>
#include <QDebug>
#include <QMimeDatabase>
#include "looqsgeneralexception.h"
#include "common.h"
#include "dbmigrator.h"
@ -178,3 +179,25 @@ QStringList Common::excludedPaths()
}
return ::excludedPaths;
}
bool Common::isTextFile(QFileInfo fileInfo)
{
/* TODO: This is not sandboxed yet ... */
QMimeDatabase mimeDatabase;
QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileInfo);
if(mimeType.name().startsWith("text/"))
{
return true;
}
else
{
for(QString &str : mimeType.allAncestors())
{
if(str.startsWith("text/"))
{
return true;
}
}
}
return false;
}