Exemplo n.º 1
0
static GdkPaintable *
gtk_icon_helper_load_paintable (GtkIconHelper   *self,
                                gboolean        *out_symbolic)
{
  GdkPaintable *paintable;
  GIcon *gicon;
  gboolean symbolic;

  switch (gtk_image_definition_get_storage_type (self->def))
    {
    case GTK_IMAGE_PAINTABLE:
      paintable = g_object_ref (gtk_image_definition_get_paintable (self->def));
      symbolic = FALSE;
      break;

    case GTK_IMAGE_ICON_NAME:
      if (self->use_fallback)
        gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name (self->def));
      else
        gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->def));
      paintable = ensure_paintable_for_gicon (self,
                                              gtk_css_node_get_style (self->node),
                                              gtk_widget_get_direction (self->owner),
                                              gtk_widget_get_scale_factor (self->owner),
                                              gicon,
                                              &symbolic);
      g_object_unref (gicon);
      break;

    case GTK_IMAGE_GICON:
      paintable = ensure_paintable_for_gicon (self, 
                                              gtk_css_node_get_style (self->node),
                                              gtk_widget_get_direction (self->owner),
                                              gtk_widget_get_scale_factor (self->owner),
                                              gtk_image_definition_get_gicon (self->def),
                                              &symbolic);
      break;

    case GTK_IMAGE_EMPTY:
    default:
      paintable = NULL;
      symbolic = FALSE;
      break;
    }

  *out_symbolic = symbolic;

  return paintable;
}
Exemplo n.º 2
0
/**
 * gs_shell_main_window_mapped_cb:
 */
