Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

CtrlPrivateChatFrame.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlPrivateChatFrame.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "ChatSession.h"
00025 #include "RichElement.h"
00026 #include "Transfers.h"
00027 #include "Uploads.h"
00028 #include "UploadTransfer.h"
00029 #include "CtrlPrivateChatFrame.h"
00030 #include "WndBrowseHost.h"
00031 #include "Skin.h"
00032 #include "Security.h"
00033 
00034 #ifdef _DEBUG
00035 #define new DEBUG_NEW
00036 #undef THIS_FILE
00037 static char THIS_FILE[] = __FILE__;
00038 #endif
00039 
00040 IMPLEMENT_DYNAMIC(CPrivateChatFrame, CChatFrame)
00041 
00042 BEGIN_MESSAGE_MAP(CPrivateChatFrame, CChatFrame)
00043         //{{AFX_MSG_MAP(CPrivateChatFrame)
00044         ON_WM_CREATE()
00045         ON_WM_SIZE()
00046         ON_WM_PAINT()
00047         ON_WM_CONTEXTMENU()
00048         ON_UPDATE_COMMAND_UI(ID_CHAT_BROWSE, OnUpdateChatBrowse)
00049         ON_COMMAND(ID_CHAT_BROWSE, OnChatBrowse)
00050         ON_UPDATE_COMMAND_UI(ID_CHAT_PRIORITY, OnUpdateChatPriority)
00051         ON_COMMAND(ID_CHAT_PRIORITY, OnChatPriority)
00052         //}}AFX_MSG_MAP
00053 END_MESSAGE_MAP()
00054 
00055 #define EDIT_HEIGHT             32
00056 #define TOOLBAR_HEIGHT  30
00057 
00058 
00060 // CPrivateChatFrame construction
00061 
00062 CPrivateChatFrame::CPrivateChatFrame()
00063 {
00064         CRect rc( 0, 0, 0, 0 );
00065         Create( NULL, _T("Chat"), WS_CHILD|WS_CLIPCHILDREN, rc, AfxGetMainWnd(), 100 );
00066 }
00067 
00068 CPrivateChatFrame::~CPrivateChatFrame()
00069 {
00070 }
00071 
00073 // CPrivateChatFrame operations
00074 
00075 void CPrivateChatFrame::Initiate(GGUID* pGUID, SOCKADDR_IN* pHost, BOOL bMustPush)
00076 {
00077         ASSERT( m_pSession == NULL );
00078 
00079         m_pSession = new CChatSession( this );
00080         m_pSession->Setup( pGUID, pHost, bMustPush );
00081 }
00082 
00083 BOOL CPrivateChatFrame::Accept(CChatSession* pSession)
00084 {
00085         if ( m_pSession != NULL )
00086         {
00087                 if ( m_pSession->m_nState > cssConnecting ) return FALSE;
00088                 m_pSession->OnCloseWindow();
00089         }
00090 
00091         m_pSession = pSession;
00092 
00093         return TRUE;
00094 }
00095 
00097 // CPrivateChatFrame message handlers
00098 
00099 int CPrivateChatFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
00100 {
00101         if ( CChatFrame::OnCreate( lpCreateStruct ) == -1 ) return -1;
00102 
00103         OnSkinChange();
00104 
00105         return 0;
00106 }
00107 
00108 void CPrivateChatFrame::OnSkinChange()
00109 {
00110         CChatFrame::OnSkinChange();
00111         Skin.CreateToolBar( _T("CPrivateChatFrame"), &m_wndToolBar );
00112 }
00113 
00114 void CPrivateChatFrame::OnSize(UINT nType, int cx, int cy)
00115 {
00116         CChatFrame::OnSize( nType, cx, cy );
00117 
00118         CRect rc;
00119         GetClientRect( &rc );
00120 
00121         HDWP hDWP = BeginDeferWindowPos( 3 );
00122 
00123         DeferWindowPos( hDWP, m_wndView, NULL, rc.left, rc.top,
00124                 rc.Width(), rc.Height() - TOOLBAR_HEIGHT - EDIT_HEIGHT, SWP_NOZORDER );
00125 
00126         DeferWindowPos( hDWP, m_wndToolBar, NULL,
00127                 rc.left, rc.bottom - TOOLBAR_HEIGHT - EDIT_HEIGHT,
00128                 rc.Width(), TOOLBAR_HEIGHT, SWP_NOZORDER );
00129 
00130         DeferWindowPos( hDWP, m_wndEdit, NULL, rc.left, rc.bottom - EDIT_HEIGHT,
00131                 rc.Width(), EDIT_HEIGHT, SWP_NOZORDER );
00132 
00133         EndDeferWindowPos( hDWP );
00134 }
00135 
00136 void CPrivateChatFrame::OnPaint()
00137 {
00138         CPaintDC dc( this );
00139         CRect rc;
00140 
00141         GetClientRect( &rc );
00142 }
00143 
00144 void CPrivateChatFrame::OnContextMenu(CWnd* pWnd, CPoint point)
00145 {
00146         Skin.TrackPopupMenu( _T("CPrivateChatFrame"), point );
00147 }
00148 
00150 // CPrivateChatFrame event handlers
00151 
00152 void CPrivateChatFrame::OnProfileReceived()
00153 {
00154         CString str;
00155 
00156         LoadString( str, IDS_CHAT_PROFILE_ACCEPTED );
00157         m_pContent.Add( retText, str, NULL, retfColour )->m_cColour = RGB( 128, 128, 128 );
00158 
00159         m_sNick = m_pSession->m_sUserNick;
00160         m_pContent.Add( retLink, m_sNick, _T("raza:command:ID_CHAT_BROWSE") );
00161 
00162         SetWindowText( _T("Chat : ") + m_sNick );
00163         GetParent()->PostMessage( WM_TIMER, 2 );
00164 
00165         AddText( _T(".") );
00166         SetAlert();
00167 }
00168 
00169 void CPrivateChatFrame::OnRemoteMessage(BOOL bAction, LPCTSTR pszText)
00170 {
00171         // Check message spam filter (if enabled)
00172         if ( ! MessageFilter.IsFiltered( pszText ) )
00173         {
00174                 // Adult filter (if enabled)
00175                 if ( AdultFilter.IsChatFiltered( pszText ) ) AdultFilter.Censor( (TCHAR*)pszText );
00176 
00177                 AddText( FALSE, bAction, m_sNick, pszText );
00178                 SetAlert();
00179                 PostMessage( WM_TIMER, 4 );
00180         }
00181 }
00182 
00183 void CPrivateChatFrame::OnLocalMessage(BOOL bAction, LPCTSTR pszText)
00184 {
00185         TRISTATE bConnected = m_pSession->GetConnectedState();
00186 
00187         if ( bConnected != TS_TRUE )
00188         {
00189                 if ( ( m_pSession->m_nProtocol == PROTOCOL_ED2K ) || ( bConnected != TS_FALSE ) )
00190                 {
00191                         m_pSession->StatusMessage( 1, IDS_CHAT_NOT_CONNECTED_2 );
00192                 }
00193                 else
00194                 {
00195                         m_pSession->StatusMessage( 1, IDS_CHAT_NOT_CONNECTED_1 );
00196                         PostMessage( WM_COMMAND, ID_CHAT_CONNECT );
00197                 }
00198                 return;
00199         }
00200 
00201         // Adult filter (if enabled)
00202         if ( AdultFilter.IsChatFiltered( pszText ) ) AdultFilter.Censor( (TCHAR*)pszText );
00203 
00204         AddText( TRUE, bAction, MyProfile.GetNick().Left( 255 ), pszText );
00205         m_pSession->SendPrivateMessage( bAction, pszText );
00206 }
00207 
00208 void CPrivateChatFrame::OnLocalCommand(LPCTSTR pszCommand, LPCTSTR pszArgs)
00209 {
00210         if ( _tcscmp( pszCommand, _T("/BROWSE") ) == 0 )
00211         {
00212                 PostMessage( WM_COMMAND, ID_CHAT_BROWSE );
00213         }
00214         else
00215         {
00216                 CChatFrame::OnLocalCommand( pszCommand, pszArgs );
00217         }
00218 }
00219 
00221 // CPrivateChatFrame commands
00222 
00223 void CPrivateChatFrame::OnUpdateChatBrowse(CCmdUI* pCmdUI)
00224 {
00225         pCmdUI->Enable( m_pSession != NULL );
00226 }
00227 
00228 void CPrivateChatFrame::OnChatBrowse()
00229 {
00230         if ( m_pSession != NULL )
00231         {
00232                 new CBrowseHostWnd( &m_pSession->m_pHost,
00233                         m_pSession->m_bGUID ? &m_pSession->m_pGUID : NULL );
00234         }
00235 }
00236 
00237 void CPrivateChatFrame::OnUpdateChatPriority(CCmdUI* pCmdUI)
00238 {
00239         pCmdUI->Enable( m_pSession != NULL && m_pSession->GetConnectedState() == TS_TRUE );
00240 }
00241 
00242 void CPrivateChatFrame::OnChatPriority()
00243 {
00244         CSingleLock pLock( &Transfers.m_pSection );
00245         if ( ! pLock.Lock( 500 ) ) return;
00246 
00247         DWORD nAddress = m_pSession->m_pHost.sin_addr.S_un.S_addr;
00248 
00249         for ( POSITION pos = Uploads.GetIterator() ; pos ; )
00250         {
00251                 CUploadTransfer* pUpload = Uploads.GetNext( pos );
00252 
00253                 if (    pUpload->m_pHost.sin_addr.S_un.S_addr == nAddress &&
00254                                 pUpload->m_nState == upsQueued )
00255                 {
00256                         pUpload->Promote();
00257                 }
00258         }
00259 
00260         m_pSession->StatusMessage( 2, IDS_CHAT_PRIORITY_GRANTED,
00261                 (LPCTSTR)m_pSession->m_sAddress );
00262 }

Generated on Thu Dec 15 10:39:37 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2