Esempio n. 1
0
void CProcessor::Edit(CBirthday * pbd)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState( )); 
	CSetBirthdayDlg bddlg( AfxGetMainWnd(), pbd->m_name, pbd->m_date.GetDay(), pbd->m_date.GetMonth(), pbd->m_date.GetYear() );
	if( bddlg.DoModal() == IDOK )
	{
		// Update the data
		pbd->m_name = bddlg.m_name;

		if( pbd->m_date != CDate(bddlg.m_day,bddlg.m_month,bddlg.m_year) )
		{
			// UPDATE ALL

			m_pApp->ClearKnown( pbd );
			// This garantees re-sorting
			CBirthday* pnew = new CBirthday;
			*pnew = *pbd;
			Remove( pbd );

			pnew->m_date = CDate(bddlg.m_day,bddlg.m_month,bddlg.m_year);
			Add( pbd=pnew );
		}

		// Persistency
		Store();

		// ONLY UPDATE SOME TEXT
		m_pApp->UpdateText( pbd );

		ProcessAction(true);
	}
}
Esempio n. 2
0
void CBDCApp::DrawToday()
{
	struct list_entry_t ple; 
	trillianListInitialize(ple);

	ple.section_id		= m_sectionID;
	ple.parent_id		= m_knowngroupID;
	ple.unique_id		= -1; 
	ple.group			= 0;
	ple.section			= 0; 
	ple.inline_editing	= 0;
	ple.drag_and_drop	= 0; 
	ple.expanded		= 1; 

	ple.font.flags = 0x1;
	ple.font.skin_name = "recent-online";
	ple.font.select_fore = "recent-online-fore";
	ple.font.hover_fore = "recent-online-fore";
	ple.font.normal_fore = "recent-online-fore";

	ASSERT( m_pproc );
	if( m_pproc )
		ple.previous_id	= m_pproc->GetNextID(&CDate());
	else
		ple.previous_id	= -1;

	CString c = CDate().GetDateString() + " (today)";
	ple.tooltip			= c.GetBuffer(0);
	ple.text			= c.GetBuffer(0);
	ple.data			= NULL;

	// icon
	ple.left_icons = (struct list_bmp_t *)malloc(sizeof(struct list_bmp_t));
	trillianInitialize((*ple.left_icons));

	ple.left_icons->num_states	= 1;
	ple.left_icons->bitmap		= (HBITMAP *)malloc(sizeof(HBITMAP));
	ple.left_icons->location		= (RECT *)malloc(sizeof(RECT));

	ple.left_icons->bitmap[0] = m_pbmpListentry_today;

	ple.left_icons->location[0].left	=  0;
	ple.left_icons->location[0].top		=  0;
	ple.left_icons->location[0].bottom	= 18;
	ple.left_icons->location[0].right	= 18;

	ple.num_left_icons = 1;

	// You'll need the UniqueID for any further manipulation, so store it somewhere nice
	m_todayID = m_plugin_send(MYGUID, "listAddEntry", (void *)&ple);

	// Free what needs to be freed
	FreeIcons(&ple);
}
Esempio n. 3
0
CDate CDate::operator-(BYTE min_days)
{
	if( min_days < 0 )
		return *this + -1*min_days;
	int day = m_day - min_days;
	int month = m_month;
	int offset_year = 0;
	while(true)
	{
		switch( m_month )
		{
			case 3:
				if( day<=0 )
				{
					day+=CountFebruary(offset_year); month--;
				}
				else
					return CDate(day, month, m_year);
				break;
			case 2:
			case 4:
			case 6:
			case 8:
			case 9:
			case 11:
			case 1:
				if( day<=0 )
				{
					day+=31; month--;
				}
				else
					return CDate(day, month, m_year);
				break;
			case 5:
			case 7:
			case 10:
			case 12:
				if( day<=0 )
				{
					day+=30; month--;
				}
				else
					return CDate(day, month, m_year);
				break;
		}
		if( month == 0 )
		{
			month=12; offset_year--;
		}
	}
}
Esempio n. 4
0
CDate CDate::operator+(BYTE plus_days)
{
	if( plus_days < 0 )
		return *this - -1*plus_days;
	int day = m_day + plus_days;
	int month = m_month;
	int offset_year = 0;
	while(true)
	{
		switch( m_month )
		{
			case 2:
				if( day>CountFebruary(offset_year) )
				{
					day-=CountFebruary(offset_year); month++;
				}
				else
					return CDate(day, month, m_year);
				break;
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				if( day>31 )
				{
					day-=31; month++;
				}
				else
					return CDate(day, month, m_year);
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				if( day>30 )
				{
					day-=30; month++;
				}
				else
					return CDate(day, month, m_year);
				break;
		}
		if( month > 12 )
		{
			month=1; offset_year++;
		}
	}
}
Esempio n. 5
0
 void CCalendar::initializeDate(int yr, int mth, int d,
                                int hr /*= 0*/, int min /*= 0*/, int sec /*= 0*/)
 {
   initDate = CDate(*this, yr, mth, d, hr, min, sec);
   timeOrigin = initDate;
   currentDate = initDate;
 }
