Example #1
0
static void
gwy_app_file_chooser_destroy(GtkObject *object)
{
    GwyAppFileChooser *chooser = GWY_APP_FILE_CHOOSER(object);

    gwy_app_file_chooser_free_preview(chooser);

    GTK_OBJECT_CLASS(_gwy_app_file_chooser_parent_class)->destroy(object);
}
Example #2
0
static void
gwy_app_file_chooser_hide(GtkWidget *widget)
{
    GwyAppFileChooser *chooser = GWY_APP_FILE_CHOOSER(widget);

    gwy_app_file_chooser_free_preview(chooser);

    GTK_WIDGET_CLASS(_gwy_app_file_chooser_parent_class)->hide(widget);
}
Example #3
0
static void
gwy_app_file_chooser_update_preview(GwyAppFileChooser *chooser)
{
    GtkFileChooser *fchooser;
    GtkTreeModel *model;
    GdkPixbuf *pixbuf;
    GtkTreeIter iter;
    gchar *filename_sys;

    gwy_app_file_chooser_free_preview(chooser);

    model = gtk_icon_view_get_model(GTK_ICON_VIEW(chooser->preview));
    gtk_list_store_clear(GTK_LIST_STORE(model));

    fchooser = GTK_FILE_CHOOSER(chooser);
    filename_sys = gtk_file_chooser_get_preview_filename(fchooser);
    /* It should be UTF-8, but don't convert it just for gwy_debug() */
    gwy_debug("%s", filename_sys);

    /* Make directories fail gracefully */
    if (filename_sys && g_file_test(filename_sys, G_FILE_TEST_IS_DIR)) {
        g_free(filename_sys);
        filename_sys = NULL;
    }
    /* Never set the preview inactive.  Gtk+ can do all kinds of silly things
     * if you do. */
    if (!filename_sys)
        return;

    pixbuf = _gwy_app_recent_file_try_thumbnail(filename_sys);
    g_free(filename_sys);

    if (!pixbuf) {
        pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
        gdk_pixbuf_fill(pixbuf, 0x00000000);
        chooser->make_thumbnail = TRUE;
    }
    else
        chooser->make_thumbnail = FALSE;

    g_object_set(chooser->renderer_fileinfo,
                 "ellipsize", PANGO_ELLIPSIZE_NONE,
                 "wrap-width", TMS_NORMAL_THUMB_SIZE,
                 NULL);
    gtk_list_store_insert_with_values(GTK_LIST_STORE(model), &iter, -1,
                                      COLUMN_PIXBUF, pixbuf,
                                      COLUMN_FILEINFO, _("…"),
                                      -1);
    g_object_unref(pixbuf);

    chooser->full_preview_id
        = g_timeout_add_full(G_PRIORITY_LOW, 250,
                             gwy_app_file_chooser_do_full_preview, chooser,
                             NULL);
}
Example #4
0
static gboolean
gwy_app_file_chooser_do_full_preview(gpointer user_data)
{
    GtkFileChooser *fchooser;
    GtkTreeModel *model;
    GtkListStore *store;
    GwyAppFileChooser *chooser;
    GSList *channel_ids, *l;
    GdkPixbuf *pixbuf;
    GtkTreeIter iter;
    GString *str;
    gint id;

    chooser = GWY_APP_FILE_CHOOSER(user_data);
    chooser->full_preview_id = 0;

    /* Always no-op here? */
    gwy_app_file_chooser_free_preview(chooser);

    fchooser = GTK_FILE_CHOOSER(chooser);
    chooser->preview_name_sys = gtk_file_chooser_get_preview_filename(fchooser);
    /* We should not be called when gtk_file_chooser_get_preview_filename()
     * returns NULL preview file name */
    if (!chooser->preview_name_sys) {
        g_warning("Full preview invoked with NULL preview file name");
        return FALSE;
    }

    model = gtk_icon_view_get_model(GTK_ICON_VIEW(chooser->preview));
    store = GTK_LIST_STORE(model);

    chooser->preview_data = gwy_file_load(chooser->preview_name_sys,
                                          GWY_RUN_NONINTERACTIVE, NULL);
    if (!chooser->preview_data) {
        gwy_app_file_chooser_free_preview(chooser);
        gtk_tree_model_get_iter_first(model, &iter);
        gtk_list_store_set(store, &iter,
                           COLUMN_FILEINFO, _("Cannot preview"),
                           -1);

        return FALSE;
    }

    channel_ids = NULL;
    gwy_container_foreach(chooser->preview_data, NULL,
                          add_channel_id, &channel_ids);
    channel_ids = g_slist_sort(channel_ids, compare_ids);
    if (!channel_ids) {
        gwy_app_file_chooser_free_preview(chooser);
        return FALSE;
    }

    g_object_set(chooser->renderer_fileinfo,
                 "ellipsize", PANGO_ELLIPSIZE_END,
                 "wrap-width", -1,
                 NULL);

    gtk_list_store_clear(store);
    str = g_string_new(NULL);
    for (l = channel_ids; l; l = g_slist_next(l)) {
        id = GPOINTER_TO_INT(l->data);
        pixbuf = gwy_app_get_channel_thumbnail(chooser->preview_data, id,
                                               TMS_NORMAL_THUMB_SIZE,
                                               TMS_NORMAL_THUMB_SIZE);
        if (!pixbuf) {
            g_warning("Cannot make a pixbuf of channel %d", id);
            continue;
        }

        if (chooser->make_thumbnail) {
            _gwy_app_recent_file_write_thumbnail(chooser->preview_name_sys,
                                                 chooser->preview_data,
                                                 id, pixbuf);
            chooser->make_thumbnail = FALSE;
        }

        gwy_app_file_chooser_describe_channel(chooser->preview_data, id, str);
        gtk_list_store_insert_with_values(store, &iter, -1,
                                          COLUMN_PIXBUF, pixbuf,
                                          COLUMN_FILEINFO, str->str,
                                          -1);
        g_object_unref(pixbuf);
    }

    g_string_free(str, TRUE);

    return FALSE;
}
static gboolean
gwy_app_file_chooser_do_full_preview(gpointer user_data)
{
    GtkFileChooser *fchooser;
    GtkTreeModel *model;
    GtkListStore *store;
    GwyAppFileChooser *chooser;
    FileInfoData filedata;
    GwyContainer *data, *settings;
    GdkPixbuf *pixbuf;
    GtkTreeIter iter;
    const gchar *name;
    gboolean row_level = FALSE, plane_level = FALSE;
    GString *str;
    GSList *l;
    gint id;

    chooser = GWY_APP_FILE_CHOOSER(user_data);
    chooser->full_preview_id = 0;

    /* Always no-op here? */
    gwy_app_file_chooser_free_preview(chooser);

    fchooser = GTK_FILE_CHOOSER(chooser);
    chooser->preview_name_sys = gtk_file_chooser_get_preview_filename(fchooser);
    /* We should not be called when gtk_file_chooser_get_preview_filename()
     * returns NULL preview file name */
    if (!chooser->preview_name_sys) {
        g_warning("Full preview invoked with NULL preview file name");
        return FALSE;
    }

    model = gtk_icon_view_get_model(GTK_ICON_VIEW(chooser->preview));
    store = GTK_LIST_STORE(model);

    data = gwy_file_load(chooser->preview_name_sys,
                         GWY_RUN_NONINTERACTIVE, NULL);
    if (!data) {
        gwy_app_file_chooser_free_preview(chooser);
        gtk_list_store_clear(store);
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter,
                           COLUMN_FILEINFO, _("Cannot preview"),
                           -1);

        return FALSE;
    }

    gwy_data_validate(data,
                      GWY_DATA_VALIDATE_CORRECT | GWY_DATA_VALIDATE_NO_REPORT);

    memset(&filedata, 0, sizeof(FileInfoData));
    gwy_container_foreach(data, NULL, add_object_id, &filedata);
    filedata.channels = g_slist_sort(filedata.channels, compare_ids);
    filedata.graphs = g_slist_sort(filedata.graphs, compare_ids);
    filedata.spectra = g_slist_sort(filedata.spectra, compare_ids);

    str = g_string_new(NULL);
    if (gwy_file_get_data_info(data, &name, NULL)) {
        /* FIXME: Make this translatable */
        g_string_printf(str, "<small>%s", name);
        if (filedata.nchannels)
            g_string_append_printf(str, ", %d ch", filedata.nchannels);
        if (filedata.graphs)
            g_string_append_printf(str, ", %d gr", filedata.ngraphs);
        if (filedata.spectra)
            g_string_append_printf(str, ", %d sps", filedata.nspectra);
        g_string_append(str, "</small>");
        gtk_label_set_markup(GTK_LABEL(chooser->preview_type), str->str);
    }

    if (!filedata.channels) {
        g_string_free(str, TRUE);
        g_slist_free(filedata.channels);
        g_slist_free(filedata.graphs);
        g_slist_free(filedata.spectra);
        g_object_unref(data);
        gwy_app_file_chooser_free_preview(chooser);
        return FALSE;
    }

    g_object_set(chooser->renderer_fileinfo,
                 "ellipsize", PANGO_ELLIPSIZE_END,
                 "wrap-width", -1,
                 NULL);
    settings = gwy_app_settings_get();
    gwy_container_gis_boolean_by_name(settings, "/app/file/preview/plane-level",
                                      &plane_level);
    gwy_container_gis_boolean_by_name(settings, "/app/file/preview/row-level",
                                      &row_level);

    gtk_list_store_clear(store);
    for (l = filedata.channels; l; l = g_slist_next(l)) {
        id = GPOINTER_TO_INT(l->data);
        modify_channel_for_preview(data, id, plane_level, row_level);
        pixbuf = gwy_app_get_channel_thumbnail(data, id,
                                               TMS_NORMAL_THUMB_SIZE,
                                               TMS_NORMAL_THUMB_SIZE);
        if (!pixbuf) {
            g_warning("Cannot make a pixbuf of channel %d", id);
            continue;
        }

        if (chooser->make_thumbnail) {
            _gwy_app_recent_file_write_thumbnail(chooser->preview_name_sys,
                                                 data,
                                                 id, pixbuf);
            chooser->make_thumbnail = FALSE;
        }

        gwy_app_file_chooser_describe_channel(data, id, str);
        gtk_list_store_insert_with_values(store, &iter, -1,
                                          COLUMN_PIXBUF, pixbuf,
                                          COLUMN_FILEINFO, str->str,
                                          -1);
        g_object_unref(pixbuf);
    }

    g_slist_free(filedata.channels);
    g_slist_free(filedata.graphs);
    g_slist_free(filedata.spectra);
    g_string_free(str, TRUE);
    g_object_unref(data);

    return FALSE;
}