Exemplo n.º 1
0
	// This method clears the list and adds contacts again, according to the current filter settings.
	void RebuildList()
	{
		LPSTR pszProto;
		MTime mtNow;
		MAnnivDate ad;
		int i = 0;
		DWORD age = 0;
		WORD wDaysBefore = db_get_w(NULL, MODNAME, SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET);
		WORD numMale = 0;
		WORD numFemale = 0;
		WORD numContacts = 0;
		WORD numBirthContacts = 0;

		ShowWindow(_hList, SW_HIDE);
		DeleteAllItems();
		mtNow.GetLocalTime();

		// insert the items into the list
		for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
			// ignore meta subcontacts here, as they are not interesting.
			if (!db_mc_isSub(hContact)) {
				// filter protocol
				pszProto = Proto_GetBaseAccountName(hContact);
				if (pszProto) {
					numContacts++;
					switch (GenderOf(hContact, pszProto)) {
					case 'M':
						numMale++;
						break;
					case 'F':
						numFemale++;
					}

					if (!ad.DBGetBirthDate(hContact, pszProto)) {
						age += ad.Age(&mtNow);
						numBirthContacts++;

						// add birthday
						if ((_filter.bFilterIndex != FILTER_ANNIV) && (!_filter.pszProto || !_strcmpi(pszProto, _filter.pszProto)))
							AddRow(hContact, pszProto, ad, mtNow, wDaysBefore);
					}

					// add anniversaries
					if (_filter.bFilterIndex != FILTER_BIRTHDAY && (!_filter.pszProto || !_strcmpi(pszProto, _filter.pszProto))) 
						for (i = 0; !ad.DBGetAnniversaryDate(hContact, i); i++)
							if (!_filter.pszAnniv || !mir_tstrcmpi(_filter.pszAnniv, ad.Description()))
								AddRow(hContact, pszProto, ad, mtNow, wDaysBefore);
				}
			}
		}
		ListView_SortItemsEx(_hList, (CMPPROC)cmpProc, this);
		ShowWindow(_hList, SW_SHOW);

		// display statistics
		SetDlgItemInt(_hDlg, TXT_NUMBIRTH, numBirthContacts, FALSE);
		SetDlgItemInt(_hDlg, TXT_NUMCONTACT, numContacts, FALSE);
		SetDlgItemInt(_hDlg, TXT_FEMALE, numFemale, FALSE);
		SetDlgItemInt(_hDlg, TXT_MALE, numMale, FALSE);
		SetDlgItemInt(_hDlg, TXT_AGE, numBirthContacts > 0 ? (age - (age % numBirthContacts)) / numBirthContacts : 0, FALSE);
	}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}