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

PageProfileIdentity.cpp

Go to the documentation of this file.
00001 //
00002 // PageProfileIdentity.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 "XML.h"
00027 #include "PageProfileIdentity.h"
00028 #include "Skin.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00036 IMPLEMENT_DYNCREATE(CIdentityProfilePage, CSettingsPage)
00037 
00038 BEGIN_MESSAGE_MAP(CIdentityProfilePage, CSettingsPage)
00039         //{{AFX_MSG_MAP(CIdentityProfilePage)
00040         //}}AFX_MSG_MAP
00041 END_MESSAGE_MAP()
00042 
00043 
00045 // CIdentityProfilePage property page
00046 
00047 CIdentityProfilePage::CIdentityProfilePage() : CSettingsPage( CIdentityProfilePage::IDD )
00048 {
00049         //{{AFX_DATA_INIT(CIdentityProfilePage)
00050         m_sAge = _T("");
00051         m_sGender = _T("");
00052         m_sNick = _T("");
00053         m_sFirst = _T("");
00054         m_sLast = _T("");
00055         m_bBrowseUser = FALSE;
00056         //}}AFX_DATA_INIT
00057 }
00058 
00059 CIdentityProfilePage::~CIdentityProfilePage()
00060 {
00061 }
00062 
00063 void CIdentityProfilePage::DoDataExchange(CDataExchange* pDX)
00064 {
00065         CSettingsPage::DoDataExchange(pDX);
00066         //{{AFX_DATA_MAP(CIdentityProfilePage)
00067         DDX_Control(pDX, IDC_PROFILE_AGE, m_wndAge);
00068         DDX_CBString(pDX, IDC_PROFILE_AGE, m_sAge);
00069         DDX_CBString(pDX, IDC_PROFILE_GENDER, m_sGender);
00070         DDX_Text(pDX, IDC_PROFILE_NICK, m_sNick);
00071         DDX_Text(pDX, IDC_PROFILE_FIRST, m_sFirst);
00072         DDX_Text(pDX, IDC_PROFILE_LAST, m_sLast);
00073         DDX_Check(pDX, IDC_BROWSE_USER, m_bBrowseUser);
00074         //}}AFX_DATA_MAP
00075 }
00076 
00078 // CIdentityProfilePage message handlers
00079 
00080 BOOL CIdentityProfilePage::OnInitDialog()
00081 {
00082         CSettingsPage::OnInitDialog();
00083 
00084         if ( CXMLElement* pIdentity = MyProfile.GetXML( _T("identity") ) )
00085         {
00086                 if ( CXMLElement* pHandle = pIdentity->GetElementByName( _T("handle") ) )
00087                 {
00088                         m_sNick = pHandle->GetAttributeValue( _T("primary") );
00089                 }
00090 
00091                 if ( CXMLElement* pName = pIdentity->GetElementByName( _T("name") ) )
00092                 {
00093                         m_sFirst        = pName->GetAttributeValue( _T("first") );
00094                         m_sLast         = pName->GetAttributeValue( _T("last") );
00095                 }
00096         }
00097 
00098         if ( CXMLElement* pVitals = MyProfile.GetXML( _T("vitals") ) )
00099         {
00100                 m_sAge = pVitals->GetAttributeValue( _T("age") );
00101 
00102                 CString strGenderMale, strGenderFemale;
00103                 GetGenderTranslations( strGenderMale, strGenderFemale );
00104 
00105                 m_sGender = pVitals->GetAttributeValue( _T("gender") );
00106 
00107                 if ( m_sGender.GetLength() )
00108                 {
00109                         CComboBox* pGender = (CComboBox*) GetDlgItem( IDC_PROFILE_GENDER );
00110                         if ( m_sGender.CompareNoCase( _T("male") ) == 0 )
00111                         {
00112                                 int nIndex = pGender->SelectString( 1, (LPCTSTR) strGenderMale );
00113                                 ASSERT(nIndex != CB_ERR);
00114                         }
00115                         else if ( m_sGender.CompareNoCase( _T("female") ) == 0 )
00116                         {
00117                                 int nIndex = pGender->SelectString( 2, (LPCTSTR) strGenderFemale );
00118                                 ASSERT(nIndex != CB_ERR);
00119                         }
00120                         else
00121                                 m_sGender.Empty();
00122                 }
00123                 else
00124                         m_sGender.Empty();
00125 
00126                 int nAge = 0;
00127 
00128                 if ( _stscanf( m_sAge, _T("%lu"), &nAge ) == 1 && nAge > 0 )
00129                         m_sAge.Format( _T("%lu"), nAge );
00130                 else
00131                         m_sAge.Empty();
00132         }
00133 
00134         for ( int nAge = 1 ; nAge < 110 ; nAge++ )
00135         {
00136                 CString str;
00137                 str.Format( _T("%i"), nAge );
00138                 m_wndAge.AddString( str );
00139         }
00140 
00141         m_bBrowseUser = Settings.Community.ServeProfile;
00142 
00143         UpdateData( FALSE );
00144 
00145         return TRUE;
00146 }
00147 
00148 void CIdentityProfilePage::OnOK()
00149 {
00150         UpdateData();
00151 
00152         Settings.Community.ServeProfile = m_bBrowseUser;
00153 
00154         if ( CXMLElement* pIdentity = MyProfile.GetXML( _T("identity"), TRUE ) )
00155         {
00156                 if ( CXMLElement* pHandle = pIdentity->GetElementByName( _T("handle"), TRUE ) )
00157                 {
00158                         pHandle->AddAttribute( _T("primary"), m_sNick );
00159                         if ( m_sNick.IsEmpty() ) pHandle->Delete();
00160                 }
00161 
00162                 if ( CXMLElement* pName = pIdentity->GetElementByName( _T("name"), TRUE ) )
00163                 {
00164                         pName->AddAttribute( _T("first"), m_sFirst );
00165                         pName->AddAttribute( _T("last"), m_sLast );
00166                         if ( m_sFirst.IsEmpty() && m_sLast.IsEmpty() ) pName->Delete();
00167                 }
00168 
00169                 if ( pIdentity->GetElementCount() == 0 ) pIdentity->Delete();
00170         }
00171 
00172         if ( CXMLElement* pVitals = MyProfile.GetXML( _T("vitals"), TRUE ) )
00173         {
00174                 int nAge = 0;
00175 
00176                 if ( _stscanf( m_sAge, _T("%lu"), &nAge ) == 1 && nAge > 0 )
00177                         m_sAge.Format( _T("%lu"), nAge );
00178                 else
00179                         m_sAge.Empty();
00180 
00181                 CString strGenderMale, strGenderFemale;
00182                 GetGenderTranslations( strGenderMale, strGenderFemale );
00183 
00184                 if ( m_sGender.CompareNoCase( strGenderMale ) == 0 || m_sGender.CompareNoCase( _T("male") ) == 0 )
00185                         pVitals->AddAttribute( _T("gender"), _T("Male") );
00186                 else if ( m_sGender.CompareNoCase( strGenderFemale ) == 0 || m_sGender.CompareNoCase( _T("female") ) == 0 )
00187                         pVitals->AddAttribute( _T("gender"), _T("Female") );
00188                 else
00189                         pVitals->DeleteAttribute( _T("gender") );
00190 
00191                 if ( m_sAge.GetLength() )
00192                         pVitals->AddAttribute( _T("age"), m_sAge );
00193                 else
00194                         pVitals->DeleteAttribute( _T("age") );
00195 
00196                 if ( pVitals->GetElementCount() == 0 &&
00197                          pVitals->GetAttributeCount() == 0 ) pVitals->Delete();
00198         }
00199 }
00200 
00201 void CIdentityProfilePage::GetGenderTranslations(CString& pMale, CString& pFemale)
00202 {
00203         // Using data from CBrowseHostProfile.1 translation since the control in the dialog
00204         // may change its order and it does not have its identifier.
00205 
00206         BOOL bCollected = FALSE;
00207 
00208         CXMLElement* pXML = Skin.GetDocument( _T("CBrowseHostProfile.1") );
00209 
00210         for ( POSITION pos = pXML->GetElementIterator() ; pos && ! bCollected ; )
00211         {
00212                 CXMLElement* pGroups = pXML->GetNextElement( pos );
00213                 if ( pGroups->IsNamed( _T("group") ) && pGroups->GetAttributeValue( _T("id") ) == "3" ) {
00214                         for ( POSITION pos = pGroups->GetElementIterator() ; pos && ! bCollected ; )
00215                         {
00216                                 CXMLElement* pText = pGroups->GetNextElement( pos );
00217                                 if ( pText->IsNamed( _T("text") ) )
00218                                 {
00219                                         CString strTemp;
00220                                         strTemp = pText->GetAttributeValue( _T("id") );
00221                                         if ( strTemp.CompareNoCase( _T("gendermale") ) == 0 )
00222                                         {
00223                                                 pMale = pText->GetValue();
00224                                                 bCollected = pFemale.IsEmpty() ? FALSE : TRUE;
00225                                         }
00226                                         if ( strTemp.CompareNoCase( _T("genderfemale") ) == 0 )
00227                                         {
00228                                                 pFemale = pText->GetValue();
00229                                                 bCollected = pMale.IsEmpty() ? FALSE : TRUE;
00230                                         }
00231                                 }
00232                         }
00233                 }
00234         }
00235 }

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