summaryrefslogtreecommitdiff
path: root/gtk2_ardour/soundcloud_export_selector.cc
blob: e7e43adea0a9b16d4f31e4cfdbc1119fb76d1c97 (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
/* soundcloud_export_selector.cpp ***************************************************

	Adapted for Ardour by Ben Loftis, March 2012

	Licence GPL:

	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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


*************************************************************************************/
#include "ardour/debug.h"
#include "ardour/soundcloud_upload.h"
#include "soundcloud_export_selector.h"

#include <pbd/error.h>
#include "pbd/openuri.h"

#include <sys/stat.h>
#include <sys/types.h>
#include <iostream>
#include "pbd/gstdio_compat.h"

#include "pbd/i18n.h"

using namespace PBD;

#include "ardour/session_metadata.h"
#include "utils.h"

SoundcloudExportSelector::SoundcloudExportSelector () :
	  sc_table (4, 3),
	  soundcloud_username_label (_("User Email"), 1.0, 0.5),
	  soundcloud_password_label (_("Password"), 1.0, 0.5),
	  soundcloud_public_checkbox (_("Make files public")),
	  soundcloud_open_checkbox (_("Open uploaded files in browser")),
	  soundcloud_download_checkbox (_("Make files downloadable")),
	  progress_bar()
{


	soundcloud_public_checkbox.set_name ("ExportCheckbox");
	soundcloud_download_checkbox.set_name ("ExportCheckbox");
	soundcloud_username_label.set_name ("ExportFormatLabel");
	soundcloud_username_entry.set_name ("ExportFormatDisplay");
	soundcloud_password_label.set_name ("ExportFormatLabel");
	soundcloud_password_entry.set_name ("ExportFormatDisplay");

	soundcloud_username_entry.set_text (ARDOUR::SessionMetadata::Metadata()->user_email());
	soundcloud_password_entry.set_visibility (false);

	Gtk::Frame *sc_frame = manage (new Gtk::Frame);
	sc_frame->set_border_width (4);
	sc_frame->set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
	sc_frame->set_name ("soundcloud_export_box");
	pack_start (*sc_frame, false, false);

	sc_table.set_border_width (4);
	sc_table.set_col_spacings (5);
	sc_table.set_row_spacings (5);
	sc_frame->add (sc_table);

	sc_table.attach ( *(Gtk::manage (new Gtk::Image (ARDOUR_UI_UTILS::get_icon (X_("soundcloud"))))) , 0, 1,  0, 2);

	sc_table.attach (soundcloud_username_label,    0, 1,  1, 2);
	sc_table.attach (soundcloud_username_entry,    1, 3,  1, 2);
	sc_table.attach (soundcloud_password_label,    0, 1,  2, 3);
	sc_table.attach (soundcloud_password_entry,    1, 3,  2, 3);
	sc_table.attach (soundcloud_public_checkbox,   2, 3,  3, 4);
	sc_table.attach (soundcloud_open_checkbox,     2, 3,  4, 5);
	sc_table.attach (soundcloud_download_checkbox, 2, 3,  5, 6);

	pack_end (progress_bar, false, false);
	sc_frame->show_all ();
}


int
SoundcloudExportSelector::do_progress_callback (double ultotal, double ulnow, const std::string &filename)
{
	DEBUG_TRACE (DEBUG::Soundcloud, string_compose ("SoundcloudExportSelector::do_progress_callback(%1, %2, %3)", ultotal, ulnow, filename));
	if (soundcloud_cancel) {
		progress_bar.set_fraction (0);
		// cancel_button.set_label ("");
		return -1;
	}

	double fraction = 0.0;
	if (ultotal != 0) {
		fraction = ulnow / ultotal;
	}

	progress_bar.set_fraction ( fraction );

	std::string prog;
	prog = string_compose (_("%1: %2 of %3 bytes uploaded"), filename, ulnow, ultotal);
	progress_bar.set_text (prog);


	return 0;
}