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