Add donation nag after 20 successful DCP encodes.
authorCarl Hetherington <cth@carlh.net>
Sun, 14 Apr 2019 20:07:32 +0000 (21:07 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 14 Apr 2019 20:07:32 +0000 (21:07 +0100)
graphics/me.jpg [new file with mode: 0644]
graphics/wscript
platform/osx/make_dmg.sh
platform/windows/wscript
src/lib/analytics.cc
src/lib/analytics.h
src/lib/state.h
src/tools/dcpomatic.cc
src/wx/html_dialog.cc [new file with mode: 0644]
src/wx/html_dialog.h [new file with mode: 0644]
src/wx/wscript

diff --git a/graphics/me.jpg b/graphics/me.jpg
new file mode 100644 (file)
index 0000000..59583b8
Binary files /dev/null and b/graphics/me.jpg differ
index f8a1183a1b429eaedda2dfa5cca60adb21ade9d2..9eb95f0b9caa28ee1a1427325547486a22f78d31 100644 (file)
@@ -35,5 +35,6 @@ def build(bld):
         bld.install_files('${PREFIX}/share/dcpomatic2', 'select.png')
         bld.install_files('${PREFIX}/share/dcpomatic2', 'snap.png')
         bld.install_files('${PREFIX}/share/dcpomatic2', 'sequence.png')
+        bld.install_files('${PREFIX}/share/dcpomatic2', 'me.jpg')
         bld.install_files('${PREFIX}/share/dcpomatic2', 'tick.png')
         bld.install_files('${PREFIX}/share/dcpomatic2', 'no_tick.png')
index 4afb54700b77fb4d85bef22f2caf046740922a3f..d7aaade8cbe6f53a1a3ee3107d5ec9cbcfb9a30a 100644 (file)
@@ -136,6 +136,7 @@ function copy_resources {
     cp $ROOT/32/src/dcpomatic/graphics/select.png "$dest"
     cp $ROOT/32/src/dcpomatic/graphics/snap.png "$dest"
     cp $ROOT/32/src/dcpomatic/graphics/sequence.png "$dest"
+    cp $ROOT/32/src/dcpomatic/graphics/me.jpg "$dest"
 
     # i18n: DCP-o-matic .mo files
     for lang in de_DE es_ES fr_FR it_IT sv_SE nl_NL ru_RU pl_PL da_DK pt_PT pt_BR sk_SK cs_CZ uk_UA zh_CN tr_TR; do
index b1665bfa9fc99fb5da8bba308228e7171fd7e3b7..b130acf2c2f219eba647ebc2178a21de299ae15c 100644 (file)
@@ -300,6 +300,7 @@ File "%graphics%/zoom_all.png"
 File "%graphics%/select.png"
 File "%graphics%/snap.png"
 File "%graphics%/sequence.png"
+File "%graphics%/me.jpg"
 File "%graphics%/tick.png"
 File "%graphics%/no_tick.png"
 
index 74c21a29c1c40a8f9e232422196c9a4024ff4d5e..0bb8ada8c79b51208d9f4770ee1d568804ba75bb 100644 (file)
 
 #include "analytics.h"
 #include "exceptions.h"
+#include "compose.hpp"
 #include <dcp/raw_convert.h>
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
 
+#include "i18n.h"
+
 using std::string;
 using dcp::raw_convert;
 using boost::algorithm::trim;
@@ -44,6 +47,35 @@ 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
index b439fca8c303fbf0b62ff958cae12274283fe94b..be41e3a1b3f7d6416c6c297216e98ba6b21a51be 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2018-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 */
 
 #include "state.h"
+#include "signaller.h"
+#include <boost/signals2.hpp>
 
-class Analytics : public State
+class Analytics : public State, public Signaller
 {
 public:
        Analytics ();
@@ -30,6 +32,8 @@ public:
        void write () const;
        void read ();
 
+       boost::signals2::signal<void (std::string, std::string)> Message;
+
        static Analytics* instance ();
 
 private:
index b60c6667379104f3215f1a56ee6a49435c5508b0..251124a43ae8d8e5071d929fb86feb94f5e7592c 100644 (file)
@@ -18,6 +18,9 @@
 
 */
 
+#ifndef DCPOMATIC_STATE_H
+#define DCPOMATIC_STATE_H
+
 #include <boost/noncopyable.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/optional.hpp>
@@ -35,3 +38,5 @@ public:
 protected:
        static boost::filesystem::path path (std::string file, bool create_directories = true);
 };
+
+#endif
index 1db6b2d0fac0082d65b0a1d3129efb36a9441d7d..cd21d8080a05ae255e180f4d0d8409c3662644e9 100644 (file)
 #include "wx/export_dialog.h"
 #include "wx/paste_dialog.h"
 #include "wx/focus_manager.h"
+#include "wx/html_dialog.h"
 #include "wx/initial_setup_dialog.h"
 #include "wx/send_i18n_dialog.h"
 #include "wx/i18n_hook.h"
 #include "lib/film.h"
+#include "lib/analytics.h"
 #include "lib/emailer.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -87,6 +89,7 @@
 #include <wx/cmdline.h>
 #include <wx/preferences.h>
 #include <wx/splash.h>
+#include <wx/wxhtml.h>
 #ifdef __WXMSW__
 #include <shellapi.h>
 #endif
@@ -290,6 +293,8 @@ public:
                _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
                config_changed (Config::OTHER);
 
+               _analytics_message_connection = Analytics::instance()->Message.connect(boost::bind(&DOMFrame::analytics_message, this, _1, _2));
+
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_new, this),                ID_file_new);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this),               ID_file_open);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_save, this),               ID_file_save);
@@ -1105,6 +1110,9 @@ private:
                */
                _config_changed_connection.disconnect ();
 
