File: kmimetypechooser.h

package info (click to toggle)
kwidgetsaddons 5.28.0-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 62,388 kB
  • ctags: 3,611
  • sloc: cpp: 26,647; python: 682; sh: 23; makefile: 6
file content (160 lines) | stat: -rw-r--r-- 6,338 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* This file is part of the KDE libraries
   Copyright (C) 2001 - 2004 Anders Lund <anders@alweb.dk>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef KMIMETYPE_CHOOSER_H
#define KMIMETYPE_CHOOSER_H

#include <kwidgetsaddons_export.h>
#include <QDialog>
#include <QWidget>

class QTreeWidgetItem;

/**
 * This widget provides a checkable list of all available mimetypes,
 * and a list of selected ones, as well as a corresponding list of file
 * extensions, an optional text and an optional edit button (not working yet).
 * Mime types is presented in a list view, with name, comment and patterns columns.
 *
 * @author Anders Lund (anders at alweb dk), jan 23, 2002
 */
class KWIDGETSADDONS_EXPORT KMimeTypeChooser : public QWidget
{
    Q_OBJECT

public:
    /**
     * Buttons and data for display.
     */
    enum Visuals {
        Comments = 1, ///< Show the Mimetypes Comment field in a column ("HTML Document").
        Patterns = 2, ///< Show the Mimetypes Patterns field in a column ("*.html;*.htm").
        EditButton = 4 ///< Show the "Edit" button, allowing to edit the selected type.
    };
    /**
     * Create a new KMimeTypeChooser.
     *
     * @param text A Text to display above the list
     * @param selectedMimeTypes A list of mimetype names, theese will be checked
     *        in the list if they exist.
     * @param visuals A OR'd Visuals enum to decide which data and buttons to display.
     * @param defaultGroup The group to open when no groups are selected (like
     *        "text"). If not provided, no group is opened. If @p groupsToShow
     *        is provided and defaultGroup is not a member of that, it is ignored.
     * @param groupsToShow a list of mimetype groups to show. If empty, all
     *        groups are shown.
     * @param parent The parent widget to use
     */
    explicit
    KMimeTypeChooser(const QString &text = QString(),
                     const QStringList &selectedMimeTypes = QStringList(),
                     const QString &defaultGroup = QString(),
                     const QStringList &groupsToShow = QStringList(),
                     int visuals = Comments | Patterns | EditButton,
                     QWidget *parent = 0);
    ~KMimeTypeChooser();

    /**
     * @return a list of all selected selected mimetypes represented by their name.
     */
    QStringList mimeTypes() const;
    /**
     * @return a list of the fileame patterns associated with all selected mimetypes.
     */
    QStringList patterns() const;

private:
    class KMimeTypeChooserPrivate *d;

    Q_PRIVATE_SLOT(d, void _k_editMimeType())
    Q_PRIVATE_SLOT(d, void _k_slotCurrentChanged(QTreeWidgetItem *))
    Q_PRIVATE_SLOT(d, void _k_slotSycocaDatabaseChanged(QStringList))
};

/**
  * @short A Dialog to choose some mimetypes.
  * Provides a checkable tree list of mimetypes, with icons and optinally
  * comments and patterns, and an (optional) button to display the KDE mimetype
  * editor.
  *
  * Here is an example, using the dialog to set the text of two lineedits:
  *
  * @code
  *    QString text = i18n("Select the MimeTypes you want for this file type.");
  *    QStringList list = QStringList::split( QRegExp("\\s*;\\s*"), leMimetypes->text() );
  *    KMimeTypeChooserDialog dlg( i18n("Select Mime Types"), text, list, "text", this );
  *    if ( dlg.exec() == KDialog::Accepted ) {
  *      leWildcards->setText( dlg.chooser()->patterns().join(";") );
  *      leMimetypes->setText( dlg.chooser()->mimeTypes().join(";") );
  *    }
  * @endcode
  *
  * \image html kmimetypechooserdialog.png "KMimeTypeChooserDialog in action"
  *
  * @author Anders Lund (anders at alweb dk) dec 19, 2001
  */
class KWIDGETSADDONS_EXPORT KMimeTypeChooserDialog : public QDialog
{
public:
    /**
     * Create a KMimeTypeChooser dialog.
     *
     * @param caption The title of the dialog
     * @param text A Text to display above the list
     * @param selectedMimeTypes A list of mimetype names, theese will be
     *        checked in the list if they exist.
     *        patterns will be added to the list view.
     * @param visuals A OR'd KMimetypeChooser::Visuals enum to decide which data
     *        and buttons to display.
     * @param defaultGroup The group to open when no groups are selected (like
     *        "text"). If not provided, no group is opened. If @p groupsToShow
     *        is provided and defaultGroup is not a member of that, it is ignored.
     * @param groupsToShow a list of mimetype groups to show. If empty, all
     *        groups are shown.
     * @param parent The parent widget to use
     */
    explicit
    KMimeTypeChooserDialog(const QString &caption = QString(),
                           const QString &text = QString(),
                           const QStringList &selectedMimeTypes = QStringList(),
                           const QString &defaultGroup = QString(),
                           const QStringList &groupsToShow = QStringList(),
                           int visuals = KMimeTypeChooser::Comments | KMimeTypeChooser::Patterns | KMimeTypeChooser::EditButton,
                           QWidget *parent = 0);

    /**
     * @overload
     */
    KMimeTypeChooserDialog(const QString &caption,
                           const QString &text,
                           const QStringList &selectedMimeTypes,
                           const QString &defaultGroup,
                           QWidget *parent = 0);

    ~KMimeTypeChooserDialog();

    /**
     * @return a pointer to the KMimeTypeChooser widget
     */
    KMimeTypeChooser *chooser();

private:
    class Private;
    Private *const d;
};
#endif // _KMIMETYPE_CHOOSER_H_