/** * This method adds a row to the listview. * * @param hContact - contact to add the line for * @param pszProto - contact's protocol * @param ad - anniversary to add * @param mtNow - current time * @param wDaysBefore - number of days in advance to remind the user of the anniversary * * @retval TRUE if successful * @retval FALSE if failed **/ BYTE AddRow(MCONTACT hContact, LPCSTR pszProto, MAnnivDate &ad, MTime &mtNow, WORD wDaysBefore) { TCHAR szText[MAX_PATH]; int diff, iItem = -1; CItemData *pdata; // first column: ETA diff = ad.CompareDays(mtNow); if (diff < 0) diff += IsLeap(mtNow.Year() + 1) ? 366 : 365; // is filtered if (diff <= _filter.wDaysBefore) { // read reminder options for the contact ad.DBGetReminderOpts(hContact); if ((_filter.bFilterIndex != FILTER_DISABLED_REMINDER) || (ad.RemindOption() == BST_UNCHECKED)) { // set default offset if required if (ad.RemindOffset() == (WORD)-1) { ad.RemindOffset(wDaysBefore); // create data object pdata = new CItemData(hContact, ad); if (!pdata) return FALSE; // add item iItem = AddItem(_itot(diff, szText, 10), (LPARAM)pdata); if (iItem == -1) { delete pdata; return FALSE; } // second column: contact name AddSubItem(iItem, COLUMN_CONTACT, DB::Contact::DisplayName(hContact)); // third column: protocol TCHAR *ptszProto = mir_a2t(pszProto); AddSubItem(iItem, COLUMN_PROTO, ptszProto); mir_free(ptszProto); // forth line: age if (ad.Age(&mtNow)) AddSubItem(iItem, COLUMN_AGE, _itot(ad.Age(&mtNow), szText, 10)); else AddSubItem(iItem, COLUMN_AGE, _T("???")); // fifth line: anniversary AddSubItem(iItem, COLUMN_DESC, (LPTSTR)ad.Description()); // sixth line: date ad.DateFormatAlt(szText, _countof(szText)); AddSubItem(iItem, COLUMN_DATE, szText); _numRows++; } } } return TRUE; }
/** * name: DateCtrl_DBGetBirthDay * desc: * param: * return: 0 on success 1 otherwise **/ INT_PTR CAnnivEditCtrl::DBGetBirthDay(MCONTACT hContact, LPCSTR pszProto) { MAnnivDate mdb; if (!mdb.DBGetBirthDate(hContact, (char *)pszProto)) { mdb.DBGetReminderOpts(hContact); return AddDate(mdb) > 0; } return 0; }
/** * name: DateCtrl_DBGetBirthDay * desc: * param: * return: 0 on success 1 otherwise **/ INT_PTR CAnnivEditCtrl::DBGetAnniversaries(MCONTACT hContact) { MAnnivDate mda; WORD i; BYTE bChanged = FALSE; for (i = 0; i < ANID_LAST && !mda.DBGetAnniversaryDate(hContact, i); i++) { mda.DBGetReminderOpts(hContact); switch (AddDate(mda)) { case -1: return bChanged; case 1: bChanged |= 1; break; } } return bChanged; }
/** * This function checks, whether a contact has a birthday and it is within the period of time to remind of or not. * * @param hContact - the contact to check * @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 BOOLEAN CheckBirthday(HANDLE hContact, MTime &Now, CEvent &evt, BOOLEAN bNotify, PWORD LastAnwer) { BOOLEAN result = FALSE; if (gRemindOpts.RemindState == REMIND_BIRTH || gRemindOpts.RemindState == REMIND_ALL) { MAnnivDate mtb; if (!mtb.DBGetBirthDate(hContact)) { INT Diff; WORD wDaysEarlier; mtb.DBGetReminderOpts(hContact); // make backup of each protocol based birthday if (DB::Setting::GetByte(SET_REMIND_SECUREBIRTHDAY, TRUE)) { mtb.BackupBirthday(hContact, NULL, 0, LastAnwer); } if (mtb.RemindOption() != BST_UNCHECKED) { wDaysEarlier = (mtb.RemindOption() == BST_CHECKED) ? mtb.RemindOffset() : -1; if (wDaysEarlier == (WORD)-1) { wDaysEarlier = gRemindOpts.wDaysEarlier; } Diff = mtb.CompareDays(Now); if ((Diff >= 0) && (Diff <= wDaysEarlier)) { if (evt._wDaysLeft > Diff) { evt._wDaysLeft = Diff; evt._eType = CEvent::BIRTHDAY; } if (bNotify) { TCHAR szMsg[MAXDATASIZE]; WORD cchMsg = 0; switch (Diff) { case 0: { cchMsg = mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("%s has birthday today."), DB::Contact::DisplayName(hContact)); } break; case 1: { cchMsg = mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("%s has birthday tomorrow."), DB::Contact::DisplayName(hContact)); } break; default: { cchMsg = mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("%s has birthday in %d days."), DB::Contact::DisplayName(hContact), Diff); } } mir_sntprintf(szMsg + cchMsg, SIZEOF(szMsg) - cchMsg, TranslateT("\n%s becomes %d years old."), ContactGender(hContact), mtb.Age(&Now) + (Diff > 0)); NotifyWithPopup(hContact, CEvent::BIRTHDAY, Diff, mtb.Description(), szMsg); } result = TRUE; } } } } return result; }
static BOOLEAN CheckAnniversaries(HANDLE hContact, MTime &Now, CEvent &evt, BOOLEAN bNotify) { INT numAnniversaries = 0; INT Diff; MAnnivDate mta; INT i; TCHAR szAnniv[MAX_PATH]; TCHAR strMsg[MAX_SECONDLINE]; BOOLEAN bOverflow = FALSE; WORD wDaysEarlier; if ((gRemindOpts.RemindState == REMIND_ANNIV) || (gRemindOpts.RemindState == REMIND_ALL)) { for (i = 0; i < ANID_LAST && !mta.DBGetAnniversaryDate(hContact, i); i++) { mta.DBGetReminderOpts(hContact); if (mta.RemindOption() != BST_UNCHECKED) { wDaysEarlier = (mta.RemindOption() == BST_CHECKED) ? mta.RemindOffset() : -1; if (wDaysEarlier == (WORD)-1) { wDaysEarlier = gRemindOpts.wDaysEarlier; } Diff = mta.CompareDays(Now); if ((Diff >= 0) && (Diff <= wDaysEarlier)) { if (evt._wDaysLeft > Diff) { evt._wDaysLeft = Diff; evt._eType = CEvent::ANNIVERSARY; } numAnniversaries++; // create displayed text for popup if (bNotify && !bOverflow) { // first anniversary found if (numAnniversaries == 1) { mir_sntprintf(szAnniv, MAX_PATH, TranslateT("%s has the following anniversaries:\0"), ContactGender(hContact)); mir_tcsncpy(strMsg, szAnniv, mir_tcslen(szAnniv)); } switch (Diff) { case 0: { mir_sntprintf(szAnniv, MAX_PATH, TranslateT("%d. %s today\0"), mta.Age(), mta.Description()); } break; case 1: { mir_sntprintf(szAnniv, MAX_PATH, TranslateT("%d. %s tomorrow\0"), mta.Age() + 1, mta.Description()); } break; default: { mir_sntprintf(szAnniv, MAX_PATH, TranslateT("%d. %s in %d days\0"), mta.Age() + 1, mta.Description(), Diff); } } if (mir_tcslen(szAnniv) >= MAX_SECONDLINE - mir_tcslen(strMsg)) { if (strMsg) mir_tcsncat(strMsg, _T("\n...\0"), SIZEOF(strMsg)); else mir_tcsncpy(strMsg, _T("\n...\0"), mir_tcslen(_T("\n...\0"))); bOverflow = TRUE; } else { if (strMsg) mir_tcsncat(strMsg, _T("\n- \0"), SIZEOF(strMsg)); else mir_tcsncpy(strMsg, _T("\n- \0"), mir_tcslen(_T("\n- \0"))); mir_tcsncat(strMsg, szAnniv, SIZEOF(strMsg)); } } } } } } // show one popup for all anniversaries if (numAnniversaries != 0 && bNotify) { NotifyWithPopup(hContact, CEvent::ANNIVERSARY, Diff, LPGENT("Anniversaries"), strMsg); } return numAnniversaries != 0; }