226
229
delete pDocument->GetDocument();
229
void CFilterDialog::LoadFilters()
233
m_filters = m_globalFilters;
234
m_filterSets = m_globalFilterSets;
239
CInterProcessMutex(MUTEX_FILTERS);
241
wxFileName file(wxGetApp().GetSettingsDir(), _T("filters.xml"));
242
TiXmlElement* pDocument = GetXmlFile(file);
245
wxString msg = wxString::Format(_("Could not load \"%s\", please make sure the file is valid and can be accessed.\nAny changes made in the Site Manager could not be saved."), file.GetFullPath().c_str());
246
wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR);
251
TiXmlElement *pFilters = pDocument->FirstChildElement("Filters");
255
delete pDocument->GetDocument();
259
TiXmlElement *pFilter = pFilters->FirstChildElement("Filter");
263
filter.name = GetTextElement(pFilter, "Name");
264
if (filter.name == _T(""))
266
pFilter = pFilter->NextSiblingElement("Filter");
270
filter.filterFiles = GetTextElement(pFilter, "ApplyToFiles") == _T("1");
271
filter.filterDirs = GetTextElement(pFilter, "ApplyToDirs") == _T("1");
273
wxString type = GetTextElement(pFilter, "MatchType");
274
if (type == _T("Any"))
275
filter.matchType = CFilter::any;
276
else if (type == _T("None"))
277
filter.matchType = CFilter::none;
279
filter.matchType = CFilter::all;
280
filter.matchCase = GetTextElement(pFilter, "MatchCase") == _T("1");
282
TiXmlElement *pConditions = pFilter->FirstChildElement("Conditions");
285
pFilter = pFilter->NextSiblingElement("Filter");
289
TiXmlElement *pCondition = pConditions->FirstChildElement("Condition");
292
CFilterCondition condition;
293
condition.type = GetTextElementInt(pCondition, "Type", 0);
294
condition.condition = GetTextElementInt(pCondition, "Condition", 0);
295
condition.strValue = GetTextElement(pCondition, "Value");
296
condition.matchCase = filter.matchCase;
297
if (condition.strValue == _T(""))
299
pCondition = pCondition->NextSiblingElement("Condition");
303
// TODO: 64bit filesize
304
if (condition.type == 1)
307
condition.strValue.ToULong(&tmp);
308
condition.value = tmp;
311
filter.filters.push_back(condition);
313
pCondition = pCondition->NextSiblingElement("Condition");
316
if (!filter.filters.empty())
317
m_globalFilters.push_back(filter);
319
pFilter = pFilter->NextSiblingElement("Filter");
321
m_filters = m_globalFilters;
323
TiXmlElement* pSets = pDocument->FirstChildElement("Sets");
326
delete pDocument->GetDocument();
330
for (TiXmlElement* pSet = pSets->FirstChildElement("Set"); pSet; pSet = pSet->NextSiblingElement("Set"))
333
TiXmlElement* pItem = pSet->FirstChildElement("Item");
336
wxString local = GetTextElement(pItem, "Local");
337
wxString remote = GetTextElement(pItem, "Remote");
338
set.local.push_back(local == _T("1") ? true : false);
339
set.remote.push_back(remote == _T("1") ? true : false);
341
pItem = pItem->NextSiblingElement("Item");
344
if (!m_globalFilterSets.empty())
346
set.name = GetTextElement(pSet, "Name");
347
if (set.name == _T(""))
351
if (set.local.size() == m_filters.size())
352
m_globalFilterSets.push_back(set);
354
m_filterSets = m_globalFilterSets;
356
wxString attribute = GetTextAttribute(pSets, "Current");
358
if (attribute.ToULong(&value))
360
if (value < m_globalFilterSets.size())
361
m_globalCurrentFilterSet = value;
364
m_currentFilterSet = m_globalCurrentFilterSet;
366
delete pDocument->GetDocument();
369
232
void CFilterDialog::DisplayFilters()
371
234
wxCheckListBox* pLocalFilters = XRCCTRL(*this, "ID_LOCALFILTERS", wxCheckListBox);
426
305
m_filterSets[0].remote[item] = remoteChecked;
429
bool CFilterDialog::FilenameFiltered(const wxString& name, bool dir, wxLongLong size, bool local) const
308
void CFilterDialog::OnSaveAs(wxCommandEvent& event)
311
dlg.Create(this, _("Enter name for filterset"), _("Please enter a unique name for this filter set"));
312
if (dlg.ShowModal() != wxID_OK)
315
wxString name = dlg.GetValue();
318
wxMessageBox(_("No name for the filterset given."), _("Cannot save filterset"), wxICON_INFORMATION);
321
wxChoice* pChoice = XRCCTRL(*this, "ID_SETS", wxChoice);
322
int pos = pChoice->FindString(name);
323
if (pos != wxNOT_FOUND)
325
if (wxMessageBox(_("Given filterset name already exists, overwrite filter set?"), _("Filter set already exists"), wxICON_QUESTION | wxYES_NO) != wxYES)
329
if (pos == wxNOT_FOUND)
331
pos = m_filterSets.size();
332
m_filterSets.push_back(m_filterSets[0]);
333
pChoice->Append(name);
336
m_filterSets[pos] = m_filterSets[0];
338
m_filterSets[pos].name = name;
340
pChoice->SetSelection(pos);
341
m_currentFilterSet = pos;
344
void CFilterDialog::OnDeleteSet(wxCommandEvent& event)
346
wxChoice* pChoice = XRCCTRL(*this, "ID_SETS", wxChoice);
347
int pos = pChoice->GetSelection();
353
wxMessageBox(_("This filter set cannot be removed."));
357
m_filterSets[0] = m_filterSets[pos];
359
pChoice->Delete(pos);
360
m_filterSets.erase(m_filterSets.begin() + pos);
361
wxASSERT(!m_filterSets.empty());
363
pChoice->SetSelection(0);
364
m_currentFilterSet = 0;
367
void CFilterDialog::OnSetSelect(wxCommandEvent& event)
369
m_currentFilterSet = event.GetSelection();
373
void CFilterDialog::OnChangeAll(wxCommandEvent& event)
376
if (event.GetId() == XRCID("ID_LOCAL_DISABLEALL") || event.GetId() == XRCID("ID_REMOTE_DISABLEALL"))
380
std::vector<bool>* pValues;
381
wxCheckListBox* pListBox;
382
if (event.GetId() == XRCID("ID_LOCAL_ENABLEALL") || event.GetId() == XRCID("ID_LOCAL_DISABLEALL"))
384
pListBox = XRCCTRL(*this, "ID_LOCALFILTERS", wxCheckListBox);
385
pValues = &m_filterSets[0].local;
390
pListBox = XRCCTRL(*this, "ID_REMOTEFILTERS", wxCheckListBox);
391
pValues = &m_filterSets[0].remote;
395
if (m_currentFilterSet)
397
m_filterSets[0] = m_filterSets[m_currentFilterSet];
398
m_currentFilterSet = 0;
399
wxChoice* pChoice = XRCCTRL(*this, "ID_SETS", wxChoice);
400
pChoice->SetSelection(0);
403
for (size_t i = 0; i < pListBox->GetCount(); i++)
405
if (!local && (m_filters[i].HasConditionOfType(attributes) || m_filters[i].HasConditionOfType(permissions)))
407
pListBox->Check(i, false);
408
(*pValues)[i] = false;
412
pListBox->Check(i, check);
413
(*pValues)[i] = check;
418
void CFilterDialog::OnApply(wxCommandEvent& event)
420
m_globalFilters = m_filters;
421
m_globalFilterSets = m_filterSets;
422
m_globalCurrentFilterSet = m_currentFilterSet;
426
m_pMainFrame->GetState()->NotifyHandlers(STATECHANGE_APPLYFILTER);
429
CFilterManager::CFilterManager()
431
m_currentFilterSet = 0;
435
if (m_globalFilterSets.empty())
438
set.local.resize(m_filters.size(), false);
439
set.remote.resize(m_filters.size(), false);
441
m_globalFilterSets.push_back(set);
442
m_filterSets.push_back(set);
446
bool CFilterManager::HasActiveFilters() const
448
wxASSERT(m_globalCurrentFilterSet < m_globalFilterSets.size());
450
const CFilterSet& set = m_globalFilterSets[m_globalCurrentFilterSet];
451
for (unsigned int i = 0; i < m_globalFilters.size(); i++)
463
bool CFilterManager::HasSameLocalAndRemoteFilters() const
465
const CFilterSet& set = m_filterSets[m_currentFilterSet];
466
for (unsigned int i = 0; i < m_filters.size(); i++)
473
else if (set.remote[i])
480
bool CFilterManager::FilenameFiltered(const wxString& name, bool dir, wxLongLong size, bool local, int attributes) const
431
482
wxASSERT(m_currentFilterSet < m_filterSets.size());
484
const CFilterSet& set = m_filterSets[m_currentFilterSet];
433
486
// Check active filters
434
487
for (unsigned int i = 0; i < m_filters.size(); i++)
438
if (m_filterSets[m_currentFilterSet].local[i])
439
if (FilenameFilteredByFilter(name, dir, size, i))
492
if (FilenameFilteredByFilter(name, dir, size, i, attributes))
444
if (m_filterSets[m_currentFilterSet].remote[i])
445
if (FilenameFilteredByFilter(name, dir, size, i))
498
if (FilenameFilteredByFilter(name, dir, size, i, attributes))
591
void CFilterDialog::OnSaveAs(wxCommandEvent& event)
594
dlg.Create(this, _("Enter name for filterset"), _("Please enter a unique name for this filter set"));
595
if (dlg.ShowModal() != wxID_OK)
598
wxString name = dlg.GetValue();
599
wxChoice* pChoice = XRCCTRL(*this, "ID_SETS", wxChoice);
600
int pos = pChoice->FindString(name);
601
if (pos != wxNOT_FOUND)
603
if (wxMessageBox(_("Given filterset name already exists, overwrite filter set?"), _("Filter set already exists"), wxICON_QUESTION | wxYES_NO) != wxYES)
607
if (pos == wxNOT_FOUND)
609
pos = m_filterSets.size();
610
m_filterSets.push_back(m_filterSets[0]);
611
pChoice->Append(name);
614
m_filterSets[pos] = m_filterSets[0];
616
m_filterSets[pos].name = name;
618
pChoice->SetSelection(pos);
619
m_currentFilterSet = pos;
622
void CFilterDialog::OnDeleteSet(wxCommandEvent& event)
624
wxChoice* pChoice = XRCCTRL(*this, "ID_SETS", wxChoice);
625
int pos = pChoice->GetSelection();
631
wxMessageBox(_("This filter set cannot be removed"));
635
m_filterSets[0] = m_filterSets[pos];
637
pChoice->Delete(pos);
638
m_filterSets.erase(m_filterSets.begin() + pos);
639
wxASSERT(!m_filterSets.empty());
641
pChoice->SetSelection(0);
642
m_currentFilterSet = 0;
645
void CFilterDialog::OnSetSelect(wxCommandEvent& event)
647
m_currentFilterSet = event.GetSelection();
651
void CFilterDialog::OnChangeAll(wxCommandEvent& event)
654
if (event.GetId() == XRCID("ID_LOCAL_DISABLEALL") || event.GetId() == XRCID("ID_REMOTE_DISABLEALL"))
657
std::vector<bool>* pValues;
658
wxCheckListBox* pListBox;
659
if (event.GetId() == XRCID("ID_LOCAL_ENABLEALL") || event.GetId() == XRCID("ID_LOCAL_DISABLEALL"))
661
pListBox = XRCCTRL(*this, "ID_LOCALFILTERS", wxCheckListBox);
662
pValues = &m_filterSets[0].local;
666
pListBox = XRCCTRL(*this, "ID_REMOTEFILTERS", wxCheckListBox);
667
pValues = &m_filterSets[0].remote;
670
if (m_currentFilterSet)
672
m_filterSets[0] = m_filterSets[m_currentFilterSet];
673
m_currentFilterSet = 0;
674
wxChoice* pChoice = XRCCTRL(*this, "ID_SETS", wxChoice);
675
pChoice->SetSelection(0);
678
for (size_t i = 0; i < pListBox->GetCount(); i++)
680
pListBox->Check(i, check);
681
(*pValues)[i] = check;
685
void CFilterDialog::OnApply(wxCommandEvent& event)
687
m_globalFilters = m_filters;
688
m_globalFilterSets = m_filterSets;
689
m_globalCurrentFilterSet = m_currentFilterSet;
693
m_pMainFrame->GetState()->ApplyCurrentFilter();
696
bool CFilterDialog::HasActiveFilters() const
698
wxASSERT(m_currentFilterSet < m_filterSets.size());
700
for (unsigned int i = 0; i < m_filters.size(); i++)
702
if (m_filterSets[m_currentFilterSet].local[i])
705
if (m_filterSets[m_currentFilterSet].remote[i])
730
void CFilterManager::LoadFilters()
734
m_filters = m_globalFilters;
735
m_filterSets = m_globalFilterSets;
736
m_currentFilterSet = m_globalCurrentFilterSet;
741
CInterProcessMutex mutex(MUTEX_FILTERS);
743
wxFileName file(wxGetApp().GetSettingsDir(), _T("filters.xml"));
744
if (!file.FileExists())
746
wxFileName defaults(wxGetApp().GetResourceDir(), _T("defaultfilters.xml"));
747
if (defaults.FileExists())
749
TiXmlElement* pDocument = GetXmlFile(defaults);
751
SaveXmlFile(file, pDocument);
755
TiXmlElement* pDocument = GetXmlFile(file);
758
wxString msg = wxString::Format(_("Could not load \"%s\", please make sure the file is valid and can be accessed.\nAny changes made in the Site Manager could not be saved."), file.GetFullPath().c_str());
759
wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR);
764
TiXmlElement *pFilters = pDocument->FirstChildElement("Filters");
768
delete pDocument->GetDocument();
772
TiXmlElement *pFilter = pFilters->FirstChildElement("Filter");
776
filter.name = GetTextElement(pFilter, "Name");
777
if (filter.name == _T(""))
779
pFilter = pFilter->NextSiblingElement("Filter");
783
filter.filterFiles = GetTextElement(pFilter, "ApplyToFiles") == _T("1");
784
filter.filterDirs = GetTextElement(pFilter, "ApplyToDirs") == _T("1");
786
wxString type = GetTextElement(pFilter, "MatchType");
787
if (type == _T("Any"))
788
filter.matchType = CFilter::any;
789
else if (type == _T("None"))
790
filter.matchType = CFilter::none;
792
filter.matchType = CFilter::all;
793
filter.matchCase = GetTextElement(pFilter, "MatchCase") == _T("1");
795
TiXmlElement *pConditions = pFilter->FirstChildElement("Conditions");
798
pFilter = pFilter->NextSiblingElement("Filter");
802
TiXmlElement *pCondition = pConditions->FirstChildElement("Condition");
805
CFilterCondition condition;
806
int type = GetTextElementInt(pCondition, "Type", 0);
807
if (type < 0 || type >= filterType_size)
809
pCondition = pCondition->NextSiblingElement("Condition");
812
condition.type = (enum t_filterType)type;
813
condition.condition = GetTextElementInt(pCondition, "Condition", 0);
814
condition.strValue = GetTextElement(pCondition, "Value");
815
condition.matchCase = filter.matchCase;
816
if (condition.strValue == _T(""))
818
pCondition = pCondition->NextSiblingElement("Condition");
822
// TODO: 64bit filesize
823
if (condition.type == size)
826
condition.strValue.ToULong(&tmp);
827
condition.value = tmp;
829
else if (condition.type == attributes || condition.type == permissions)
831
if (condition.strValue == _T("0"))
837
filter.filters.push_back(condition);
839
pCondition = pCondition->NextSiblingElement("Condition");
842
if (!filter.filters.empty())
843
m_globalFilters.push_back(filter);
845
pFilter = pFilter->NextSiblingElement("Filter");
847
m_filters = m_globalFilters;
849
TiXmlElement* pSets = pDocument->FirstChildElement("Sets");
852
delete pDocument->GetDocument();
856
for (TiXmlElement* pSet = pSets->FirstChildElement("Set"); pSet; pSet = pSet->NextSiblingElement("Set"))
859
TiXmlElement* pItem = pSet->FirstChildElement("Item");
862
wxString local = GetTextElement(pItem, "Local");
863
wxString remote = GetTextElement(pItem, "Remote");
864
set.local.push_back(local == _T("1") ? true : false);
865
set.remote.push_back(remote == _T("1") ? true : false);
867
pItem = pItem->NextSiblingElement("Item");
870
if (!m_globalFilterSets.empty())
872
set.name = GetTextElement(pSet, "Name");
873
if (set.name == _T(""))
877
if (set.local.size() == m_filters.size())
878
m_globalFilterSets.push_back(set);
880
m_filterSets = m_globalFilterSets;
882
wxString attribute = GetTextAttribute(pSets, "Current");
884
if (attribute.ToULong(&value))
886
if (value < m_globalFilterSets.size())
887
m_globalCurrentFilterSet = value;
890
m_currentFilterSet = m_globalCurrentFilterSet;
892
delete pDocument->GetDocument();