KIO

kencodingfiledialog.h
1// -*- c++ -*-
2/*
3 This file is part of the KDE libraries
4 SPDX-FileCopyrightText: 2003 Joseph Wenninger <jowenn@kde.org>
5 SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@freemail.hu>
6 SPDX-FileCopyrightText: 2013 Teo Mrnjavac <teo@kde.org>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#ifndef __KENCODINGFILEDIALOG_H__
12#define __KENCODINGFILEDIALOG_H__
13
14#include "kiofilewidgets_export.h"
15
16#include <QFileDialog>
17
18#include <memory>
19
20struct KEncodingFileDialogPrivate;
21
22/**
23 * @class KEncodingFileDialog kencodingfiledialog.h <KEncodingFileDialog>
24 *
25 * Provides a user (and developer) friendly way to select files with support for
26 * choosing encoding.
27 * This class comes with a private constructor, the only way to show a file dialog
28 * is through its static methods.
29 */
31{
33
34public:
35 class KIOFILEWIDGETS_EXPORT Result
36 {
37 public:
38 QStringList fileNames;
39 QList<QUrl> URLs;
40 QString encoding;
41 };
42
43 /**
44 * Creates a modal file dialog and return the selected
45 * filename or an empty string if none was chosen additionally a chosen
46 * encoding value is returned.
47 *
48 * Note that with
49 * this method the user must select an existing filename.
50 *
51 * @param encoding The encoding shown in the encoding combo.
52 * @param startDir This can either be
53 * @li The URL of the directory to start in.
54 * @li QString() to start in the current working
55 * directory, or the last directory where a file has been
56 * selected.
57 * @li ':&lt;keyword&gt;' to start in the directory last used
58 * by a filedialog in the same application that specified
59 * the same keyword.
60 * @li '::&lt;keyword&gt;' to start in the directory last used
61 * by a filedialog in any application that specified the
62 * same keyword.
63 * @param filter A shell glob or a MIME type filter that specifies which files to display.
64 * The preferred option is to set a list of MIME type names, see setMimeFilter() for details.
65 * Otherwise you can set the text to be displayed for the each glob, and
66 * provide multiple globs, see setFilter() for details.
67 * @param parent The widget the dialog will be centered on initially.
68 * @param title The name of the dialog widget.
69 */
70 static KIOFILEWIDGETS_EXPORT Result getOpenFileNameAndEncoding(const QString &encoding = QString(),
71 const QUrl &startDir = QUrl(),
72 const QString &filter = QString(),
73 QWidget *parent = nullptr,
74 const QString &title = QString());
75
76 /**
77 * Creates a modal file dialog and returns the selected encoding and the selected
78 * filenames or an empty list if none was chosen.
79 *
80 * Note that with
81 * this method the user must select an existing filename.
82 *
83 * @param encoding The encoding shown in the encoding combo.
84 * @param startDir This can either be
85 * @li The URL of the directory to start in.
86 * @li QString() to start in the current working
87 * directory, or the last directory where a file has been
88 * selected.
89 * @li ':&lt;keyword&gt;' to start in the directory last used
90 * by a filedialog in the same application that specified
91 * the same keyword.
92 * @li '::&lt;keyword&gt;' to start in the directory last used
93 * by a filedialog in any application that specified the
94 * same keyword.
95 * @param filter A shell glob or a MIME type filter that specifies which files to display.
96 * The preferred option is to set a list of MIME type names, see setMimeFilter() for details.
97 * Otherwise you can set the text to be displayed for the each glob, and
98 * provide multiple globs, see setFilter() for details.
99 * @param parent The widget the dialog will be centered on initially.
100 * @param title The name of the dialog widget.
101 */
102 static KIOFILEWIDGETS_EXPORT Result getOpenFileNamesAndEncoding(const QString &encoding = QString(),
103 const QUrl &startDir = QUrl(),
104 const QString &filter = QString(),
105 QWidget *parent = nullptr,
106 const QString &title = QString());
107
108 /**
109 * Creates a modal file dialog and returns the selected encoding and
110 * URL or an empty string if none was chosen.
111 *
112 * Note that with
113 * this method the user must select an existing URL.
114 *
115 * @param encoding The encoding shown in the encoding combo.
116 * @param startDir This can either be
117 * @li The URL of the directory to start in.
118 * @li QString() to start in the current working
119 * directory, or the last directory where a file has been
120 * selected.
121 * @li ':&lt;keyword&gt;' to start in the directory last used
122 * by a filedialog in the same application that specified
123 * the same keyword.
124 * @li '::&lt;keyword&gt;' to start in the directory last used
125 * by a filedialog in any application that specified the
126 * same keyword.
127 * @param filter A shell glob or a MIME type filter that specifies which files to display.
128 * The preferred option is to set a list of MIME type names, see setMimeFilter() for details.
129 * Otherwise you can set the text to be displayed for the each glob, and
130 * provide multiple globs, see setFilter() for details.
131 * @param parent The widget the dialog will be centered on initially.
132 * @param title The name of the dialog widget.
133 */
134 static KIOFILEWIDGETS_EXPORT Result getOpenUrlAndEncoding(const QString &encoding = QString(),
135 const QUrl &startDir = QUrl(),
136 const QString &filter = QString(),
137 QWidget *parent = nullptr,
138 const QString &title = QString());
139
140 /**
141 * Creates a modal file dialog and returns the selected encoding
142 * URLs or an empty list if none was chosen.
143 *
144 * Note that with
145 * this method the user must select an existing filename.
146 *
147 * @param encoding The encoding shown in the encoding combo.
148 * @param startDir This can either be
149 * @li The URL of the directory to start in.
150 * @li QString() to start in the current working
151 * directory, or the last directory where a file has been
152 * selected.
153 * @li ':&lt;keyword&gt;' to start in the directory last used
154 * by a filedialog in the same application that specified
155 * the same keyword.
156 * @li '::&lt;keyword&gt;' to start in the directory last used
157 * by a filedialog in any application that specified the
158 * same keyword.
159 * @param filter A shell glob or a MIME type filter that specifies which files to display.
160 * The preferred option is to set a list of MIME type names, see setMimeFilter() for details.
161 * Otherwise you can set the text to be displayed for the each glob, and
162 * provide multiple globs, see setFilter() for details.
163 * @param parent The widget the dialog will be centered on initially.
164 * @param title The name of the dialog widget.
165 */
166 static KIOFILEWIDGETS_EXPORT Result getOpenUrlsAndEncoding(const QString &encoding = QString(),
167 const QUrl &startDir = QUrl(),
168 const QString &filter = QString(),
169 QWidget *parent = nullptr,
170 const QString &title = QString());
171
172 /**
173 * Creates a modal file dialog and returns the selected encoding and
174 * filename or an empty string if none was chosen.
175 *
176 * Note that with this
177 * method the user need not select an existing filename.
178 *
179 * @param encoding The encoding shown in the encoding combo.
180 * @param startDir This can either be
181 * @li The URL of the directory to start in.
182 * @li a relative path or a filename determining the
183 * directory to start in and the file to be selected.
184 * @li QString() to start in the current working
185 * directory, or the last directory where a file has been
186 * selected.
187 * @li ':&lt;keyword&gt;' to start in the directory last used
188 * by a filedialog in the same application that specified
189 * the same keyword.
190 * @li '::&lt;keyword&gt;' to start in the directory last used
191 * by a filedialog in any application that specified the
192 * same keyword.
193 * @param filter A shell glob or a MIME type filter that specifies which files to display.
194 * The preferred option is to set a list of MIME type names, see setMimeFilter() for details.
195 * Otherwise you can set the text to be displayed for the each glob, and
196 * provide multiple globs, see setFilter() for details.
197 * @param parent The widget the dialog will be centered on initially.
198 * @param title The name of the dialog widget.
199 */
200 static KIOFILEWIDGETS_EXPORT Result getSaveFileNameAndEncoding(const QString &encoding = QString(),
201 const QUrl &startDir = QUrl(),
202 const QString &filter = QString(),
203 QWidget *parent = nullptr,
204 const QString &title = QString());
205
206 /**
207 * Creates a modal file dialog and returns the selected encoding and
208 * filename or an empty string if none was chosen.
209 *
210 * Note that with this
211 * method the user need not select an existing filename.
212 *
213 * @param encoding The encoding shown in the encoding combo.
214 * @param startDir This can either be
215 * @li The URL of the directory to start in.
216 * @li a relative path or a filename determining the
217 * directory to start in and the file to be selected.
218 * @li QString() to start in the current working
219 * directory, or the last directory where a file has been
220 * selected.
221 * @li ':&lt;keyword&gt;' to start in the directory last used
222 * by a filedialog in the same application that specified
223 * the same keyword.
224 * @li '::&lt;keyword&gt;' to start in the directory last used
225 * by a filedialog in any application that specified the
226 * same keyword.
227 * @param filter A shell glob or a MIME type filter that specifies which files to display.
228 * The preferred option is to set a list of MIME type names, see setMimeFilter() for details.
229 * Otherwise you can set the text to be displayed for the each glob, and
230 * provide multiple globs, see setFilter() for details.
231 * @param parent The widget the dialog will be centered on initially.
232 * @param title The name of the dialog widget.
233 */
234 static KIOFILEWIDGETS_EXPORT Result getSaveUrlAndEncoding(const QString &encoding = QString(),
235 const QUrl &startDir = QUrl(),
236 const QString &filter = QString(),
237 QWidget *parent = nullptr,
238 const QString &title = QString());
239
240 QSize sizeHint() const override;
241
242protected:
243 void hideEvent(QHideEvent *e) override;
244
245private Q_SLOTS:
246 void accept() override;
247
248 void slotOk();
249 void slotCancel();
250
251private:
252 /**
253 * Constructs a file dialog for text files with encoding selection possibility.
254 *
255 * @param startDir This can either be
256 * @li The URL of the directory to start in.
257 * @li QString() to start in the current working
258 * directory, or the last directory where a file has been
259 * selected.
260 * @li ':&lt;keyword&gt;' to start in the directory last used
261 * by a filedialog in the same application that specified
262 * the same keyword.
263 * @li '::&lt;keyword&gt;' to start in the directory last used
264 * by a filedialog in any application that specified the
265 * same keyword.
266 *
267 * @param encoding The encoding shown in the encoding combo. If it's
268 * QString(), the global default encoding will be shown.
269 *
270 * @param filter A shell glob or a MIME type filter that specifies which files to display.
271 * The preferred option is to set a list of MIME type names, see setMimeFilter() for details.
272 * Otherwise you can set the text to be displayed for the each glob, and
273 * provide multiple globs, see setFilter() for details.
274 *
275 * @param title The title of the dialog
276 *
277 * @param type This can either be
278 * @li QFileDialog::AcceptOpen (open dialog, the default setting)
279 * @li QFileDialog::AcceptSave
280 * @param parent The parent widget of this dialog
281 */
282 KEncodingFileDialog(const QUrl &startDir = QUrl(),
283 const QString &encoding = QString(),
284 const QString &filter = QString(),
285 const QString &title = QString(),
287 QWidget *parent = nullptr);
288 /**
289 * Destructs the file dialog.
290 */
291 ~KEncodingFileDialog() override;
292
293 /**
294 * @returns The selected encoding if the constructor with the encoding parameter was used, otherwise QString().
295 */
296 QString selectedEncoding() const;
297
298 std::unique_ptr<KEncodingFileDialogPrivate> const d;
299};
300
301#endif
Provides a user (and developer) friendly way to select files with support for choosing encoding.
static KIOFILEWIDGETS_EXPORT Result getOpenFileNamesAndEncoding(const QString &encoding=QString(), const QUrl &startDir=QUrl(), const QString &filter=QString(), QWidget *parent=nullptr, const QString &title=QString())
Creates a modal file dialog and returns the selected encoding and the selected filenames or an empty ...
static KIOFILEWIDGETS_EXPORT Result getOpenUrlAndEncoding(const QString &encoding=QString(), const QUrl &startDir=QUrl(), const QString &filter=QString(), QWidget *parent=nullptr, const QString &title=QString())
Creates a modal file dialog and returns the selected encoding and URL or an empty string if none was ...
static KIOFILEWIDGETS_EXPORT Result getOpenFileNameAndEncoding(const QString &encoding=QString(), const QUrl &startDir=QUrl(), const QString &filter=QString(), QWidget *parent=nullptr, const QString &title=QString())
Creates a modal file dialog and return the selected filename or an empty string if none was chosen ad...
static KIOFILEWIDGETS_EXPORT Result getOpenUrlsAndEncoding(const QString &encoding=QString(), const QUrl &startDir=QUrl(), const QString &filter=QString(), QWidget *parent=nullptr, const QString &title=QString())
Creates a modal file dialog and returns the selected encoding URLs or an empty list if none was chose...
static KIOFILEWIDGETS_EXPORT Result getSaveUrlAndEncoding(const QString &encoding=QString(), const QUrl &startDir=QUrl(), const QString &filter=QString(), QWidget *parent=nullptr, const QString &title=QString())
Creates a modal file dialog and returns the selected encoding and filename or an empty string if none...
static KIOFILEWIDGETS_EXPORT Result getSaveFileNameAndEncoding(const QString &encoding=QString(), const QUrl &startDir=QUrl(), const QString &filter=QString(), QWidget *parent=nullptr, const QString &title=QString())
Creates a modal file dialog and returns the selected encoding and filename or an empty string if none...
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.