File indexing completed on 2024-04-28 16:44:27
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2007, 2008 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef MIMETYPEWRITER_H 0008 #define MIMETYPEWRITER_H 0009 0010 #include <QtContainerFwd> 0011 class QString; 0012 class MimeTypeWriterPrivate; 0013 0014 /// WARNING: this code is duplicated between apps/nsplugins and runtime/filetypes 0015 0016 /** 0017 * MimeTypeWriter writes out the definition of a mimetype 0018 * in a XDG shared-mime-info compliant way. 0019 */ 0020 class MimeTypeWriter 0021 { 0022 public: 0023 MimeTypeWriter(const QString &mimeType); 0024 ~MimeTypeWriter(); 0025 0026 /** 0027 * Sets the comment describing this mimetype. 0028 * It is strongly recommended to call this. 0029 */ 0030 void setComment(const QString &comment); 0031 0032 /** 0033 * Define the patterns associated with this mimetype, 0034 * like "*.png" 0035 */ 0036 void setPatterns(const QStringList &patterns); 0037 0038 /** 0039 * Optional: set a user-specified icon name for this mimetype. 0040 * Otherwise the icon name is based on the mimetype name. 0041 */ 0042 void setIconName(const QString &iconName); 0043 0044 /** 0045 * Sets a string that will be written out as an XML comment 0046 * in the XML definition file, to make it possible to recognize 0047 * this file later on. Used by nspluginscan. 0048 */ 0049 void setMarker(const QString &marker); 0050 0051 /** 0052 * Write out the mimetype definition file 0053 * Returns true on success 0054 */ 0055 bool write(); 0056 0057 /** 0058 * Returns true if a mimetype definition file already exists 0059 * for the given mimetype. 0060 * 0061 * NOTE: this is not the same as testing whether the 0062 * mimetype is defined in general (for instance by freedesktop.org.xml) 0063 * you should use db.mimeTypeForName() for that. 0064 * This method is only for mimetypes generated by MimeTypeWriter. 0065 */ 0066 static bool hasDefinitionFile(const QString &mimeType); 0067 0068 /** 0069 * Remove mimetype created by MimeTypeWriter. 0070 * Assumes hasDefinitionFile(mimeType). 0071 * Remember to call runUpdateMimeDatabase afterwards! 0072 */ 0073 static void removeOwnMimeType(const QString &mimeType); 0074 0075 /** 0076 * Call this once after writing as many mimetypes as you want, 0077 * to let update-mime-database process the new mimetype xml files. 0078 */ 0079 static void runUpdateMimeDatabase(); 0080 0081 private: 0082 MimeTypeWriterPrivate *const d; 0083 }; 0084 0085 /// WARNING: this code is duplicated between apps/nsplugins and runtime/filetypes 0086 0087 #endif /* MIMETYPEWRITER_H */