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 "Settings.h"
00025 #include "Library.h"
00026 #include "SharedFile.h"
00027 #include "PageFileSources.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(CFileSourcesPage, CFilePropertiesPage)
00037
00038 BEGIN_MESSAGE_MAP(CFileSourcesPage, CFilePropertiesPage)
00039
00040 ON_NOTIFY(LVN_ITEMCHANGED, IDC_FILE_SOURCES, OnItemChangedFileSources)
00041 ON_EN_CHANGE(IDC_FILE_SOURCE, OnChangeFileSource)
00042 ON_BN_CLICKED(IDC_SOURCE_REMOVE, OnSourceRemove)
00043 ON_BN_CLICKED(IDC_SOURCE_NEW, OnSourceNew)
00044
00045 END_MESSAGE_MAP()
00046
00047
00049
00050
00051 CFileSourcesPage::CFileSourcesPage() : CFilePropertiesPage(CFileSourcesPage::IDD)
00052 {
00053
00054 m_sSource = _T("");
00055
00056 }
00057
00058 CFileSourcesPage::~CFileSourcesPage()
00059 {
00060 }
00061
00062 void CFileSourcesPage::DoDataExchange(CDataExchange* pDX)
00063 {
00064 CFilePropertiesPage::DoDataExchange(pDX);
00065
00066 DDX_Control(pDX, IDC_SOURCE_REMOVE, m_wndRemove);
00067 DDX_Control(pDX, IDC_SOURCE_NEW, m_wndNew);
00068 DDX_Control(pDX, IDC_FILE_SOURCES, m_wndList);
00069 DDX_Text(pDX, IDC_FILE_SOURCE, m_sSource);
00070
00071 }
00072
00074
00075
00076 BOOL CFileSourcesPage::OnInitDialog()
00077 {
00078 CFilePropertiesPage::OnInitDialog();
00079
00080 CRect rc;
00081 m_wndList.GetClientRect( &rc );
00082 rc.right -= GetSystemMetrics( SM_CXVSCROLL );
00083 m_wndList.InsertColumn( 0, _T("URL"), LVCFMT_LEFT, rc.right - 128, -1 );
00084 m_wndList.InsertColumn( 1, _T("Expires"), LVCFMT_RIGHT, 128, 0 );
00085
00086 m_gdiImageList.Create( 16, 16, ILC_COLOR16|ILC_MASK, 1, 1 );
00087 HICON hIcon;
00088 hIcon = theApp.LoadIcon( IDI_WEB_URL );
00089 if ( theApp.m_bRTL ) hIcon = CreateMirroredIcon( hIcon );
00090 m_gdiImageList.Add( hIcon );
00091 m_wndList.SetImageList( &m_gdiImageList, LVSIL_SMALL );
00092
00093 m_wndList.SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE,
00094 LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT );
00095
00096 {
00097 CQuickLock oLock( Library.m_pSection );
00098 CLibraryFile* pFile = GetFile();
00099 if ( pFile == NULL ) return TRUE;
00100
00101 for ( POSITION pos = pFile->m_pSources.GetHeadPosition() ; pos ; )
00102 {
00103 AddSource( (CSharedSource*)pFile->m_pSources.GetNext( pos ) );
00104 }
00105 }
00106
00107 Skin.Translate( _T("CFileSourcesPageList"), m_wndList.GetHeaderCtrl() );
00108 m_wndNew.EnableWindow( FALSE );
00109 m_wndRemove.EnableWindow( FALSE );
00110
00111 return TRUE;
00112 }
00113
00114 void CFileSourcesPage::AddSource(CSharedSource* pSource)
00115 {
00116 LV_ITEM pItem;
00117 CString strURL = pSource->m_sURL;
00118 if ( theApp.m_bRTL ) strURL = _T("\x202A") + strURL;
00119
00120 ZeroMemory( &pItem, sizeof(pItem) );
00121 pItem.mask = LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE;
00122 pItem.pszText = (LPTSTR)(LPCTSTR)strURL;
00123 pItem.iImage = 0;
00124 pItem.lParam = (LPARAM)pSource;
00125 pItem.iItem = m_wndList.GetItemCount();
00126 pItem.iItem = m_wndList.InsertItem( &pItem );
00127
00128 FILETIME pFileTime = pSource->m_pTime;
00129 CString strDate, strTime;
00130 SYSTEMTIME pSystemTime;
00131
00132 (LONGLONG&)pFileTime += (LONGLONG)Settings.Library.SourceExpire * 10000000;
00133 FileTimeToSystemTime( &pFileTime, &pSystemTime );
00134 SystemTimeToTzSpecificLocalTime( NULL, &pSystemTime, &pSystemTime );
00135
00136 GetDateFormat( LOCALE_USER_DEFAULT, 0, &pSystemTime, _T("yyyy-MM-dd"), strDate.GetBuffer( 64 ), 64 );
00137 GetTimeFormat( LOCALE_USER_DEFAULT, 0, &pSystemTime, _T("HH:mm"), strTime.GetBuffer( 64 ), 64 );
00138 strDate.ReleaseBuffer(); strTime.ReleaseBuffer();
00139
00140 strDate += ' ';
00141 strDate += strTime;
00142
00143 m_wndList.SetItemText( pItem.iItem, 1, strDate );
00144 }
00145
00146 void CFileSourcesPage::OnItemChangedFileSources(NMHDR* pNMHDR, LRESULT* pResult)
00147 {
00148 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
00149 m_wndRemove.EnableWindow( m_wndList.GetSelectedCount() > 0 );
00150 *pResult = 0;
00151 }
00152
00153 void CFileSourcesPage::OnChangeFileSource()
00154 {
00155 UpdateData();
00156 m_wndNew.EnableWindow( m_sSource.Find( _T("http://") ) == 0 );
00157 }
00158
00159 void CFileSourcesPage::OnSourceRemove()
00160 {
00161 {
00162 CQuickLock oLock( Library.m_pSection );
00163 CLibraryFile* pFile = GetFile();
00164 if ( pFile == NULL ) return;
00165
00166 for ( int nItem ; ( nItem = m_wndList.GetNextItem( -1, LVNI_SELECTED ) ) >= 0 ; )
00167 {
00168 CSharedSource* pSource = (CSharedSource*)m_wndList.GetItemData( nItem );
00169
00170 if ( POSITION pos = pFile->m_pSources.Find( pSource ) )
00171 {
00172 delete pSource;
00173 pFile->m_pSources.RemoveAt( pos );
00174 }
00175
00176 m_wndList.DeleteItem( nItem );
00177 }
00178 Library.Update();
00179 }
00180
00181 m_wndRemove.EnableWindow( FALSE );
00182 }
00183
00184 void CFileSourcesPage::OnSourceNew()
00185 {
00186 UpdateData();
00187
00188 if ( m_sSource.Find( _T("http://") ) == 0 )
00189 {
00190 CSingleLock oLock( &Library.m_pSection, TRUE );
00191 if ( CLibraryFile* pFile = GetFile() )
00192 {
00193 CSharedSource* pSource = pFile->AddAlternateSources( m_sSource );
00194 m_sSource.Empty();
00195 Library.Update();
00196 oLock.Unlock();
00197 UpdateData( FALSE );
00198 if ( pSource ) AddSource( pSource );
00199 }
00200 }
00201 }