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

ResultFilters.cpp

Go to the documentation of this file.
00001 //
00002 // ResultFilters.cpp
00003 //
00004 //      Date:                   "$Date: 2005/10/03 17:21:43 $"
00005 //      Revision:               "$Revision: 1.7 $"
00006 //  Last change by:     "$Author: mogthecat $"
00007 //
00008 // Copyright (c) Shareaza Development Team, 2002-2005.
00009 // This file is part of SHAREAZA (www.shareaza.com)
00010 //
00011 // Shareaza is free software; you can redistribute it
00012 // and/or modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Shareaza is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU General Public License
00022 // along with Shareaza; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //
00025 //
00026 // Author : [email protected]
00027 //
00029 // ResultFilters
00030 // Save the filters used for results
00031 #include "stdafx.h"
00032 #include "Shareaza.h"
00033 #include "Settings.h"
00034 #include "ResultFilters.h"
00035 
00036 CResultFilters::CResultFilters(void)
00037 {
00038         m_pFilters = NULL;
00039         m_nFilters = 0;
00040         m_nDefault = NONE;
00041 }
00042 
00043 CResultFilters::~CResultFilters(void)
00044 {
00045         if ( m_pFilters )
00046         {
00047                 for ( DWORD i = 0; i < m_nFilters; i++ )
00048                 {
00049                         delete m_pFilters[i];
00050                 }
00051         }
00052 
00053         delete [] ( m_pFilters );
00054 }
00055 
00056 void CResultFilters::Serialize(CArchive & ar)
00057 {
00058         int nVersion = 1;
00059 
00060         if ( ar.IsStoring() )
00061         {
00062                 ar << nVersion;
00063 
00064                 ar.WriteCount(m_nFilters);
00065 
00066                 for (DWORD i = 0; i < m_nFilters; i++)
00067                 {
00068                         CFilterOptions* pFilter = m_pFilters[ i ];
00069                         pFilter->Serialize( ar );
00070                 }
00071 
00072                 ar << m_nDefault;
00073         }
00074         else
00075         {
00076                 ar >> nVersion;
00077 
00078                 m_nFilters = ar.ReadCount();
00079 
00080                 m_pFilters = new CFilterOptions *[ m_nFilters ];
00081                 ZeroMemory( m_pFilters, sizeof(CFilterOptions*) * m_nFilters );
00082 
00083                 for (DWORD i = 0; i < m_nFilters; i++)
00084                 {
00085                         CFilterOptions* pFilter = new CFilterOptions();
00086                         m_pFilters[ i ] = pFilter;
00087                         pFilter->Serialize( ar );
00088                 }
00089 
00090                 ar >> m_nDefault;
00091         }
00092 }
00093 
00094 void CResultFilters::Add(CFilterOptions *pOptions)
00095 {
00096         CFilterOptions **pFilters = new CFilterOptions * [m_nFilters + 1];
00097 
00098         CopyMemory(pFilters, m_pFilters, sizeof(CFilterOptions *) * m_nFilters);
00099 
00100         pFilters[m_nFilters++] = pOptions;
00101 
00102         delete [] m_pFilters;
00103 
00104         m_pFilters = pFilters;
00105 }
00106 
00107 // Search for (first) filter with name strName, return index if found, -1 (NONE) otherwise
00108 int CResultFilters::Search(const CString& strName)
00109 {
00110         for ( DWORD index = 0; index < m_nFilters; index++ )
00111         {
00112                 if ( strName.Compare( m_pFilters[index]->m_sName ) == 0 )
00113                 {
00114                         return index;
00115                 }
00116         }
00117         return NONE;
00118  }
00119 
00120 void CResultFilters::Remove(DWORD index)
00121 {
00122         if ( ( index >= 0 ) && ( index < m_nFilters ) )
00123         {
00124                 delete m_pFilters[index];
00125                 CopyMemory(&m_pFilters[index], &m_pFilters[index + 1], sizeof(CFilterOptions *) * (m_nFilters - index));
00126                 m_nFilters--;
00127 
00128                 if ( index == m_nDefault ) m_nDefault = NONE;
00129                 else if ( ( m_nDefault != NONE ) && ( index < m_nDefault ) ) m_nDefault--;
00130                 
00131                 if ( m_nFilters == 0 ) m_nDefault = NONE;
00132         }
00133 }
00134 
00135 void CResultFilters::Load()
00136 {
00137         // Delete old content first
00138         if ( m_pFilters )
00139         {
00140                 for ( DWORD i = 0; i < m_nFilters; i++ )
00141                 {
00142                         delete m_pFilters[i];
00143                 }
00144         }
00145         delete [] ( m_pFilters );
00146         
00147         CString strFile;
00148         CFile f;
00149 
00150         strFile.Format( _T("%s\\Data\\Filters.dat"), (LPCTSTR)Settings.General.UserPath );
00151 
00152         if ( f.Open( strFile, CFile::modeRead ) )
00153         {
00154                 CArchive ar( &f, CArchive::load );
00155                 Serialize(ar);
00156                 ar.Close();
00157                 f.Close();
00158         }
00159 }
00160 
00161 void CResultFilters::Save()
00162 {
00163         CString strFile;
00164         CFile f;
00165 
00166         strFile.Format( _T("%s\\Data\\Filters.dat"), (LPCTSTR)Settings.General.UserPath );
00167 
00168         if (f.Open(strFile, CFile::modeCreate | CFile::modeWrite))
00169         {
00170                 CArchive ar( &f, CArchive::store );
00171                 Serialize( ar );
00172                 ar.Close();
00173                 f.Close();
00174         }
00175 }
00177 // FilterOptions
00178 // The filter settings
00179 CFilterOptions::CFilterOptions()
00180 {
00181         m_bFilterBusy           = ( Settings.Search.FilterMask & ( 1 << 0 ) ) > 0;
00182         m_bFilterPush           = ( Settings.Search.FilterMask & ( 1 << 1 ) ) > 0;
00183         m_bFilterUnstable       = ( Settings.Search.FilterMask & ( 1 << 2 ) ) > 0;
00184         m_bFilterReject         = ( Settings.Search.FilterMask & ( 1 << 3 ) ) > 0;
00185         m_bFilterLocal          = ( Settings.Search.FilterMask & ( 1 << 4 ) ) > 0;
00186         m_bFilterBogus          = ( Settings.Search.FilterMask & ( 1 << 5 ) ) > 0;
00187         m_bFilterDRM            = ( Settings.Search.FilterMask & ( 1 << 6 ) ) > 0;
00188         m_bFilterAdult          = ( Settings.Search.FilterMask & ( 1 << 7 ) ) > 0;
00189         m_nFilterMinSize        = 1;
00190         m_nFilterMaxSize        = 0;
00191         m_nFilterSources        = 1;
00192 }
00193 
00194 void CFilterOptions::Serialize(CArchive & ar)
00195 {
00196         if ( ar.IsStoring() ) // saving
00197         {
00198                 ar << m_sName;
00199                 ar << m_sFilter;
00200                 ar << m_bFilterBusy;
00201                 ar << m_bFilterPush;
00202                 ar << m_bFilterUnstable;
00203                 ar << m_bFilterReject;
00204                 ar << m_bFilterLocal;
00205                 ar << m_bFilterBogus;
00206                 ar << m_nFilterMinSize;
00207                 ar << m_nFilterMaxSize;
00208                 ar << m_nFilterSources;
00209         }
00210         else //loading
00211         {
00212                 ar >> m_sName;
00213                 ar >> m_sFilter;
00214                 ar >> m_bFilterBusy;
00215                 ar >> m_bFilterPush;
00216                 ar >> m_bFilterUnstable;
00217                 ar >> m_bFilterReject;
00218                 ar >> m_bFilterLocal;
00219                 ar >> m_bFilterBogus;
00220                 ar >> m_nFilterMinSize;
00221                 ar >> m_nFilterMaxSize;
00222                 ar >> m_nFilterSources;
00223         }
00224 }

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