summaryrefslogtreecommitdiffstats
path: root/tdeio/tdeio/kmimetypechooser.h
blob: 16ec052f5ddb2a9f11c7aef6151dc1b83649b9aa (plain)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* 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 <tqvbox.h>
#include <kdialogbase.h>


/**
 * 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 TDEIO_EXPORT KMimeTypeChooser : public TQVBox
{
  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
     * @param name The internal name of this object
     */
    KMimeTypeChooser( const TQString& text=TQString::null,
                      const TQStringList &selectedMimeTypes=0,
                      const TQString &defaultGroup=TQString::null,
                      const TQStringList &groupsToShow=TQStringList(),
                      int visuals=Comments|Patterns|EditButton,
                      TQWidget *parent=0, const char *name=0 );
    ~KMimeTypeChooser();

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

  public slots:
    /**
     * @short edit the current mimetype
     * Uses KRun to start the KDE mimetype editor for editing the currently
     * selected mimetype.
     */
    void editMimeType();

  private slots:
    /**
     * @internal disables the "edit" button for groups
     */
    void slotCurrentChanged(TQListViewItem* i);

    /**
     *  @internal called when the sycoca database has changed after
     * the user edited a mimetype
     */
     void slotSycocaDatabaseChanged();

  private:
    /**
     * @internal Load mime types into the list view
     * If @p selected is empty, selectedMimeTypesStringList() is called
     * to fill it in.
     */
    void loadMimeTypes( const TQStringList &selected=TQStringList() );

    class KMimeTypeChooserPrivate *d;
};

/**
  * @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
  *    TQString text = i18n("Select the MimeTypes you want for this file type.");
  *    TQStringList list = TQStringList::split( TQRegExp("\\s*;\\s*"), leMimetypes->text() );
  *    KMimeTypeChooserDialog *d = new KMimeTypeChooserDialog( this, 0,
  *                  i18n("Select Mime Types"), text, list, "text" );
  *    if ( d->exec() == KDialogBase::Accepted ) {
  *      leWildcards->setText( d->chooser()->patterns().join(";") );
  *      leMimetypes->setText( d->chooser()->mimeTypes().join(";") );
  *    }
  * @endcode
  *
  * @author Anders Lund (anders at alweb dk) dec 19, 2001
  */
class TDEIO_EXPORT KMimeTypeChooserDialog : public KDialogBase
{
  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
     * @param name The internal name of this object
     */
    KMimeTypeChooserDialog( const TQString &caption=TQString::null,
                         const TQString& text=TQString::null,
                         const TQStringList &selectedMimeTypes=TQStringList(),
                         const TQString &defaultGroup=TQString::null,
                         const TQStringList &groupsToShow=TQStringList(),
                         int visuals=KMimeTypeChooser::Comments|KMimeTypeChooser::Patterns|KMimeTypeChooser::EditButton,
                         TQWidget *parent=0, const char *name=0 );

    /**
     * @overload
     */
    KMimeTypeChooserDialog( const TQString &caption,
                         const TQString& text,
                         const TQStringList &selectedMimeTypes,
                         const TQString &defaultGroup,
                         TQWidget *parent=0, const char *name=0 );

    ~KMimeTypeChooserDialog();

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

  private:
    KMimeTypeChooser *m_chooser;
};
#endif // _KMIMETYPE_CHOOSER_H_
// kate: space-indent on; indent-width 2; replace-tabs on;