Exemplo n.º 1
0
CAnnivEditCtrl::CAnnivEditCtrl(HWND hDlg, WORD idCtrl, LPCSTR pszSetting)
	: CBaseCtrl(hDlg, idCtrl, pszSetting)
{
	_hwndDlg = hDlg;
	_hBtnAdd = GetDlgItem(hDlg, BTN_ADD);
	_hBtnDel = GetDlgItem(hDlg, BTN_DELETE);
	_hBtnEdit = GetDlgItem(hDlg, BTN_EDIT);
	_hBtnMenu = GetDlgItem(hDlg, BTN_MENU);
	_hwndDate = GetDlgItem(hDlg, EDIT_ANNIVERSARY_DATE);
	_ReminderEnabled = db_get_b(NULL, MODNAME, SET_REMIND_ENABLED, DEFVAL_REMIND_ENABLED);

	_pDates = NULL;
	_curDate = 0;
	_numDates = 0;
	
	// set button tooltips
	SendMessage(_hBtnAdd, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Add a new anniversary"), MBBF_TCHAR);
	SendMessage(_hBtnDel, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete an existing anniversary"), MBBF_TCHAR);

	// limit textinput
	SendDlgItemMessage(_hwndDlg, EDIT_REMIND, EM_LIMITTEXT, 2, 0);
	SendDlgItemMessage(_hwndDlg, SPIN_REMIND, UDM_SETRANGE32, 0, 50);

	// birthday is shown as an item in any case
	{
		MAnnivDate mdb;

		mdb.Id(ANID_BIRTHDAY);
		mdb.Description(TranslateT("Birthday"));
		AddDate(mdb);
	}
}
Exemplo n.º 2
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.º 3
0
		static void SetZodiacAvatar(HANDLE hContact)
		{
			MAnnivDate mtb;

			// try to load birthday for contact
			if (!mtb.DBGetBirthDate(hContact))
			{
				MZodiac zodiac;
				//ICONINFO iinfo;
				CHAR szFileName[MAX_PATH];

				// get zodiac for birthday
				zodiac = mtb.Zodiac();

				if (!GetContactAvatarFileName(zodiac.pszName, szFileName, SIZEOF(szFileName)))
				{
					// extract the bitmap from the icon
					//GetIconInfo(zodiac.hIcon, &iinfo);

					// save the bitmap to a file used as avatar later
					if (!CallService(MS_AV_SETAVATAR, (WPARAM)hContact, (LPARAM)szFileName))
						db_set_b(hContact, "ContactPhoto", "IsZodiac", 1);
				}
			}
		}
Exemplo n.º 4
0
/**
 * 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;
}
Exemplo n.º 5
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;
	}
Exemplo n.º 6
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;
}
Exemplo n.º 7
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);
		}
	}
}
Exemplo n.º 8
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.º 9
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;
}
Exemplo n.º 10
0
/**
 * name:	EnableCurrentItem
 * class:	CAnnivEditCtrl
 * desc:	make control readonly if required
 * param:	none
 * return:	nothing
 **/
void CAnnivEditCtrl::EnableCurrentItem()
{
	MAnnivDate *pCurrent = Current();

	if (pCurrent) {
		MCONTACT hContact;
	
		PSGetContact(_hwndDlg, hContact);

		const BYTE bEnabled
			= !hContact ||
				(pCurrent->Flags() & CTRLF_HASCUSTOM) || 
				!(pCurrent->Flags() & (CTRLF_HASPROTO|CTRLF_HASMETA)) ||
				!db_get_b(NULL, MODNAME, SET_PROPSHEET_PCBIREADONLY, 0);

		EnableWindow(_hBtnEdit, bEnabled);
		EnableWindow(_hBtnDel, bEnabled);
		EnableWindow(_hwndDate, bEnabled);
	}
}
Exemplo n.º 11
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();
}
Exemplo n.º 12
0
/**
 * name:	OnMenuPopup
 * class:	CAnnivEditCtrl
 * desc:	is called to show a popup menu for all anniversaries of a contact
 * param:	none
 * return:	nothing
 **/
void CAnnivEditCtrl::OnDateChanged(LPNMDATETIMECHANGE lpChange)
{
	MAnnivDate *pCurrent = Current();

	if (pCurrent && !pCurrent->IsEqual(lpChange->st))
	{
		HWND hPs = GetParent(_hwndDlg);

		// save the new date to the structure
		DateTime_SetFormat(_hwndDate, NULL);
		pCurrent->Set(lpChange->st, TRUE);
		pCurrent->SetFlags(MAnnivDate::MADF_CHANGED|MAnnivDate::MADF_HASCUSTOM);
		
		// notify parent of the change
		SendMessage(hPs, PSM_CHANGED, NULL, NULL);
		EnableWindow(_hBtnDel, TRUE);

		// update the age and zodiac controls on the general propertysheetpage
		if (pCurrent->Id() == ANID_BIRTHDAY) 
		{
			SetZodiacAndAge(pCurrent);
		}
	}
}
Exemplo n.º 13
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);
	}
}
Exemplo n.º 14
0
/**
 * name:	DBWriteBirthDay
 * class:	CAnnivEditCtrl
 * desc:	writes the birthday for a contact to database
 * param:	hContact - the contact to write the anniversaries to
 * return:	0 on success 1 otherwise
 **/
