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

DlgDownloadEdit.cpp

Go to the documentation of this file.
00001 //
00002 // DlgDownloadEdit.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 "Download.h"
00025 #include "Downloads.h"
00026 #include "Transfers.h"
00027 #include "DlgDownloadEdit.h"
00028 #include "DlgTorrentTracker.h"
00029 
00030 #include "SHA.h"
00031 #include "ED2K.h"
00032 #include "TigerTree.h"
00033 
00034 IMPLEMENT_DYNAMIC(CDownloadEditDlg, CSkinDialog)
00035 
00036 BEGIN_MESSAGE_MAP(CDownloadEditDlg, CSkinDialog)
00037         ON_WM_CTLCOLOR()
00038         ON_WM_SETCURSOR()
00039         ON_WM_LBUTTONUP()
00040         ON_BN_CLICKED(IDC_TORRENT_INFO, OnTorrentInfo)
00041         ON_BN_CLICKED(IDC_ERASE, OnErase)
00042 END_MESSAGE_MAP()
00043 
00044 
00046 // CDownloadEditDlg construction
00047 
00048 CDownloadEditDlg::CDownloadEditDlg(CDownload* pDownload, CWnd* pParent) : CSkinDialog( CDownloadEditDlg::IDD, pParent )
00049 {
00050         m_pDownload = pDownload;
00051 }
00052 
00053 CDownloadEditDlg::~CDownloadEditDlg()
00054 {
00055 }
00056 
00057 void CDownloadEditDlg::DoDataExchange(CDataExchange* pDX)
00058 {
00059         CSkinDialog::DoDataExchange(pDX);
00060         DDX_Text(pDX, IDC_NAME, m_sName);
00061         DDX_Text(pDX, IDC_URN_SHA1, m_sSHA1);
00062         DDX_Text(pDX, IDC_URN_TIGER, m_sTiger);
00063         DDX_Text(pDX, IDC_URN_ED2K, m_sED2K);
00064         DDX_Control(pDX, IDC_FORGET_VERIFY, m_wndForgetVerify);
00065         DDX_Control(pDX, IDC_FORGET_SOURCES, m_wndForgetSources);
00066         DDX_Text(pDX, IDC_ERASE_FROM, m_sEraseFrom);
00067         DDX_Text(pDX, IDC_ERASE_TO, m_sEraseTo);
00068         DDX_Control(pDX, IDC_TORRENT_INFO, m_wndTorrent);
00069         DDX_Control(pDX, IDC_COMPLETE_AND_VERIFY, m_wndCompleteVerify);
00070 }
00071 
00073 // CDownloadEditDlg message handlers
00074 
00075 BOOL CDownloadEditDlg::OnInitDialog()
00076 {
00077         CSkinDialog::OnInitDialog();
00078 
00079         SkinMe( NULL, ID_TOOLS_DOWNLOAD );
00080 
00081         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00082 
00083         if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() )
00084         {
00085                 PostMessage( WM_CLOSE );
00086                 return TRUE;
00087         }
00088 
00089         m_sName = m_pDownload->m_sRemoteName;
00090 
00091         if ( m_pDownload->m_bSHA1 )
00092                 m_sSHA1 = CSHA::HashToString( &m_pDownload->m_pSHA1 );
00093         if ( m_pDownload->m_bTiger )
00094                 m_sTiger = CTigerNode::HashToString( &m_pDownload->m_pTiger );
00095         if ( m_pDownload->m_bED2K )
00096                 m_sED2K = CED2K::HashToString( &m_pDownload->m_pED2K );
00097 
00098         m_wndTorrent.EnableWindow( m_pDownload->m_pTorrent.IsAvailable() );
00099 
00100         UpdateData( FALSE );
00101 
00102         return TRUE;
00103 }
00104 
00105 HBRUSH CDownloadEditDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00106 {
00107         HBRUSH hbr = CSkinDialog::OnCtlColor( pDC, pWnd, nCtlColor );
00108 
00109         if ( pWnd == &m_wndForgetVerify || pWnd == &m_wndForgetSources || pWnd == &m_wndCompleteVerify )
00110         {
00111                 pDC->SelectObject( &theApp.m_gdiFontLine );
00112                 pDC->SetTextColor( RGB( 0, 0, 255 ) );
00113         }
00114 
00115         return hbr;
00116 }
00117 
00118 BOOL CDownloadEditDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00119 {
00120         CRect rcCtrl1, rcCtrl2, rcCtrl3;
00121         CPoint point;
00122 
00123         GetCursorPos( &point );
00124     m_wndForgetVerify.GetWindowRect( &rcCtrl1 );
00125         m_wndForgetSources.GetWindowRect( &rcCtrl2 );
00126         m_wndCompleteVerify.GetWindowRect( &rcCtrl3 );
00127 
00128         if ( rcCtrl1.PtInRect( point ) || rcCtrl2.PtInRect( point ) || rcCtrl3.PtInRect( point ) )
00129         {
00130                 SetCursor( AfxGetApp()->LoadCursor( IDC_HAND ) );
00131                 return TRUE;
00132         }
00133 
00134         return CSkinDialog::OnSetCursor( pWnd, nHitTest, message );
00135 }
00136 
00137 void CDownloadEditDlg::OnLButtonUp(UINT nFlags, CPoint point)
00138 {
00139         CSkinDialog::OnLButtonUp(nFlags, point);
00140 
00141         CRect rcCtrl1, rcCtrl2, rcCtrl3;
00142 
00143         m_wndForgetVerify.GetWindowRect( &rcCtrl1 );
00144         ScreenToClient( &rcCtrl1 );
00145         m_wndForgetSources.GetWindowRect( &rcCtrl2 );
00146         ScreenToClient( &rcCtrl2 );
00147         m_wndCompleteVerify.GetWindowRect( &rcCtrl3 );
00148         ScreenToClient( &rcCtrl3 );
00149 
00150         if ( rcCtrl1.PtInRect( point ) )
00151         {
00152                 if ( ! Commit() ) return;
00153 
00154                 CString strMessage;
00155                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_FORGET_VERIFY );
00156                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return;
00157 
00158                 CSingleLock pLock( &Transfers.m_pSection, TRUE );
00159                 if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return;
00160                 m_pDownload->ClearVerification();
00161         }
00162         else if ( rcCtrl2.PtInRect( point ) )
00163         {
00164                 if ( ! Commit() ) return;
00165 
00166                 CString strMessage;
00167                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_FORGET_SOURCES );
00168                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return;
00169 
00170                 CSingleLock pLock( &Transfers.m_pSection, TRUE );
00171                 if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return;
00172 
00173                 m_pDownload->CloseTransfers();
00174                 m_pDownload->ClearSources();
00175                 m_pDownload->SetModified();
00176         }
00177         else if ( rcCtrl3.PtInRect( point ) )
00178         {
00179                 if ( ! Commit() ) return;
00180 
00181                 CSingleLock pLock( &Transfers.m_pSection, TRUE );
00182                 CString strMessage;
00183 
00184                 if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return;
00185 
00186                 if ( m_pDownload->NeedTigerTree() && m_pDownload->NeedHashset() && ! m_pDownload->m_bBTH )
00187                 {
00188                         pLock.Unlock();
00189                         LoadString( strMessage, IDS_DOWNLOAD_EDIT_COMPLETE_NOHASH );
00190                         AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00191                         return;
00192                 }
00193                 else
00194                 {
00195                         pLock.Unlock();
00196             LoadString( strMessage, IDS_DOWNLOAD_EDIT_COMPLETE_VERIFY );
00197                         if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return;
00198                 }
00199 
00200                 pLock.Lock();
00201                 if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return;
00202 
00203                 m_pDownload->MakeComplete();
00204                 m_pDownload->ResetVerification();
00205                 m_pDownload->SetModified();
00206         }
00207 }
00208 
00209 void CDownloadEditDlg::OnTorrentInfo()
00210 {
00211         int nStart;
00212         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00213 
00214         if ( ! Downloads.Check( m_pDownload ) ) return;
00215         if ( ! m_pDownload->m_pTorrent.IsAvailable() ) return;
00216 
00217         nStart = m_pDownload->m_nStartTorrentDownloads;
00218         CTorrentTrackerDlg dlg( &m_pDownload->m_pTorrent, &nStart );
00219         pLock.Unlock();
00220         dlg.DoModal();
00221 
00222         if ( pLock.Lock(250) )
00223         {
00224                 if ( Downloads.Check( m_pDownload ) ) m_pDownload->m_nStartTorrentDownloads = nStart;
00225         }
00226 }
00227 
00228 void CDownloadEditDlg::OnErase()
00229 {
00230         QWORD nFrom = 0, nTo = 0;
00231         CString strMessage;
00232 
00233         UpdateData();
00234 
00235         if ( _stscanf( m_sEraseFrom, _T("%I64i"), &nFrom ) != 1 ||
00236                  _stscanf( m_sEraseTo, _T("%I64i"), &nTo ) != 1 ||
00237                  nTo < nFrom )
00238         {
00239                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_BAD_RANGE );
00240                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00241                 return;
00242         }
00243 
00244         if ( ! Commit() ) return;
00245 
00246         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00247         if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return;
00248 
00249         m_pDownload->CloseTransfers();
00250         QWORD nErased = m_pDownload->EraseRange( nFrom, nTo + 1 - nFrom );
00251 
00252         if ( nErased > 0 )
00253         {
00254                 m_pDownload->ClearVerification();
00255                 pLock.Unlock();
00256                 CString strFormat;
00257                 LoadString( strFormat, IDS_DOWNLOAD_EDIT_ERASED );
00258                 strMessage.Format( strFormat, nErased );
00259                 AfxMessageBox( strMessage, MB_ICONINFORMATION );
00260         }
00261         else
00262         {
00263                 pLock.Unlock();
00264                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_CANT_ERASE );
00265                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00266         }
00267 }
00268 
00269 void CDownloadEditDlg::OnOK()
00270 {
00271         if ( ! Commit() ) return;
00272         CSkinDialog::OnOK();
00273 }
00274 
00275 BOOL CDownloadEditDlg::Commit()
00276 {
00277         CString strMessage;
00278 
00279         UpdateData();
00280 
00281         SHA1 pSHA1;
00282         BOOL bSHA1 = CSHA::HashFromString( m_sSHA1, &pSHA1 );
00283         TIGEROOT pTiger;
00284         BOOL bTiger = CTigerNode::HashFromString( m_sTiger, &pTiger );
00285         MD4 pED2K;
00286         BOOL bED2K = CED2K::HashFromString( m_sED2K, &pED2K );
00287 
00288         if ( m_sSHA1.GetLength() > 0 && ! bSHA1 )
00289         {
00290                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_BAD_SHA1 );
00291                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00292                 return FALSE;
00293         }
00294         else if ( m_sTiger.GetLength() > 0 && ! bTiger )
00295         {
00296                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_BAD_TIGER );
00297                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00298                 return FALSE;
00299         }
00300         else if ( m_sED2K.GetLength() > 0 && ! bED2K )
00301         {
00302                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_BAD_ED2K );
00303                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00304                 return FALSE;
00305         }
00306 
00307         CSingleLock pLock( &Transfers.m_pSection, TRUE );
00308     if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return FALSE;
00309 
00310         if ( m_pDownload->m_sRemoteName != m_sName )
00311         {
00312                 pLock.Unlock();
00313                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_RENAME );
00314                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
00315                 pLock.Lock();
00316                 if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return FALSE;
00317 
00318                 m_pDownload->Rename( m_sName );
00319         }
00320 
00321         if ( m_pDownload->m_bSHA1 != bSHA1 || ( bSHA1 && m_pDownload->m_pSHA1 != pSHA1 ) )
00322         {
00323                 pLock.Unlock();
00324                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_CHANGE_SHA1 );
00325                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
00326                 pLock.Lock();
00327                 if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return FALSE;
00328 
00329                 m_pDownload->m_bSHA1 = bSHA1;
00330                 m_pDownload->m_pSHA1 = pSHA1;
00331 
00332                 m_pDownload->CloseTransfers();
00333                 m_pDownload->ClearVerification();
00334         }
00335 
00336         if ( m_pDownload->m_bTiger != bTiger || ( bTiger && m_pDownload->m_pTiger != pTiger ) )
00337         {
00338                 pLock.Unlock();
00339                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_CHANGE_TIGER );
00340                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
00341                 pLock.Lock();
00342                 if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return FALSE;
00343 
00344                 m_pDownload->m_bTiger = bTiger;
00345                 m_pDownload->m_pTiger = pTiger;
00346 
00347                 m_pDownload->CloseTransfers();
00348                 m_pDownload->ClearVerification();
00349         }
00350 
00351         if ( m_pDownload->m_bED2K != bED2K || ( bED2K && m_pDownload->m_pED2K != pED2K ) )
00352         {
00353                 pLock.Unlock();
00354                 LoadString( strMessage, IDS_DOWNLOAD_EDIT_CHANGE_ED2K );
00355                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE;
00356                 pLock.Lock();
00357                 if ( ! Downloads.Check( m_pDownload ) || m_pDownload->IsMoving() ) return FALSE;
00358 
00359                 m_pDownload->m_bED2K = bED2K;
00360                 m_pDownload->m_pED2K = pED2K;
00361 
00362                 m_pDownload->CloseTransfers();
00363                 m_pDownload->ClearVerification();
00364         }
00365 
00366         return TRUE;
00367 }

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