Beispiel #1
0
/**
 * gd_create_symbolic_icon:
 * @name:
 *
 * Returns: (transfer full):
 */
GIcon *
gd_create_symbolic_icon (const gchar *name,
                         gint base_size)
{
  gchar *symbolic_name;
  GIcon *icon, *retval = NULL;
  cairo_surface_t *surface;
  cairo_t *cr;
  GtkStyleContext *style;
  GtkWidgetPath *path;
  GdkPixbuf *pixbuf;
  GtkIconTheme *theme;
  GtkIconInfo *info;
  gint bg_size;
  gint emblem_size;
  gint total_size;

  total_size = base_size / 2;
  bg_size = MAX (total_size / 2, _BG_MIN_SIZE);
  emblem_size = MAX (bg_size - 8, _EMBLEM_MIN_SIZE);

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size, total_size);
  cr = cairo_create (surface);

  style = gtk_style_context_new ();

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
  gtk_style_context_set_path (style, path);
  gtk_widget_path_unref (path);

  gtk_style_context_add_class (style, "documents-icon-bg");

  gtk_render_background (style, cr, (total_size - bg_size) / 2, (total_size - bg_size) / 2, bg_size, bg_size);

  symbolic_name = g_strconcat (name, "-symbolic", NULL);
  icon = g_themed_icon_new_with_default_fallbacks (symbolic_name);
  g_free (symbolic_name);

  theme = gtk_icon_theme_get_default();
  info = gtk_icon_theme_lookup_by_gicon (theme, icon, emblem_size,
                                         GTK_ICON_LOOKUP_FORCE_SIZE);
  g_object_unref (icon);

  if (info == NULL)
    goto out;

  pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL);
  g_object_unref (info);

  if (pixbuf == NULL)
    goto out;

  gtk_render_icon (style, cr, pixbuf, (total_size - emblem_size) / 2,  (total_size - emblem_size) / 2);
  g_object_unref (pixbuf);

  retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size, total_size));

 out:
  g_object_unref (style);
  cairo_surface_destroy (surface);
  cairo_destroy (cr);

  return retval;
}
Beispiel #2
0
static gint on_ask_rename(FmFileOpsJob* job, FmFileInfo* src, FmFileInfo* dest, char** new_name, FmProgressDisplay* data)
{
    int res;
    GtkBuilder* builder;
    GtkDialog *dlg;
    GtkImage *src_icon, *dest_icon;
    GtkLabel *src_fi, *dest_fi;
    GtkEntry *filename;
    GtkToggleButton *apply_all;
    char* tmp;
    const char* disp_size;
    FmPath* path;
    FmIcon* icon;
    FmFileOpOption options;
    gboolean no_valid_dest;

    /* return default operation if the user has set it */
    if(data->default_opt)
        return data->default_opt;

    no_valid_dest = (fm_file_info_get_desc(dest) == NULL);

    builder = gtk_builder_new();
    path = fm_file_info_get_path(dest);
    icon = fm_file_info_get_icon(src);

    if(data->timer)
        g_timer_stop(data->timer);

    gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE);
    ensure_dlg(data);

    gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/ask-rename.ui", NULL);
    dlg = GTK_DIALOG(gtk_builder_get_object(builder, "dlg"));
    src_icon = GTK_IMAGE(gtk_builder_get_object(builder, "src_icon"));
    src_fi = GTK_LABEL(gtk_builder_get_object(builder, "src_fi"));
    dest_icon = GTK_IMAGE(gtk_builder_get_object(builder, "dest_icon"));
    dest_fi = GTK_LABEL(gtk_builder_get_object(builder, "dest_fi"));
    filename = GTK_ENTRY(gtk_builder_get_object(builder, "filename"));
    apply_all = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "apply_all"));
    gtk_window_set_transient_for(GTK_WINDOW(dlg), GTK_WINDOW(data->dlg));

    gtk_image_set_from_gicon(src_icon, G_ICON(icon), GTK_ICON_SIZE_DIALOG);
    disp_size = fm_file_info_get_disp_size(src);
    if(disp_size)
    {
        tmp = g_strdup_printf(_("Type: %s\nSize: %s\nModified: %s"),
                              fm_file_info_get_desc(src), disp_size,
                              fm_file_info_get_disp_mtime(src));
    }
    else
    {
        tmp = g_strdup_printf(_("Type: %s\nModified: %s"),
                              fm_file_info_get_desc(src),
                              fm_file_info_get_disp_mtime(src));
    }

    gtk_label_set_text(src_fi, tmp);
    g_free(tmp);

    gtk_image_set_from_gicon(dest_icon, G_ICON(icon), GTK_ICON_SIZE_DIALOG);
    disp_size = fm_file_info_get_disp_size(dest);
    if(disp_size)
    {
        tmp = g_strdup_printf(_("Type: %s\nSize: %s\nModified: %s"),
                              fm_file_info_get_desc(dest), disp_size,
                              fm_file_info_get_disp_mtime(dest));
    }
    else if (no_valid_dest)
    {
        tmp = NULL;
        gtk_widget_destroy(GTK_WIDGET(dest_icon));
        gtk_widget_destroy(GTK_WIDGET(dest_fi));
        /* FIXME: change texts in dialog appropriately */
    }
    else
    {
        tmp = g_strdup_printf(_("Type: %s\nModified: %s"),
                              fm_file_info_get_desc(dest),
                              fm_file_info_get_disp_mtime(dest));
    }

    if (tmp)
        gtk_label_set_text(dest_fi, tmp);
    g_free(tmp);

    options = fm_file_ops_job_get_options(job);
    if (!(options & FM_FILE_OP_RENAME))
    {
        GtkWidget *widget = GTK_WIDGET(gtk_builder_get_object(builder, "rename"));
        gtk_widget_destroy(widget);
    }
    if (!(options & FM_FILE_OP_OVERWRITE) || no_valid_dest)
    {
        GtkWidget *widget = GTK_WIDGET(gtk_builder_get_object(builder, "overwrite"));
        gtk_widget_destroy(widget);
    }
    if (!(options & FM_FILE_OP_SKIP))
    {
        GtkWidget *widget = GTK_WIDGET(gtk_builder_get_object(builder, "skip"));
        gtk_widget_destroy(widget);
    }

    tmp = g_filename_display_name(fm_path_get_basename(path));
    gtk_entry_set_text(filename, tmp);
    g_object_set_data_full(G_OBJECT(filename), "old_name", tmp, g_free);
    g_signal_connect(filename, "changed", G_CALLBACK(on_filename_changed), gtk_builder_get_object(builder, "rename"));

    g_object_unref(builder);

    res = gtk_dialog_run(dlg);
    switch(res)
    {
    case RESPONSE_RENAME:
        *new_name = g_strdup(gtk_entry_get_text(filename));
        res = FM_FILE_OP_RENAME;
        break;
    case RESPONSE_OVERWRITE:
        res = FM_FILE_OP_OVERWRITE;
        break;
    case RESPONSE_SKIP:
        res = FM_FILE_OP_SKIP;
        break;
    default:
        res = FM_FILE_OP_CANCEL;
    }

    if(gtk_toggle_button_get_active(apply_all))
    {
        if(res == RESPONSE_OVERWRITE || res == FM_FILE_OP_SKIP)
            data->default_opt = res;
    }

    gtk_widget_destroy(GTK_WIDGET(dlg));

    if(data->timer)
        g_timer_continue(data->timer);

    return res;
}
Beispiel #3
0
GIcon *
photos_utils_create_collection_icon (gint base_size, GList *pixbufs)
{
  cairo_surface_t *surface;
  cairo_t *cr;
  GdkPixbuf *pix;
  GIcon *ret_val;
  GList *l;
  GtkStyleContext *context;
  GtkWidgetPath *path;
  gint cur_x;
  gint cur_y;
  gint idx;
  gint padding;
  gint pix_height;
  gint pix_width;
  gint scale_size;
  gint tile_size;

  /* TODO: do not hardcode 4, but scale to another layout if more
   * pixbufs are provided.
   */

  padding = MAX (floor (base_size / 10), 4);
  tile_size = (base_size - (3 * padding)) / 2;

  context = gtk_style_context_new ();
  gtk_style_context_add_class (context, "photos-collection-icon");

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
  gtk_style_context_set_path (context, path);
  gtk_widget_path_unref (path);

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, base_size, base_size);
  cr = cairo_create (surface);

  gtk_render_background (context, cr, 0, 0, base_size, base_size);

  l = pixbufs;
  idx = 0;
  cur_x = padding;
  cur_y = padding;

  while (l != NULL && idx < 4)
    {
      pix = l->data;
      pix_width = gdk_pixbuf_get_width (pix);
      pix_height = gdk_pixbuf_get_height (pix);

      scale_size = MIN (pix_width, pix_height);

      cairo_save (cr);

      cairo_translate (cr, cur_x, cur_y);

      cairo_rectangle (cr, 0, 0,
                       tile_size, tile_size);
      cairo_clip (cr);

      cairo_scale (cr, (gdouble) tile_size / (gdouble) scale_size, (gdouble) tile_size / (gdouble) scale_size);
      gdk_cairo_set_source_pixbuf (cr, pix, 0, 0);

      cairo_paint (cr);
      cairo_restore (cr);

      if ((idx % 2) == 0)
        {
          cur_x += tile_size + padding;
        }
      else
        {
          cur_x = padding;
          cur_y += tile_size + padding;
        }

      idx++;
      l = l->next;
    }

  ret_val = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, base_size, base_size));

  cairo_surface_destroy (surface);
  cairo_destroy (cr);
  g_object_unref (context);

  return ret_val;
}
Beispiel #4
0
static void
nemo_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
{
	NemoListModel *model;
	FileEntry *file_entry;
	NemoFile *file;
	char *str;
	GdkPixbuf *icon, *rendered_icon;
	GIcon *gicon, *emblemed_icon, *emblem_icon;
	NemoIconInfo *icon_info;
	GEmblem *emblem;
	GList *emblem_icons, *l;
	int icon_size;
	NemoZoomLevel zoom_level;
	NemoFile *parent_file;
	char *emblems_to_ignore[3];
	int i;
	NemoFileIconFlags flags;
	
	model = (NemoListModel *)tree_model;

	g_return_if_fail (model->details->stamp == iter->stamp);
	g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));

	file_entry = g_sequence_get (iter->user_data);
	file = file_entry->file;
	
	switch (column) {
	case NEMO_LIST_MODEL_FILE_COLUMN:
		g_value_init (value, NEMO_TYPE_FILE);

		g_value_set_object (value, file);
		break;
	case NEMO_LIST_MODEL_SUBDIRECTORY_COLUMN:
		g_value_init (value, NEMO_TYPE_DIRECTORY);

		g_value_set_object (value, file_entry->subdirectory);
		break;
	case NEMO_LIST_MODEL_SMALLEST_ICON_COLUMN:
	case NEMO_LIST_MODEL_SMALLER_ICON_COLUMN:
	case NEMO_LIST_MODEL_SMALL_ICON_COLUMN:
	case NEMO_LIST_MODEL_STANDARD_ICON_COLUMN:
	case NEMO_LIST_MODEL_LARGE_ICON_COLUMN:
	case NEMO_LIST_MODEL_LARGER_ICON_COLUMN:
	case NEMO_LIST_MODEL_LARGEST_ICON_COLUMN:
		g_value_init (value, GDK_TYPE_PIXBUF);

		if (file != NULL) {
			zoom_level = nemo_list_model_get_zoom_level_from_column_id (column);
			icon_size = nemo_get_icon_size_for_zoom_level (zoom_level);

			flags = NEMO_FILE_ICON_FLAGS_USE_THUMBNAILS |
				NEMO_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
				NEMO_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM;
			if (model->details->drag_view != NULL) {
				GtkTreePath *path_a, *path_b;
				
				gtk_tree_view_get_drag_dest_row (model->details->drag_view,
								 &path_a,
								 NULL);
				if (path_a != NULL) {
					path_b = gtk_tree_model_get_path (tree_model, iter);

					if (gtk_tree_path_compare (path_a, path_b) == 0) {
						flags |= NEMO_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
					}
						
					gtk_tree_path_free (path_a);
					gtk_tree_path_free (path_b);
				}
			}

			gicon = G_ICON (nemo_file_get_icon_pixbuf (file, icon_size, TRUE, flags));

			/* render emblems with GEmblemedIcon */
			parent_file = nemo_file_get_parent (file);
			i = 0;
			emblems_to_ignore[i++] = NEMO_FILE_EMBLEM_NAME_TRASH;
			if (parent_file) {
				if (!nemo_file_can_write (parent_file)) {
					emblems_to_ignore[i++] = NEMO_FILE_EMBLEM_NAME_CANT_WRITE;
				}
				nemo_file_unref (parent_file);
			}
			emblems_to_ignore[i++] = NULL;

			emblem_icons = nemo_file_get_emblem_icons (file,
								       emblems_to_ignore);

			/* pick only the first emblem we can render for the list view */
			for (l = emblem_icons; l != NULL; l = l->next) {
				emblem_icon = l->data;
				if (nemo_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) {
					emblem = g_emblem_new (emblem_icon);
					emblemed_icon = g_emblemed_icon_new (gicon, emblem);

					g_object_unref (gicon);
					g_object_unref (emblem);
					gicon = emblemed_icon;

					break;
				}
			}

			g_list_free_full (emblem_icons, g_object_unref);

			icon_info = nemo_icon_info_lookup (gicon, icon_size);
			icon = nemo_icon_info_get_pixbuf_at_size (icon_info, icon_size);

			g_object_unref (icon_info);
			g_object_unref (gicon);

			if (model->details->highlight_files != NULL &&
			    g_list_find_custom (model->details->highlight_files,
			                        file, (GCompareFunc) nemo_file_compare_location))
			{
				rendered_icon = eel_create_spotlight_pixbuf (icon);

				if (rendered_icon != NULL) {
					g_object_unref (icon);
					icon = rendered_icon;
				}
			}

			g_value_set_object (value, icon);
			g_object_unref (icon);
		}
		break;
	case NEMO_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
		g_value_init (value, G_TYPE_BOOLEAN);
		
                g_value_set_boolean (value, file != NULL && nemo_file_can_rename (file));
                break;
 	default:
 		if (column >= NEMO_LIST_MODEL_NUM_COLUMNS || column < NEMO_LIST_MODEL_NUM_COLUMNS + model->details->columns->len) {
			NemoColumn *nemo_column;
			GQuark attribute;
			nemo_column = model->details->columns->pdata[column - NEMO_LIST_MODEL_NUM_COLUMNS];
			
			g_value_init (value, G_TYPE_STRING);
			g_object_get (nemo_column, 
				      "attribute_q", &attribute, 
				      NULL);
			if (file != NULL) {
				str = nemo_file_get_string_attribute_with_default_q (file, 
											 attribute);
				g_value_take_string (value, str);
			} else if (attribute == attribute_name_q) {
				if (file_entry->parent->loaded) {
					g_value_set_string (value, _("(Empty)"));
				} else {
					g_value_set_string (value, _("Loading..."));
				}
			}
		} else {
			g_assert_not_reached ();
		}
	}
}