INT_PTR CAnnivEditCtrl::DBWriteBirthDay(MCONTACT hContact)
{
	MAnnivDate *pmdb;

	if ((pmdb = FindDateById(ANID_BIRTHDAY)) == NULL)
		return 1;
		
	if (pmdb->IsChanged()) {
		// save birthday, to mBirthday module by default
		if (pmdb->Flags() & pmdb->MADF_HASCUSTOM)
			pmdb->DBWriteBirthDate(hContact);
		else
			pmdb->DBDeleteBirthDate(hContact);
	}

	if (pmdb->IsReminderChanged()) {
		pmdb->DBWriteReminderOpts(hContact);
	}
	pmdb->RemoveFlags(MAnnivDate::MADF_CHANGED|MAnnivDate::MADF_REMINDER_CHANGED);
	return 0;
}
Exemplo n.º 15
0
/**
 * This is the service procedure to retrieve contact information
 *
 * @param	wParam		- not used
 * @param	lParam		- pointer to a CONTACTINFO structure which tells what information is desired
 *
 * @retval	0 - if contact information was found and read correctly 
 * @retval	1 - if any error occured or setting was not found
 **/
INT_PTR GetContactInfo(WPARAM wParam, LPARAM lParam) 
{
	CONTACTINFO *ci = (CONTACTINFO*) lParam;
	INT_PTR result;

	if (ci && ci->cbSize == sizeof(CONTACTINFO) && (ci->szProto != NULL || (ci->szProto = DB::Contact::Proto(ci->hContact)) != NULL))
	{
		switch (ci->dwFlag & 0x7F) {

		//
		// contact name
		//
		case CNF_FIRSTNAME:		{
				result = GCIVarEx(ci, SET_CONTACT_FIRSTNAME);
			} break;

		case CNF_LASTNAME:		{
				result = GCIVarEx(ci, SET_CONTACT_LASTNAME);
			} break;

		case CNF_FIRSTLAST:		{
				result = GCIVarEx(ci, SET_CONTACT_FIRSTLASTNAME);	//first try to read "FullName"
				if(result) result = GCIFirstLast(ci);				//fallback to "FirstName" + "LastName"
			} break;

		case CNF_NICK:			{
				result = GCIVarEx(ci, SET_CONTACT_NICK);
			} break;

		case CNF_CUSTOMNICK:	{
				LPSTR s = ci->szProto;
				ci->szProto = MOD_CLIST;
				result = GCIVar(ci, SET_CONTACT_MYHANDLE);
				ci->szProto = s;
			} break;

		case CNF_LANGUAGE1:			{
				result = GCILangEx(ci, SET_CONTACT_LANG1);
			} break;

		case CNF_LANGUAGE2:			{
				result = GCILangEx(ci, SET_CONTACT_LANG2);
			} break;

		case CNF_LANGUAGE3:			{
				result = GCILangEx(ci, SET_CONTACT_LANG3);
			} break;

		//
		// private contact
		//
		case CNF_STREET:		{
				result = GCIVarEx(ci, SET_CONTACT_STREET);
			} break;

		case CNF_ZIP:			{
				result = GCIVarEx(ci, SET_CONTACT_ZIP); 
			} break;

		case CNF_CITY:			{
				result = GCIVarEx(ci, SET_CONTACT_CITY);
			} break;

		case CNF_STATE:			{
				result = GCIVarEx(ci, SET_CONTACT_STATE);
			} break;

		case CNF_COUNTRY:		{
				result = GCICountry(ci, SET_CONTACT_COUNTRY);
			} break;

		case CNF_PHONE:			{
				result = GCIVarEx(ci, SET_CONTACT_PHONE);
			} break;

		case CNF_FAX:			{
				result = GCIVarEx(ci, SET_CONTACT_FAX);
			} break;

		case CNF_CELLULAR:		{
				result = GCIVarEx(ci, SET_CONTACT_CELLULAR);
			} break;

		case CNF_EMAIL:			{
				result = GCIVarEx(ci, SET_CONTACT_EMAIL);
			} break;

		case CNF_HOMEPAGE:		{
				result = GCIVarEx(ci, SET_CONTACT_HOMEPAGE);
			} break;

		//
		// company information
		//
		case CNF_CONAME:		{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY);
			} break;

		case CNF_CODEPT:		{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_DEPARTMENT);
			} break;

		case CNF_COPOSITION:	{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_POSITION);
			} break;

		case CNF_COSTREET:		{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_STREET);
			} break;

		case CNF_COZIP:			{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_ZIP);
			} break;

		case CNF_COCITY:		{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_CITY);
			} break;

		case CNF_COSTATE:		{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_STATE);
			} break;

		case CNF_COCOUNTRY:		{
				result = GCICountry(ci, SET_CONTACT_COMPANY_COUNTRY);
			} break;

		case CNF_COPHONE:		{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_PHONE);
			} break;

		case CNF_COFAX:			{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_FAX);
			} break;

		case CNF_COCELLULAR:	{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_CELLULAR);
			} break;

		case CNF_COEMAIL:		{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_EMAIL);
			} break;

		case CNF_COHOMEPAGE:	{
				result = GCIVarEx(ci, SET_CONTACT_COMPANY_HOMEPAGE);
			} break;

		//
		// personal information
		//
		case CNF_ABOUT:			{
				result = GCIVarEx(ci, SET_CONTACT_ABOUT);
			} break;

		case CNF_MYNOTES:		{
				result = GCIVarEx(ci, SET_CONTACT_MYNOTES);
			} break;

		case CNF_AGE:			{
				result = GCIVarEx(ci, SET_CONTACT_AGE);
			} break;	  // returns age (byte, 0==unspecified) ??

		case CNF_GENDER:		{
				ci->bVal = GenderOf(ci->hContact, ci->szProto);
				ci->type = (ci->bVal != 0) ? CNFT_BYTE : 0;
				result = ci->type == 0;
			} break;

		case CNF_BIRTHDAY:		{
				MAnnivDate mda;
				result = mda.DBGetBirthDate(ci->hContact, ci->szProto);
				if (result == 0) {
					ci->bVal = (BYTE) mda.Day();
					ci->type = CNFT_BYTE;
				}
			} break;

		case CNF_BIRTHMONTH:	{
				MAnnivDate mda;
				result = mda.DBGetBirthDate(ci->hContact, ci->szProto);
				if (result == 0) {
					ci->bVal = (BYTE) mda.Month();
					ci->type = CNFT_BYTE;
				}
			} break;

		case CNF_BIRTHYEAR:		{
				MAnnivDate mda;
				result = mda.DBGetBirthDate(ci->hContact, ci->szProto);
				if (result == 0) {
					ci->wVal = (WORD) mda.Year();
					ci->type = CNFT_WORD;
				}
			} break;

		case CNF_BIRTHDATE:		{
				MAnnivDate mda;
				result = mda.DBGetBirthDate(ci->hContact, ci->szProto);
				if (result == 0) {
					SYSTEMTIME st = mda.SystemTime();
					ci->pszVal = NULL;
					if (ci->dwFlag & CNF_UNICODE) {
						WCHAR wszDate[80];
						if (GetDateFormatW(LOCALE_USER_DEFAULT, wParam == 1 ? DATE_LONGDATE : DATE_SHORTDATE, &st, NULL, wszDate, SIZEOF(wszDate))) {
							ci->pszVal = (LPTSTR)mir_wcsdup(wszDate);
						}
					}
					else {
						CHAR szDate[80];
						if (GetDateFormatA(LOCALE_USER_DEFAULT, wParam == 1 ? DATE_LONGDATE : DATE_SHORTDATE, &st, NULL, szDate, SIZEOF(szDate))) {
							ci->pszVal = (LPTSTR)mir_strdup(szDate);
						}
					}
					ci->type = (ci->pszVal != NULL) ? CNFT_ASCIIZ : 0;
					result = ci->type == 0;
				}
			} break;

		case CNF_TIMEZONE:		{
				//use new core tz interface
				if(tmi.prepareList) {
					HANDLE hTz = tmi.createByContact(ci->hContact, TZF_KNOWNONLY);
					if (hTz) {
						LPTIME_ZONE_INFORMATION tzi = tmi.getTzi(hTz);
						int offset = tzi->Bias + tzi->StandardBias;

						char str[80];
						mir_snprintf(str, SIZEOF(str), offset ? "UTC%+d:%02d" : "UTC", offset / -60, abs(offset % 60));
						ci->pszVal =	ci->dwFlag & CNF_UNICODE
										? (TCHAR*)mir_a2u(str) 
										: (TCHAR*)mir_strdup(str);
						ci->type = CNFT_ASCIIZ;
						return 0;
					}
					else {
						ci->pszVal = NULL;
					}
				}
				//fallback use old UIEX method
				else {
					CTimeZone* ptz = GetContactTimeZone(ci->hContact, ci->szProto);
					if (ptz) {
						if (ci->dwFlag & CNF_UNICODE) {
							ci->pszVal = (LPTSTR) mir_t2u(ptz->ptszDisplay);
						}
						else {
							ci->pszVal = (LPTSTR) mir_t2a(ptz->ptszDisplay);
						}
					}
					else {
						/* If a timezone does not exist in CTzMgr, it is a invalid timezone,
						because Windows and CTzMgr know all existing timezones and it
						would not be shown anywhere anyway as UserInfoEx displays only 
						known windows timezones in the details dialog!
						*/
						ci->pszVal = NULL;
					}
				}
				ci->type = (ci->pszVal != NULL) ? CNFT_ASCIIZ : 0;
				result = ci->type == 0;
			} break;

		//
		// information about IM specific stuff
		//
		case CNF_UNIQUEID:		{
				// protocol must define a PFLAG_UNIQUEIDSETTING
				result = CallProtoService(ci->szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
				if (result != CALLSERVICE_NOTFOUND && result != NULL) {
					result = GCIVar(ci, (LPCSTR) result);
				}
			} break;

		case CNF_DISPLAYUID:	{
				if (!GCIVar(ci, "display_uid"))
					result=0;
				else {
					result = CallProtoService(ci->szProto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0);
					if (result != CALLSERVICE_NOTFOUND && result != NULL) {
						result = GCIVar(ci, (LPCSTR) result);
					}
				}
			} break;

		case CNF_DISPLAYNC:
		case CNF_DISPLAY:		{
				INT i;
				for (i = 0; i < NAMEORDERCOUNT; i++) {
					switch (gNameOrder[i]) {
					case 0: // custom name
						{
							// make sure we aren't in CNF_DISPLAYNC mode
							// don't get custom name for NULL contact
							if (ci->hContact != NULL && (ci->dwFlag & 0x7F) == CNF_DISPLAY) {
								BYTE dwFlag = ci->dwFlag;
								ci->dwFlag = (ci->dwFlag & CNF_UNICODE) | CNF_CUSTOMNICK;
								if (!GetContactInfo(NULL, (LPARAM)ci)) {
									ci->dwFlag = dwFlag;
									return 0;
								}
								ci->dwFlag = dwFlag;
							}
						} break;
					case 1: // nick
						{
							if (!GCIVarEx(ci, SET_CONTACT_NICK))
								return 0;
						} break;
					case 2: // First Name
						{
							if (!GCIVarEx(ci, SET_CONTACT_FIRSTNAME))
								return 0;
						} break;
					case 3: // E-mail
						{
							if (!GCIVarEx(ci, SET_CONTACT_EMAIL))
								return 0;
						} break;
					case 4: // Last Name
						{
							if (!GCIVarEx(ci, SET_CONTACT_LASTNAME))
								return 0;
						} break;
					case 5: // Unique id
						{
							// protocol must define a PFLAG_UNIQUEIDSETTING
							result = CallProtoService(ci->szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
							if (result != CALLSERVICE_NOTFOUND && result != NULL) {
								if (!GCIStr(ci, (LPCSTR) result))
									return 0;
							}
						} break;
					case 6: // first + last name
						{
							if (!GCIFirstLast(ci))
								return 0;
						} break;
					default: // unknown contact
						{
							if (ci->dwFlag & CNF_UNICODE) {
								ci->pszVal = (LPTSTR) mir_wcsdup(TranslateW(L"'(Unknown Contact)'"));
							}
							else {
								ci->pszVal = (LPTSTR) mir_strdup(Translate("'(Unknown Contact)'"));
							}
							ci->type = (ci->pszVal != NULL) ? CNFT_ASCIIZ : 0;
							return ci->type == 0;
						}
					}
				}
			}

		default:				{
				result = 1;
			}
		}
	}
	else
	{
		result = 1;
	}
	return result;
}
Exemplo n.º 16
0
/**
 * Dialog procedure for the anniversary add/edit dialog
 *
 * @param	 hDlg	- handle to the dialog window
 * @param	 uMsg	- the message to handle
 * @param	 wParam	- parameter
 * @param	 lParam	- parameter
 *
 * @return	different values
 **/
