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
23 #include "pwmdExpireDialog.h"
25 PwmdExpireDialog::PwmdExpireDialog (time_t e
, time_t incr
, QWidget
*p
)
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);
43 if (n
>= (60*60*24*7))
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 ()
81 PwmdExpireDialog::expire ()
83 if (!ui
.ck_expiry
->isChecked ())
86 time_t now
= time (nullptr);
87 time_t n
= ui
.dt_expire
->dateTime ().toSecsSinceEpoch ();
89 return n
<= now
? n
+ increment () : n
;
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;