]>
cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kfileitemlisttostring.cpp
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@zohomail.eu>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 #include "kfileitemlisttostring.h"
11 #include <KFileItemListProperties>
12 #include <KLocalizedString>
14 #include <QFontMetrics>
17 QString
fileItemListToString(KFileItemList items
, int maximumTextWidth
, const QFontMetrics
&fontMetrics
, ItemsState itemsState
)
20 switch (items
.count()) {
22 text
= i18nc("Textual representation of a file. %1 is the name of the file/folder.", "\"%1\"", items
.first().name());
26 i18nc("Textual representation of two files. %1 and %2 are names of files/folders.", "\"%1\" and \"%2\"", items
.first().name(), items
.last().name());
29 text
= i18nc("Textual representation of three files. %1, %2 and %3 are names of files/folders.",
30 "\"%1\", \"%2\" and \"%3\"",
36 text
= i18nc("Textual representation of four files. %1, %2, %3 and %4 are names of files/folders.",
37 "\"%1\", \"%2\", \"%3\" and \"%4\"",
44 text
= i18nc("Textual representation of five files. %1, %2, %3, %4 and %5 are names of files/folders.",
45 "\"%1\", \"%2\", \"%3\", \"%4\" and \"%5\"",
57 // At some point the added clarity from the text starts being less important than the text width.
58 if (!text
.isEmpty() && fontMetrics
.horizontalAdvance(text
) <= maximumTextWidth
) {
62 const KFileItemListProperties
properties(items
);
63 if (itemsState
== Selected
) {
64 if (properties
.isFile()) {
65 text
= i18ncp("Textual representation of selected files. %1 is the number of files.", "One Selected File", "%1 Selected Files", items
.count());
66 } else if (properties
.isDirectory()) {
68 i18ncp("Textual representation of selected folders. %1 is the number of folders.", "One Selected Folder", "%1 Selected Folders", items
.count());
70 text
= i18ncp("Textual representation of selected fileitems. %1 is the number of files/folders.",
76 if (fontMetrics
.horizontalAdvance(text
) <= maximumTextWidth
) {
81 if (properties
.isFile()) {
82 return i18ncp("Textual representation of files. %1 is the number of files.", "One File", "%1 Files", items
.count());
83 } else if (properties
.isDirectory()) {
84 return i18ncp("Textual representation of folders. %1 is the number of folders.", "One Folder", "%1 Folders", items
.count());
86 return i18ncp("Textual representation of fileitems. %1 is the number of files/folders.", "One Item", "%1 Items", items
.count());