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