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

📄 calllistdialog.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    void
    )
{
    //
    //  Read the Call Record Item that is selected.
    //
    HRESULT          hr;
    CComPtr<IVoIPCallRecord> cpCallRecord;
    hr = GetSelectedCallRecord(&cpCallRecord);    
    if (FAILED(hr))
    {
        return hr;
    }    

    PH_MAKEPHONECALL_PARAMETERS Parameters = {0};
    Parameters.StructSize = sizeof(Parameters);
    
    ce::auto_bstr URI = NULL;

    if (!cpCallRecord)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    //
    //  Get the phone number from the call record.
    //
    hr = cpCallRecord->get_URI(&URI);
    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to get URI from call record. hr = 0x%x", hr));   
        return hr;
    }    
    if (URI == NULL || URI[0] == 0)
    {
        return E_FAIL;
    }
    
    StringCchCopy(
        Parameters.DestAddress,
        _countof(Parameters.DestAddress),
        URI
        );

    //
    //  Get the name from the call record, ignore errors.
    //
    ce::auto_bstr Name = NULL;
    hr = cpCallRecord->get_FriendlyName(&Name);
    if (SUCCEEDED(hr) && Name != NULL && Name[0] != 0)
    {
        StringCchCopy(
            Parameters.CalledParty,
            _countof(Parameters.CalledParty),
            Name
            );
    }
    return PHMakePhoneCall(&Parameters);
}

HRESULT
CallListDialog_t::OnBlock(
    void
    )
{
    CloseCurrentMessageBox();
    
    PH_MESSAGE_BOX_PARAMETERS   Params = {0};

    Params.Flags    = VDF_TYPE_MODELESS;
    Params.Instance = GlobalData_t::s_ModuleInstance;
    Params.IconId   = IDB_CONFIRMDELETE;
    Params.MenuId   = IDMB_YESNO;
    Params.Owner    = m_Dialog;
    Params.pText    = CommonUtilities_t::LoadString(
                        GlobalData_t::s_ModuleInstance, 
                        IDS_LABEL_CONFIRMBLOCK_QUESTION
                        );    
    Params.pTitle   = CommonUtilities_t::LoadString(
                        GlobalData_t::s_ModuleInstance, 
                        IDS_TITLE_CONFIRM_BLOCK
                        );
    Params.StructSize = sizeof(Params);

    if (! PHMessageBox(&Params))
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    m_MessageBox      = Params.result.Dialog;
    m_PendingQuestion = QuestionBlockCaller;
    
    return S_OK; 
}

HRESULT
CallListDialog_t::OnDeleteAll()
{
    CloseCurrentMessageBox();

    UINT ItemCount = m_Listbox.GetCount();

    WCHAR   Question[MAX_PATH] = L"";

    StringCchPrintf(
        Question, 
        _countof(Question),
        CommonUtilities_t::LoadString(
            GlobalData_t::s_ModuleInstance, IDS_FMT_CONFIRMDELETEALL_QUESTION
            ),
        ItemCount
        );

    if (! Question[0])
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    PH_MESSAGE_BOX_PARAMETERS   Params = {0};

    Params.Flags    = VDF_TYPE_MODELESS;
    Params.Instance = GlobalData_t::s_ModuleInstance;
    Params.IconId   = IDB_CONFIRMDELETE;
    Params.MenuId   = IDMB_YESNO;
    Params.Owner    = m_Dialog;
    Params.pText    = Question;
    Params.pTitle   = CommonUtilities_t::LoadString(
                        GlobalData_t::s_ModuleInstance, 
                        IDS_TITLE_CONFIRM_DELETE
                        );
    Params.StructSize = sizeof(Params);

    if (! PHMessageBox(&Params))
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    m_MessageBox      = Params.result.Dialog;
    m_PendingQuestion = QuestionDeleteAll;

    return S_OK; 
}

/*------------------------------------------------------------------------------
    OnCallLogEntryDetails 
    
    Display call details.
------------------------------------------------------------------------------*/
HRESULT
CallListDialog_t::OnCallLogEntryDetails(
    void
    )
{
    //
    //  Read the Call Record Item that is selected.
    //
    HRESULT                  hr;
    CComPtr<IVoIPCallRecord> cpCallRecord;
    hr = GetSelectedCallRecord(&cpCallRecord);    
    if (FAILED(hr))
    {
        return hr;
    }    


    InfoApp_t::ScreenId CallDetailsScreenId = GetCallDetailsScreenId ();
    if (CallDetailsScreenId == InfoApp_t::IdLast) 
    {
        return E_FAIL;
    }    

    return PhInfoGlobalData_t::pPhInfoApp->CreateDetailsScreen(
        CallDetailsScreenId,
        cpCallRecord
        );

    return S_OK;
}