+               /* Also stop hearing about analytics-related stuff */
+               _analytics_message_connection.disconnect ();
+
                ev.Skip ();
        }
 
@@ -1403,6 +1411,13 @@ private:
                _film_viewer->seek_by (_film_viewer->one_video_frame(), true);
        }
 
+       void analytics_message (string title, string html)
+       {
+               HTMLDialog* d = new HTMLDialog(this, std_to_wx(title), std_to_wx(html));
+               d->ShowModal();
+               d->Destroy();
+       }
+
        FilmEditor* _film_editor;
        boost::shared_ptr<FilmViewer> _film_viewer;
        StandardControls* _controls;
@@ -1418,6 +1433,7 @@ private:
        int _history_position;
        wxMenuItem* _history_separator;
        boost::signals2::scoped_connection _config_changed_connection;
+       boost::signals2::scoped_connection _analytics_message_connection;
        bool _update_news_requested;
        shared_ptr<Content> _clipboard;
 };
diff --git a/src/wx/html_dialog.cc b/src/wx/html_dialog.cc
new file mode 100644 (file)
index 0000000..b5f86e7
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+    Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "html_dialog.h"
+#include "wx_util.h"
+#include "lib/cross.h"
+#include <boost/filesystem.hpp>
+#include <wx/wxhtml.h>
+#include <wx/fs_mem.h>
+#include <iostream>
+
+HTMLDialog::HTMLDialog (wxWindow* parent, wxString title, wxString html)
+       : wxDialog (parent, wxID_ANY, title)
+{
+       wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
+
+       wxFileSystem::AddHandler(new wxMemoryFSHandler);
+
+       /* Add some resources that are used by HTML passed into this dialog */
+       wxMemoryFSHandler::AddFile(
+               "me.jpg",
+               wxBitmap(std_to_wx(boost::filesystem::path(shared_path() / "me.jpg").string()), wxBITMAP_TYPE_JPEG), wxBITMAP_TYPE_JPEG
+               );
+
+       wxHtmlWindow* h = new wxHtmlWindow (this);
+       h->SetPage (html);
+       sizer->Add (h, 1, wxEXPAND | wxALL, 6);
+
+       h->Bind (wxEVT_HTML_LINK_CLICKED, boost::bind(&HTMLDialog::link_clicked, this, _1));
+
+       SetSizer (sizer);
+       sizer->Layout ();
+
+       /* Set width */
+       SetSize (800, -1);
+
+       /* Set height */
+       SetSize (h->GetInternalRepresentation()->GetWidth(), h->GetInternalRepresentation()->GetHeight() + 64);
+}
+
+void
+HTMLDialog::link_clicked (wxHtmlLinkEvent& ev)
+{
+       wxLaunchDefaultBrowser(ev.GetLinkInfo().GetHref());
+}
diff --git a/src/wx/html_dialog.h b/src/wx/html_dialog.h
new file mode 100644 (file)
index 0000000..f5fc76e
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+    Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <wx/wx.h>
+
+class wxHtmlLinkEvent;
+
+class HTMLDialog : public wxDialog
+{
+public:
+       HTMLDialog (wxWindow* parent, wxString title, wxString html);
+
+private:
+       void link_clicked (wxHtmlLinkEvent& ev);
+};
index 183466106db5647e805752491f4a585d8a3157b8..47c9d1b3e33d2ae2644bacf321929f3182a6b8ac 100644 (file)
@@ -71,6 +71,7 @@ sources = """
           gain_calculator_dialog.cc
           gdc_certificate_panel.cc
           hints_dialog.cc
+          html_dialog.cc
           initial_setup_dialog.cc
           instant_i18n_dialog.cc
           i18n_hook.cc