chxavmessagedialog.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 364 行
CPP
364 行
/*****************************************************************************
* chxavmessagedialog.cpp
* ----------------------
*
* Synopsis:
* Contains the declaration of the CHXAvMessageDialog. It's used to encapsulate
* nicely the diffent dialogs and warning boxes, requiring input or yes/no/cancel.
*
* Target:
* Symbian OS
*
*
* (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
*
*****************************************************************************/
// Symbian includes...
#include <eikdialg.h>
#include <aknglobalnote.h>
#include <aknnotedialog.h>
#include <aknnotewrappers.h>
#include <aknquerydialog.h>
#include <errorui.h>
#include <aknprogressdialog.h>
#include <aknmessagequerydialog.h>
// Helix includes...
#include "hxstring.h"
#include "hlxosstr.h"
// Includes from this project...
#include "chxavmisc.h"
#include "chxavfileutil.h"
#include "chxavcleanstring.h"
#include "chxavmessagedialog.h"
#include "chxavcleanupstack.h"
#include "chxavmessagedialog.h"
#include "realplayer.rsg"
#include "realplayer.hrh"
#include "chxavutil.h"
// Local functions...
namespace
{
void SetInfoCbaHelper(CEikDialog* pDlg, CHXAvMessageDialog::InfoPromptType type)
{
// possibly reset cba
CEikButtonGroupContainer& cba = pDlg->ButtonGroupContainer();
switch(type)
{
case CHXAvMessageDialog::PromptOk:
// use our own so ok is on right side like others
cba.SetCommandSetL(R_AVP_SOFTKEYS_OK);
break;
case CHXAvMessageDialog::PromptCancel:
cba.SetCommandSetL(R_AVKON_SOFTKEYS_CANCEL);
break;
case CHXAvMessageDialog::PromptBack:
cba.SetCommandSetL(R_AVKON_SOFTKEYS_BACK);
break;
case CHXAvMessageDialog::PromptClose:
cba.SetCommandSetL(R_AVKON_SOFTKEYS_CLOSE);
break;
}
}
void DoAlertHelperLD(CAknResourceNoteDialog* pDlg,
const TDesC& text,
CAknNoteDialog::TTimeout timeout,
CAknNoteDialog::TTone tone)
{
pDlg->SetTimeout(timeout);
pDlg->SetTone(tone);
pDlg->ExecuteLD(text);
}
} // locals
template<typename BaseClass>
void CHXAvNoteWrapper<BaseClass>::PostLayoutDynInitL()
{
BaseClass::PostLayoutDynInitL();
if(m_bAddCloseButton)
{
// show close button so user knows he can cancel
SetInfoCbaHelper(this, CHXAvMessageDialog::PromptClose);
}
}
void CHXAvMessageDialog::DoAlertConfirmL(const TDesC& text,
bool bModal,
CAknNoteDialog::TTimeout timeout,
CAknNoteDialog::TTone tone)
{
CAknConfirmationNote* pDlg = new (ELeave) CHXAvNoteWrapper<CAknConfirmationNote>(bModal, CAknNoteDialog::ENoTimeout == timeout);
DoAlertHelperLD(pDlg, text, timeout, tone);
}
HBufC* CHXAvMessageDialog::DoQueryTextL(const TDesC& prompt, const TDesC& defaultText, TUint cchMax)
{
HBufC* pBuff = HBufC::NewL(cchMax);
AUTO_PUSH_POP(pBuff); // out
//
// this handles case where defaultText > max (i.e., edit box is
// initialized with a string that is longer than what user is supposed
// to be able to enter)
//
TUint cchMaxCopy = min( TUint(defaultText.Length()), cchMax);
// copy default text to appear in edit box
TPtr ptr = pBuff->Des();
ptr.Copy(defaultText.Ptr(), cchMaxCopy);
// in case filename has weird non-printable characters
CHXAvMisc::MakeDisplayFriendly(ptr);
TPtrC ptrPrompt(prompt);
CAknTextQueryDialog* pDlg = new (ELeave) CAknTextQueryDialog(ptr, ptrPrompt);
pDlg->PrepareLC(R_AVP_QUERY_TEXT_DIALOG);
pDlg->SetMaxLength(cchMax);
// default to lower case text entry mode (see AVKON EDWIN CONSTANTS in uikon.hrh)
CAknQueryControl* pQuery = static_cast<CAknQueryControl*>(pDlg->ControlOrNull(EGeneralQuery));
CEikEdwin* pEd = static_cast<CEikEdwin*>(pQuery->ControlByLayoutOrNull(EDataLayout));
pEd->SetAknEditorCase(EAknEditorLowerCase);
TInt res = pDlg->RunLD();
if(0 == res)
{
// user canceled
HX_DELETE(pBuff);
}
// user entered something
return pBuff;
}
////////////////////////////////////////////
//
// ask for a filename (until user supplies a valid
// name or cancels)
//
// return 0 if user cancels
//
TFileName* CHXAvMessageDialog::GetFileNameFromUserL(const TDesC& prompt,
const TDesC& oldName,
TUint32 cchMaxName)
{
HX_ASSERT(cchMaxName <= KMaxFileName);
HX_ASSERT(cchMaxName > 0);
TPtrC ptrPrompt(prompt);
TFileName* pNameOut = new (ELeave) TFileName;
AUTO_PUSH_POP(pNameOut); // out
pNameOut->Copy(oldName);
bool bNeedToPrompt = true;
while(bNeedToPrompt)
{
HBufC* pbuff = CHXAvMessageDialog::DoQueryTextL(ptrPrompt, *pNameOut, cchMaxName);
if( pbuff )
{
AUTO_PUSH_POP_DEL(pbuff);
pNameOut->Copy(*pbuff);
// check that name is valid
CHXAvFile::FileNameValidity validity = CHXAvFile::GetFileNameValidity(*pNameOut);
switch( validity )
{
case CHXAvFile::nvValid:
// good name!
bNeedToPrompt = false;
break;
case CHXAvFile::nvInvalidIllegalChars:
// 'name can't contain certain chars'
DoAlertInfoL(CHXAvCleanString(R_ERR_INVALID_FILENAME_CHARS)());
break;
case CHXAvFile::nvTooLong:
// user should be prevented from entering this via cchMaxName above
HX_ASSERT(false);
// fall through...
case CHXAvFile::nvInvalidDots:
default:
// 'unsuitable filename'
DoAlertInfoL(CHXAvCleanString(R_ERR_INVALID_FILENAME_BAD)());
break;
}
}
else
{
// cancel out
HX_DELETE(pNameOut);
bNeedToPrompt = false;
}
}
return pNameOut;
}
void CHXAvMessageDialog::DoAlertErrorL(const TDesC& text,
bool bModal,
CAknNoteDialog::TTimeout timeout,
CAknNoteDialog::TTone tone)
{
CAknErrorNote* pDlg = new (ELeave) CHXAvNoteWrapper<CAknErrorNote>(bModal, CAknNoteDialog::ENoTimeout == timeout);
DoAlertHelperLD(pDlg, text, timeout, tone);
}
////////////////////////////////////////////////
// use this for info text that needs to be scrollable
//
void CHXAvMessageDialog::DoLongTextInfoPromptL(const TDesC& caption, const TDesC& text, InfoPromptType type)
{
TPtrC ptr(text);
CAknMessageQueryDialog* pDlg = CAknMessageQueryDialog::NewL(ptr);
pDlg->PrepareLC(R_AVKON_MESSAGE_QUERY_DIALOG);
// save cleanupstack init until LD
{
AUTO_PUSH_POP(pDlg);
pDlg->MakeLeftSoftkeyVisible(EFalse);
pDlg->QueryHeading()->SetTextL(caption);
SetInfoCbaHelper(pDlg, type);
}
pDlg->RunLD();
}
void CHXAvMessageDialog::DoAlertInfoL(const TDesC& text,
bool bModal,
CAknNoteDialog::TTimeout timeout,
CAknNoteDialog::TTone tone)
{
CAknInformationNote* pDlg = new (ELeave) CHXAvNoteWrapper<CAknInformationNote>(bModal, CAknNoteDialog::ENoTimeout == timeout);
DoAlertHelperLD(pDlg, text, timeout, tone);
}
////////////////////////////////////////////
//
TInt CHXAvMessageDialog::DoGlobalNoteL(TAknGlobalNoteType type, TInt textResID)
{
CHXAvCleanString text(textResID);
return DoGlobalNoteL(type, text());
}
////////////////////////////////////////////
//
TInt CHXAvMessageDialog::DoGlobalNoteL(TAknGlobalNoteType type, const TDesC& text)
{
/*
aknnotifystd.h:
EAknGlobalInformationNote
EAknGlobalWarningNote
EAknGlobalConfirmationNote
EAknGlobalErrorNote
EAknGlobalWaitNote
EAknGlobalPermanentNote
*/
// caller must manage ids and ensure that only one note is be shown at
// a time; epoc debug build panics otherwise
CAknGlobalNote* pNote = CAknGlobalNote::NewL();
AUTO_PUSH_POP_DEL(pNote);
return pNote->ShowNoteL(type, text);
}
////////////////////////////////////////////
// cancel global note associated with given id
//
void CHXAvMessageDialog::CancelGlobalNoteL(TInt idNote)
{
CAknGlobalNote* pNote = CAknGlobalNote::NewL();
AUTO_PUSH_POP_DEL(pNote);
pNote->CancelNoteL(idNote);
}
////////////////////////////////////////////////////////
// show modal; prompt for affirmative or negative
//
bool CHXAvMessageDialog::DoQueryL(TInt textResID, QueryPromptType type, CAknQueryDialog::TTone tone)
{
CHXAvCleanString queryText(textResID);
return DoQueryL(queryText(), type, tone);
}
bool CHXAvMessageDialog::DoQueryL(const TDesC& promptText, QueryPromptType type, CAknQueryDialog::TTone tone)
{
TPtrC ptr(promptText);
CAknQueryDialog* pDlg = new (ELeave) CAknQueryDialog(ptr, tone);
pDlg->PrepareLC(R_AVP_YES_NO_DIALOG);
// save cleanupstack init until LD
{
AUTO_PUSH_POP(pDlg);
// possibly reset cba
CEikButtonGroupContainer& cba = pDlg->ButtonGroupContainer();
switch(type)
{
case QueryYesNo:
// this is default
break;
case QueryOkCancel:
cba.SetCommandSetL(R_AVKON_SOFTKEYS_OK_CANCEL);
break;
case QueryOkBack:
cba.SetCommandSetL(R_AVKON_SOFTKEYS_OK_BACK);
break;
}
}
TInt res = pDlg->RunLD();
return 0 != res;
}
////////////////////////////////////////////////
//
void CHXAvMessageDialog::DoSystemErrorNoteL(TInt err)
{
// use system handler
CCoeEnv* pEnv = CCoeEnv::Static();
CErrorUI* pError = CErrorUI::NewL(*pEnv);
AUTO_PUSH_POP_DEL(pError);
pError->ShowGlobalErrorNoteL(err);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?