00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00045 END_MESSAGE_MAP()
00046
00047
00049
00050
00051 CFavouritesProfilePage::CFavouritesProfilePage() : CSettingsPage( CFavouritesProfilePage::IDD )
00052 {
00053
00054 m_sURL = _T("");
00055 m_sTitle = _T("");
00056
00057 }
00058
00059 CFavouritesProfilePage::~CFavouritesProfilePage()
00060 {
00061 }
00062
00063 void CFavouritesProfilePage::DoDataExchange(CDataExchange* pDX)
00064 {
00065 CSettingsPage::DoDataExchange(pDX);
00066
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
00073 }
00074
00076
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