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

PageProfileFavourites.cpp

Go to the documentation of this file.
00001 //
00002 // PageProfileFavourites.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 "PageProfileFavourites.h"
00027 #include "Skin.h"
00028 
00029 #ifdef _DEBUG
00030 #define new DEBUG_NEW
00031 #undef THIS_FILE
00032 static char THIS_FILE[] = __FILE__;
00033 #endif
00034 
00035 IMPLEMENT_DYNCREATE(CFavouritesProfilePage, CSettingsPage)
00036 
00037 BEGIN_MESSAGE_MAP(CFavouritesProfilePage, CSettingsPage)
00038         //{{AFX_MSG_MAP(CFavouritesProfilePage)
00039         ON_EN_CHANGE(IDC_WEB_NAME, OnChangeWebName)
00040         ON_EN_CHANGE(IDC_WEB_URL, OnChangeWebUrl)
00041         ON_BN_CLICKED(IDC_WEB_ADD, OnWebAdd)
00042         ON_BN_CLICKED(IDC_WEB_REMOVE, OnWebRemove)
00043         ON_NOTIFY(LVN_ITEMCHANGED, IDC_WEB_LIST, OnItemChangedWebList)
00044         //}}AFX_MSG_MAP
00045 END_MESSAGE_MAP()
00046 
00047 
00049 // CFavouritesProfilePage property page
00050 
00051 CFavouritesProfilePage::CFavouritesProfilePage() : CSettingsPage( CFavouritesProfilePage::IDD )
00052 {
00053         //{{AFX_DATA_INIT(CFavouritesProfilePage)
00054         m_sURL = _T("");
00055         m_sTitle = _T("");
00056         //}}AFX_DATA_INIT
00057 }
00058 
00059 CFavouritesProfilePage::~CFavouritesProfilePage()
00060 {
00061 }
00062 
00063 void CFavouritesProfilePage::DoDataExchange(CDataExchange* pDX)
00064 {
00065         CSettingsPage::DoDataExchange(pDX);
00066         //{{AFX_DATA_MAP(CFavouritesProfilePage)
00067         DDX_Control(pDX, IDC_WEB_REMOVE, m_wndRemove);
00068         DDX_Control(pDX, IDC_WEB_ADD, m_wndAdd);
00069         DDX_Control(pDX, IDC_WEB_LIST, m_wndList);
00070         DDX_Text(pDX, IDC_WEB_URL, m_sURL);
00071         DDX_Text(pDX, IDC_WEB_NAME, m_sTitle);
00072         //}}AFX_DATA_MAP
00073 }
00074 
00076 // CFavouritesProfilePage message handlers
00077 
00078 BOOL CFavouritesProfilePage::OnInitDialog()
00079 {
00080         CSettingsPage::OnInitDialog();
00081 
00082         m_gdiImageList.Create( 16, 16, ILC_COLOR16|ILC_MASK, 1, 1 );
00083         HICON hIcon = AfxGetApp()->LoadIcon( IDI_WEB_URL );
00084         if ( theApp.m_bRTL ) hIcon = CreateMirroredIcon( hIcon );
00085         m_gdiImageList.Add( hIcon );
00086 
00087         CRect rc;
00088         m_wndList.GetClientRect( &rc );
00089         rc.right -= GetSystemMetrics( SM_CXVSCROLL ) + 1;
00090 
00091         m_wndList.SetImageList( &m_gdiImageList, LVSIL_SMALL );
00092         m_wndList.InsertColumn( 0, _T("Name"), LVCFMT_LEFT, rc.right / 2, -1 );
00093         m_wndList.InsertColumn( 1, _T("URL"), LVCFMT_LEFT, rc.right / 2, 0 );
00094 
00095         m_wndList.SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE,
00096                 LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT );
00097 
00098         if ( CXMLElement* pBookmarks = MyProfile.GetXML( _T("bookmarks") ) )
00099         {
00100                 for ( POSITION pos = pBookmarks->GetElementIterator() ; pos ; )
00101                 {
00102                         CXMLElement* pBookmark = pBookmarks->GetNextElement( pos );
00103 
00104                         if ( pBookmark->IsNamed( _T("bookmark") ) )
00105                         {
00106                                 CString strTitle        = pBookmark->GetAttributeValue( _T("title") );
00107                                 CString strURL          = pBookmark->GetAttributeValue( _T("url") );
00108                                 if ( theApp.m_bRTL ) strURL = _T("\x202A") + strURL;
00109 
00110                                 int nItem = m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE,
00111                                         m_wndList.GetItemCount(), strTitle, 0, 0, 0, 0 );
00112                                 m_wndList.SetItemText( nItem, 1, strURL );
00113                         }
00114                 }
00115         }
00116 
00117         Skin.Translate( _T("CFavouritesProfileList"), m_wndList.GetHeaderCtrl() );
00118         UpdateData( FALSE );
00119         m_wndAdd.EnableWindow( FALSE );
00120         m_wndRemove.EnableWindow( FALSE );
00121 
00122         return TRUE;
00123 }
00124 
00125 void CFavouritesProfilePage::OnChangeWebName()
00126 {
00127         UpdateData();
00128         m_wndAdd.EnableWindow( m_sTitle.GetLength() && m_sURL.Find( _T("http://") ) == 0 );
00129 }
00130 
00131 void CFavouritesProfilePage::OnChangeWebUrl()
00132 {
00133         UpdateData();
00134         m_wndAdd.EnableWindow( m_sTitle.GetLength() && m_sURL.Find( _T("http://") ) == 0 );
00135 }
00136 
00137 void CFavouritesProfilePage::OnItemChangedWebList(NMHDR* pNMHDR, LRESULT* pResult)
00138 {
00139         *pResult = 0;
00140         m_wndRemove.EnableWindow( m_wndList.GetSelectedCount() > 0 );
00141 }
00142 
00143 void CFavouritesProfilePage::OnWebAdd()
00144 {
00145         UpdateData();
00146 
00147         int nItem = m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE,
00148                 m_wndList.GetItemCount(), m_sTitle, 0, 0, 0, 0 );
00149         m_wndList.SetItemText( nItem, 1, theApp.m_bRTL ? _T("\x202A") + m_sURL : m_sURL );
00150 
00151         m_sTitle.Empty();
00152         m_sURL.Empty();
00153 
00154         UpdateData( FALSE );
00155         m_wndAdd.EnableWindow( FALSE );
00156 }
00157 
00158 void CFavouritesProfilePage::OnWebRemove()
00159 {
00160         for ( int nItem = m_wndList.GetItemCount() - 1 ; nItem >= 0 ; nItem-- )
00161         {
00162                 if ( m_wndList.GetItemState( nItem, LVIS_SELECTED ) )
00163                 {
00164                         m_wndList.DeleteItem( nItem );
00165                 }
00166         }
00167 
00168         m_wndRemove.EnableWindow( FALSE );
00169 }
00170 
00171 void CFavouritesProfilePage::OnOK()
00172 {
00173         UpdateData();
00174 
00175         if ( CXMLElement* pBookmarks = MyProfile.GetXML( _T("bookmarks"), TRUE ) )
00176         {
00177                 pBookmarks->DeleteAllElements();
00178 
00179                 for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00180                 {
00181                         CXMLElement* pBookmark = pBookmarks->AddElement( _T("bookmark") );
00182                         pBookmark->AddAttribute( _T("title"), m_wndList.GetItemText( nItem, 0 ) );
00183                         pBookmark->AddAttribute( _T("url"), m_wndList.GetItemText( nItem, 1 ) );
00184                 }
00185 
00186                 if ( pBookmarks->GetElementCount() == 0 ) pBookmarks->Delete();
00187         }
00188 
00189         CSettingsPage::OnOK();
00190 }
00191 

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