Esempio n. 6
0
void CProcessor::Confirm(CBirthday *pbd)
{
	pbd->m_confirmed = true;

	if( !pbd->m_date.AfterAndWithinDays( CDate(),
			m_pconfig->m_daysAdvance ) )
		pbd->m_alerted_this_year = false;

	Store();
	ProcessAction(true);
}
Esempio n. 7
0
CDate CCreateData::RandDate()
{
    int nYear = 1985 + rd.Rand() % 30;    
    int nMonth = rd.Rand() % 12 + 1;    
    int Days1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int Days2[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int nDay = 0;
    //这样处理一下,生成的日期满足平闰年
    if (nYear % 4 == 0 && nYear % 100 != 0 || nYear % 400 == 0)
    {
        nDay = rd.Rand() % Days2[nMonth - 1];
    }
    else
    {
        //平年
        nDay = rd.Rand() % Days1[nMonth - 1];

    }
    return CDate(nYear, nMonth, nDay);
}
Esempio n. 8
0
int CBDCApp::menuCallback(char *event, void *data)
{
	struct menu_entry_t *item;
	item = (struct menu_entry_t *)data;

	if( !strcmp(event, "menu-select") )
	{
		switch( (MENU)(UINT)(void*)item->menu_id )
		{
			case MENU_ADD:
				{
					ASSERT(m_pproc);
					if( m_pproc )
					{
						AFX_MANAGE_STATE(AfxGetStaticModuleState( )); 
						CAddBirthdayDlg bddlg( AfxGetMainWnd() );
						if( bddlg.DoModal() == IDOK )
						{
							CBirthday * pbd = new CBirthday;
							// Store the data
								pbd->m_name = bddlg.m_name;
								pbd->m_date = CDate(bddlg.m_day,bddlg.m_month,bddlg.m_year);
								m_pproc->Add( pbd );
						}
					}
				}
				break;
			case MENU_REMOVE:
				{
					CBirthday * pbd = (CBirthday*)item->data;
					// Remove from data
					ASSERT(m_pproc);
					if( m_pproc ) m_pproc->Remove( pbd );
				}
				break;
			case MENU_EDIT:
				{
					CBirthday * pbd = (CBirthday*)item->data;
					ASSERT(m_pproc);
					if( m_pproc ) m_pproc->Edit(pbd);
				}
				break;
			case MENU_RELOAD:
				{
					CBirthday * pbd = (CBirthday*)item->data;
					ASSERT(m_pproc);
					if( m_pproc ) m_pproc->Reload(pbd);
				}
				break;
			case MENU_CONFIRM:
				{
					CBirthday * pbd = (CBirthday*)item->data;
					ASSERT(m_pproc);
					if( m_pproc ) m_pproc->Confirm(pbd);
				}
				break;
			default:
				break;
		}

	}
	return 0;
}
Esempio n. 9
0
CDate CDate::Today() {
	time_t t;
	time( &t );
	tm* tmp = localtime( &t );
	return CDate( tmp->tm_mon+1, tmp->tm_mday, 1900+tmp->tm_year );
}
Esempio n. 10
0
void CProcessor::ImportWAB()
{
	HINSTANCE hinstLib;
	HRESULT hRes;
	LPADRBOOK lpAdrBook;
	LPWABOBJECT lpWABObject;
	DWORD Reserved2 = NULL;

	fWABOpen procWABOpen;

    {
        TCHAR  szWABDllPath[MAX_PATH];
        DWORD  dwType = 0;
        ULONG  cbData = sizeof(szWABDllPath);
        HKEY hKey = NULL;

        *szWABDllPath = '\0';
        
        // First we look under the default WAB DLL path location in the
        // Registry. 
        // WAB_DLL_PATH_KEY is defined in wabapi.h
        //
        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
            RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);

        if(hKey) RegCloseKey(hKey);

        // if the Registry came up blank, we do a loadlibrary on the wab32.dll
        // WAB_DLL_NAME is defined in wabapi.h
        //
        hinstLib = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
    }

	if (hinstLib != NULL)
	{
		procWABOpen = (fWABOpen) GetProcAddress(hinstLib, "WABOpen");

		if (procWABOpen != NULL)
		{
			hRes = (procWABOpen)(&lpAdrBook,&lpWABObject,NULL,Reserved2); // WABOpen
			_ASSERTE(hRes == S_OK);
			if (hRes != S_OK) return;

			ULONG lpcbEntryID;
			ENTRYID *lpEntryID;
			hRes = lpAdrBook->GetPAB(
				&lpcbEntryID,
				&lpEntryID
			);
			_ASSERTE(hRes == S_OK);
			if (hRes != S_OK) return;

			ULONG ulFlags = MAPI_BEST_ACCESS;
			ULONG ulObjType = NULL;
			LPUNKNOWN lpUnk = NULL;
			hRes = lpAdrBook->OpenEntry(
				lpcbEntryID,
				lpEntryID,
				NULL,
				ulFlags,
				&ulObjType,
				&lpUnk
			);

			ulFlags = NULL;
			//IABTable *lpTable;
			
			if (ulObjType == MAPI_ABCONT)
			{
				IABContainer *lpContainer = static_cast <IABContainer *>(lpUnk);
				LPMAPITABLE lpTable = NULL;
				hRes = lpContainer->GetContentsTable(
					ulFlags,
					&lpTable
				);

				_ASSERT(lpTable);
				ULONG ulRows, ulFound = 0, ulExisted = 0;
				hRes = lpTable->GetRowCount(0,&ulRows);
				_ASSERTE(hRes == S_OK);

				SRowSet *lpRows;

				hRes = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0 );

				hRes = lpTable->QueryRows(
					ulRows,		// Get all Rows
					0,
					&lpRows
				);

				for(ULONG i=0;i<lpRows->cRows;i++)
				{
					bool bBirthdayProcessed = false;
					CBirthday* pbd = new CBirthday;
					SRow *lpRow = &lpRows->aRow[i];
					for(ULONG j=0;j<lpRow->cValues;j++)
					{
						SPropValue *lpProp = &lpRow->lpProps[j];
						if(lpProp->ulPropTag == PR_BIRTHDAY)
						{
							SYSTEMTIME st;
							FileTimeToSystemTime(&lpProp->Value.ft,&st);

							pbd->m_date = CDate((BYTE)st.wDay, (BYTE)st.wMonth, (UINT)st.wYear);
							bBirthdayProcessed = true;
						}
						if(lpProp->ulPropTag == PR_DISPLAY_NAME_A)
						{
							pbd->m_name = lpProp->Value.lpszA;
						}
					}
					if( bBirthdayProcessed && pbd->m_date.ValidDate() )
					{
						ulFound++;
						if( !WABExists(pbd) )
						{
							pbd->m_medium = MEDIUM_WAB;
							Add( pbd );
						}
						else
						{
							delete pbd;
							ulExisted++;
						}
					}
					else
						delete pbd;

					lpWABObject->FreeBuffer(lpRow);
				}
				CString c;
				c.Format( "Processed %d contacts\r\n\r\nFound %d birthdays of which\r\n%d already existed",
					ulRows, ulFound, ulExisted );
				AfxMessageBox( c, MB_OK|MB_SYSTEMMODAL, 0 );

				lpWABObject->FreeBuffer(lpRows);
			}
			if(lpAdrBook)
				lpAdrBook->Release();

			if(lpWABObject)
				lpWABObject->Release();

		}
// This would be nice but leads to crashing Trillian
//		FreeLibrary(hinstLib);
	}
}
Esempio n. 11
0
void CProcessor::ProcessAction(bool bForce/*=false*/)
{
	CString today;
	CString reminder;
	bool bChanged = false;
	bool bFirst = false;
	// Check if we entered a new hour
	if( (m_hours!=CTime::GetCurrentTime().GetHour()) || bForce )
	{
		m_hours=CTime::GetCurrentTime().GetHour();
		// Search for a birthday person
		POSITION pos = m_pbds->GetHead();
		while( pos )
		{
			CBirthday* pbd = m_pbds->GetNext( pos );

			// ARRANGE STATUSES
			if( pbd->m_date.AfterAndWithinDays( CDate(),
					m_pconfig->m_daysAdvance ) )
			{
				if( !pbd->m_alerted_this_year )
				{
					pbd->m_alerted_this_year = true;
					bFirst = true;
					pbd->m_confirmed = false;
					bChanged = true;
				}
			}
			else
			{
				if( pbd->m_alerted_this_year )
				{
					pbd->m_alerted_this_year = false;
					bChanged = true;
				}
			}

			// ARRANGE ALERTS

			// An alert could be given if the birthday is in the time that
			// is still to come or it is in the past but not yet confirmed
			if( pbd->m_date.AfterAndWithinDays( CDate(),
					m_pconfig->m_daysAdvance )
				|| (!pbd->m_confirmed && m_pconfig->m_keepUntilConfirmed) )
			{
				// Only alert if not already alerted today
				if( pbd->m_recent_alert!=CDate() )
				{
					pbd->m_recent_alert = CDate();
					if( pbd->m_date.IsDateOfYear() )
					{
						if( !pbd->m_confirmed || !m_pconfig->m_keepUntilConfirmed )
						{
							// TODAY
							if( m_pconfig->m_warnAnnoyingly )
							{
								if( today.GetLength() )
									today += ", ";
								today += pbd->m_name;
							}
							else
								m_pApp->Alert("Today's birthday: "+pbd->m_name);
						}
					}
					else
					{
						if( pbd->m_alerted_this_year && !bFirst )
						{
							if( m_pconfig->m_warnDaily
									&& (!pbd->m_confirmed || !m_pconfig->m_keepUntilConfirmed) )
							{
								// UPCOMING
								// ALREADY ALERTED (REMIND)
								if( m_pconfig->m_warnAnnoyingly )
								{
									if( reminder.GetLength() )
										reminder += ", ";
									reminder += pbd->m_name;
								}
								else
									m_pApp->Alert("Birthday reminder: "+pbd->m_name);
							}
						}
						else
							if( pbd->m_date.AfterAndWithinDays( CDate(),
									m_pconfig->m_daysAdvance ) )
							{
								// UPCOMING
								// FIRST ALERT
								if( m_pconfig->m_warnAnnoyingly )
								{
									if( reminder.GetLength() )
										reminder += ", ";
									reminder += pbd->m_name;
								}
								else
									m_pApp->Alert("Upcoming birthday: "+pbd->m_name);
							}
							else
								if( m_pconfig->m_warnDaily )
								{
									if( m_pconfig->m_warnAnnoyingly )
									{
										if( reminder.GetLength() )
											reminder += ", ";
										reminder += pbd->m_name;
									}
									else
										m_pApp->Alert("Forgotten birthday: "+pbd->m_name);
								}
					}
					bChanged = true;
				}
			}

			// ARRANGE LIST ENTRY
			if( pbd->m_date.AfterAndWithinDays( CDate(),
					m_pconfig->m_daysAdvance )
				|| (!pbd->m_confirmed && m_pconfig->m_keepUntilConfirmed) )
			{
				if( pbd->m_listid_bd >= 0 )
					m_pApp->UpdateIcon(pbd);
				else
					m_pApp->DrawBirthday(pbd);
			}
			else
			{
				if( pbd->m_listid_bd >= 0 )
					m_pApp->ClearBirthday( pbd );
			}
		}
		m_pApp->ClearToday();
		m_pApp->DrawToday();
	}
	if( bChanged ) Store();
	if( today.GetLength() || reminder.GetLength() )
	{
		AFX_MANAGE_STATE(AfxGetStaticModuleState( )); 
		CAnnoyDlg d( AfxGetMainWnd() );
		if( today.GetLength() )
			d.m_text = "TODAY'S BIRTHDAY(S):\r\n"+today+"\r\n\r\n";
		else
			d.m_text = "NO TODAY'S BIRTHDAYS\r\n\r\n";
		if( reminder.GetLength() )
			d.m_text += "OTHER CURRENT BIRTHDAY(S):\r\n"+reminder;
		d.DoModal();
	}
}
Esempio n. 12
0
bool CDate::IsDateOfYear()
{
	return IsDateOfYear(CDate());
}
Esempio n. 13
0
int CDate::GetAge()
{
	return CTime::GetCurrentTime().GetYear() - m_year - 
		((CDate()<*this)?1:0);
}
Esempio n. 14
0
// returns true if the value passed to it is a null date
bool CDateEditHelper::IsNull( CVariant& data ) {
	// pretty simple
	return ((CDate)data) == CDate();
}