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

DlgFileProperties.cpp

Go to the documentation of this file.
00001 //
00002 // DlgFileProperties.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 "Settings.h"
00025 #include "DlgFileProperties.h"
00026 #include "Library.h"
00027 #include "SharedFile.h"
00028 #include "SharedFolder.h"
00029 #include "ShellIcons.h"
00030 #include "Schema.h"
00031 #include "TigerTree.h"
00032 #include "SHA.h"
00033 #include "XML.h"
00034 
00035 #ifdef _DEBUG
00036 #define new DEBUG_NEW
00037 #undef THIS_FILE
00038 static char THIS_FILE[] = __FILE__;
00039 #endif
00040 
00041 IMPLEMENT_DYNAMIC(CFilePropertiesDlg, CSkinDialog)
00042 
00043 BEGIN_MESSAGE_MAP(CFilePropertiesDlg, CSkinDialog)
00044         //{{AFX_MSG_MAP(CFilePropertiesDlg)
00045         ON_WM_SIZE()
00046         ON_WM_GETMINMAXINFO()
00047         ON_CBN_SELCHANGE(IDC_SCHEMAS, OnSelChangeSchemas)
00048         ON_WM_DESTROY()
00049         ON_CBN_CLOSEUP(IDC_SCHEMAS, OnCloseUpSchemas)
00050         ON_WM_LBUTTONUP()
00051         ON_WM_TIMER()
00052         //}}AFX_MSG_MAP
00053 END_MESSAGE_MAP()
00054 
00055 
00057 // CFilePropertiesDlg dialog
00058 
00059 CFilePropertiesDlg::CFilePropertiesDlg(CWnd* pParent, DWORD nIndex) : CSkinDialog( CFilePropertiesDlg::IDD, pParent )
00060 {
00061         m_nIndex        = nIndex;
00062         m_bHexHash      = FALSE;
00063         m_nWidth        = 0;
00064 
00065         //{{AFX_DATA_INIT(CFilePropertiesDlg)
00066         m_sName = _T("");
00067         m_sSize = _T("");
00068         m_sType = _T("");
00069         m_sPath = _T("");
00070         m_sIndex = _T("");
00071         m_sSHA1 = _T("");
00072         m_sTiger = _T("");
00073         //}}AFX_DATA_INIT
00074 }
00075 
00076 void CFilePropertiesDlg::DoDataExchange(CDataExchange* pDX)
00077 {
00078         CSkinDialog::DoDataExchange(pDX);
00079         //{{AFX_DATA_MAP(CFilePropertiesDlg)
00080         DDX_Control(pDX, IDC_FILE_HASH_LABEL, m_wndHash);
00081         DDX_Control(pDX, IDC_FILE_ICON, m_wndIcon);
00082         DDX_Control(pDX, IDCANCEL, m_wndCancel);
00083         DDX_Control(pDX, IDOK, m_wndOK);
00084         DDX_Control(pDX, IDC_SCHEMAS, m_wndSchemas);
00085         DDX_Text(pDX, IDC_FILE_NAME, m_sName);
00086         DDX_Text(pDX, IDC_FILE_SIZE, m_sSize);
00087         DDX_Text(pDX, IDC_FILE_TYPE, m_sType);
00088         DDX_Text(pDX, IDC_FILE_PATH, m_sPath);
00089         DDX_Text(pDX, IDC_FILE_INDEX, m_sIndex);
00090         DDX_Text(pDX, IDC_FILE_SHA1, m_sSHA1);
00091         DDX_Text(pDX, IDC_FILE_TIGER, m_sTiger);
00092         //}}AFX_DATA_MAP
00093 }
00094 
00096 // CFilePropertiesDlg message handlers
00097 
00098 BOOL CFilePropertiesDlg::OnInitDialog()
00099 {
00100         CSkinDialog::OnInitDialog();
00101 
00102         SkinMe( _T("CFilePropertiesDlg"), IDI_PROPERTIES );
00103 
00104         CRect rc;
00105         GetWindowRect( &rc );
00106         m_nWidth = rc.Width();
00107 
00108         m_wndSchema.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, rc, this, IDC_METADATA );
00109 
00110         Update();
00111 
00112         if ( ! Settings.LoadWindow( _T("CFilePropertiesDlg"), this ) )
00113         {
00114                 CRect rc;
00115                 GetWindowRect( &rc );
00116                 rc.bottom++;
00117                 MoveWindow( &rc );
00118         }
00119 
00120         PostMessage( WM_TIMER, 1 );
00121 
00122         return TRUE;
00123 }
00124 
00125 void CFilePropertiesDlg::Update()
00126 {
00127         CQuickLock oLock( Library.m_pSection );
00128 
00129         CLibraryFile* pFile = Library.LookupFile( m_nIndex );
00130 
00131         if ( pFile == NULL )
00132         {
00133                 PostMessage( WM_COMMAND, IDCANCEL );
00134                 return;
00135         }
00136 
00137         m_sName = pFile->m_sName;
00138         if ( pFile->IsAvailable() ) m_sPath = pFile->m_pFolder->m_sPath;
00139         m_sSize = Settings.SmartVolume( pFile->GetSize(), FALSE );
00140         m_sIndex.Format( _T("# %lu"), pFile->m_nIndex );
00141 
00142         if ( pFile->m_bSHA1 )
00143         {
00144                 if ( m_bHexHash )
00145                         m_sSHA1 = _T("sha1:") + CSHA::HashToHexString( &pFile->m_pSHA1 );
00146                 else
00147                         m_sSHA1 = _T("sha1:") + CSHA::HashToString( &pFile->m_pSHA1 );
00148         }
00149         else
00150         {
00151                 LoadString(m_sSHA1, IDS_GENERAL_NOURNAVAILABLE );
00152         }
00153 
00154         if ( pFile->m_bTiger )
00155         {
00156                 m_sTiger = _T("tree:tiger/:") + CTigerNode::HashToString( &pFile->m_pTiger );
00157         }
00158         else
00159         {
00160                 m_sTiger.Empty();
00161         }
00162 
00163         CString strExt = pFile->m_sName;
00164         int nPeriod = strExt.ReverseFind( '.' );
00165         if ( nPeriod > 0 ) strExt = strExt.Mid( nPeriod );
00166 
00167         CString strMIME, strText;
00168         HICON hIcon;
00169 
00170         if ( ShellIcons.Lookup( strExt, NULL, &hIcon, &m_sType, &strMIME ) ) m_wndIcon.SetIcon( hIcon );
00171         if ( strMIME.GetLength() ) m_sType += _T(" (") + strMIME + _T(")");
00172 
00173         UpdateData( FALSE );
00174 
00175         LoadString ( strText, IDS_SEARCH_NO_METADATA );
00176         m_wndSchemas.m_sNoSchemaText = strText;
00177         m_wndSchemas.Load( pFile->m_pSchema ? (LPCTSTR)pFile->m_pSchema->m_sURI : NULL );
00178 
00179         OnSelChangeSchemas();
00180 
00181         if ( pFile->m_pMetadata )
00182         {
00183                 CXMLElement* pXML = pFile->m_pMetadata->Clone();
00184 
00185                 if ( pFile->m_bSHA1 )
00186                         pXML->AddAttribute( _T("SHA1"), CSHA::HashToString( &pFile->m_pSHA1 ) );
00187                 else if ( CXMLAttribute* pSHA1 = pXML->GetAttribute( _T("SHA1") ) )
00188                         pSHA1->Delete();
00189 
00190                 m_wndSchema.UpdateData( pXML, FALSE );
00191 
00192                 delete pXML;
00193         }
00194 
00195 }
00196 
00197 void CFilePropertiesDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
00198 {
00199         CSkinDialog::OnGetMinMaxInfo( lpMMI );
00200 
00201         if ( m_nWidth )
00202         {
00203                 lpMMI->ptMinTrackSize.x = m_nWidth;
00204                 lpMMI->ptMinTrackSize.y = 256;
00205                 lpMMI->ptMaxTrackSize.x = m_nWidth;
00206         }
00207 }
00208 
00209 void CFilePropertiesDlg::OnSize(UINT nType, int cx, int cy)
00210 {
00211         if ( nType != 1982 ) CSkinDialog::OnSize( nType, cx, cy );
00212 
00213         if ( ! IsWindow( m_wndSchema.m_hWnd ) ) return;
00214 
00215         CRect rc;
00216 
00217         m_wndSchemas.GetWindowRect( &rc );
00218         ScreenToClient( &rc );
00219 
00220         m_wndSchema.SetWindowPos( NULL, rc.left, rc.bottom + 8, rc.Width(),
00221                 cy - 24 - 16 - ( rc.bottom + 8 ), SWP_NOZORDER );
00222 
00223         m_wndOK.GetWindowRect( &rc );
00224         ScreenToClient( &rc );
00225 
00226         m_wndOK.SetWindowPos( NULL, rc.left, cy - 32, 0, 0, SWP_NOZORDER|SWP_NOSIZE );
00227         m_wndCancel.SetWindowPos( NULL, rc.right + 8, cy - 32, 0, 0, SWP_NOZORDER|SWP_NOSIZE );
00228 }
00229 
00230 void CFilePropertiesDlg::OnTimer(UINT nIDEvent)
00231 {
00232         CRect rc;
00233         GetClientRect( &rc );
00234         OnSize( 1982, rc.Width(), rc.Height() );
00235 }
00236 
00237 void CFilePropertiesDlg::OnSelChangeSchemas()
00238 {
00239         CSchema* pSchema = m_wndSchemas.GetSelected();
00240         m_wndSchema.SetSchema( pSchema );
00241 }
00242 
00243 void CFilePropertiesDlg::OnCloseUpSchemas()
00244 {
00245         if ( CSchema* pSchema = m_wndSchemas.GetSelected() )
00246         {
00247                 PostMessage( WM_KEYDOWN, VK_TAB );
00248         }
00249 }
00250 
00251 BOOL CFilePropertiesDlg::PreTranslateMessage(MSG* pMsg)
00252 {
00253         if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB )
00254         {
00255                 if ( m_wndSchema.OnTab() ) return TRUE;
00256         }
00257 
00258         return CSkinDialog::PreTranslateMessage( pMsg );
00259 }
00260 
00261 void CFilePropertiesDlg::OnLButtonUp(UINT nFlags, CPoint point)
00262 {
00263         CRect rc;
00264 
00265         m_wndHash.GetWindowRect( &rc );
00266         ScreenToClient( &rc );
00267 
00268         if ( rc.PtInRect( point ) )
00269         {
00270                 m_bHexHash = ! m_bHexHash;
00271                 Update();
00272         }
00273 
00274         CSkinDialog::OnLButtonUp(nFlags, point);
00275 }
00276 
00277 void CFilePropertiesDlg::OnOK()
00278 {
00279         {
00280                 CQuickLock oLock( Library.m_pSection );
00281 
00282                 if ( CLibraryFile* pFile = Library.LookupFile( m_nIndex ) )
00283                 {
00284                         if ( CSchema* pSchema = m_wndSchemas.GetSelected() )
00285                         {
00286                                 CXMLElement* pXML               = pSchema->Instantiate( TRUE );
00287                                 CXMLElement* pSingular  = pXML->AddElement( pSchema->m_sSingular );
00288 
00289                                 m_wndSchema.UpdateData( pSingular, TRUE );
00290 
00291                                 if ( CXMLAttribute* pSHA1 = pSingular->GetAttribute( _T("SHA1") ) )
00292                                         pSHA1->Delete();
00293 
00294                                 pFile->SetMetadata( pXML );
00295                                 delete pXML;
00296                         }
00297                         else
00298                         {
00299                                 pFile->SetMetadata( NULL );
00300                         }
00301 
00302                         Library.Update();
00303                 }
00304         }
00305 
00306         CSkinDialog::OnOK();
00307 }
00308 
00309 void CFilePropertiesDlg::OnDestroy()
00310 {
00311         Settings.SaveWindow( _T("CFilePropertiesDlg"), this );
00312         CSkinDialog::OnDestroy();
00313 }
00314 

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