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

WizardProfilePage.cpp

Go to the documentation of this file.
00001 //
00002 // WizardProfilePage.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 "WorldGPS.h"
00027 #include "Skin.h"
00028 #include "XML.h"
00029 #include "WizardProfilePage.h"
00030 
00031 #ifdef _DEBUG
00032 #define new DEBUG_NEW
00033 #undef THIS_FILE
00034 static char THIS_FILE[] = __FILE__;
00035 #endif
00036 
00037 IMPLEMENT_DYNCREATE(CWizardProfilePage, CWizardPage)
00038 
00039 BEGIN_MESSAGE_MAP(CWizardProfilePage, CWizardPage)
00040         //{{AFX_MSG_MAP(CWizardProfilePage)
00041         ON_CBN_CLOSEUP(IDC_LOC_COUNTRY, OnCloseUpCountry)
00042         //}}AFX_MSG_MAP
00043 END_MESSAGE_MAP()
00044 
00045 
00047 // CWizardProfilePage property page
00048 
00049 CWizardProfilePage::CWizardProfilePage() : CWizardPage(CWizardProfilePage::IDD)
00050 {
00051         //{{AFX_DATA_INIT(CWizardProfilePage)
00052         m_nGender = 0;
00053         m_nAge = 0;
00054         //}}AFX_DATA_INIT
00055         m_pWorld = NULL;
00056 }
00057 
00058 CWizardProfilePage::~CWizardProfilePage()
00059 {
00060         delete m_pWorld;
00061 }
00062 
00063 void CWizardProfilePage::DoDataExchange(CDataExchange* pDX)
00064 {
00065         CWizardPage::DoDataExchange(pDX);
00066         //{{AFX_DATA_MAP(CWizardProfilePage)
00067         DDX_Text(pDX, IDC_PROFILE_NICK, m_sNick);
00068         DDX_Control(pDX, IDC_LOC_CITY, m_wndCity);
00069         DDX_Control(pDX, IDC_LOC_COUNTRY, m_wndCountry);
00070         DDX_CBString(pDX, IDC_LOC_CITY, m_sLocCity);
00071         DDX_CBString(pDX, IDC_LOC_COUNTRY, m_sLocCountry);
00072         DDX_Control(pDX, IDC_PROFILE_AGE, m_wndAge);
00073         DDX_CBIndex(pDX, IDC_PROFILE_AGE, m_nAge);
00074         DDX_CBIndex(pDX, IDC_PROFILE_GENDER, m_nGender);
00075         //}}AFX_DATA_MAP
00076 }
00077 
00079 // CWizardProfilePage message handlers
00080 
00081 BOOL CWizardProfilePage::OnInitDialog()
00082 {
00083         CWizardPage::OnInitDialog();
00084 
00085         Skin.Apply( _T("CWizardProfilePage"), this );
00086 
00087         for ( int nAge = 13 ; nAge < 110 ; nAge++ )
00088         {
00089                 CString str, strYearsOld;
00090                 LoadString( strYearsOld, IDS_WIZARD_YEARS_OLD );
00091                 str.Format( _T(" %i ") + strYearsOld, nAge );
00092                 m_wndAge.SetItemData( m_wndAge.AddString( str ), nAge );
00093         }
00094 
00095         m_pWorld = new CWorldGPS();
00096         m_pWorld->Load();
00097 
00098         CWorldCountry* pCountry = m_pWorld->m_pCountry;
00099 
00100         for ( int nCountry = m_pWorld->m_nCountry ; nCountry ; nCountry--, pCountry++ )
00101         {
00102                 m_wndCountry.SetItemData( m_wndCountry.AddString( pCountry->m_sName ), (LPARAM)pCountry );
00103         }
00104 
00105         return TRUE;
00106 }
00107 
00108 BOOL CWizardProfilePage::OnSetActive()
00109 {
00110         SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );
00111 
00112         m_sNick = MyProfile.GetNick();
00113 
00114         if ( m_sNick.IsEmpty() )
00115         {
00116                 TCHAR pBuffer[64];
00117                 DWORD nSize = 64;
00118                 if ( GetUserNameW( pBuffer, &nSize ) ) m_sNick = pBuffer;
00119         }
00120 
00121         if ( CXMLElement* pVitals = MyProfile.GetXML( _T("vitals") ) )
00122         {
00123                 CString strGender       = pVitals->GetAttributeValue( _T("gender") );
00124                 CString strAge          = pVitals->GetAttributeValue( _T("age") );
00125 
00126                 if ( strGender.CompareNoCase( _T("male") ) == 0 )
00127                 {
00128                         m_nGender = 1;
00129                 }
00130                 else if ( strGender.CompareNoCase( _T("female") ) == 0 )
00131                 {
00132                         m_nGender = 2;
00133                 }
00134 
00135                 int nAge = 0;
00136                 _stscanf( strAge, _T("%i"), &nAge );
00137 
00138                 for ( int nAgeItem = 0 ; nAgeItem < m_wndAge.GetCount() ; nAgeItem ++ )
00139                 {
00140                         if ( m_wndAge.GetItemData( nAgeItem ) == nAge )
00141                         {
00142                                 m_nAge = nAgeItem;
00143                                 break;
00144                         }
00145                 }
00146         }
00147 
00148         if ( CXMLElement* pLocation = MyProfile.GetXML( _T("location") ) )
00149         {
00150                 if ( CXMLElement* pPolitical = pLocation->GetElementByName( _T("political") ) )
00151                 {
00152                         m_sLocCountry   = pPolitical->GetAttributeValue( _T("country") );
00153                         m_sLocCity              = pPolitical->GetAttributeValue( _T("city") ) + _T(", ")
00154                                                         + pPolitical->GetAttributeValue( _T("state") );
00155                 }
00156         }
00157 
00158         UpdateData( FALSE );
00159 
00160         return CWizardPage::OnSetActive();
00161 }
00162 
00163 void CWizardProfilePage::OnCloseUpCountry()
00164 {
00165         CWaitCursor pCursor;
00166 
00167         int nSel = m_wndCountry.GetCurSel();
00168         if ( nSel < 0 ) return;
00169         CWorldCountry* pCountry = (CWorldCountry*)m_wndCountry.GetItemData( nSel );
00170         if ( ! pCountry ) return;
00171 
00172         if ( m_wndCity.GetCount() ) m_wndCity.ResetContent();
00173 
00174         CWorldCity* pCity = pCountry->m_pCity;
00175         CString strCity;
00176 
00177         for ( int nCity = pCountry->m_nCity ; nCity ; nCity--, pCity++ )
00178         {
00179                 if ( pCity->m_sName.GetLength() )
00180                 {
00181                         if ( pCity->m_sState.GetLength() )
00182                                 strCity = pCity->m_sName + _T(", ") + pCity->m_sState;
00183                         else
00184                                 strCity = pCity->m_sName;
00185                 }
00186                 else if ( pCity->m_sState.GetLength() )
00187                 {
00188                         strCity = pCity->m_sState;
00189                 }
00190                 else
00191                 {
00192                         continue;
00193                 }
00194                 m_wndCity.SetItemData( m_wndCity.AddString( strCity ), (LPARAM)pCity );
00195         }
00196 }
00197 
00198 LRESULT CWizardProfilePage::OnWizardBack()
00199 {
00200         return CWizardPage::OnWizardBack();
00201 }
00202 
00203 LRESULT CWizardProfilePage::OnWizardNext()
00204 {
00205         CString strMessage;
00206 
00207         UpdateData( TRUE );
00208 
00209         if ( CXMLElement* pIdentity = MyProfile.GetXML( _T("identity"), TRUE ) )
00210         {
00211                 if ( CXMLElement* pHandle = pIdentity->GetElementByName( _T("handle"), TRUE ) )
00212                 {
00213                         pHandle->AddAttribute( _T("primary"), m_sNick );
00214                         if ( m_sNick.IsEmpty() ) pHandle->Delete();
00215                 }
00216         }
00217 
00218         if ( CXMLElement* pVitals = MyProfile.GetXML( _T("vitals"), TRUE ) )
00219         {
00220                 if ( m_nAge > 0 )
00221                 {
00222                         CString strAge;
00223                         strAge.Format( _T("%i"), m_wndAge.GetItemData( m_nAge ) );
00224                         pVitals->AddAttribute( _T("age"), strAge );
00225                 }
00226                 else
00227                 {
00228                         pVitals->DeleteAttribute( _T("age") );
00229                 }
00230 
00231                 if ( m_nGender == 1 || m_nGender == 3 )
00232                         pVitals->AddAttribute( _T("gender"), _T("male") );
00233                 else if ( m_nGender == 2 || m_nGender == 4 )
00234                         pVitals->AddAttribute( _T("gender"), _T("female") );
00235                 else
00236                         pVitals->DeleteAttribute( _T("gender") );
00237 
00238                 if ( pVitals->GetElementCount() == 0 &&
00239                          pVitals->GetAttributeCount() == 0 ) pVitals->Delete();
00240         }
00241 
00242         if ( CXMLElement* pLocation = MyProfile.GetXML( _T("location"), TRUE ) )
00243         {
00244                 if ( CXMLElement* pPolitical = pLocation->GetElementByName( _T("political"), TRUE ) )
00245                 {
00246                         if ( m_sLocCountry.GetLength() )
00247                         {
00248                                 pPolitical->AddAttribute( _T("country"), m_sLocCountry );
00249                         }
00250                         else
00251                         {
00252                                 pPolitical->DeleteAttribute( _T("country") );
00253                         }
00254 
00255                         int nPos = m_sLocCity.Find( _T(", ") );
00256 
00257                         if ( nPos >= 0 )
00258                         {
00259                                 pPolitical->AddAttribute( _T("city"), m_sLocCity.Left( nPos ) );
00260                                 pPolitical->AddAttribute( _T("state"), m_sLocCity.Mid( nPos + 2 ) );
00261                         }
00262                         else if ( m_sLocCity.GetLength() )
00263                         {
00264                                 pPolitical->AddAttribute( _T("city"), m_sLocCity );
00265                                 pPolitical->DeleteAttribute( _T("state") );
00266                         }
00267                         else
00268                         {
00269                                 pPolitical->DeleteAttribute( _T("city") );
00270                                 pPolitical->DeleteAttribute( _T("state") );
00271                         }
00272 
00273                         if ( pPolitical->GetElementCount() == 0 && pPolitical->GetAttributeCount() == 0 )
00274                                 pPolitical->Delete();
00275                 }
00276 
00277                 if ( CXMLElement* pCoordinates = pLocation->GetElementByName( _T("coordinates"), TRUE ) )
00278                 {
00279                         int nSel = m_wndCity.GetCurSel();
00280                         CWorldCity* pCity = (CWorldCity*)m_wndCity.GetItemData( m_wndCity.GetCurSel() );
00281 
00282                         if ( nSel >= 0 && pCity != NULL )
00283                         {
00284                                 CString strValue;
00285 
00286                                 strValue.Format( _T("%f"), pCity->m_nLatitude );
00287                                 pCoordinates->AddAttribute( _T("latitude"), strValue );
00288 
00289                                 strValue.Format( _T("%f"), pCity->m_nLongitude );
00290                                 pCoordinates->AddAttribute( _T("longitude"), strValue );
00291                         }
00292                         else
00293                         {
00294                                 pCoordinates->Delete();
00295                         }
00296                 }
00297 
00298                 if ( pLocation->GetElementCount() == 0 ) pLocation->Delete();
00299         }
00300 
00301         if ( MyProfile.GetNick().IsEmpty() )
00302         {
00303                 LoadString( strMessage, IDS_PROFILE_NO_NICK );
00304                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00305                 return -1;
00306         }
00307 
00308         if ( MyProfile.GetXML( _T("vitals") ) == NULL )
00309         {
00310                 LoadString( strMessage, IDS_PROFILE_NO_VITALS );
00311                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 ) != IDYES ) return -1;
00312         }
00313 
00314         if ( MyProfile.GetLocation().IsEmpty() )
00315         {
00316                 LoadString( strMessage, IDS_PROFILE_NO_LOCATION );
00317                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 ) != IDYES ) return -1;
00318         }
00319 
00320         MyProfile.Save();
00321 
00322         return 0;
00323 }

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