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
50 /**
51 * Checks whether two filters are equal.
52 *
53 * Filters are considered equal if their file and name patters match.
54 * The label is ignored here.
55 */
56 bool operator==(const KFileFilter &other) const;
57
58 /**
59 * The user-facing label for this filter.
60 *
61 * If no label is passed on creation one is created based on the patterns.
62 */
63 QString label() const;
64
65 /**
66 * List of file name patterns that are included by this filter.
67 */
68 QStringList filePatterns() const;
69
70 /**
71 * List of MIME types that are included by this filter;
72 */
73 QStringList mimePatterns() const;
74
75 /**
76 * Converts this filter to a string representation
77 */
78 QString toFilterString() const;
79
80 /**
81 * Whether the filer is empty, i.e.\ matches all files.
82 */
83 bool isEmpty() const;
84
85 /**
86 * Whether the filter is valid.
87 *
88 * Creating a filter from an invalid/unkown MIME type will result in an invalid filter.
89 *
90 * @since 6.0
91 */
92 bool isValid() const;
93
94 /*
95 * Creates a filter for one MIME type.
96 * The user-facing label is automatically determined from the MIME type.
97 */
98 static KFileFilter fromMimeType(const QString &mimeType);
99
100 /**
101 * Creates filters from a list of MIME types.
102 * The user-facing label is automatically determined from the MIME type.
103 *
104 * @since 6.0
105 */
106 static QList<KFileFilter> fromMimeTypes(const QStringList &mimeTypes);
107
108private:
109 /**
110 * Convert a filter string understood by KFileWidget to a list of KFileFilters.
111 */
112 static QList<KFileFilter> fromFilterString(const QString &filterString);
113 friend class KFileFilterCombo;
114 friend class KFileFilterTest;
115 friend class KFileFilterComboPrivate;
116 friend class KFileWidgetTest;
117 friend class KFileFilterComboTest;
118 friend class KDEPlatformFileDialog;
119 friend class KDEPlatformFileDialogHelper;
120 friend class KEncodingFileDialog;
121
123};
124
125KIOCORE_EXPORT QDebug operator<<(QDebug dbg, const KFileFilter &filter);
126
127#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 Mon Nov 18 2024 12:16:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.