Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: Vala  |  size: 2.20 KB  |  hits: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         public void load_thumbs(){
  2.  
  3.             pane.set_visible(false);
  4.             pane.newmodel = new Gtk.ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
  5.             pane.set_selection_mode (Gtk.SelectionMode.SINGLE);
  6.             pane.set_pixbuf_column (0);
  7.             pane.set_model(pane.newmodel);
  8.  
  9.             string icon_style = """
  10.                         .thumbnail-view {
  11.                    background-color: #FFFFFF;
  12.                }
  13.                .thumbnail-view:selected {
  14.                    background-color: #9D9D9D;
  15.                    border-color: shade (mix (rgb (34, 255, 120), #fff, 0.5), 0.9);
  16.                }
  17.            """;
  18.  
  19.             var icon_view_style = new Gtk.CssProvider ();
  20.  
  21.             try {
  22.                 icon_view_style.load_from_data (icon_style, -1);
  23.             } catch (Error e) {
  24.                 warning (e.message);
  25.             }
  26.             pane.get_style_context ().add_class ("thumbnail-view");
  27.             pane.get_style_context ().add_provider (icon_view_style, Gtk.STYLE_PROVIDER_PRIORITY_THEME);
  28.             //Add thumbnails to the iconview
  29.             string buff1, buff2;
  30.             for(int i=1; i<pane.image_list.size; i++){
  31.                 buff1 = pane.image_list.get_full_filename(i);
  32.                 buff2 = pane.image_list.get_filename(i);
  33.                 load_image_async.begin (buff2, buff1, (obj, async_res) => {
  34.                  GLib.debug ("Finished loading.");
  35.                   });
  36.             }
  37.             pane.selection_changed.connect (update_selected);
  38.             pane.set_sensitive(true);
  39.             this.queue_draw();
  40.     }
  41.  
  42.  
  43. //I will use this as a base code to code the async load of stuff
  44.     private async void load_image_async (string filename, string full_filename) {
  45.           GLib.File file = GLib.File.new_for_commandline_arg (full_filename);
  46.           try {
  47.             GLib.InputStream stream = yield file.read_async ();
  48.             Gdk.Pixbuf image = yield Gdk.Pixbuf.new_from_stream_at_scale_async (stream, 110, -1, true);
  49.             // Add the image name and thumbnail to the IconView
  50.             Gtk.TreeIter root;
  51.             pane.newmodel.append(out root);
  52.             pane.newmodel.set(root, 0, image, -1);
  53.             pane.newmodel.set(root, 1, filename, -1);
  54.             pane.iters.append (root);      
  55.             stdout.printf("Added %s to thumbnail\n", filename);
  56.           } catch ( GLib.Error e ) {
  57.             GLib.error (e.message);
  58.           }
  59.     }