summaryrefslogtreecommitdiffstats
path: root/src/declarative/declarativemimetype.cpp
blob: b8c668a1832387ad24b5c53b782bbe0173e67c6f (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "declarativemimetype_p.h"

#include <QtCore/QDebug>

// ------------------------------------------------------------------------------------------------

DeclarativeMimeType::DeclarativeMimeType(QObject *theParent) :
        QObject(theParent),
        m_MimeType()
{}

// ------------------------------------------------------------------------------------------------

DeclarativeMimeType::DeclarativeMimeType(const QMimeType &other, QObject *theParent) :
        QObject(theParent),
        m_MimeType(other)
{}

// ------------------------------------------------------------------------------------------------

DeclarativeMimeType::~DeclarativeMimeType()
{
    //qDebug() << Q_FUNC_INFO << "name():" << name();
}

// ------------------------------------------------------------------------------------------------

void DeclarativeMimeType::assign(DeclarativeMimeType *other)
{
    if (other == 0) {
        qWarning() << Q_FUNC_INFO << "other:" << other;
        return;
    }

    m_MimeType = other->m_MimeType;
}

// ------------------------------------------------------------------------------------------------

bool DeclarativeMimeType::equals(DeclarativeMimeType *other) const
{
    if (other == 0) {
        qWarning() << Q_FUNC_INFO << "other:" << other;
        return false;
    }

    return m_MimeType == other->m_MimeType;
}

// ------------------------------------------------------------------------------------------------

QMimeType DeclarativeMimeType::mimeType() const
{
    return m_MimeType;
}

// ------------------------------------------------------------------------------------------------

bool DeclarativeMimeType::isValid() const
{
    return m_MimeType.isValid();
}

// ------------------------------------------------------------------------------------------------

const QMimeTypeName &DeclarativeMimeType::name() const
{
    return m_MimeType.name();
}

// ------------------------------------------------------------------------------------------------

void DeclarativeMimeType::setName(const QMimeTypeName &newName)
{
    m_MimeType = QMimeType(newName, m_MimeType.displayName(), m_MimeType.iconUrl(), m_MimeType.fileExtentions());
}

// ------------------------------------------------------------------------------------------------

const QString &DeclarativeMimeType::displayName() const
{
    return m_MimeType.displayName();
}

// ------------------------------------------------------------------------------------------------

void DeclarativeMimeType::setDisplayName(const QString &newDisplayName)
{
    m_MimeType = QMimeType(m_MimeType.name(), newDisplayName, m_MimeType.iconUrl(), m_MimeType.fileExtentions());
}

// ------------------------------------------------------------------------------------------------

const QString &DeclarativeMimeType::iconUrl() const
{
    return m_MimeType.iconUrl();
}

// ------------------------------------------------------------------------------------------------

void DeclarativeMimeType::setIconUrl(const QString &newIconUrl)
{
    m_MimeType = QMimeType(m_MimeType.name(), m_MimeType.displayName(), newIconUrl, m_MimeType.fileExtentions());
}

// ------------------------------------------------------------------------------------------------

QVariantList DeclarativeMimeType::fileExtentions() const
{
    QVariantList result;

    foreach (const QString &fileExtention, m_MimeType.fileExtentions()) {
        result << fileExtention;
    }

    return result;
}

// ------------------------------------------------------------------------------------------------

void DeclarativeMimeType::setFileExtentions(const QVariantList &newFileExtentions)
{
    QList<QString> result;

    foreach (const QVariant &newFileExtention, newFileExtentions) {
        if (newFileExtention.type() != QVariant::String) {
            qWarning() << Q_FUNC_INFO << "newFileExtention" << newFileExtention << " is not a string!";
            continue;
        }

        result << newFileExtention.toString();
    }

    m_MimeType = QMimeType(m_MimeType.name(), m_MimeType.displayName(), m_MimeType.iconUrl(), result);
}