1/* This file is part of the KDE libraries
2 Copyright (C) 2001 - 2004 Anders Lund <anders@alweb.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#ifndef KMIMETYPE_CHOOSER_H
20#define KMIMETYPE_CHOOSER_H
21
22#include <kio/kio_export.h>
23#include <kdialog.h>
24#include <kvbox.h>
25
26class QTreeWidgetItem;
27
28/**
29 * This widget provides a checkable list of all available mimetypes,
30 * and a list of selected ones, as well as a corresponding list of file
31 * extensions, an optional text and an optional edit button (not working yet).
32 * Mime types is presented in a list view, with name, comment and patterns columns.
33 *
34 * @author Anders Lund (anders at alweb dk), jan 23, 2002
35 */
36class KIO_EXPORT KMimeTypeChooser : public KVBox
37{
38 Q_OBJECT
39
40 public:
41 /**
42 * Buttons and data for display.
43 */
44 enum Visuals {
45 Comments=1, ///< Show the Mimetypes Comment field in a column ("HTML Document").
46 Patterns=2, ///< Show the Mimetypes Patterns field in a column ("*.html;*.htm").
47 EditButton=4 ///< Show the "Edit" button, allowing to edit the selected type.
48 };
49 /**
50 * Create a new KMimeTypeChooser.
51 *
52 * @param text A Text to display above the list
53 * @param selectedMimeTypes A list of mimetype names, theese will be checked
54 * in the list if they exist.
55 * @param visuals A OR'd Visuals enum to decide which data and buttons to display.
56 * @param defaultGroup The group to open when no groups are selected (like
57 * "text"). If not provided, no group is opened. If @p groupsToShow
58 * is provided and defaultGroup is not a member of that, it is ignored.
59 * @param groupsToShow a list of mimetype groups to show. If empty, all
60 * groups are shown.
61 * @param parent The parent widget to use
62 */
63 explicit
64 KMimeTypeChooser( const QString& text=QString(),
65 const QStringList &selectedMimeTypes=QStringList(),
66 const QString &defaultGroup=QString(),
67 const QStringList &groupsToShow=QStringList(),
68 int visuals=Comments|Patterns|EditButton,
69 QWidget *parent=0 );
70 ~KMimeTypeChooser();
71
72 /**
73 * @return a list of all selected selected mimetypes represented by their name.
74 */
75 QStringList mimeTypes() const;
76 /**
77 * @return a list of the fileame patterns associated with all selected mimetypes.
78 */
79 QStringList patterns() const;
80
81 private:
82 class KMimeTypeChooserPrivate *d;
83
84 Q_PRIVATE_SLOT( d, void _k_editMimeType() )
85 Q_PRIVATE_SLOT( d, void _k_slotCurrentChanged(QTreeWidgetItem*) )
86 Q_PRIVATE_SLOT( d, void _k_slotSycocaDatabaseChanged(QStringList) )
87};
88
89/**
90 * @short A Dialog to choose some mimetypes.
91 * Provides a checkable tree list of mimetypes, with icons and optinally
92 * comments and patterns, and an (optional) button to display the KDE mimetype
93 * editor.
94 *
95 * Here is an example, using the dialog to set the text of two lineedits:
96 *
97 * @code
98 * QString text = i18n("Select the MimeTypes you want for this file type.");
99 * QStringList list = QStringList::split( QRegExp("\\s*;\\s*"), leMimetypes->text() );
100 * KMimeTypeChooserDialog dlg( i18n("Select Mime Types"), text, list, "text", this );
101 * if ( dlg.exec() == KDialog::Accepted ) {
102 * leWildcards->setText( dlg.chooser()->patterns().join(";") );
103 * leMimetypes->setText( dlg.chooser()->mimeTypes().join(";") );
104 * }
105 * @endcode
106 *
107 * \image html kmimetypechooserdialog.png "KMimeTypeChooserDialog in action"
108 *
109 * @author Anders Lund (anders at alweb dk) dec 19, 2001
110 */
111class KIO_EXPORT KMimeTypeChooserDialog : public KDialog
112{
113 public:
114 /**
115 * Create a KMimeTypeChooser dialog.
116 *
117 * @param caption The title of the dialog
118 * @param text A Text to display above the list
119 * @param selectedMimeTypes A list of mimetype names, theese will be
120 * checked in the list if they exist.
121 * patterns will be added to the list view.
122 * @param visuals A OR'd KMimetypeChooser::Visuals enum to decide which data
123 * and buttons to display.
124 * @param defaultGroup The group to open when no groups are selected (like
125 * "text"). If not provided, no group is opened. If @p groupsToShow
126 * is provided and defaultGroup is not a member of that, it is ignored.
127 * @param groupsToShow a list of mimetype groups to show. If empty, all
128 * groups are shown.
129 * @param parent The parent widget to use
130 */
131 explicit
132 KMimeTypeChooserDialog( const QString &caption=QString(),
133 const QString& text=QString(),
134 const QStringList &selectedMimeTypes=QStringList(),
135 const QString &defaultGroup=QString(),
136 const QStringList &groupsToShow=QStringList(),
137 int visuals=KMimeTypeChooser::Comments|KMimeTypeChooser::Patterns|KMimeTypeChooser::EditButton,
138 QWidget *parent=0 );
139
140 /**
141 * @overload
142 */
143 KMimeTypeChooserDialog( const QString &caption,
144 const QString& text,
145 const QStringList &selectedMimeTypes,
146 const QString &defaultGroup,
147 QWidget *parent=0 );
148
149 ~KMimeTypeChooserDialog();
150
151 /**
152 * @return a pointer to the KMimeTypeChooser widget
153 */
154 KMimeTypeChooser* chooser();
155
156 private:
157 class Private;
158 Private* const d;
159};
160#endif // _KMIMETYPE_CHOOSER_H_
161// kate: space-indent on; indent-width 2; replace-tabs on;
162