Warning, file /system/kjournald/lib/bootmodel_p.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-License-Identifier: LGPL-2.1-or-later OR MIT
0003     SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@kde.org>
0004 */
0005 
0006 #ifndef BOOT_MODEL_PRIVATE_H
0007 #define BOOT_MODEL_PRIVATE_H
0008 
0009 #include "journaldhelper.h"
0010 
0011 class BootModelPrivate
0012 {
0013 public:
0014     enum class TIME_FORMAT {
0015         UTC,
0016         LOCALTIME,
0017     };
0018 
0019     using BootInfo = JournaldHelper::BootInfo;
0020 
0021     explicit BootModelPrivate(std::unique_ptr<IJournal> journal);
0022 
0023     static QString prettyPrintBoot(const BootInfo &bootInfo, TIME_FORMAT format);
0024 
0025     void sort(Qt::SortOrder order);
0026 
0027     QVector<BootInfo> mBootInfo;
0028     QString mJournaldPath;
0029     std::unique_ptr<IJournal> mJournal;
0030 };
0031 
0032 QString BootModelPrivate::prettyPrintBoot(const BootInfo &bootInfo, TIME_FORMAT format)
0033 {
0034     const QString id = bootInfo.mBootId.left(10);
0035     QString sinceTime;
0036     QString sinceDate;
0037     QString untilTime;
0038     QString untilDate;
0039 
0040     if (format == TIME_FORMAT::UTC) {
0041         sinceTime = bootInfo.mSince.toUTC().toString(QLatin1String("hh:mm"));
0042         sinceDate = bootInfo.mSince.toUTC().toString(QLatin1String("yyyy-MM-dd"));
0043         untilTime = bootInfo.mUntil.toUTC().toString(QLatin1String("hh:mm"));
0044         untilDate = bootInfo.mUntil.toUTC().toString(QLatin1String("yyyy-MM-dd"));
0045     } else {
0046         sinceTime = bootInfo.mSince.toString(QLatin1String("hh:mm"));
0047         sinceDate = bootInfo.mSince.toString(QLatin1String("yyyy-MM-dd"));
0048         untilTime = bootInfo.mUntil.toString(QLatin1String("hh:mm"));
0049         untilDate = bootInfo.mUntil.toString(QLatin1String("yyyy-MM-dd"));
0050     }
0051     if (sinceDate == untilDate) {
0052         return QString(QLatin1String("%1 %2-%3 [%4...]")).arg(sinceDate, sinceTime, untilTime, id);
0053     } else {
0054         return QString(QLatin1String("%1 %2-%3 %4 [%5...]")).arg(sinceDate, sinceTime, untilDate, untilTime, id);
0055     }
0056 }
0057 
0058 void BootModelPrivate::sort(Qt::SortOrder order)
0059 {
0060     std::sort(std::begin(mBootInfo), std::end(mBootInfo), [order](const BootInfo &left, const BootInfo &right) {
0061         if (order == Qt::AscendingOrder) {
0062             return left.mSince <= right.mSince;
0063         } else {
0064             return left.mSince > right.mSince;
0065         }
0066     });
0067 }
0068 
0069 #endif // JOURNAL_H