Warning, file /frameworks/kwidgetsaddons/src/kmimetypechooser.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2001-2004 Anders Lund <anders@alweb.dk> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef KMIMETYPE_CHOOSER_H 0009 #define KMIMETYPE_CHOOSER_H 0010 0011 #include <QDialog> 0012 #include <QWidget> 0013 #include <kwidgetsaddons_export.h> 0014 #include <memory> 0015 0016 /** 0017 * @class KMimeTypeChooser kmimetypechooser.h KMimeTypeChooser 0018 * 0019 * This widget provides a checkable list of all available MIME types, presented 0020 * as a treeview, with the MIME type comment and glob patterns as individual columns. 0021 * It allows users to edit a MIME type by launching a MIME type editor (if it's 0022 * available on the system). 0023 * 0024 * When the user clicks the OK button, a list of the selected MIME type names 0025 * and associated glob patterns can be retrieved respectively; those lists can 0026 * be used to populate a text line edit, or set a configuration entry... etc. 0027 * 0028 * @author Anders Lund (anders at alweb dk), jan 23, 2002 0029 */ 0030 class KWIDGETSADDONS_EXPORT KMimeTypeChooser : public QWidget 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 /** 0036 * Buttons and data for display. 0037 */ 0038 enum Visuals { 0039 Comments = 1, ///< Show the MIME type comment (e.g. "HTML Document") in a column 0040 Patterns = 2, ///< Show the MIME types glob patterns (e.g. "*.html;*.htm") in a column 0041 EditButton = 4 ///< Show the "Edit" button, allowing to edit the selected type 0042 }; 0043 /** 0044 * Create a new KMimeTypeChooser. 0045 * 0046 * @param text A plain text line to display above the list 0047 * @param selectedMimeTypes A list of MIME type names, these will be initially selected 0048 * in the list (provided they exist) 0049 * @param visuals OR'd KMimetypeChooser::Visuals enum values to to set whether to 0050 * show the MIME type comment and glob patterns columns and an Edit button, 0051 * respectively, or not 0052 * @param defaultGroup The group (e.g. "text") to expand in the treeview when no groups 0053 * are selected. If not provided, no group is expanded by default. 0054 * If @p groupsToShow is provided and it doesn't include @p defaultGroup, this 0055 * parameter is ignored 0056 * @param groupsToShow a list of MIME type groups to show. If empty, all groups are shown 0057 * @param parent The parent widget to use 0058 */ 0059 explicit KMimeTypeChooser(const QString &text = QString(), 0060 const QStringList &selectedMimeTypes = QStringList(), 0061 const QString &defaultGroup = QString(), 0062 const QStringList &groupsToShow = QStringList(), 0063 int visuals = Comments | Patterns | EditButton, 0064 QWidget *parent = nullptr); 0065 ~KMimeTypeChooser() override; 0066 0067 /** 0068 * @return a list of all selected MIME type names 0069 */ 0070 QStringList mimeTypes() const; 0071 /** 0072 * @return a list of the filename glob patterns associated with all selected MIME types 0073 */ 0074 QStringList patterns() const; 0075 0076 private: 0077 std::unique_ptr<class KMimeTypeChooserPrivate> const d; 0078 }; 0079 0080 /** 0081 * @class KMimeTypeChooserDialog kmimetypechooser.h KMimeTypeChooserDialog 0082 * 0083 * @short A dialog to select MIME types from the list of available ones on the system 0084 * 0085 * This dialog embeds KMimeTypeChooser widget, presenting a checkable tree list of 0086 * MIME types, each with its associated icon, and optionally associated glob patterns 0087 * (displayed in a separate column); also an optional Edit button to launch a 0088 * MIME type editor to edit the selected MIME type. 0089 * 0090 * Here is an example, using the dialog to set the text of two line edits with the 0091 * list of MIME type names and glob patterns, respectively, of the MIME types that 0092 * the user has selected: 0093 * 0094 * @code 0095 * QLineEdit *leMimetypes = new QLineEdit(); 0096 * QLineEdit *leGlobPatterns = new QLineEdit(); 0097 * [...] 0098 * QString textLine = i18n("Select MIME types"); 0099 * QStringList mimeList = QStringList::split(QRegularExpression("\\s*;\\s*"), leMimetypes->text()); 0100 * KMimeTypeChooserDialog dlg(i18n("Select MIME Types"), textLine, mimeList, "text", this); 0101 * if (dlg.exec() == QDialog::Accepted) { 0102 * leMimetypes->setText(dlg.chooser()->mimeTypes().join(";")); 0103 * leGlobPatterns->setText(dlg.chooser()->patterns().join(";")); 0104 * } 0105 * @endcode 0106 * 0107 * \image html kmimetypechooserdialog.png "KMimeTypeChooserDialog in action" 0108 * 0109 * @author Anders Lund (anders at alweb dk) dec 19, 2001 0110 */ 0111 class KWIDGETSADDONS_EXPORT KMimeTypeChooserDialog : public QDialog 0112 { 0113 Q_OBJECT 0114 public: 0115 /** 0116 * Create a KMimeTypeChooser dialog. 0117 * 0118 * @param title The title of the dialog 0119 * @param text A plain text line to display above the list 0120 * @param selectedMimeTypes A list of MIME type names, these will be initially selected 0121 * in the list, provided they exist 0122 * @param visuals OR'd KMimetypeChooser::Visuals enum values to to set whether to 0123 * show the MIME type comment and glob patterns columns and an Edit button, 0124 * respectively, or not 0125 * @param defaultGroup The group (e.g. "text") to expand in the treeview when no 0126 * groups are selected. If not provided, no group is expanded by default 0127 * If @p groupsToShow is provided and it doesn't include @p defaultGroup, 0128 * this parameter is ignored 0129 * @param groupsToShow A list of MIME type groups to show. If empty, all groups are shown 0130 * @param parent The parent widget to use 0131 */ 0132 explicit KMimeTypeChooserDialog(const QString &title = QString(), 0133 const QString &text = QString(), 0134 const QStringList &selectedMimeTypes = QStringList(), 0135 const QString &defaultGroup = QString(), 0136 const QStringList &groupsToShow = QStringList(), 0137 int visuals = KMimeTypeChooser::Comments | KMimeTypeChooser::Patterns | KMimeTypeChooser::EditButton, 0138 QWidget *parent = nullptr); 0139 0140 /** 0141 * @overload 0142 */ 0143 KMimeTypeChooserDialog(const QString &title, 0144 const QString &text, 0145 const QStringList &selectedMimeTypes, 0146 const QString &defaultGroup, 0147 QWidget *parent = nullptr); 0148 0149 ~KMimeTypeChooserDialog() override; 0150 0151 /** 0152 * @return a pointer to the KMimeTypeChooser widget 0153 */ 0154 KMimeTypeChooser *chooser(); 0155 0156 QSize sizeHint() const override; 0157 0158 private: 0159 std::unique_ptr<class KMimeTypeChooserDialogPrivate> const d; 0160 }; 0161 #endif // _KMIMETYPE_CHOOSER_H_