Add Kyber to algorithm strings.
[qpwmc.git] / pwmdExpireDialog.cpp
blobce0628545d1280e201507b7c678ccc332b89ab63
1 /*
2 Copyright (C) 2017-2024 Ben Kibbey <bjk@luxsci.net>
4 This file is part of qpwmc.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 USA
21 #include <QDateTime>
22 #include <time.h>
23 #include "pwmdExpireDialog.h"
25 PwmdExpireDialog::PwmdExpireDialog (time_t e, time_t incr, QWidget *p)
26 : QDialog (p)
28 ui.setupUi (this);
29 QDateTime dt;
30 dt.setSecsSinceEpoch (e ? e : time (nullptr));
31 ui.dt_expire->setDateTime (dt);
32 ui.ck_expiry->setChecked (e != 0);
34 time_t s = 0, m = 0, h = 0, d = 0, w = 0, mo = 0, n = 0;
35 if (incr >= (60*60*24*31))
37 mo = incr/(60*60*24*31);
38 n = incr%(60*60*24*31);
40 else
41 n = incr;
43 if (n >= (60*60*24*7))
45 w = n/(60*60*24*7);
46 n = n%(60*60*24*7);
49 if (n >= (60*60*24))
51 d = n/(60*60*24);
52 n = n%(60*60*24);
55 if (n >= (60*60))
57 h = n/(60*60);
58 n = n%(60*60);
61 if (n >= 60)
63 m = n/60;
64 n = n%60;
67 s = n;
68 ui.sp_second->setValue (s);
69 ui.sp_minute->setValue (m);
70 ui.sp_hour->setValue (h);
71 ui.sp_day->setValue (d);
72 ui.sp_week->setValue (w);
73 ui.sp_month->setValue (mo);
76 PwmdExpireDialog::~PwmdExpireDialog ()
80 time_t
81 PwmdExpireDialog::expire ()
83 if (!ui.ck_expiry->isChecked ())
84 return 0;
86 time_t now = time (nullptr);
87 time_t n = ui.dt_expire->dateTime ().toSecsSinceEpoch ();
89 return n <= now ? n + increment () : n;
92 time_t
93 PwmdExpireDialog::increment ()
95 int s, m, h, d, w, mo;
97 s = ui.sp_second->value();
98 m = ui.sp_minute->value();
99 h = ui.sp_hour->value();
100 d = ui.sp_day->value();
101 w = ui.sp_week->value();
102 mo = ui.sp_month->value();
104 mo *= mo ? 60*60*24*31: 1;
105 w *= w ? 60*60*24*7 : 1;
106 d *= d ? 60*60*24 : 1;
107 h *= h ? 60*60 : 1;
108 m *= m ? 60 : 1;
109 return mo+w+d+h+m+s;