static void
gs_shell_main_window_mapped_cb (GtkWidget *widget, GsShell *shell)
{
	GsShellPrivate *priv = gs_shell_get_instance_private (shell);
	gs_plugin_loader_set_scale (priv->plugin_loader,
				    gtk_widget_get_scale_factor (widget));
}
Exemplo n.º 3
0
static void
gd_tagged_entry_tag_ensure_close_surface (GdTaggedEntryTag *tag,
        GtkStyleContext *context)
{
    GtkIconInfo *info;
    GdkPixbuf *pixbuf;
    gint icon_size;
    gint scale_factor;

    if (tag->close_surface != NULL)
        return;

    gtk_icon_size_lookup (GTK_ICON_SIZE_MENU,
                          &icon_size, NULL);
    scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (tag->entry));

    info = gtk_icon_theme_lookup_icon_for_scale (gtk_icon_theme_get_default (),
            "window-close-symbolic",
            icon_size, scale_factor,
            GTK_ICON_LOOKUP_GENERIC_FALLBACK);

    /* FIXME: we need a fallback icon in case the icon is not found */
    pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
    tag->close_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, tag->window);

    g_object_unref (info);
    g_object_unref (pixbuf);
}
Exemplo n.º 4
0
static NemoIconInfo *
real_get_icon (NemoWindow *window,
	       NemoWindowSlot *slot)
{
	return nemo_icon_info_lookup_from_name (NEMO_ICON_DESKTOP, 48,
                                            gtk_widget_get_scale_factor (GTK_WIDGET (window)));
}
static NautilusIconInfo *
nautilus_canvas_view_container_get_icon_images (NautilusCanvasContainer *container,
					      NautilusCanvasIconData      *data,
					      int                    size,
					      gboolean               for_drag_accept)
{
	NautilusCanvasView *canvas_view;
	NautilusFile *file;
	NautilusFileIconFlags flags;
	NautilusIconInfo *icon_info;
	gint scale;

	file = (NautilusFile *) data;

	g_assert (NAUTILUS_IS_FILE (file));
	canvas_view = get_canvas_view (container);
	g_return_val_if_fail (canvas_view != NULL, NULL);
	
	flags = NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS |
		NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS;

	if (for_drag_accept) {
		flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
	}

	scale = gtk_widget_get_scale_factor (GTK_WIDGET (canvas_view));
	icon_info = nautilus_file_get_icon (file, size, scale, flags);

	return icon_info;
}
Exemplo n.º 6
0
static void
size_allocate(GtkWidget *widget, GdkRectangle *allocation, gpointer user_data)
{
    GeglGtkView *self = GEGL_GTK_VIEW(widget);
    gint scale_factor;

    scale_factor = gtk_widget_get_scale_factor (widget);
    view_helper_set_allocation(GET_PRIVATE(self), allocation, scale_factor);
}
Exemplo n.º 7
0
gint
bg_source_get_scale_factor (BgSource *source)
{
  BgSourcePrivate *priv;

  g_return_val_if_fail (BG_IS_SOURCE (source), 1);

  priv = bg_source_get_instance_private (source);
  return gtk_widget_get_scale_factor (priv->window);
}
static void
update_display_preview (CcBackgroundPanel *panel,
                        GtkWidget         *widget,
                        CcBackgroundItem  *current_background)
{
  CcBackgroundPanelPrivate *priv = panel->priv;
  GtkAllocation allocation;
  const gint preview_width = 309;
  const gint preview_height = 168;
  gint scale_factor;
  GdkPixbuf *pixbuf;
  cairo_t *cr;

  gtk_widget_get_allocation (widget, &allocation);

  if (!current_background)
    return;

  scale_factor = gtk_widget_get_scale_factor (widget);
  pixbuf = cc_background_item_get_frame_thumbnail (current_background,
                                                   priv->thumb_factory,
                                                   preview_width,
                                                   preview_height,
                                                   scale_factor,
                                                   -2, TRUE);

  cr = gdk_cairo_create (gtk_widget_get_window (widget));
  gdk_cairo_set_source_pixbuf (cr,
                               pixbuf,
                               0, 0);
  cairo_paint (cr);
  g_object_unref (pixbuf);

  pixbuf = NULL;
  if (current_background == priv->current_background &&
      panel->priv->display_screenshot != NULL)
    {
      pixbuf = gdk_pixbuf_scale_simple (panel->priv->display_screenshot,
                                        preview_width,
                                        preview_height,
                                        GDK_INTERP_BILINEAR);
    }

  if (pixbuf)
    {
      gdk_cairo_set_source_pixbuf (cr,
                                   pixbuf,
                                   0, 0);
      cairo_paint (cr);
      g_object_unref (pixbuf);
    }

  cairo_destroy (cr);
}
Exemplo n.º 9
0
static void
gtk_icon_helper_ensure_surface (GtkIconHelper *self)
{
  int scale;

  if (self->priv->rendered_surface)
    return;

  scale = gtk_widget_get_scale_factor (gtk_css_gadget_get_owner (GTK_CSS_GADGET (self)));

  self->priv->rendered_surface = gtk_icon_helper_load_surface (self, scale);
}
Exemplo n.º 10
0
static void
photos_image_view_update (PhotosImageView *self)
{
  GdkRectangle viewport;
  GeglRectangle bbox;
  float zoom_scaled = 1.0;
  gint scale_factor;
  gint viewport_height_real;
  gint viewport_width_real;

  if (self->node == NULL)
    return;

  gtk_widget_get_allocation (GTK_WIDGET (self), &viewport);

  if (viewport.width < 0 || viewport.height < 0)
    return;

  bbox = gegl_node_get_bounding_box (self->node);
  if (bbox.width < 0 || bbox.height < 0)
    return;

  scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
  viewport_height_real = viewport.height * scale_factor;
  viewport_width_real = viewport.width * scale_factor;

  if (bbox.height > viewport_height_real || bbox.width > viewport_width_real)
    {
      gfloat height_ratio = bbox.height / (gfloat) viewport_height_real;
      gfloat width_ratio = bbox.width / (gfloat) viewport_width_real;
      gfloat max_ratio =  MAX (height_ratio, width_ratio);

      zoom_scaled = 1.0 / max_ratio;

      bbox.width = (gint) (zoom_scaled * bbox.width + 0.5);
      bbox.height = (gint) (zoom_scaled * bbox.height + 0.5);
      bbox.x = (gint) (zoom_scaled * bbox.x + 0.5);
      bbox.y = (gint) (zoom_scaled * bbox.y + 0.5);
    }

  self->zoom_scaled = zoom_scaled;
  self->zoom = self->zoom_scaled / (gfloat) scale_factor;

  /* At this point, viewport is definitely bigger than bbox. */
  self->x_scaled = (bbox.width - viewport_width_real) / 2.0 + bbox.x;
  self->y_scaled = (bbox.height - viewport_height_real) / 2.0 + bbox.y;

  self->x = self->x_scaled / (gfloat) scale_factor;
  self->y = self->y_scaled / (gfloat) scale_factor;
}
Exemplo n.º 11
0
static void
file_icons_changed (NautilusFile *file,
                    NautilusFileConflictDialog *fcd)
{
    GdkPixbuf *pixbuf;

    pixbuf = nautilus_file_get_icon_pixbuf (fcd->details->destination,
                                            NAUTILUS_ICON_SIZE_LARGE,
                                            TRUE,
                                            gtk_widget_get_scale_factor (fcd->details->dest_image),
                                            NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS);

    gtk_image_set_from_pixbuf (GTK_IMAGE (fcd->details->dest_image), pixbuf);
    g_object_unref (pixbuf);

    pixbuf = nautilus_file_get_icon_pixbuf (fcd->details->source,
                                            NAUTILUS_ICON_SIZE_LARGE,
                                            TRUE,
                                            gtk_widget_get_scale_factor (fcd->details->src_image),
                                            NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS);

    gtk_image_set_from_pixbuf (GTK_IMAGE (fcd->details->src_image), pixbuf);
    g_object_unref (pixbuf);
}
Exemplo n.º 12
0
static gboolean
resize_cb (GtkWidget * widget, GdkEvent * event, gpointer sink)
{
  GtkAllocation allocation;
  gint scale = 1;

#if GTK_CHECK_VERSION(3, 10, 0)
  scale = gtk_widget_get_scale_factor (widget);
#endif

  gtk_widget_get_allocation (widget, &allocation);
  gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (sink),
      allocation.x * scale, allocation.y * scale, allocation.width * scale,
      allocation.height * scale);

  return G_SOURCE_CONTINUE;
}
Exemplo n.º 13
0
static void
update_size_window (MetaResizePopup *popup)
{
  char *str;
  int x, y;
  int width, height;
  int scale;

  g_return_if_fail (popup->size_window != NULL);

  scale = gtk_widget_get_scale_factor (GTK_WIDGET (popup->size_window));
  /* Translators: This represents the size of a window.  The first number is
   * the width of the window and the second is the height.
   */
  str = g_strdup_printf (_("%d x %d"),
                         popup->horizontal_size,
                         popup->vertical_size);

  gtk_label_set_text (GTK_LABEL (popup->size_label), str);

  g_free (str);

  gtk_window_get_size (GTK_WINDOW (popup->size_window), &width, &height);

  x = popup->rect.x + (popup->rect.width - width) / 2;
  y = popup->rect.y + (popup->rect.height - height) / 2;

  if (scale)
    {
      x = x / scale;
      y = y / scale;
    }

  if (gtk_widget_get_realized (popup->size_window))
    {
      /* using move_resize to avoid jumpiness */
      gdk_window_move_resize (gtk_widget_get_window (popup->size_window),
                              x, y,
                              width, height);
    }
  else
    {
      gtk_window_move   (GTK_WINDOW (popup->size_window),
                         x, y);
    }
}
Exemplo n.º 14
0
static void
render_image (UmUserImage *image)
{
        cairo_surface_t *surface;
        gint scale, pixel_size;

        if (image->priv->user == NULL)
                return;

        pixel_size = gtk_image_get_pixel_size (GTK_IMAGE (image));
        scale = gtk_widget_get_scale_factor (GTK_WIDGET (image));
        surface = render_user_icon (image->priv->user,
                                    UM_ICON_STYLE_NONE,
                                    pixel_size > 0 ? pixel_size : 48,
                                    scale);
        gtk_image_set_from_surface (GTK_IMAGE (image), surface);
        cairo_surface_destroy (surface);
}
Exemplo n.º 15
0
static GtkStyleProviderPrivate *
gtk_css_widget_node_get_style_provider (GtkCssNode *node)
{
  GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
  GtkStyleContext *context;
  GtkStyleCascade *cascade;

  if (widget_node->widget == NULL)
    return NULL;

  context = _gtk_widget_peek_style_context (widget_node->widget);
  if (context)
    return gtk_style_context_get_style_provider (context);

  cascade = _gtk_settings_get_style_cascade (gtk_widget_get_settings (widget_node->widget),
                                             gtk_widget_get_scale_factor (widget_node->widget));
  return GTK_STYLE_PROVIDER_PRIVATE (cascade);
}
Exemplo n.º 16
0
void
gtd_row_measure_with_max (GtkWidget      *widget,
                          GtkOrientation  orientation,
                          gint            for_size,
                          gint           *minimum,
                          gint           *natural,
                          gint           *minimum_baseline,
                          gint           *natural_baseline)
{
  if (orientation == GTK_ORIENTATION_VERTICAL)
    {
      gtk_widget_measure (gtk_bin_get_child (GTK_BIN (widget)),
                          orientation,
                          for_size,
                          minimum,
                          natural,
                          minimum_baseline,
                          natural_baseline);
    }
  else
    {
      gint local_minimum_width;
      gint local_natural_width;
      gint scale_factor;
      gint margins;

      gtk_widget_measure (gtk_bin_get_child (GTK_BIN (widget)),
                          orientation,
                          for_size,
                          &local_minimum_width,
                          &local_natural_width,
                          minimum_baseline,
                          natural_baseline);

      scale_factor = gtk_widget_get_scale_factor (widget);
      margins = gtk_widget_get_margin_start (widget) + gtk_widget_get_margin_end (widget);

      if (minimum)
        *minimum = (MIN (local_minimum_width, MAX_WIDTH) - margins) * scale_factor;

      if (natural)
        *natural = (MAX (local_minimum_width, MAX_WIDTH) - margins) * scale_factor;
    }
}
Exemplo n.º 17
0
static void
photos_image_view_draw_node (PhotosImageView *self, cairo_t *cr, GdkRectangle *rect)
{
  const Babl *format;
  GeglRectangle roi;
  cairo_surface_t *surface = NULL;
  guchar *buf = NULL;
  gint scale_factor;
  gint stride;
  gint64 end;
  gint64 start;

  scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));

  roi.x = (gint) self->x_scaled + rect->x * scale_factor;
  roi.y = (gint) self->y_scaled + rect->y * scale_factor;
  roi.width  = rect->width * scale_factor;
  roi.height = rect->height * scale_factor;

  format = babl_format ("cairo-ARGB32");
  stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, roi.width);
  buf = g_malloc0 (stride * roi.height);

  start = g_get_monotonic_time ();

  gegl_node_blit (self->node,
                  (gdouble) self->zoom_scaled,
                  &roi,
                  format,
                  buf,
                  GEGL_AUTO_ROWSTRIDE,
                  GEGL_BLIT_CACHE | GEGL_BLIT_DIRTY);

  end = g_get_monotonic_time ();
  photos_debug (PHOTOS_DEBUG_GEGL, "PhotosImageView: Node Blit: %" G_GINT64_FORMAT, end - start);

  surface = cairo_image_surface_create_for_data (buf, CAIRO_FORMAT_ARGB32, roi.width, roi.height, stride);
  cairo_surface_set_device_scale (surface, (gdouble) scale_factor, (gdouble) scale_factor);
  cairo_set_source_surface (cr, surface, rect->x, rect->y);
  cairo_paint (cr);

  cairo_surface_destroy (surface);
  g_free (buf);
}
Exemplo n.º 18
0
static void
bg_source_calculate_thumbnail_dimensions (BgSource *source)
{
  BgSourcePrivate *priv = bg_source_get_instance_private (source);
  gint scale_factor;

  priv->thumbnail_height = THUMBNAIL_HEIGHT;
  priv->thumbnail_width = THUMBNAIL_WIDTH;

  if (priv->window == NULL)
    return;

  scale_factor = gtk_widget_get_scale_factor (priv->window);
  if (scale_factor > 1)
    {
      priv->thumbnail_height *= scale_factor;
      priv->thumbnail_width *= scale_factor;
    }
}
Exemplo n.º 19
0
static void
from_name (GtkSourcePixbufHelper *helper,
           GtkWidget             *widget,
           gint                   size)
{
	GdkScreen *screen;
	GtkIconTheme *icon_theme;
	GtkIconInfo *info;
	GtkIconLookupFlags flags;
	gint scale;

	screen = gtk_widget_get_screen (widget);
	icon_theme = gtk_icon_theme_get_for_screen (screen);

	flags = GTK_ICON_LOOKUP_USE_BUILTIN;
        scale = gtk_widget_get_scale_factor (widget);

	info = gtk_icon_theme_lookup_icon_for_scale (icon_theme,
	                                             helper->icon_name,
	                                             size,
	                                             scale,
	                                             flags);

	if (info)
	{
		GdkPixbuf *pixbuf;

		if (gtk_icon_info_is_symbolic (info))
		{
			GtkStyleContext *context;

			context = gtk_widget_get_style_context (widget);
			pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
		}
		else
		{
			pixbuf = gtk_icon_info_load_icon (info, NULL);
		}

		set_cache (helper, pixbuf);
	}
}
Exemplo n.º 20
0
GdkPixbuf *
nemo_ui_get_menu_icon (const char *icon_name,
                       GtkWidget  *parent_widget)
{
	NemoIconInfo *info;
	GdkPixbuf *pixbuf;
	int size;
    int scale;

	size = nemo_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
    scale = gtk_widget_get_scale_factor (parent_widget);

	if (g_path_is_absolute (icon_name)) {
		info = nemo_icon_info_lookup_from_path (icon_name, size, scale);
	} else {
		info = nemo_icon_info_lookup_from_name (icon_name, size, scale);
	}
	pixbuf = nemo_icon_info_get_pixbuf_nodefault_at_size (info, size);
	g_object_unref (info);

	return pixbuf;
}
Exemplo n.º 21
0
static gint
gd_tagged_entry_tag_get_width (GdTaggedEntryTag *tag,
                               GdTaggedEntry *entry)
{
    GtkBorder button_padding, button_border, button_margin;
    GtkStyleContext *context;
    GtkStateFlags state;
    gint layout_width;
    gint button_width;
    gint scale_factor;

    gd_tagged_entry_tag_ensure_layout (tag, entry);
    pango_layout_get_pixel_size (tag->layout, &layout_width, NULL);

    context = gd_tagged_entry_tag_get_context (tag, entry);
    state = gd_tagged_entry_tag_get_state (tag, entry);

    gtk_style_context_get_padding (context, state, &button_padding);
    gtk_style_context_get_border (context, state, &button_border);
    gtk_style_context_get_margin (context, state, &button_margin);

    gd_tagged_entry_tag_ensure_close_surface (tag, context);

    g_object_unref (context);

    button_width = 0;
    if (entry->button_visible && tag->has_close_button)
    {
        scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (entry));
        button_width = cairo_image_surface_get_width (tag->close_surface) / scale_factor +
                       BUTTON_INTERNAL_SPACING;
    }

    return layout_width + button_padding.left + button_padding.right +
           button_border.left + button_border.right +
           button_margin.left + button_margin.right +
           button_width;
}
Exemplo n.º 22
0
void
cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data)
{
  zathura_t* zathura = data;
  if (zathura == NULL || zathura->document == NULL) {
    return;
  }

  int new_factor = gtk_widget_get_scale_factor(GTK_WIDGET(object));
  if (new_factor == 0) {
    girara_debug("Ignoring new device scale factor = 0");
    return;
  }

  zathura_device_factors_t current = zathura_document_get_device_factors(zathura->document);
  if (fabs(new_factor - current.x) >= DBL_EPSILON ||
      fabs(new_factor - current.y) >= DBL_EPSILON) {
    zathura_document_set_device_factors(zathura->document, new_factor, new_factor);
    girara_debug("New device scale factor: %d", new_factor);
    zathura_update_view_ppi(zathura);
    render_all(zathura);
  }
}
Exemplo n.º 23
0
void
egg_empty_state_set_resource (EggEmptyState *self,
                              const gchar   *resource)
{
  EggEmptyStatePrivate *priv = egg_empty_state_get_instance_private (self);

  g_return_if_fail (EGG_IS_EMPTY_STATE (self));

  if (resource != NULL)
    {
      GdkPixbuf *pixbuf;
      GError *error = NULL;
      gint scale_factor;

      scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));

      pixbuf = gdk_pixbuf_new_from_resource_at_scale (resource,
                                                      128 * scale_factor,
                                                      128 * scale_factor,
                                                      TRUE,
                                                      &error);

      if (pixbuf == NULL)
        {
          g_warning ("%s", error->message);
          g_clear_error (&error);
          return;
        }

      g_object_set (priv->image,
                    "pixbuf", pixbuf,
                    NULL);

      g_clear_object (&pixbuf);
    }
}
Exemplo n.º 24
0
static void
_size_changed_cb (GtkWidget * widget, GdkRectangle * rectangle,
                  GstGtkGLSink * gtk_sink)
{
    gint scale_factor, width, height;
    gboolean reconfigure;

    scale_factor = gtk_widget_get_scale_factor (widget);
    width = scale_factor * gtk_widget_get_allocated_width (widget);
    height = scale_factor * gtk_widget_get_allocated_height (widget);

    GST_OBJECT_LOCK (gtk_sink);
    reconfigure =
        (width != gtk_sink->display_width || height != gtk_sink->display_height);
    gtk_sink->display_width = width;
    gtk_sink->display_height = height;
    GST_OBJECT_UNLOCK (gtk_sink);

    if (reconfigure) {
        GST_DEBUG_OBJECT (gtk_sink, "Sending reconfigure event on sinkpad.");
        gst_pad_push_event (GST_BASE_SINK (gtk_sink)->sinkpad,
                            gst_event_new_reconfigure ());
    }
}
Exemplo n.º 25
0
int XournalView::getDpiScaleFactor()
{
	XOJ_CHECK_TYPE(XournalView);
	return gtk_widget_get_scale_factor(widget);
}
Exemplo n.º 26
0
static NemoIconInfo *
nemo_icon_view_container_get_icon_images (NemoIconContainer *container,
					      NemoIconData      *data,
					      int                    size,
					      char                 **embedded_text,
					      gboolean               for_drag_accept,
					      gboolean               need_large_embeddded_text,
					      gboolean              *embedded_text_needs_loading,
					      gboolean              *has_window_open)
{
	NemoIconView *icon_view;
	char **emblems_to_ignore;
	NemoFile *file;
	NemoFileIconFlags flags;
	NemoIconInfo *icon_info;
	GdkPixbuf *pixbuf;
	GIcon *emblemed_icon;
	GEmblem *emblem;
	GList *emblem_icons, *l;
    gint scale;

	file = (NemoFile *) data;

	g_assert (NEMO_IS_FILE (file));
	icon_view = get_icon_view (container);
	g_return_val_if_fail (icon_view != NULL, NULL);
	
	*has_window_open = nemo_file_has_open_window (file);

	flags = NEMO_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM |
			NEMO_FILE_ICON_FLAGS_USE_THUMBNAILS;

	if (for_drag_accept) {
		flags |= NEMO_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
	}

	emblems_to_ignore = nemo_view_get_emblem_names_to_exclude 
		(NEMO_VIEW (icon_view));
	emblem_icons = nemo_file_get_emblem_icons (file,
						       emblems_to_ignore);
	g_strfreev (emblems_to_ignore);

    scale = gtk_widget_get_scale_factor (GTK_WIDGET (icon_view));
	icon_info = nemo_file_get_icon (file, size, scale, flags);

	/* apply emblems */
	if (emblem_icons != NULL) {
		l = emblem_icons;


		pixbuf = nemo_icon_info_get_pixbuf (icon_info);

        gint w, h, s;
        gboolean bad_ratio;

        w = gdk_pixbuf_get_width (pixbuf);
        h = gdk_pixbuf_get_height (pixbuf);

        s = MAX (w, h);
        if (s < size)
            size = s;

        bad_ratio = nemo_icon_get_emblem_size_for_icon_size (size) * scale > w ||
                    nemo_icon_get_emblem_size_for_icon_size (size) * scale > h;

        if (bad_ratio)
            goto skip_emblem; /* Would prefer to not use goto, but
                               * I don't want to do these checks on
                               * non-emblemed icons (the majority)
                               * as it would be too costly */

        emblem = g_emblem_new (l->data);

		emblemed_icon = g_emblemed_icon_new (G_ICON (pixbuf), emblem);
		g_object_unref (emblem);

		for (l = l->next; l != NULL; l = l->next) {
			emblem = g_emblem_new (l->data);
			g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon),
						    emblem);
			g_object_unref (emblem);
		}

		g_clear_object (&icon_info);
		icon_info = nemo_icon_info_lookup (emblemed_icon, size, scale);
        g_object_unref (emblemed_icon);

