shared: Move textfile detector to common
This commit is contained in:
		@@ -7,6 +7,7 @@
 | 
				
			|||||||
#include <QSqlError>
 | 
					#include <QSqlError>
 | 
				
			||||||
#include <QTextStream>
 | 
					#include <QTextStream>
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
 | 
					#include <QMimeDatabase>
 | 
				
			||||||
#include "looqsgeneralexception.h"
 | 
					#include "looqsgeneralexception.h"
 | 
				
			||||||
#include "common.h"
 | 
					#include "common.h"
 | 
				
			||||||
#include "dbmigrator.h"
 | 
					#include "dbmigrator.h"
 | 
				
			||||||
@@ -178,3 +179,25 @@ QStringList Common::excludedPaths()
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return ::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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
#ifndef COMMON_H
 | 
					#ifndef COMMON_H
 | 
				
			||||||
#define COMMON_H
 | 
					#define COMMON_H
 | 
				
			||||||
#include <QCoreApplication>
 | 
					#include <QCoreApplication>
 | 
				
			||||||
 | 
					#include <QFileInfo>
 | 
				
			||||||
namespace Common
 | 
					namespace Common
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
void setupAppInfo();
 | 
					void setupAppInfo();
 | 
				
			||||||
@@ -12,5 +12,6 @@ QString findInPath(QString needle);
 | 
				
			|||||||
bool initSqliteDatabase(QString path);
 | 
					bool initSqliteDatabase(QString path);
 | 
				
			||||||
void ensureConfigured();
 | 
					void ensureConfigured();
 | 
				
			||||||
QStringList excludedPaths();
 | 
					QStringList excludedPaths();
 | 
				
			||||||
 | 
					bool isTextFile(QFileInfo fileInfo);
 | 
				
			||||||
} // namespace Common
 | 
					} // namespace Common
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@
 | 
				
			|||||||
#include "odtprocessor.h"
 | 
					#include "odtprocessor.h"
 | 
				
			||||||
#include "odsprocessor.h"
 | 
					#include "odsprocessor.h"
 | 
				
			||||||
#include "../submodules/exile.h/exile.h"
 | 
					#include "../submodules/exile.h/exile.h"
 | 
				
			||||||
 | 
					#include "common.h"
 | 
				
			||||||
#include "logger.h"
 | 
					#include "logger.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static DefaultTextProcessor *defaultTextProcessor = new DefaultTextProcessor();
 | 
					static DefaultTextProcessor *defaultTextProcessor = new DefaultTextProcessor();
 | 
				
			||||||
@@ -77,22 +78,11 @@ int SandboxedProcessor::process()
 | 
				
			|||||||
	Processor *processor = processors.value(fileInfo.suffix(), nullptr);
 | 
						Processor *processor = processors.value(fileInfo.suffix(), nullptr);
 | 
				
			||||||
	if(processor == nullptr)
 | 
						if(processor == nullptr)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		/* TODO: This is not sandboxed yet ... */
 | 
							/* TODO: Not sandboxed */
 | 
				
			||||||
		QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileInfo);
 | 
							if(Common::isTextFile(fileInfo))
 | 
				
			||||||
		if(mimeType.name().startsWith("text/"))
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			processor = defaultTextProcessor;
 | 
								processor = defaultTextProcessor;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			for(QString &str : mimeType.allAncestors())
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				if(str.startsWith("text/"))
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					processor = defaultTextProcessor;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if(processor == nullptr || processor == nothingProcessor)
 | 
						if(processor == nullptr || processor == nothingProcessor)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user