enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / soundcloud_export_selector.cc
1 /* soundcloud_export_selector.cpp ***************************************************
2
3         Adapted for Ardour by Ben Loftis, March 2012
4
5         Licence GPL:
6
7         This program is free software; you can redistribute it and/or
8         modify it under the terms of the GNU General Public License
9         as published by the Free Software Foundation; either version 2
10         of the License, or (at your option) any later version.
11
12         This program is distributed in the hope that it will be useful,
13         but WITHOUT ANY WARRANTY; without even the implied warranty of
14         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15         GNU General Public License for more details.
16
17         You should have received a copy of the GNU General Public License
18         along with this program; if not, write to the Free Software
19         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21
22 *************************************************************************************/
23 #include "ardour/debug.h"
24 #include "ardour/soundcloud_upload.h"
25 #include "soundcloud_export_selector.h"
26
27 #include <pbd/error.h>
28 #include "pbd/openuri.h"
29
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <iostream>
33 #include "pbd/gstdio_compat.h"
34
35 #include "pbd/i18n.h"
36
37 using namespace PBD;
38
39 #include "ardour/session_metadata.h"
40 #include "utils.h"
41
42 SoundcloudExportSelector::SoundcloudExportSelector () :
43           sc_table (4, 3),
44           soundcloud_username_label (_("User Email"), 1.0, 0.5),
45           soundcloud_password_label (_("Password"), 1.0, 0.5),
46           soundcloud_public_checkbox (_("Make files public")),
47           soundcloud_open_checkbox (_("Open uploaded files in browser")),
48           soundcloud_download_checkbox (_("Make files downloadable")),
49           progress_bar()
50 {
51
52
53         soundcloud_public_checkbox.set_name ("ExportCheckbox");
54         soundcloud_download_checkbox.set_name ("ExportCheckbox");
55         soundcloud_username_label.set_name ("ExportFormatLabel");
56         soundcloud_username_entry.set_name ("ExportFormatDisplay");
57         soundcloud_password_label.set_name ("ExportFormatLabel");
58         soundcloud_password_entry.set_name ("ExportFormatDisplay");
59
60         soundcloud_username_entry.set_text (ARDOUR::SessionMetadata::Metadata()->user_email());
61         soundcloud_password_entry.set_visibility (false);
62
63         Gtk::Frame *sc_frame = manage (new Gtk::Frame);
64         sc_frame->set_border_width (4);
65         sc_frame->set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
66         sc_frame->set_name ("soundcloud_export_box");
67         pack_start (*sc_frame, false, false);
68
69         sc_table.set_border_width (4);
70         sc_table.set_col_spacings (5);
71         sc_table.set_row_spacings (5);
72         sc_frame->add (sc_table);
73
74         sc_table.attach ( *(Gtk::manage (new Gtk::Image (ARDOUR_UI_UTILS::get_icon (X_("soundcloud"))))) , 0, 1,  0, 2);
75
76         sc_table.attach (soundcloud_username_label,    0, 1,  1, 2);
77         sc_table.attach (soundcloud_username_entry,    1, 3,  1, 2);
78         sc_table.attach (soundcloud_password_label,    0, 1,  2, 3);
79         sc_table.attach (soundcloud_password_entry,    1, 3,  2, 3);
80         sc_table.attach (soundcloud_public_checkbox,   2, 3,  3, 4);
81         sc_table.attach (soundcloud_open_checkbox,     2, 3,  4, 5);
82         sc_table.attach (soundcloud_download_checkbox, 2, 3,  5, 6);
83
84         pack_end (progress_bar, false, false);
85         sc_frame->show_all ();
86 }
87
88
89 int
90 SoundcloudExportSelector::do_progress_callback (double ultotal, double ulnow, const std::string &filename)
91 {
92         DEBUG_TRACE (DEBUG::Soundcloud, string_compose ("SoundcloudExportSelector::do_progress_callback(%1, %2, %3)", ultotal, ulnow, filename));
93         if (soundcloud_cancel) {
94                 progress_bar.set_fraction (0);
95                 // cancel_button.set_label ("");
96                 return -1;
97         }
98
99         double fraction = 0.0;
100         if (ultotal != 0) {
101                 fraction = ulnow / ultotal;
102         }
103
104         progress_bar.set_fraction ( fraction );
105
106         std::string prog;
107         prog = string_compose (_("%1: %2 of %3 bytes uploaded"), filename, ulnow, ultotal);
108         progress_bar.set_text (prog);
109
110
111         return 0;
112 }
113