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

LibraryList.cpp

Go to the documentation of this file.
00001 //
00002 // LibraryList.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 "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 // CLibraryList construction
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 // CLibraryList file access
00058 
00059 CLibraryFile* CLibraryList::GetNextFile(POSITION& pos) const
00060 {
00061         return Library.LookupFile( GetNext( pos ) );
00062 }
00063 
00065 // CLibraryList list merging
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 // CLibraryList IGenericView
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 // CLibraryList IEnumVARIANT enumerator
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 }

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