示例#1
0
/**
 * This is the service function for MS_USERINFO_REMINDER_AGGRASIVEBACKUP.
 *
 * @param	hContact		- handle to single contact or NULL to backup all
 * @param	lParam			- if 1, the messagebox will not be displayed
 *
 * return:	0
 **/
static INT_PTR BackupBirthdayService(WPARAM wParam, LPARAM lParam)
{
    HANDLE hContact	= (HANDLE)wParam;
    MAnnivDate mdb;

    if (hContact)
    {
        if (!mdb.DBGetBirthDate(hContact))
        {
            mdb.BackupBirthday(hContact, NULL, TRUE);
        }
    }
    else
    {
        WORD a1 = 0;

        //walk through all the contacts stored in the DB
        for (hContact = DB::Contact::FindFirst();
                hContact != NULL;
                hContact = DB::Contact::FindNext(hContact))
        {
            if (!DB::MetaContact::IsSub(hContact) && !mdb.DBGetBirthDate(hContact))
            {
                mdb.BackupBirthday(hContact, NULL, TRUE, &a1);
            }
        }
    }

    if (lParam != TRUE)
    {
        MSGBOX mBox;

        mBox.cbSize = sizeof(MSGBOX);
        mBox.hParent = NULL;
        mBox.hiLogo = IcoLib_GetIcon(ICO_COMMON_BIRTHDAY);
        mBox.uType = MB_ICON_INFO;
        mBox.ptszTitle = TranslateT("Update custom birthday");
        mBox.ptszMsg = TranslateT("Backing up and syncing all birthdays complete!");
        MsgBoxService(NULL, (LPARAM)&mBox);
    }
    return 0;
}
示例#2
0
/**
 * 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;
}