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 "Application.h"
00025 #include "Library.h"
00026 #include "LibraryList.h"
00027
00028 #ifdef _DEBUG
00029 #undef THIS_FILE
00030 static char THIS_FILE[]=__FILE__;
00031 #define new DEBUG_NEW
00032 #endif
00033
00034 BEGIN_INTERFACE_MAP(CLibraryList, CComObject)
00035 INTERFACE_PART(CLibraryList, IID_IGenericView, GenericView)
00036 INTERFACE_PART(CLibraryList, IID_IEnumVARIANT, EnumVARIANT)
00037 END_INTERFACE_MAP()
00038
00039
00041
00042
00043 CLibraryList::CLibraryList(int nBlockSize)
00044 {
00045 m_pList = NULL;
00046 m_nCount = 0;
00047 m_nBuffer = 0;
00048 m_nBlock = nBlockSize;
00049 }
00050
00051 CLibraryList::~CLibraryList()
00052 {
00053 if ( m_pList != NULL ) free( m_pList );
00054 }
00055
00057
00058
00059 CLibraryFile* CLibraryList::GetNextFile(POSITION& pos) const
00060 {
00061 return Library.LookupFile( GetNext( pos ) );
00062 }
00063
00065
00066
00067 int CLibraryList::Merge(CLibraryList* pList)
00068 {
00069 int nCount = 0;
00070
00071 if ( pList == NULL ) return 0;
00072
00073 for ( POSITION pos = pList->GetIterator() ; pos ; )
00074 {
00075 DWORD nItem = pList->GetNext( pos );
00076
00077 if ( Find( nItem ) == NULL )
00078 {
00079 AddTail( nItem );
00080 nCount++;
00081 }
00082 }
00083
00084 return nCount;
00085 }
00086
00088
00089
00090 IMPLEMENT_DISPATCH(CLibraryList, GenericView)
00091
00092 STDMETHODIMP CLibraryList::XGenericView::get_Name(BSTR FAR* psName)
00093 {
00094 METHOD_PROLOGUE( CLibraryList, GenericView )
00095 CString strName( _T("CLibraryFileView") );
00096 strName.SetSysString( psName );
00097 return S_OK;
00098 }
00099
00100 STDMETHODIMP CLibraryList::XGenericView::get_Unknown(IUnknown FAR* FAR* ppUnknown)
00101 {
00102 METHOD_PROLOGUE( CLibraryList, GenericView )
00103 return E_NOTIMPL;
00104 }
00105
00106 STDMETHODIMP CLibraryList::XGenericView::get_Param(LONG FAR* pnParam)
00107 {
00108 METHOD_PROLOGUE( CLibraryList, GenericView )
00109 return E_NOTIMPL;
00110 }
00111
00112 STDMETHODIMP CLibraryList::XGenericView::get__NewEnum(IUnknown FAR* FAR* ppEnum)
00113 {
00114 METHOD_PROLOGUE( CLibraryList, GenericView )
00115 *ppEnum = &pThis->m_xEnumVARIANT;
00116 pThis->m_xEnumVARIANT.m_pos = pThis->GetHeadPosition();
00117 AddRef();
00118 return S_OK;
00119 }
00120
00121 STDMETHODIMP CLibraryList::XGenericView::get_Item(VARIANT vIndex, VARIANT FAR* pvItem)
00122 {
00123 METHOD_PROLOGUE( CLibraryList, GenericView )
00124
00125 VARIANT va;
00126 VariantInit( &va );
00127 VariantClear( pvItem );
00128
00129 if ( FAILED( VariantChangeType( &va, (VARIANT FAR*)&vIndex, 0, VT_I4 ) ) ) return E_INVALIDARG;
00130
00131 if ( va.lVal < 0 || va.lVal >= pThis->GetCount() ) return S_OK;
00132
00133 for ( POSITION pos = pThis->GetHeadPosition() ; pos ; )
00134 {
00135 DWORD nItem = pThis->GetNext( pos );
00136
00137 if ( va.lVal-- == 0 )
00138 {
00139 pvItem->vt = VT_I4;
00140 pvItem->lVal = nItem;
00141 break;
00142 }
00143 }
00144
00145 return S_OK;
00146 }
00147
00148 STDMETHODIMP CLibraryList::XGenericView::get_Count(LONG FAR* pnCount)
00149 {
00150 METHOD_PROLOGUE( CLibraryList, GenericView )
00151 *pnCount = pThis->GetCount();
00152 return S_OK;
00153 }
00154
00156
00157
00158 IMPLEMENT_UNKNOWN(CLibraryList, EnumVARIANT)
00159
00160 STDMETHODIMP CLibraryList::XEnumVARIANT::Next(ULONG celt, VARIANT FAR* rgvar, ULONG FAR* pceltFetched)
00161 {
00162 METHOD_PROLOGUE( CLibraryList, EnumVARIANT )
00163
00164 if ( pceltFetched ) *pceltFetched = 0;
00165 else if ( celt > 1 ) return E_INVALIDARG;
00166
00167 if ( m_pos == NULL ) return S_FALSE;
00168
00169 VariantInit( &rgvar[0] );
00170 rgvar[0].vt = VT_I4;
00171 rgvar[0].lVal = pThis->GetNext( m_pos );
00172
00173 if ( pceltFetched ) (*pceltFetched)++;
00174
00175 return S_OK;
00176 }
00177
00178 STDMETHODIMP CLibraryList::XEnumVARIANT::Skip(ULONG celt)
00179 {
00180 METHOD_PROLOGUE( CLibraryList, EnumVARIANT )
00181
00182 while ( celt-- && m_pos ) pThis->GetNext( m_pos );
00183
00184 return ( celt == 0 ? S_OK : S_FALSE );
00185 }
00186
00187 STDMETHODIMP CLibraryList::XEnumVARIANT::Reset()
00188 {
00189 METHOD_PROLOGUE( CLibraryList, EnumVARIANT )
00190 m_pos = pThis->GetHeadPosition();
00191 return S_OK;
00192 }
00193
00194 STDMETHODIMP CLibraryList::XEnumVARIANT::Clone(IEnumVARIANT FAR* FAR* ppenum)
00195 {
00196 return E_NOTIMPL;
00197 }