Fix various misbehaviours with update checking (#749).
authorCarl Hetherington <cth@carlh.net>
Sat, 14 Nov 2015 18:27:25 +0000 (18:27 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 14 Nov 2015 18:27:54 +0000 (18:27 +0000)
ChangeLog
src/lib/update_checker.cc
src/lib/update_checker.h
src/tools/dcpomatic.cc

index a79f7fb14697ad4359e247253fad8eda249996da..6c8cab5302f59dfa27115099b2c2c6b613a40b08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2015-11-14  Carl Hetherington  <cth@carlh.net>
 
+       * Fix various misbehaviours with update checking (#749).
+
        * Updated fr_FR translation from Thierry Journet.
 
 2015-11-13  Carl Hetherington  <cth@carlh.net>
index 4c5075e20f3d81a1e298cf0f914e3434fd616497..31ea9a4fd8d6e8938481b46f48b6d071429f1a82 100644 (file)
@@ -20,7 +20,6 @@
 #include "update_checker.h"
 #include "version.h"
 #include "safe_stringstream.h"
-#include "config.h"
 #include "util.h"
 #include "raw_convert.h"
 #include <libcxml/cxml.h>
@@ -154,7 +153,7 @@ UpdateChecker::thread ()
                                _stable = stable;
                        }
 
-                       if (Config::instance()->check_for_test_updates() && version_less_than (dcpomatic_version, test)) {
+                       if (version_less_than (dcpomatic_version, test)) {
                                _test = test;
                        }
 
index b0eb62273719ecab4bda6231066ac982ae3863ee..ff1999810404822f916f07006bc0b49b5f84a6e1 100644 (file)
@@ -57,18 +57,12 @@ public:
                return _stable;
        }
 
-       /** @return new test version, if there is one and Config is set to look for it */
+       /** @return new test version, if there is one */
        boost::optional<std::string> test () {
                boost::mutex::scoped_lock lm (_data_mutex);
                return _test;
        }
 
-       /** @return true if the last signal emission was the first */
-       bool last_emit_was_first () const {
-               boost::mutex::scoped_lock lm (_data_mutex);
-               return _emits == 1;
-       }
-
        size_t write_callback (void *, size_t, size_t);
 
        boost::signals2::signal<void (void)> StateChanged;
index 28198a68564411f81c5bb295a2a8a031a0ae57a2..4d74563eb022c742af7159f8150a2b768163bcc7 100644 (file)
@@ -163,6 +163,7 @@ public:
                , _history_items (0)
                , _history_position (0)
                , _history_separator (0)
+               , _update_news_requested (false)
        {
 #if defined(DCPOMATIC_WINDOWS)
                if (Config::instance()->win32_console ()) {
@@ -247,6 +248,8 @@ public:
 
                /* Instantly save any config changes when using the DCP-o-matic GUI */
                Config::instance()->Changed.connect (boost::bind (&Config::write, Config::instance ()));
+
+               UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
        }
 
        void new_film (boost::filesystem::path path)
@@ -561,6 +564,7 @@ private:
        void tools_check_for_updates ()
        {
                UpdateChecker::instance()->run ();
+               _update_news_requested = true;
        }
 
        void help_about ()
@@ -770,6 +774,34 @@ private:
                _history_items = history.size ();
        }
 
+       void update_checker_state_changed ()
+       {
+               UpdateChecker* uc = UpdateChecker::instance ();
+
+               bool const announce =
+                       _update_news_requested ||
+                       (uc->stable() && Config::instance()->check_for_updates()) ||
+                       (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
+
+               _update_news_requested = false;
+
+               if (!announce) {
+                       return;
+               }
+
+               if (uc->state() == UpdateChecker::YES) {
+                       UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
+                       dialog->ShowModal ();
+                       dialog->Destroy ();
+               } else if (uc->state() == UpdateChecker::FAILED) {
+                       error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
+               } else {
+                       error_dialog (this, _("There are no new versions of DCP-o-matic available."));
+               }
+
+               _update_news_requested = false;
+       }
+
        FilmEditor* _film_editor;
        FilmViewer* _film_viewer;
        VideoWaveformDialog* _video_waveform_dialog;
@@ -782,6 +814,7 @@ private:
        int _history_position;
        wxMenuItem* _history_separator;
        boost::signals2::scoped_connection _config_changed_connection;
+       bool _update_news_requested;
 };
 
 static const wxCmdLineEntryDesc command_line_description[] = {
@@ -889,7 +922,6 @@ private:
                _timer.reset (new wxTimer (this));
                _timer->Start (1000);
 
-               UpdateChecker::instance()->StateChanged.connect (boost::bind (&App::update_checker_state_changed, this));
                if (Config::instance()->check_for_updates ()) {
                        UpdateChecker::instance()->run ();
                }
@@ -979,24 +1011,6 @@ private:
                }
        }
 
-       void update_checker_state_changed ()
-       {
-               UpdateChecker* uc = UpdateChecker::instance ();
-               if (uc->state() == UpdateChecker::YES && (uc->stable() || uc->test())) {
-                       UpdateDialog* dialog = new UpdateDialog (_frame, uc->stable (), uc->test ());
-                       dialog->ShowModal ();
-                       dialog->Destroy ();
-               } else if (uc->state() == UpdateChecker::FAILED) {
-                       if (!UpdateChecker::instance()->last_emit_was_first ()) {
-                               error_dialog (_frame, _("The DCP-o-matic download server could not be contacted."));
-                       }
-               } else {
-                       if (!UpdateChecker::instance()->last_emit_was_first ()) {
-                               error_dialog (_frame, _("There are no new versions of DCP-o-matic available."));
-                       }
-               }
-       }
-
        DOMFrame* _frame;
        shared_ptr<wxTimer> _timer;
        string _film_to_load;