InfoApp_t::ScreenId 
CallListDialog_t::GetCallDetailsScreenId (
    void
    )
{
    switch (m_ScreenId)
    {
    case InfoApp_t::IdOutgoingCallsListDialog:
        return InfoApp_t::IdOutgoingCallDetailsDialog;
                    
    case InfoApp_t::IdIncomingCallsListDialog:
        return InfoApp_t::IdIncomingCallDetailsDialog;
                    
    case InfoApp_t::IdMissedCallsListDialog:
        return InfoApp_t::IdMissedCallDetailsDialog;
    }

    ASSERT (FALSE);
    return InfoApp_t::IdLast;
}


BOOL
CallListDialog_t::OnCommand(
    WPARAM wParam
    )
{
    switch(HIWORD(wParam))
    {        
    case LBN_SELCHANGE:
        return SUCCEEDED(OnSelectionChange());        

    case 0:
        switch (LOWORD(wParam)) 
        {
        case IDC_DETAILS:
            return SUCCEEDED(OnCallLogEntryDetails()); 
            
        case IDC_DELETE :
            return SUCCEEDED(OnDelete());

        case IDC_DELETEALL:
            return SUCCEEDED(OnDeleteAll());
            
        case IDC_BLOCK  :
            return SUCCEEDED(OnBlock());
            
        case IDC_DIAL   :                
            return SUCCEEDED(OnDial());
                
        case IDOK:   
        case IDCANCEL:
            return SUCCEEDED(PhInfoGlobalData_t::pPhInfoApp->GoBackToPreviousScreen ()); 
        }    
    }
    return FALSE;
}

/*------------------------------------------------------------------------------
    CallListDialog_t::OnSelectionChange
    
    Handle the selection changing in the listbox. 
    If a caller is already blocked, gray out the block button.
------------------------------------------------------------------------------*/
HRESULT
CallListDialog_t::OnSelectionChange(
    void
    )
{
 
    if (m_CurrentMenuId != IDMB_CALLLOGLIST_BUTTONS)    
    {
        return S_FALSE;
    }
    
    BOOL                           ShowBlockButton;
    VARIANT_BOOL                   IsCallerBlocked;
    CComPtr<IVoIPCallerInfoRecord> cpCallerInfoRecord; 
    
    //
    //  Find the caller info record in the DB. 
    //  Don't create a new one if one doesn't exist.
    //
    HRESULT hr = GetCallerInfoFromSelectedCallRecord (
        &cpCallerInfoRecord,
        false
        );
    if (FAILED(hr) || cpCallerInfoRecord == NULL)
    {
        ShowBlockButton = TRUE;
        goto exit;
    }

    //
    //  Check if the caller is blocked.
    //
    hr = cpCallerInfoRecord->get_Blocked (
        &IsCallerBlocked
        );
    
    if (SUCCEEDED(hr) && IsCallerBlocked == VARIANT_TRUE)
    {
        ShowBlockButton = FALSE;
    }
    else
    {
        ShowBlockButton = TRUE;
    }   

exit:
    return m_MenuBar.EnableMenuItem(
        IDC_BLOCK, 
        ShowBlockButton
        );
}

/*------------------------------------------------------------------------------
    CallListDialog_t::OnNotify
    
    Handle a notification from one of our message boxes. 
------------------------------------------------------------------------------*/
HRESULT
CallListDialog_t::OnNotify(
    WPARAM wParam, 
    LPARAM lParam
    )
{

    //we only care about NOTIFY when we are waiting for a delete confirmation
    NMHDR* pNmHdr = reinterpret_cast<NMHDR*>(lParam);
    if (! pNmHdr)
    {
        ASSERT(FALSE);
        return E_FAIL;
    }

    if (m_MessageBox == NULL)
    {
        return S_FALSE;
    }

    //validate the return value...
    switch (LOWORD(wParam))
    {
    case IDC_CONFIRMDELETE_YES:
    case IDC_CONFIRMDELETE_NO:
    case IDCANCEL:
        break;

    default:
        //unknown, ignore this...
        return S_FALSE;
    }

    QuestionType_e  Type = m_PendingQuestion;

    //close the pending message box
    CloseCurrentMessageBox();
    
    //if the user didn't say "Yes" we can ignore this event
    if (LOWORD(wParam) != IDC_CONFIRMDELETE_YES)
    {
        return S_OK;
    }

    switch (Type)
    {
    case QuestionBlockCaller:
        return BlockCaller();

    case QuestionDeleteAll:
        return ClearCallLog();

    default:
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }
}

