Libksieve

sievedatespinbox.cpp
1 /*
2  Copyright (C) 2017-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "sievedatespinbox.h"
21 #include "libksieve_debug.h"
22 using namespace KSieveUi;
23 
24 SieveDateSpinBox::SieveDateSpinBox(QWidget *parent)
25  : QSpinBox(parent)
26 {
27  setSpecialValueText(QStringLiteral("*"));
28 }
29 
30 SieveDateSpinBox::~SieveDateSpinBox()
31 {
32 }
33 
34 void SieveDateSpinBox::setRange(int minValue, int maxValue)
35 {
36  //We need to define specialValueText => we set minimum to minimum - 1
37  setMaximum(maxValue);
38  setMinimum(minValue - 1);
39 }
40 
41 void SieveDateSpinBox::setType(KSieveUi::SelectDateWidget::DateType type)
42 {
43  mType = type;
44  switch (type) {
45  case SelectDateWidget::Year:
46  setRange(0, 9999);
47  break;
48  case SelectDateWidget::Month:
49  setRange(1, 12);
50  break;
51  case SelectDateWidget::Day:
52  setRange(1, 31);
53  break;
54  case SelectDateWidget::Hour:
55  setRange(0, 23);
56  break;
57  case SelectDateWidget::Minute:
58  setRange(0, 59);
59  break;
60  case SelectDateWidget::Second:
61  setRange(0, 59);
62  break;
63  case SelectDateWidget::Weekday:
64  setRange(0, 6);
65  break;
66  default:
67  qCWarning(LIBKSIEVE_LOG) << "This type mustn't be selected " << mType;
68  }
69 }
70 
71 void SieveDateSpinBox::setCode(const QString &str)
72 {
73  if (str == QLatin1String("*")) {
74  //setSpecialValue
75  setValue(minimum());
76  } else {
77  setValue(str.toInt());
78  }
79 }
80 
81 QString SieveDateSpinBox::code() const
82 {
83  if (value() == minimum()) {
84  return QStringLiteral("*");
85  }
86  return convertValue();
87 }
88 
89 QString SieveDateSpinBox::convertValue() const
90 {
91  QString str;
92  switch (mType) {
93  case SelectDateWidget::Year:
94  str = QStringLiteral("%1").arg(value(), 4, 10, QLatin1Char('0'));
95  break;
96  case SelectDateWidget::Month:
97  str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
98  break;
99  case SelectDateWidget::Day:
100  str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
101  break;
102  case SelectDateWidget::Hour:
103  str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
104  break;
105  case SelectDateWidget::Minute:
106  str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
107  break;
108  case SelectDateWidget::Second:
109  str = QStringLiteral("%1").arg(value(), 2, 10, QLatin1Char('0'));
110  break;
111  case SelectDateWidget::Weekday:
112  str = value();
113  break;
114  default:
115  qCWarning(LIBKSIEVE_LOG) << "This type mustn't be selected " << mType;
116  break;
117  }
118  return str;
119 }
int toInt(bool *ok, int base) const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:09:20 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.