-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileextensionfilter.cpp
65 lines (51 loc) · 1.67 KB
/
fileextensionfilter.cpp
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
54
55
56
57
58
59
60
61
62
63
#include <QDebug>
#include <QString>
#include "fileextensionfilter.h"
TypeFilter::TypeFilter(FileType type, QString extension) : m_type(type)
, m_extension(extension)
{
}
FileType TypeFilter::type() const
{
return m_type;
}
QString TypeFilter::extension() const
{
return m_extension;
}
// ---
FileExtensionFilter::FileExtensionFilter(QObject *parent) : QObject(parent)
{
m_filterList.push_back(TypeFilter(Image, QString(".JPG")));
m_filterList.push_back(TypeFilter(Image, QString(".JPEG")));
m_filterList.push_back(TypeFilter(Video, QString(".MOV")));
m_filterList.push_back(TypeFilter(Video, QString(".AVI")));
m_filterList.push_back(TypeFilter(Video, QString(".MPG")));
m_filterList.push_back(TypeFilter(Video, QString(".MPEG")));
m_filterList.push_back(TypeFilter(Video, QString(".MP4")));
}
FileType FileExtensionFilter::getType(QString filename)
{
int last_dot_index = filename.lastIndexOf(".");
int remaining = filename.length() - last_dot_index;
if (last_dot_index > 0 && remaining > 0) {
QString extension = filename.right(remaining);
extension = extension.toUpper();
for (TypeFilter& tf : m_filterList) {
if (tf.extension() == extension) {
return tf.type();
}
}
}
return Unknown;
}
QString FileExtensionFilter::getExtension(QString filename)
{
QString extension = "";
int last_dot_index = filename.lastIndexOf(".");
int remaining = filename.length() - last_dot_index;
if (last_dot_index > 0 && remaining > 0) {
extension = filename.right(remaining);
}
return extension;
}