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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/* This file is part of the KDE project
SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org>
SPDX-FileCopyrightText: 2003, 2007 David Faure <faure@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
*/
#ifndef MIMETYPEDATA_H
#define MIMETYPEDATA_H
#include <QMimeType>
class KConfigGroup;
/**
* This is a non-gui (data) class, that represents a mimetype.
* It is a QMimeType plus the changes we made to it.
*/
class MimeTypeData
{
public:
// Constructor used for groups
explicit MimeTypeData(const QString &major);
// Real constructor, used for an existing mimetype.
explicit MimeTypeData(const QMimeType &mime);
// Real constructor, used for a new mimetype.
explicit MimeTypeData(const QString &mimeName, bool /*unused, just to distinguish from the other QString ctor*/);
QString name() const
{
return m_isGroup ? m_major : m_major + QLatin1Char('/') + m_minor;
}
QString majorType() const
{
return m_major;
}
QString minorType() const
{
return m_minor;
}
void setMinor(const QString &m)
{
m_minor = m;
}
QString comment() const
{
return m_comment;
}
void setComment(const QString &c)
{
m_comment = c;
}
/**
* Returns true if "this" is a group
*/
bool isMeta() const
{
return m_isGroup;
}
/**
* Returns true if the type is essential, i.e. can't be deleted
* (see KMimeType::checkEssentialMimeTypes)
*/
bool isEssential() const;
QString icon() const;
void setUserSpecifiedIcon(const QString &icon);
QStringList patterns() const
{
return m_patterns;
}
void setPatterns(const QStringList &p);
QStringList appServices() const;
void setAppServices(const QStringList &dsl);
QStringList embedParts() const;
void setEmbedParts(const QStringList &dsl);
enum AutoEmbed {
Yes = 0,
No = 1,
UseGroupSetting = 2,
};
AutoEmbed autoEmbed() const
{
return m_autoEmbed;
}
void setAutoEmbed(AutoEmbed a)
{
m_autoEmbed = a;
}
const QMimeType &mimeType() const
{
return m_mimetype;
}
bool canUseGroupSetting() const;
void getAskSave(bool &);
void setAskSave(bool);
/**
* Returns true if the mimetype data has any unsaved changes.
*/
bool isDirty() const;
/**
* Returns true if the mimetype data has any unsaved changes in the service list.
*/
bool isServiceListDirty() const;
/**
* Save changes to disk.
* Does not check isDirty(), so the common idiom is if (data.isDirty()) { needUpdate = data.sync(); }
* Returns true if update-mime-database needs to be run afterwards
*/
bool sync();
/**
* Update m_mimetype from the xml when Apply is pressed
*/
void refresh();
/**
* Return true if this is a new mimetype, i.e. one that is not yet on disk
*/
bool isNew() const
{
return m_bNewItem;
}
/**
* Helper method for the filtering in the listview
*/
bool matchesFilter(const QString &filter) const;
private:
void initFromQMimeType();
AutoEmbed readAutoEmbed() const;
void writeAutoEmbed();
bool isMimeTypeDirty() const; // whether the mimetype definition file needs saving
QStringList getAppOffers() const;
QStringList getPartOffers() const;
void getMyServiceOffers() const;
void syncServices();
void saveServices(KConfigGroup &config, const QStringList &services);
void saveDefaultApplication(KConfigGroup &config, const QStringList &services);
void saveRemovedServices(KConfigGroup &config, const QStringList &services, const QStringList &oldServices);
QMimeType m_mimetype;
enum AskSave {
AskSaveYes = 0,
AskSaveNo = 1,
AskSaveDefault = 2,
};
AskSave m_askSave : 3;
AutoEmbed m_autoEmbed : 3;
bool m_bNewItem : 1;
mutable bool m_bFullInit : 1; // lazy init of m_appServices and m_embedServices
bool m_isGroup : 1;
bool m_appServicesModified : 1;
bool m_embedServicesModified : 1;
bool m_userSpecifiedIconModified : 1;
QString m_major, m_minor, m_comment, m_userSpecifiedIcon;
QStringList m_patterns;
mutable QStringList m_appServices;
mutable QStringList m_embedParts;
};
#endif /* MIMETYPEDATA_H */
|