static void
treeview_gsettings_changed_callback (GSettings *settings, gchar *key, GtkTreeView *list)
{
  GtkTreeModel *store;
  gchar *curr_value;
  gchar *path;

  /* find value in model */
  curr_value = g_settings_get_string (settings, key);
  store = gtk_tree_view_get_model (list);

  path = find_string_in_model (store, curr_value, COL_NAME);

  /* Add a temporary item if we can't find a match
   * TODO: delete this item if it is no longer selected?
   */
  if (!path)
  {
    GtkListStore *list_store;
    GtkTreeIter iter, sort_iter;
    ThemeConvData *conv;

    list_store = GTK_LIST_STORE (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (store)));

    conv = g_object_get_data (G_OBJECT(list), THEME_DATA);
    gtk_list_store_insert_with_values (list_store, &iter, 0,
                                       COL_LABEL, curr_value,
                                       COL_NAME, curr_value,
                                       COL_THUMBNAIL, conv->thumbnail,
                                       -1);
    /* convert the tree store iter for use with the sort model */
    gtk_tree_model_sort_convert_child_iter_to_iter (GTK_TREE_MODEL_SORT (store),
                                                    &sort_iter, &iter);
    path = gtk_tree_model_get_string_from_iter (store, &sort_iter);

    create_thumbnail (curr_value, conv->thumbnail, conv->data);
  }
  /* select the new gsettings theme in treeview */
  GtkTreeSelection *selection = gtk_tree_view_get_selection (list);
  GtkTreePath *treepath = gtk_tree_path_new_from_string (path);
  gtk_tree_selection_select_path (selection, treepath);
  gtk_tree_view_scroll_to_cell (list, treepath, NULL, FALSE, 0, 0);
  gtk_tree_path_free (treepath);
}
Exemplo n.º 2
0
static gboolean
ensure_thumbnail_job (GIOSchedulerJob *job,
                      GCancellable *cancellable,
                      gpointer user_data)
{
    LoadThumbnailData *data = user_data;
    gboolean thumb_failed;
    const gchar *thumb_path;

    GError *error = NULL;
    GFile *thumb_file = NULL;
    GFileInputStream *is = NULL;
    GFileInfo *info = NULL;

    info = g_file_query_info (data->font_file,
                              ATTRIBUTES_FOR_EXISTING_THUMBNAIL,
                              G_FILE_QUERY_INFO_NONE,
                              NULL, &error);

    if (error != NULL) {
        g_debug ("Can't query info for file %s: %s\n", data->font_path, error->message);
        goto out;
    }

    thumb_failed = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
    if (thumb_failed)
        goto out;

    thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);

    if (thumb_path != NULL) {
        thumb_file = g_file_new_for_path (thumb_path);
        is = g_file_read (thumb_file, NULL, &error);

        if (error != NULL) {
            g_debug ("Can't read file %s: %s\n", thumb_path, error->message);
            goto out;
        }

        data->pixbuf = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (is),
                                                            128, 128, TRUE,
                                                            NULL, &error);

        if (error != NULL) {
            g_debug ("Can't read thumbnail pixbuf %s: %s\n", thumb_path, error->message);
            goto out;
        }
    } else {
        data->pixbuf = create_thumbnail (data);
    }

 out:
    g_clear_error (&error);
    g_clear_object (&is);
    g_clear_object (&thumb_file);
    g_clear_object (&info);

    g_io_scheduler_job_send_to_mainloop_async (job, ensure_thumbnail_job_done,
                                               data, NULL);

    return FALSE;
}