static INT_PTR CALLBACK DlgProc_AnniversaryEditor(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	MAnnivDate *pDlgEditAnniv = (MAnnivDate *)GetUserData(hDlg);

	switch (uMsg) {
	case WM_INITDIALOG:
		pDlgEditAnniv = (MAnnivDate *)lParam;
		if (!PtrIsValid(pDlgEditAnniv))
			break;

		SetUserData(hDlg, lParam);

		// set icons
		if (db_get_b(NULL, MODNAME, SET_ICONS_BUTTONS, 1)) {
			SendDlgItemMessage(hDlg, IDOK, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIcon(ICO_BTN_OK));
			SendDlgItemMessage(hDlg, IDCANCEL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIcon(ICO_BTN_CANCEL));
		}
		SendDlgItemMessage(hDlg, IDC_HEADERBAR, WM_SETICON, 0, (LPARAM)IcoLib_GetIcon(ICO_DLG_ANNIVERSARY, TRUE));

		// translate controls
		SendDlgItemMessage(hDlg, IDOK, BUTTONTRANSLATE, NULL, NULL);
		SendDlgItemMessage(hDlg, IDCANCEL, BUTTONTRANSLATE, NULL, NULL);
		TranslateDialogDefault(hDlg);

		// init controls
		EnableWindow(GetDlgItem(hDlg, EDIT_CATEGORY), pDlgEditAnniv->Id() != ANID_BIRTHDAY);
		SetDlgItemText(hDlg, EDIT_CATEGORY, pDlgEditAnniv->Description());
		return TRUE;

	case WM_CTLCOLORSTATIC:
		SetBkColor((HDC)wParam, RGB(255, 255, 255));
		return (INT_PTR)GetStockObject(WHITE_BRUSH);

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case EDIT_CATEGORY:
			if (HIWORD(wParam) == EN_UPDATE)
				EnableWindow(GetDlgItem(hDlg, IDOK), GetWindowTextLength((HWND)lParam) > 0);
			break;

		case IDOK: {
			// read new description
			HWND hEdit = GetDlgItem(hDlg, EDIT_CATEGORY);
			int len = Edit_GetTextLength(hEdit);
			LPTSTR pszText;

			if (len == 0
				|| (pszText = (LPTSTR)_alloca((len + 1) * sizeof(TCHAR))) == NULL
				|| !Edit_GetText(hEdit, pszText, len + 1))
			{
				MsgErr(hDlg, LPGENT("Please enter a valid description first!"));
				break;
			}

			if (mir_tstrcmpi(pszText, pDlgEditAnniv->Description())) {
				pDlgEditAnniv->Description(pszText);
				pDlgEditAnniv->SetFlags(MAnnivDate::MADF_HASCUSTOM | MAnnivDate::MADF_CHANGED);
			}
		}
		// fall through
		case IDCANCEL:
			return EndDialog(hDlg, LOWORD(wParam));

		}
	}
	return FALSE;
}
Exemplo n.º 17
0
INT_PTR CALLBACK PSPProcAnniversary(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	CAnnivEditCtrl *pDateCtrl = CAnnivEditCtrl::GetObj(hDlg, EDIT_ANNIVERSARY_DATE);

	switch (uMsg) {
	case WM_INITDIALOG:
		{
			CCtrlList *pCtrlList = CCtrlList::CreateObj(hDlg);
			if (pCtrlList) {
				HFONT hBoldFont;
				PSGetBoldFont(hDlg, hBoldFont);
				SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hBoldFont, 0);

				TranslateDialogDefault(hDlg);

				pCtrlList->insert(CEditCtrl::CreateObj(hDlg, EDIT_AGE, SET_CONTACT_AGE, DBVT_BYTE));
				pCtrlList->insert(CAnnivEditCtrl::CreateObj(hDlg, EDIT_ANNIVERSARY_DATE, NULL));

				// hContact == NULL or reminder disabled
				CAnnivEditCtrl::GetObj(hDlg, EDIT_ANNIVERSARY_DATE)->EnableReminderCtrl(lParam != NULL);

				SendDlgItemMessage(hDlg, EDIT_AGE, EM_LIMITTEXT, 3, 0);
				SendDlgItemMessage(hDlg, SPIN_AGE, UDM_SETRANGE32, 0, 200);
			}
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_ICONCHANGED:
				{
					const ICONCTRL idIcon[] = {
						{ ICO_COMMON_BIRTHDAY, STM_SETIMAGE, ICO_BIRTHDAY },
						{ ICO_BTN_ADD, BM_SETIMAGE, BTN_ADD },
						{ ICO_BTN_DELETE, BM_SETIMAGE, BTN_DELETE }
					};
					IcoLib_SetCtrlIcons(hDlg, idIcon, _countof(idIcon));
				}
				return FALSE;
			}
			break; /* case 0 */

		case EDIT_ANNIVERSARY_DATE:
			if (!PspIsLocked(hDlg) && PtrIsValid(pDateCtrl)) {
				LPNMHDR lpNmhdr = (LPNMHDR)lParam;
				switch (lpNmhdr->code) {
				case DTN_DATETIMECHANGE:
					pDateCtrl->OnDateChanged((LPNMDATETIMECHANGE)lParam);
					break;
				case DTN_DROPDOWN:
					HWND hMonthCal = DateTime_GetMonthCal(lpNmhdr->hwndFrom);
					SetWindowLongPtr(hMonthCal, GWL_STYLE, GetWindowLongPtr(hMonthCal, GWL_STYLE) | MCS_WEEKNUMBERS);
					InvalidateRect(hMonthCal, NULL, TRUE);
				}
			}
			return FALSE;
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case EDIT_REMIND:
			if (!PspIsLocked(hDlg) && HIWORD(wParam) == EN_UPDATE)
			if (PtrIsValid(pDateCtrl))
				pDateCtrl->OnRemindEditChanged();
			return FALSE;

		/**
		* name:	BTN_MENU
		* desc:	the button to dropdown the list to show all items is pressed
		**/
		case BTN_MENU:
			if (HIWORD(wParam) == BN_CLICKED) {
				if (PtrIsValid(pDateCtrl))
					pDateCtrl->OnMenuPopup();
			}
			return FALSE;

		/**
		* name:	BTN_ADD
		* desc:	creates a new dialog to add a new anniversary
		**/
		case BTN_ADD:
			if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) {
				MAnnivDate Date;
				if (IDOK == DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_ANNIVERSARY_EDITOR), hDlg, DlgProc_AnniversaryEditor, (LPARAM)&Date)) {
					SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL);
					if (!pDateCtrl->AddDate(Date))
						pDateCtrl->SetCurSel(pDateCtrl->NumDates() - 1);
				}
			}
			return FALSE;

		/**
		* name:	BTN_EDIT
		* desc:	edit the currently selected anniversary
		**/
		case BTN_EDIT:
			if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) {
				MAnnivDate *pDate = pDateCtrl->Current();
				if (!pDate)
					MsgErr(hDlg, LPGENT("No valid date selected for editing!"));
				else if (
					IDOK == DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_ANNIVERSARY_EDITOR), hDlg, DlgProc_AnniversaryEditor, (LPARAM)pDate) &&
					(pDate->Flags() & (MAnnivDate::MADF_CHANGED | MAnnivDate::MADF_REMINDER_CHANGED)))
				{
					SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL);
					pDateCtrl->SetCurSel(pDateCtrl->CurrentIndex());
				}
			}
			return FALSE;

		/**
		* name:	BTN_DELETE
		* desc:	user wants to delete an anniversary
		**/
		case BTN_DELETE:
			if (HIWORD(wParam) == BN_CLICKED && PtrIsValid(pDateCtrl)) {
				MAnnivDate *pCurrent = pDateCtrl->Current();
				if (pCurrent) {
					int rc = MsgBox(hDlg, MB_YESNO | MB_ICON_QUESTION | MB_NOPOPUP, LPGENT("Delete"), NULL,
						LPGENT("Do you really want to delete the %s?"), pCurrent->Description());

					if (rc == IDYES)
						pDateCtrl->DeleteDate(pDateCtrl->CurrentIndex());
				}
			}
			return FALSE;

		/**
		* name:	CHECK_REMIND
		* desc:	state of reminder checkbox is changed
		**/
		case RADIO_REMIND1:
		case RADIO_REMIND2:
		case RADIO_REMIND3:
			CAnnivEditCtrl *pDateCtrl = CAnnivEditCtrl::GetObj(hDlg, EDIT_ANNIVERSARY_DATE);
			if (PtrIsValid(pDateCtrl) && HIWORD(wParam) == BN_CLICKED)
				pDateCtrl->OnReminderChecked();
			return FALSE;
		} /* switch (LOWORD(wParam)) */
		break;
	}
	return PSPBaseProc(hDlg, uMsg, wParam, lParam);
}
Exemplo n.º 18
0
/**
 * name:	Export
 * desc:	export the contacts information
 * param:	none
 * return	TRUE or FALSE
 **/
