Ejemplo n.º 1
0
	/**
	 * 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;
	}
Ejemplo n.º 2
0
/**
 * name:	OnReminderChecked
 * class:	CAnnivEditCtrl
 * desc:	is called if reminder checkbox's state was changed
 * param:	none
 * return:	nothing
 **/
void CAnnivEditCtrl::OnReminderChecked()
{
	MCONTACT hContact;
	LPCSTR pszProto;
	int state;
	TCHAR buf[6];
	MAnnivDate *pCurrent = Current();

	PSGetContact(_hwndDlg, hContact);
	if (!hContact || !PSGetBaseProto(_hwndDlg, pszProto) || !pCurrent) 
	{
		EnableReminderCtrl(FALSE);
	}
	else
	{
		if (IsDlgButtonChecked(_hwndDlg, RADIO_REMIND1))
		{
			_itot(db_get_b(NULL, MODNAME, SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET), buf, 10);
			EnableWindow(GetDlgItem(_hwndDlg, EDIT_REMIND), FALSE);
			EnableWindow(GetDlgItem(_hwndDlg, SPIN_REMIND), FALSE);
			state = BST_INDETERMINATE;
		}
		else if (IsDlgButtonChecked(_hwndDlg, RADIO_REMIND2))
		{
			if (pCurrent->RemindOffset() == (WORD)-1)
			{
				_itot(db_get_b(NULL, MODNAME, SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET), buf, 10);
			}
			else
			{
				_itot(pCurrent->RemindOffset(), buf, 10);
			}
			EnableWindow(GetDlgItem(_hwndDlg, EDIT_REMIND), _ReminderEnabled);
			EnableWindow(GetDlgItem(_hwndDlg, SPIN_REMIND), _ReminderEnabled);
			state = BST_CHECKED;
		}
		else
		{
			*buf = 0;
			EnableWindow(GetDlgItem(_hwndDlg, EDIT_REMIND), FALSE);
			EnableWindow(GetDlgItem(_hwndDlg, SPIN_REMIND), FALSE);
			state = BST_UNCHECKED;
		}
		if (pCurrent->RemindOption() != state) 
		{
			pCurrent->RemindOption(state);
			if (!PspIsLocked(_hwndDlg)) 
			{
				pCurrent->SetFlags(MAnnivDate::MADF_REMINDER_CHANGED);
				SendMessage(GetParent(_hwndDlg), PSM_CHANGED, NULL, NULL);
			}
		}
		SetDlgItemText(_hwndDlg, EDIT_REMIND, buf);
	}
}
Ejemplo n.º 3
0
/**
 * name:	OnRemindEditChanged
 * class:	CAnnivEditCtrl
 * desc:	is called, if reminder edit control was changed
 * param:	none
 * return:	nothing
 **/
void CAnnivEditCtrl::OnRemindEditChanged()
{
	MAnnivDate	*pCurrent = Current();

	if (pCurrent) 
	{
		UINT iVal = GetDlgItemInt(_hwndDlg, EDIT_REMIND, NULL, FALSE);
		if (iVal != pCurrent->RemindOffset() && IsDlgButtonChecked(_hwndDlg, RADIO_REMIND2) == BST_CHECKED) 
		{
			SendMessage(GetParent(_hwndDlg), PSM_CHANGED, NULL, NULL);
			pCurrent->SetFlags(MAnnivDate::MADF_REMINDER_CHANGED);
			pCurrent->RemindOffset(iVal);
		}
	}
}
Ejemplo n.º 4
0
/**
 * name:	AddDate
 * class:	CAnnivEditCtrl
 * desc:	Add a new item to the array of dates
 * param:	mda		- the date to add
 * return:	0 on success, -1 on failure, 1 if the item to change was edited before and the new item was not set
 **/
INT_PTR CAnnivEditCtrl::AddDate(MAnnivDate &mda)
{
	MAnnivDate *pmda, **pmd;

	// if a date with wID exists, replace it
	if ((pmda = FindDateById(mda.Id())) != NULL) {
		BYTE bChanged = pmda->IsChanged(),
			bRemindChanged = pmda->IsReminderChanged();

		if (!bChanged) {
			pmda->Set(mda);
			pmda->Module(mda.Module());
			pmda->Description(mda.Description());
			pmda->Flags(mda.Flags());
		}
		if (!bRemindChanged) {
			pmda->RemindOption(mda.RemindOption());
			pmda->RemindOffset(mda.RemindOffset());
		}
		return bChanged || bRemindChanged;
	}
	if (mda.Id() == ANID_NONE)
		mda.Id(_numDates - 1);

	if (pmd = (MAnnivDate **)mir_realloc(_pDates, (_numDates + 1) * sizeof(pmda))) {
		_pDates = pmd;
		if (_pDates[_numDates] = new MAnnivDate(mda)) {
			_numDates++;
			return 0;
		}
	}
	return 1;
}
Ejemplo n.º 5
0
/**
 * name:	Set
 * class:	MAnnivDate
 * desc:	duplicates the given anniversary date class
 * param:	none
 * return:	nothing
 **/ 
VOID MAnnivDate::SetDate(MAnnivDate &mda)
{
	SetDate(mda.SystemTime());
	_wID = mda.Id();
	_strDesc = mda.Description();
	_strModule = mda.Module();
	_wFlags = mda.Flags();
	_bRemind = mda.RemindOption();
	_wDaysEarlier = mda.RemindOffset();
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
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;
}