skip_emblem:
		g_object_unref (pixbuf);

	}

	if (emblem_icons != NULL) {
		g_list_free_full (emblem_icons, g_object_unref);
	}

	return icon_info;
}
Exemplo n.º 27
0
void
nemo_launch_application_by_uri (GAppInfo *application, 
				    GList *uris,
				    GtkWindow *parent_window)
{
	char *uri;
	GList *locations, *l;
	GFile *location;
	NemoFile *file;
	gboolean result;
	GError *error;
	GdkDisplay *display;
	GdkAppLaunchContext *launch_context;
	NemoIconInfo *icon;
	int count, total;

	g_assert (uris != NULL);

	/* count the number of uris with local paths */
	count = 0;
	total = g_list_length (uris);
	locations = NULL;
	for (l = uris; l != NULL; l = l->next) {
		uri = l->data;
		
		location = g_file_new_for_uri (uri);
		if (g_file_is_native (location)) {
			count++;
		}
		locations = g_list_prepend (locations, location);
	}
	locations = g_list_reverse (locations);

	if (parent_window != NULL) {
		display = gtk_widget_get_display (GTK_WIDGET (parent_window));
	} else {
		display = gdk_display_get_default ();
	}

	launch_context = gdk_display_get_app_launch_context (display);

	if (parent_window != NULL) {
		gdk_app_launch_context_set_screen (launch_context,
						   gtk_window_get_screen (parent_window));
	}

	file = nemo_file_get_by_uri (uris->data);
	icon = nemo_file_get_icon (file,
                               48,
                               gtk_widget_get_scale_factor (GTK_WIDGET (parent_window)),
                               0);
	nemo_file_unref (file);
	if (icon) {
		gdk_app_launch_context_set_icon_name (launch_context,
							nemo_icon_info_get_used_name (icon));
		g_object_unref (icon);
	}
	
	error = NULL;

	if (count == total) {
		/* All files are local, so we can use g_app_info_launch () with
		 * the file list we constructed before.
		 */
		result = g_app_info_launch (application,
					    locations,
					    G_APP_LAUNCH_CONTEXT (launch_context),
					    &error);
	} else {
		/* Some files are non local, better use g_app_info_launch_uris ().
		 */
		result = g_app_info_launch_uris (application,
						 uris,
						 G_APP_LAUNCH_CONTEXT (launch_context),
						 &error);
	}

	g_object_unref (launch_context);

	if (result) {
		for (l = uris; l != NULL; l = l->next) {
			file = nemo_file_get_by_uri (l->data);
			nemo_recent_add_file (file, application);
			nemo_file_unref (file);
		}
	}

	g_list_free_full (locations, g_object_unref);
}
Exemplo n.º 28
0
static gboolean
gtk_color_swatch_render_overlay (GtkCssGadget *gadget,
                                 cairo_t      *cr,
                                 int           x,
                                 int           y,
                                 int           width,
                                 int           height,
                                 gpointer      data)
{
    GtkWidget *widget;
    GtkColorSwatch *swatch;
    GtkStyleContext *context;
    GtkStateFlags state;
    GtkIconTheme *theme;
    GtkIconInfo *icon_info = NULL;
    gint scale;

    widget = gtk_css_gadget_get_owner (gadget);
    swatch = GTK_COLOR_SWATCH (widget);

    theme = gtk_icon_theme_get_default ();
    context = gtk_widget_get_style_context (widget);
    state = gtk_style_context_get_state (context);

    scale = gtk_widget_get_scale_factor (widget);
    if (swatch->priv->icon)
    {
        icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, swatch->priv->icon, PIXBUF_SIZE,
                    scale,
                    GTK_ICON_LOOKUP_GENERIC_FALLBACK
                    | GTK_ICON_LOOKUP_USE_BUILTIN);
    }
    else if ((state & GTK_STATE_FLAG_SELECTED) != 0)
    {
        GIcon *gicon;

        gicon = g_themed_icon_new ("object-select-symbolic");
        /* fallback for themes that don't have object-select-symbolic */
        g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply");

        icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, gicon, PIXBUF_SIZE,
                    scale,
                    GTK_ICON_LOOKUP_USE_BUILTIN);
        g_object_unref (gicon);
    }

    /* now draw the overlay image */
    if (icon_info != NULL)
    {
        GdkPixbuf *pixbuf;

        pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context, NULL, NULL);
        if (pixbuf != NULL)
        {
            cairo_surface_t *surface;

            surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, gtk_widget_get_window (widget));
            gtk_render_icon_surface (context, cr, surface, x, y);
            cairo_surface_destroy (surface);
            g_object_unref (pixbuf);
        }

        g_object_unref (icon_info);
    }

    return FALSE;
}
Exemplo n.º 29
0
/**
 * gs_screenshot_image_load_async:
 **/
void
gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
				GCancellable *cancellable)
{
	AsImage *im = NULL;
	GsScreenshotImagePrivate *priv;
	SoupURI *base_uri = NULL;
	const gchar *url;
	gint rc;
	_cleanup_free_ gchar *basename = NULL;
	_cleanup_free_ gchar *cachedir2 = NULL;
	_cleanup_free_ gchar *cachedir = NULL;
	_cleanup_free_ gchar *sizedir = NULL;

	g_return_if_fail (GS_IS_SCREENSHOT_IMAGE (ssimg));

	priv = gs_screenshot_image_get_instance_private (ssimg);

	g_return_if_fail (AS_IS_SCREENSHOT (priv->screenshot));
	g_return_if_fail (priv->width != 0);
	g_return_if_fail (priv->height != 0);

	/* load an image according to the scale factor */
	priv->scale = gtk_widget_get_scale_factor (GTK_WIDGET (ssimg));
	im = as_screenshot_get_image (priv->screenshot,
				      priv->width * priv->scale,
				      priv->height * priv->scale);

	/* if we've failed to load a HiDPI image, fallback to LoDPI */
	if (im == NULL && priv->scale > 1) {
		priv->scale = 1;
		im = as_screenshot_get_image (priv->screenshot,
					      priv->width,
					      priv->height);
	}
	if (im == NULL) {
		/* TRANSLATORS: this is when we request a screenshot size that
		 * the generator did not create or the parser did not add */
		gs_screenshot_image_set_error (ssimg, _("Screenshot size not found"));
		return;
	}
	url = as_image_get_url (im);
	basename = g_path_get_basename (url);
	if (priv->width == G_MAXUINT || priv->height == G_MAXUINT) {
		sizedir = g_strdup ("unknown");
	} else {
		sizedir = g_strdup_printf ("%ux%u", priv->width * priv->scale, priv->height * priv->scale);
	}
	cachedir = g_build_filename (priv->cachedir,
				     "gnome-software",
				     "screenshots",
				     sizedir,
				     NULL);
	rc = g_mkdir_with_parents (cachedir, 0700);
	if (rc != 0) {
		/* TRANSLATORS: this is when we try create the cache directory
		 * but we were out of space or permission was denied */
		gs_screenshot_image_set_error (ssimg, _("Could not create cache"));
		return;
	}

	/* does local file already exist */
	priv->filename = g_build_filename (cachedir, basename, NULL);
	if (g_file_test (priv->filename, G_FILE_TEST_EXISTS)) {
		as_screenshot_show_image (ssimg);
		return;
	}

	/* can we load a blurred smaller version of this straight away */
	if (priv->width > AS_IMAGE_THUMBNAIL_WIDTH &&
	    priv->height > AS_IMAGE_THUMBNAIL_HEIGHT) {
		cachedir2 = g_build_filename (priv->cachedir,
					      "gnome-software",
					      "screenshots",
					      "112x63",
					      basename,
					      NULL);
		if (g_file_test (cachedir2, G_FILE_TEST_EXISTS))
			gs_screenshot_image_show_blurred (ssimg, cachedir2);
	}

	/* download file */
	g_debug ("downloading %s to %s", url, priv->filename);
	base_uri = soup_uri_new (url);
	if (base_uri == NULL || !SOUP_URI_VALID_FOR_HTTP (base_uri)) {
		/* TRANSLATORS: this is when we try to download a screenshot
		 * that was not a valid URL */
		gs_screenshot_image_set_error (ssimg, _("Screenshot not valid"));
		soup_uri_free (base_uri);
		return;
	}

	/* cancel any previous messages */
	if (priv->message != NULL) {
		soup_session_cancel_message (priv->session,
		                             priv->message,
		                             SOUP_STATUS_CANCELLED);
		g_clear_object (&priv->message);
	}

	priv->message = soup_message_new_from_uri (SOUP_METHOD_GET, base_uri);
	if (priv->message == NULL) {
		/* TRANSLATORS: this is when networking is not available */
		gs_screenshot_image_set_error (ssimg, _("Screenshot not available"));
		soup_uri_free (base_uri);
		return;
	}

	/* send async */
	soup_session_queue_message (priv->session,
				    g_object_ref (priv->message) /* transfer full */,
				    gs_screenshot_image_complete_cb,
				    g_object_ref (ssimg));
	soup_uri_free (base_uri);
}
Exemplo n.º 30
0
static void
file_list_ready_cb (GList *files,
                    gpointer user_data)
{
    NautilusFileConflictDialog *fcd = user_data;
    NautilusFile *src, *dest, *dest_dir;
    time_t src_mtime, dest_mtime;
    gboolean source_is_dir,	dest_is_dir, should_show_type;
    NautilusFileConflictDialogDetails *details;
    char *primary_text, *message, *secondary_text;
    const gchar *message_extra;
    char *dest_name, *dest_dir_name, *edit_name;
    char *label_text;
    char *size, *date, *type = NULL;
    GdkPixbuf *pixbuf;
    GtkWidget *label;
    GString *str;
    PangoAttrList *attr_list;

    details = fcd->details;

    details->handle = NULL;

    dest_dir = g_list_nth_data (files, 0);
    dest = g_list_nth_data (files, 1);
    src = g_list_nth_data (files, 2);

    src_mtime = nautilus_file_get_mtime (src);
    dest_mtime = nautilus_file_get_mtime (dest);

    dest_name = nautilus_file_get_display_name (dest);
    dest_dir_name = nautilus_file_get_display_name (dest_dir);

    source_is_dir = nautilus_file_is_directory (src);
    dest_is_dir = nautilus_file_is_directory (dest);

    type = nautilus_file_get_mime_type (dest);
    should_show_type = !nautilus_file_is_mime_type (src, type);

    g_free (type);
    type = NULL;

    /* Set up the right labels */
    if (dest_is_dir) {
        if (source_is_dir) {
            primary_text = g_strdup_printf
                           (_("Merge folder “%s”?"),
                            dest_name);

            message_extra =
                _("Merging will ask for confirmation before replacing any files in "
                  "the folder that conflict with the files being copied.");

            if (src_mtime > dest_mtime) {
                message = g_strdup_printf (
                              _("An older folder with the same name already exists in “%s”."),
                              dest_dir_name);
            } else if (src_mtime < dest_mtime) {
                message = g_strdup_printf (
                              _("A newer folder with the same name already exists in “%s”."),
                              dest_dir_name);
            } else {
                message = g_strdup_printf (
                              _("Another folder with the same name already exists in “%s”."),
                              dest_dir_name);
            }
        } else {
            message_extra =
                _("Replacing it will remove all files in the folder.");
            primary_text = g_strdup_printf
                           (_("Replace folder “%s”?"), dest_name);
            message = g_strdup_printf
                      (_("A folder with the same name already exists in “%s”."),
                       dest_dir_name);
        }
    } else {
        primary_text = g_strdup_printf
                       (_("Replace file “%s”?"), dest_name);

        message_extra = _("Replacing it will overwrite its content.");

        if (src_mtime > dest_mtime) {
            message = g_strdup_printf (
                          _("An older file with the same name already exists in “%s”."),
                          dest_dir_name);
        } else if (src_mtime < dest_mtime) {
            message = g_strdup_printf (
                          _("A newer file with the same name already exists in “%s”."),
                          dest_dir_name);
        } else {
            message = g_strdup_printf (
                          _("Another file with the same name already exists in “%s”."),
                          dest_dir_name);
        }
    }

    secondary_text = g_strdup_printf ("%s\n%s", message, message_extra);
    g_free (message);

    label = gtk_label_new (primary_text);
    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
    gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR);
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (details->titles_vbox),
                        label, FALSE, FALSE, 0);
    gtk_widget_show (label);

    attr_list = pango_attr_list_new ();
    pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
    pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_LARGE));
    g_object_set (label,
                  "attributes", attr_list,
                  NULL);

    pango_attr_list_unref (attr_list);

    label = gtk_label_new (secondary_text);
    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (details->titles_vbox),
                        label, FALSE, FALSE, 0);
    gtk_widget_show (label);
    g_free (primary_text);
    g_free (secondary_text);

    /* Set up file icons */
    pixbuf = nautilus_file_get_icon_pixbuf (dest,
                                            NAUTILUS_ICON_SIZE_LARGE,
                                            TRUE,
                                            gtk_widget_get_scale_factor (fcd->details->titles_vbox),
                                            NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS);
    details->dest_image = gtk_image_new_from_pixbuf (pixbuf);
    gtk_box_pack_start (GTK_BOX (details->first_hbox),
                        details->dest_image, FALSE, FALSE, 0);
    gtk_widget_show (details->dest_image);
    g_object_unref (pixbuf);

    pixbuf = nautilus_file_get_icon_pixbuf (src,
                                            NAUTILUS_ICON_SIZE_LARGE,
                                            TRUE,
                                            gtk_widget_get_scale_factor (fcd->details->titles_vbox),
                                            NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS);
    details->src_image = gtk_image_new_from_pixbuf (pixbuf);
    gtk_box_pack_start (GTK_BOX (details->second_hbox),
                        details->src_image, FALSE, FALSE, 0);
    gtk_widget_show (details->src_image);
    g_object_unref (pixbuf);

    /* Set up labels */
    label = gtk_label_new (NULL);
    date = nautilus_file_get_string_attribute (dest,
            "date_modified");
    size = nautilus_file_get_string_attribute (dest, "size");

    if (should_show_type) {
        type = nautilus_file_get_string_attribute (dest, "type");
    }

    str = g_string_new (NULL);
    g_string_append_printf (str, "<b>%s</b>\n", _("Original file"));
    g_string_append_printf (str, "%s %s\n", _("Size:"), size);

    if (should_show_type) {
        g_string_append_printf (str, "%s %s\n", _("Type:"), type);
    }

    g_string_append_printf (str, "%s %s", _("Last modified:"), date);

    label_text = str->str;
    gtk_label_set_markup (GTK_LABEL (label),
                          label_text);
    gtk_box_pack_start (GTK_BOX (details->first_hbox),
                        label, FALSE, FALSE, 0);
    gtk_widget_show (label);

    g_free (size);
    g_free (type);
    g_free (date);
    g_string_erase (str, 0, -1);

    /* Second label */
    label = gtk_label_new (NULL);
    date = nautilus_file_get_string_attribute (src,
            "date_modified");
    size = nautilus_file_get_string_attribute (src, "size");

    if (should_show_type) {
        type = nautilus_file_get_string_attribute (src, "type");
    }

    g_string_append_printf (str, "<b>%s</b>\n", _("Replace with"));
    g_string_append_printf (str, "%s %s\n", _("Size:"), size);

    if (should_show_type) {
        g_string_append_printf (str, "%s %s\n", _("Type:"), type);
    }

    g_string_append_printf (str, "%s %s", _("Last modified:"), date);
    label_text = g_string_free (str, FALSE);

    gtk_label_set_markup (GTK_LABEL (label),
                          label_text);
    gtk_box_pack_start (GTK_BOX (details->second_hbox),
                        label, FALSE, FALSE, 0);
    gtk_widget_show (label);

    g_free (size);
    g_free (date);
    g_free (type);
    g_free (label_text);

    /* Populate the entry */
    edit_name = nautilus_file_get_edit_name (dest);
    details->conflict_name = edit_name;

    gtk_entry_set_text (GTK_ENTRY (details->entry), edit_name);

    if (source_is_dir && dest_is_dir) {
        gtk_button_set_label (GTK_BUTTON (details->replace_button),
                              _("Merge"));
    }

    nautilus_file_monitor_add (src, fcd, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
    nautilus_file_monitor_add (dest, fcd, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);

    details->src_handler_id = g_signal_connect (src, "changed",
                              G_CALLBACK (file_icons_changed), fcd);
    details->dest_handler_id = g_signal_connect (dest, "changed",
                               G_CALLBACK (file_icons_changed), fcd);
}