Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* KColorScheme migration has been completed.
* KIconThemes migration has been completed.
* The MeshMC News section is now displayed via KF6 Syndication.
* KFormat migration has been completed.

## Removed

Expand Down
4 changes: 0 additions & 4 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,6 @@ target_sources(MeshMC_logic PRIVATE
# A Recursive file system watcher
RecursiveFileSystemWatcher.h
RecursiveFileSystemWatcher.cpp

# Time
MMCTime.h
MMCTime.cpp
)

add_subdirectory(pathmatcher)
Expand Down
42 changes: 0 additions & 42 deletions launcher/MMCTime.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions launcher/MMCTime.h

This file was deleted.

16 changes: 13 additions & 3 deletions launcher/minecraft/MinecraftInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "pathmatcher/MultiMatcher.h"
#include "FileSystem.h"
#include "java/JavaVersion.h"
#include "MMCTime.h"
#include <KFormat>

#include "launch/LaunchTask.h"
#include "launch/steps/LookupServerAddress.h"
Expand Down Expand Up @@ -100,6 +100,16 @@ class OrSetting : public Setting
std::shared_ptr<Setting> m_b;
};

namespace
{
// A time played, given in seconds, as "1 hr 2 min".
QString playTime(qint64 seconds)
{
return KFormat().formatDuration(static_cast<quint64>(seconds) * 1000,
KFormat::AbbreviatedDuration);
}
} // namespace

MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings,
SettingsObjectPtr settings,
const QString& rootDir)
Expand Down Expand Up @@ -955,12 +965,12 @@ QString MinecraftInstance::getStatusbarDescription()
if (m_settings->get("ShowGameTime").toBool()) {
if (lastTimePlayed() > 0) {
description.append(
i18n(", last played for %1", Time::prettifyDuration(lastTimePlayed())));
i18n(", last played for %1", playTime(lastTimePlayed())));
}

if (totalTimePlayed() > 0) {
description.append(
i18n(", total played for %1", Time::prettifyDuration(totalTimePlayed())));
i18n(", total played for %1", playTime(totalTimePlayed())));
}
}
if (hasCrashed()) {
Expand Down
12 changes: 8 additions & 4 deletions launcher/net/NetJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "Download.h"

#include <QDebug>
#include <QLocale>
#include <KFormat>
#include <KLocalizedString>

TaskStepProgressList NetJob::getStepProgress() const
Expand Down Expand Up @@ -57,12 +57,16 @@ void NetJob::emitPartStep(int index, TaskStepState state)
}
}

QLocale locale;
const KFormat format;
const auto size = [&format](qint64 bytes) {
return format.formatByteSize(bytes, 1, KFormat::IECBinaryDialect);
};
QString details;
if (slot.total_progress > 0) {
details = i18n("%1 of %2", locale.formattedDataSize(slot.current_progress), locale.formattedDataSize(slot.total_progress));
details = i18n("%1 of %2", size(slot.current_progress),
size(slot.total_progress));
} else if (slot.current_progress > 0) {
details = locale.formattedDataSize(slot.current_progress);
details = size(slot.current_progress);
}

slot.step->state = state;
Expand Down
6 changes: 4 additions & 2 deletions launcher/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <KAboutApplicationDialog>
#include <KAboutData>
#include <KBugReport>
#include <KFormat>
#include <KHelpMenu>

#include <BaseInstance.h>
Expand Down Expand Up @@ -117,7 +118,6 @@
#include "InstanceImportTask.h"
#include "InstanceCopyTask.h"

#include "MMCTime.h"
#include <KLocalizedString>

namespace
Expand Down Expand Up @@ -2161,6 +2161,8 @@ void MainWindow::updateStatusCenter()
int timePlayed = APPLICATION->instances()->getTotalPlayTime();
if (timePlayed > 0) {
m_statusCenter->setText(
i18n("Total playtime: %1", Time::prettifyDuration(timePlayed)));
i18n("Total playtime: %1",
KFormat().formatDuration(static_cast<quint64>(timePlayed) * 1000,
KFormat::AbbreviatedDuration)));
}
}
18 changes: 3 additions & 15 deletions launcher/ui/pages/instance/BackupPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "backup/BackupTask.h"
#include "ui/dialogs/ProgressDialog.h"
#include <KFormat>
#include <KLocalizedString>

BackupPage::BackupPage(BaseInstance* inst, QWidget* parent)
Expand Down Expand Up @@ -73,7 +74,8 @@ void BackupPage::refreshList()
item->setText(0, entry.name.isEmpty() ? entry.fileName : entry.name);
item->setText(1, entry.timestamp.toString(
QStringLiteral("yyyy-MM-dd HH:mm:ss")));
item->setText(2, humanFileSize(entry.sizeBytes));
item->setText(2, KFormat().formatByteSize(
entry.sizeBytes, 1, KFormat::IECBinaryDialect));
item->setData(0, Qt::UserRole, entry.fullPath);
}

Expand Down Expand Up @@ -246,17 +248,3 @@ void BackupPage::on_btnDelete_clicked()
m_manager->deleteBackup(entry);
refreshList();
}

/* static */
QString BackupPage::humanFileSize(qint64 bytes)
{
if (bytes < 1024)
return QStringLiteral("%1 B").arg(bytes);
if (bytes < 1024 * 1024)
return QStringLiteral("%1 KiB").arg(bytes / 1024.0, 0, 'f', 1);
if (bytes < 1024LL * 1024 * 1024)
return QStringLiteral("%1 MiB").arg(bytes / (1024.0 * 1024.0), 0, 'f',
1);
return QStringLiteral("%1 GiB").arg(bytes / (1024.0 * 1024.0 * 1024.0), 0,
'f', 2);
}
1 change: 0 additions & 1 deletion launcher/ui/pages/instance/BackupPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class BackupPage : public QWidget, public BasePage
void refreshList();
void updateButtons();
BackupEntry selectedEntry() const;
static QString humanFileSize(qint64 bytes);

Ui::BackupPage* ui;
BaseInstance* m_inst;
Expand Down
Loading