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