973 lines
33 KiB
C
973 lines
33 KiB
C
|
/* PIKA - Photo and Image Kooker Application
|
||
|
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
||
|
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
||
|
*
|
||
|
* Original copyright, applying to most contents (license remains unchanged):
|
||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||
|
*
|
||
|
* pikafiledialog.c
|
||
|
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "config.h"
|
||
|
|
||
|
#include <gegl.h>
|
||
|
#include <gtk/gtk.h>
|
||
|
|
||
|
#include "libpikabase/pikabase.h"
|
||
|
#include "libpikaconfig/pikaconfig.h"
|
||
|
#include "libpikawidgets/pikawidgets.h"
|
||
|
|
||
|
#include "widgets-types.h"
|
||
|
|
||
|
#include "core/pika.h"
|
||
|
#include "core/pikaimage.h"
|
||
|
#include "core/pikaprogress.h"
|
||
|
|
||
|
#include "config/pikaguiconfig.h"
|
||
|
|
||
|
#include "plug-in/pikapluginmanager-file.h"
|
||
|
#include "plug-in/pikapluginprocedure.h"
|
||
|
|
||
|
#include "pikafiledialog.h"
|
||
|
#include "pikafileprocview.h"
|
||
|
#include "pikaprogressbox.h"
|
||
|
#include "pikathumbbox.h"
|
||
|
#include "pikawidgets-utils.h"
|
||
|
|
||
|
#include "pika-intl.h"
|
||
|
|
||
|
|
||
|
enum
|
||
|
{
|
||
|
PROP_0,
|
||
|
PROP_PIKA,
|
||
|
PROP_HELP_ID,
|
||
|
PROP_OK_BUTTON_LABEL,
|
||
|
PROP_AUTOMATIC_HELP_ID,
|
||
|
PROP_AUTOMATIC_LABEL,
|
||
|
PROP_FILE_FILTER_LABEL,
|
||
|
PROP_FILE_PROCS,
|
||
|
PROP_FILE_PROCS_ALL_IMAGES,
|
||
|
PROP_SHOW_ALL_FILES,
|
||
|
};
|
||
|
|
||
|
typedef struct _PikaFileDialogState PikaFileDialogState;
|
||
|
|
||
|
struct _PikaFileDialogState
|
||
|
{
|
||
|
gchar *filter_name;
|
||
|
};
|
||
|
|
||
|
|
||
|
static void pika_file_dialog_progress_iface_init (PikaProgressInterface *iface);
|
||
|
|
||
|
static void pika_file_dialog_set_property (GObject *object,
|
||
|
guint property_id,
|
||
|
const GValue *value,
|
||
|
GParamSpec *pspec);
|
||
|
static void pika_file_dialog_get_property (GObject *object,
|
||
|
guint property_id,
|
||
|
GValue *value,
|
||
|
GParamSpec *pspec);
|
||
|
static void pika_file_dialog_constructed (GObject *object);
|
||
|
static void pika_file_dialog_dispose (GObject *object);
|
||
|
|
||
|
static gboolean pika_file_dialog_delete_event (GtkWidget *widget,
|
||
|
GdkEventAny *event);
|
||
|
static void pika_file_dialog_response (GtkDialog *dialog,
|
||
|
gint response_id);
|
||
|
static GFile * pika_file_dialog_real_get_default_folder (PikaFileDialog *dialog);
|
||
|
static void pika_file_dialog_real_save_state (PikaFileDialog *dialog,
|
||
|
const gchar *state_name);
|
||
|
static void pika_file_dialog_real_load_state (PikaFileDialog *dialog,
|
||
|
const gchar *state_name);
|
||
|
|
||
|
static PikaProgress *
|
||
|
pika_file_dialog_progress_start (PikaProgress *progress,
|
||
|
gboolean cancellable,
|
||
|
const gchar *message);
|
||
|
static void pika_file_dialog_progress_end (PikaProgress *progress);
|
||
|
static gboolean pika_file_dialog_progress_is_active (PikaProgress *progress);
|
||
|
static void pika_file_dialog_progress_set_text (PikaProgress *progress,
|
||
|
const gchar *message);
|
||
|
static void pika_file_dialog_progress_set_value (PikaProgress *progress,
|
||
|
gdouble percentage);
|
||
|
static gdouble pika_file_dialog_progress_get_value (PikaProgress *progress);
|
||
|
static void pika_file_dialog_progress_pulse (PikaProgress *progress);
|
||
|
static guint32 pika_file_dialog_progress_get_window_id (PikaProgress *progress);
|
||
|
|
||
|
static void pika_file_dialog_add_user_dir (PikaFileDialog *dialog,
|
||
|
GUserDirectory directory);
|
||
|
static void pika_file_dialog_add_preview (PikaFileDialog *dialog);
|
||
|
static void pika_file_dialog_add_proc_selection (PikaFileDialog *dialog);
|
||
|
|
||
|
static void pika_file_dialog_selection_changed (GtkFileChooser *chooser,
|
||
|
PikaFileDialog *dialog);
|
||
|
static void pika_file_dialog_update_preview (GtkFileChooser *chooser,
|
||
|
PikaFileDialog *dialog);
|
||
|
|
||
|
static void pika_file_dialog_proc_changed (PikaFileProcView *view,
|
||
|
PikaFileDialog *dialog);
|
||
|
|
||
|
static void pika_file_dialog_help_func (const gchar *help_id,
|
||
|
gpointer help_data);
|
||
|
|
||
|
static PikaFileDialogState
|
||
|
* pika_file_dialog_get_state (PikaFileDialog *dialog);
|
||
|
static void pika_file_dialog_set_state (PikaFileDialog *dialog,
|
||
|
PikaFileDialogState *state);
|
||
|
static void pika_file_dialog_state_destroy (PikaFileDialogState *state);
|
||
|
|
||
|
|
||
|
|
||
|
G_DEFINE_TYPE_WITH_CODE (PikaFileDialog, pika_file_dialog,
|
||
|
GTK_TYPE_FILE_CHOOSER_DIALOG,
|
||
|
G_IMPLEMENT_INTERFACE (PIKA_TYPE_PROGRESS,
|
||
|
pika_file_dialog_progress_iface_init))
|
||
|
|
||
|
#define parent_class pika_file_dialog_parent_class
|
||
|
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_class_init (PikaFileDialogClass *klass)
|
||
|
{
|
||
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||
|
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
|
||
|
|
||
|
object_class->set_property = pika_file_dialog_set_property;
|
||
|
object_class->get_property = pika_file_dialog_get_property;
|
||
|
object_class->constructed = pika_file_dialog_constructed;
|
||
|
object_class->dispose = pika_file_dialog_dispose;
|
||
|
|
||
|
widget_class->delete_event = pika_file_dialog_delete_event;
|
||
|
|
||
|
dialog_class->response = pika_file_dialog_response;
|
||
|
|
||
|
klass->get_default_folder = pika_file_dialog_real_get_default_folder;
|
||
|
klass->save_state = pika_file_dialog_real_save_state;
|
||
|
klass->load_state = pika_file_dialog_real_load_state;
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_PIKA,
|
||
|
g_param_spec_object ("pika", NULL, NULL,
|
||
|
PIKA_TYPE_PIKA,
|
||
|
PIKA_PARAM_READWRITE |
|
||
|
G_PARAM_CONSTRUCT_ONLY));
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_HELP_ID,
|
||
|
g_param_spec_string ("help-id", NULL, NULL,
|
||
|
NULL,
|
||
|
PIKA_PARAM_READWRITE |
|
||
|
G_PARAM_CONSTRUCT_ONLY));
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_OK_BUTTON_LABEL,
|
||
|
g_param_spec_string ("ok-button-label",
|
||
|
NULL, NULL,
|
||
|
_("_OK"),
|
||
|
PIKA_PARAM_WRITABLE |
|
||
|
G_PARAM_CONSTRUCT_ONLY));
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_AUTOMATIC_HELP_ID,
|
||
|
g_param_spec_string ("automatic-help-id",
|
||
|
NULL, NULL,
|
||
|
NULL,
|
||
|
PIKA_PARAM_WRITABLE |
|
||
|
G_PARAM_CONSTRUCT_ONLY));
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_AUTOMATIC_LABEL,
|
||
|
g_param_spec_string ("automatic-label",
|
||
|
NULL, NULL,
|
||
|
NULL,
|
||
|
PIKA_PARAM_WRITABLE |
|
||
|
G_PARAM_CONSTRUCT_ONLY));
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_FILE_FILTER_LABEL,
|
||
|
g_param_spec_string ("file-filter-label",
|
||
|
NULL, NULL,
|
||
|
NULL,
|
||
|
PIKA_PARAM_WRITABLE |
|
||
|
G_PARAM_CONSTRUCT_ONLY));
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_FILE_PROCS,
|
||
|
g_param_spec_enum ("file-procs",
|
||
|
NULL, NULL,
|
||
|
PIKA_TYPE_FILE_PROCEDURE_GROUP,
|
||
|
PIKA_FILE_PROCEDURE_GROUP_NONE,
|
||
|
PIKA_PARAM_WRITABLE |
|
||
|
G_PARAM_CONSTRUCT_ONLY));
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_FILE_PROCS_ALL_IMAGES,
|
||
|
g_param_spec_enum ("file-procs-all-images",
|
||
|
NULL, NULL,
|
||
|
PIKA_TYPE_FILE_PROCEDURE_GROUP,
|
||
|
PIKA_FILE_PROCEDURE_GROUP_NONE,
|
||
|
PIKA_PARAM_WRITABLE |
|
||
|
G_PARAM_CONSTRUCT_ONLY));
|
||
|
|
||
|
g_object_class_install_property (object_class, PROP_SHOW_ALL_FILES,
|
||
|
g_param_spec_boolean ("show-all-files",
|
||
|
NULL, NULL, FALSE,
|
||
|
PIKA_PARAM_READWRITE));
|
||
|
|
||
|
gtk_widget_class_set_css_name (widget_class, "PikaFileDialog");
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_init (PikaFileDialog *dialog)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_progress_iface_init (PikaProgressInterface *iface)
|
||
|
{
|
||
|
iface->start = pika_file_dialog_progress_start;
|
||
|
iface->end = pika_file_dialog_progress_end;
|
||
|
iface->is_active = pika_file_dialog_progress_is_active;
|
||
|
iface->set_text = pika_file_dialog_progress_set_text;
|
||
|
iface->set_value = pika_file_dialog_progress_set_value;
|
||
|
iface->get_value = pika_file_dialog_progress_get_value;
|
||
|
iface->pulse = pika_file_dialog_progress_pulse;
|
||
|
iface->get_window_id = pika_file_dialog_progress_get_window_id;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_set_property (GObject *object,
|
||
|
guint property_id,
|
||
|
const GValue *value,
|
||
|
GParamSpec *pspec)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (object);
|
||
|
|
||
|
switch (property_id)
|
||
|
{
|
||
|
case PROP_PIKA:
|
||
|
dialog->pika = g_value_get_object (value);
|
||
|
break;
|
||
|
case PROP_HELP_ID:
|
||
|
dialog->help_id = g_value_dup_string (value);
|
||
|
break;
|
||
|
case PROP_OK_BUTTON_LABEL:
|
||
|
dialog->ok_button_label = g_value_dup_string (value);
|
||
|
break;
|
||
|
case PROP_AUTOMATIC_HELP_ID:
|
||
|
dialog->automatic_help_id = g_value_dup_string (value);
|
||
|
break;
|
||
|
case PROP_AUTOMATIC_LABEL:
|
||
|
dialog->automatic_label = g_value_dup_string (value);
|
||
|
break;
|
||
|
case PROP_FILE_FILTER_LABEL:
|
||
|
dialog->file_filter_label = g_value_dup_string (value);
|
||
|
break;
|
||
|
case PROP_FILE_PROCS:
|
||
|
dialog->file_procs =
|
||
|
pika_plug_in_manager_get_file_procedures (dialog->pika->plug_in_manager,
|
||
|
g_value_get_enum (value));
|
||
|
break;
|
||
|
case PROP_FILE_PROCS_ALL_IMAGES:
|
||
|
dialog->file_procs_all_images =
|
||
|
pika_plug_in_manager_get_file_procedures (dialog->pika->plug_in_manager,
|
||
|
g_value_get_enum (value));
|
||
|
break;
|
||
|
case PROP_SHOW_ALL_FILES:
|
||
|
dialog->show_all_files = g_value_get_boolean (value);
|
||
|
pika_file_dialog_proc_changed (PIKA_FILE_PROC_VIEW (dialog->proc_view),
|
||
|
dialog);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_get_property (GObject *object,
|
||
|
guint property_id,
|
||
|
GValue *value,
|
||
|
GParamSpec *pspec)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (object);
|
||
|
|
||
|
switch (property_id)
|
||
|
{
|
||
|
case PROP_PIKA:
|
||
|
g_value_set_object (value, dialog->pika);
|
||
|
break;
|
||
|
case PROP_HELP_ID:
|
||
|
g_value_set_string (value, dialog->help_id);
|
||
|
break;
|
||
|
case PROP_SHOW_ALL_FILES:
|
||
|
g_value_set_boolean (value, dialog->show_all_files);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_constructed (GObject *object)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (object);
|
||
|
|
||
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
||
|
|
||
|
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
|
||
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
||
|
dialog->ok_button_label, GTK_RESPONSE_OK,
|
||
|
NULL);
|
||
|
|
||
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
||
|
pika_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
||
|
GTK_RESPONSE_OK,
|
||
|
GTK_RESPONSE_CANCEL,
|
||
|
-1);
|
||
|
|
||
|
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (object), FALSE);
|
||
|
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (object),
|
||
|
TRUE);
|
||
|
|
||
|
if (dialog->help_id)
|
||
|
{
|
||
|
pika_help_connect (GTK_WIDGET (dialog),
|
||
|
pika_file_dialog_help_func, dialog->help_id,
|
||
|
dialog, NULL);
|
||
|
|
||
|
if (PIKA_GUI_CONFIG (dialog->pika->config)->show_help_button)
|
||
|
{
|
||
|
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
|
||
|
_("_Help"), GTK_RESPONSE_HELP,
|
||
|
NULL);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* All classes derivated from PikaFileDialog should show these. */
|
||
|
pika_file_dialog_add_user_dir (dialog, G_USER_DIRECTORY_PICTURES);
|
||
|
pika_file_dialog_add_user_dir (dialog, G_USER_DIRECTORY_DOCUMENTS);
|
||
|
|
||
|
pika_file_dialog_add_preview (dialog);
|
||
|
|
||
|
dialog->extra_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
|
||
|
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog),
|
||
|
dialog->extra_vbox);
|
||
|
gtk_widget_show (dialog->extra_vbox);
|
||
|
|
||
|
pika_file_dialog_add_proc_selection (dialog);
|
||
|
|
||
|
dialog->progress = pika_progress_box_new ();
|
||
|
gtk_box_pack_end (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
||
|
dialog->progress, FALSE, FALSE, 0);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_dispose (GObject *object)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (object);
|
||
|
|
||
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||
|
|
||
|
dialog->progress = NULL;
|
||
|
|
||
|
g_clear_pointer (&dialog->help_id, g_free);
|
||
|
g_clear_pointer (&dialog->ok_button_label, g_free);
|
||
|
g_clear_pointer (&dialog->automatic_help_id, g_free);
|
||
|
g_clear_pointer (&dialog->automatic_label, g_free);
|
||
|
g_clear_pointer (&dialog->file_filter_label, g_free);
|
||
|
}
|
||
|
|
||
|
static gboolean
|
||
|
pika_file_dialog_delete_event (GtkWidget *widget,
|
||
|
GdkEventAny *event)
|
||
|
{
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_response (GtkDialog *dialog,
|
||
|
gint response_id)
|
||
|
{
|
||
|
PikaFileDialog *file_dialog = PIKA_FILE_DIALOG (dialog);
|
||
|
|
||
|
if (response_id == GTK_RESPONSE_HELP)
|
||
|
{
|
||
|
pika_standard_help_func (file_dialog->help_id, NULL);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (response_id != GTK_RESPONSE_OK && file_dialog->busy)
|
||
|
{
|
||
|
file_dialog->canceled = TRUE;
|
||
|
|
||
|
if (file_dialog->progress &&
|
||
|
PIKA_PROGRESS_BOX (file_dialog->progress)->active &&
|
||
|
PIKA_PROGRESS_BOX (file_dialog->progress)->cancellable)
|
||
|
{
|
||
|
pika_progress_cancel (PIKA_PROGRESS (dialog));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static GFile *
|
||
|
pika_file_dialog_real_get_default_folder (PikaFileDialog *dialog)
|
||
|
{
|
||
|
GFile *file = NULL;
|
||
|
|
||
|
if (dialog->pika->default_folder)
|
||
|
{
|
||
|
file = dialog->pika->default_folder;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
file = g_object_get_data (G_OBJECT (dialog->pika),
|
||
|
"pika-default-folder");
|
||
|
|
||
|
if (! file)
|
||
|
{
|
||
|
gchar *path;
|
||
|
|
||
|
/* Make sure the paths end with G_DIR_SEPARATOR_S */
|
||
|
|
||
|
#ifdef PLATFORM_OSX
|
||
|
/* See bug 753683, "Desktop" is expected on OS X */
|
||
|
path = g_build_path (G_DIR_SEPARATOR_S,
|
||
|
g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP),
|
||
|
G_DIR_SEPARATOR_S,
|
||
|
NULL);
|
||
|
#else
|
||
|
path = g_build_path (G_DIR_SEPARATOR_S,
|
||
|
g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
|
||
|
G_DIR_SEPARATOR_S,
|
||
|
NULL);
|
||
|
#endif
|
||
|
|
||
|
/* Paranoia fallback, see bug #722400 */
|
||
|
if (! path)
|
||
|
path = g_build_path (G_DIR_SEPARATOR_S,
|
||
|
g_get_home_dir (),
|
||
|
G_DIR_SEPARATOR_S,
|
||
|
NULL);
|
||
|
|
||
|
file = g_file_new_for_path (path);
|
||
|
g_free (path);
|
||
|
|
||
|
g_object_set_data_full (G_OBJECT (dialog->pika),
|
||
|
"pika-default-folder",
|
||
|
file, (GDestroyNotify) g_object_unref);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return file;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_real_save_state (PikaFileDialog *dialog,
|
||
|
const gchar *state_name)
|
||
|
{
|
||
|
g_object_set_data_full (G_OBJECT (dialog->pika), state_name,
|
||
|
pika_file_dialog_get_state (dialog),
|
||
|
(GDestroyNotify) pika_file_dialog_state_destroy);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_real_load_state (PikaFileDialog *dialog,
|
||
|
const gchar *state_name)
|
||
|
{
|
||
|
PikaFileDialogState *state;
|
||
|
|
||
|
state = g_object_get_data (G_OBJECT (dialog->pika), state_name);
|
||
|
|
||
|
if (state)
|
||
|
pika_file_dialog_set_state (PIKA_FILE_DIALOG (dialog), state);
|
||
|
}
|
||
|
|
||
|
static PikaProgress *
|
||
|
pika_file_dialog_progress_start (PikaProgress *progress,
|
||
|
gboolean cancellable,
|
||
|
const gchar *message)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (progress);
|
||
|
PikaProgress *retval = NULL;
|
||
|
|
||
|
if (dialog->progress)
|
||
|
{
|
||
|
retval = pika_progress_start (PIKA_PROGRESS (dialog->progress),
|
||
|
cancellable, "%s", message);
|
||
|
gtk_widget_show (dialog->progress);
|
||
|
|
||
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||
|
GTK_RESPONSE_CANCEL, cancellable);
|
||
|
}
|
||
|
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_progress_end (PikaProgress *progress)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (progress);
|
||
|
|
||
|
if (dialog->progress)
|
||
|
{
|
||
|
pika_progress_end (PIKA_PROGRESS (dialog->progress));
|
||
|
gtk_widget_hide (dialog->progress);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static gboolean
|
||
|
pika_file_dialog_progress_is_active (PikaProgress *progress)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (progress);
|
||
|
|
||
|
if (dialog->progress)
|
||
|
return pika_progress_is_active (PIKA_PROGRESS (dialog->progress));
|
||
|
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_progress_set_text (PikaProgress *progress,
|
||
|
const gchar *message)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (progress);
|
||
|
|
||
|
if (dialog->progress)
|
||
|
pika_progress_set_text_literal (PIKA_PROGRESS (dialog->progress), message);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_progress_set_value (PikaProgress *progress,
|
||
|
gdouble percentage)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (progress);
|
||
|
|
||
|
if (dialog->progress)
|
||
|
pika_progress_set_value (PIKA_PROGRESS (dialog->progress), percentage);
|
||
|
}
|
||
|
|
||
|
static gdouble
|
||
|
pika_file_dialog_progress_get_value (PikaProgress *progress)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (progress);
|
||
|
|
||
|
if (dialog->progress)
|
||
|
return pika_progress_get_value (PIKA_PROGRESS (dialog->progress));
|
||
|
|
||
|
return 0.0;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_progress_pulse (PikaProgress *progress)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (progress);
|
||
|
|
||
|
if (dialog->progress)
|
||
|
pika_progress_pulse (PIKA_PROGRESS (dialog->progress));
|
||
|
}
|
||
|
|
||
|
static guint32
|
||
|
pika_file_dialog_progress_get_window_id (PikaProgress *progress)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (progress);
|
||
|
|
||
|
return pika_window_get_native_id (GTK_WINDOW (dialog));
|
||
|
}
|
||
|
|
||
|
|
||
|
/* public functions */
|
||
|
|
||
|
void
|
||
|
pika_file_dialog_add_extra_widget (PikaFileDialog *dialog,
|
||
|
GtkWidget *widget,
|
||
|
gboolean expand,
|
||
|
gboolean fill,
|
||
|
guint padding)
|
||
|
{
|
||
|
gtk_box_pack_start (GTK_BOX (dialog->extra_vbox),
|
||
|
widget, expand, fill, padding);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
pika_file_dialog_set_sensitive (PikaFileDialog *dialog,
|
||
|
gboolean sensitive)
|
||
|
{
|
||
|
GtkWidget *content_area;
|
||
|
GList *children;
|
||
|
GList *list;
|
||
|
|
||
|
g_return_if_fail (PIKA_IS_FILE_DIALOG (dialog));
|
||
|
|
||
|
/* bail out if we are already destroyed */
|
||
|
if (! dialog->progress)
|
||
|
return;
|
||
|
|
||
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
||
|
|
||
|
children = gtk_container_get_children (GTK_CONTAINER (content_area));
|
||
|
|
||
|
for (list = children; list; list = g_list_next (list))
|
||
|
{
|
||
|
/* skip the last item (the action area) */
|
||
|
if (! g_list_next (list))
|
||
|
break;
|
||
|
|
||
|
gtk_widget_set_sensitive (list->data, sensitive);
|
||
|
}
|
||
|
|
||
|
g_list_free (children);
|
||
|
|
||
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||
|
GTK_RESPONSE_CANCEL, sensitive);
|
||
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||
|
GTK_RESPONSE_OK, sensitive);
|
||
|
|
||
|
dialog->busy = ! sensitive;
|
||
|
dialog->canceled = FALSE;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
pika_file_dialog_set_file_proc (PikaFileDialog *dialog,
|
||
|
PikaPlugInProcedure *file_proc)
|
||
|
{
|
||
|
g_return_if_fail (PIKA_IS_FILE_DIALOG (dialog));
|
||
|
|
||
|
if (file_proc != dialog->file_proc)
|
||
|
pika_file_proc_view_set_proc (PIKA_FILE_PROC_VIEW (dialog->proc_view),
|
||
|
file_proc);
|
||
|
}
|
||
|
|
||
|
GFile *
|
||
|
pika_file_dialog_get_default_folder (PikaFileDialog *dialog)
|
||
|
{
|
||
|
g_return_val_if_fail (PIKA_IS_FILE_DIALOG (dialog), NULL);
|
||
|
|
||
|
return PIKA_FILE_DIALOG_GET_CLASS (dialog)->get_default_folder (dialog);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
pika_file_dialog_save_state (PikaFileDialog *dialog,
|
||
|
const gchar *state_name)
|
||
|
{
|
||
|
g_return_if_fail (PIKA_IS_FILE_DIALOG (dialog));
|
||
|
|
||
|
PIKA_FILE_DIALOG_GET_CLASS (dialog)->save_state (dialog, state_name);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
pika_file_dialog_load_state (PikaFileDialog *dialog,
|
||
|
const gchar *state_name)
|
||
|
{
|
||
|
g_return_if_fail (PIKA_IS_FILE_DIALOG (dialog));
|
||
|
|
||
|
PIKA_FILE_DIALOG_GET_CLASS (dialog)->load_state (dialog, state_name);
|
||
|
}
|
||
|
|
||
|
|
||
|
/* private functions */
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_add_user_dir (PikaFileDialog *dialog,
|
||
|
GUserDirectory directory)
|
||
|
{
|
||
|
const gchar *user_dir = g_get_user_special_dir (directory);
|
||
|
|
||
|
if (user_dir)
|
||
|
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
|
||
|
user_dir, NULL);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_add_preview (PikaFileDialog *dialog)
|
||
|
{
|
||
|
if (dialog->pika->config->thumbnail_size <= 0)
|
||
|
return;
|
||
|
|
||
|
gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (dialog), FALSE);
|
||
|
|
||
|
g_signal_connect (dialog, "selection-changed",
|
||
|
G_CALLBACK (pika_file_dialog_selection_changed),
|
||
|
dialog);
|
||
|
g_signal_connect (dialog, "update-preview",
|
||
|
G_CALLBACK (pika_file_dialog_update_preview),
|
||
|
dialog);
|
||
|
|
||
|
dialog->thumb_box = pika_thumb_box_new (pika_get_user_context (dialog->pika));
|
||
|
gtk_widget_set_sensitive (GTK_WIDGET (dialog->thumb_box), FALSE);
|
||
|
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog),
|
||
|
dialog->thumb_box);
|
||
|
gtk_widget_show (dialog->thumb_box);
|
||
|
|
||
|
#ifdef ENABLE_FILE_SYSTEM_ICONS
|
||
|
PIKA_VIEW_RENDERER_IMAGEFILE (PIKA_VIEW (PIKA_THUMB_BOX (dialog->thumb_box)->preview)->renderer)->file_system = _gtk_file_chooser_get_file_system (GTK_FILE_CHOOSER (dialog));
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_add_proc_selection (PikaFileDialog *dialog)
|
||
|
{
|
||
|
GtkWidget *box;
|
||
|
GtkWidget *scrolled_window;
|
||
|
GtkWidget *checkbox;
|
||
|
|
||
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
|
||
|
pika_file_dialog_add_extra_widget (dialog, box, TRUE, TRUE, 0);
|
||
|
gtk_widget_show (box);
|
||
|
|
||
|
dialog->proc_expander = gtk_expander_new_with_mnemonic (NULL);
|
||
|
gtk_expander_set_resize_toplevel (GTK_EXPANDER (dialog->proc_expander), TRUE);
|
||
|
gtk_widget_set_hexpand (GTK_WIDGET (dialog->proc_expander), TRUE);
|
||
|
gtk_box_pack_end (GTK_BOX (box), dialog->proc_expander, FALSE, FALSE, 1);
|
||
|
gtk_widget_show (dialog->proc_expander);
|
||
|
|
||
|
/* The list of file formats. */
|
||
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
||
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
|
||
|
GTK_SHADOW_IN);
|
||
|
gtk_container_add (GTK_CONTAINER (dialog->proc_expander), scrolled_window);
|
||
|
gtk_widget_show (scrolled_window);
|
||
|
|
||
|
gtk_widget_set_size_request (scrolled_window, -1, 200);
|
||
|
|
||
|
dialog->proc_view = pika_file_proc_view_new (dialog->pika,
|
||
|
dialog->file_procs,
|
||
|
dialog->automatic_label,
|
||
|
dialog->automatic_help_id);
|
||
|
gtk_container_add (GTK_CONTAINER (scrolled_window), dialog->proc_view);
|
||
|
gtk_widget_show (dialog->proc_view);
|
||
|
|
||
|
g_signal_connect (dialog->proc_view, "changed",
|
||
|
G_CALLBACK (pika_file_dialog_proc_changed),
|
||
|
dialog);
|
||
|
|
||
|
pika_file_proc_view_set_proc (PIKA_FILE_PROC_VIEW (dialog->proc_view), NULL);
|
||
|
|
||
|
/* Checkbox to show all files. */
|
||
|
checkbox = pika_prop_check_button_new (G_OBJECT (dialog),
|
||
|
"show-all-files",
|
||
|
_("Show _All Files"));
|
||
|
gtk_box_pack_end (GTK_BOX (box), checkbox, FALSE, FALSE, 1);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_selection_changed (GtkFileChooser *chooser,
|
||
|
PikaFileDialog *dialog)
|
||
|
{
|
||
|
pika_thumb_box_take_files (PIKA_THUMB_BOX (dialog->thumb_box),
|
||
|
gtk_file_chooser_get_files (chooser));
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_update_preview (GtkFileChooser *chooser,
|
||
|
PikaFileDialog *dialog)
|
||
|
{
|
||
|
pika_thumb_box_take_file (PIKA_THUMB_BOX (dialog->thumb_box),
|
||
|
gtk_file_chooser_get_preview_file (chooser));
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_proc_changed (PikaFileProcView *view,
|
||
|
PikaFileDialog *dialog)
|
||
|
{
|
||
|
GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
|
||
|
GtkFileFilter *filter;
|
||
|
gchar *name;
|
||
|
gchar *label;
|
||
|
|
||
|
dialog->file_proc = pika_file_proc_view_get_proc (view, &name, &filter);
|
||
|
|
||
|
if (name)
|
||
|
label = g_strdup_printf (_("Select File _Type (%s)"), name);
|
||
|
else
|
||
|
label = g_strdup (_("Select File _Type"));
|
||
|
|
||
|
gtk_expander_set_label (GTK_EXPANDER (dialog->proc_expander), label);
|
||
|
|
||
|
g_free (label);
|
||
|
g_free (name);
|
||
|
|
||
|
if (dialog->show_all_files)
|
||
|
g_clear_object (&filter);
|
||
|
|
||
|
if (! filter)
|
||
|
{
|
||
|
filter = g_object_ref_sink (gtk_file_filter_new ());
|
||
|
|
||
|
gtk_file_filter_add_pattern (filter, "*");
|
||
|
}
|
||
|
|
||
|
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
|
||
|
|
||
|
g_object_unref (filter);
|
||
|
|
||
|
if (gtk_file_chooser_get_action (chooser) == GTK_FILE_CHOOSER_ACTION_SAVE)
|
||
|
{
|
||
|
PikaPlugInProcedure *proc = dialog->file_proc;
|
||
|
|
||
|
if (proc && proc->extensions_list)
|
||
|
{
|
||
|
gchar *uri = gtk_file_chooser_get_uri (chooser);
|
||
|
|
||
|
if (uri && strlen (uri))
|
||
|
{
|
||
|
const gchar *last_dot = strrchr (uri, '.');
|
||
|
|
||
|
/* if the dot is before the last slash, ignore it */
|
||
|
if (last_dot && strrchr (uri, '/') > last_dot)
|
||
|
last_dot = NULL;
|
||
|
|
||
|
/* check if the uri has a "meta extension" (e.g. foo.bar.gz)
|
||
|
* and try to truncate both extensions away.
|
||
|
*/
|
||
|
if (last_dot && last_dot != uri)
|
||
|
{
|
||
|
GList *list;
|
||
|
|
||
|
for (list = view->meta_extensions;
|
||
|
list;
|
||
|
list = g_list_next (list))
|
||
|
{
|
||
|
const gchar *ext = list->data;
|
||
|
|
||
|
if (! strcmp (ext, last_dot + 1))
|
||
|
{
|
||
|
const gchar *p = last_dot - 1;
|
||
|
|
||
|
while (p > uri && *p != '.')
|
||
|
p--;
|
||
|
|
||
|
if (p != uri && *p == '.')
|
||
|
{
|
||
|
last_dot = p;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (last_dot != uri)
|
||
|
{
|
||
|
GString *s = g_string_new (uri);
|
||
|
GFile *file;
|
||
|
gchar *basename;
|
||
|
|
||
|
if (last_dot)
|
||
|
g_string_truncate (s, last_dot - uri);
|
||
|
|
||
|
g_string_append (s, ".");
|
||
|
g_string_append (s, (gchar *) proc->extensions_list->data);
|
||
|
|
||
|
file = g_file_new_for_uri (s->str);
|
||
|
g_string_free (s, TRUE);
|
||
|
|
||
|
gtk_file_chooser_set_file (chooser, file, NULL);
|
||
|
|
||
|
basename = g_path_get_basename (pika_file_get_utf8_name (file));
|
||
|
gtk_file_chooser_set_current_name (chooser, basename);
|
||
|
g_free (basename);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
g_free (uri);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_help_func (const gchar *help_id,
|
||
|
gpointer help_data)
|
||
|
{
|
||
|
PikaFileDialog *dialog = PIKA_FILE_DIALOG (help_data);
|
||
|
GtkWidget *focus;
|
||
|
|
||
|
focus = gtk_window_get_focus (GTK_WINDOW (dialog));
|
||
|
|
||
|
if (focus == dialog->proc_view)
|
||
|
{
|
||
|
gchar *proc_help_id;
|
||
|
|
||
|
proc_help_id =
|
||
|
pika_file_proc_view_get_help_id (PIKA_FILE_PROC_VIEW (dialog->proc_view));
|
||
|
|
||
|
pika_standard_help_func (proc_help_id, NULL);
|
||
|
|
||
|
g_free (proc_help_id);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
pika_standard_help_func (help_id, NULL);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static PikaFileDialogState *
|
||
|
pika_file_dialog_get_state (PikaFileDialog *dialog)
|
||
|
{
|
||
|
PikaFileDialogState *state;
|
||
|
GtkFileFilter *filter;
|
||
|
|
||
|
g_return_val_if_fail (PIKA_IS_FILE_DIALOG (dialog), NULL);
|
||
|
|
||
|
state = g_slice_new0 (PikaFileDialogState);
|
||
|
|
||
|
filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
|
||
|
|
||
|
if (filter)
|
||
|
state->filter_name = g_strdup (gtk_file_filter_get_name (filter));
|
||
|
|
||
|
return state;
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_set_state (PikaFileDialog *dialog,
|
||
|
PikaFileDialogState *state)
|
||
|
{
|
||
|
g_return_if_fail (PIKA_IS_FILE_DIALOG (dialog));
|
||
|
g_return_if_fail (state != NULL);
|
||
|
|
||
|
if (state->filter_name)
|
||
|
{
|
||
|
GSList *filters;
|
||
|
GSList *list;
|
||
|
|
||
|
filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (dialog));
|
||
|
|
||
|
for (list = filters; list; list = list->next)
|
||
|
{
|
||
|
GtkFileFilter *filter = GTK_FILE_FILTER (list->data);
|
||
|
const gchar *name = gtk_file_filter_get_name (filter);
|
||
|
|
||
|
if (name && strcmp (state->filter_name, name) == 0)
|
||
|
{
|
||
|
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
g_slist_free (filters);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
pika_file_dialog_state_destroy (PikaFileDialogState *state)
|
||
|
{
|
||
|
g_return_if_fail (state != NULL);
|
||
|
|
||
|
g_free (state->filter_name);
|
||
|
g_slice_free (PikaFileDialogState, state);
|
||
|
}
|