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 "DlgDeleteFile.h"
00025
00026 #include "Library.h"
00027 #include "SharedFile.h"
00028 #include "Download.h"
00029
00030 IMPLEMENT_DYNAMIC(CDeleteFileDlg, CSkinDialog)
00031
00032 BEGIN_MESSAGE_MAP(CDeleteFileDlg, CSkinDialog)
00033 ON_WM_CTLCOLOR()
00034 ON_BN_CLICKED(IDC_DELETE_ALL, OnDeleteAll)
00035 ON_BN_CLICKED(IDC_RATE_VALUE_0, OnBnClickedRateValue)
00036 ON_BN_CLICKED(IDC_RATE_VALUE_1, OnBnClickedRateValue)
00037 ON_BN_CLICKED(IDC_RATE_VALUE_2, OnBnClickedRateValue)
00038 ON_BN_CLICKED(IDC_RATE_VALUE_3, OnBnClickedRateValue)
00039 END_MESSAGE_MAP()
00040
00041
00042 CDeleteFileDlg::CDeleteFileDlg(CWnd* pParent) : CSkinDialog( CDeleteFileDlg::IDD, pParent )
00043 {
00044 m_nRateValue = 0;
00045 m_bAll = FALSE;
00046 }
00047
00048 CDeleteFileDlg::~CDeleteFileDlg()
00049 {
00050 }
00051
00052 void CDeleteFileDlg::DoDataExchange(CDataExchange* pDX)
00053 {
00054 CSkinDialog::DoDataExchange(pDX);
00055 DDX_Control(pDX, IDC_FILE_NAME, m_wndName);
00056 DDX_Control(pDX, IDC_RATE_COMMENTS, m_wndComments);
00057 DDX_Control(pDX, IDC_RATE_PROMPT, m_wndPrompt);
00058 DDX_Text(pDX, IDC_RATE_COMMENTS, m_sComments);
00059 DDX_Text(pDX, IDC_FILE_NAME, m_sName);
00060 DDX_Radio(pDX, IDC_RATE_VALUE_0, m_nRateValue);
00061 DDX_Control(pDX, IDOK, m_wndOK);
00062 DDX_Control(pDX, IDC_DELETE_ALL, m_wndAll);
00063 }
00064
00065 BOOL CDeleteFileDlg::OnInitDialog()
00066 {
00067 CSkinDialog::OnInitDialog();
00068
00069 SkinMe( NULL, ID_LIBRARY_DELETE );
00070
00071 if ( m_bAll )
00072 {
00073 m_wndAll.EnableWindow( TRUE );
00074 m_bAll = FALSE;
00075 }
00076
00077 return FALSE;
00078 }
00079
00080 HBRUSH CDeleteFileDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00081 {
00082 HBRUSH hbr = CSkinDialog::OnCtlColor( pDC, pWnd, nCtlColor );
00083
00084 if ( pWnd == &m_wndName )
00085 {
00086 pDC->SelectObject( &theApp.m_gdiFontBold );
00087 }
00088
00089 return hbr;
00090 }
00091
00092 void CDeleteFileDlg::OnBnClickedRateValue()
00093 {
00094 UpdateData();
00095
00096 switch ( m_nRateValue )
00097 {
00098 case 0:
00099 m_sComments.Empty();
00100 break;
00101 case 1:
00102 m_sComments = _T("Incorrectly named \"") + m_sName + _T("\"");
00103 break;
00104 case 2:
00105 m_sComments = _T("Very poor quality");
00106 break;
00107 case 3:
00108 m_sComments = _T("Fake/corrupt");
00109 break;
00110 }
00111
00112 m_wndComments.SetWindowText( m_sComments );
00113
00114 BOOL bComments = ( m_nRateValue > 0 || m_sComments.GetLength() );
00115
00116 if ( bComments != m_wndComments.IsWindowEnabled() )
00117 {
00118 m_wndPrompt.EnableWindow( bComments );
00119 m_wndComments.EnableWindow( bComments );
00120 }
00121
00122 if ( bComments )
00123 {
00124 m_wndComments.SetFocus();
00125 m_wndComments.SetSel( 0, m_sComments.GetLength() );
00126 }
00127 }
00128
00129 void CDeleteFileDlg::OnDeleteAll()
00130 {
00131 if ( m_nRateValue != 1 ) m_bAll = TRUE;
00132 CDialog::OnOK();
00133 }
00134
00135 void CDeleteFileDlg::Apply(CLibraryFile* pFile)
00136 {
00137 if ( m_nRateValue > 0 || m_sComments.GetLength() > 0 )
00138 {
00139 if ( m_sComments.GetLength() > 0 )
00140 pFile->m_sComments = m_sComments;
00141
00142 switch ( m_nRateValue )
00143 {
00144 case 1:
00145
00146 break;
00147 case 2:
00148 pFile->m_nRating = 2;
00149 break;
00150 case 3:
00151 pFile->m_nRating = 1;
00152 break;
00153 }
00154
00155 pFile->SaveMetadata();
00156 }
00157 }
00158
00159 void CDeleteFileDlg::Create(CDownload* pDownload, BOOL bShare)
00160 {
00161 if ( ! pDownload->m_bSHA1 && ! pDownload->m_bTiger && ! pDownload->m_bED2K ) return;
00162 if ( m_sComments.IsEmpty() ) return;
00163
00164 CSingleLock oLock( &Library.m_pSection );
00165 if ( !oLock.Lock( 500 ) ) return;
00166
00167 CLibraryFile* pFile = NULL;
00168
00169 if ( pFile == NULL && pDownload->m_bSHA1 )
00170 pFile = LibraryMaps.LookupFileBySHA1( &pDownload->m_pSHA1 );
00171 if ( pFile == NULL && pDownload->m_bTiger )
00172 pFile = LibraryMaps.LookupFileByTiger( &pDownload->m_pTiger );
00173 if ( pFile == NULL && pDownload->m_bED2K )
00174 pFile = LibraryMaps.LookupFileByED2K( &pDownload->m_pED2K );
00175
00176 if ( pFile == NULL )
00177 {
00178 pFile = new CLibraryFile( NULL, pDownload->m_sRemoteName );
00179 pFile->m_nSize = pDownload->m_nSize;
00180 pFile->m_bSHA1 = pDownload->m_bSHA1;
00181 pFile->m_pSHA1 = pDownload->m_pSHA1;
00182 pFile->m_bTiger = pDownload->m_bTiger;
00183 pFile->m_pTiger = pDownload->m_pTiger;
00184 pFile->m_bMD5 = pDownload->m_bMD5;
00185 pFile->m_pMD5 = pDownload->m_pMD5;
00186 pFile->m_bED2K = pDownload->m_bED2K;
00187 pFile->m_pED2K = pDownload->m_pED2K;
00188 pFile->m_bShared = bShare ? TS_TRUE : TS_FALSE;
00189 pFile->Ghost();
00190 }
00191
00192 Apply( pFile );
00193
00194 Library.Update();
00195 }