Adjust how macOS drives are analysed and add a couple of tests.
[dcpomatic.git] / src / lib / analytics.cc
index 74c21a29c1c40a8f9e232422196c9a4024ff4d5e..7483166bad72bc444d006dd93ac0ff4b32109a7c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 #include "analytics.h"
+#include "compose.hpp"
 #include "exceptions.h"
+#include "warnings.h"
 #include <dcp/raw_convert.h>
 #include <libcxml/cxml.h>
+DCPOMATIC_DISABLE_WARNINGS
 #include <libxml++/libxml++.h>
-#include <boost/filesystem.hpp>
+DCPOMATIC_ENABLE_WARNINGS
 #include <boost/algorithm/string.hpp>
+#include <boost/filesystem.hpp>
+
+#include "i18n.h"
+
 
 using std::string;
 using dcp::raw_convert;
 using boost::algorithm::trim;
 
+
 Analytics* Analytics::_instance;
 int const Analytics::_current_version = 1;
 
+
 Analytics::Analytics ()
-       : _successful_dcp_encodes (0)
 {
 
 }
 
+
 void
 Analytics::successful_dcp_encode ()
 {
        ++_successful_dcp_encodes;
        write ();
+
+       if (_successful_dcp_encodes == 20) {
+               emit (
+                       boost::bind(
+                               boost::ref(Message),
+                               _("Congratulations!"),
+                               String::compose (_(
+                                       "<h2>You have made %1 DCPs with DCP-o-matic!</h2>"
+                                       "<img width=\"20%%\" src=\"memory:me.jpg\" align=\"center\">"
+                                        "<p>Hello. I'm Carl and I'm the "
+                                       "developer of DCP-o-matic. I work on it in my spare time (with the help "
+                                       "of a fine volunteer team of testers and translators) and I release it "
+                                       "as free software."
+
+                                       "<p>If you find DCP-o-matic useful, please consider a donation to the "
+                                       "project. Financial support will help me to spend more "
+                                       "time developing DCP-o-matic and making it better!"
+
+                                       "<p><ul>"
+                                       "<li><a href=\"https://dcpomatic.com/donate_amount?amount=40\">Go to Paypal to donate €40</a>"
+                                       "<li><a href=\"https://dcpomatic.com/donate_amount?amount=20\">Go to Paypal to donate €20</a>"
+                                       "<li><a href=\"https://dcpomatic.com/donate_amount?amount=10\">Go to Paypal to donate €10</a>"
+                                       "</ul>"
+
+                                       "<p>Thank you!"), _successful_dcp_encodes
+                                       )
+                               )
+                       );
+       }
 }
 
+
 void
 Analytics::write () const
 {
        xmlpp::Document doc;
-       xmlpp::Element* root = doc.create_root_node ("Analytics");
+       auto root = doc.create_root_node ("Analytics");
 
        root->add_child("Version")->add_child_text(raw_convert<string>(_current_version));
        root->add_child("SuccessfulDCPEncodes")->add_child_text(raw_convert<string>(_successful_dcp_encodes));
 
        try {
-               doc.write_to_file_formatted(path("analytics.xml").string());
+               doc.write_to_file_formatted(write_path("analytics.xml").string());
        } catch (xmlpp::exception& e) {
                string s = e.what ();
                trim (s);
-               throw FileError (s, path("analytics.xml"));
+               throw FileError (s, write_path("analytics.xml"));
        }
 }
 
+
 void
 Analytics::read ()
 try
 {
        cxml::Document f ("Analytics");
-       f.read_file (path("analytics.xml"));
+       f.read_file (read_path("analytics.xml"));
        _successful_dcp_encodes = f.number_child<int>("SuccessfulDCPEncodes");
 } catch (...) {
        /* Never mind */
 }
 
+
 Analytics*
 Analytics::instance ()
 {