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

WndLibrary.cpp

Go to the documentation of this file.
00001 //
00002 // WndLibrary.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 "Library.h"
00026 #include "LibraryFolders.h"
00027 #include "LibraryBuilder.h"
00028 #include "CollectionFile.h"
00029 #include "SharedFile.h"
00030 #include "WndLibrary.h"
00031 #include "SharedFolder.h"
00032 
00033 #ifdef _DEBUG
00034 #define new DEBUG_NEW
00035 #undef THIS_FILE
00036 static char THIS_FILE[] = __FILE__;
00037 #endif
00038 
00039 IMPLEMENT_SERIAL(CLibraryWnd, CPanelWnd, 0)
00040 
00041 BEGIN_MESSAGE_MAP(CLibraryWnd, CPanelWnd)
00042         //{{AFX_MSG_MAP(CLibraryWnd)
00043         ON_WM_CREATE()
00044         ON_WM_DESTROY()
00045         ON_WM_SIZE()
00046         ON_WM_MDIACTIVATE()
00047         ON_WM_TIMER()
00048         //}}AFX_MSG_MAP
00049 END_MESSAGE_MAP()
00050 
00051 
00052 
00054 // CLibraryWnd construction
00055 
00056 CLibraryWnd::CLibraryWnd() : CPanelWnd( TRUE, FALSE )
00057 {
00058         Create( IDR_LIBRARYFRAME );
00059 }
00060 
00061 CLibraryWnd::~CLibraryWnd()
00062 {
00063 }
00064 
00066 // CLibraryWnd operations
00067 
00068 BOOL CLibraryWnd::Display(CLibraryFile* pFile)
00069 {
00070         return m_wndFrame.Display( pFile );
00071 }
00072 
00073 BOOL CLibraryWnd::Display(CAlbumFolder* pFolder)
00074 {
00075         return m_wndFrame.Display( pFolder );
00076 }
00077 
00079 // CLibraryWnd message handlers
00080 
00081 int CLibraryWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00082 {
00083         if ( CPanelWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00084 
00085         m_tLast = 0;
00086 
00087         m_wndFrame.Create( this );
00088 
00089         LoadState();
00090 
00091         return 0;
00092 }
00093 
00094 void CLibraryWnd::OnDestroy()
00095 {
00096         SaveState();
00097         CPanelWnd::OnDestroy();
00098 }
00099 
00100 BOOL CLibraryWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
00101 {
00102         if ( m_wndFrame.m_hWnd )
00103         {
00104                 if ( m_wndFrame.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00105         }
00106 
00107         return CPanelWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00108 }
00109 
00110 void CLibraryWnd::OnSize(UINT nType, int cx, int cy)
00111 {
00112         CPanelWnd::OnSize( nType, cx, cy );
00113         if ( m_wndFrame.m_hWnd ) m_wndFrame.SetWindowPos( NULL, 0, 0, cx, cy, SWP_NOZORDER );
00114 }
00115 
00116 void CLibraryWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
00117 {
00118         CPanelWnd::OnMDIActivate( bActivate, pActivateWnd, pDeactivateWnd );
00119 
00120         if ( bActivate )
00121         {
00122                 m_wndFrame.Update();
00123                 m_wndFrame.SetFocus();
00124         }
00125 }
00126 
00127 void CLibraryWnd::OnTimer(UINT nIDEvent)
00128 {
00129         DWORD tNow = GetTickCount();
00130 
00131         if ( nIDEvent == 1 )
00132         {
00133                 if ( IsPartiallyVisible() )
00134                 {
00135                         CWaitCursor pCursor;
00136                         m_wndFrame.Update( FALSE );
00137                         m_tLast = tNow;
00138                 }
00139         }
00140         else if ( tNow - m_tLast > 30000 )
00141         {
00142                 m_wndFrame.Update( FALSE );
00143                 m_tLast = tNow;
00144         }
00145 }
00146 
00147 void CLibraryWnd::OnSkinChange()
00148 {
00149         CPanelWnd::OnSkinChange();
00150         m_wndFrame.OnSkinChange();
00151 }
00152 
00154 // CLibraryWnd events
00155 
00156 HRESULT CLibraryWnd::GetGenericView(IGenericView** ppView)
00157 {
00158         if ( m_wndFrame.m_hWnd == NULL ) return S_FALSE;
00159         CLibraryList* pList = m_wndFrame.GetViewSelection();
00160         *ppView = (IGenericView*)pList->GetInterface( IID_IGenericView, TRUE );
00161         return S_OK;
00162 }
00163 
00164 BOOL CLibraryWnd::OnCollection(LPCTSTR pszPath)
00165 {
00166         CAlbumFolder* pFolder = NULL;
00167         CString strFormat, strMessage;
00168         CCollectionFile pCollection;
00169         CLibraryFolder* pLibFolder;
00170 
00171         if ( pCollection.Open( pszPath ) )
00172         {       //The specified collection is valid
00173 
00174                 //Create the collection folder (in case it doesn't exist)
00175                 CreateDirectory( Settings.Downloads.CollectionPath, NULL );
00176                 //Add the collection folder to the library (in case it isn't there)
00177                 pLibFolder = LibraryFolders.AddFolder( Settings.Downloads.CollectionPath );
00178                 //Force a scan of it (in case watch library folders is disabled)
00179                 pLibFolder =  LibraryFolders.GetFolder( Settings.Downloads.CollectionPath );
00180                 if( pLibFolder != NULL ) pLibFolder->Scan();
00181 
00182                 CSingleLock oLock( &Library.m_pSection, TRUE );
00183                 if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( pszPath, FALSE, TRUE ) )
00184                 {       //Collection IS already in the library
00185 
00186                         //Re-mount the collection
00187                         LibraryFolders.MountCollection( &pFile->m_pSHA1, &pCollection );
00188                         pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00189                         oLock.Unlock();
00190                 }
00191                 else
00192                 {       //Collection is not already in the main library
00193                         oLock.Unlock();
00194                         //Check the collection folder
00195                         CString strSource( pszPath ), strTarget;
00196 
00197                         int nName = strSource.ReverseFind( '\\' );
00198                         if ( nName >= 0 )
00199                         {
00200                                 strTarget = Settings.Downloads.CollectionPath + strSource.Mid( nName );
00201                                 LibraryBuilder.RequestPriority( strTarget );
00202                         }
00203 
00204                         oLock.Lock();
00205                         if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( strTarget, FALSE, TRUE ) )
00206                         {       //Collection is already in the collection folder
00207 
00208                                 //Re-mount the collection
00209                                 LibraryFolders.MountCollection( &pFile->m_pSHA1, &pCollection );
00210                                 pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00211                                 oLock.Unlock();
00212                         }
00213                         else
00214                         {       //Collection is not already in collection folder
00215                                 oLock.Unlock();
00216 
00217                                 if ( strTarget.GetLength() > 0 && CopyFile( strSource, strTarget, TRUE ) )
00218                                 {       //Collection was copied into the collection folder
00219 
00220                                         //Force a scan of collection folder (in case watch library folders is disabled)
00221                                         if( pLibFolder != NULL ) pLibFolder->Scan();
00222 
00223                                         LoadString( strFormat, IDS_LIBRARY_COLLECTION_INSTALLED );
00224                                         strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle() );
00225                                         AfxMessageBox( strMessage, MB_ICONINFORMATION );
00226                                         oLock.Lock();
00227                                         if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( strTarget, FALSE, TRUE ) )
00228                                         {
00229                                                 pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00230                                         }
00231                                         oLock.Unlock();
00232                                 }
00233                                 else
00234                                 {       //Was not able to copy collection to the collection folder
00235                                         if( GetLastError() == ERROR_FILE_EXISTS )
00236                                         {       //File of this name already exists
00237 
00238                                                 //We cannot copy the collection because it's already there.
00239                                                 //But it doesn't appear in the library.
00240 
00241                                                 //The greatest probablility is that the file is there, but hasn't
00242                                                 //been added yet. The best bet is to pretend everything is okay
00243                                                 //Because the delay it takes the user to respond will fix everything.
00244                                                 LoadString( strFormat, IDS_LIBRARY_COLLECTION_INSTALLED );
00245                                                 strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle() );
00246                                                 AfxMessageBox( strMessage , MB_ICONINFORMATION );
00247 
00248                                                 oLock.Lock();
00249                                                 if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( strTarget, FALSE, TRUE ) )
00250                                                 {       //Collection was already there.
00251                                                         //Re-mount the collection
00252                                                         LibraryFolders.MountCollection( &pFile->m_pSHA1, &pCollection );
00253                                                         pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00254                                                         oLock.Unlock();
00255                                                 }
00256                                                 else
00257                                                 {       //File of this name exists in the folder, but does not appear in the
00258                                                         //library. Most likely cause- Corrupt file in collection folder.
00259                                                         oLock.Unlock();
00260                                                         LoadString( strFormat, IDS_LIBRARY_COLLECTION_CANT_INSTALL );
00261                                                         strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle(), (LPCTSTR)Settings.Downloads.CollectionPath );
00262                                                         AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00263                                                 }
00264                                         }
00265                                         else
00266                                         {       //Unknown reason- Display an error message
00267                                                 LoadString( strFormat, IDS_LIBRARY_COLLECTION_CANT_INSTALL );
00268                                                 strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle(), (LPCTSTR)Settings.Downloads.CollectionPath );
00269                                                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00270                                         }
00271                                 }
00272                         }
00273                 }
00274         }
00275         else
00276         {       //User clicked on an invalid collection
00277                 LoadString( strFormat, IDS_LIBRARY_COLLECTION_INVALID );
00278                 strMessage.Format( strFormat, pszPath );
00279                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00280         }
00281 
00282         if ( pFolder != NULL ) Display( pFolder ); //Display the collection
00283         return ( pFolder != NULL );
00284 }
00285 
00286 
00287 /*
00289 // CLibraryWnd events
00290 
00291 HRESULT CLibraryWnd::GetGenericView(IGenericView** ppView)
00292 {
00293         if ( m_wndFrame.m_hWnd == NULL ) return S_FALSE;
00294         CLibraryList* pList = m_wndFrame.GetViewSelection();
00295         *ppView = (IGenericView*)pList->GetInterface( IID_IGenericView, TRUE );
00296         return S_OK;
00297 }
00298 
00299 BOOL CLibraryWnd::OnCollection(LPCTSTR pszPath)
00300 {
00301         CAlbumFolder* pFolder = NULL;
00302 
00303         if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( pszPath, TRUE, FALSE, TRUE ) )
00304         {
00305                 pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00306                 Library.Unlock();
00307         }
00308         else
00309         {
00310                 CString strFormat, strMessage;
00311                 CCollectionFile pCollection;
00312 
00313                 if ( pCollection.Open( pszPath ) )
00314                 {
00315                         CString strSource( pszPath ), strTarget;
00316 
00317                         int nName = strSource.ReverseFind( '\\' );
00318                         if ( nName >= 0 )
00319                         {
00320                                 strTarget = Settings.Downloads.CompletePath + strSource.Mid( nName );
00321                                 LibraryBuilder.RequestPriority( strTarget );
00322                         }
00323 
00324                         if ( strTarget.GetLength() > 0 && CopyFile( strSource, strTarget, TRUE ) )
00325                         {
00326                                 LoadString( strFormat, IDS_LIBRARY_COLLECTION_INSTALLED );
00327                                 strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle() );
00328                                 AfxMessageBox( strMessage, MB_ICONINFORMATION );
00329 
00330                                 if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( strTarget, TRUE, FALSE, TRUE ) )
00331                                 {
00332                                         pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00333                                         Library.Unlock();
00334                                 }
00335                         }
00336                         else
00337                         {
00338                                 LoadString( strFormat, IDS_LIBRARY_COLLECTION_CANT_INSTALL );
00339                                 strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle(), (LPCTSTR)Settings.Downloads.CompletePath );
00340                                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00341                         }
00342                 }
00343                 else
00344                 {
00345                         LoadString( strFormat, IDS_LIBRARY_COLLECTION_INVALID );
00346                         strMessage.Format( strFormat, pszPath );
00347                         AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00348                 }
00349         }
00350 
00351         if ( pFolder != NULL ) Display( pFolder );
00352         return ( pFolder != NULL );
00353 }
00354 */

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