]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlisttostring.h
SVN_SILENT made messages (.desktop file) - always resolve ours
[dolphin.git] / src / kitemviews / kfileitemlisttostring.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8 #ifndef KFILEITEMLISTTOSTRING_H
9 #define KFILEITEMLISTTOSTRING_H
10
11 class KFileItemList;
12 class QFontMetrics;
13 class QString;
14
15 enum ItemsState { None, Selected };
16
17 /**
18 * @brief Generates a textual representation of the given list of KFileItems.
19 *
20 * This method is especially useful to be very explicit about which items will be affected by an action.
21 * For example can a label for a delete button be enriched to say "Permanantly Delete `picture1` and `picture2`"
22 * but also "Permanently Delete 7 Selected Folders" without requiring a huge amount of new translations for this.
23 *
24 * Unfortunately this doesn't always work.
25 *
26 * For some texts and some languages this wide range of words cannot be inserted into a text while staying
27 * grammatically correct. Because of this you will probably need to write a fallback for these languages.
28 * Something like this:
29 * \code
30 * // i18n: @action:inmenu menu with actions like copy, paste, rename.
31 * // %2 is a textual representation of the currently selected files or folders. This can be the name of
32 * // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
33 * // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
34 * // and a fallback will be used.
35 * auto buttonText = i18ncp("@action A more elaborate and clearly worded version of the Delete action", "Permanently Delete %2", "Permanently Delete %2", items.count(), fileItemListToString(items, fontMetrics.averageCharWidth() * 20, fontMetrics));
36 * if (buttonText == QStringLiteral("NULL")) {
37 * buttonText = i18ncp("@action Delete button label. %1 is the number of items to be deleted.",
38 * "Permanently Delete %1 Item", "Permanently Delete %1 Items", items.count())
39 * }
40 * \endcode
41 * (The i18n call should be completely in the line following the i18n: comment without any line breaks within the i18n call or the comment might not be correctly extracted. See: https://commits.kde.org/kxmlgui/a31135046e1b3335b5d7bbbe6aa9a883ce3284c1 )
42 *
43 * @param items The KFileItemList for which a QString should be generated.
44 * @param maximumTextWidth The maximum width/horizontalAdvance the QString should have. Keep scaling in mind.
45 * @param fontMetrics the fontMetrics for the font that is used to calculate the maximumTextWidth.
46 * @param itemsState A state of the @p items that should be spelled out in the returned QString.
47 * @returns the names of the @p items separated by commas if that is below the @p maximumCharacterWidth.
48 * Otherwise returns something like "5 Files", "8 Selected Folders" or "60 Items"
49 * while being as specific as possible.
50 */
51 QString fileItemListToString(KFileItemList items, int maximumTextWidth, const QFontMetrics &fontMetrics, ItemsState itemsState = ItemsState::None);
52
53 #endif // KFILEITEMLISTTOSTRING_H