enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / nag.cc
1 /*
2     Copyright (C) 2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 #include "pbd/gstdio_compat.h"
25 #include <gtkmm/stock.h>
26
27 #include "pbd/openuri.h"
28
29 #include "ardour/filesystem_paths.h"
30 #include "ardour/rc_configuration.h"
31
32 #include "nag.h"
33 #include "pbd/i18n.h"
34
35 using namespace ARDOUR;
36 using namespace std;
37 using namespace Glib;
38 using namespace Gtk;
39
40 NagScreen::NagScreen (std::string /*context*/, bool maybe_sub)
41         : ArdourDialog (string_compose (_("Support %1 Development"), PROGRAM_NAME), true)
42         , donate_button (button_group, _("I'd like to make a one-time donation"))
43         , subscribe_button (button_group, _("Tell me more about becoming a subscriber"))
44         , existing_button (button_group, _("I'm already a subscriber!"))
45         , next_time_button (button_group, _("Ask about this the next time I export"))
46         , never_again_button (button_group, _("Never ever ask me about this again"))
47 {
48         if (maybe_sub) {
49                 message.set_text (_("Congratulations on your session export.\n\n\
50 It looks as if you may already be a subscriber. If so, thanks, and sorry\n\
51 to bother you again about this - I'm working on improving our subscriber system\n\
52 so that I don't have to keep annoying you with this message.\n\n\
53 If you're not a subscriber, perhaps you might consider supporting my work\n\
54 on Ardour with either a one-time donation or subscription. Nothing will \n\
55 happen if you choose not to do so. However Ardour's continuing development\n\
56 relies on a stable, sustainable income stream. Thanks for using Ardour!"));
57         } else {
58                 message.set_text (_("Congratulations on your session export.\n\n\
59 I hope you find Ardour a useful tool. I'd like to ask you to consider supporting\n\
60 its development with either a one-time donation or subscription. Nothing\n\
61 will happen if you choose not to do so. However Ardour's continuing development\n\
62 relies on a stable, sustainable income stream. Thanks for using Ardour!"));
63         }
64
65         button_box.pack_start (donate_button);
66         button_box.pack_start (subscribe_button);
67         button_box.pack_start (existing_button);
68         button_box.pack_start (next_time_button);
69         button_box.pack_start (never_again_button);
70
71         get_vbox()->set_spacing (12);
72         get_vbox()->pack_start (message);
73         get_vbox()->pack_start (button_box);
74
75         set_border_width (12);
76         add_button (Stock::OK, RESPONSE_ACCEPT);
77 }
78
79 NagScreen::~NagScreen ()
80 {
81 }
82
83 void
84 NagScreen::nag ()
85 {
86         show_all ();
87
88         int response = run ();
89
90         hide ();
91
92         switch (response) {
93         case RESPONSE_ACCEPT:
94                 break;
95         default:
96                 return;
97         }
98
99         if (donate_button.get_active()) {
100                 offer_to_donate ();
101         } else if (subscribe_button.get_active()) {
102                 offer_to_subscribe ();
103         } else if (never_again_button.get_active ()) {
104                 mark_never_again ();
105         } else if (existing_button.get_active ()) {
106                 mark_affirmed_subscriber ();
107         }
108 }
109
110 NagScreen*
111 NagScreen::maybe_nag (std::string why)
112 {
113         std::string path;
114         bool really_subscribed;
115         bool maybe_subscribed;
116
117         path = Glib::build_filename (user_config_directory(), ".nevernag");
118
119         if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
120                 return 0;
121         }
122
123         maybe_subscribed = is_subscribed (really_subscribed);
124
125         if (really_subscribed) {
126                 return 0;
127         }
128
129         return new NagScreen (why, maybe_subscribed);
130 }
131
132 void
133 NagScreen::mark_never_again ()
134 {
135         std::string path;
136
137         path = Glib::build_filename (user_config_directory(), ".nevernag");
138
139         g_file_set_contents (path.c_str(), "", -1, NULL);
140 }
141
142 void
143 NagScreen::mark_subscriber ()
144 {
145         std::string path;
146
147         path = Glib::build_filename (user_config_directory(), ".askedaboutsub");
148
149         g_file_set_contents (path.c_str(), "", -1, NULL);
150 }
151
152 void
153 NagScreen::mark_affirmed_subscriber ()
154 {
155         std::string path;
156
157         path = Glib::build_filename (user_config_directory(), ".isubscribe");
158
159         g_file_set_contents (path.c_str(), "", -1, NULL);
160 }
161
162 bool
163 NagScreen::is_subscribed (bool& really)
164 {
165         std::string path;
166
167         really = false;
168
169         /* what we'd really like here is a way to query paypal
170            for someone's subscription status. thats a bit complicated
171            so for now, just see if they ever told us they were
172            subscribed. we try to trust our users :)
173         */
174
175         path = Glib::build_filename (user_config_directory(), ".isubscribe");
176         if (file_test (path, FILE_TEST_EXISTS)) {
177                 really = true;
178                 return true;
179         }
180
181         path = Glib::build_filename (user_config_directory(), ".askedaboutsub");
182         if (file_test (path, FILE_TEST_EXISTS)) {
183                 /* they never said they were subscribed but they
184                    did once express an interest in it.
185                 */
186                 really = false;
187                 return true;
188         }
189
190         return false;
191 }
192
193 void
194 NagScreen::offer_to_donate ()
195 {
196         /* we don't care if it fails */
197
198         PBD::open_uri (Config->get_donate_url());
199 }
200
201 void
202 NagScreen::offer_to_subscribe ()
203 {
204         const char* uri = "http://ardour.org/subscribe";
205
206         if (PBD::open_uri (uri)) {
207                 mark_subscriber ();
208         }
209 }
210