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

CtrlBrowseProfile.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlBrowseProfile.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 "Settings.h"
00025 #include "GProfile.h"
00026 #include "G2Packet.h"
00027 #include "HostBrowser.h"
00028 #include "XML.h"
00029 
00030 #include "RichElement.h"
00031 #include "RichDocument.h"
00032 #include "CoolInterface.h"
00033 #include "ImageServices.h"
00034 #include "CtrlBrowseProfile.h"
00035 #include "Skin.h"
00036 
00037 #ifdef _DEBUG
00038 #define new DEBUG_NEW
00039 #undef THIS_FILE
00040 static char THIS_FILE[] = __FILE__;
00041 #endif
00042 
00043 BEGIN_MESSAGE_MAP(CBrowseProfileCtrl, CWnd)
00044         //{{AFX_MSG_MAP(CBrowseProfileCtrl)
00045         ON_WM_CREATE()
00046         ON_WM_DESTROY()
00047         ON_WM_SIZE()
00048         ON_WM_PAINT()
00049         ON_WM_TIMER()
00050         ON_NOTIFY(RVN_CLICK, IDC_BROWSE_PROFILE, OnClickView)
00051         //}}AFX_MSG_MAP
00052 END_MESSAGE_MAP()
00053 
00054 
00056 // CBrowseProfileCtrl construction
00057 
00058 CBrowseProfileCtrl::CBrowseProfileCtrl()
00059 {
00060         m_pDocument1 = NULL;
00061         m_pDocument2 = NULL;
00062 }
00063 
00064 CBrowseProfileCtrl::~CBrowseProfileCtrl()
00065 {
00066 }
00067 
00069 // CBrowseProfileCtrl operations
00070 
00071 BOOL CBrowseProfileCtrl::Create(CWnd* pParentWnd)
00072 {
00073         CRect rect( 0, 0, 0, 0 );
00074         return CWnd::Create( NULL, NULL, WS_CHILD,
00075                 rect, pParentWnd, IDC_BROWSE_PROFILE, NULL );
00076 }
00077 
00078 void CBrowseProfileCtrl::OnSkinChange()
00079 {
00080         CSingleLock pLock( &m_pSection, TRUE );
00081 
00082         if ( m_pDocument1 != NULL )
00083                 m_pDocument1->Clear();
00084         else
00085                 m_pDocument1 = new CRichDocument();
00086 
00087         m_pdNick = m_pdFullName = m_pdFullLocation = NULL;
00088         m_pdGenderMale = m_pdGenderFemale = m_pdAge = NULL;
00089         m_pdContactEmail = m_pdContactMSN = m_pdContactYahoo = m_pdContactICQ = m_pdContactAOL = m_pdContactJabber = NULL;
00090         m_pdBioText = m_pdInterests = NULL;
00091 
00092         if ( CXMLElement* pXML = Skin.GetDocument( _T("CBrowseHostProfile.1") ) )
00093         {
00094                 CMapStringToPtr pMap;
00095                 m_pDocument1->LoadXML( pXML, &pMap );
00096 
00097                 pMap.Lookup( _T("Nick"), (void*&)m_pdNick );
00098                 pMap.Lookup( _T("FullName"), (void*&)m_pdFullName );
00099                 pMap.Lookup( _T("FullLocation"), (void*&)m_pdFullLocation );
00100                 pMap.Lookup( _T("GenderMale"), (void*&)m_pdGenderMale );
00101                 pMap.Lookup( _T("GenderFemale"), (void*&)m_pdGenderFemale );
00102                 pMap.Lookup( _T("Age"), (void*&)m_pdAge );
00103                 pMap.Lookup( _T("ContactEmail"), (void*&)m_pdContactEmail );
00104                 pMap.Lookup( _T("ContactMSN"), (void*&)m_pdContactMSN );
00105                 pMap.Lookup( _T("ContactYahoo"), (void*&)m_pdContactYahoo );
00106                 pMap.Lookup( _T("ContactICQ"), (void*&)m_pdContactICQ );
00107                 pMap.Lookup( _T("ContactAOL"), (void*&)m_pdContactAOL );
00108                 pMap.Lookup( _T("ContactJabber"), (void*&)m_pdContactJabber );
00109                 pMap.Lookup( _T("Interests"), (void*&)m_pdInterests );
00110                 pMap.Lookup( _T("BioText"), (void*&)m_pdBioText );
00111         }
00112 
00113         if ( m_pDocument2 != NULL )
00114                 m_pDocument2->Clear();
00115         else
00116                 m_pDocument2 = new CRichDocument();
00117 
00118         m_pdBookmarks = NULL;
00119 
00120         if ( CXMLElement* pXML = Skin.GetDocument( _T("CBrowseHostProfile.2") ) )
00121         {
00122                 CMapStringToPtr pMap;
00123                 m_pDocument2->LoadXML( pXML, &pMap );
00124 
00125                 pMap.Lookup( _T("Bookmarks"), (void*&)m_pdBookmarks );
00126         }
00127 
00128         m_wndDoc1.SetDocument( m_pDocument1 );
00129         m_wndDoc2.SetDocument( m_pDocument2 );
00130 }
00131 
00132 void CBrowseProfileCtrl::Update(CHostBrowser* pBrowser)
00133 {
00134         CSingleLock pLock( &m_pSection, TRUE );
00135 
00136         CGProfile* pProfile = pBrowser->m_pProfile;
00137 
00138         if ( m_pDocument1 == NULL || m_pDocument2 == NULL ) return;
00139         if ( pProfile == NULL || pProfile->IsValid() == FALSE ) return;
00140 
00141         if ( pBrowser->IsBrowsing() == FALSE && pBrowser->m_nHits > 0 &&
00142                  m_bmHead.m_hObject == NULL )
00143         {
00144                 LoadDefaultHead();
00145         }
00146 
00147         UpdateDocument1( pProfile );
00148         UpdateDocument2( pBrowser );
00149 
00150         if ( m_wndDoc1.IsWindowVisible() == FALSE ) m_wndDoc1.ShowWindow( SW_SHOW );
00151         if ( m_wndDoc2.IsWindowVisible() == FALSE ) m_wndDoc2.ShowWindow( SW_SHOW );
00152 }
00153 
00154 void CBrowseProfileCtrl::UpdateDocument1(CGProfile* pProfile)
00155 {
00156         CSingleLock pLock( &m_pDocument1->m_pSection, TRUE );
00157         CString str;
00158 
00159         if ( m_pdNick != NULL ) m_pdNick->SetText( pProfile->GetNick() );
00160 
00161         if ( CXMLElement* pIdentity = pProfile->GetXML( _T("identity") ) )
00162         {
00163                 if ( CXMLElement* pName = pIdentity->GetElementByName( _T("name") ) )
00164                 {
00165                         CString strFirst        = pName->GetAttributeValue( _T("first") );
00166                         CString strLast         = pName->GetAttributeValue( _T("last") );
00167 
00168                         if ( m_pdFullName != NULL && ( strFirst.GetLength() || strLast.GetLength() ) )
00169                         {
00170                                 m_pDocument1->ShowGroup( 1, TRUE );
00171                                 m_pdFullName->SetText( strFirst + ' ' + strLast );
00172                         }
00173                         else
00174                         {
00175                                 m_pDocument1->ShowGroup( 1, FALSE );
00176                         }
00177                 }
00178                 else
00179                 {
00180                         m_pDocument1->ShowGroup( 1, FALSE );
00181                 }
00182         }
00183         else
00184         {
00185                 m_pDocument1->ShowGroup( 1, FALSE );
00186         }
00187 
00188         str = pProfile->GetLocation();
00189         m_pDocument1->ShowGroup( 2, str.GetLength() > 0 );
00190         if ( m_pdFullLocation != NULL ) m_pdFullLocation->SetText( str );
00191 
00192         if ( CXMLElement* pVitals = pProfile->GetXML( _T("vitals") ) )
00193         {
00194                 str = pVitals->GetAttributeValue( _T("gender") );
00195                 m_pDocument1->ShowGroup( 3, str.GetLength() > 0 );
00196 
00197                 if ( m_pdGenderMale != NULL && m_pdGenderFemale != NULL )
00198                 {
00199                         m_pdGenderMale->Show( str.CompareNoCase( _T("male") ) == 0 );
00200                         m_pdGenderFemale->Show( str.CompareNoCase( _T("female") ) == 0 );
00201                 }
00202 
00203                 str = pVitals->GetAttributeValue( _T("age") );
00204                 if ( m_pdAge != NULL ) m_pdAge->SetText( str );
00205         }
00206         else
00207         {
00208                 m_pDocument1->ShowGroup( 3, FALSE );
00209         }
00210 
00211         BOOL bContact = FALSE;
00212 
00213         str = pProfile->GetContact( _T("Email") );
00214         bContact |= ( str.GetLength() > 0 );
00215         m_pDocument1->ShowGroup( 40, str.GetLength() > 0 );
00216         if ( m_pdContactEmail != NULL )
00217         {
00218                 m_pdContactEmail->SetText( str );
00219                 m_pdContactEmail->m_sLink = _T("mailto:") + str;
00220         }
00221 
00222         str = pProfile->GetContact( _T("MSN") );
00223         bContact |= ( str.GetLength() > 0 );
00224         m_pDocument1->ShowGroup( 44, str.GetLength() > 0 );
00225         if ( m_pdContactMSN != NULL )
00226         {
00227                 m_pdContactMSN->SetText( str );
00228                 m_pdContactMSN->m_sLink = _T("msn:") + str;
00229         }
00230 
00231         str = pProfile->GetContact( _T("Yahoo") );
00232         bContact |= ( str.GetLength() > 0 );
00233         m_pDocument1->ShowGroup( 41, str.GetLength() > 0 );
00234         if ( m_pdContactYahoo != NULL )
00235         {
00236                 m_pdContactYahoo->SetText( str );
00237                 m_pdContactYahoo->m_sLink = _T("ymsgr:sendim?") + str;
00238         }
00239 
00240         str = pProfile->GetContact( _T("ICQ") );
00241         bContact |= ( str.GetLength() > 0 );
00242         m_pDocument1->ShowGroup( 42, str.GetLength() > 0 );
00243         if ( m_pdContactICQ != NULL )
00244         {
00245                 m_pdContactICQ->SetText( str );
00246                 m_pdContactICQ->m_sLink = _T("http://web.icq.com/wwp?Uin=") + str;
00247         }
00248 
00249         str = pProfile->GetContact( _T("AOL") );
00250         bContact |= ( str.GetLength() > 0 );
00251         m_pDocument1->ShowGroup( 43, str.GetLength() > 0 );
00252         if ( m_pdContactAOL != NULL )
00253         {
00254                 m_pdContactAOL->SetText( str );
00255                 m_pdContactAOL->m_sLink = _T("aim:goim?screenname=") + str;
00256         }
00257 
00258         str = pProfile->GetContact( _T("Jabber") );
00259         bContact |= ( str.GetLength() > 0 );
00260         m_pDocument1->ShowGroup( 45, str.GetLength() > 0 );
00261         if ( m_pdContactJabber != NULL )
00262         {
00263                 m_pdContactJabber->SetText( str );
00264         }
00265 
00266         m_pDocument1->ShowGroup( 4, bContact );
00267 
00268         str.Empty();
00269 
00270         if ( CXMLElement* pInterests = pProfile->GetXML( _T("interests") ) )
00271         {
00272                 for ( POSITION pos = pInterests->GetElementIterator() ; pos ; )
00273                 {
00274                         CXMLElement* pInterest = pInterests->GetNextElement( pos );
00275 
00276                         if ( pInterest->IsNamed( _T("interest") ) )
00277                         {
00278                                 if ( str.GetLength() ) str += _T(", ");
00279                                 str += pInterest->GetValue();
00280                         }
00281                 }
00282         }
00283 
00284         m_pDocument1->ShowGroup( 5, str.GetLength() > 0 );
00285         if ( m_pdInterests != NULL ) m_pdInterests->SetText( str );
00286 
00287         str.Empty();
00288         if ( CXMLElement* pBio = pProfile->GetXML( _T("notes") ) )
00289                 str = pBio->GetValue();
00290         m_pDocument1->ShowGroup( 6, str.GetLength() > 0 );
00291         if ( m_pdBioText != NULL ) m_pdBioText->SetText( str );
00292 
00293         m_wndDoc1.InvalidateIfModified();
00294 }
00295 
00296 void CBrowseProfileCtrl::UpdateDocument2(CHostBrowser* pBrowser)
00297 {
00298         int nBookmarks = 0;
00299         CGProfile* pProfile = pBrowser->m_pProfile;
00300 
00301         CSingleLock pLock( &m_pDocument2->m_pSection, TRUE );
00302 
00303         m_pDocument2->ShowGroup( 2, pBrowser->m_bCanChat );
00304 
00305         if ( m_pdBookmarks != NULL )
00306         {
00307                 POSITION pos = m_pDocument2->Find( m_pdBookmarks );
00308                 if ( pos == NULL ) return;
00309 
00310                 POSITION posSave = pos;
00311                 m_pDocument2->GetNext( pos );
00312 
00313                 while ( pos )
00314                 {
00315                         CRichElement* pElement = m_pDocument2->GetNext( pos );
00316                         if ( pElement->m_nGroup != 1 ) break;
00317                         pElement->Delete();
00318                 }
00319 
00320                 m_pDocument2->GetNext( posSave );
00321 
00322                 if ( CXMLElement* pBookmarks = pProfile->GetXML( _T("bookmarks") ) )
00323                 {
00324                         for ( pos = pBookmarks->GetElementIterator() ; pos ; )
00325                         {
00326                                 CXMLElement* pBookmark = pBookmarks->GetNextElement( pos );
00327                                 if ( ! pBookmark->IsNamed( _T("bookmark") ) ) continue;
00328 
00329                                 CString strTitle        = pBookmark->GetAttributeValue( _T("title") );
00330                                 CString strURL          = pBookmark->GetAttributeValue( _T("url") );
00331 
00332                                 if ( strTitle.IsEmpty() ) continue;
00333                                 if ( strURL.Find( _T("http://") ) != 0 ) continue;
00334 
00335                                 m_pDocument2->Add( retIcon, MAKEINTRESOURCE(IDI_WEB_URL), strURL, 0, 1, posSave );
00336                                 m_pDocument2->Add( retGap, _T("5"), NULL, 0, 1, posSave );
00337                                 m_pDocument2->Add( retLink, strTitle, strURL, retfMiddle, 1, posSave );
00338                                 m_pDocument2->Add( retNewline, _T("2"), NULL, 0, 1, posSave );
00339 
00340                                 nBookmarks ++;
00341                         }
00342                 }
00343         }
00344 
00345 
00346         if ( nBookmarks )
00347                 m_pDocument2->ShowGroup( 3, TRUE );
00348         else
00349                 m_pDocument2->ShowGroup( 3, FALSE );
00350 
00351         m_wndDoc2.InvalidateIfModified();
00352 }
00353 
00354 void CBrowseProfileCtrl::OnHeadPacket(CG2Packet* pPacket)
00355 {
00356         CSingleLock pLock( &m_pSection, TRUE );
00357         CString strFile;
00358         CHAR szType[9];
00359         DWORD nLength;
00360 
00361         while ( pPacket->ReadPacket( szType, nLength ) )
00362         {
00363                 DWORD nNext = pPacket->m_nPosition + nLength;
00364 
00365                 if ( strcmp( szType, "NAME" ) == 0 )
00366                 {
00367                         strFile = pPacket->ReadString( nLength );
00368                 }
00369                 else if ( strcmp( szType, "BODY" ) == 0 )
00370                 {
00371                         CImageServices pServices;
00372                         CImageFile pImage( &pServices );
00373 
00374                         if ( pImage.LoadFromMemory( strFile,
00375                                  (LPCVOID)( pPacket->m_pBuffer + pPacket->m_nPosition ), nLength )
00376                                  && pImage.EnsureRGB( CoolInterface.m_crWindow ) )
00377                         {
00378                                 pImage.Resample( 128, 128 );
00379                                 if ( m_bmHead.m_hObject ) m_bmHead.DeleteObject();
00380                                 m_bmHead.Attach( pImage.CreateBitmap() );
00381                         }
00382                 }
00383 
00384                 pPacket->m_nPosition = nNext;
00385         }
00386 
00387         PostMessage( WM_TIMER, 1 );
00388 }
00389 
00390 void CBrowseProfileCtrl::LoadDefaultHead()
00391 {
00392         CSingleLock pLock( &m_pSection, TRUE );
00393 
00394         if ( m_bmHead.m_hObject != NULL ) return;
00395 
00396         CImageServices pServices;
00397         CImageFile pImage( &pServices );
00398 
00399         if ( pImage.LoadFromFile( Settings.General.Path + _T("\\Data\\DefaultAvatar.png") )
00400                  && pImage.EnsureRGB( CoolInterface.m_crWindow ) )
00401         {
00402                 pImage.Resample( 128, 128 );
00403                 if ( m_bmHead.m_hObject ) m_bmHead.DeleteObject();
00404                 m_bmHead.Attach( pImage.CreateBitmap() );
00405                 Invalidate();
00406         }
00407 }
00408 
00410 // CBrowseProfileCtrl message handlers
00411 
00412 int CBrowseProfileCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
00413 {
00414         if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00415 
00416         CRect rect;
00417         m_wndDoc1.Create( WS_CHILD, rect, this, IDC_BROWSE_PROFILE );
00418         m_wndDoc2.Create( WS_CHILD, rect, this, IDC_BROWSE_PROFILE );
00419         m_wndDoc1.SetSelectable( TRUE );
00420 
00421         return 0;
00422 }
00423 
00424 void CBrowseProfileCtrl::OnDestroy()
00425 {
00426         CWnd::OnDestroy();
00427 
00428         if ( m_pDocument2 != NULL ) delete m_pDocument2;
00429         m_pDocument2 = NULL;
00430 
00431         if ( m_pDocument1 != NULL ) delete m_pDocument1;
00432         m_pDocument1 = NULL;
00433 }
00434 
00435 void CBrowseProfileCtrl::OnSize(UINT nType, int cx, int cy)
00436 {
00437         CWnd::OnSize( nType, cx, cy );
00438 
00439         CRect rc;
00440         GetClientRect( &rc );
00441         rc.left += 148;
00442 
00443         m_wndDoc1.SetWindowPos( NULL, rc.left, rc.top, rc.Width() / 2,
00444                 rc.Height(), SWP_NOZORDER );
00445 
00446         m_wndDoc2.SetWindowPos( NULL, ( rc.left + rc.right ) / 2, rc.top,
00447                 rc.Width() - rc.Width() / 2, rc.Height(), SWP_NOZORDER );
00448 }
00449 
00450 void CBrowseProfileCtrl::OnPaint()
00451 {
00452         CSingleLock pLock( &m_pSection, TRUE );
00453         CPaintDC dc( this );
00454         CRect rcPanel;
00455 
00456         GetClientRect( &rcPanel );
00457 
00458         if ( m_bmHead.m_hObject != NULL )
00459         {
00460                 CRect rcHead( 10, 10, 138, 138 );
00461                 CDC dcMem;
00462 
00463                 dcMem.CreateCompatibleDC( &dc );
00464                 CBitmap* pOldBmp = (CBitmap*)dcMem.SelectObject( &m_bmHead );
00465                 dc.BitBlt( rcHead.left, rcHead.top, rcHead.Width(), rcHead.Height(),
00466                         &dcMem, 0, 0, SRCCOPY );
00467                 dc.ExcludeClipRect( &rcHead );
00468                 dcMem.SelectObject( pOldBmp );
00469         }
00470 
00471         if ( m_wndDoc1.IsWindowVisible() )
00472         {
00473                 rcPanel.right = rcPanel.left + 148;
00474         }
00475 
00476         dc.FillSolidRect( &rcPanel, CoolInterface.m_crWindow );
00477 }
00478 
00479 void CBrowseProfileCtrl::OnTimer(UINT nIDEvent)
00480 {
00481         if ( nIDEvent == 1 )
00482         {
00483                 Invalidate();
00484         }
00485 }
00486 
00487 void CBrowseProfileCtrl::OnClickView(RVN_ELEMENTEVENT* pNotify, LRESULT *pResult)
00488 {
00489         if ( CRichElement* pElement = pNotify->pElement )
00490         {
00491                 theApp.InternalURI( pElement->m_sLink );
00492         }
00493 }
00494 

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