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

MatchListView.cpp

Go to the documentation of this file.
00001 //
00002 // MatchListView.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 "MatchObjects.h"
00025 #include "QueryHit.h"
00026 #include "MatchListView.h"
00027 
00028 #include "TigerTree.h"
00029 #include "ED2K.h"
00030 #include "SHA.h"
00031 
00032 #ifdef _DEBUG
00033 #undef THIS_FILE
00034 static char THIS_FILE[]=__FILE__;
00035 #define new DEBUG_NEW
00036 #endif
00037 
00038 BEGIN_INTERFACE_MAP(CMatchListView, CComObject)
00039         INTERFACE_PART(CMatchListView, IID_IGenericView, GenericView)
00040         INTERFACE_PART(CMatchListView, IID_IEnumVARIANT, EnumVARIANT)
00041 END_INTERFACE_MAP()
00042 
00043 
00045 // CMatchListView construction
00046 
00047 CMatchListView::CMatchListView(LPCTSTR pszName, CMatchList* pList)
00048 {
00049         EnableDispatch( IID_IGenericView );
00050 
00051         m_sName = pszName;
00052         m_pList = pList;
00053         m_pList->m_pSection.Lock();
00054 
00055         for ( POSITION pos = m_pList->m_pSelectedFiles.GetHeadPosition() ; pos ; )
00056         {
00057                 m_pSelection.AddTail( m_pList->m_pSelectedFiles.GetNext( pos ) );
00058         }
00059 
00060         for ( POSITION pos = m_pList->m_pSelectedHits.GetHeadPosition() ; pos ; )
00061         {
00062                 m_pSelection.AddTail( m_pList->m_pSelectedHits.GetNext( pos ) );
00063         }
00064 }
00065 
00066 CMatchListView::~CMatchListView()
00067 {
00068         m_pList->m_pSection.Unlock();
00069 }
00070 
00072 // CMatchListView operations
00073 
00074 IGenericView* CMatchListView::Attach(LPCTSTR pszName, CMatchList* pList)
00075 {
00076         CMatchListView* pView = new CMatchListView( pszName, pList );
00077         return (IGenericView*)pView->GetInterface( IID_IGenericView, FALSE );
00078 }
00079 
00080 POSITION CMatchListView::GetIterator() const
00081 {
00082         return m_pSelection.GetHeadPosition();
00083 }
00084 
00085 int CMatchListView::GetCount() const
00086 {
00087         return m_pSelection.GetCount();
00088 }
00089 
00090 void CMatchListView::GetNext(POSITION& pos, CMatchFile** ppFile, CQueryHit** ppHit) const
00091 {
00092         LPVOID pItem = (LPVOID)( pos != NULL ? m_pSelection.GetNext( pos ) : NULL );
00093 
00094         if ( ppFile != NULL )
00095         {
00096                 if ( m_pList->m_pSelectedFiles.Find( pItem ) != NULL )
00097                 {
00098                         *ppFile = (CMatchFile*)pItem;
00099                 }
00100         }
00101         else
00102         {
00103                 *ppFile = NULL;
00104         }
00105 
00106         if ( ppHit != NULL )
00107         {
00108                 if ( m_pList->m_pSelectedHits.Find( pItem ) != NULL )
00109                 {
00110                         *ppHit = (CQueryHit*)pItem;
00111                 }
00112         }
00113         else
00114         {
00115                 *ppHit = NULL;
00116         }
00117 }
00118 
00119 void CMatchListView::GetNext(POSITION& pos, VARIANT* pVar) const
00120 {
00121         CMatchFile* pFile;
00122         CQueryHit* pHit;
00123 
00124         GetNext( pos, &pFile, &pHit );
00125         if ( pVar == NULL ) return;
00126 
00127         TIGEROOT* pTiger = NULL;
00128         SHA1* pSHA1 = NULL;
00129         MD4* pED2K = NULL;
00130 
00131         if ( pFile != NULL )
00132         {
00133                 pTiger = pFile->m_bTiger ? &pFile->m_pTiger : NULL;
00134                 pSHA1 = pFile->m_bSHA1 ? &pFile->m_pSHA1 : NULL;
00135                 pED2K = pFile->m_bED2K ? &pFile->m_pED2K : NULL;
00136         }
00137         else
00138         {
00139                 pTiger = pHit->m_bTiger ? &pHit->m_pTiger : NULL;
00140                 pSHA1 = pHit->m_bSHA1 ? &pHit->m_pSHA1 : NULL;
00141                 pED2K = pHit->m_bED2K ? &pHit->m_pED2K : NULL;
00142         }
00143 
00144         CString strURN;
00145         VariantClear( pVar );
00146 
00147         if ( pSHA1 != NULL && pTiger != NULL )
00148         {
00149                 strURN  = _T("urn:bitprint:")
00150                                 + CSHA::HashToString( pSHA1 ) + '.'
00151                                 + CTigerNode::HashToString( pTiger );
00152         }
00153         else if ( pSHA1 != NULL )
00154         {
00155                 strURN = CSHA::HashToString( pSHA1, TRUE );
00156         }
00157         else if ( pTiger != NULL )
00158         {
00159                 strURN = CTigerNode::HashToString( pTiger, TRUE );
00160         }
00161         else if ( pED2K != NULL )
00162         {
00163                 strURN = CED2K::HashToString( pED2K, TRUE );
00164         }
00165         else
00166         {
00167                 return;
00168         }
00169 
00170         pVar->vt                = VT_BSTR;
00171         pVar->bstrVal   = strURN.AllocSysString();
00172 }
00173 
00175 // CMatchListView IGenericView
00176 
00177 IMPLEMENT_DISPATCH(CMatchListView, GenericView)
00178 
00179 STDMETHODIMP CMatchListView::XGenericView::get_Name(BSTR FAR* psName)
00180 {
00181         METHOD_PROLOGUE( CMatchListView, GenericView )
00182         pThis->m_sName.SetSysString( psName );
00183         return S_OK;
00184 }
00185 
00186 STDMETHODIMP CMatchListView::XGenericView::get_Unknown(IUnknown FAR* FAR* ppUnknown)
00187 {
00188         METHOD_PROLOGUE( CMatchListView, GenericView )
00189         return E_NOTIMPL;
00190 }
00191 
00192 STDMETHODIMP CMatchListView::XGenericView::get_Param(LONG FAR* pnParam)
00193 {
00194         METHOD_PROLOGUE( CMatchListView, GenericView )
00195         return E_NOTIMPL;
00196 }
00197 
00198 STDMETHODIMP CMatchListView::XGenericView::get__NewEnum(IUnknown FAR* FAR* ppEnum)
00199 {
00200         METHOD_PROLOGUE( CMatchListView, GenericView )
00201         *ppEnum = &pThis->m_xEnumVARIANT;
00202         pThis->m_xEnumVARIANT.m_pos = pThis->GetIterator();
00203         AddRef();
00204         return S_OK;
00205 }
00206 
00207 STDMETHODIMP CMatchListView::XGenericView::get_Item(VARIANT vIndex, VARIANT FAR* pvItem)
00208 {
00209         METHOD_PROLOGUE( CMatchListView, GenericView )
00210 
00211         VARIANT va;
00212         VariantInit( &va );
00213         VariantClear( pvItem );
00214 
00215         if ( FAILED( VariantChangeType( &va, (VARIANT FAR*)&vIndex, 0, VT_I4 ) ) ) return E_INVALIDARG;
00216 
00217         if ( va.lVal < 0 || va.lVal >= pThis->GetCount() ) return S_OK;
00218 
00219         for ( POSITION pos = pThis->GetIterator() ; pos ; )
00220         {
00221                 BOOL bThis = ( va.lVal-- == 0 );
00222 
00223                 pThis->GetNext( pos, bThis ? pvItem : NULL );
00224                 if ( bThis ) break;
00225         }
00226 
00227         return S_OK;
00228 }
00229 
00230 STDMETHODIMP CMatchListView::XGenericView::get_Count(LONG FAR* pnCount)
00231 {
00232         METHOD_PROLOGUE( CMatchListView, GenericView )
00233         *pnCount = pThis->GetCount();
00234         return S_OK;
00235 }
00236 
00238 // CMatchListView IEnumVARIANT enumerator
00239 
00240 IMPLEMENT_UNKNOWN(CMatchListView, EnumVARIANT)
00241 
00242 STDMETHODIMP CMatchListView::XEnumVARIANT::Next(ULONG celt, VARIANT FAR* rgvar, ULONG FAR* pceltFetched)
00243 {
00244         METHOD_PROLOGUE( CMatchListView, EnumVARIANT )
00245 
00246         if ( pceltFetched ) *pceltFetched = 0;
00247         else if ( celt > 1 ) return E_INVALIDARG;
00248 
00249         if ( m_pos == NULL ) return S_FALSE;
00250 
00251         VariantInit( &rgvar[0] );
00252         pThis->GetNext( m_pos, rgvar );
00253 
00254         if ( pceltFetched ) (*pceltFetched)++;
00255 
00256         return S_OK;
00257 }
00258 
00259 STDMETHODIMP CMatchListView::XEnumVARIANT::Skip(ULONG celt)
00260 {
00261     METHOD_PROLOGUE( CMatchListView, EnumVARIANT )
00262 
00263         while ( celt-- && m_pos ) pThis->GetNext( m_pos, NULL, NULL );
00264 
00265     return ( celt == 0 ? S_OK : S_FALSE );
00266 }
00267 
00268 STDMETHODIMP CMatchListView::XEnumVARIANT::Reset()
00269 {
00270     METHOD_PROLOGUE( CMatchListView, EnumVARIANT )
00271         m_pos = pThis->GetIterator();
00272     return S_OK;
00273 }
00274 
00275 STDMETHODIMP CMatchListView::XEnumVARIANT::Clone(IEnumVARIANT FAR* FAR* ppenum)
00276 {
00277     return E_NOTIMPL;
00278 }

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