diff options
author | George Hazan <ghazan@miranda.im> | 2021-03-17 20:36:59 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-03-17 20:37:04 +0300 |
commit | 2d712275e2ecf08e106fa93783767a6587a31e5a (patch) | |
tree | a85e8c5f487556a53b2b81245d6575478eb89f8d /plugins/NotesAndReminders/src | |
parent | 619f76e0581eb19293d09f43dd10a7f251e5585d (diff) |
Notes & Reminders:
- minus perversion with storing dates in hidden controls (we have classes for that);
- fixes #2772 (Notes and Reminders: невозможно отмотать дату на сегодняшнюю);
Diffstat (limited to 'plugins/NotesAndReminders/src')
-rw-r--r-- | plugins/NotesAndReminders/src/reminders.cpp | 130 | ||||
-rw-r--r-- | plugins/NotesAndReminders/src/resource.h | 1 |
2 files changed, 54 insertions, 77 deletions
diff --git a/plugins/NotesAndReminders/src/reminders.cpp b/plugins/NotesAndReminders/src/reminders.cpp index f03f92ccdf..2ec9369fcd 100644 --- a/plugins/NotesAndReminders/src/reminders.cpp +++ b/plugins/NotesAndReminders/src/reminders.cpp @@ -10,6 +10,9 @@ #define DATATAG_SNDSEL 3 // %d (which sound to use, default, alt1, alt2, -1 means no sound at all)
#define DATATAG_REPEAT 4 // %d (repeateable reminder)
+#define MinutesToFileTime (60ll * FILETIME_TICKS_PER_SEC)
+#define DayToFileTime (86400ll * FILETIME_TICKS_PER_SEC)
+
/////////////////////////////////////////////////////////////////////////////////////////
static void RemoveReminderSystemEvent(struct REMINDERDATA *p);
@@ -599,7 +602,6 @@ static void PopulateTimeCombo(CCtrlCombo &pCombo, const SYSTEMTIME *tmUtc) ULONGLONG li;
wchar_t s[64];
- const ULONGLONG MinutesToFileTime = 60ll * FILETIME_TICKS_PER_SEC;
// generate absolute time table for date different than today
SYSTEMTIME tm2;
@@ -626,7 +628,7 @@ static void PopulateTimeCombo(CCtrlCombo &pCombo, const SYSTEMTIME *tmUtc) // combo box items are absolute times and not relative times like below
pCombo.AddString(s, ((h * 60 + m) * 60) | 0x80000000);
- li += (ULONGLONG)30 * MinutesToFileTime;
+ li += 30ll * MinutesToFileTime;
if (tm2.wHour == 23 && tm2.wMinute >= 30)
break;
@@ -703,27 +705,19 @@ static void PopulateTimeCombo(CCtrlCombo &pCombo, const SYSTEMTIME *tmUtc) mir_snwprintf(s, L"%02d:%02d (%d.%d %s)", (UINT)tm2.wHour, (UINT)tm2.wMinute, dt / 60, ((dt % 60) * 10) / 60, TranslateT("Hours"));
pCombo.AddString(s, dt * 60);
- li += (ULONGLONG)30 * MinutesToFileTime;
+ li += 30ll * MinutesToFileTime;
}
}
// returns non-zero if specified time was inside "missing" hour of daylight saving
// IMPORTANT: triggerRelUtcOut is only initialized if IsRelativeCombo() is TRUE and return value is 0
-static int ReformatTimeInput(CCtrlCombo &pCombo, CCtrlBase &pRef, int h, int m, const SYSTEMTIME *pDateLocal, ULONGLONG *triggerRelUtcOut = nullptr)
+static int ReformatTimeInput(CCtrlCombo &pCombo, ULONGLONG savedLi, int h, int m, const SYSTEMTIME *pDateLocal, ULONGLONG *triggerRelUtcOut = nullptr)
{
- const ULONGLONG MinutesToFileTime = (ULONGLONG)60 * FILETIME_TICKS_PER_SEC;
-
if (h < 0) {
// time value is an offset ('m' holds the offset in minutes)
-
if (IsRelativeCombo(pCombo)) {
- // get reference time (UTC) from hidden control
- wchar_t buf[64];
- pRef.GetText(buf, _countof(buf));
-
- ULONGLONG ref;
- ULONGLONG li;
- li = ref = _wcstoui64(buf, nullptr, 16);
+ ULONGLONG ref, li;
+ li = ref = savedLi;
// clamp delta time to 23.5 hours (coule be issues otherwise as relative combo only handles <24)
if (m > (23 * 60 + 30))
@@ -739,6 +733,7 @@ static int ReformatTimeInput(CCtrlCombo &pCombo, CCtrlBase &pRef, int h, int m, if (triggerRelUtcOut)
*triggerRelUtcOut = li;
+ wchar_t buf[64];
UINT dt = (UINT)((li / MinutesToFileTime) - (ref / MinutesToFileTime));
if (dt < 60)
mir_snwprintf(buf, L"%02d:%02d (%d %s)", h, m, dt, TranslateT("Minutes"));
@@ -772,8 +767,7 @@ static int ReformatTimeInput(CCtrlCombo &pCombo, CCtrlBase &pRef, int h, int m, // date format is a time offset ("24:43 (5 Minutes)" etc.)
if (IsRelativeCombo(pCombo)) {
// get reference time (UTC) from hidden control
- pRef.GetText(buf, _countof(buf));
- ULONGLONG ref = _wcstoui64(buf, nullptr, 16);
+ ULONGLONG ref = savedLi;
SYSTEMTIME tmRefLocal;
FileTimeToTzLocalST((FILETIME*)&ref, &tmRefLocal);
@@ -862,7 +856,6 @@ output_result: goto invalid_dst;
}
- pRef.SetText(buf);
goto invalid_dst;
}
}
@@ -873,48 +866,47 @@ output_result: // in: pDate contains the desired trigger date in LOCAL time
// out: pDate contains the resulting trigger time and date in UTC
-static bool GetTriggerTime(CCtrlCombo &pCombo, CCtrlBase &pRef, SYSTEMTIME *pDate)
+static bool GetTriggerTime(CCtrlCombo &pCombo, ULONGLONG savedLi, SYSTEMTIME &pDate)
{
- // get reference (UTC) time from hidden control
- wchar_t buf[32];
- pRef.GetText(buf, _countof(buf));
- ULONGLONG li = _wcstoui64(buf, nullptr, 16);
-
int n = pCombo.GetCurSel();
if (n != -1) {
// use preset value
preset_value:;
if (IsRelativeCombo(pCombo)) {
- // time offset from ref time ("24:43 (5 Minutes)" etc.)
+ ULONGLONG li;
+ SystemTimeToFileTime(&pDate, (FILETIME*)&li);
+ savedLi = li - (li % DayToFileTime) + (savedLi % DayToFileTime);
+ // time offset from ref time ("24:43 (5 Minutes)" etc.)
UINT nDeltaSeconds = pCombo.GetItemData(n);
- li += (ULONGLONG)nDeltaSeconds * FILETIME_TICKS_PER_SEC;
+ savedLi += (ULONGLONG)nDeltaSeconds * FILETIME_TICKS_PER_SEC;
- FileTimeToSystemTime((FILETIME*)&li, pDate);
+ FileTimeToSystemTime((FILETIME*)&savedLi, &pDate);
// if specified time is a small offset (< 10 Minutes) then retain current second count for better accuracy
// otherwise try to match specified time (which never contains seconds only even minutes) as close as possible
if (nDeltaSeconds >= 10 * 60) {
- pDate->wSecond = 0;
- pDate->wMilliseconds = 0;
+ pDate.wSecond = 0;
+ pDate.wMilliseconds = 0;
}
}
else {
// absolute time (offset from midnight on pDate)
UINT nDeltaSeconds = pCombo.GetItemData(n) & ~0x80000000;
- pDate->wHour = 0;
- pDate->wMinute = 0;
- pDate->wSecond = 0;
- pDate->wMilliseconds = 0;
- TzLocalSTToFileTime(pDate, (FILETIME*)&li);
- li += (ULONGLONG)nDeltaSeconds * FILETIME_TICKS_PER_SEC;
-
- FileTimeToSystemTime((FILETIME*)&li, pDate);
+ pDate.wHour = 0;
+ pDate.wMinute = 0;
+ pDate.wSecond = 0;
+ pDate.wMilliseconds = 0;
+ TzLocalSTToFileTime(&pDate, (FILETIME*)&savedLi);
+ savedLi += (ULONGLONG)nDeltaSeconds * FILETIME_TICKS_PER_SEC;
+
+ FileTimeToSystemTime((FILETIME*)&savedLi, &pDate);
}
return true;
}
// user entered a custom value
+ wchar_t buf[32];
pCombo.GetText(buf, _countof(buf));
int h, m;
@@ -926,18 +918,18 @@ preset_value:; if (IsRelativeCombo(pCombo)) {
// date has not been changed, the specified time is a time between reftime and reftime+24h
ULONGLONG li2;
- if (ReformatTimeInput(pCombo, pRef, h, m, pDate, &li2))
+ if (ReformatTimeInput(pCombo, savedLi, h, m, &pDate, &li2))
return FALSE;
// check if reformatted value is a preset
if ((n = pCombo.GetCurSel()) != -1)
goto preset_value;
- FileTimeToSystemTime((FILETIME*)&li2, pDate);
+ FileTimeToSystemTime((FILETIME*)&li2, &pDate);
return true;
}
- if (ReformatTimeInput(pCombo, pRef, h, m, pDate, nullptr))
+ if (ReformatTimeInput(pCombo, savedLi, h, m, &pDate, nullptr))
return false;
// check if reformatted value is a preset
@@ -945,17 +937,18 @@ preset_value:; goto preset_value;
// absolute time (on pDate)
- pDate->wHour = h;
- pDate->wMinute = m;
- pDate->wSecond = 0;
- pDate->wMilliseconds = 0;
+ pDate.wHour = h;
+ pDate.wMinute = m;
+ pDate.wSecond = 0;
+ pDate.wMilliseconds = 0;
- TzLocalSTToFileTime(pDate, (FILETIME*)&li);
- FileTimeToSystemTime((FILETIME*)&li, pDate);
+ ULONGLONG li;
+ TzLocalSTToFileTime(&pDate, (FILETIME*)&li);
+ FileTimeToSystemTime((FILETIME*)&li, &pDate);
return true;
}
-static void OnDateChanged(CCtrlDate &pDate, CCtrlCombo &pTime, CCtrlBase &refTime)
+static void OnDateChanged(CCtrlDate &pDate, CCtrlCombo &pTime, ULONGLONG &savedLi)
{
// repopulate time combo list with regular times (not offsets like "23:32 (5 minutes)" etc.)
wchar_t s[32];
@@ -978,7 +971,7 @@ static void OnDateChanged(CCtrlDate &pDate, CCtrlCombo &pTime, CCtrlBase &refTim m = (UINT)tm.wMinute;
}
- ReformatTimeInput(pTime, refTime, h, m, &Date);
+ ReformatTimeInput(pTime, savedLi, h, m, &Date);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -987,6 +980,7 @@ static void OnDateChanged(CCtrlDate &pDate, CCtrlCombo &pTime, CCtrlBase &refTim class CReminderNotifyDlg : public CDlgBase
{
REMINDERDATA *m_pReminder;
+ ULONGLONG m_savedLi;
void PopulateTimeOffsetCombo()
{
@@ -1024,7 +1018,6 @@ class CReminderNotifyDlg : public CDlgBase cmbRemindAgainIn.AddString(s, 7 * 24 * 60);
}
- CCtrlBase refTime;
CCtrlDate dateAgain;
CCtrlEdit edtText;
CCtrlCheck chkAfter, chkOnDate;
@@ -1035,7 +1028,7 @@ public: CReminderNotifyDlg(REMINDERDATA *pReminder) :
CDlgBase(g_plugin, IDD_NOTIFYREMINDER),
m_pReminder(pReminder),
- refTime(this, IDC_REFTIME),
+ m_savedLi(pReminder->When),
btnNone(this, IDC_NONE),
btnDismiss(this, IDC_DISMISS),
btnRemindAgain(this, IDC_REMINDAGAIN),
@@ -1067,13 +1060,6 @@ public: ULONGLONG li = m_pReminder->When;
FileTimeToSystemTime((FILETIME*)&li, &tm);
- // save reference time in hidden control, is needed when adding reminder to properly detect if speicifed
- // time wrapped around to tomorrow or not (dialog could in theory be open for a longer period of time
- // which could potentially mess up things otherwise)
- wchar_t s[32];
- mir_snwprintf(s, L"%I64x", li);
- refTime.SetText(s);
-
BringWindowToTop(m_hwnd);
PopulateTimeOffsetCombo();
@@ -1143,7 +1129,7 @@ public: void onChange_Date(CCtrlDate*)
{
- OnDateChanged(dateAgain, cmbTimeAgain, refTime);
+ OnDateChanged(dateAgain, cmbTimeAgain, m_savedLi);
}
void onKillFocus_TimeAgain(CCtrlCombo*)
@@ -1157,7 +1143,7 @@ public: if (ParseTime(buf, &h, &m, FALSE, IsRelativeCombo(cmbTimeAgain))) {
SYSTEMTIME Date;
dateAgain.GetTime(&Date);
- ReformatTimeInput(cmbTimeAgain, refTime, h, m, &Date);
+ ReformatTimeInput(cmbTimeAgain, m_savedLi, h, m, &Date);
}
else cmbTimeAgain.SetCurSel(0);
}
@@ -1230,7 +1216,7 @@ public: else if (chkOnDate.GetState()) {
SYSTEMTIME Date;
dateAgain.GetTime(&Date);
- if (!GetTriggerTime(cmbTimeAgain, refTime, &Date))
+ if (!GetTriggerTime(cmbTimeAgain, m_savedLi, Date))
return;
SystemTimeToFileTime(&Date, (FILETIME*)&m_pReminder->When);
@@ -1278,8 +1264,8 @@ INT_PTR OpenTriggeredReminder(WPARAM, LPARAM l) class CReminderFormDlg : public CDlgBase
{
REMINDERDATA *m_pReminder;
+ ULONGLONG m_savedLi;
- CCtrlBase refTime;
CCtrlDate date;
CCtrlEdit edtText;
CCtrlCheck chkRepeat;
@@ -1295,7 +1281,6 @@ public: btnView(this, IDC_VIEWREMINDERS),
btnPlaySound(this, IDC_BTN_PLAYSOUND),
edtText(this, IDC_REMINDER),
- refTime(this, IDC_REFTIME),
chkRepeat(this, IDC_CHECK_REPEAT),
cmbTime(this, IDC_COMBOREMINDERTIME),
cmbSound(this, IDC_COMBO_SOUND),
@@ -1313,7 +1298,6 @@ public: bool OnInitDialog() override
{
- ULONGLONG li;
SYSTEMTIME tm;
if (m_pReminder) {
@@ -1322,30 +1306,24 @@ public: SetDlgItemText(m_hwnd, IDC_ADDREMINDER, TranslateT("&Update Reminder"));
btnView.Hide();
- li = m_pReminder->When;
- FileTimeToSystemTime((FILETIME*)&li, &tm);
+ m_savedLi = m_pReminder->When;
+ FileTimeToSystemTime((FILETIME*)&m_savedLi, &tm);
}
else {
GetSystemTime(&tm);
- SystemTimeToFileTime(&tm, (FILETIME*)&li);
+ SystemTimeToFileTime(&tm, (FILETIME*)&m_savedLi);
}
- // save reference time in hidden control, is needed when adding reminder to properly detect if speicifed
- // time wrapped around to tomorrow or not (dialog could in theory be open for a longer period of time
- // which could potentially mess up things otherwise)
- wchar_t s[64];
- mir_snwprintf(s, L"%I64x", li);
- refTime.SetText(s);
-
PopulateTimeCombo(cmbTime, &tm);
// make sure date picker uses reference time
- FileTimeToTzLocalST((FILETIME*)&li, &tm);
+ FileTimeToTzLocalST((FILETIME*)&m_savedLi, &tm);
date.SetTime(&tm);
InitDatePicker(date);
edtText.SendMsg(EM_LIMITTEXT, MAX_REMINDER_LEN, 0);
+ wchar_t s[64];
if (m_pReminder) {
mir_snwprintf(s, L"%02d:%02d", tm.wHour, tm.wMinute);
@@ -1430,7 +1408,7 @@ public: {
SYSTEMTIME Date;
date.GetTime(&Date);
- if (!GetTriggerTime(cmbTime, refTime, &Date))
+ if (!GetTriggerTime(cmbTime, m_savedLi, Date))
return;
int RepeatSound = cmbRepeat.GetCurSel();
@@ -1498,7 +1476,7 @@ public: void onChange_Date(CCtrlDate*)
{
- OnDateChanged(date, cmbTime, refTime);
+ OnDateChanged(date, cmbTime, m_savedLi);
}
void onChange_Time(CCtrlCombo*)
@@ -1513,7 +1491,7 @@ public: if (ParseTime(buf, &h, &m, FALSE, IsRelativeCombo(cmbTime))) {
SYSTEMTIME Date;
date.GetTime(&Date);
- ReformatTimeInput(cmbTime, refTime, h, m, &Date);
+ ReformatTimeInput(cmbTime, m_savedLi, h, m, &Date);
}
else cmbTime.SetCurSel(0);
}
diff --git a/plugins/NotesAndReminders/src/resource.h b/plugins/NotesAndReminders/src/resource.h index d74d0aaf14..5538209feb 100644 --- a/plugins/NotesAndReminders/src/resource.h +++ b/plugins/NotesAndReminders/src/resource.h @@ -50,7 +50,6 @@ #define IDC_COMBOTIME 1022
#define IDC_COMBOREMINDERTIME 1023
#define IDC_CHECK_MSI 1023
-#define IDC_REFTIME 1024
#define IDC_STATIC_DATE 1025
#define IDC_STATIC_TIME 1026
#define IDC_COMBO_REPEATSND 1028
|