From 7b5ebb74c654044a26aefc545a7f8a9a6a39c089 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 2 Aug 2022 13:57:52 +0300 Subject: UInfoEx: reminder options -> UI classes --- plugins/UserInfoEx/src/ctrl_annivedit.cpp | 6 +- plugins/UserInfoEx/src/dlg_anniversarylist.cpp | 4 +- plugins/UserInfoEx/src/init.cpp | 11 +- plugins/UserInfoEx/src/mir_menuitems.cpp | 4 +- plugins/UserInfoEx/src/psp_options.cpp | 306 ++++++++----------------- plugins/UserInfoEx/src/stdafx.h | 4 + plugins/UserInfoEx/src/svc_reminder.cpp | 52 ++--- plugins/UserInfoEx/src/svc_reminder.h | 25 +- 8 files changed, 136 insertions(+), 276 deletions(-) diff --git a/plugins/UserInfoEx/src/ctrl_annivedit.cpp b/plugins/UserInfoEx/src/ctrl_annivedit.cpp index 65df0c7dac..e3058fa3fe 100644 --- a/plugins/UserInfoEx/src/ctrl_annivedit.cpp +++ b/plugins/UserInfoEx/src/ctrl_annivedit.cpp @@ -41,7 +41,7 @@ CAnnivEditCtrl::CAnnivEditCtrl(HWND hDlg, uint16_t idCtrl, LPCSTR pszSetting) _hBtnEdit = GetDlgItem(hDlg, BTN_EDIT); _hBtnMenu = GetDlgItem(hDlg, BTN_MENU); _hwndDate = GetDlgItem(hDlg, EDIT_ANNIVERSARY_DATE); - _ReminderEnabled = g_plugin.getByte(SET_REMIND_ENABLED, DEFVAL_REMIND_ENABLED); + _ReminderEnabled = g_plugin.iRemindEnabled; _pDates = nullptr; _curDate = 0; @@ -537,7 +537,7 @@ void CAnnivEditCtrl::OnReminderChecked() { if (IsDlgButtonChecked(_hwndDlg, RADIO_REMIND1)) { - _itow(g_plugin.getByte(SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET), buf, 10); + _itow(g_plugin.wRemindOffset, buf, 10); EnableWindow(GetDlgItem(_hwndDlg, EDIT_REMIND), FALSE); EnableWindow(GetDlgItem(_hwndDlg, SPIN_REMIND), FALSE); state = BST_INDETERMINATE; @@ -546,7 +546,7 @@ void CAnnivEditCtrl::OnReminderChecked() { if (pCurrent->RemindOffset() == (uint16_t)-1) { - _itow(g_plugin.getByte(SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET), buf, 10); + _itow(g_plugin.wRemindOffset, buf, 10); } else { diff --git a/plugins/UserInfoEx/src/dlg_anniversarylist.cpp b/plugins/UserInfoEx/src/dlg_anniversarylist.cpp index c13f69613c..abc296e48e 100644 --- a/plugins/UserInfoEx/src/dlg_anniversarylist.cpp +++ b/plugins/UserInfoEx/src/dlg_anniversarylist.cpp @@ -322,7 +322,7 @@ class CAnnivList } // init reminder groups - pDlg->_bRemindEnable = g_plugin.getByte(SET_REMIND_ENABLED, DEFVAL_REMIND_ENABLED) != REMIND_OFF; + pDlg->_bRemindEnable = g_plugin.iRemindEnabled != REMIND_OFF; if (hCtrl = GetDlgItem(hDlg, CHECK_REMIND)) { Button_SetCheck(hCtrl, pDlg->_bRemindEnable ? BST_INDETERMINATE : BST_UNCHECKED); EnableWindow(hCtrl, pDlg->_bRemindEnable); @@ -690,7 +690,7 @@ class CAnnivList MAnnivDate ad; int i = 0; int totalAge = 0; - int wDaysBefore = g_plugin.getWord(SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET); + int wDaysBefore = g_plugin.wRemindOffset; int numMale = 0; int numFemale = 0; int numContacts = 0; diff --git a/plugins/UserInfoEx/src/init.cpp b/plugins/UserInfoEx/src/init.cpp index 7e77154b06..aba0400f1a 100644 --- a/plugins/UserInfoEx/src/init.cpp +++ b/plugins/UserInfoEx/src/init.cpp @@ -44,7 +44,16 @@ static PLUGININFOEX pluginInfoEx = }; CMPlugin::CMPlugin() : - PLUGIN(MODULENAME, pluginInfoEx) + PLUGIN(MODULENAME, pluginInfoEx), + bRemindExtraIcon(MODULENAME, "RemindExtraIcon", true), + bRemindFlashIcon(MODULENAME, "RemindFlashIcon", false), + bRemindMenuEnabled(MODULENAME, "RemindMenuEnabled", true), + bRemindStartupCheck(MODULENAME, "RemindStartupCheck", false), + bRemindCheckVisible(MODULENAME, "RemindCheckVisible", false), + iRemindEnabled(MODULENAME, "RemindEnabled", REMIND_ALL), + wRemindOffset(MODULENAME, "RemindOffset", 9), + wRemindSoundOffset(MODULENAME, "RemindSoundOffset", 3), + wRemindNotifyInterval(MODULENAME, "RemindNotifyInterval", 12) {} /* diff --git a/plugins/UserInfoEx/src/mir_menuitems.cpp b/plugins/UserInfoEx/src/mir_menuitems.cpp index 97d5a0111e..9dffcb95ed 100644 --- a/plugins/UserInfoEx/src/mir_menuitems.cpp +++ b/plugins/UserInfoEx/src/mir_menuitems.cpp @@ -239,9 +239,7 @@ void RebuildMain() // reminder mi.root = mhRoot; - const uint8_t bRemindMenus = - g_plugin.getByte(SET_REMIND_ENABLED, DEFVAL_REMIND_ENABLED) && - g_plugin.getByte(SET_REMIND_MENUENABLED, DEFVAL_REMIND_MENUENABLED); + bool bRemindMenus = g_plugin.iRemindEnabled && g_plugin.bRemindMenuEnabled; if (bRemindMenus) { // Check anniversaries SET_UID(mi, 0xcc1c8aa1, 0x7d1, 0x4554, 0x9c, 0xfe, 0xc4, 0x1e, 0xb9, 0x5d, 0x4a, 0xf); diff --git a/plugins/UserInfoEx/src/psp_options.cpp b/plugins/UserInfoEx/src/psp_options.cpp index 697c838f1b..bbbf06b8f5 100644 --- a/plugins/UserInfoEx/src/psp_options.cpp +++ b/plugins/UserInfoEx/src/psp_options.cpp @@ -173,82 +173,8 @@ static void DBWriteColor(HWND hDlg, const int idCtrl, LPCSTR pszSetting) g_plugin.setDword(pszSetting, (uint32_t)SendDlgItemMessage(hDlg, idCtrl, CPM_GETCOLOUR, 0, 0)); } -/** - * This function writes a uint8_t to database according to the value - * read from the edit control identified by 'idCtrl'. - * - * @param hWnd - the dialog's window handle - * @param idCtrl - the dialog item's identifier - * @param pszSetting - the setting to write the button state to - * @param defVal - this is the default value used by the GetByte() function in order - * to check whether updating the value is required or not. - * - * @retval TRUE - the database value was updated - * @retval FALSE - no database update needed - **/ -static uint8_t DBWriteEditByte(HWND hDlg, const int idCtrl, LPCSTR pszSetting, uint8_t defVal) -{ - uint8_t v; - BOOL t; - - v = (uint8_t)GetDlgItemInt(hDlg, idCtrl, &t, FALSE); - if (t && (v != g_plugin.getByte(pszSetting, defVal))) { - g_plugin.setByte(pszSetting, v); - return true; - } - return FALSE; -} - -/** - * This function writes a uint16_t to database according to the value - * read from the edit control identified by 'idCtrl'. - * - * @param hWnd - the dialog's window handle - * @param idCtrl - the dialog item's identifier - * @param pszSetting - the setting to write the button state to - * @param defVal - this is the default value used by the GetWord() function in order - * to check whether updating the value is required or not. - * - * @retval TRUE - the database value was updated - * @retval FALSE - no database update needed - **/ -static uint8_t DBWriteEditWord(HWND hDlg, const int idCtrl, LPCSTR pszSetting, uint16_t defVal) -{ - uint16_t v; - BOOL t; - - v = (uint16_t)GetDlgItemInt(hDlg, idCtrl, &t, FALSE); - if (t && (v != g_plugin.getWord(pszSetting, defVal))) { - g_plugin.setWord(pszSetting, v); - return true; - } - return FALSE; -} - -/** - * This function writes a uint8_t to database according to the currently - * selected item of a combobox identified by 'idCtrl'. - * - * @param hWnd - the dialog's window handle - * @param idCtrl - the dialog item's identifier - * @param pszSetting - the setting to write the button state to - * @param defVal - this is the default value used by the GetByte() function in order - * to check whether updating the value is required or not. - * - * @retval TRUE - the database value was updated - * @retval FALSE - no database update needed - **/ -static uint8_t DBWriteComboByte(HWND hDlg, const int idCtrl, LPCSTR pszSetting, uint8_t defVal) -{ - uint8_t v; - - v = (uint8_t)SendDlgItemMessage(hDlg, idCtrl, CB_GETCURSEL, NULL, NULL); - if (v != g_plugin.getByte(pszSetting, defVal)) { - g_plugin.setByte(pszSetting, v); - return true; - } - return FALSE; -} +///////////////////////////////////////////////////////////////////////////////////////// +// Common options dialog static INT_PTR CALLBACK DlgProc_CommonOpts(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -361,6 +287,9 @@ static INT_PTR CALLBACK DlgProc_CommonOpts(HWND hDlg, UINT uMsg, WPARAM wParam, return FALSE; } +///////////////////////////////////////////////////////////////////////////////////////// +// Advanced options dialog + static INT_PTR CALLBACK DlgProc_AdvancedOpts(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static uint8_t bInitialized = 0; @@ -449,6 +378,9 @@ static INT_PTR CALLBACK DlgProc_AdvancedOpts(HWND hDlg, UINT uMsg, WPARAM wParam return FALSE; } +///////////////////////////////////////////////////////////////////////////////////////// +// Details options dialog + static INT_PTR CALLBACK DlgProc_DetailsDlgOpts(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static uint8_t bInitialized = 0; @@ -528,155 +460,97 @@ static INT_PTR CALLBACK DlgProc_DetailsDlgOpts(HWND hDlg, UINT uMsg, WPARAM wPar return FALSE; } +///////////////////////////////////////////////////////////////////////////////////////// +// Reminder options dialog -static INT_PTR CALLBACK DlgProc_ReminderOpts(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +class CReminderOptsDlg : public CDlgBase { - static uint8_t bInitialized = 0; - - switch (uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hDlg); + CCtrlSpin spin1, spin2, spinOffset; + CCtrlCheck chkVisible, chkFlash, chkStartup, chkMenu; + CCtrlCombo cmbEnabled; + +public: + CReminderOptsDlg() : + CDlgBase(g_plugin, IDD_OPT_REMINDER), + cmbEnabled(this, EDIT_REMIND_ENABLED), + chkMenu(this, CHECK_REMIND_MI), + chkFlash(this, CHECK_REMIND_FLASHICON), + chkStartup(this, CHECK_REMIND_STARTUP), + chkVisible(this, CHECK_REMIND_VISIBLEONLY), + spin1(this, SPIN_REMIND, 50), + spin2(this, SPIN_REMIND2, 8760, 1), + spinOffset(this, SPIN_REMIND_SOUNDOFFSET, 50) + { + CreateLink(chkMenu, g_plugin.bRemindMenuEnabled); + CreateLink(chkFlash, g_plugin.bRemindFlashIcon); + CreateLink(chkStartup, g_plugin.bRemindStartupCheck); + CreateLink(chkVisible, g_plugin.bRemindCheckVisible); + + CreateLink(spin1, g_plugin.wRemindOffset); + CreateLink(spin1, g_plugin.wRemindNotifyInterval); + CreateLink(spinOffset, g_plugin.wRemindSoundOffset); + + cmbEnabled.OnSelChanged = Callback(this, &CReminderOptsDlg::onChange_Enabled); + } - SendDlgItemMessage(hDlg, ICO_BIRTHDAY, STM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_ANNIVERSARY, true)); + bool OnInitDialog() override + { + SendDlgItemMessage(m_hwnd, ICO_BIRTHDAY, STM_SETIMAGE, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_ANNIVERSARY, true)); // set colours - SendDlgItemMessage(hDlg, EDIT_REMIND, EM_LIMITTEXT, 2, 0); - SendDlgItemMessage(hDlg, SPIN_REMIND, UDM_SETRANGE32, 0, 50); - SendDlgItemMessage(hDlg, EDIT_REMIND2, EM_LIMITTEXT, 4, 0); - SendDlgItemMessage(hDlg, SPIN_REMIND2, UDM_SETRANGE32, 1, 8760); - SendDlgItemMessage(hDlg, EDIT_REMIND_SOUNDOFFSET, EM_LIMITTEXT, 2, 0); - SendDlgItemMessage(hDlg, SPIN_REMIND_SOUNDOFFSET, UDM_SETRANGE32, 0, 50); - - HWND hCtrl; - if (hCtrl = GetDlgItem(hDlg, EDIT_REMIND_ENABLED)) { - ComboBox_AddString(hCtrl, TranslateT("Reminder disabled")); - ComboBox_AddString(hCtrl, TranslateT("Birthdays only")); - ComboBox_AddString(hCtrl, TranslateT("Anniversaries only")); - ComboBox_AddString(hCtrl, TranslateT("Everything")); - } - - bInitialized = 0; - { - // set reminder options - uint8_t bEnabled = g_plugin.getByte(SET_REMIND_ENABLED, DEFVAL_REMIND_ENABLED); - SendDlgItemMessage(hDlg, EDIT_REMIND_ENABLED, CB_SETCURSEL, bEnabled, NULL); - DlgProc_ReminderOpts(hDlg, WM_COMMAND, MAKEWPARAM(EDIT_REMIND_ENABLED, CBN_SELCHANGE), - (LPARAM)GetDlgItem(hDlg, EDIT_REMIND_ENABLED)); - - DBGetCheckBtn(hDlg, CHECK_REMIND_MI, SET_REMIND_MENUENABLED, DEFVAL_REMIND_MENUENABLED); - DBGetCheckBtn(hDlg, CHECK_REMIND_FLASHICON, SET_REMIND_FLASHICON, FALSE); - DBGetCheckBtn(hDlg, CHECK_REMIND_VISIBLEONLY, SET_REMIND_CHECKVISIBLE, DEFVAL_REMIND_CHECKVISIBLE); - DBGetCheckBtn(hDlg, CHECK_REMIND_STARTUP, SET_REMIND_CHECKON_STARTUP, FALSE); - - SetDlgItemInt(hDlg, EDIT_REMIND, g_plugin.getWord(SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET), FALSE); - SetDlgItemInt(hDlg, EDIT_REMIND_SOUNDOFFSET, g_plugin.getByte(SET_REMIND_SOUNDOFFSET, DEFVAL_REMIND_SOUNDOFFSET), FALSE); - SetDlgItemInt(hDlg, EDIT_REMIND2, g_plugin.getWord(SET_REMIND_NOTIFYINTERVAL, DEFVAL_REMIND_NOTIFYINTERVAL), FALSE); - - MTime mtLast; - wchar_t szTime[MAX_PATH]; - - mtLast.DBGetStamp(0, MODULENAME, SET_REMIND_LASTCHECK); - mtLast.UTCToLocal(); - mtLast.TimeFormat(szTime, _countof(szTime)); - - SetDlgItemText(hDlg, TXT_REMIND_LASTCHECK, szTime); - } - bInitialized = 1; - return TRUE; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->code) { - case PSN_APPLY: - { - uint8_t bReminderCheck = FALSE; - - // save checkbox options - DBWriteCheckBtn(hDlg, CHECK_REMIND_MI, SET_REMIND_MENUENABLED); - DBWriteCheckBtn(hDlg, CHECK_REMIND_FLASHICON, SET_REMIND_FLASHICON); - DBWriteCheckBtn(hDlg, CHECK_REMIND_VISIBLEONLY, SET_REMIND_CHECKVISIBLE); - DBWriteCheckBtn(hDlg, CHECK_REMIND_STARTUP, SET_REMIND_CHECKON_STARTUP); - - DBWriteEditByte(hDlg, EDIT_REMIND_SOUNDOFFSET, SET_REMIND_SOUNDOFFSET, DEFVAL_REMIND_SOUNDOFFSET); - DBWriteEditWord(hDlg, EDIT_REMIND2, SET_REMIND_NOTIFYINTERVAL, DEFVAL_REMIND_NOTIFYINTERVAL); - bReminderCheck = DBWriteEditWord(hDlg, EDIT_REMIND, SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET); - - // update current reminder state - uint8_t bNewVal = (uint8_t)SendDlgItemMessage(hDlg, EDIT_REMIND_ENABLED, CB_GETCURSEL, NULL, NULL); - if (g_plugin.getByte(SET_REMIND_ENABLED, 1) != bNewVal) { - g_plugin.setByte(SET_REMIND_ENABLED, bNewVal); - if (bNewVal == REMIND_OFF) { - SvcReminderEnable(FALSE); - bReminderCheck = FALSE; - } - else bReminderCheck = TRUE; - } + cmbEnabled.AddString(TranslateT("Reminder disabled")); + cmbEnabled.AddString(TranslateT("Birthdays only")); + cmbEnabled.AddString(TranslateT("Anniversaries only")); + cmbEnabled.AddString(TranslateT("Everything")); + + // set reminder options + cmbEnabled.SetCurSel(g_plugin.iRemindEnabled); + + MTime mtLast; + wchar_t szTime[MAX_PATH]; + + mtLast.DBGetStamp(0, MODULENAME, SET_REMIND_LASTCHECK); + mtLast.UTCToLocal(); + mtLast.TimeFormat(szTime, _countof(szTime)); + + SetDlgItemText(m_hwnd, TXT_REMIND_LASTCHECK, szTime); + return true; + } + bool OnApply() override + { + // update current reminder state + uint8_t bNewVal = (uint8_t)cmbEnabled.GetCurSel(); + if (g_plugin.iRemindEnabled != bNewVal) { + g_plugin.iRemindEnabled = bNewVal; + if (bNewVal == REMIND_OFF) + SvcReminderEnable(false); + else { // update all contact list extra icons - if (bReminderCheck) { - SvcReminderEnable(TRUE); // reinit reminder options from db - SvcReminderCheckAll(NOTIFY_CLIST); // notify - } - RebuildMain(); + SvcReminderEnable(true); // reinit reminder options from db + SvcReminderCheckAll(NOTIFY_CLIST); // notify } } - break; - case WM_COMMAND: - switch (LOWORD(wParam)) { - case EDIT_REMIND_ENABLED: - if (HIWORD(wParam) == CBN_SELCHANGE) { - int bEnabled = ComboBox_GetCurSel((HWND)lParam) > 0; - const int idCtrl[] = { - CHECK_REMIND_MI, EDIT_REMIND, EDIT_REMIND2, SPIN_REMIND, SPIN_REMIND2, TXT_REMIND, - TXT_REMIND2, TXT_REMIND3, TXT_REMIND4, TXT_REMIND6, TXT_REMIND8, TXT_REMIND9, - TXT_REMIND_LASTCHECK, CHECK_REMIND_FLASHICON, CHECK_REMIND_VISIBLEONLY, - CHECK_REMIND_STARTUP, EDIT_REMIND_SOUNDOFFSET, SPIN_REMIND_SOUNDOFFSET - }; - - EnableControls(hDlg, idCtrl, _countof(idCtrl), bEnabled); - } - __fallthrough; - - case CHECK_REMIND_MI: - case CHECK_REMIND_FLASHICON: - case CHECK_REMIND_VISIBLEONLY: - case CHECK_REMIND_STARTUP: - if (bInitialized && HIWORD(wParam) == BN_CLICKED) - NotifyParentOfChange(hDlg); - break; - - // The user changes the number of days in advance of an anniversary to be notified by popups and clist extra icon. - case EDIT_REMIND: - if (bInitialized && HIWORD(wParam) == EN_UPDATE) { - BOOL t; - uint16_t v = (uint16_t)GetDlgItemInt(hDlg, LOWORD(wParam), &t, FALSE); - if (t && (v != g_plugin.getWord(SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET))) - NotifyParentOfChange(hDlg); - } - break; + RebuildMain(); + return true; + } - // The user changes the number of days in advance of an anniversary to be notified by sound. - case EDIT_REMIND_SOUNDOFFSET: - if (bInitialized && HIWORD(wParam) == EN_UPDATE) { - BOOL t; - uint8_t v = (uint8_t)GetDlgItemInt(hDlg, LOWORD(wParam), &t, FALSE); - if (t && (v != g_plugin.getByte(SET_REMIND_SOUNDOFFSET, DEFVAL_REMIND_SOUNDOFFSET))) - NotifyParentOfChange(hDlg); - } - break; + void onChange_Enabled(CCtrlCombo *pCombo) + { + const int idCtrl[] = { + CHECK_REMIND_MI, EDIT_REMIND, EDIT_REMIND2, SPIN_REMIND, SPIN_REMIND2, TXT_REMIND, + TXT_REMIND2, TXT_REMIND3, TXT_REMIND4, TXT_REMIND6, TXT_REMIND8, TXT_REMIND9, + TXT_REMIND_LASTCHECK, CHECK_REMIND_FLASHICON, CHECK_REMIND_VISIBLEONLY, + CHECK_REMIND_STARTUP, EDIT_REMIND_SOUNDOFFSET, SPIN_REMIND_SOUNDOFFSET + }; - // The user changes the notification interval - case EDIT_REMIND2: - if (bInitialized && HIWORD(wParam) == EN_UPDATE) { - BOOL t; - uint16_t v = (uint16_t)GetDlgItemInt(hDlg, LOWORD(wParam), &t, FALSE); - if (t && (v != g_plugin.getWord(SET_REMIND_NOTIFYINTERVAL, DEFVAL_REMIND_NOTIFYINTERVAL))) - NotifyParentOfChange(hDlg); - } - } + EnableControls(m_hwnd, idCtrl, _countof(idCtrl), pCombo->GetCurSel() > 0); } - return FALSE; -} +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// Popup options dialog static INT_PTR CALLBACK DlgProc_Popups(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -694,7 +568,7 @@ static INT_PTR CALLBACK DlgProc_Popups(HWND hDlg, UINT uMsg, WPARAM wParam, LPAR EnableDlgItem(hDlg, CHECK_OPT_POPUP_MSGBOX, FALSE); // enable/disable popups - uint8_t isEnabled = DBGetCheckBtn(hDlg, CHECK_OPT_POPUP_ENABLED, SET_POPUP_ENABLED, DEFVAL_POPUP_ENABLED); + uint8_t isEnabled = DBGetCheckBtn(hDlg, CHECK_OPT_POPUP_ENABLED, SET_POPUP_ENABLED, TRUE); SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(CHECK_OPT_POPUP_ENABLED, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, CHECK_OPT_POPUP_ENABLED)); // set colortype checkboxes and color controls @@ -966,8 +840,9 @@ int OnInitOptions(WPARAM wParam, LPARAM) // Reminder page odp.szTab.a = LPGEN("Reminder"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_REMINDER); - odp.pfnDlgProc = DlgProc_ReminderOpts; + odp.pszTemplate = 0; + odp.pfnDlgProc = 0; + odp.pDialog = new CReminderOptsDlg(); odp.flags = ODPF_BOLDGROUPS; g_plugin.addOptions(wParam, &odp); @@ -976,6 +851,7 @@ int OnInitOptions(WPARAM wParam, LPARAM) odp.szGroup.a = LPGEN("Popups"); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_POPUP); odp.pfnDlgProc = DlgProc_Popups; + odp.pDialog = 0; odp.flags = ODPF_BOLDGROUPS; g_plugin.addOptions(wParam, &odp); return MIR_OK; diff --git a/plugins/UserInfoEx/src/stdafx.h b/plugins/UserInfoEx/src/stdafx.h index 9568ee19c9..1d9186588e 100644 --- a/plugins/UserInfoEx/src/stdafx.h +++ b/plugins/UserInfoEx/src/stdafx.h @@ -107,6 +107,10 @@ struct CMPlugin : public PLUGIN { CMPlugin(); + CMOption iRemindEnabled; + CMOption wRemindOffset, wRemindSoundOffset, wRemindNotifyInterval; + CMOption bRemindExtraIcon, bRemindCheckVisible, bRemindFlashIcon, bRemindStartupCheck, bRemindMenuEnabled; + int Load() override; int Unload() override; }; diff --git a/plugins/UserInfoEx/src/svc_reminder.cpp b/plugins/UserInfoEx/src/svc_reminder.cpp index ba2d059ead..e479924df2 100644 --- a/plugins/UserInfoEx/src/svc_reminder.cpp +++ b/plugins/UserInfoEx/src/svc_reminder.cpp @@ -56,13 +56,12 @@ REMINDEROPTIONS, *LPREMINDEROPTIONS; static HANDLE ExtraIcon = INVALID_HANDLE_VALUE; +static HANDLE ghCListIA = nullptr; +static HANDLE ghCListIR = nullptr; +static HANDLE ghSettingsChanged = nullptr; -static HANDLE ghCListIA = nullptr; -static HANDLE ghCListIR = nullptr; -static HANDLE ghSettingsChanged = nullptr; - -static UINT_PTR ghRemindTimer = 0; -static UINT_PTR ghRemindDateChangeTimer = 0; +static UINT_PTR ghRemindTimer = 0; +static UINT_PTR ghRemindDateChangeTimer = 0; HANDLE ghCListAnnivIcons[11]; HANDLE ghCListBirthdayIcons[11]; @@ -339,7 +338,7 @@ static void NotifyFlashCListIcon(MCONTACT hContact, const CEvent &evt) static uint8_t NotifyWithSound(const CEvent &evt) { - if (evt._wDaysLeft <= min(g_plugin.getByte(SET_REMIND_SOUNDOFFSET, DEFVAL_REMIND_SOUNDOFFSET), gRemindOpts.wDaysEarlier)) { + if (evt._wDaysLeft <= min(g_plugin.wRemindSoundOffset, gRemindOpts.wDaysEarlier)) { switch (evt._eType) { case CEvent::BIRTHDAY: Skin_PlaySound(evt._wDaysLeft == 0 ? SOUND_BIRTHDAY_TODAY : SOUND_BIRTHDAY_SOON); @@ -434,13 +433,12 @@ static uint8_t CheckAnniversaries(MCONTACT hContact, MTime &Now, CEvent &evt, ui * @param Now - current time * @param evt - the reference to a structure, which retrieves the resulting DTB * @param bNotify - if TRUE, a popup will be displayed for a contact having birthday within the next few days. -* @param LastAnswer - this parameter is used for the automatic backup function * * @retval TRUE - contact has a birthday to remind of * @retval FALSE - contact has no birthday or it is not within the desired period of time. **/ -static bool CheckBirthday(MCONTACT hContact, MTime &Now, CEvent &evt, uint8_t bNotify, PWORD LastAnwer) +static bool CheckBirthday(MCONTACT hContact, MTime &Now, CEvent &evt, uint8_t bNotify) { if (gRemindOpts.RemindState == REMIND_BIRTH || gRemindOpts.RemindState == REMIND_ALL) { MAnnivDate mtb; @@ -511,18 +509,17 @@ static bool CheckBirthday(MCONTACT hContact, MTime &Now, CEvent &evt, uint8_t bN * @param Now - current time * @param evt - the reference to a structure, which retrieves the resulting DTB * @param bNotify - if TRUE, a popup will be displayed for a contact having birthday within the next few days. -* @param LastAnswer - this parameter is used for the automatic backup function * * @return nothing **/ -static void CheckContact(MCONTACT hContact, MTime &Now, CEvent &evt, uint8_t bNotify, PWORD LastAnwer = nullptr) +static void CheckContact(MCONTACT hContact, MTime &Now, CEvent &evt, uint8_t bNotify) { // ignore meta subcontacts here as their birthday information are collected explicitly if (hContact && (!gRemindOpts.bCheckVisibleOnly || !Contact::IsHidden(hContact)) && !db_mc_isSub(hContact)) { CEvent ca; - if (CheckBirthday(hContact, Now, ca, bNotify, LastAnwer) || CheckAnniversaries(hContact, Now, ca, bNotify)) { + if (CheckBirthday(hContact, Now, ca, bNotify) || CheckAnniversaries(hContact, Now, ca, bNotify)) { evt << ca; if (bNotify) NotifyFlashCListIcon(hContact, ca); @@ -549,9 +546,8 @@ void SvcReminderCheckAll(const ENotify notify) // walk through all the contacts stored in the DB CEvent evt; - uint16_t a1 = 0; for (auto &hContact : Contacts()) - CheckContact(hContact, now, evt, notify != NOTIFY_CLIST, &a1); + CheckContact(hContact, now, evt, notify != NOTIFY_CLIST); if (notify != NOTIFY_CLIST) { // play sound for the next anniversary @@ -641,11 +637,7 @@ static int OnContactSettingChanged(MCONTACT hContact, DBCONTACTWRITESETTING* pdb CEvent evt; MTime now; now.GetLocalTime(); - if (!mir_strcmp(pdbcws->szModule, USERINFO)) { - uint16_t LastAnswer = IDNONE; - CheckContact(hContact, now, evt, FALSE, &LastAnswer); - } - else CheckContact(hContact, now, evt, FALSE, nullptr); + CheckContact(hContact, now, evt, FALSE); } return 0; } @@ -721,7 +713,7 @@ static void CALLBACK TimerProc_Check(HWND, UINT, UINT_PTR, DWORD) static void UpdateTimer(uint8_t bStartup) { - LONG wNotifyInterval = 60 * 60 * (LONG)g_plugin.getWord(SET_REMIND_NOTIFYINTERVAL, DEFVAL_REMIND_NOTIFYINTERVAL); + LONG wNotifyInterval = 60 * 60 * (LONG)g_plugin.wRemindNotifyInterval; MTime now, last; now.GetTimeUTC(); @@ -730,7 +722,7 @@ static void UpdateTimer(uint8_t bStartup) last.DBGetStamp(0, MODULENAME, SET_REMIND_LASTCHECK); // if last check occured at least one day before just do it on startup again - if (now.Year() > last.Year() || now.Month() > last.Month() || now.Day() > last.Day() || g_plugin.getByte(SET_REMIND_CHECKON_STARTUP, FALSE)) + if (now.Year() > last.Year() || now.Month() > last.Month() || now.Day() > last.Day() || g_plugin.bRemindFlashIcon) wNotifyInterval = 5; else wNotifyInterval -= now.Compare(last); @@ -748,7 +740,7 @@ static void UpdateTimer(uint8_t bStartup) * module loading & unloading ***********************************************************************************************************/ -void SvcReminderEnable(uint8_t bEnable) +void SvcReminderEnable(bool bEnable) { if (bEnable) { // Reminder is on // init hooks @@ -759,12 +751,12 @@ void SvcReminderEnable(uint8_t bEnable) ghSettingsChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, (MIRANDAHOOK)OnContactSettingChanged); // reinit reminder options - gRemindOpts.RemindState = g_plugin.getByte(SET_REMIND_ENABLED, DEFVAL_REMIND_ENABLED); - gRemindOpts.wDaysEarlier = g_plugin.getWord(SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET); - gRemindOpts.bCListExtraIcon = g_plugin.getByte(SET_REMIND_EXTRAICON, 1); - gRemindOpts.bCheckVisibleOnly = g_plugin.getByte(SET_REMIND_CHECKVISIBLE, DEFVAL_REMIND_CHECKVISIBLE); - gRemindOpts.bFlashCList = g_plugin.getByte(SET_REMIND_FLASHICON, FALSE); - gRemindOpts.bPopups = g_plugin.getByte(SET_POPUP_ENABLED, DEFVAL_POPUP_ENABLED); + gRemindOpts.RemindState = g_plugin.iRemindEnabled; + gRemindOpts.wDaysEarlier = g_plugin.wRemindOffset; + gRemindOpts.bCListExtraIcon = g_plugin.bRemindExtraIcon; + gRemindOpts.bCheckVisibleOnly = g_plugin.bRemindCheckVisible; + gRemindOpts.bFlashCList = g_plugin.bRemindFlashIcon; + gRemindOpts.bPopups = g_plugin.getByte(SET_POPUP_ENABLED, TRUE); // init the timer UpdateTimer(TRUE); @@ -791,7 +783,7 @@ void SvcReminderOnModulesLoaded(void) // init clist extra icon structure OnCListRebuildIcons(0, 0); - SvcReminderEnable(g_plugin.getByte(SET_REMIND_ENABLED, DEFVAL_REMIND_ENABLED) != REMIND_OFF); + SvcReminderEnable(g_plugin.iRemindEnabled != REMIND_OFF); } /** @@ -816,7 +808,7 @@ void SvcReminderLoadModule(void) hk.pszService = MS_USERINFO_REMINDER_CHECK; g_plugin.addHotkey(&hk); - if (g_plugin.getByte(SET_REMIND_ENABLED, DEFVAL_REMIND_ENABLED) != REMIND_OFF && ExtraIcon == INVALID_HANDLE_VALUE) + if (g_plugin.iRemindEnabled != REMIND_OFF && ExtraIcon == INVALID_HANDLE_VALUE) ExtraIcon = ExtraIcon_RegisterIcolib("Reminder", LPGEN("Reminder (UInfoEx)"), g_plugin.getIconHandle(IDI_ANNIVERSARY)); } diff --git a/plugins/UserInfoEx/src/svc_reminder.h b/plugins/UserInfoEx/src/svc_reminder.h index f162800866..115c23d673 100644 --- a/plugins/UserInfoEx/src/svc_reminder.h +++ b/plugins/UserInfoEx/src/svc_reminder.h @@ -38,20 +38,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define SOUND_BIRTHDAY_SOON "BirthdayComing" #define SOUND_ANNIVERSARY "Anniversary" -// databbase settings +// database settings #define SET_REMIND_LASTCHECK "RemindLastCheck" -#define SET_REMIND_ENABLED "RemindEnabled" -#define SET_REMIND_OFFSET "RemindOffset" -#define SET_REMIND_CHECKVISIBLE "RemindCheckVisible" -#define SET_REMIND_NOTIFYINTERVAL "RemindNotifyInterval" -#define SET_REMIND_FLASHICON "RemindFlashIcon" -#define SET_REMIND_EXTRAICON "RemindExtraIcon" -#define SET_REMIND_MENUENABLED "RemindMenuEnabled" #define SET_REMIND_BIRTHDAY_ENABLED "RemindBirthday" #define SET_REMIND_BIRTHDAY_OFFSET "RemindBirthdayOffset" -#define SET_REMIND_CHECKON_STARTUP "RemindStartupCheck" -#define SET_REMIND_BIRTHDAY_IGNORED "RemindSecureIgnored" -#define SET_REMIND_SOUNDOFFSET "RemindSoundOffset" + #define SET_POPUP_ENABLED "PopupEnabled" #define SET_POPUP_BIRTHDAY_COLORTYPE "PopupBirthClrType" #define SET_POPUP_BIRTHDAY_COLOR_TEXT "PopupBirthClrBirthText" @@ -61,15 +52,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define SET_POPUP_ANNIVERSARY_COLOR_BACK "PopupAnnivClrBack" #define SET_POPUP_DELAY "PopupDelay" -// default values -#define DEFVAL_REMIND_ENABLED REMIND_ALL -#define DEFVAL_REMIND_MENUENABLED 1 -#define DEFVAL_REMIND_OFFSET 9 -#define DEFVAL_REMIND_SOUNDOFFSET 3 -#define DEFVAL_REMIND_NOTIFYINTERVAL 12 -#define DEFVAL_POPUP_ENABLED 1 -#define DEFVAL_REMIND_CHECKVISIBLE 0 - #define HM_OPENMSG (WM_USER+1) /** @@ -95,10 +77,9 @@ enum ENotify **/ void SvcReminderCheckAll(const ENotify notify); -void SvcReminderOnTopToolBarLoaded(void); void SvcReminderOnModulesLoaded(void); -void SvcReminderEnable(uint8_t bEnable); +void SvcReminderEnable(bool bEnable); void SvcReminderLoadModule(void); void SvcReminderUnloadModule(void); -- cgit v1.2.3