-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmimetypemanager.cpp
More file actions
executable file
·53 lines (42 loc) · 1.47 KB
/
mimetypemanager.cpp
File metadata and controls
executable file
·53 lines (42 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* bitshift dynamics - Copyright 2012, All rights reserved
* Author: Alexander Nassian <nassian@bitshift-dynamics.com>
*/
#include "mimetypemanager.h"
#include <QFile>
#include <QDebug>
#include <QStringList>
/**
* This overloaded constructor loads a mime.types file with the given path and stores it's
* contents in an internal QMap.
*
* @param filePath The path to the mime.types file.
*/
MimeTypeManager::MimeTypeManager(const QString& filePath)
{
QFile mimeFile(filePath);
if (mimeFile.open(QIODevice::ReadOnly) == false) {
qCritical() << "Failed opening mime type mapping.";
return;
}
QTextStream stream(&mimeFile);
while (mimeFile.atEnd() == false) {
QString currentLine = stream.readLine();
// Ignore commented lines
if (currentLine.startsWith("#") == true)
continue;
// Split the current entry and filter invalid entries
QStringList components = currentLine.split("\t", QString::SkipEmptyParts);
if (components.count() != 2) {
qWarning() << "Invalid entry.";
continue;
}
// Split multiple filename suffixes for every mimetype
QStringList endings = components.at(1).split(" ", QString::SkipEmptyParts);
QString mimeType = components.at(0);
foreach (QString ending, endings) {
mimeTypes[ending] = mimeType;
}
}
mimeFile.close();
}