📄 chworld.cpp
字号:
ChCore* pCore = GetCore();
ChWorldList worldList;
ASSERT( GetWorldInfo() );
worldList.Add( *GetWorldInfo() );
worldList.Store();
#if defined( CH_MSW )
{ // Put up a status message
string strFormat;
string strStatus;
LOADSTRING( IDS_STATUS_WORLD_ADDED, strFormat );
strStatus.Format( strFormat, (const char*)GetWorldInfo()->GetName() );
pCore->DisplayStatus( strStatus );
}
#endif // defined( CH_MSW )
}
void ChWorldMainInfo::CreateShortcut()
{
ChWorldInfo info( string("") );
info.CreateShortcut( GetCore() );
}
void ChWorldMainInfo::CreateCurrentWorldShortcut()
{
ASSERT( GetWorldInfo() );
GetWorldInfo()->CreateShortcut( GetCore() );
}
bool ChWorldMainInfo::GetPersonalWorldList()
{
ChWorldList worldList;
ChPosition pos;
string strText;
bool boolSuccess;
string strFormat;
SetPersonalList();
// Hide & clear the window
GetTextOutput()->Show( false );
GetTextOutput()->Clear();
SetDisplayChanged( false );
// Display the title
LOADSTRING( IDS_PERSONAL_LIST_TITLE, strText );
GetTextOutput()->Add( strText );
if (!GetHomePage().IsEmpty())
{
LOADSTRING( IDS_PERSONAL_LIST_PREFETCH, strFormat );
strText.Format( strFormat, (const char*)GetHomePage() );
GetTextOutput()->Add( strText );
}
/* Loop through items in world
list, adding one at a time */
pos = worldList.GetHead();
if (pos)
{
string strHomePagePrefix;
string strHomePageSuffix;
boolSuccess = true;
LOADSTRING( IDS_PERSONAL_LIST_HDR, strText );
GetTextOutput()->Add( strText );
AddChacoListJump();
GetTextOutput()->Add( "<ul>" );
LOADSTRING( IDS_PERSONAL_LIST_HOMEPAGE_PREFIX, strHomePagePrefix );
LOADSTRING( IDS_PERSONAL_LIST_HOMEPAGE_SUFFIX, strHomePageSuffix );
while( pos )
{
ChWorldInfo* pInfo = worldList.GetData( pos );
string strWorld;
string strWorldEscaped("This is the \"Real\" thing!");
strText = "<li><a " ATTR_XWORLD "=\"";
pInfo->Stringize( strWorld );
ChUtil::EncodeAttributeString( strWorld, strWorldEscaped );
strText += strWorldEscaped;
strText += "\">";
if (pInfo->GetName().GetLength() > 0)
{
strText += pInfo->GetName();
}
else
{
strText += pInfo->GetAddr();
}
strText += "</a>";
if (!pInfo->GetUsername().IsEmpty())
{
strText += " - " + pInfo->GetUsername();
}
if (!pInfo->GetHomePage().IsEmpty())
{
strText += " " + strHomePagePrefix + pInfo->GetHomePage() +
strHomePageSuffix;
}
if (pInfo->GetDesc().GetLength() > 0)
{
strText += "<p>";
strText += pInfo->GetDesc();
strText += "</p>";
}
GetTextOutput()->Add( strText );
worldList.GetNext( pos );
}
GetTextOutput()->Add( "</ul>" );
}
else
{
boolSuccess = false;
LOADSTRING( IDS_PERSONAL_LIST_EMPTY, strText );
GetTextOutput()->Add( strText );
AddChacoListJump();
}
GetTextOutput()->Show();
return boolSuccess;
}
void ChWorldMainInfo::EditPersonalWorldList()
{
#if defined( CH_MSW )
{ // Load and execute the dialog
ChWorldListDlg worldListDlg( GetCore(), IsConnected() );
chint16 sResult;
sResult = worldListDlg.DoModal();
switch( sResult )
{
case IDOK:
{
break;
}
case IDC_LIST_CONNECT:
{
ChWorldInfo info( worldListDlg.GetName(),
worldListDlg.GetDesc(),
worldListDlg.GetHost(),
worldListDlg.GetPort(),
worldListDlg.GetType(),
worldListDlg.GetLoginType(),
worldListDlg.GetUsername(),
worldListDlg.GetPassword(),
worldListDlg.GetHomePage() );
Connect( info );
break;
}
case IDCANCEL:
{ // Do nothing
break;
}
}
if (IsPersonalList() && (sResult != IDCANCEL) && !IsConnected())
{
/* Redisplay the personal list as
it may have changed */
GetPersonalWorldList();
}
}
#else // defined( CH_MSW )
{
cerr << "XXX: " << __FILE__ << ":" << __LINE__ << endl;
}
#endif // defined( CH_MSW )
}
void ChWorldMainInfo::DoPreviousURL()
{
string* pstrTail;
ASSERT( m_urlList.GetCount() > 0 );
/* Remove the tail URL (which is
the current one) */
pstrTail = (string*)m_urlList.GetTail();
m_urlList.RemoveTail();
// Free the item
delete pstrTail;
ASSERT( m_urlList.GetCount() > 0 );
/* Make the last URL the new bottom
most page */
pstrTail = (string*)m_urlList.GetTail();
DoJump( *pstrTail, "", true, false );
}
void ChWorldMainInfo::SetEchoPrefs( bool boolEcho, bool boolBold,
bool boolItalic )
{
ChWorldConn* pConn = GetWorldConnection();
if (pConn)
{
pConn->SetEchoPrefs( boolEcho, boolBold, boolItalic );
}
}
bool ChWorldMainInfo::LookForPuebloEnhanced( const string& strLine,
ChVersion& versEnhanced )
{
/* We want to find the first string
followed by a version and then
the second string */
const char* pstrFirstPart = PUEBLO_ENHANCED_PART_1;
const char* pstrSecondPart = PUEBLO_ENHANCED_PART_2;
string strSearch( strLine );
int iFirst;
bool boolFound = false;
// Search case-insensitive
strSearch.MakeLower();
do
{ // Look for the first string
iFirst = strSearch.Find( pstrFirstPart );
if (-1 != iFirst)
{
int iSecond;
string strRest;
/* First part found, so look for
the second part */
strRest = strSearch.Mid( iFirst + strlen( pstrFirstPart ) );
iSecond = strRest.Find( pstrSecondPart );
if (-1 != iSecond)
{ /* Second part found, look between
them for the version number */
const char* pstrScan;
chint16 sMajor = 0;
chint16 sMinor = 0;
int iDigits = 0;
strRest = strRest.Left( iSecond );
#if defined( CH_ARCH_16 )
{
TrimLeft( strRest );
TrimRight( strRest );
}
#else // defined( CH_ARCH_16 )
{
strRest.TrimLeft();
strRest.TrimRight();
}
#endif // defined( CH_ARCH_16 )
// Look for digits in form #.#
pstrScan = strRest;
while (isdigit( *pstrScan ))
{
sMajor = (sMajor * 10) + (*pstrScan - '0');
pstrScan++;
iDigits++;
}
if (iDigits)
{ /* There must be at least one
digit in the major version
number */
if ('.' == *pstrScan)
{ /* Found the decimal... Now get
the second part of the
version */
pstrScan++;
while (isdigit( *pstrScan ))
{
sMinor = (sMinor * 10) + (*pstrScan - '0');
pstrScan++;
}
/* Purity check -- make sure these
minor digits are the last
things we find */
if (0 == *pstrScan)
{ // Yes!
versEnhanced = ChVersion( sMajor, sMinor );
boolFound = true;
}
}
else if (0 == *pstrScan)
{ // Only major version number found
versEnhanced = ChVersion( sMajor, 0 );
boolFound = true;
}
// Illegal version format... ignore
}
}
if ((-1 != iFirst) && !boolFound)
{ /* We found the wrong first string.
Start again after this
string. */
strSearch = strSearch.Mid( iFirst + strlen( pstrFirstPart ) );
}
}
}
while ((-1 != iFirst) && !boolFound);
if (boolFound)
{ /* Perform out Pueblo Enhanced
processing */
OnPuebloEnhanced( versEnhanced );
}
return boolFound;
}
void ChWorldMainInfo::UpdatePreferences()
{
ChRegistry worldPrefsReg( WORLD_PREFS_GROUP );
// Read values from registry
worldPrefsReg.ReadBool( WORLD_PREFS_PAUSE_DISCONNECT,
m_boolPauseOnDisconnect, true );
worldPrefsReg.ReadBool( WORLD_PREFS_NOTIFY, m_boolNotify, true );
worldPrefsReg.ReadBool( WORLD_PREFS_NOTIFY_ALERT, m_boolNotifyAlert,
false );
worldPrefsReg.Read( WORLD_PREFS_NOTIFY_STR, m_strNotifyMatch, "" );
if (GetTextInput())
{
GetTextInput()->UpdatePreferences();
}
if (GetWorldConnection())
{
GetWorldConnection()->UpdatePreferences();
}
}
void ChWorldMainInfo::SetFocusTarget( FocusTarget target,
bool boolGainingFocus )
{
if ((GetFocusTarget() == target) && !boolGainingFocus)
{
// We're losing the focus
m_focusTarget = focusNone;
#if !defined( CH_PUEBLO_PLUGIN )
if (m_boolMenusInstalled)
{ // Demote ourselves
GetEditMenu()->Promote( false );
}
#endif
}
else if (boolGainingFocus)
{ // New target has the focus
ASSERT( focusNone != target );
m_focusTarget = target;
#if !defined( CH_PUEBLO_PLUGIN )
if (m_boolMenusInstalled)
{ /* Promote ourselves (we want to
get the Cut/Copy/Paste menu
messages first) */
GetEditMenu()->Promote();
}
#endif
}
}
bool ChWorldMainInfo::WantTextLines()
{
bool boolWantLines;
boolWantLines = GetCore()->GetFrameWnd()->IsIconic() &&
(GetNotify() || GetNotifyAlert());
boolWantLines = boolWantLines ||
(GetTinTin()->IsActionsDefined() &&
!GetTinTin()->IsIgnore());
return boolWantLines;
}
void ChWorldMainInfo::OnTextLine( const string& strLine )
{
/* If the user wants notification,
then check to see if it's
appropriate */
if (GetNotify() || GetNotifyAlert())
{
LookForNotify( strLine );
}
if (!GetTinTin()->IsIgnore())
{
GetTinTin()->CheckActions( strLine );
}
}
void ChWorldMainInfo::LookForNotify( const string& strLine ) const
{
ChCore* pCore = GetCore();
bool boolIconic;
#if defined( CH_MSW )
{
boolIconic = pCore->GetFrameWnd()->IsIconic();
}
#else // defined( CH_MSW )
{
TRACE( "ChWorldMainInfo::LookForNotify : "
"Need to confirm if app is iconic" );
boolIconic = false;
}
#endif // defined( CH_MSW )
if (boolIconic && !pCore->IsFlashWindow())
{
/* Do this only if we haven't
already notified the user */
bool boolMatch;
string strMatch = GetNotifyMatch();
if (strMatch.IsEmpty())
{
boolMatch = true;
}
else
{
string strTest( strLine );
strTest.MakeLower();
boolMatch = (strTest.Find( strMatch ) >= 0);
}
if (boolMatch)
{
if (GetNotify())
{
pCore->EnableFlashWindow();
}
if (GetNotifyAlert())
{
if (GetSoundID())
{
ChMsg doAlert( CH_MSG_SOUND_ALERT );
NotifySound( doAlert );
}
}
}
}
}
void ChWorldMainInfo::SetEchoState( EchoState newState, bool boolPreserve )
{
EchoState oldEchoState = GetEchoState();
if (oldEchoState != newState)
{
m_echoState = newState;
GetTextInput()->SetEcho( (echoOn == m_echoState), boolPreserve );
}
}
/*----------------------------------------------------------------------------
ChWorldMainInfo protected methods
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
ChWorldMainInfo::OnWorldConnect
This method is called after the first data is recieved from the
destination world, confirming the connection is two-way.
----------------------------------------------------------------------------*/
void ChWorldMainInfo::OnWorldConnect()
{
string strText;
string strStatusFmt;
string strStatus;
string strOnLine;
ChWorldInfo* pWorldInfo = GetWorldInfo();
#if !defined( CH_PUEBLO_PLUGIN )
ChMenuItem* pItem;
#endif
ASSERT( 0 != pWorldInfo );
// Turn on echo
SetEchoState( echoOn );
// Show the 'text in' window
GetTextInput()->Show();
GetTextInput()->Clear();
/* Clear the text out window
and set it to auto-scroll.
Also set the default buffer
limit. */
GetTextOutput()->Clear();
GetTextOutput()->SetAutoScroll();
GetTextOutput()->SetBufferLimit();
SetDisplayChanged();
// Enable the disconnect command
#if !defined( CH_PUEBLO_PLUGIN )
LOADSTRING( IDS_MENU_WORLD_DISCON, strText );
if (pItem = GetWorldMenu()->FindItem( strText ))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -