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

DlgFilterSearch.cpp

Go to the documentation of this file.
00001 //
00002 // DlgFilterSearch.cpp
00003 //
00004 //      Date:                   "$Date: 2005/06/19 10:00:18 $"
00005 //      Revision:               "$Revision: 1.6 $"
00006 //  Last change by:     "$Author: spooky23 $"
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 #include "StdAfx.h"
00027 #include "Shareaza.h"
00028 #include "Settings.h"
00029 #include "DlgFilterSearch.h"
00030 #include "MatchObjects.h"
00031 #include "ResultFilters.h"
00032 #include "DlgSaveFilterAs.h"
00033 
00034 #ifdef _DEBUG
00035 #define new DEBUG_NEW
00036 #undef THIS_FILE
00037 static char THIS_FILE[] = __FILE__;
00038 #endif
00039 
00040 BEGIN_MESSAGE_MAP(CFilterSearchDlg, CSkinDialog)
00041         //{{AFX_MSG_MAP(CFilterSearchDlg)
00042         //}}AFX_MSG_MAP
00043         ON_BN_CLICKED(IDC_SAVE_FILTER, OnBnClickedSaveFilter)
00044         ON_WM_DESTROY()
00045         ON_CBN_SELCHANGE(IDC_FILTERS, OnCbnSelChangeFilters)
00046         ON_BN_CLICKED(IDC_DELETE_FILTER, OnBnClickedDeleteFilter)
00047         ON_BN_CLICKED(IDC_SET_DEFAULT_FILTER, OnBnClickedSetDefaultFilter)
00048 END_MESSAGE_MAP()
00049 
00050 
00052 // CFilterSearchDlg dialog
00053 
00054 CFilterSearchDlg::CFilterSearchDlg(CWnd* pParent, CMatchList* pMatches) : CSkinDialog(CFilterSearchDlg::IDD, pParent)
00055 {
00056         //{{AFX_DATA_INIT(CFilterSearchDlg)
00057         m_sFilter = _T("");
00058         m_bHideBusy = FALSE;
00059         m_bHideLocal = FALSE;
00060         m_bHidePush = FALSE;
00061         m_bHideReject = FALSE;
00062         m_bHideUnstable = FALSE;
00063         m_bHideBogus = FALSE;
00064         m_nSources = 0;
00065         m_sMaxSize = _T("");
00066         m_sMinSize = _T("");
00067         m_bDefault = FALSE;
00068         //}}AFX_DATA_INIT
00069         m_pMatches = pMatches;
00070 }
00071 
00072 void CFilterSearchDlg::DoDataExchange(CDataExchange* pDX)
00073 {
00074         CSkinDialog::DoDataExchange(pDX);
00075         //{{AFX_DATA_MAP(CFilterSearchDlg)
00076         DDX_Control(pDX, IDC_SOURCES_SPIN, m_wndSources);
00077         DDX_Text(pDX, IDC_FILTER, m_sFilter);
00078         DDX_Check(pDX, IDC_FILTER_BUSY, m_bHideBusy);
00079         DDX_Check(pDX, IDC_FILTER_LOCAL, m_bHideLocal);
00080         DDX_Check(pDX, IDC_FILTER_PUSH, m_bHidePush);
00081         DDX_Check(pDX, IDC_FILTER_REJECT, m_bHideReject);
00082         DDX_Check(pDX, IDC_FILTER_UNSTABLE, m_bHideUnstable);
00083         DDX_Check(pDX, IDC_FILTER_BOGUS, m_bHideBogus);
00084         DDX_Text(pDX, IDC_SOURCES, m_nSources);
00085         DDX_Text(pDX, IDC_MAX_SIZE, m_sMaxSize);
00086         DDX_Text(pDX, IDC_MIN_SIZE, m_sMinSize);
00087         DDX_Check(pDX, IDC_SET_DEFAULT_FILTER, m_bDefault);
00088         //}}AFX_DATA_MAP
00089         DDX_Control(pDX, IDC_FILTERS, m_Filters);
00090 }
00091 
00093 // CFilterSearchDlg message handlers
00094 
00095 BOOL CFilterSearchDlg::OnInitDialog()
00096 {
00097         CSkinDialog::OnInitDialog();
00098 
00099         SkinMe( _T("CFilterSearchDlg"), IDR_SEARCHFRAME );
00100 
00101         if ( m_pMatches != NULL ) 
00102         {
00103                 m_pResultFilters = m_pMatches->m_pResultFilters;
00104                 m_pResultFilters->Load();
00105                 UpdateList();
00106                 UpdateFields();
00107         }
00108 
00109         ASSERT( m_pResultFilters != NULL );
00110 
00111         m_wndSources.SetRange( 0, 256 );
00112 
00113         UpdateData( FALSE );
00114 
00115         return TRUE;
00116 }
00117 
00118 void CFilterSearchDlg::OnOK()
00119 {
00120         UpdateData( TRUE );
00121 
00122         if ( m_pMatches != NULL )
00123         {
00124                 m_pMatches->m_sFilter                   = m_sFilter;
00125                 m_pMatches->m_bFilterBusy               = m_bHideBusy;
00126                 m_pMatches->m_bFilterPush               = m_bHidePush;
00127                 m_pMatches->m_bFilterUnstable   = m_bHideUnstable;
00128                 m_pMatches->m_bFilterLocal              = m_bHideLocal;
00129                 m_pMatches->m_bFilterReject             = m_bHideReject;
00130                 m_pMatches->m_bFilterBogus              = m_bHideBogus;
00131                 m_pMatches->m_nFilterMinSize    = Settings.ParseVolume( m_sMinSize, FALSE );
00132                 m_pMatches->m_nFilterMaxSize    = Settings.ParseVolume( m_sMaxSize, FALSE );
00133                 m_pMatches->m_nFilterSources    = m_nSources;
00134         }
00135 
00136         CSkinDialog::OnOK();
00137 }
00138 
00139 
00140 void CFilterSearchDlg::OnBnClickedSaveFilter()
00141 {
00142         CSaveFilterAsDlg dlg( this );
00143 
00144         if ( dlg.DoModal() == IDOK )
00145         {
00146                 int nExistingFilter = m_pResultFilters->Search( dlg.m_sName );
00147                 CFilterOptions *pOptions;
00148                 if ( nExistingFilter >= 0 )
00149                 {
00150                         pOptions = m_pResultFilters->m_pFilters[nExistingFilter];
00151                 }
00152                 else
00153                 {
00154                         pOptions = new CFilterOptions;
00155                 }
00156 
00157                 UpdateData(TRUE);
00158 
00159                 pOptions->m_sName                       = dlg.m_sName;
00160                 pOptions->m_sFilter                     = m_sFilter;
00161                 pOptions->m_bFilterBusy         = m_bHideBusy;
00162                 pOptions->m_bFilterPush         = m_bHidePush;
00163                 pOptions->m_bFilterUnstable     = m_bHideUnstable;
00164                 pOptions->m_bFilterLocal        = m_bHideLocal;
00165                 pOptions->m_bFilterReject       = m_bHideReject;
00166                 pOptions->m_bFilterBogus        = m_bHideBogus;
00167                 pOptions->m_nFilterMinSize      = Settings.ParseVolume( m_sMinSize, FALSE );
00168                 pOptions->m_nFilterMaxSize      = Settings.ParseVolume( m_sMaxSize, FALSE );
00169                 pOptions->m_nFilterSources      = m_nSources;
00170 
00171                 if ( nExistingFilter < 0 )
00172                 {
00173                         m_pResultFilters->Add( pOptions );
00174                 }
00175                 m_pResultFilters->Save();
00176 
00177                 UpdateList();
00178 
00179                 m_Filters.SetCurSel( m_pResultFilters->m_nFilters - 1 ); // select the last item added
00180                 OnCbnSelChangeFilters();
00181         }
00182 }
00183 
00184 //Update the filter fields with current data
00185 void CFilterSearchDlg::UpdateFields()
00186 {
00187         m_sFilter               = m_pMatches->m_sFilter;
00188         m_bHideBusy             = m_pMatches->m_bFilterBusy;
00189         m_bHidePush             = m_pMatches->m_bFilterPush;
00190         m_bHideUnstable = m_pMatches->m_bFilterUnstable;
00191         m_bHideLocal    = m_pMatches->m_bFilterLocal;
00192         m_bHideReject   = m_pMatches->m_bFilterReject;
00193         m_bHideBogus    = m_pMatches->m_bFilterBogus;
00194         m_nSources              = m_pMatches->m_nFilterSources;
00195 
00196         if ( m_pMatches->m_nFilterMinSize > 0 )
00197                 m_sMinSize      = Settings.SmartVolume( m_pMatches->m_nFilterMinSize, FALSE );
00198         else
00199                 m_sMinSize.Empty();
00200 
00201         if ( m_pMatches->m_nFilterMaxSize > 0 )
00202                 m_sMaxSize      = Settings.SmartVolume( m_pMatches->m_nFilterMaxSize, FALSE );
00203         else
00204                 m_sMaxSize.Empty();
00205 
00206         DWORD sel = m_Filters.GetCurSel();
00207 
00208         if ( sel != CB_ERR )
00209                 m_bDefault = ( sel == m_pResultFilters->m_nDefault );
00210 
00211         UpdateData(FALSE);
00212 }
00213 //update the filter selection combo-box with filter list items
00214 void CFilterSearchDlg::UpdateList()
00215 {
00216         m_Filters.ResetContent();
00217 
00218         for ( DWORD i = 0; i < m_pResultFilters->m_nFilters; i++ )
00219         {
00220                 if ( i == m_pResultFilters->m_nDefault )
00221                         m_Filters.AddString( m_pResultFilters->m_pFilters[i]->m_sName + " *" );
00222                 else
00223                         m_Filters.AddString( m_pResultFilters->m_pFilters[i]->m_sName );
00224 
00225 //              m_Filters.SetItemDataPtr( i, m_pResultFilters->m_pFilters[i] ); //save a pointer to the item
00226         }
00227 
00228         GetDlgItem( IDC_SET_DEFAULT_FILTER )->EnableWindow( m_pResultFilters->m_nFilters > 0 );
00229 }
00230 
00231 void CFilterSearchDlg::OnCbnSelChangeFilters()
00232 {
00233         DWORD sel = m_Filters.GetCurSel();
00234 
00235         if ( sel != CB_ERR )
00236         {
00237 //              CFilterOptions *pOptions = (CFilterOptions *) m_Filters.GetItemDataPtr(sel);
00238                 CFilterOptions *pOptions = m_pResultFilters->m_pFilters[sel];
00239 
00240                 m_sFilter                       = pOptions->m_sFilter;
00241                 m_bHideBusy                     = pOptions->m_bFilterBusy;
00242                 m_bHidePush                     = pOptions->m_bFilterPush;
00243                 m_bHideUnstable         = pOptions->m_bFilterUnstable;
00244                 m_bHideLocal            = pOptions->m_bFilterLocal;
00245                 m_bHideReject           = pOptions->m_bFilterReject;
00246                 m_bHideBogus            = pOptions->m_bFilterBogus;
00247                 m_nSources                      = pOptions->m_nFilterSources;
00248 
00249                 if ( pOptions->m_nFilterMinSize > 0 )
00250                         m_sMinSize      = Settings.SmartVolume( pOptions->m_nFilterMinSize, FALSE );
00251                 else
00252                         m_sMinSize.Empty();
00253 
00254                 if ( pOptions->m_nFilterMaxSize > 0 )
00255                         m_sMaxSize      = Settings.SmartVolume( pOptions->m_nFilterMaxSize, FALSE );
00256                 else
00257                         m_sMaxSize.Empty();
00258 
00259                 m_bDefault = ( sel == m_pResultFilters->m_nDefault );
00260 
00261                 UpdateData(FALSE);
00262         }
00263 }
00264 
00265 void CFilterSearchDlg::OnBnClickedDeleteFilter()
00266 {
00267         UpdateData(TRUE);
00268 
00269         DWORD sel = m_Filters.GetCurSel();
00270 
00271         if ( sel != CB_ERR )
00272         {
00273                 CString strMessage;
00274                 LoadString( strMessage, IDS_FILTER_DELETE_CONFIRM );
00275                 if ( AfxMessageBox( strMessage, MB_ICONQUESTION | MB_YESNO ) == IDYES )
00276                 {
00277                         m_pResultFilters->Remove( sel );
00278                         m_pResultFilters->Save();
00279                         UpdateList();
00280                         m_Filters.SetCurSel( min( sel, m_pResultFilters->m_nFilters - 1 ) );
00281                         m_bDefault = FALSE;
00282                         OnCbnSelChangeFilters();
00283                         UpdateData(FALSE);
00284                 }
00285         }
00286 }
00287 
00288 void CFilterSearchDlg::OnBnClickedSetDefaultFilter()
00289 {
00290         UpdateData( TRUE );
00291 
00292         DWORD sel = m_Filters.GetCurSel();
00293         if ( m_bDefault )
00294         {
00295                 if ( sel != CB_ERR )
00296                         m_pResultFilters->m_nDefault = sel;
00297         }
00298         else
00299         {
00300                 m_pResultFilters->m_nDefault = NONE;
00301         }
00302         UpdateList();
00303         m_Filters.SetCurSel( sel );
00304         m_pResultFilters->Save();
00305 }

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