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