File indexing completed on 2024-05-12 16:39:37
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003-2018 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KEXIFILEFILTERS_H 0021 #define KEXIFILEFILTERS_H 0022 0023 #include "kexicore_export.h" 0024 0025 #include <QList> 0026 0027 class QMimeType; 0028 class QString; 0029 class QStringList; 0030 0031 //! Format specification for KexiFileFilters 0032 class KEXICORE_EXPORT KexiFileFiltersFormat 0033 { 0034 public: 0035 //! Format type 0036 enum class Type { 0037 Qt, //!< QFileDialog-compatible format, e.g. "Image files (*.png *.xpm *.jpg)", ";;" 0038 //!< separators 0039 KDE, //!< KDE-compatible format, e.g. "*.png *.xpm *.jpg|Image files (*.png *.xpm 0040 //!< *.jpg)", "\\n" separators 0041 KUrlRequester //!< KUrlRequester-compatible format, e.g. "*.png *.xpm *.jpg|Image 0042 //!< files", "\\n" separators 0043 }; 0044 0045 Type type = Type::KDE; 0046 0047 //!< Add "All files" entry needed e.g. for KexiFileRequester because KFileFilterCombo does not 0048 //! add it automatically while KFileWidget does. 0049 bool addAllFiles = false; 0050 }; 0051 0052 //! A tool for handling file filters for Kexi 0053 class KEXICORE_EXPORT KexiFileFilters 0054 { 0055 public: 0056 //! Filter mode 0057 enum Mode { 0058 Opening, //!< Opening existing database (or shortcut) 0059 CustomOpening, //!< Used for opening other files, like CSV 0060 SavingFileBasedDB, //!< Saving file-based database file 0061 CustomSavingFileBasedDB, //!< Used for saving other files, like CSV 0062 SavingServerBasedDB //!< Saving server-based (shortcut) file 0063 }; 0064 0065 KexiFileFilters(); 0066 ~KexiFileFilters(); 0067 0068 //! @return mode for the filer 0069 Mode mode() const; 0070 0071 //! Sets mode for the filter 0072 void setMode(Mode mode); 0073 0074 /*! Sets a default-filter, that is used when an empty filter is set. 0075 * By default, this is set to "All Supported Files" 0076 * @see defaultFilter 0077 */ 0078 void setDefaultFilter(const QString &filter); 0079 0080 /** 0081 * @return the default filter, used when an empty filter is set. 0082 * @see setDefaultFilter 0083 */ 0084 QString defaultFilter() const; 0085 0086 //! @return additional mime types 0087 QStringList additionalMimeTypes() const; 0088 0089 //! Sets additional mime types, e.g. "text/x-csv" 0090 void setAdditionalMimeTypes(const QStringList &mimeTypes); 0091 0092 //! @return excluded mime types 0093 QStringList excludedMimeTypes() const; 0094 0095 //! Set excluded mime types 0096 void setExcludedMimeTypes(const QStringList &mimeTypes); 0097 0098 //! @return glob patterns for all mime types for given mode 0099 //! Includes additional mime types and excludes miem types specified by excludedMimeTypes(). 0100 QStringList allGlobPatterns() const; 0101 0102 //! @return mime types for this filter 0103 QList<QMimeType> mimeTypes() const; 0104 0105 //! @return mime types names for this filter 0106 QStringList mimeTypeNames() const; 0107 0108 //! @return @c true if existing file is required 0109 //! This is true for Opening and CustomOpening modes. 0110 bool isExistingFileRequired() const; 0111 0112 static QString separator(const KexiFileFiltersFormat &format); 0113 0114 //! @return filters based on supplied parameters in given format 0115 QString toString(const KexiFileFiltersFormat &format) const; 0116 0117 //! @return list of filters based on supplied parameters in given format 0118 QStringList toList(const KexiFileFiltersFormat &format) const; 0119 0120 //! @return filter string in given format 0121 static QString toString(const QMimeType &mime, const KexiFileFiltersFormat &format); 0122 0123 //! @overload 0124 static QString toString(const QString& mimeName, const KexiFileFiltersFormat &format); 0125 0126 //! @overload 0127 static QString toString(const QStringList &patterns, const QString &comment, 0128 const KexiFileFiltersFormat &format); 0129 0130 //! Static version of QString KexiFileFilters::toString(Format format) const 0131 static QString toString(const QStringList& mimeNames, const KexiFileFiltersFormat &format); 0132 0133 //! Static version of QStringList toList(Format format) const 0134 static QStringList toList(const QStringList& mimeNames, const KexiFileFiltersFormat &format); 0135 0136 private: 0137 class Private; 0138 Private * const d; 0139 }; 0140 0141 #endif