Cleanup: extract sorted_cinemas().
[dcpomatic.git] / src / wx / screens_panel.cc
index 272b983d90c8bf5e72c81e00c3b38ef3e9791163..b7defe0e9be39e482d6163fe1f4f1972edb21330 100644 (file)
@@ -32,6 +32,7 @@
 
 
 using std::cout;
+using std::list;
 using std::make_pair;
 using std::make_shared;
 using std::map;
@@ -235,10 +236,7 @@ ScreensPanel::add_cinema_clicked ()
        if (dialog->ShowModal() == wxID_OK) {
                auto cinema = make_shared<Cinema>(dialog->name(), dialog->emails(), dialog->notes(), dialog->utc_offset_hour(), dialog->utc_offset_minute());
 
-               auto cinemas = Config::instance()->cinemas();
-               cinemas.sort(
-                       [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return _collator.compare(a->name, b->name) < 0; }
-                       );
+               auto cinemas = sorted_cinemas();
 
                try {
                        _ignore_cinemas_changed = true;
@@ -495,15 +493,23 @@ ScreensPanel::selection_changed ()
 }
 
 
-void
-ScreensPanel::add_cinemas ()
+list<shared_ptr<Cinema>>
+ScreensPanel::sorted_cinemas() const
 {
        auto cinemas = Config::instance()->cinemas();
+
        cinemas.sort(
                [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return _collator.compare(a->name, b->name) < 0; }
                );
 
-       for (auto cinema: cinemas) {
+       return cinemas;
+}
+
+
+void
+ScreensPanel::add_cinemas ()
+{
+       for (auto cinema: sorted_cinemas()) {
                add_cinema (cinema, wxTLI_LAST);
        }
 }