BYTE CVCardFileVCF::Export(BYTE bExportUtf)
{
	size_t cbRew = 0;

	_useUtf8 = bExportUtf;

	fputs("BEGIN:VCARD\nVERSION:2.1\n", _pFile);

	//
	// naming
	//
	packDB(USERINFO, SET_CONTACT_LASTNAME, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_FIRSTNAME, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_SECONDNAME, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_TITLE, &cbRew);
	_clVal + DELIM;
	packDBList(USERINFO, SET_CONTACT_PREFIX, (MIRANDASERVICE)GetNamePrefixList, FALSE, &cbRew);
	writeLine("N", &cbRew);

	if (packDB(USERINFO, SET_CONTACT_TITLE))
		_clVal + " ";

	if (packDB(USERINFO, SET_CONTACT_FIRSTNAME))
		_clVal + " ";
	else
		cbRew = 1;

	if (packDB(USERINFO, SET_CONTACT_SECONDNAME))
		_clVal + " ";
	else
		cbRew = 1;

	if (packDB(USERINFO, SET_CONTACT_LASTNAME))
		_clVal + " ";
	else
		cbRew = 1;

	packDBList(USERINFO, SET_CONTACT_PREFIX, (MIRANDASERVICE)GetNamePrefixList, FALSE, &cbRew);
	writeLine("FN");

	packDB(USERINFO, SET_CONTACT_NICK);
	writeLine("NICKNAME");

	//
	// organisation
	//
	packDB(USERINFO, SET_CONTACT_COMPANY, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_COMPANY_DEPARTMENT, &cbRew);
	writeLine("ORG", &cbRew);
	packDB(USERINFO, SET_CONTACT_COMPANY_POSITION);
	writeLine("TITLE");
	packDBList(USERINFO, SET_CONTACT_COMPANY_OCCUPATION, (MIRANDASERVICE)GetOccupationList, FALSE);
	writeLine("ROLE");

	//
	// phone numbers
	//
	if (packDB(USERINFO, SET_CONTACT_PHONE)) {
		_clVal.TruncateSMS();
		writeLine("TEL;HOME;VOICE");
	}
	if (packDB(USERINFO, SET_CONTACT_FAX)) {
		_clVal.TruncateSMS();
		writeLine("TEL;HOME;FAX");
	}
	if (packDB(USERINFO, SET_CONTACT_CELLULAR)) {
		_clVal.TruncateSMS();
		writeLine("TEL;CELL;VOICE");
	}
	if (packDB(USERINFO, SET_CONTACT_COMPANY_PHONE)) {
		_clVal.TruncateSMS();
		writeLine("TEL;WORK;VOICE");
	}
	if (packDB(USERINFO, SET_CONTACT_COMPANY_FAX)) {
		_clVal.TruncateSMS();
		writeLine("TEL;WORK;FAX");
	}
	if (packDB(USERINFO, SET_CONTACT_COMPANY_CELLULAR)) {
		_clVal.TruncateSMS();
		writeLine("TEL;PAGER;VOICE");
	}

	//
	// private address
	//
	_clVal + ";;"; 
	cbRew = 1;
	packDB(USERINFO, SET_CONTACT_STREET, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_CITY, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_STATE, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_ZIP, &cbRew);
	_clVal + DELIM;
	packDBList(USERINFO, SET_CONTACT_COUNTRY, (MIRANDASERVICE)GetCountryList, FALSE, &cbRew);
	writeLine("ADR;HOME", &cbRew);

	//
	// company address
	//
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_COMPANY_OFFICE, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_COMPANY_STREET, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_COMPANY_CITY, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_COMPANY_STATE, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_COMPANY_ZIP, &cbRew);
	_clVal + DELIM;
	packDBList(USERINFO, SET_CONTACT_COMPANY_COUNTRY, (MIRANDASERVICE)GetCountryList, FALSE, &cbRew);
	writeLine("ADR;WORK", &cbRew);

	//
	// origin address
	//
	_clVal + ";;";
	cbRew = 1;
	packDB(USERINFO, SET_CONTACT_ORIGIN_STREET, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_ORIGIN_CITY, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_ORIGIN_STATE, &cbRew);
	_clVal + DELIM;
	packDB(USERINFO, SET_CONTACT_ORIGIN_ZIP, &cbRew);
	_clVal + DELIM;
	packDBList(USERINFO, SET_CONTACT_ORIGIN_COUNTRY, (MIRANDASERVICE)GetCountryList, FALSE, &cbRew);
	writeLine("ADR;POSTAL", &cbRew);

	//
	// homepages
	//
	if (packDB(USERINFO, SET_CONTACT_HOMEPAGE))
		writeLine("URL;HOME");
	if (packDB(USERINFO, SET_CONTACT_COMPANY_HOMEPAGE))
		writeLine("URL;WORK");

	//
	// e-mails
	//
	if (packDB(USERINFO, SET_CONTACT_EMAIL))
		writeLine("EMAIL;PREF;intERNET");
	if (packDB(USERINFO, SET_CONTACT_EMAIL0))
		writeLine("EMAIL;intERNET");
	if (packDB(USERINFO, SET_CONTACT_EMAIL1))
		writeLine("EMAIL;intERNET");

	//
	// gender
	//
	{
		BYTE gender = db_get_b(_hContact, USERINFO, SET_CONTACT_GENDER, 0);
		if (!gender) gender = db_get_b(_hContact, _pszBaseProto, SET_CONTACT_GENDER, 0);
		switch (gender) {
			case 'F':
				fputs("X-WAB-GENDER:1\n", _pFile);
				break;
			case 'M':
				fputs("X-WAB-GENDER:2\n", _pFile);
				break;
		}
	}

	//
	// birthday
	//
	{
		MAnnivDate mdb;

		if (!mdb.DBGetBirthDate(_hContact, NULL))
			fprintf(_pFile, "BDAY:%d%02d%02d\n", mdb.Year(), mdb.Month(), mdb.Day());
	}
	
	//
	// notes
	//
	if (packDB(USERINFO, SET_CONTACT_MYNOTES))
		writeLineEncoded("NOTE");

	//
	// about
	//
	if (packDB(USERINFO, SET_CONTACT_ABOUT))
		writeLineEncoded("ABOUT");

	//
	// contacts protocol, uin setting, uin value
	//
	{
		CHAR szUID[MAXUID];
		LPCSTR uid;

		uid = (LPCSTR)CallProtoService(_pszBaseProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
		if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) {
			if (!db_get_static(_hContact, _pszBaseProto, uid, szUID, sizeof(szUID)))
				fprintf(_pFile, "IM;%s;%s:%s\n", _pszBaseProto, uid, szUID);
		}
	}
	
	//
	// time of creation
	//
	{
		SYSTEMTIME	st;
	
		GetLocalTime(&st);
		fprintf(_pFile, "REV:%04d%02d%02dD%02d%02d%02dT\n", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
	}

	fputs("END:VCARD", _pFile);
	return 0;
}
Exemplo n.º 19
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;
}
Exemplo n.º 20
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;
}