2 Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "analytics.h"
22 #include "exceptions.h"
23 #include "compose.hpp"
24 #include <dcp/raw_convert.h>
25 #include <libcxml/cxml.h>
26 #include <libxml++/libxml++.h>
27 #include <boost/filesystem.hpp>
28 #include <boost/algorithm/string.hpp>
33 using dcp::raw_convert;
34 using boost::algorithm::trim;
36 Analytics* Analytics::_instance;
37 int const Analytics::_current_version = 1;
39 Analytics::Analytics ()
40 : _successful_dcp_encodes (0)
46 Analytics::successful_dcp_encode ()
48 ++_successful_dcp_encodes;
51 if (_successful_dcp_encodes == 20) {
55 _("Congratulations!"),
57 "<h2>You have made %1 DCPs with DCP-o-matic!</h2>"
58 "<img width=\"20%%\" src=\"memory:me.jpg\" align=\"center\">"
59 "<p>Hello. I'm Carl and I'm the "
60 "developer of DCP-o-matic. I work on it in my spare time (with the help "
61 "of a fine volunteer team of testers and translators) and I release it "
64 "<p>If you find DCP-o-matic useful, please consider a donation to the "
65 "project. Financial support will help me to spend more "
66 "time developing DCP-o-matic and making it better!"
69 "<li><a href=\"https://dcpomatic.com/donate_amount?amount=40\">Go to Paypal to donate £40</a>"
70 "<li><a href=\"https://dcpomatic.com/donate_amount?amount=20\">Go to Paypal to donate £20</a>"
71 "<li><a href=\"https://dcpomatic.com/donate_amount?amount=10\">Go to Paypal to donate £10</a>"
74 "<p>Thank you!"), _successful_dcp_encodes
82 Analytics::write () const
85 xmlpp::Element* root = doc.create_root_node ("Analytics");
87 root->add_child("Version")->add_child_text(raw_convert<string>(_current_version));
88 root->add_child("SuccessfulDCPEncodes")->add_child_text(raw_convert<string>(_successful_dcp_encodes));
91 doc.write_to_file_formatted(path("analytics.xml").string());
92 } catch (xmlpp::exception& e) {
95 throw FileError (s, path("analytics.xml"));
103 cxml::Document f ("Analytics");
104 f.read_file (path("analytics.xml"));
105 _successful_dcp_encodes = f.number_child<int>("SuccessfulDCPEncodes");
111 Analytics::instance ()
114 _instance = new Analytics();