File: mimetypedata.h

package info (click to toggle)
kde-cli-tools 4%3A5.14.5-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,064 kB
  • sloc: cpp: 4,218; sh: 71; makefile: 11
file content (139 lines) | stat: -rw-r--r-- 4,818 bytes parent folder | download
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
/* This file is part of the KDE project
   Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
   Copyright (C) 2003, 2007 David Faure <faure@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License version 2 or at your option version 3 as published by
   the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef MIMETYPEDATA_H
#define MIMETYPEDATA_H

#include <QMimeType>
#include <QMimeDatabase>

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
    MimeTypeData(const QString& major);
    // Real constructor, used for an existing mimetype.
    MimeTypeData(const QMimeType& mime);
    // Real constructor, used for a new mimetype.
    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 embedServices() const;
    void setEmbedServices(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_embedServices;
};

#endif /* MIMETYPEDATA_H */