1 | /* This file is part of the KDE project |
2 | Copyright (C) 2003 Waldo Bastian <bastian@kde.org> |
3 | Copyright (C) 2003, 2007 David Faure <faure@kde.org> |
4 | |
5 | This program is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU General Public |
7 | License version 2 or at your option version 3 as published by |
8 | the Free Software Foundation. |
9 | |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; see the file COPYING. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef MIMETYPEDATA_H |
22 | #define MIMETYPEDATA_H |
23 | |
24 | #include <kmimetype.h> |
25 | |
26 | /** |
27 | * This is a non-gui (data) class, that represents a mimetype. |
28 | * It is a KMimeType::Ptr plus the changes we made to it. |
29 | */ |
30 | class MimeTypeData |
31 | { |
32 | public: |
33 | // Constructor used for groups |
34 | MimeTypeData(const QString& major); |
35 | // Real constructor, used for an existing mimetype. |
36 | MimeTypeData(const KMimeType::Ptr mime); |
37 | // Real constructor, used for a new mimetype. |
38 | MimeTypeData(const QString& mimeName, bool /*unused, just to distinguish from the other QString ctor*/); |
39 | |
40 | QString name() const { return m_isGroup ? m_major : m_major + '/' + m_minor; } |
41 | QString majorType() const { return m_major; } |
42 | QString minorType() const { return m_minor; } |
43 | void setMinor(const QString& m) { m_minor = m; } |
44 | QString () const { return m_comment; } |
45 | void (const QString& c) { m_comment = c; } |
46 | |
47 | /** |
48 | * Returns true if "this" is a group |
49 | */ |
50 | bool isMeta() const { return m_isGroup; } |
51 | |
52 | /** |
53 | * Returns true if the type is essential, i.e. can't be deleted |
54 | * (see KMimeType::checkEssentialMimeTypes) |
55 | */ |
56 | bool isEssential() const; |
57 | QString icon() const; |
58 | void setUserSpecifiedIcon(const QString& icon); |
59 | QStringList patterns() const { return m_patterns; } |
60 | void setPatterns(const QStringList &p); |
61 | QStringList appServices() const; |
62 | void setAppServices(const QStringList &dsl); |
63 | QStringList embedServices() const; |
64 | void setEmbedServices(const QStringList &dsl); |
65 | |
66 | enum AutoEmbed { Yes = 0, No = 1, UseGroupSetting = 2 }; |
67 | AutoEmbed autoEmbed() const { return m_autoEmbed; } |
68 | void setAutoEmbed( AutoEmbed a ) { m_autoEmbed = a; } |
69 | |
70 | const KMimeType::Ptr& mimeType() const { return m_mimetype; } |
71 | bool canUseGroupSetting() const; |
72 | |
73 | void getAskSave(bool &); |
74 | void setAskSave(bool); |
75 | |
76 | /** |
77 | * Returns true if the mimetype data has any unsaved changes. |
78 | */ |
79 | bool isDirty() const; |
80 | |
81 | /** |
82 | * Returns true if the mimetype data has any unsaved changes in the service list. |
83 | */ |
84 | bool isServiceListDirty() const; |
85 | |
86 | /** |
87 | * Save changes to disk. |
88 | * Does not check isDirty(), so the common idiom is if (data.isDirty()) { needUpdate = data.sync(); } |
89 | * Returns true if update-mime-database needs to be run afterwards |
90 | */ |
91 | bool sync(); |
92 | /** |
93 | * Update m_mimetype from the xml when Apply is pressed |
94 | */ |
95 | void refresh(); |
96 | |
97 | /** |
98 | * Return true if this is a new mimetype, i.e. one that is not yet on disk |
99 | */ |
100 | bool isNew() const { return m_bNewItem; } |
101 | |
102 | /** |
103 | * Helper method for the filtering in the listview |
104 | */ |
105 | bool matchesFilter(const QString& filter) const; |
106 | |
107 | private: |
108 | void initFromKMimeType(); |
109 | AutoEmbed readAutoEmbed() const; |
110 | void writeAutoEmbed(); |
111 | bool isMimeTypeDirty() const; // whether the mimetype definition file needs saving |
112 | QStringList getAppOffers() const; |
113 | QStringList getPartOffers() const; |
114 | void getMyServiceOffers() const; |
115 | void syncServices(); |
116 | void saveServices(KConfigGroup & config, const QStringList& services); |
117 | void saveRemovedServices(KConfigGroup & config, const QStringList& services, const QStringList& oldServices); |
118 | |
119 | KMimeType::Ptr m_mimetype; // 0 if this is data for a mimetype group (m_isGroup==true) |
120 | enum AskSave { AskSaveYes = 0, AskSaveNo = 1, AskSaveDefault = 2 }; |
121 | AskSave m_askSave:3; |
122 | AutoEmbed m_autoEmbed:3; |
123 | bool m_bNewItem:1; |
124 | mutable bool m_bFullInit:1; // lazy init of m_appServices and m_embedServices |
125 | bool m_isGroup:1; |
126 | bool m_appServicesModified:1; |
127 | bool m_embedServicesModified:1; |
128 | QString m_major, m_minor, , m_userSpecifiedIcon; |
129 | QStringList m_patterns; |
130 | mutable QStringList m_appServices; |
131 | mutable QStringList m_embedServices; |
132 | }; |
133 | |
134 | #endif /* MIMETYPEDATA_H */ |
135 | |