fix lack of return value in tell_about_jack_death(), and fixed up indentation for...
[ardour2.git] / gtk2_ardour / nag.cc
blob301dc2036a9719e5e9feebf203bba27c1ab2ae1b
1 #include <fstream>
2 #include <gtkmm/stock.h>
4 #include <ardour/ardour.h>
6 #include "nag.h"
7 #include "i18n.h"
9 using namespace ARDOUR;
10 using namespace std;
11 using namespace Glib;
12 using namespace Gtk;
14 NagScreen::NagScreen (std::string context, bool maybe_sub)
15 : ArdourDialog (_("Support Ardour Development"), true)
16 , donate_button (button_group, _("I'd like to make a one-time donation"))
17 , subscribe_button (button_group, _("Tell me more about becoming a subscriber"))
18 , existing_button (button_group, _("I'm already a subscriber!"))
19 , next_time_button (button_group, _("Ask about this the next time I export"))
20 , never_again_button (button_group, _("Never ever ask me about this again"))
22 if (maybe_sub) {
23 message.set_text (_("Congratulations on your session export.\n\n\
24 It looks as if you may already be a subscriber. If so, thanks, and sorry\n\
25 to bother you again about this - I'm working on improving our subscriber system\n\
26 so that I don't have to keep annoying you with this message.\n\n\
27 If you're not a subscriber, perhaps you might consider supporting my work\n\
28 on Ardour with either a one-time donation or subscription. Nothing will \n\
29 happen if you choose not to do so. However Ardour's continuing development\n\
30 relies on a stable, sustainable income stream. Thanks for using Ardour!"));
31 } else {
32 message.set_text (_("Congratulations on your session export.\n\n\
33 I hope you find Ardour a useful tool. I'd like to ask you to consider supporting\n\
34 its development with either a one-time donation or subscription. Nothing\n\
35 will happen if you choose not to do so. However Ardour's continuing development\n\
36 relies on a stable, sustainable income stream. Thanks for using Ardour!"));
39 button_box.pack_start (donate_button);
40 button_box.pack_start (subscribe_button);
41 button_box.pack_start (existing_button);
42 button_box.pack_start (next_time_button);
43 button_box.pack_start (never_again_button);
45 get_vbox()->set_spacing (12);
46 get_vbox()->pack_start (message);
47 get_vbox()->pack_start (button_box);
49 set_border_width (12);
50 add_button (Stock::OK, RESPONSE_ACCEPT);
53 NagScreen::~NagScreen ()
57 void
58 NagScreen::nag ()
60 show_all ();
62 int response = run ();
64 hide ();
66 switch (response) {
67 case RESPONSE_ACCEPT:
68 break;
69 default:
70 return;
73 if (donate_button.get_active()) {
74 offer_to_donate ();
75 } else if (subscribe_button.get_active()) {
76 offer_to_subscribe ();
77 } else if (never_again_button.get_active ()) {
78 mark_never_again ();
79 } else if (existing_button.get_active ()) {
80 mark_affirmed_subscriber ();
84 NagScreen*
85 NagScreen::maybe_nag (std::string why)
87 Glib::ustring path;
88 bool really_subscribed;
89 bool maybe_subscribed;
91 path = Glib::build_filename (get_user_ardour_path(), ".nevernag");
93 if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
94 return 0;
97 maybe_subscribed = is_subscribed (really_subscribed);
99 if (really_subscribed) {
100 return 0;
103 return new NagScreen (why, maybe_subscribed);
106 void
107 NagScreen::mark_never_again ()
109 Glib::ustring path;
111 path = Glib::build_filename (get_user_ardour_path(), ".nevernag");
113 ofstream nagfile (path.c_str());
116 void
117 NagScreen::mark_subscriber ()
119 Glib::ustring path;
121 path = Glib::build_filename (get_user_ardour_path(), ".askedaboutsub");
123 ofstream subsfile (path.c_str());
126 void
127 NagScreen::mark_affirmed_subscriber ()
129 Glib::ustring path;
131 path = Glib::build_filename (get_user_ardour_path(), ".isubscribe");
133 ofstream subsfile (path.c_str());
136 bool
137 NagScreen::is_subscribed (bool& really)
139 Glib::ustring path;
141 really = false;
143 /* what we'd really like here is a way to query paypal
144 for someone's subscription status. thats a bit complicated
145 so for now, just see if they ever told us they were
146 subscribed. we try to trust our users :)
149 path = Glib::build_filename (get_user_ardour_path(), ".isubscribe");
150 if (file_test (path, FILE_TEST_EXISTS)) {
151 really = true;
152 return true;
155 path = Glib::build_filename (get_user_ardour_path(), ".askedaboutsub");
156 if (file_test (path, FILE_TEST_EXISTS)) {
157 /* they never said they were subscribed but they
158 did once express an interest in it.
160 really = false;
161 return true;
164 return false;
167 void
168 NagScreen::offer_to_donate ()
170 const char* uri = "http://ardour.org/donate";
172 /* we don't care if it fails */
174 open_uri (uri);
177 void
178 NagScreen::offer_to_subscribe ()
180 const char* uri = "http://ardour.org/subscribe";
182 if (open_uri (uri)) {
183 mark_subscriber ();
187 bool
188 NagScreen::open_uri (const char* uri)
190 #ifdef HAVE_GTK_OPEN_URI
191 GError* err;
192 return gtk_open_uri (0, uri, GDK_CURRENT_TIME, &err);
193 #else
194 #ifndef __APPLE__
195 std::string command = "xdg-open ";
196 command += uri;
197 spawn_command_line_async (command);
199 return true;
200 #else
201 extern bool cocoa_open_url (const char*);
202 return cocoa_open_url (uri);
203 #endif
204 #endif