00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00042
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
00053
00054 CFilterSearchDlg::CFilterSearchDlg(CWnd* pParent, CMatchList* pMatches) : CSkinDialog(CFilterSearchDlg::IDD, pParent)
00055 {
00056
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
00069 m_pMatches = pMatches;
00070 }
00071
00072 void CFilterSearchDlg::DoDataExchange(CDataExchange* pDX)
00073 {
00074 CSkinDialog::DoDataExchange(pDX);
00075
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
00089 DDX_Control(pDX, IDC_FILTERS, m_Filters);
00090 }
00091
00093
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 );
00180 OnCbnSelChangeFilters();
00181 }
00182 }
00183
00184
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
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
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
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 }