/*------------------------------------------------------------------------------
    CallListDialog_t::BlockCaller
    
    Block the selected caller by adding them to the blocked list in the
    info DB
------------------------------------------------------------------------------*/
HRESULT
CallListDialog_t::BlockCaller()
{
    //
    //  Find the caller info record in the DB.
    //  Create a new one if one doesn't exist in the DB,
    //
    CComPtr<IVoIPCallerInfoRecord> cpCallerInfoRecord; 
    HRESULT hr = GetCallerInfoFromSelectedCallRecord (
        &cpCallerInfoRecord,
        true
        );
    if (FAILED(hr))
    {
        return hr; 
    }
    if (cpCallerInfoRecord == NULL)
    {
        return E_FAIL;
    }

    hr = cpCallerInfoRecord->put_Blocked(VARIANT_TRUE); 
    if (FAILED(hr))
    {
        return hr;
    }
    
    return cpCallerInfoRecord->Commit(); 
}

/*------------------------------------------------------------------------------
    CallListDialog_t::GetCallerInfoFromSelectedCallRecord
    
        Gets the caller info record that corresponds to the call record selected
        in the list box.
        
        If CreateNewRecord flag is set to new, a caller info record is created if 
        one is not already present in the DB.
    
    Parameters:
        ppCallerInfoRecord: Pointer to the caller info record.
        CreateNewRecord:    Flag that specifies if a new record should be created 
                            if one is not already present.
    
    Returns (HRESULT): indicating success or failure of the call.
------------------------------------------------------------------------------*/
HRESULT
CallListDialog_t::GetCallerInfoFromSelectedCallRecord(
    IVoIPCallerInfoRecord** ppCallerInfoRecord,
    bool                    CreateNewRecord
    )
{
    if (ppCallerInfoRecord == NULL)
    {
        return E_INVALIDARG;
    }
    *ppCallerInfoRecord = NULL;

    //        
    //  Get the selected call record 
    //
    CComPtr<IVoIPCallRecord> cpCallRecord;
    HRESULT hr = GetSelectedCallRecord(
        &cpCallRecord
        );    
    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to get URI from call record. hr = 0x%x", hr));   
        return hr; 
    }

    //
    // Retrieve the Uri
    //
    ce::auto_bstr FriendlyNumber; 
    hr = cpCallRecord->get_URI(
        &FriendlyNumber
        );
    if (FAILED(hr))
    {
        return hr; 
    }

    //
    // Open the caller info database if required.
    //
    if (m_cpCallerInfoDB == NULL)
    {
        hr = PhInfoGlobalData_t::pPhInfoApp->GetCallerInfoDB(
            &m_cpCallerInfoDB
            );
        if (FAILED (hr))
        {
            COMMON_DEBUGMSG(ZONE_PHINFO_ERROR, (L"Unable to create call record in the caller info DB. hr = 0x%x", hr));   
            return hr; 
        }
        if (m_cpCallerInfoDB == NULL)
        {
            return E_FAIL; 
        }
    }

    //
    // Find the caller info record by Uri
    //
    hr = m_cpCallerInfoDB->FindCallerInfoByURI(
        FriendlyNumber, 
        ppCallerInfoRecord
        ); 

    //
    //  the user didn't request to create a new one, return right here.
    //
    if (CreateNewRecord == false)
    {
        return hr;
    }

    //
    //  If the caller info is not in the DB, create a new one.
    //
    if (hr == VOIP_E_RECORDNOTINDB)
    {
        hr = m_cpCallerInfoDB->CreateRecord(
            ppCallerInfoRecord
            );         
        if (FAILED(hr))
        {
            return hr; 
        }
        hr = CopyInfoFromCallRecordToCallerInfoRecord(
            cpCallRecord, 
            *ppCallerInfoRecord
            );         
    }
    return hr;
}
    
/*------------------------------------------------------------------------------
    CallListDialog_t::ClearCallLog
    
    Delete all the entries from the DB and refresh the screen
------------------------------------------------------------------------------*/
HRESULT
CallListDialog_t::ClearCallLog()
{
    if (! m_cpEnum)
    {
        ASSERT(FALSE);
        return E_UNEXPECTED;
    }

    CComPtr<IVoIPCallRecord>    cpRecord;

    HRESULT hr = m_cpEnum->Reset();
    if (FAILED(hr))
    {
        COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Call log DB enumerator reset failed. hr = 0x%x", hr));
    }

    while (m_cpEnum->Next(1, &cpRecord, NULL) == S_OK)
    {
        hr = cpRecord->DeleteFromDB();
        if (FAILED(hr))
        {
            COMMON_DEBUGMSG(ZONE_PHINFO_WARNING, (L"Unable to delete the call record from DB. hr = 0x%x", hr));
        }
        cpRecord = NULL;
    }

    PostMessage(
        m_Dialog, 
        WM_SCREEN_REFRESH, 
        0, 
        0
        );
    return S_OK;
}

⌨️ 快捷键说明

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