Commit f291efed authored by Jordan Petridis's avatar Jordan Petridis 🌱

AudioPlayer: Wire it to the Message widget.

parent 8df8182b
......@@ -19,6 +19,7 @@
<object class="GtkBox" id="container">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="buttons">
<property name="visible">True</property>
......@@ -26,7 +27,8 @@
<property name="valign">center</property>
<child>
<object class="GtkButton" id="play_button">
<property name="width_request">60</property>
<property name="width_request">-1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Play</property>
......@@ -41,10 +43,10 @@
</child>
<child>
<object class="GtkButton" id="pause_button">
<property name="width_request">60</property>
<property name="visible">True</property>
<property name="width_request">-1</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="no_show_all">True</property>
<property name="tooltip_text" translatable="yes">Play</property>
<property name="image">pause_image</property>
<property name="always_show_image">True</property>
......@@ -70,6 +72,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="spacing">6</property>
<child>
<object class="GtkScale" id="seek">
<property name="visible">True</property>
......
......@@ -52,5 +52,6 @@ use app::App;
fn main() {
static_resources::init().expect("GResource initialization failed.");
gst::init().expect("Error initializing gstreamer");
App::new();
}
......@@ -29,12 +29,10 @@ use gtk::prelude::*;
use glib::SignalHandlerId;
use chrono::NaiveTime;
use failure::Error;
use fragile::Fragile;
use std::ops::Deref;
use std::rc::Rc;
// use std::path::Path;
trait PlayerExt {
fn play(&self);
......@@ -134,7 +132,7 @@ impl Default for AudioPlayerWidget {
config.set_position_update_interval(250);
player.set_config(config).unwrap();
let builder = gtk::Builder::new_from_resource("/org/gnome/Fractal/ui/player_toolbar.ui");
let builder = gtk::Builder::new_from_resource("/org/gnome/Fractal/ui/audio_player.ui");
let container = builder.get_object("container").unwrap();
let buttons = builder.get_object("buttons").unwrap();
......
......@@ -121,25 +121,14 @@ impl<'a> MessageBox<'a> {
content.pack_start(&info, false, false, 0);
}
let body: gtk::Box;
match msg.mtype.as_ref() {
"m.sticker" => {
body = self.build_room_msg_sticker();
}
"m.image" => {
body = self.build_room_msg_image();
}
"m.emote" => {
body = self.build_room_msg_emote(&msg);
}
"m.video" | "m.audio" | "m.file" => {
body = self.build_room_msg_file();
}
_ => {
body = self.build_room_msg_body(&msg.body);
}
}
let body = match msg.mtype.as_ref() {
"m.sticker" => self.build_room_msg_sticker(),
"m.image" => self.build_room_msg_image(),
"m.emote" => self.build_room_msg_emote(&msg),
"m.audio" => self.build_room_audio_player(),
"m.video" | "m.file" => self.build_room_msg_file(),
_ => self.build_room_msg_body(&msg.body),
};
content.pack_start(&body, true, true, 0);
......@@ -315,6 +304,48 @@ impl<'a> MessageBox<'a> {
bx
}
fn build_room_audio_player(&self) -> gtk::Box {
let msg = self.msg;
let bx = gtk::Box::new(gtk::Orientation::Horizontal, 6);
let player = widgets::AudioPlayerWidget::new();
let name = msg.body.clone();
let url = msg.url.clone().unwrap_or_default();
let backend = self.op.backend.clone();
let download_btn = gtk::Button::new_from_icon_name(
"document-save-symbolic",
gtk::IconSize::Button.into(),
);
download_btn.set_tooltip_text(i18n("Save").as_str());
download_btn.connect_clicked(clone!(name, url, backend => move |_| {
let (tx, rx): (Sender<String>, Receiver<String>) = channel();
backend.send(BKCommand::GetMediaAsync(url.clone(), tx)).unwrap();
gtk::timeout_add(50, clone!(name => move || match rx.try_recv() {
Err(TryRecvError::Empty) => gtk::Continue(true),
Err(TryRecvError::Disconnected) => {
let msg = i18n("Could not download the file");
APPOP!(show_error, (msg));
gtk::Continue(true)
},
Ok(fname) => {
let name = name.clone();
APPOP!(save_file_as, (fname, name));
gtk::Continue(false)
}
}));
}));
bx.pack_start(&download_btn, false, false, 0);
bx.pack_start(&player.container, false, true, 0);
bx
}
fn build_room_msg_file(&self) -> gtk::Box {
let msg = self.msg;
let bx = gtk::Box::new(gtk::Orientation::Horizontal, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment