⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calldetailsdialog.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//

#include "InfoApp.hpp"
#include "CallDetailsDialog.hpp"
#include "Controls.hpp"
#include "FreeBusyCallRecordDisplayItem.h"
#include "SystemTimeUtils.h"
#include "Common.hpp"
#include "PhoneAPI.hpp"
#include "LabeledInfoDisplayItem.h"
#include "IExchangeClient.h"
#include "Poom.hpp"

const GalDrawingEntry CallDetailsDialog_t::sc_GalEntries[] =    
{
    GalName,         IDS_LABEL_NAME,         IExchangeClientGALSearchInformation::GetDisplayName, FALSE, 
    GalPhoneNumber,  IDS_LABEL_WORK_PHONE,   IExchangeClientGALSearchInformation::GetPhoneNumber, FALSE, 
    GalOfficeNumber, IDS_LABEL_OFFICENUMBER, IExchangeClientGALSearchInformation::GetOffice,      FALSE, 
    GalEmailAddress, IDS_LABEL_EMAILADDRESS, IExchangeClientGALSearchInformation::GetSMTPAddress, FALSE, 
};

const ContactsDrawingEntry CallDetailsDialog_t::sc_ContactsEntries[] =
{
    ContactName,        IDS_LABEL_NAME,         IContact::get_FileAs,                  FALSE, 
    ContactHomePhone,   IDS_LABEL_HOME_PHONE,   IContact::get_HomeTelephoneNumber,     FALSE, 
    ContactMobilePhone, IDS_LABEL_MOBILE_PHONE, IContact::get_MobileTelephoneNumber,   FALSE, 
    ContactWorkPhone,   IDS_LABEL_WORK_PHONE,   IContact::get_BusinessTelephoneNumber, FALSE, 
    ContactEmailAddr,   IDS_LABEL_EMAILADDRESS, IContact::get_Email1Address,           FALSE, 
};

const ContactsAddressDrawingEntry CallDetailsDialog_t::sc_ContactsAddressEntries[] =
{
    ContactHomeAddr, IDS_LABEL_HOMEADDRESS,
    ContactWorkAddr, IDS_LABEL_WORKADDRESS,
};

const pfnGetContactProperty CallDetailsDialog_t::sc_ContactsHomeAddressProperties[] =    
{
    IContact::get_HomeAddressStreet, 
    IContact::get_HomeAddressCity, 
    IContact::get_HomeAddressState,
    IContact::get_HomeAddressPostalCode, 
    IContact::get_HomeAddressCountry, 
};

const pfnGetContactProperty CallDetailsDialog_t::sc_ContactsOfficeAddressProperties[] =
{
    IContact::get_BusinessAddressStreet, 
    IContact::get_BusinessAddressCity, 
    IContact::get_BusinessAddressState, 
    IContact::get_BusinessAddressPostalCode, 
    IContact::get_BusinessAddressCountry, 
};

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::CallDetailsDialog_t

    Constructor.    
------------------------------------------------------------------------------*/
CallDetailsDialog_t::CallDetailsDialog_t(
    InfoApp_t::ScreenId Id, 
    IUnknown*           piInformation
    )
{
    if (piInformation == NULL)
    {
        ASSERT (FALSE);
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Record (Call Details/GAL/Poom) is NULL."));   
        return;
    }
    //    
    //  On creation, we either have already completed:
    //  A GAL Search        - this is the GAL details state
    //  A Contacts search   - this is the contact information state
    //  A calllog record    - this is the call log details state
    //
    m_ScreenId = Id;
    switch (m_ScreenId)
    {
    case InfoApp_t::IdOutgoingCallDetailsDialog:    
    case InfoApp_t::IdIncomingCallDetailsDialog:
    case InfoApp_t::IdMissedCallDetailsDialog:
        
        piInformation->QueryInterface (
            IID_IVoIPCallRecord,
            (void**)&m_cpCallRecord
            );
        if (m_cpCallRecord == NULL)
        {
            COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Call record is not valid."));   
            ASSERT (FALSE);
        }
        break;
        
    case InfoApp_t::IdOutlookContactDetailsDialog:
        
        piInformation->QueryInterface(
            IID_IContact,
            (void**)&m_cpContact
            );
        if (m_cpContact == NULL)
        {
            COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Contact record is not valid."));   
            ASSERT (FALSE);
        }
        break;
        
    case InfoApp_t::IdGalContactDetailsDialog:
        
        piInformation->QueryInterface(
            IID_IExchangeClientGALSearchInformation,
            (void**)&m_cpGalInfo
            );
        if (m_cpGalInfo == NULL)
        {
            COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Gal record is not valid."));   
            ASSERT (FALSE);
        }
        break;

    default:        
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Scrren Id is not valid."));   
        ASSERT (FALSE);
    }    
}

CallDetailsDialog_t::~CallDetailsDialog_t()
{
}

/*------------------------------------------------------------------------------
    CreateDialogScreen
    
    Create call details dialog screen.
------------------------------------------------------------------------------*/
HRESULT
CallDetailsDialog_t::CreateDialogScreen()
{
    UINT   DialogId;
    UINT   TitleResourceId; 
    
    switch (m_ScreenId) 
    {
    case InfoApp_t::IdOutgoingCallDetailsDialog:
        DialogId        = PHINFO_OUTGOING_CALL_DETAILS_SCREEN_ID;
        TitleResourceId = IDS_TITLE_OUTGOINGDETAILS;
        break;        
        
    case InfoApp_t::IdIncomingCallDetailsDialog:
        DialogId        = PHINFO_INCOMING_CALL_DETAILS_SCREEN_ID; 
        TitleResourceId = IDS_TITLE_INCOMINGDETAILS;    
        break;
        
    case InfoApp_t::IdMissedCallDetailsDialog:
        DialogId        = PHINFO_MISSED_CALL_DETAILS_SCREEN_ID;   
        TitleResourceId = IDS_TITLE_MISSEDDETAILS;
        break;

    case InfoApp_t::IdOutlookContactDetailsDialog:
        DialogId        = PHINFO_OUTLOOK_CONTACT_DETAILS_SCREEN_ID;
        TitleResourceId = IDS_TITLE_CONTACTDETAILS;
        break;

    case InfoApp_t::IdGalContactDetailsDialog:
        DialogId        = PHINFO_GAL_CONTACT_DETAILS_SCREEN_ID;     
        TitleResourceId = IDS_TITLE_GALDETAILS;
        break;

    default:
        ASSERT(FALSE);
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Scrren Id is not valid."));
        return E_FAIL;
    }

    HRESULT hr = DialogScreen_t::CreateDialogScreen(
        DialogId, 
        IDMB_CALLDETAILS_BUTTONS, 
        CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, TitleResourceId), 
        CommonUtilities_t::LoadString(GlobalData_t::s_ModuleInstance, IDS_STATUS_HELP_DETAILSVIEW)
        );
    if (FAILED(hr))
    {
        return hr;
    }
    
    return Enter();  
}


/*------------------------------------------------------------------------------
    ConvertEmailAddressToAliasAndDomain
    
    Helper function used to aid in GAL lookup by contacts. The scenario is:

    1) Contact has email address: contact@domain.extension.server.com. 
    2) Perform a GAL search by alias for "contact" (the beginning of the email addr)
    3) If we get results we need to verify that both:
            The ALIAS (contact) matches
            and the server matches (server.com)

    E.g. joe@microsoft.com matches joe@windows.microsoft.com BUT not joe@othercompany.com

    This function parses the address into alias and domain.com portion by NULL-terminating
    the alias substring, and filling in a pointer to the domain.com portaion
        
    Parameters:
        wszAddress: The address 
        ppwchDomainDotCom: Pointer to the substring containing the domain.com portion
    
    Returns (BOOL): indicating whether we could get the alias and domain.com or not
------------------------------------------------------------------------------*/
BOOL ConvertEmailAddressToAliasAndDomain(
    WCHAR*  pAddress, 
    WCHAR** ppDomainDotCom
    )
{
    PREFAST_ASSERT(pAddress && ppDomainDotCom);

    *ppDomainDotCom = NULL;

    WCHAR *pAt     = NULL; 
    WCHAR *pBefore = NULL;
    WCHAR *pDot    = NULL;
    WCHAR *pNext   = NULL;

    //first search for alias (to ensure valid email addr)          
    pAt = wcschr(pAddress, L'@');
    if (!pAt)
    {
        return FALSE;
    }

    *pAt = 0;
    pAt++;

    //return the pointer to the string after the '@' and all '.'s EXCEPT the last '.'
    pBefore = pAt;
    pDot    = wcschr(pBefore, L'.');
    if (!pDot)
    {
        return FALSE;
    }

    do
    {
        pNext = wcschr(pDot+1, L'.');
        if (pNext)
        {
            pBefore = pDot+1;
            pDot    = pNext;
        }
    } 
    while (pNext);

    *ppDomainDotCom = pBefore;
    return TRUE;
}

/*------------------------------------------------------------------------------
    FormatContactsEmailAddress
    
    Email addresses that come back from contacts usually come back in 2 parts:
        "quoted email address" 
        < pretty name > (with html markup &lt for <)

    This helper function sets a pointer to the beginning of the email address, and
    null-terminates the address as well. 

    For example: "some_address@microsoft.com" &lt SOME_ADDRESS LDAP INFO, Last name, First Name &rt
    is returned as a pointer to some_address\0
    
    Parameters:
        : **ppwchStart - OUT will receive a pointer to the first valid char (after quotation)
        : wszEmailBuf - IN/OUT the buffer containing the email address - will insert
                        a NULL-character in the necessary place
    
    Returns (BOOL): TRUE if the format was successful
------------------------------------------------------------------------------*/
BOOL FormatContactsEmailAddress(
    WCHAR** ppStart,
    WCHAR*  pEmail
    )
{
    PREFAST_ASSERT(ppStart && pEmail);

    *ppStart = pEmail;
    
    WCHAR *pQuote = wcschr(pEmail, L'\"');
    if (!pQuote)
    {
        return FALSE;
    }

    *ppStart = pQuote+1;

    pQuote = wcschr(*ppStart, L'\"');
    if (!pQuote)
    {
        return FALSE;
    }

    *pQuote = 0;
    return TRUE;
}

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::Enter
    
    Enters the details state
    
    Returns (HRESULT): Indicating success or failure
------------------------------------------------------------------------------*/
HRESULT CallDetailsDialog_t::Enter()
{   
    //
    //  Make sure we were created properly
    //
    if (m_cpContact == NULL && m_cpGalInfo == NULL && m_cpCallRecord == NULL)
    {
        ASSERT(FALSE);
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Record (Call Details/GAL/Poom) is NULL."));   
        return E_POINTER;
    }

    //
    //  if we have no contact - but we do have some GAL information, 
    //  we might be able to find the contact by matching phone numbers
    //
    HRESULT hr = S_OK; 
    if (m_cpContact == NULL)
    {
        TryToGetContactInfo();
    }
    
    //
    //  try to get GAL information or FB
    //
    if (SUCCEEDED(hr))
    {
        hr = StartChildRequests();
    }

    //
    //  refresh the display
    //
    if (SUCCEEDED(hr))
    {
        hr = Refresh();
    }
    return hr;
}

/*------------------------------------------------------------------------------
    CallDetailsDialog_t::TryToGetContactInfo
    
    Try to match a contact
    
    Returns (HRESULT): indicating success or failure
------------------------------------------------------------------------------*/
HRESULT CallDetailsDialog_t::TryToGetContactInfo()
{ 
    
    WCHAR   GalPhone[100] = L"";
    Poom_t* pPoom         = NULL;
    HRESULT hr            = S_OK;

    ce::auto_bstr         Uri;    
    CComPtr<IPOutlookApp> cpOutlookApp;        

    //
    //  There are 2 ways to match a contact
    //  (1) - If we have a call record, try to match the URI to a contact
    //  (2) - If we have GAL results, try to match the phone number to the contact
    //
    if (m_cpCallRecord != NULL)
    {
        //get the URI
        hr = m_cpCallRecord->get_URI(
            &Uri
            );

        if (FAILED(hr))
        {
            goto exit;
        }
    }
    else
    {
        //We must have some GAL information
        ASSERT(m_cpGalInfo != NULL);

        //get the phone number
        hr = m_cpGalInfo->GetPhoneNumber(
            GalPhone, 
            _countof(GalPhone)
            );
    
        if (FAILED(hr) || !GalPhone[0])
        {
            goto exit;
        }
        
        Uri = SysAllocString(
            GalPhone
            );
        if (Uri == NULL)
        {
            hr = E_OUTOFMEMORY;
            goto exit;
        }        
    }
    
    //
    //  Try Find the contact by the URI, ignore all errors.
    //    
    hr = PhInfoGlobalData_t::pPhInfoApp->GetOutlookApp(
        &cpOutlookApp
        );
    if (FAILED(hr))
    {
        goto exit;
    }
    pPoom = new Poom_t(cpOutlookApp);
    if (pPoom == NULL)
    {
        hr = E_OUTOFMEMORY;
        goto exit;
    }
    
    hr = pPoom->GetContactInformation (
        Uri, 
        &m_cpContact
        );
    if (FAILED(hr))
    {
        goto exit;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -