[gnome-control-center/wip/jsparber/background: 5/58] [backport] fix background preview code



commit f2a0924c791994aecdc999ce0d8afdbfc55520db
Merge: 293de2e 9f263c3
Author: Julian Sparber <julian sparber net>
Date:   Mon Oct 23 02:01:23 2017 +0200

    [backport] fix background preview code

 panels/background/cc-background-panel.c |  107 +++++++++++++++++--------------
 1 files changed, 60 insertions(+), 47 deletions(-)
---
diff --cc panels/background/cc-background-panel.c
index f850630,c4ec717..4efece3
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@@ -177,10 -207,11 +177,11 @@@ get_or_create_cached_pixbuf (CcBackgrou
                               CcBackgroundItem  *background)
  {
    GtkAllocation allocation;
--  const gint preview_width = 309;
--  const gint preview_height = 168;
++  const gint preview_width = 310; //309
++  const gint preview_height = 174; //168
    gint scale_factor;
    GdkPixbuf *pixbuf;
+   GdkPixbuf *pixbuf_tmp;
  
    pixbuf = g_object_get_data (G_OBJECT (background), "pixbuf");
    if (pixbuf == NULL)
@@@ -685,100 -733,60 +688,107 @@@ set_background (CcBackgroundPanel *pane
  }
  
  static void
 -on_chooser_dialog_response (GtkDialog         *dialog,
 -                            int                response_id,
 -                            CcBackgroundPanel *self)
 +on_settings_changed (GSettings         *settings,
 +                     gchar             *key,
 +                     CcBackgroundPanel *self)
  {
 -  if (response_id == GTK_RESPONSE_OK)
 -    {
 -      CcBackgroundItem *item;
 -
 -      item = cc_background_chooser_dialog_get_item (CC_BACKGROUND_CHOOSER_DIALOG (dialog));
 -      if (item != NULL)
 -        {
 -          set_background (self, g_object_get_data (G_OBJECT (dialog), "settings"), item);
 -          g_object_unref (item);
 -        }
 -    }
 -
 -  gtk_widget_destroy (GTK_WIDGET (dialog));
 +  reload_current_bg (self, settings);
 +  update_preview (self, settings, NULL);
  }
  
 -static void
 -launch_chooser (CcBackgroundPanel *panel,
 -                GSettings         *settings)
 +static GtkWidget *
 +create_view (GtkWidget *parent, GtkTreeModel *model)
  {
 -  GtkWidget *dialog;
 -
 -  dialog = cc_background_chooser_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (WID 
("background-panel"))));
 -  g_object_set_data (G_OBJECT (dialog), "settings", settings);
 -  gtk_widget_show (dialog);
 -  g_signal_connect (dialog, "response", G_CALLBACK (on_chooser_dialog_response), panel);
 -  panel->chooser = dialog;
 -  g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &panel->chooser);
 +  GtkCellRenderer *renderer;
 +  GtkWidget *icon_view;
 +  GtkWidget *sw;
 +
 +  sw = gtk_scrolled_window_new (NULL, NULL);
 +  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 +  gtk_widget_set_hexpand (sw, TRUE);
 +  gtk_widget_set_vexpand (sw, TRUE);
 +
 +  icon_view = gtk_icon_view_new ();
 +  gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), model);
 +  gtk_widget_set_hexpand (icon_view, TRUE);
 +  gtk_container_add (GTK_CONTAINER (sw), icon_view);
 +
 +  gtk_icon_view_set_columns (GTK_ICON_VIEW (icon_view), 3);
 +
 +  renderer = gtk_cell_renderer_pixbuf_new ();
 +  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
 +                              renderer,
 +                              FALSE);
 +  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
 +                                  renderer,
 +                                  "surface", 0,
 +                                  NULL);
 +
 +  return sw;
  }
  
 -static void
 -on_background_button_clicked (GtkButton         *button,
 -                              CcBackgroundPanel *self)
 +static gboolean
 +on_slides_draw (GtkWidget         *widget,
 +                cairo_t           *cr,
 +                CcBackgroundPanel *panel)
  {
 -  launch_chooser (self, self->settings);
 -}
 +  GdkPixbuf *pixbuf;
  
 +  g_print("Redraw: %s\n", gtk_widget_get_name(widget));
 +  pixbuf = get_or_create_cached_pixbuf (panel, widget, panel->current_background);
 +
 +  cr = gdk_cairo_create (gtk_widget_get_window (widget));
 +  gdk_cairo_set_source_pixbuf (cr,
 +                               pixbuf,
 +                               0, 0);
 +  cairo_paint (cr);
 +  cairo_destroy (cr);
 +  return TRUE;
 +}
+ static void
 -on_lock_button_clicked (GtkButton         *button,
 -                        CcBackgroundPanel *self)
++on_background_select (GtkFlowBox      *box,
++                      GtkFlowBoxChild *child,
++                      gpointer         user_data)
+ {
 -  launch_chooser (self, self->lock_settings);
++    g_debug ("New background selected");
+ }
  
 +
  static void
 -on_settings_changed (GSettings         *settings,
 -                     gchar             *key,
 -                     CcBackgroundPanel *self)
 +cc_background_create_wallpapers (CcBackgroundPanel *panel, GtkWidget *parent)
  {
 -  reload_current_bg (self, settings);
 -  update_preview (self, settings, NULL);
 +  //GtkListStore *model;
 +  //GtkWidget *sw;
 +  //model = bg_source_get_liststore (BG_SOURCE (bg_wallpapers_source_new (GTK_WINDOW (WID 
("background-desktop-drawingarea")))));
 +  //sw = create_view (parent, GTK_TREE_MODEL (model));
 +
 +  GtkWidget *box;
 +  GtkWidget *widget;
 +  GdkPixbuf *pixbuf;
 +  const gint preview_width = 309;
 +  const gint preview_height = 168;
 +  gint scale_factor;
 +
 +  scale_factor = gtk_widget_get_scale_factor (panel);
 +  for (int i = 0; i < 18; i++) {
 +    //widget = gtk_drawing_area_new ();
 +    box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 +    pixbuf = gdk_pixbuf_new_from_file ("/usr/share/backgrounds/gnome/adwaita-day.jpg", NULL);
 +    pixbuf = gdk_pixbuf_scale_simple (pixbuf,
 +                                      preview_width,
 +                                      preview_height,
 +                                      GDK_INTERP_BILINEAR);
 +
 +    //widget = gtk_image_new ();
 +    //pixbuf = get_or_create_cached_pixbuf (panel, widget, panel->current_background);
 +    widget = gtk_image_new_from_pixbuf (pixbuf);
 +
 +    gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
 +    gtk_flow_box_insert (GTK_FLOW_BOX (parent), box, -1);
 +    //g_signal_connect (G_OBJECT (widget), "draw",
 +    //                G_CALLBACK (on_slides_draw), panel);
 +
 +  }
  }
  
  static void
@@@ -808,10 -814,8 +818,13 @@@ cc_background_panel_init (CcBackgroundP
    panel->settings = g_settings_new (WP_PATH_ID);
    g_settings_delay (panel->settings);
  
 -  panel->lock_settings = g_settings_new (WP_LOCK_PATH_ID);
 -  g_settings_delay (panel->lock_settings);
 +  /* add the gallery widget */
 +  widget = WID ("background-gallery");
 +
++  g_signal_connect (G_OBJECT (widget), "child-activated",
++                    G_CALLBACK (on_background_select), panel);
++
 +  cc_background_create_wallpapers (panel, widget);
  
    /* add the top level widget */
    widget = WID ("background-panel");


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