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