Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send notification when recording has finished. #142

Merged
merged 16 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,39 @@ public class Camera.MainWindow : Hdy.ApplicationWindow {
camera_view = new Widgets.CameraView ();
camera_view.bind_property ("horizontal-flip", header_bar, "horizontal-flip", GLib.BindingFlags.BIDIRECTIONAL | GLib.BindingFlags.SYNC_CREATE);

var overlay = new Gtk.Overlay ();
overlay.add (camera_view);

var recording_finished_toast = new Granite.Widgets.Toast (_("Saved to Videos"));
recording_finished_toast.set_default_action (_("View File"));
recording_finished_toast.set_data ("location", "");
recording_finished_toast.default_action.connect (() => {
var file_path = recording_finished_toast.get_data<string> ("location");
var file = GLib.File.new_for_path (file_path);
try {
AppInfo.launch_default_for_uri (file.get_parent ().get_uri (), new Gdk.AppLaunchContext ());
} catch (Error e) {
warning ("Error launching file manager: %s", e.message);
}
});
overlay.add_overlay (recording_finished_toast);

var recording_finished_fail_toast = new Granite.Widgets.Toast (_("Recording failed"));
overlay.add_overlay (recording_finished_fail_toast);

camera_view.recording_finished.connect ((file_path) => {
if (file_path == "") {
recording_finished_fail_toast.send_notification ();
} else {
recording_finished_toast.set_data ("location", file_path);
recording_finished_toast.send_notification ();
}
});


var grid = new Gtk.Grid ();
grid.attach (header_bar, 0, 0);
grid.attach (camera_view, 0, 1);
grid.attach (overlay, 0, 1);

var window_handle = new Hdy.WindowHandle ();
window_handle.add (grid);
Expand Down
13 changes: 12 additions & 1 deletion src/Widgets/CameraView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/

public class Camera.Widgets.CameraView : Gtk.Stack {
public signal void recording_finished (string file_path);

private Gtk.Grid status_grid;
private Granite.Widgets.AlertView no_device_view;
private Gtk.Label status_label;
Expand Down Expand Up @@ -367,7 +369,7 @@ public class Camera.Widgets.CameraView : Gtk.Stack {
missing_messages += Gst.PbUtils.missing_element_installer_detail_new ("vorbisenc");
}

var filesink = Gst.ElementFactory.make ("filesink", null);
var filesink = Gst.ElementFactory.make ("filesink", "filesink");
if (filesink == null) {
missing_messages += Gst.PbUtils.missing_element_installer_detail_new ("filesink");
} else {
Expand Down Expand Up @@ -404,6 +406,15 @@ public class Camera.Widgets.CameraView : Gtk.Stack {

pipeline.set_state (Gst.State.PAUSED);
tee.unlink (record_bin);
var filesink = record_bin.get_by_name ("filesink");

if (filesink != null) {
var locationval = GLib.Value (typeof (string));
filesink.get_property ("location", ref locationval);
string location = locationval.get_string ();
recording_finished (location);
}

pipeline.remove (record_bin);
pipeline.set_state (Gst.State.PLAYING);
record_bin.set_state (Gst.State.NULL);
Expand Down