~jeremywootten/pantheon-files/fix-backspace-in-columnv-view

« back to all changes in this revision

Viewing changes to src/View/PropertiesWindow.vala

  • Committer: jeremy at elementaryos
  • Date: 2016-04-03 16:43:53 UTC
  • mfrom: (2023.1.76 pantheon-files)
  • Revision ID: jeremy@elementaryos.org-20160403164353-mad2e7f4cohfgg6f
Merge trunk to r2099

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
}
195
195
 
196
196
public class Marlin.View.PropertiesWindow : Marlin.View.PropertiesWindowBase {
 
197
    private const string resolution_key = _("Resolution:");
 
198
 
197
199
    private class Pair<F, G> {
198
200
        public F key;
199
201
        public G value;
247
249
    }
248
250
 
249
251
    private Gee.Set<string>? mimes;
250
 
 
 
252
    private Gtk.Box info_vbox;
 
253
    private Gtk.Grid information;
251
254
    private Gtk.Widget header_title;
252
255
    private Gtk.Label type_label;
253
256
    private Gtk.Label size_label;
339
342
 
340
343
        /* Info */
341
344
        if (info.size > 0) {
342
 
            var info_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
 
345
            info_vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
343
346
            construct_info_panel (info_vbox, info);
344
347
            add_section (stack, _("General"), PanelType.INFO.to_string (), info_vbox);
345
348
        }
435
438
        size_warning_image.hide ();
436
439
 
437
440
        foreach (GOF.File gof in files) {
 
441
            if (gof.is_root_network_folder ()) {
 
442
                size_label.label = _("unknown");
 
443
                continue;
 
444
            }
438
445
            if (gof.is_directory) {
439
446
                folder_count++;
440
447
                var d = new Marlin.DeepCount (gof.location);
659
666
            }
660
667
        }
661
668
 
662
 
        /* get image size in pixels */
663
 
        var mime = file.icon.to_string ();
664
 
        if ("image" in mime) {
665
 
            string path;
666
 
 
667
 
            if (view.is_in_recent ())
668
 
                path = (file.get_display_target_uri ()).substring (7, -1).replace ("%20", " ");
669
 
            else
670
 
                path = file.location.get_path ();
671
 
 
672
 
            try {
673
 
                Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.from_file (path);
674
 
                var width = pixbuf.get_width ().to_string ();
675
 
                var height = pixbuf.get_height ().to_string ();
676
 
                info.add (new Pair<string, string> (_("Size:"), width +" × " + height + " px"));
677
 
            } catch (Error e) {
678
 
                warning ("Error: %s\n", e.message);
 
669
        /* get image size in pixels using an asynchronous method to stop the interface blocking on
 
670
         * large images. */
 
671
        if ("image" in ftype) {
 
672
            string resolution_value = "";
 
673
            if (file.width > 0) { /* resolution has already been determined */
 
674
                resolution_value = goffile.width.to_string () +" × " + goffile.height.to_string () + " px";
 
675
            } else {
 
676
                resolution_value = _("loading ...");
 
677
                /* Async function will update info when resolution determined */
 
678
                get_resolution.begin (file, info);
679
679
            }
 
680
            info.add (new Pair<string, string> (resolution_key, resolution_value));
680
681
        }
681
682
 
682
683
        if (got_common_location ()) {
702
703
        }
703
704
    }
704
705
 
 
706
    private async void get_resolution (GOF.File goffile, Gee.LinkedList<Pair<string, string>> info) {
 
707
        GLib.FileInputStream? stream = null;
 
708
        GLib.File file = goffile.location;
 
709
        string resolution_value = _("Could not be determined");
 
710
 
 
711
        try {
 
712
            stream = yield file.read_async (0, cancellable);
 
713
            if (stream == null) {
 
714
                error ("Could not read image file's size data");
 
715
            } else {
 
716
                var pixbuf = yield new Gdk.Pixbuf.from_stream_async (stream, cancellable);
 
717
                goffile.width = pixbuf.get_width ();
 
718
                goffile.height = pixbuf.get_height ();
 
719
                resolution_value = goffile.width.to_string () +" × " + goffile.height.to_string () + " px";
 
720
            }
 
721
        } catch (Error e) {
 
722
            warning ("Error loading image resolution in PropertiesWindow: %s", e.message);
 
723
        }
 
724
        try {
 
725
            stream.close ();
 
726
        } catch (GLib.Error e) {
 
727
            debug ("Error closing stream in get_resolution: %s", e.message);
 
728
        }
 
729
 
 
730
        /* Cannot be sure which row the resolution line was added to the grid so we have to search for it */
 
731
        Gtk.Widget? kw = null;
 
732
        int row = 0;
 
733
        do {
 
734
            kw = information.get_child_at (0, row);
 
735
            if (kw is Gtk.Label && (kw as Gtk.Label).label == resolution_key) {
 
736
                Gtk.Widget vw = information.get_child_at (1, row);
 
737
                if (vw is Gtk.Label) {
 
738
                    (vw as Gtk.Label).label = resolution_value;
 
739
                    break;
 
740
                }
 
741
            }
 
742
            row++;
 
743
        } while (kw != null);
 
744
    }
705
745
    private void construct_info_panel (Gtk.Box box, Gee.LinkedList<Pair<string, string>> item_info) {
706
 
        var information = new Gtk.Grid();
 
746
        information = new Gtk.Grid();
707
747
        information.column_spacing = 6;
708
748
        information.row_spacing = 6;
709
749