File: confoption.h

package info (click to toggle)
kde-config-systemd 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,560 kB
  • ctags: 688
  • sloc: cpp: 3,306; makefile: 9; sh: 2
file content (94 lines) | stat: -rw-r--r-- 3,559 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*******************************************************************************
 * Copyright (C) 2013-2015 Ragnar Thomsen <rthomsen6@gmail.com>                *
 *                                                                             *
 * This program is free software: you can redistribute it and/or modify it     *
 * under the terms of the GNU General Public License as published by the Free  *
 * Software Foundation, either version 2 of the License, or (at your option)   *
 * any later version.                                                          *
 *                                                                             *
 * This program is distributed in the hope that it will be useful, but WITHOUT *
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
 * more details.                                                               *
 *                                                                             *
 * You should have received a copy of the GNU General Public License along     *
 * with this program. If not, see <http://www.gnu.org/licenses/>.              *
 *******************************************************************************/

#ifndef CONFOPTION_H
#define CONFOPTION_H

#include <QStringList>
#include <QVariant>
#include "kcm-systemd-features.h"

#if defined(HAVE_CXX11_CHRONO)
#include <ratio>
#include <chrono>

namespace ratio = std;
namespace chrono = std::chrono;
#else
#include <boost/ratio.hpp>
#include <boost/chrono.hpp>

namespace ratio = boost;
namespace chrono = boost::chrono;
#endif

enum settingType
{
  BOOL, TIME, INTEGER, STRING, LIST, MULTILIST, RESLIMIT, SIZE
};

enum confFile
{
  SYSTEMD, JOURNALD, LOGIND, COREDUMP
};

class confOption {
  
  public:
    typedef chrono::duration<double, ratio::nano > nanoseconds;
    typedef chrono::duration<double, ratio::micro > microseconds;
    typedef chrono::duration<double, ratio::milli > milliseconds;
    typedef chrono::duration<double> seconds;
    typedef chrono::duration<double, ratio::ratio<60, 1> > minutes;
    typedef chrono::duration<double, ratio::ratio<3600, 1> > hours;
    typedef chrono::duration<double, ratio::ratio<86400, 1> > days;
    typedef chrono::duration<double, ratio::ratio<604800, 1> > weeks;
    typedef chrono::duration<double, ratio::ratio<2629800, 1> > months; // define a month as 30.4375days
    typedef chrono::duration<double, ratio::ratio<29030400, 1> > years;
    typedef enum timeUnit { ns, us, ms, s, min, h, d, w, month, year } timeUnit;
    
    confFile file;
    settingType type;
    QString uniqueName, realName, toolTip;
    qlonglong minVal = 0, maxVal = 999999999;
    QStringList possibleVals = QStringList();
    static QStringList capabilities;
    
    confOption();
    // Used for comparing
    explicit confOption(QString newName);
    explicit confOption(QVariantMap);
    
    bool operator==(const confOption& other) const;
    int setValue(QVariant);
    int setValueFromFile(QString);
    bool isDefault() const;
    void setToDefault();
    QVariant getValue() const;
    QString getValueAsString() const;
    QString getLineForFile() const;
    QString getFilename() const;
    QString getTimeUnit() const;

  private:
    bool hasNsec = false;
    QVariant value, defVal;
    timeUnit defUnit = timeUnit::s, defReadUnit = timeUnit::s, minUnit = timeUnit::ns, maxUnit = timeUnit::year;
    QVariant convertTimeUnit(double, timeUnit, timeUnit);
};

#endif