[gnome-boxes] actions-popover: Add "Take Screenshot" action



commit 449b86c7a3a54d8e735a8307668818ca7503e67c
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Mar 20 10:58:44 2017 +0100

    actions-popover: Add "Take Screenshot" action
    
    This feature allows screenshots to be easily taken in the display
    mode.
    
    The resulting png files are stored in the user's pictures folder,
    named with the same format as gnome-settings-daemon screenshots:
    _("Screenshot from %Y-%m-%d %H-%M-%S").
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780256

 src/actions-popover.vala |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/src/actions-popover.vala b/src/actions-popover.vala
index c47ba45..b013012 100644
--- a/src/actions-popover.vala
+++ b/src/actions-popover.vala
@@ -4,6 +4,7 @@ private class Boxes.ActionsPopover: Gtk.Popover {
     private const GLib.ActionEntry[] action_entries = {
         {"open-in-new-win", open_in_new_win_activated},
         {"favorite",        favorite_activated},
+        {"take_screenshot", take_screenshot_activated},
         {"pause",           pause_activated},
         {"force_shutdown",  force_shutdown_activated},
         {"delete",          delete_activated},
@@ -51,6 +52,9 @@ private class Boxes.ActionsPopover: Gtk.Popover {
             section.append (_("Add to Favorites"), "box.favorite");
         menu.append_section (null, section);
 
+        // Take Screenshot
+        section.append (_("Take Screenshot"), "box.take_screenshot");
+
         // New section for force shutdown, pause and delete
         section = new GLib.Menu ();
 
@@ -104,6 +108,27 @@ private class Boxes.ActionsPopover: Gtk.Popover {
         machine.config.set_category ("favorite", enabled);
     }
 
+    private string get_screenshot_filename () {
+        var now = new GLib.DateTime.now_local ();
+        var timestamp = now.format ("%Y-%m-%d %H-%M-%S");
+
+        // Translators: %s => the timestamp of when the screenshot was taken.
+        var filename =_("Screenshot from %s").printf (timestamp);
+
+        return Path.build_filename (GLib.Environment.get_user_special_dir (GLib.UserDirectory.PICTURES),
+                                    filename);
+    }
+
+    private void take_screenshot_activated () {
+        var machine = window.current_item as Machine;
+        try {
+            Gdk.Pixbuf pixbuf = machine.display.get_pixbuf (0);
+            pixbuf.save (get_screenshot_filename (), "png");
+        } catch (GLib.Error error) {
+            warning (error.message);
+        }
+    }
+
     private void pause_activated () {
         var machine = window.current_item as Machine;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]