1/* This file is part of the KDE project
2 Copyright (C) 2007, 2008 David Faure <faure@kde.org>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License or ( at
7 your option ) version 3 or, at the discretion of KDE e.V. ( which shall
8 act as a proxy as in section 14 of the GPLv3 ), any later version.
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 MIMETYPEWRITER_H
22#define MIMETYPEWRITER_H
23
24class QStringList;
25class QString;
26class MimeTypeWriterPrivate;
27
28/// WARNING: this code is duplicated between apps/nsplugins and runtime/filetypes
29
30/**
31 * MimeTypeWriter writes out the definition of a mimetype
32 * in a XDG shared-mime-info compliant way.
33 */
34class MimeTypeWriter
35{
36public:
37 MimeTypeWriter(const QString& mimeType);
38 ~MimeTypeWriter();
39
40 /**
41 * Sets the comment describing this mimetype.
42 * It is strongly recommended to call this.
43 */
44 void setComment(const QString& comment);
45
46 /**
47 * Define the patterns associated with this mimetype,
48 * like "*.png"
49 */
50 void setPatterns(const QStringList& patterns);
51
52 /**
53 * Optional: set a user-specified icon name for this mimetype.
54 * Otherwise the icon name is based on the mimetype name.
55 */
56 void setIconName(const QString& iconName);
57
58 /**
59 * Sets a string that will be written out as an XML comment
60 * in the XML definition file, to make it possible to recognize
61 * this file later on. Used by nspluginscan.
62 */
63 void setMarker(const QString& marker);
64
65 /**
66 * Write out the mimetype definition file
67 * Returns true on success
68 */
69 bool write();
70
71 /**
72 * Returns true if a mimetype definition file already exists
73 * for the given mimetype.
74 *
75 * NOTE: this is not the same as testing whether the
76 * mimetype is defined in general (for instance by freedesktop.org.xml)
77 * you should use KMimeType::mimeType() for that.
78 * This method is only for mimetypes generated by MimeTypeWriter.
79 */
80 static bool hasDefinitionFile(const QString& mimeType);
81
82
83 /**
84 * Remove mimetype created by MimeTypeWriter.
85 * Assumes hasDefinitionFile(mimeType).
86 * Remember to call runUpdateMimeDatabase afterwards!
87 */
88 static void removeOwnMimeType(const QString& mimeType);
89
90 /**
91 * Call this once after writing as many mimetypes as you want,
92 * to let update-mime-database process the new mimetype xml files.
93 */
94 static void runUpdateMimeDatabase();
95
96private:
97 MimeTypeWriterPrivate* const d;
98};
99
100/// WARNING: this code is duplicated between apps/nsplugins and runtime/filetypes
101
102#endif /* MIMETYPEWRITER_H */
103