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

DlgDownload.cpp

Go to the documentation of this file.
00001 //
00002 // DlgDownload.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 "ShareazaURL.h"
00026 #include "DlgDownload.h"
00027 #include "Settings.h"
00028 
00029 IMPLEMENT_DYNAMIC(CDownloadDlg, CSkinDialog)
00030 
00031 BEGIN_MESSAGE_MAP(CDownloadDlg, CSkinDialog)
00032         ON_EN_CHANGE(IDC_URL, OnChangeURL)
00033         ON_BN_CLICKED(IDC_TORRENT_FILE, OnTorrentFile)
00034 END_MESSAGE_MAP()
00035 
00036 
00038 // CDownloadDlg dialog
00039 
00040 CDownloadDlg::CDownloadDlg(CWnd* pParent, CDownload* pDownload) : CSkinDialog( CDownloadDlg::IDD, pParent )
00041 {
00042         m_pDownload = pDownload;
00043         m_pURL = NULL;
00044 }
00045 
00046 CDownloadDlg::~CDownloadDlg()
00047 {
00048         if ( m_pURL != NULL ) delete m_pURL;
00049 }
00050 
00051 void CDownloadDlg::DoDataExchange(CDataExchange* pDX)
00052 {
00053         CSkinDialog::DoDataExchange(pDX);
00054         DDX_Control(pDX, IDC_TORRENT_FILE, m_wndTorrentFile);
00055         DDX_Control(pDX, IDOK, m_wndOK);
00056         DDX_Control(pDX, IDC_URL, m_wndURL);
00057         DDX_Text(pDX, IDC_URL, m_sURL);
00058 }
00059 
00061 // CDownloadDlg message handlers
00062 
00063 BOOL CDownloadDlg::OnInitDialog() 
00064 {
00065         CSkinDialog::OnInitDialog();
00066         
00067         SkinMe( NULL, IDR_DOWNLOADSFRAME );
00068         m_wndTorrentFile.EnableWindow( m_pDownload == NULL );
00069         
00070         if ( OpenClipboard() )
00071         {
00072                 CString strClipboard;
00073 
00074                 if ( theApp.m_bNT )
00075                 {
00076                         // These OSes can handle unicode file names
00077                         if ( HGLOBAL hData = GetClipboardData( CF_UNICODETEXT ) )
00078                         {
00079                                 DWORD nData = GlobalSize( hData );
00080                                 LPVOID pData = GlobalLock( hData );
00081                                 
00082                                 LPTSTR pszData = new TCHAR[ nData + 1 ];
00083                                 CopyMemory( pszData, pData, nData );
00084                                 pszData[ nData ] = 0;
00085                                 strClipboard = pszData;
00086                                 delete [] pszData;
00087                                 GlobalUnlock( hData );
00088                         }
00089                 }
00090                 else
00091                 {
00092                         // We need to have the file "%" encoded to display the names. 
00093                         if ( HGLOBAL hData = GetClipboardData( CF_TEXT ) )
00094                         {
00095                                 DWORD nData = GlobalSize( hData );
00096                                 LPVOID pData = GlobalLock( hData );
00097                                 
00098                                 LPSTR pszData = new CHAR[ nData + 1 ];
00099                                 CopyMemory( pszData, pData, nData );
00100                                 pszData[ nData ] = 0;
00101                                 strClipboard = pszData;
00102                                 delete [] pszData;
00103                                 GlobalUnlock( hData );
00104                         }       
00105                 }
00106                         
00107                 // If we had something in the clipboard, see if it's a valid URL
00108                 if ( ! strClipboard.IsEmpty() )
00109                 {
00110                         strClipboard.Trim( _T(" \t\r\n") );
00111                                         
00112                         CShareazaURL pURL;
00113                         if( pURL.Parse( strClipboard ) )
00114                         {
00115                                 m_sURL = strClipboard;
00116                                 UpdateData( FALSE );
00117                                 OnChangeURL();
00118                         }
00119                 }
00120                 
00121                 CloseClipboard();
00122         }
00123         
00124         return TRUE;
00125 }
00126 
00127 void CDownloadDlg::OnChangeURL() 
00128 {
00129         UpdateData();
00130         
00131         if ( m_pDownload && FALSE )
00132         {
00133                 int nIP[4];
00134                 
00135                 if ( _stscanf( m_sURL, _T("%i.%i.%i.%i"), &nIP[0], &nIP[1], &nIP[2], &nIP[3] ) == 4 )
00136                 {
00137                         m_wndOK.EnableWindow( TRUE );
00138                         return;
00139                 }
00140         }
00141         
00142         CShareazaURL pURL;
00143         
00144         m_wndOK.EnableWindow( pURL.Parse( m_sURL ) &&
00145                 ( m_pDownload == NULL || pURL.m_nAction == CShareazaURL::uriSource ) );
00146 }
00147 
00148 void CDownloadDlg::OnTorrentFile() 
00149 {
00150         CFileDialog dlg( TRUE, _T("torrent"), ( Settings.Downloads.TorrentPath + "\\." ) , OFN_HIDEREADONLY,
00151                 _T("Torrent Files|*.torrent|All Files|*.*||"), this );
00152         
00153         if ( dlg.DoModal() != IDOK ) return;
00154         
00155         CBTInfo* pTorrent = new CBTInfo();
00156         
00157         if ( pTorrent->LoadTorrentFile( dlg.GetPathName() ) )
00158         {
00159                 CShareazaURL* pURL = new CShareazaURL( pTorrent );
00160                 
00161                 if ( AfxGetMainWnd()->PostMessage( WM_URL, (WPARAM)pURL ) )
00162                 {
00163                         EndDialog( IDCANCEL );
00164                         return;
00165                 }
00166                 
00167                 delete pURL;
00168         }
00169         
00170         delete pTorrent;
00171 }
00172 
00173 void CDownloadDlg::OnOK() 
00174 {
00175         UpdateData( TRUE );
00176 
00177         if ( m_pURL != NULL ) delete m_pURL;
00178         m_pURL = new CShareazaURL();
00179         
00180         if ( m_pURL->Parse( m_sURL ) ) CSkinDialog::OnOK();
00181 }
00182 
00183 CShareazaURL* CDownloadDlg::GetURL()
00184 {
00185         CShareazaURL* pURL = m_pURL;
00186         m_pURL = NULL;
00187         return pURL;
00188 }

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