KJobWidgets

kjobtrackerformatters.cpp
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 1997, 2001 Stephan Kulow <coolo@kde.org>
4 SPDX-FileCopyrightText: 1999 Preston Brown <pbrown@kde.org>
5 SPDX-FileCopyrightText: 1999-2002 Hans Petter Bieker <bieker@kde.org>
6 SPDX-FileCopyrightText: 2002 Lukas Tinkl <lukas@kde.org>
7 SPDX-FileCopyrightText: 2007 Bernhard Loos <nhuh.put@web.de>
8 SPDX-FileCopyrightText: 2009, 2010 John Layt <john@layt.net>
9
10 SPDX-License-Identifier: LGPL-2.0-only
11*/
12
13#include "kjobtrackerformatters_p.h"
14#include <KFormat>
15
16#include <QCoreApplication>
17
18QString KJobTrackerFormatters::byteSize(double size)
19{
20 return KFormat().formatByteSize(size);
21}
22
23QString KJobTrackerFormatters::daysDuration(int n)
24{
25 //~ singular %n day
26 //~ plural %n days
27 return QCoreApplication::translate("KJobTrackerFormatters", "%n day(s)", "@item:intext", n);
28}
29
30QString KJobTrackerFormatters::hoursDuration(int n)
31{
32 //~ singular %n hour
33 //~ plural %n hours
34 return QCoreApplication::translate("KJobTrackerFormatters", "%n hour(s)", "@item:intext", n);
35}
36
37QString KJobTrackerFormatters::minutesDuration(int n)
38{
39 //~ singular %n minute
40 //~ plural %n minutes
41 return QCoreApplication::translate("KJobTrackerFormatters", "%n minute(s)", "@item:intext", n);
42}
43
44QString KJobTrackerFormatters::secondsDuration(int n)
45{
46 //~ singular %n second
47 //~ plural %n seconds
48 return QCoreApplication::translate("KJobTrackerFormatters", "%n second(s)", "@item:intext", n);
49}
50
51QString KJobTrackerFormatters::duration(unsigned long mSec)
52{
53 unsigned long ms = mSec;
54 int days = ms / (24 * 3600000);
55 ms = ms % (24 * 3600000);
56 int hours = ms / 3600000;
57 ms = ms % 3600000;
58 int minutes = ms / 60000;
59 ms = ms % 60000;
60 int seconds = qRound(ms / 1000.0);
61
62 // Handle correctly problematic case #1 (look at KLocaleTest::prettyFormatDuration()
63 // at klocaletest.cpp)
64 if (seconds == 60) {
65 return duration(mSec - ms + 60000);
66 }
67
68 if (days && hours) {
69 return QCoreApplication::translate("KJobTrackerFormatters", "%1 and %2", "@item:intext days and hours.").arg(daysDuration(days), hoursDuration(hours));
70 } else if (days) {
71 return daysDuration(days);
72 } else if (hours && minutes) {
73 return QCoreApplication::translate("KJobTrackerFormatters", "%1 and %2", "@item:intext hours and minutes.")
74 .arg(hoursDuration(hours), minutesDuration(minutes));
75 } else if (hours) {
76 return hoursDuration(hours);
77 } else if (minutes && seconds) {
78 return QCoreApplication::translate("KJobTrackerFormatters", "%1 and %2", "@item:intext minutes and seconds.")
79 .arg(minutesDuration(minutes), secondsDuration(seconds));
80 } else if (minutes) {
81 return minutesDuration(minutes);
82 } else {
83 return secondsDuration(seconds);
84 }
85}
QString formatByteSize(double size, int precision=1, KFormat::BinaryUnitDialect dialect=KFormat::DefaultBinaryDialect, KFormat::BinarySizeUnits units=KFormat::DefaultBinaryUnits) const
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.