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

PageProfileContact.cpp

Go to the documentation of this file.
00001 //
00002 // PageProfileContact.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 "GProfile.h"
00025 #include "XML.h"
00026 #include "PageProfileContact.h"
00027 
00028 #ifdef _DEBUG
00029 #define new DEBUG_NEW
00030 #undef THIS_FILE
00031 static char THIS_FILE[] = __FILE__;
00032 #endif
00033 
00034 IMPLEMENT_DYNCREATE(CContactProfilePage, CSettingsPage)
00035 
00036 BEGIN_MESSAGE_MAP(CContactProfilePage, CSettingsPage)
00037         //{{AFX_MSG_MAP(CContactProfilePage)
00038         //}}AFX_MSG_MAP
00039 END_MESSAGE_MAP()
00040 
00041 
00043 // CContactProfilePage property page
00044 
00045 CContactProfilePage::CContactProfilePage() : CSettingsPage( CContactProfilePage::IDD )
00046 {
00047         //{{AFX_DATA_INIT(CContactProfilePage)
00048         //}}AFX_DATA_INIT
00049 }
00050 
00051 CContactProfilePage::~CContactProfilePage()
00052 {
00053 }
00054 
00055 void CContactProfilePage::DoDataExchange(CDataExchange* pDX)
00056 {
00057         CSettingsPage::DoDataExchange(pDX);
00058         //{{AFX_DATA_MAP(CContactProfilePage)
00059         DDX_Text(pDX, IDC_PROFILE_EMAIL, m_sEmail);
00060         DDX_Text(pDX, IDC_PROFILE_AOL, m_sAOL);
00061         DDX_Text(pDX, IDC_PROFILE_ICQ, m_sICQ);
00062         DDX_Text(pDX, IDC_PROFILE_YAHOO, m_sYahoo);
00063         DDX_Text(pDX, IDC_PROFILE_MSN, m_sMSN);
00064         //}}AFX_DATA_MAP
00065         DDX_Text(pDX, IDC_PROFILE_JABBER, m_sJabber);
00066 }
00067 
00069 // CContactProfilePage message handlers
00070 
00071 BOOL CContactProfilePage::OnInitDialog()
00072 {
00073         CSettingsPage::OnInitDialog();
00074 
00075         if ( CXMLElement* pContacts = MyProfile.GetXML( _T("contacts") ) )
00076         {
00077                 for ( POSITION pos1 = pContacts->GetElementIterator() ; pos1 ; )
00078                 {
00079                         CXMLElement* pGroup = pContacts->GetNextElement( pos1 );
00080 
00081                         if ( pGroup->IsNamed( _T("group") ) )
00082                         {
00083                                 CString strGroup = pGroup->GetAttributeValue( _T("class") );
00084 
00085                                 if ( CXMLElement* pAddress = pGroup->GetElementByName( _T("address") ) )
00086                                 {
00087                                         CString strAddress = pAddress->GetAttributeValue( _T("content") );
00088 
00089                                         if ( strGroup.CompareNoCase( _T("email") ) == 0 )
00090                                         {
00091                                                 m_sEmail = strAddress;
00092                                         }
00093                                         else if ( strGroup.CompareNoCase( _T("msn") ) == 0 )
00094                                         {
00095                                                 m_sMSN = strAddress;
00096                                         }
00097                                         else if ( strGroup.CompareNoCase( _T("yahoo") ) == 0 )
00098                                         {
00099                                                 m_sYahoo = strAddress;
00100                                         }
00101                                         else if ( strGroup.CompareNoCase( _T("icq") ) == 0 )
00102                                         {
00103                                                 m_sICQ = strAddress;
00104                                         }
00105                                         else if ( strGroup.CompareNoCase( _T("aol") ) == 0 )
00106                                         {
00107                                                 m_sAOL = strAddress;
00108                                         }
00109                                         else if ( strGroup.CompareNoCase( _T("jabber") ) == 0 )
00110                                         {
00111                                                 m_sJabber = strAddress;
00112                                         }
00113                                 }
00114                         }
00115                 }
00116         }
00117 
00118         if ( m_sEmail.Find( '@' ) < 0 || m_sEmail.Find( '.' ) < 0 ) m_sEmail.Empty();
00119 
00120         UpdateData( FALSE );
00121 
00122         return TRUE;
00123 }
00124 
00125 void CContactProfilePage::OnOK()
00126 {
00127         UpdateData();
00128 
00129         if ( m_sEmail.Find( '@' ) < 0 || m_sEmail.Find( '.' ) < 0 ) m_sEmail.Empty();
00130 
00131         AddAddress( _T("Email"), _T("Primary"), m_sEmail );
00132         AddAddress( _T("MSN"), _T("Primary"), m_sMSN );
00133         AddAddress( _T("Yahoo"), _T("Primary"), m_sYahoo );
00134         AddAddress( _T("ICQ"), _T("Primary"), m_sICQ );
00135         AddAddress( _T("AOL"), _T("Primary"), m_sAOL );
00136         AddAddress( _T("Jabber"), _T("Primary"), m_sJabber );
00137 }
00138 
00139 void CContactProfilePage::AddAddress(LPCTSTR pszClass, LPCTSTR pszName, LPCTSTR pszAddress)
00140 {
00141         if ( CXMLElement* pContacts = MyProfile.GetXML( _T("contacts"), TRUE ) )
00142         {
00143                 for ( POSITION pos1 = pContacts->GetElementIterator() ; pos1 ; )
00144                 {
00145                         CXMLElement* pGroup = pContacts->GetNextElement( pos1 );
00146 
00147                         if ( pGroup->IsNamed( _T("group") ) &&
00148                                  pGroup->GetAttributeValue( _T("class") ).CompareNoCase( pszClass ) == 0 )
00149                         {
00150                                 for ( POSITION pos2 = pGroup->GetElementIterator() ; pos2 ; )
00151                                 {
00152                                         CXMLElement* pAddress = pGroup->GetNextElement( pos2 );
00153 
00154                                         if ( pAddress->IsNamed( _T("address") ) &&
00155                                                  pAddress->GetAttributeValue( _T("name") ).CompareNoCase( pszName ) == 0 )
00156                                         {
00157                                                 if ( pszAddress && *pszAddress )
00158                                                 {
00159                                                         pAddress->AddAttribute( _T("content"), pszAddress );
00160                                                         return;
00161                                                 }
00162                                                 else
00163                                                 {
00164                                                         pAddress->Delete();
00165                                                         break;
00166                                                 }
00167                                         }
00168                                 }
00169 
00170                                 if ( pszAddress && *pszAddress )
00171                                 {
00172                                         CXMLElement* pAddress = pGroup->AddElement( _T("address") );
00173                                         pAddress->AddAttribute( _T("name"), pszName );
00174                                         pAddress->AddAttribute( _T("content"), pszAddress );
00175                                 }
00176                                 else if ( pGroup->GetElementCount() == 0 )
00177                                 {
00178                                         pGroup->Delete();
00179                                 }
00180                                 break;
00181                         }
00182                 }
00183 
00184                 if ( pszAddress && *pszAddress )
00185                 {
00186                         CXMLElement* pGroup = pContacts->AddElement( _T("group") );
00187                         pGroup->AddAttribute( _T("class"), pszClass );
00188 
00189                         CXMLElement* pAddress = pGroup->AddElement( _T("address") );
00190                         pAddress->AddAttribute( _T("name"), pszName );
00191                         pAddress->AddAttribute( _T("content"), pszAddress );
00192                 }
00193                 else if ( pContacts->GetElementCount() == 0 )
00194                 {
00195                         pContacts->Delete();
00196                 }
00197         }
00198 }

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