1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #pragma once
41 
42 #include <utils/utils_global.h>
43 
44 #include <QtCore/qshareddata.h>
45 #include <QtCore/qstring.h>
46 
47 QT_BEGIN_NAMESPACE
48 class QFileinfo;
49 QT_END_NAMESPACE
50 
51 namespace Utils {
52 
53 namespace Internal {
54 class MimeTypeParserBase;
55 class MimeTypeMapEntry;
56 class MimeDatabasePrivate;
57 class MimeXMLProvider;
58 class MimeBinaryProvider;
59 class MimeTypePrivate;
60 }
61 
62 class QTCREATOR_UTILS_EXPORT MimeType
63 {
64 public:
65     MimeType();
66     MimeType(const MimeType &other);
67     MimeType &operator=(const MimeType &other);
68 //#ifdef Q_COMPILER_RVALUE_REFS
69 //    MimeType &operator=(MimeType &&other)
70 //    {
71 //        qSwap(d, other.d);
72 //        return *this;
73 //    }
74 //#endif
75 //    void swap(MimeType &other)
76 //    {
77 //        qSwap(d, other.d);
78 //    }
79     explicit MimeType(const Internal::MimeTypePrivate &dd);
80     ~MimeType();
81 
82     bool operator==(const MimeType &other) const;
83 
84     inline bool operator!=(const MimeType &other) const
85     {
86         return !operator==(other);
87     }
88 
89     bool isValid() const;
90 
91     bool isDefault() const;
92 
93     QString name() const;
94     QString comment() const;
95     QString genericIconName() const;
96     QString iconName() const;
97     QStringList globPatterns() const;
98     QStringList parentMimeTypes() const;
99     QStringList allAncestors() const;
100     QStringList aliases() const;
101     QStringList suffixes() const;
102     QString preferredSuffix() const;
103 
104     bool inherits(const QString &mimeTypeName) const;
105 
106     QString filterString() const;
107 
108     // Qt Creator additions
109     bool matchesName(const QString &nameOrAlias) const;
110     void setPreferredSuffix(const QString &suffix);
111 
112 protected:
113     friend class Internal::MimeTypeParserBase;
114     friend class Internal::MimeTypeMapEntry;
115     friend class Internal::MimeDatabasePrivate;
116     friend class Internal::MimeXMLProvider;
117     friend class Internal::MimeBinaryProvider;
118     friend class Internal::MimeTypePrivate;
119 
120     QExplicitlySharedDataPointer<Internal::MimeTypePrivate> d;
121 };
122 
qHash(const MimeType & mime)123 inline auto qHash(const MimeType &mime) { return qHash(mime.name()); }
124 
125 } // Utils
126 
127 //Q_DECLARE_SHARED(Utils::MimeType)
128 
129 #ifndef QT_NO_DEBUG_STREAM
130 QT_BEGIN_NAMESPACE
131 class QDebug;
132 QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug debug, const Utils::MimeType &mime);
133 QT_END_NAMESPACE
134 #endif
135 
136