Numerical sort patch from mantis #2654
[ardour.git] / gtk2_ardour / nag.cc
1 #include <fstream>
2 #include <gtkmm/stock.h>
3
4 #include <ardour/ardour.h>
5
6 #include "nag.h"
7 #include "i18n.h"
8
9 using namespace ARDOUR;
10 using namespace std;
11 using namespace Glib;
12 using namespace Gtk;
13
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"))
21 {
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!"));
37         }
38         
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);
44         
45         get_vbox()->set_spacing (12);
46         get_vbox()->pack_start (message);
47         get_vbox()->pack_start (button_box);
48
49         set_border_width (12);
50         add_button (Stock::OK, RESPONSE_ACCEPT);
51 }
52
53 NagScreen::~NagScreen ()
54 {
55 }
56
57 void
58 NagScreen::nag ()
59 {
60         show_all ();
61
62         int response = run ();
63
64         hide ();
65
66         switch (response) {
67         case RESPONSE_ACCEPT:
68                 break;
69         default:
70                 return;
71         }
72
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 ();
81         }
82 }
83
84 NagScreen*
85 NagScreen::maybe_nag (std::string why)
86 {
87         Glib::ustring path;
88         bool really_subscribed;
89         bool maybe_subscribed;
90
91         path = Glib::build_filename (get_user_ardour_path(), ".nevernag");
92
93         if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
94                 return 0;
95         }
96
97         maybe_subscribed = is_subscribed (really_subscribed);
98         
99         if (really_subscribed) {
100                 return 0;
101         }
102
103         return new NagScreen (why, maybe_subscribed);
104 }
105
106 void
107 NagScreen::mark_never_again ()
108 {
109         Glib::ustring path;
110
111         path = Glib::build_filename (get_user_ardour_path(), ".nevernag");
112         
113         ofstream nagfile (path.c_str());
114 }
115
116 void
117 NagScreen::mark_subscriber ()
118 {
119         Glib::ustring path;
120
121         path = Glib::build_filename (get_user_ardour_path(), ".askedaboutsub");
122         
123         ofstream subsfile (path.c_str());
124 }
125
126 void
127 NagScreen::mark_affirmed_subscriber ()
128 {
129         Glib::ustring path;
130
131         path = Glib::build_filename (get_user_ardour_path(), ".isubscribe");
132         
133         ofstream subsfile (path.c_str());
134 }
135
136 bool
137 NagScreen::is_subscribed (bool& really)
138 {
139         Glib::ustring path;
140
141         really = false;
142
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 :)
147         */
148
149         path = Glib::build_filename (get_user_ardour_path(), ".isubscribe");
150         if (file_test (path, FILE_TEST_EXISTS)) {
151                 really = true;
152                 return true;
153         }
154
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.
159                 */
160                 really = false;
161                 return true;
162         }
163
164         return false;
165 }
166
167 void
168 NagScreen::offer_to_donate ()
169 {
170         const char* uri = "http://ardour.org/donate";
171
172         /* we don't care if it fails */
173
174         open_uri (uri);
175 }
176
177 void
178 NagScreen::offer_to_subscribe ()
179 {
180         const char* uri = "http://ardour.org/subscribe";
181
182         if (open_uri (uri)) {
183                 mark_subscriber ();
184         }
185 }
186
187 bool
188 NagScreen::open_uri (const char* uri)
189 {
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);
198
199         return true;
200 #else
201         extern bool cocoa_open_url (const char*);
202         return cocoa_open_url (uri);
203 #endif
204 #endif
205 }