1 /*
2     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
3     SPDX-FileCopyrightText: 2015 Vyacheslav Matyushin
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "journaldConfiguration.h"
9 
JournaldConfiguration()10 JournaldConfiguration::JournaldConfiguration()
11 {
12     mDisplayCurrentBootOnly = true;
13     mEntriesType = EntriesAll;
14 
15     mConfiguration->setCurrentGroup(QLatin1String("JournaldLogMode"));
16     mConfiguration->addItemBool(QLatin1String("CurrentBootOnly"), mDisplayCurrentBootOnly, true);
17     mConfiguration->addItemInt(QLatin1String("EntriesType"), mEntriesType);
18     mConfiguration->addItemStringList(QLatin1String("RemoteJournals"), mRemoteJournals);
19 }
20 
displayCurrentBootOnly() const21 bool JournaldConfiguration::displayCurrentBootOnly() const
22 {
23     return mDisplayCurrentBootOnly;
24 }
25 
setDisplayCurrentBootOnly(bool displayCurrentBootOnly)26 void JournaldConfiguration::setDisplayCurrentBootOnly(bool displayCurrentBootOnly)
27 {
28     mDisplayCurrentBootOnly = displayCurrentBootOnly;
29 }
30 
entriesType()31 JournaldConfiguration::EntriesType JournaldConfiguration::entriesType()
32 {
33     if ((mEntriesType < EntriesAll) || (mEntriesType > EntriesSystem)) {
34         mEntriesType = EntriesAll;
35     }
36     return static_cast<EntriesType>(mEntriesType);
37 }
38 
setEntriesType(JournaldConfiguration::EntriesType entriesType)39 void JournaldConfiguration::setEntriesType(JournaldConfiguration::EntriesType entriesType)
40 {
41     mEntriesType = entriesType;
42 }
43 
remoteJournals() const44 QVector<JournalAddress> JournaldConfiguration::remoteJournals() const
45 {
46     QVector<JournalAddress> journals;
47     for (const QString &addressItem : std::as_const(mRemoteJournals)) {
48         JournalAddress addressInfo;
49         addressInfo.address = addressItem.section(QChar::fromLatin1('|'), 0, 0);
50         addressInfo.port = addressItem.section(QChar::fromLatin1('|'), 1, 1).toUInt();
51         const int https = addressItem.section(QChar::fromLatin1('|'), 2).toInt();
52         addressInfo.https = https != 0;
53         journals.append(addressInfo);
54     }
55     return journals;
56 }
57 
setRemoteJournals(const QVector<JournalAddress> & remoteJournals)58 void JournaldConfiguration::setRemoteJournals(const QVector<JournalAddress> &remoteJournals)
59 {
60     mRemoteJournals.clear();
61     for (const JournalAddress &addressInfo : remoteJournals) {
62         mRemoteJournals.append(QStringLiteral("%1|%2|%3").arg(addressInfo.address).arg(addressInfo.port).arg(addressInfo.https ? 1 : 0));
63     }
64 }
65