]>
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
, QFontMetrics fontMetrics
, ItemsState itemsState
)
20 switch (items
.count()) {
22 text
= i18nc("Textual representation of a file. %1 is the name of the file/folder.",
23 "\"%1\"", items
.first().name());
26 text
= i18nc("Textual representation of two files. %1 and %2 are names of files/folders.",
27 "\"%1\" and \"%2\"", items
.first().name(), items
.last().name());
30 text
= i18nc("Textual representation of three files. %1, %2 and %3 are names of files/folders.",
31 "\"%1\", \"%2\" and \"%3\"",
32 items
.first().name(), items
.at(1).name(), items
.last().name());
35 text
= i18nc("Textual representation of four files. %1, %2, %3 and %4 are names of files/folders.",
36 "\"%1\", \"%2\", \"%3\" and \"%4\"",
37 items
.first().name(), items
.at(1).name(), items
.at(2).name(), items
.last().name());
40 text
= i18nc("Textual representation of five files. %1, %2, %3, %4 and %5 are names of files/folders.",
41 "\"%1\", \"%2\", \"%3\", \"%4\" and \"%5\"",
42 items
.first().name(), items
.at(1).name(), items
.at(2).name(), items
.at(3).name(), items
.last().name());
49 // At some point the added clarity from the text starts being less important than the text width.
50 if (!text
.isEmpty() && fontMetrics
.horizontalAdvance(text
) <= maximumTextWidth
) {
54 const KFileItemListProperties
properties(items
);
55 if (itemsState
== Selected
) {
56 if (properties
.isFile()) {
57 text
= i18ncp("Textual representation of selected files. %1 is the number of files.",
58 "One Selected File", "%1 Selected Files", items
.count());
59 } else if (properties
.isDirectory()) {
60 text
= i18ncp("Textual representation of selected folders. %1 is the number of folders.",
61 "One Selected Folder", "%1 Selected Folders", items
.count());
63 text
= i18ncp("Textual representation of selected fileitems. %1 is the number of files/folders.",
64 "One Selected Item", "%1 Selected Items", items
.count());
67 if (fontMetrics
.horizontalAdvance(text
) <= maximumTextWidth
) {
72 if (properties
.isFile()) {
73 return i18ncp("Textual representation of files. %1 is the number of files.",
74 "One File", "%1 Files", items
.count());
75 } else if (properties
.isDirectory()) {
76 return i18ncp("Textual representation of folders. %1 is the number of folders.",
77 "One Folder", "%1 Folders", items
.count());
79 return i18ncp("Textual representation of fileitems. %1 is the number of files/folders.",
80 "One Item", "%1 Items", items
.count());