summaryrefslogtreecommitdiff
path: root/gtk2_ardour/nag.cc
blob: d553efd1979220bf97629d596ad98e4a75ddaca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
    Copyright (C) 2012 Paul Davis

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifdef WAF_BUILD
#include "gtk2ardour-config.h"
#endif

#include "pbd/gstdio_compat.h"
#include <gtkmm/stock.h>

#include "pbd/openuri.h"

#include "ardour/filesystem_paths.h"
#include "ardour/rc_configuration.h"

#include "nag.h"
#include "pbd/i18n.h"

using namespace ARDOUR;
using namespace std;
using namespace Glib;
using namespace Gtk;

NagScreen::NagScreen (std::string /*context*/, bool maybe_sub)
	: ArdourDialog (string_compose (_("Support %1 Development"), PROGRAM_NAME), true)
	, donate_button (button_group, _("I'd like to make a one-time donation"))
	, subscribe_button (button_group, _("Tell me more about becoming a subscriber"))
	, existing_button (button_group, _("I'm already a subscriber!"))
	, next_time_button (button_group, _("Ask about this the next time I export"))
	, never_again_button (button_group, _("Never ever ask me about this again"))
{
	if (maybe_sub) {
		message.set_text (_("Congratulations on your session export.\n\n\
It looks as if you may already be a subscriber. If so, thanks, and sorry\n\
to bother you again about this - I'm working on improving our subscriber system\n\
so that I don't have to keep annoying you with this message.\n\n\
If you're not a subscriber, perhaps you might consider supporting my work\n\
on Ardour with either a one-time donation or subscription. Nothing will \n\
happen if you choose not to do so. However Ardour's continuing development\n\
relies on a stable, sustainable income stream. Thanks for using Ardour!"));
	} else {
		message.set_text (_("Congratulations on your session export.\n\n\
I hope you find Ardour a useful tool. I'd like to ask you to consider supporting\n\
its development with either a one-time donation or subscription. Nothing\n\
will happen if you choose not to do so. However Ardour's continuing development\n\
relies on a stable, sustainable income stream. Thanks for using Ardour!"));
	}

	button_box.pack_start (donate_button);
	button_box.pack_start (subscribe_button);
	button_box.pack_start (existing_button);
	button_box.pack_start (next_time_button);
	button_box.pack_start (never_again_button);

	get_vbox()->set_spacing (12);
	get_vbox()->pack_start (message);
	get_vbox()->pack_start (button_box);

	set_border_width (12);
	add_button (Stock::OK, RESPONSE_ACCEPT);
}

NagScreen::~NagScreen ()
{
}

void
NagScreen::nag ()
{
	show_all ();

	int response = run ();

	hide ();

	switch (response) {
	case RESPONSE_ACCEPT:
		break;
	default:
		return;
	}

	if (donate_button.get_active()) {
		offer_to_donate ();
	} else if (subscribe_button.get_active()) {
		offer_to_subscribe ();
	} else if (never_again_button.get_active ()) {
		mark_never_again ();
	} else if (existing_button.get_active ()) {
		mark_affirmed_subscriber ();
	}
}

NagScreen*
NagScreen::maybe_nag (std::string why)
{
	std::string path;
	bool really_subscribed;
	bool maybe_subscribed;

	path = Glib::build_filename (user_config_directory(), ".nevernag");

	if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
		return 0;
	}

	maybe_subscribed = is_subscribed (really_subscribed);

	if (really_subscribed) {
		return 0;
	}

	return new NagScreen (why, maybe_subscribed);
}

void
NagScreen::mark_never_again ()
{
	std::string path;

	path = Glib::build_filename (user_config_directory(), ".nevernag");

	g_file_set_contents (path.c_str(), "", -1, NULL);
}

void
NagScreen::mark_subscriber ()
{
	std::string path;

	path = Glib::build_filename (user_config_directory(), ".askedaboutsub");

	g_file_set_contents (path.c_str(), "", -1, NULL);
}

void
NagScreen::mark_affirmed_subscriber ()
{
	std::string path;

	path = Glib::build_filename (user_config_directory(), ".isubscribe");

	g_file_set_contents (path.c_str(), "", -1, NULL);
}

bool
NagScreen::is_subscribed (bool& really)
{
	std::string path;

	really = false;

	/* what we'd really like here is a way to query paypal
	   for someone's subscription status. thats a bit complicated
	   so for now, just see if they ever told us they were
	   subscribed. we try to trust our users :)
	*/

	path = Glib::build_filename (user_config_directory(), ".isubscribe");
	if (file_test (path, FILE_TEST_EXISTS)) {
		really = true;
		return true;
	}

	path = Glib::build_filename (user_config_directory(), ".askedaboutsub");
	if (file_test (path, FILE_TEST_EXISTS)) {
		/* they never said they were subscribed but they
		   did once express an interest in it.
		*/
		really = false;
		return true;
	}

	return false;
}

void
NagScreen::offer_to_donate ()
{
	/* we don't care if it fails */

        PBD::open_uri (Config->get_donate_url());
}

void
NagScreen::offer_to_subscribe ()
{
	const char* uri = "http://ardour.org/subscribe";

	if (PBD::open_uri (uri)) {
		mark_subscriber ();
	}
}