add copyright comments
[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 <fstream>
25 #include <gtkmm/stock.h>
26
27 #include "pbd/openuri.h"
28
29 #include "ardour/filesystem_paths.h"
30
31 #include "nag.h"
32 #include "i18n.h"
33
34 using namespace ARDOUR;
35 using namespace std;
36 using namespace Glib;
37 using namespace Gtk;
38
39 NagScreen::NagScreen (std::string /*context*/, bool maybe_sub)
40         : ArdourDialog (_("Support Ardour Development"), true)
41         , donate_button (button_group, _("I'd like to make a one-time donation"))
42         , subscribe_button (button_group, _("Tell me more about becoming a subscriber"))
43         , existing_button (button_group, _("I'm already a subscriber!"))
44         , next_time_button (button_group, _("Ask about this the next time I export"))
45         , never_again_button (button_group, _("Never ever ask me about this again"))
46 {
47         if (maybe_sub) {
48                 message.set_text (_("Congratulations on your session export.\n\n\
49 It looks as if you may already be a subscriber. If so, thanks, and sorry\n\
50 to bother you again about this - I'm working on improving our subscriber system\n\
51 so that I don't have to keep annoying you with this message.\n\n\
52 If you're not a subscriber, perhaps you might consider supporting my work\n\
53 on Ardour with either a one-time donation or subscription. Nothing will \n\
54 happen if you choose not to do so. However Ardour's continuing development\n\
55 relies on a stable, sustainable income stream. Thanks for using Ardour!"));
56         } else {
57                 message.set_text (_("Congratulations on your session export.\n\n\
58 I hope you find Ardour a useful tool. I'd like to ask you to consider supporting\n\
59 its development with either a one-time donation or subscription. Nothing\n\
60 will happen if you choose not to do so. However Ardour's continuing development\n\
61 relies on a stable, sustainable income stream. Thanks for using Ardour!"));
62         }
63
64         button_box.pack_start (donate_button);
65         button_box.pack_start (subscribe_button);
66         button_box.pack_start (existing_button);
67         button_box.pack_start (next_time_button);
68         button_box.pack_start (never_again_button);
69
70         get_vbox()->set_spacing (12);
71         get_vbox()->pack_start (message);
72         get_vbox()->pack_start (button_box);
73
74         set_border_width (12);
75         add_button (Stock::OK, RESPONSE_ACCEPT);
76 }
77
78 NagScreen::~NagScreen ()
79 {
80 }
81
82 void
83 NagScreen::nag ()
84 {
85         show_all ();
86
87         int response = run ();
88
89         hide ();
90
91         switch (response) {
92         case RESPONSE_ACCEPT:
93                 break;
94         default:
95                 return;
96         }
97
98         if (donate_button.get_active()) {
99                 offer_to_donate ();
100         } else if (subscribe_button.get_active()) {
101                 offer_to_subscribe ();
102         } else if (never_again_button.get_active ()) {
103                 mark_never_again ();
104         } else if (existing_button.get_active ()) {
105                 mark_affirmed_subscriber ();
106         }
107 }
108
109 NagScreen*
110 NagScreen::maybe_nag (std::string why)
111 {
112         std::string path;
113         bool really_subscribed;
114         bool maybe_subscribed;
115
116         path = Glib::build_filename (user_config_directory(), ".nevernag");
117
118         if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
119                 return 0;
120         }
121
122         maybe_subscribed = is_subscribed (really_subscribed);
123
124         if (really_subscribed) {
125                 return 0;
126         }
127
128         return new NagScreen (why, maybe_subscribed);
129 }
130
131 void
132 NagScreen::mark_never_again ()
133 {
134         std::string path;
135
136         path = Glib::build_filename (user_config_directory(), ".nevernag");
137
138         ofstream nagfile (path.c_str());
139 }
140
141 void
142 NagScreen::mark_subscriber ()
143 {
144         std::string path;
145
146         path = Glib::build_filename (user_config_directory(), ".askedaboutsub");
147
148         ofstream subsfile (path.c_str());
149 }
150
151 void
152 NagScreen::mark_affirmed_subscriber ()
153 {
154         std::string path;
155
156         path = Glib::build_filename (user_config_directory(), ".isubscribe");
157
158         ofstream subsfile (path.c_str());
159 }
160
161 bool
162 NagScreen::is_subscribed (bool& really)
163 {
164         std::string path;
165
166         really = false;
167
168         /* what we'd really like here is a way to query paypal
169            for someone's subscription status. thats a bit complicated
170            so for now, just see if they ever told us they were
171            subscribed. we try to trust our users :)
172         */
173
174         path = Glib::build_filename (user_config_directory(), ".isubscribe");
175         if (file_test (path, FILE_TEST_EXISTS)) {
176                 really = true;
177                 return true;
178         }
179
180         path = Glib::build_filename (user_config_directory(), ".askedaboutsub");
181         if (file_test (path, FILE_TEST_EXISTS)) {
182                 /* they never said they were subscribed but they
183                    did once express an interest in it.
184                 */
185                 really = false;
186                 return true;
187         }
188
189         return false;
190 }
191
192 void
193 NagScreen::offer_to_donate ()
194 {
195         const char* uri = "http://ardour.org/donate";
196
197         /* we don't care if it fails */
198
199         PBD::open_uri (uri);
200 }
201
202 void
203 NagScreen::offer_to_subscribe ()
204 {
205         const char* uri = "http://ardour.org/subscribe";
206
207         if (PBD::open_uri (uri)) {
208                 mark_subscriber ();
209         }
210 }
211