KIO

kfilefilter.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KFILEFILTER_H
9#define KFILEFILTER_H
10
11#include "kiocore_export.h"
12
13#include <QSharedDataPointer>
14#include <QString>
15#include <QStringList>
16
17class KFileFilterPrivate;
18
19/**
20 * @class KFileFilter kfilefilter.h <KFileFilter>
21 *
22 * Encapsulates rules to filter a list of files.
23 * Files can be filtered based on name patterns (e.g. *.cpp), MIME types, or both.
24 * Filters also optionally have a user-facing label.
25 *
26 * @since 5.101
27 */
28class KIOCORE_EXPORT KFileFilter
29{
30public:
31 /**
32 * Creates an empty filter.
33 */
34 explicit KFileFilter();
35
36 /**
37 * Creates a filter with a given label, name patterns, and MIME types.
38 *
39 * @param label The user-facing label for this filter.
40 * @param filePatterns A list of file name patterns that should be included, e.g. ("*.cpp", "*.cxx").
41 * @param mimePatterns A list of MIME types that should be included, e.g. ("text/plain", "image/png").
42 *
43 */
44 explicit KFileFilter(const QString &label, const QStringList &filePatterns, const QStringList &mimePatterns);
45
46 KFileFilter(const KFileFilter &other);
47 KFileFilter &operator=(const KFileFilter &other);
49 bool operator==(const KFileFilter &other) const;
50
51 /**
52 * The user-facing label for this filter.
53 *
54 * If no label is passed on creation one is created based on the patterns.
55 */
56 QString label() const;
57
58 /**
59 * List of file name patterns that are included by this filter.
60 */
61 QStringList filePatterns() const;
62
63 /**
64 * List of MIME types that are included by this filter;
65 */
66 QStringList mimePatterns() const;
67
68 /**
69 * Converts this filter to a string representation
70 */
71 QString toFilterString() const;
72
73 /**
74 * Whether the filer is empty, i.e.\ matches all files.
75 */
76 bool isEmpty() const;
77
78 /**
79 * Whether the filter is valid.
80 *
81 * Creating a filter from an invalid/unkown MIME type will result in an invalid filter.
82 *
83 * @since 6.0
84 */
85 bool isValid() const;
86
87 /*
88 * Creates a filter for one MIME type.
89 * The user-facing label is automatically determined from the MIME type.
90 */
91 static KFileFilter fromMimeType(const QString &mimeType);
92
93 /**
94 * Creates filters from a list of MIME types.
95 * The user-facing label is automatically determined from the MIME type.
96 *
97 * @since 6.0
98 */
99 static QList<KFileFilter> fromMimeTypes(const QStringList &mimeTypes);
100
101private:
102 /**
103 * Convert a filter string understood by KFileWidget to a list of KFileFilters.
104 */
105 static QList<KFileFilter> fromFilterString(const QString &filterString);
106 friend class KFileFilterCombo;
107 friend class KFileFilterTest;
108 friend class KFileFilterComboPrivate;
109 friend class KFileWidgetTest;
110 friend class KFileFilterComboTest;
111 friend class KDEPlatformFileDialog;
112 friend class KDEPlatformFileDialogHelper;
113 friend class KEncodingFileDialog;
114
116};
117
118KIOCORE_EXPORT QDebug operator<<(QDebug dbg, const KFileFilter &filter);
119
120#endif
Provides a user (and developer) friendly way to select files with support for choosing encoding.
File filter combo box.
Encapsulates rules to filter a list of files.
Definition kfilefilter.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:54:08 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.