Use Collator for recipients search (#2426).
[dcpomatic.git] / src / wx / recipients_panel.cc
index 8bb78750e83e4afd208088dc1ae6da0f9c438752..485a0f94e1ea65f8219f7bea1e9c690b6e157302 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2015-2020 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 #include "recipients_panel.h"
 #include "wx_util.h"
 #include "recipient_dialog.h"
 #include "dcpomatic_button.h"
 #include "lib/config.h"
-#include <boost/foreach.hpp>
 #include <list>
 #include <iostream>
 
-using std::list;
-using std::pair;
+
 using std::cout;
+using std::list;
+using std::make_pair;
 using std::map;
+using std::pair;
+using std::shared_ptr;
 using std::string;
-using std::make_pair;
-using boost::shared_ptr;
 using boost::optional;
 using namespace dcpomatic;
 
+
 RecipientsPanel::RecipientsPanel (wxWindow* parent)
        : wxPanel (parent, wxID_ANY)
        , _ignore_selection_change (false)
 {
-       wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
+       auto sizer = new wxBoxSizer (wxVERTICAL);
 
 #ifdef __WXGTK3__
        int const height = 30;
@@ -56,13 +58,13 @@ RecipientsPanel::RecipientsPanel (wxWindow* parent)
 #endif
        sizer->Add (_search, 0, wxBOTTOM, DCPOMATIC_SIZER_GAP);
 
-       wxBoxSizer* targets = new wxBoxSizer (wxHORIZONTAL);
+       auto targets = new wxBoxSizer (wxHORIZONTAL);
        _targets = new wxTreeCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_MULTIPLE | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT);
        targets->Add (_targets, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
 
        add_recipients ();
 
-       wxBoxSizer* target_buttons = new wxBoxSizer (wxVERTICAL);
+       auto target_buttons = new wxBoxSizer (wxVERTICAL);
 
        _add_recipient = new Button (this, _("Add..."));
        target_buttons->Add (_add_recipient, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
@@ -103,15 +105,10 @@ RecipientsPanel::setup_sensitivity ()
 void
 RecipientsPanel::add_recipient (shared_ptr<DKDMRecipient> r)
 {
-       string search = wx_to_std (_search->GetValue());
-       transform (search.begin(), search.end(), search.begin(), ::tolower);
-
-       if (!search.empty()) {
-               string name = r->name;
-               transform (name.begin(), name.end(), name.begin(), ::tolower);
-               if (name.find(search) == string::npos) {
-                       return;
-               }
+       string const search = wx_to_std(_search->GetValue());
+
+       if (!search.empty() && !_collator.find(search, r->name)) {
+               return;
        }
 
        _recipients[_targets->AppendItem(_root, std_to_wx(r->name))] = r;
@@ -123,14 +120,12 @@ RecipientsPanel::add_recipient (shared_ptr<DKDMRecipient> r)
 void
 RecipientsPanel::add_recipient_clicked ()
 {
-       RecipientDialog* d = new RecipientDialog (GetParent(), _("Add recipient"));
-       if (d->ShowModal() == wxID_OK) {
-               shared_ptr<DKDMRecipient> r (new DKDMRecipient(d->name(), d->notes(), d->recipient(), d->emails(), d->utc_offset_hour(), d->utc_offset_minute()));
+       RecipientDialog dialog(GetParent(), _("Add recipient"));
+       if (dialog.ShowModal() == wxID_OK) {
+               auto r = std::make_shared<DKDMRecipient>(dialog.name(), dialog.notes(), dialog.recipient(), dialog.emails(), dialog.utc_offset_hour(), dialog.utc_offset_minute());
                Config::instance()->add_dkdm_recipient (r);
                add_recipient (r);
        }
-
-       d->Destroy ();
 }
 
 
@@ -141,45 +136,43 @@ RecipientsPanel::edit_recipient_clicked ()
                return;
        }
 
-       pair<wxTreeItemId, shared_ptr<DKDMRecipient> > c = *_selected.begin();
+       auto c = *_selected.begin();
 
-       RecipientDialog* d = new RecipientDialog (
+       RecipientDialog dialog(
                GetParent(), _("Edit recipient"), c.second->name, c.second->notes, c.second->emails, c.second->utc_offset_hour, c.second->utc_offset_minute, c.second->recipient
                );
 
-       if (d->ShowModal () == wxID_OK) {
-               c.second->name = d->name ();
-               c.second->emails = d->emails ();
-               c.second->notes = d->notes ();
-               c.second->utc_offset_hour = d->utc_offset_hour ();
-               c.second->utc_offset_minute = d->utc_offset_minute ();
-               _targets->SetItemText (c.first, std_to_wx (d->name()));
+       if (dialog.ShowModal() == wxID_OK) {
+               c.second->name = dialog.name();
+               c.second->emails = dialog.emails();
+               c.second->notes = dialog.notes();
+               c.second->utc_offset_hour = dialog.utc_offset_hour();
+               c.second->utc_offset_minute = dialog.utc_offset_minute();
+               _targets->SetItemText(c.first, std_to_wx(dialog.name()));
                Config::instance()->changed (Config::DKDM_RECIPIENTS);
        }
-
-       d->Destroy ();
 }
 
 
 void
 RecipientsPanel::remove_recipient_clicked ()
 {
-       for (RecipientMap::iterator i = _selected.begin(); i != _selected.end(); ++i) {
-               Config::instance()->remove_dkdm_recipient (i->second);
-               _targets->Delete (i->first);
+       for (auto const& i: _selected) {
+               Config::instance()->remove_dkdm_recipient (i.second);
+               _targets->Delete (i.first);
        }
 
        selection_changed ();
 }
 
 
-list<shared_ptr<DKDMRecipient> >
+list<shared_ptr<DKDMRecipient>>
 RecipientsPanel::recipients () const
 {
-       list<shared_ptr<DKDMRecipient> > r;
+       list<shared_ptr<DKDMRecipient>> r;
 
-       for (RecipientMap::const_iterator i = _selected.begin(); i != _selected.end(); ++i) {
-               r.push_back (i->second);
+       for (auto const& i: _selected) {
+               r.push_back (i.second);
        }
 
        r.sort ();
@@ -225,7 +218,7 @@ RecipientsPanel::add_recipients ()
 {
        _root = _targets->AddRoot ("Foo");
 
-       BOOST_FOREACH (shared_ptr<DKDMRecipient> i, Config::instance()->dkdm_recipients()) {
+       for (auto i: Config::instance()->dkdm_recipients()) {
                add_recipient (i);
        }
 }
@@ -241,10 +234,10 @@ RecipientsPanel::search_changed ()
 
        _ignore_selection_change = true;
 
-       for (RecipientMap::const_iterator i = _selected.begin(); i != _selected.end(); ++i) {
+       for (auto const& i: _selected) {
                /* The wxTreeItemIds will now be different, so we must search by recipient */
-               RecipientMap::const_iterator j = _recipients.begin ();
-               while (j != _recipients.end() && j->second != i->second) {
+               auto j = _recipients.begin ();
+               while (j != _recipients.end() && j->second != i.second) {
                        ++j;
                }