[nautilus-actions] NAIOptionsList and NAIOption interfaces are up and running
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] NAIOptionsList and NAIOption interfaces are up and running
- Date: Sun, 1 Jan 2012 16:33:28 +0000 (UTC)
commit 03ced3501b34a86084f11583351c3cbecb0988e9
Author: Pierre Wieser <pwieser trychlos org>
Date: Thu Dec 29 17:23:18 2011 +0100
NAIOptionsList and NAIOption interfaces are up and running
ChangeLog | 2 +-
src/core/na-export-format.c | 240 ++++++++------
src/core/na-export-format.h | 8 +-
src/core/na-exporter.c | 4 +
src/core/na-ioption.c | 46 +++-
src/core/na-ioption.h | 25 +-
src/core/na-ioptions-list.c | 597 +++++++++++++++++++++--------------
src/core/na-ioptions-list.h | 42 ++-
src/io-desktop/nadp-formats.c | 27 ++
src/io-xml/naxml-formats.c | 31 ++-
src/nact/Makefile.am | 1 +
src/nact/base-assistant.c | 1 -
src/nact/base-builder.c | 24 ++-
src/nact/base-window.c | 2 +-
src/nact/nact-assistant-export.c | 259 +++++++++-------
src/nact/nact-export-ask.c | 79 ++++-
src/nact/nact-export-format.c | 608 +++---------------------------------
src/nact/nact-export-format.h | 53 +---
src/nact/nact-preferences-editor.c | 182 ++++++++----
src/utils/nautilus-actions-print.c | 3 +-
20 files changed, 1056 insertions(+), 1178 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e7e20ac..5590acf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -28,7 +28,7 @@
XML export formats.
* src/io-xml/Makefile.am: Updated accordingly.
-
+
* src/core/na-import-mode.c:
* src/core/na-import-mode.h:
* src/core/na-ioption.c:
diff --git a/src/core/na-export-format.c b/src/core/na-export-format.c
index 08c5d2c..c37352f 100644
--- a/src/core/na-export-format.c
+++ b/src/core/na-export-format.c
@@ -33,6 +33,7 @@
#endif
#include "na-export-format.h"
+#include "na-ioption.h"
/* private class data
*/
@@ -54,11 +55,16 @@ struct _NAExportFormatPrivate {
static GObjectClass *st_parent_class = NULL;
-static GType register_type( void );
-static void class_init( NAExportFormatClass *klass );
-static void instance_init( GTypeInstance *instance, gpointer klass );
-static void instance_dispose( GObject *object );
-static void instance_finalize( GObject *object );
+static GType register_type( void );
+static void class_init( NAExportFormatClass *klass );
+static void ioption_iface_init( NAIOptionInterface *iface );
+static void instance_init( GTypeInstance *instance, gpointer klass );
+static void instance_dispose( GObject *object );
+static void instance_finalize( GObject *object );
+static gchar *ioption_get_id( const NAIOption *option );
+static gchar *ioption_get_label( const NAIOption *option );
+static gchar *ioption_get_description( const NAIOption *option );
+static GdkPixbuf *ioption_get_pixbuf( const NAIOption *option );
GType
na_export_format_get_type( void )
@@ -90,10 +96,18 @@ register_type( void )
( GInstanceInitFunc ) instance_init
};
+ static const GInterfaceInfo ioption_iface_info = {
+ ( GInterfaceInitFunc ) ioption_iface_init,
+ NULL,
+ NULL
+ };
+
g_debug( "%s", thisfn );
type = g_type_register_static( G_TYPE_OBJECT, "NAExportFormat", &info, 0 );
+ g_type_add_interface_static( type, NA_IOPTION_TYPE, &ioption_iface_info );
+
return( type );
}
@@ -115,6 +129,119 @@ class_init( NAExportFormatClass *klass )
}
static void
+ioption_iface_init( NAIOptionInterface *iface )
+{
+ static const gchar *thisfn = "na_export_format_ioption_iface_init";
+
+ g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
+
+ iface->get_id = ioption_get_id;
+ iface->get_label = ioption_get_label;
+ iface->get_description = ioption_get_description;
+ iface->get_pixbuf = ioption_get_pixbuf;
+}
+
+/*
+ * ioption_get_id:
+ * @option: this #NAIOption instance.
+ *
+ * Returns: the ASCII id of the @option, as a newly allocated string which
+ * should be g_free() by the caller.
+ */
+static gchar *
+ioption_get_id( const NAIOption *option )
+{
+ gchar *id;
+ NAExportFormat *format;
+
+ g_return_val_if_fail( NA_IS_EXPORT_FORMAT( option ), NULL );
+ format = NA_EXPORT_FORMAT( option );
+ id = NULL;
+
+ if( !format->private->dispose_has_run ){
+
+ id = g_strdup( format->private->format );
+ }
+
+ return( id );
+}
+
+/*
+ * ioption_get_label:
+ * @option: this #NAIOption instance.
+ *
+ * Returns: the label associated to @option, as a newly allocated string
+ * which should be g_free() by the caller.
+ */
+static gchar *
+ioption_get_label( const NAIOption *option )
+{
+ gchar *label;
+ NAExportFormat *format;
+
+ g_return_val_if_fail( NA_IS_EXPORT_FORMAT( option ), NULL );
+ format = NA_EXPORT_FORMAT( option );
+ label = NULL;
+
+ if( !format->private->dispose_has_run ){
+
+ label = g_strdup( format->private->label );
+ }
+
+ return( label );
+}
+
+/*
+ * ioption_get_description:
+ * @option: this #NAIOption instance.
+ *
+ * Returns: the description associated to @option, as a newly allocated string
+ * which should be g_free() by the caller.
+ */
+static gchar *
+ioption_get_description( const NAIOption *option )
+{
+ gchar *description;
+ NAExportFormat *format;
+
+ g_return_val_if_fail( NA_IS_EXPORT_FORMAT( option ), NULL );
+ format = NA_EXPORT_FORMAT( option );
+ description = NULL;
+
+ if( !format->private->dispose_has_run ){
+
+ description = g_strdup( format->private->description );
+ }
+
+ return( description );
+}
+
+/*
+ * ioption_get_pixbuf:
+ * @option: this #NAIOption instance.
+ *
+ * Returns: a new reference to the pixbuf associated to @option;
+ * which should later be g_object_unref() by the caller.
+ */
+static GdkPixbuf *
+ioption_get_pixbuf( const NAIOption *option )
+{
+ GdkPixbuf *pixbuf;
+ NAExportFormat *format;
+
+ g_return_val_if_fail( NA_IS_EXPORT_FORMAT( option ), NULL );
+ format = NA_EXPORT_FORMAT( option );
+ pixbuf = NULL;
+
+ if( !format->private->dispose_has_run ){
+
+ pixbuf = format->private->pixbuf ? g_object_ref( format->private->pixbuf ) : NULL;
+ }
+
+ return( pixbuf );
+}
+
+static void
instance_init( GTypeInstance *instance, gpointer klass )
{
static const gchar *thisfn = "na_export_format_instance_init";
@@ -148,6 +275,11 @@ instance_dispose( GObject *object )
self->private->dispose_has_run = TRUE;
if( self->private->pixbuf ){
+ g_debug( "%s: pixbuf=%p (%s) ref_count=%d",
+ thisfn,
+ ( void * ) self->private->pixbuf,
+ G_OBJECT_TYPE_NAME( self->private->pixbuf ),
+ G_OBJECT( self->private->pixbuf )->ref_count );
g_object_unref( self->private->pixbuf );
self->private->pixbuf = NULL;
}
@@ -228,78 +360,6 @@ na_export_format_get_quark( const NAExportFormat *format )
}
/*
- * na_export_format_get_id:
- * @format: this #NAExportFormat object.
- *
- * Returns: the ASCII id of the format, as a newly allocated string which
- * should be g_free() by the caller.
- */
-gchar *
-na_export_format_get_id( const NAExportFormat *format )
-{
- gchar *id;
-
- g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), NULL );
-
- id = NULL;
-
- if( !format->private->dispose_has_run ){
-
- id = g_strdup( format->private->format );
- }
-
- return( id );
-}
-
-/*
- * na_export_format_get_label:
- * @format: this #NAExportFormat object.
- *
- * Returns: the UTF-8 localizable label of the format, as a newly
- * allocated string which should be g_free() by the caller.
- */
-gchar *
-na_export_format_get_label( const NAExportFormat *format )
-{
- gchar *label;
-
- g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), NULL );
-
- label = NULL;
-
- if( !format->private->dispose_has_run ){
-
- label = g_strdup( format->private->label );
- }
-
- return( label );
-}
-
-/*
- * na_export_format_get_description:
- * @format: this #NAExportFormat object.
- *
- * Returns: the UTF-8 localizable description of the format, as a newly
- * allocated string which should be g_free() by the caller.
- */
-gchar *
-na_export_format_get_description( const NAExportFormat *format )
-{
- gchar *description;
-
- g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), NULL );
-
- description = NULL;
-
- if( !format->private->dispose_has_run ){
-
- description = g_strdup( format->private->description );
- }
-
- return( description );
-}
-
-/*
* na_export_format_get_provider:
* @format: this #NAExportFormat object.
*
@@ -324,29 +384,3 @@ na_export_format_get_provider( const NAExportFormat *format )
return( exporter );
}
-
-/*
- * na_export_format_get_pixbuf:
- * @format: this #NAExportFormat object.
- *
- * Returns: a new reference to the #GdkPixbuf image associated with this format,
- * or %NULL.
- */
-GdkPixbuf *
-na_export_format_get_pixbuf( const NAExportFormat *format )
-{
- GdkPixbuf *pixbuf;
-
- g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), NULL );
-
- pixbuf = NULL;
-
- if( !format->private->dispose_has_run ){
-
- if( format->private->pixbuf ){
- pixbuf = g_object_ref( format->private->pixbuf );
- }
- }
-
- return( pixbuf );
-}
diff --git a/src/core/na-export-format.h b/src/core/na-export-format.h
index 17ba878..0b46357 100644
--- a/src/core/na-export-format.h
+++ b/src/core/na-export-format.h
@@ -71,12 +71,8 @@ GType na_export_format_get_type( void );
NAExportFormat *na_export_format_new( const NAIExporterFormatExt *exporter_format );
-GQuark na_export_format_get_quark ( const NAExportFormat *format );
-gchar *na_export_format_get_id ( const NAExportFormat *format );
-gchar *na_export_format_get_label ( const NAExportFormat *format );
-gchar *na_export_format_get_description( const NAExportFormat *format );
-NAIExporter *na_export_format_get_provider ( const NAExportFormat *format );
-GdkPixbuf *na_export_format_get_pixbuf ( const NAExportFormat *format );
+GQuark na_export_format_get_quark ( const NAExportFormat *format );
+NAIExporter *na_export_format_get_provider( const NAExportFormat *format );
G_END_DECLS
diff --git a/src/core/na-exporter.c b/src/core/na-exporter.c
index cb2f6e4..569d9bc 100644
--- a/src/core/na-exporter.c
+++ b/src/core/na-exporter.c
@@ -98,6 +98,10 @@ na_exporter_get_formats( const NAPivot *pivot )
void
na_exporter_free_formats( GList *formats )
{
+ static const gchar *thisfn = "na_exporter_free_formats";
+
+ g_debug( "%s: formats=%p (count=%d)", thisfn, ( void * ) formats, g_list_length( formats ));
+
g_list_foreach( formats, ( GFunc ) g_object_unref, NULL );
g_list_free( formats );
}
diff --git a/src/core/na-ioption.c b/src/core/na-ioption.c
index 6857d48..cbe3d97 100644
--- a/src/core/na-ioption.c
+++ b/src/core/na-ioption.c
@@ -194,27 +194,27 @@ option_set_initialized( NAIOption *instance, gboolean initialized )
}
/*
- * na_ioption_get_description:
- * @format: this #NAExportFormat object.
+ * na_ioption_get_id:
+ * @option: this #NAIOption instance.
*
- * Returns: the UTF-8 localizable description of the format, as a newly
+ * Returns: the string identifier of the format, as a newly
* allocated string which should be g_free() by the caller.
*/
gchar *
-na_ioption_get_description( const NAIOption *option )
+na_ioption_get_id( const NAIOption *option )
{
- gchar *description;
+ gchar *id;
g_return_val_if_fail( NA_IS_IOPTION( option ), NULL );
check_for_initialized_instance( NA_IOPTION( option ));
- description = NULL;
+ id = NULL;
- if( NA_IOPTION_GET_INTERFACE( option )->get_description ){
- description = NA_IOPTION_GET_INTERFACE( option )->get_description( option );
+ if( NA_IOPTION_GET_INTERFACE( option )->get_id ){
+ id = NA_IOPTION_GET_INTERFACE( option )->get_id( option );
}
- return( description );
+ return( id );
}
/*
@@ -242,6 +242,30 @@ na_ioption_get_label( const NAIOption *option )
}
/*
+ * na_ioption_get_description:
+ * @format: this #NAExportFormat object.
+ *
+ * Returns: the UTF-8 localizable description of the format, as a newly
+ * allocated string which should be g_free() by the caller.
+ */
+gchar *
+na_ioption_get_description( const NAIOption *option )
+{
+ gchar *description;
+
+ g_return_val_if_fail( NA_IS_IOPTION( option ), NULL );
+
+ check_for_initialized_instance( NA_IOPTION( option ));
+ description = NULL;
+
+ if( NA_IOPTION_GET_INTERFACE( option )->get_description ){
+ description = NA_IOPTION_GET_INTERFACE( option )->get_description( option );
+ }
+
+ return( description );
+}
+
+/*
* na_ioption_get_pixbuf:
* @option: this #NAIOption instance.
*
@@ -265,6 +289,7 @@ na_ioption_get_pixbuf( const NAIOption *option )
return( pixbuf );
}
+#if 0
/*
* na_ioption_free_option:
* @option: this #NAIOption instance.
@@ -275,4 +300,7 @@ void
na_ioption_free_option( NAIOption *option )
{
g_return_if_fail( NA_IS_IOPTION( option ));
+
+ g_object_unref( option );
}
+#endif
diff --git a/src/core/na-ioption.h b/src/core/na-ioption.h
index dece761..16b4330 100644
--- a/src/core/na-ioption.h
+++ b/src/core/na-ioption.h
@@ -85,8 +85,9 @@ typedef struct _NAIOptionManageImportModeParms NAIOptionManageImportModeParms;
* NAIOptionInterface:
* @get_version: returns the version of this interface that the
* instance implements.
- * @get_description: returns the description of the option.
+ * @get_id: returns the string identifier of the option.
* @get_label: returns the label of the option.
+ * @get_description: returns the description of the option.
* @get_pixbuf: returns the image associated to the option.
*
* This defines the interface that a #NAIOption implementation should provide.
@@ -115,15 +116,15 @@ typedef struct {
guint ( *get_version ) ( const NAIOption *instance );
/*
- * get_description:
+ * get_id:
* @instance: the #NAIOption instance of the implementation.
*
- * Returns: the description of the option, as a newly allocated string
+ * Returns: the string identifier of the option, as a newly allocated string
* which should be g_free() by the caller.
*
* Since: 3.2
*/
- gchar * ( *get_description )( const NAIOption *instance );
+ gchar * ( *get_id ) ( const NAIOption *instance );
/*
* get_label:
@@ -137,6 +138,17 @@ typedef struct {
gchar * ( *get_label ) ( const NAIOption *instance );
/*
+ * get_description:
+ * @instance: the #NAIOption instance of the implementation.
+ *
+ * Returns: the description of the option, as a newly allocated string
+ * which should be g_free() by the caller.
+ *
+ * Since: 3.2
+ */
+ gchar * ( *get_description )( const NAIOption *instance );
+
+ /*
* get_pixbuf:
* @instance: the #NAIOption instance of the implementation.
*
@@ -153,12 +165,11 @@ typedef struct {
GType na_ioption_get_type( void );
-gchar *na_ioption_get_description( const NAIOption *option );
+gchar *na_ioption_get_id ( const NAIOption *option );
gchar *na_ioption_get_label ( const NAIOption *option );
+gchar *na_ioption_get_description( const NAIOption *option );
GdkPixbuf *na_ioption_get_pixbuf ( const NAIOption *option );
-void na_ioption_free_option ( NAIOption *option );
-
G_END_DECLS
#endif /* __CORE_NA_IOPTION_H__ */
diff --git a/src/core/na-ioptions-list.c b/src/core/na-ioptions-list.c
index 186dde8..61244a2 100644
--- a/src/core/na-ioptions-list.c
+++ b/src/core/na-ioptions-list.c
@@ -32,6 +32,8 @@
#include <config.h>
#endif
+#include <string.h>
+
#include <api/na-core-utils.h>
#include "na-gtk-utils.h"
@@ -53,52 +55,53 @@ enum {
N_COLUMN
};
-#define IOPTIONS_LIST_DATA_CONTAINER "ioptions-list-data-container"
+/* data associated to the container of the instance
+ */
#define IOPTIONS_LIST_DATA_EDITABLE "ioptions-list-data-editable"
#define IOPTIONS_LIST_DATA_INITIALIZED "ioptions-list-data-initialized"
#define IOPTIONS_LIST_DATA_OPTION "ioptions-list-data-option"
-#define IOPTIONS_LIST_DATA_PARENT "ioptions-list-data-parent"
+#define IOPTIONS_LIST_DATA_OPTION_ID "ioptions-list-data-option-id"
#define IOPTIONS_LIST_DATA_SENSITIVE "ioptions-list-data-sensitive"
-#define IOPTIONS_LIST_DATA_WITH_ASK "ioptions-list-data-with-ask"
static gboolean st_ioptions_list_iface_initialized = FALSE;
static gboolean st_ioptions_list_iface_finalized = FALSE;
-static GType register_type( void );
-static void interface_base_init( NAIOptionsListInterface *iface );
-static void interface_base_finalize( NAIOptionsListInterface *iface );
-static guint ioptions_list_get_version( const NAIOptionsList *instance );
-static void ioptions_list_free_options( const NAIOptionsList *instance, GList *options );
-static void ioptions_list_free_ask_option( const NAIOptionsList *instance, NAIOption *option );
-static GList *options_list_get_options( const NAIOptionsList *instance );
-static void options_list_free_options( const NAIOptionsList *instance, GList *options );
-static NAIOption *options_list_get_ask_option( const NAIOptionsList *instance );
-static void options_list_free_ask_option( const NAIOptionsList *instance, NAIOption *ask_option );
-static NAIOption *options_list_get_container_option( GtkWidget *container );
-static void options_list_set_container_option( GtkWidget *container, const NAIOption *option );
-static GtkWidget *options_list_get_container_parent( NAIOptionsList *instance );
-static void options_list_set_container_parent( NAIOptionsList *instance, GtkWidget *parent );
-static gboolean options_list_get_editable( NAIOptionsList *instance );
-static void options_list_set_editable( NAIOptionsList *instance, gboolean editable );
-static gboolean options_list_get_initialized( NAIOptionsList *instance );
-static void options_list_set_initialized( NAIOptionsList *instance, gboolean initialized );
-static NAIOption *options_list_get_option( NAIOptionsList *instance );
-static void options_list_set_option( NAIOptionsList *instance, NAIOption *option );
-static gboolean options_list_get_sensitive( NAIOptionsList *instance );
-static void options_list_set_sensitive( NAIOptionsList *instance, gboolean sensitive );
-static gboolean options_list_get_with_ask( NAIOptionsList *instance );
-static void options_list_set_with_ask( NAIOptionsList *instance, gboolean with_ask );
-static void check_for_initialized_instance( NAIOptionsList *instance );
-static void on_instance_finalized( gpointer user_data, GObject *instance );
-static void radio_button_create_group( NAIOptionsList *instance );
-static void radio_button_draw_vbox( GtkWidget *container_parent, const NAIOption *option );
-static void radio_button_weak_notify( NAIOption *option, GObject *vbox );
-static void tree_view_create_model( NAIOptionsList *instance );
-static void tree_view_populate( NAIOptionsList *instance );
-static void tree_view_add_item( GtkTreeView *listview, GtkTreeModel *model, const NAIOption *option );
-static void tree_view_weak_notify( GtkTreeModel *model, GObject *tree_view );
-static void radio_button_select_iter( GtkWidget *container_option, NAIOptionsList *instance );
-static gboolean tree_view_select_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, NAIOptionsList *instance );
+static GType register_type( void );
+static void interface_base_init( NAIOptionsListInterface *iface );
+static void interface_base_finalize( NAIOptionsListInterface *iface );
+static guint ioptions_list_get_version( const NAIOptionsList *instance );
+static void ioptions_list_free_options( const NAIOptionsList *instance, GList *options );
+static void ioptions_list_free_ask_option( const NAIOptionsList *instance, NAIOption *option );
+static GList *options_list_get_options( const NAIOptionsList *instance, GtkWidget *container_parent );
+static void options_list_free_options( const NAIOptionsList *instance, GList *options );
+static NAIOption *options_list_get_ask_option( const NAIOptionsList *instance, GtkWidget *container_parent );
+static void options_list_free_ask_option( const NAIOptionsList *instance, NAIOption *ask_option );
+static gboolean get_options_list_editable( GtkWidget *container_parent );
+static void set_options_list_editable( GtkWidget *container_parent, gboolean editable );
+static gboolean get_options_list_container_initialized( GtkWidget *container_parent );
+static void set_options_list_container_initialized( GtkWidget *container_parent, gboolean initialized );
+static gboolean get_options_list_instance_initialized( const NAIOptionsList *instance );
+static void set_options_list_instance_initialized( const NAIOptionsList *instance, gboolean initialized );
+static NAIOption *get_options_list_option( GtkWidget *container );
+static void set_options_list_option( GtkWidget *container, NAIOption *option );
+static const gchar *get_options_list_option_id( GtkWidget *container );
+static void set_options_list_option_id( GtkWidget *container, const gchar *id );
+static gboolean get_options_list_sensitive( GtkWidget *container_parent );
+static void set_options_list_sensitive( GtkWidget *container_parent, gboolean sensitive );
+static void check_for_initializations( const NAIOptionsList *instance, GtkWidget *container_parent );
+static void on_parent_container_finalized( gpointer user_data, GObject *container );
+static void on_instance_finalized( gpointer user_data, GObject *instance );
+static void radio_button_create_group( const NAIOptionsList *instance, GtkWidget *container_parent, gboolean with_ask );
+static void radio_button_draw_vbox( GtkWidget *container_parent, const NAIOption *option );
+static void radio_button_weak_notify( NAIOption *option, GObject *vbox );
+static void tree_view_create_model( const NAIOptionsList *instance, GtkWidget *container_parent );
+static void tree_view_populate( const NAIOptionsList *instance, GtkWidget *container_parent, gboolean with_ask );
+static void tree_view_add_item( GtkTreeView *listview, GtkTreeModel *model, const NAIOption *option );
+static void tree_view_weak_notify( GtkTreeModel *model, GObject *tree_view );
+static void radio_button_select_iter( GtkWidget *container_option, GtkWidget *container_parent );
+static gboolean tree_view_select_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkWidget *container_parent );
+static void radio_button_get_selected_iter( GtkWidget *container_option, GtkWidget *container_parent );
+static void tree_view_get_selected( const NAIOptionsList *instance, GtkWidget *container_parent );
/**
* na_ioptions_list_get_type:
@@ -220,14 +223,14 @@ ioptions_list_free_ask_option( const NAIOptionsList *instance, NAIOption *ask_op
* or the default provided by the interface
*/
static GList *
-options_list_get_options( const NAIOptionsList *instance )
+options_list_get_options( const NAIOptionsList *instance, GtkWidget *container_parent )
{
GList *options;
options = NULL;
if( NA_IOPTIONS_LIST_GET_INTERFACE( instance )->get_options ){
- options = NA_IOPTIONS_LIST_GET_INTERFACE( instance )->get_options( instance );
+ options = NA_IOPTIONS_LIST_GET_INTERFACE( instance )->get_options( instance, container_parent );
}
return( options );
@@ -242,14 +245,14 @@ options_list_free_options( const NAIOptionsList *instance, GList *options )
}
static NAIOption *
-options_list_get_ask_option( const NAIOptionsList *instance )
+options_list_get_ask_option( const NAIOptionsList *instance, GtkWidget *container_parent )
{
NAIOption *option;
option = NULL;
if( NA_IOPTIONS_LIST_GET_INTERFACE( instance )->get_ask_option ){
- option = NA_IOPTIONS_LIST_GET_INTERFACE( instance )->get_ask_option( instance );
+ option = NA_IOPTIONS_LIST_GET_INTERFACE( instance )->get_ask_option( instance, container_parent );
}
return( option );
@@ -264,67 +267,50 @@ options_list_free_ask_option( const NAIOptionsList *instance, NAIOption *ask_opt
}
/*
- * get/set properties
- */
-/* the option associated to this 'option' container
+ * get/set pseudo-properties
+ * pseudo properties are set:
+ * - against the instance: whether it has been initialized
+ * - against the parent container: editable, sensitive, default and current options
+ * - against each option container when drawing inside of a VBox: the corresponding option
*/
-static NAIOption *
-options_list_get_container_option( GtkWidget *container )
-{
- NAIOption *option;
-
- option = ( NAIOption * ) g_object_get_data( G_OBJECT( container ), IOPTIONS_LIST_DATA_CONTAINER );
-
- return( option );
-}
-
-static void
-options_list_set_container_option( GtkWidget *container, const NAIOption *option )
-{
- g_object_set_data( G_OBJECT( container ), IOPTIONS_LIST_DATA_CONTAINER, ( gpointer ) option );
-}
-
-/* the global parent container, i.e. a GtkVBox or a GtkTreeView
- *
- * the container parent is provided when calling na_ioptions_list_display_init()
- * function; storing it as a data of the instance just let us to know it without
- * having to require it in subsequent function calls
+/* whether the selectable user's preference is editable
+ * most of the time, a user's preference is not editable if it is set as mandatory,
+ * or if the whole user's preference are not writable
*/
-static GtkWidget *
-options_list_get_container_parent( NAIOptionsList *instance )
+static gboolean
+get_options_list_editable( GtkWidget *container_parent )
{
- GtkWidget *parent;
+ gboolean editable;
- parent = ( GtkWidget * ) g_object_get_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_PARENT );
+ editable = ( gboolean ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( container_parent ), IOPTIONS_LIST_DATA_EDITABLE ));
- return( parent );
+ return( editable );
}
static void
-options_list_set_container_parent( NAIOptionsList *instance, GtkWidget *parent )
+set_options_list_editable( GtkWidget *container_parent, gboolean editable )
{
- g_object_set_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_PARENT, parent );
+ g_object_set_data( G_OBJECT( container_parent ), IOPTIONS_LIST_DATA_EDITABLE, GUINT_TO_POINTER( editable ));
}
-/* whether the selectable user's preference is editable
+/* whether the container has been initialized
*
- * most of the time, a user's preference is not editable if it is set as mandatory,
- * or if the whole user's preference are not writable
+ * initializing the container so that its pseudo-properties are valid
*/
static gboolean
-options_list_get_editable( NAIOptionsList *instance )
+get_options_list_container_initialized( GtkWidget *container_parent )
{
- gboolean editable;
+ gboolean initialized;
- editable = ( gboolean ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_EDITABLE ));
+ initialized = ( gboolean ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( container_parent ), IOPTIONS_LIST_DATA_INITIALIZED ));
- return( editable );
+ return( initialized );
}
static void
-options_list_set_editable( NAIOptionsList *instance, gboolean editable )
+set_options_list_container_initialized( GtkWidget *container_parent, gboolean initialized )
{
- g_object_set_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_EDITABLE, GUINT_TO_POINTER( editable ));
+ g_object_set_data( G_OBJECT( container_parent ), IOPTIONS_LIST_DATA_INITIALIZED, GUINT_TO_POINTER( initialized ));
}
/* whether the instance has been initialized
@@ -334,7 +320,7 @@ options_list_set_editable( NAIOptionsList *instance, gboolean editable )
* finalized
*/
static gboolean
-options_list_get_initialized( NAIOptionsList *instance )
+get_options_list_instance_initialized( const NAIOptionsList *instance )
{
gboolean initialized;
@@ -344,88 +330,114 @@ options_list_get_initialized( NAIOptionsList *instance )
}
static void
-options_list_set_initialized( NAIOptionsList *instance, gboolean initialized )
+set_options_list_instance_initialized( const NAIOptionsList *instance, gboolean initialized )
{
g_object_set_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_INITIALIZED, GUINT_TO_POINTER( initialized ));
}
-/* the current option
+/* the parent container: the current option
+ * the option container: the option attached to this container (VBox only)
*/
static NAIOption *
-options_list_get_option( NAIOptionsList *instance )
+get_options_list_option( GtkWidget *container )
{
- NAIOption *option;
-
- option = ( NAIOption * ) g_object_get_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_OPTION );
-
- return( option );
+ return(( NAIOption * ) g_object_get_data( G_OBJECT( container ), IOPTIONS_LIST_DATA_OPTION ));
}
static void
-options_list_set_option( NAIOptionsList *instance, NAIOption *option )
+set_options_list_option( GtkWidget *container, NAIOption *option )
{
- g_object_set_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_OPTION, option );
+ g_object_set_data( G_OBJECT( container ), IOPTIONS_LIST_DATA_OPTION, option );
}
-/* whether the selectable user's preference is sensitive
- *
- * an option should be made insensitive when it is not relevant in
- * the considered case
+/* the string identifier of the option (stored as a GQuark)
+ * it is set in two places:
+ * - at the option container level, in order to identify the option (gtk initialization)
+ * - at the parent container level, when setting the default option (display initialization)
*/
-static gboolean
-options_list_get_sensitive( NAIOptionsList *instance )
+static const gchar *
+get_options_list_option_id( GtkWidget *container )
{
- gboolean sensitive;
+ GQuark quark;
+ const gchar *id;
- sensitive = ( gboolean ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_SENSITIVE ));
+ quark = GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( container ), IOPTIONS_LIST_DATA_OPTION_ID ));
+ id = g_quark_to_string( quark );
- return( sensitive );
+ return( id );
}
static void
-options_list_set_sensitive( NAIOptionsList *instance, gboolean sensitive )
+set_options_list_option_id( GtkWidget *container, const gchar *id )
{
- g_object_set_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_SENSITIVE, GUINT_TO_POINTER( sensitive ));
+ g_object_set_data( G_OBJECT( container ), IOPTIONS_LIST_DATA_OPTION_ID, GUINT_TO_POINTER( g_quark_from_string( id )));
}
-/* whether the options list must include an 'Ask me' option
+/* whether the selectable user's preference is sensitive
+ *
+ * an option should be made insensitive when it is not relevant in
+ * the considered case
*/
static gboolean
-options_list_get_with_ask( NAIOptionsList *instance )
+get_options_list_sensitive( GtkWidget *container_parent )
{
- gboolean with_ask;
+ gboolean sensitive;
- with_ask = ( gboolean ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_WITH_ASK ));
+ sensitive = ( gboolean ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( container_parent ), IOPTIONS_LIST_DATA_SENSITIVE ));
- return( with_ask );
+ return( sensitive );
}
static void
-options_list_set_with_ask( NAIOptionsList *instance, gboolean with_ask )
+set_options_list_sensitive( GtkWidget *container_parent, gboolean sensitive )
{
- g_object_set_data( G_OBJECT( instance ), IOPTIONS_LIST_DATA_WITH_ASK, GUINT_TO_POINTER( with_ask ));
+ g_object_set_data( G_OBJECT( container_parent ), IOPTIONS_LIST_DATA_SENSITIVE, GUINT_TO_POINTER( sensitive ));
}
/*
- * na_ioptions_list_instance_init:
- * @instance: the object which implements this #NAIOptionsList interface.
+ * check_for_initializations:
+ * @instance: the interface implementation.
+ * @container: the #Gtkwidget which embeds our list of values.
+ *
+ * Setup both instance and container initialization levels.
*
- * Initialize all #NAIOptionsList-relative properties of the implementation
- * object at instanciation time.
+ * Having these levels explicitely initialized not only let us setup weak
+ * references on the objects, but also assert that pseudo-properties have
+ * valid values.
*/
static void
-check_for_initialized_instance( NAIOptionsList *instance )
+check_for_initializations( const NAIOptionsList *instance, GtkWidget *container_parent )
{
- static const gchar *thisfn = "na_ioptions_list_check_for_initialized_instance";
+ static const gchar *thisfn = "na_ioptions_list_check_for_initializations";
- if( !options_list_get_initialized( instance )){
+ if( !get_options_list_instance_initialized( instance )){
g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
g_object_weak_ref( G_OBJECT( instance ), ( GWeakNotify ) on_instance_finalized, NULL );
- options_list_set_initialized( instance, TRUE );
+ set_options_list_instance_initialized( instance, TRUE );
}
+
+ if( !get_options_list_container_initialized( container_parent )){
+
+ g_debug( "%s: container_parent=%p", thisfn, ( void * ) container_parent );
+
+ set_options_list_editable( container_parent, TRUE );
+ set_options_list_sensitive( container_parent, TRUE );
+
+ g_object_weak_ref( G_OBJECT( container_parent ), ( GWeakNotify ) on_parent_container_finalized, NULL );
+
+ set_options_list_container_initialized( container_parent, TRUE );
+ }
+}
+
+static void
+on_parent_container_finalized( gpointer user_data, GObject *container )
+{
+ static const gchar *thisfn = "na_ioptions_list_on_parent_container_finalized";
+
+ g_debug( "%s: user_data=%p, container=%p", thisfn, ( void * ) user_data, ( void * ) container );
}
static void
@@ -437,81 +449,64 @@ on_instance_finalized( gpointer user_data, GObject *instance )
}
/*
- * na_ioptions_list_display_init:
+ * na_ioptions_list_gtk_init:
* @instance: the object which implements this #NAIOptionsList interface.
- * @parent: the #GtkWidget container_parent is which we are goint to setup the items
- * list. @parent may be a #GtkVBox or a #GtkTreeView.
+ * @container_parent: the #GtkWidget parent container in which we are going to setup the
+ * list of values. @container_parent may be a #GtkVBox or a #GtkTreeView.
* @with_ask: whether we should also display an 'Ask me' option.
- * @editable: whether the selectable user's preference is editable;
- * Most of time, a user's preference is not editable if it is set as mandatory,
- * or if the whole user's preferences are not writable.
- * @sensitive: whether the radio button group is to be sensitive;
- * a widget should not be sensitive if the selectable option is not relevant
- * in the considered case.
*
* Initialize the gtk objects which will be used to display the selection.
*/
void
-na_ioptions_list_display_init( NAIOptionsList *instance,
- GtkWidget *parent, gboolean with_ask, gboolean editable, gboolean sensitive )
+na_ioptions_list_gtk_init( const NAIOptionsList *instance, GtkWidget *container_parent, gboolean with_ask )
{
- static const gchar *thisfn = "na_ioptions_list_display_init";
+ static const gchar *thisfn = "na_ioptions_list_gtk_init";
g_return_if_fail( st_ioptions_list_iface_initialized && !st_ioptions_list_iface_finalized );
+ check_for_initializations( instance, container_parent );
- check_for_initialized_instance( instance );
-
- g_debug( "%s: instance=%p (%s), parent=%p (%s), with_ask=%s, editable=%s, sensitive=%s",
+ g_debug( "%s: instance=%p (%s), container_parent=%p (%s), with_ask=%s",
thisfn,
( void * ) instance, G_OBJECT_TYPE_NAME( instance ),
- ( void * ) parent, G_OBJECT_TYPE_NAME( parent ),
- with_ask ? "True":"False",
- editable ? "True":"False",
- sensitive ? "True":"False" );
-
- options_list_set_container_parent( instance, parent );
- options_list_set_with_ask( instance, with_ask );
- options_list_set_editable( instance, editable );
- options_list_set_sensitive( instance, sensitive );
+ ( void * ) container_parent, G_OBJECT_TYPE_NAME( container_parent ),
+ with_ask ? "True":"False" );
- if( GTK_IS_BOX( parent )){
- radio_button_create_group( instance );
+ if( GTK_IS_BOX( container_parent )){
+ radio_button_create_group( instance, container_parent, with_ask );
- } else if( GTK_IS_TREE_VIEW( parent )){
- tree_view_create_model( instance );
- tree_view_populate( instance );
+ } else if( GTK_IS_TREE_VIEW( container_parent )){
+ tree_view_create_model( instance, container_parent );
+ tree_view_populate( instance, container_parent, with_ask );
} else {
- g_warning( "%s: unknown parent type: %s", thisfn, G_OBJECT_TYPE_NAME( parent ));
+ g_warning( "%s: unknown container_parent type: %s", thisfn, G_OBJECT_TYPE_NAME( container_parent ));
}
}
static void
-radio_button_create_group( NAIOptionsList *instance )
+radio_button_create_group( const NAIOptionsList *instance, GtkWidget *container_parent, gboolean with_ask )
{
- static const gchar *thisfn = "na_ioptions_list_create_radio_button_group";
+ static const gchar *thisfn = "na_ioptions_list_radio_button_create_group";
GList *options, *iopt;
NAIOption *option;
- GtkWidget *parent;
g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
- parent = options_list_get_container_parent( instance );
- options = options_list_get_options( instance );
+ options = options_list_get_options( instance, container_parent );
/* draw the formats as a group of radio buttons
*/
for( iopt = options ; iopt ; iopt = iopt->next ){
- radio_button_draw_vbox( parent, NA_IOPTION( iopt->data ));
+ radio_button_draw_vbox( container_parent, NA_IOPTION( iopt->data ));
}
options_list_free_options( instance, options );
/* eventually add the 'Ask me' mode
*/
- if( options_list_get_with_ask( instance )){
- option = options_list_get_ask_option( instance );
- radio_button_draw_vbox( parent, option );
+ if( with_ask ){
+ option = options_list_get_ask_option( instance, container_parent );
+ radio_button_draw_vbox( container_parent, option );
options_list_free_ask_option( instance, option );
}
}
@@ -557,12 +552,14 @@ radio_button_draw_vbox( GtkWidget *container_parent, const NAIOption *option )
g_free( description );
/* first line/child is the radio button
+ * first button of the group does not have the property set
*/
button = GTK_RADIO_BUTTON( gtk_radio_button_new( NULL ));
- if( !first_button ){
+ if( first_button ){
+ g_object_set( G_OBJECT( button ), "group", first_button, NULL );
+ } else {
first_button = button;
}
- g_object_set( G_OBJECT( button ), "group", first_button, NULL );
#if GTK_CHECK_VERSION( 3, 2, 0 )
gtk_grid_attach( GTK_GRID( container_option ), GTK_WIDGET( button ), 0, 0, 1, 1 );
@@ -575,53 +572,37 @@ radio_button_draw_vbox( GtkWidget *container_parent, const NAIOption *option )
g_free( label );
gtk_button_set_use_underline( GTK_BUTTON( button ), TRUE );
-#if 0
- vbox_data = g_new0( VBoxData, 1 );
- g_debug( "%s: container_option=%p, allocating VBoxData at %p",
- thisfn, ( void * ) container_option, ( void * ) vbox_data );
-
- vbox_data->container_parent_vbox = container_parent;
- vbox_data->button = button;
- vbox_data->format = g_object_ref(( gpointer ) format );
-
- g_object_set_data( G_OBJECT( container_option ), EXPORT_FORMAT_PROP_VBOX_DATA, vbox_data );
- g_object_weak_ref( G_OBJECT( container_option ), ( GWeakNotify ) format_weak_notify, ( gpointer ) vbox_data );
-#endif
-
- options_list_set_container_option( container_option, option );
+ set_options_list_option( container_option, g_object_ref(( gpointer ) option ));
g_object_weak_ref( G_OBJECT( container_option ), ( GWeakNotify ) radio_button_weak_notify, ( gpointer ) option );
}
/*
- * release the data structure attached to each individual 'option' container
+ * release the resources attached to each individual 'option' container
* when destroying the window
*/
static void
radio_button_weak_notify( NAIOption *option, GObject *vbox )
{
- static const gchar *thisfn = "na_iptions_list_radio_button_weak_notify";
+ static const gchar *thisfn = "na_ioptions_list_radio_button_weak_notify";
g_debug( "%s: option=%p, vbox=%p", thisfn, ( void * ) option, ( void * ) vbox );
- na_ioption_free_option( option );
+ g_object_unref( option );
}
static void
-tree_view_create_model( NAIOptionsList *instance )
+tree_view_create_model( const NAIOptionsList *instance, GtkWidget *container_parent )
{
static const gchar *thisfn = "na_ioptions_list_tree_view_create_model";
- GtkWidget *parent;
GtkListStore *model;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
- parent = options_list_get_container_parent( instance );
- g_return_if_fail( GTK_IS_TREE_VIEW( parent ));
-
- g_debug( "%s: instance=%p, parent=%p", thisfn, ( void * ) instance, ( void * ) parent );
+ g_return_if_fail( GTK_IS_TREE_VIEW( container_parent ));
+ g_debug( "%s: instance=%p, container_parent=%p", thisfn, ( void * ) instance, ( void * ) container_parent );
model = gtk_list_store_new( N_COLUMN, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_OBJECT );
- gtk_tree_view_set_model( GTK_TREE_VIEW( parent ), GTK_TREE_MODEL( model ));
+ gtk_tree_view_set_model( GTK_TREE_VIEW( container_parent ), GTK_TREE_MODEL( model ));
g_object_unref( model );
/* create visible columns on the tree view
@@ -631,50 +612,47 @@ tree_view_create_model( NAIOptionsList *instance )
gtk_cell_renderer_pixbuf_new(),
"pixbuf", IMAGE_COLUMN,
NULL );
- gtk_tree_view_append_column( GTK_TREE_VIEW( parent ), column );
+ gtk_tree_view_append_column( GTK_TREE_VIEW( container_parent ), column );
column = gtk_tree_view_column_new_with_attributes(
"label",
gtk_cell_renderer_text_new(),
"text", LABEL_COLUMN,
NULL );
- gtk_tree_view_append_column( GTK_TREE_VIEW( parent ), column );
+ gtk_tree_view_append_column( GTK_TREE_VIEW( container_parent ), column );
- g_object_set( G_OBJECT( parent ), "tooltip-column", TOOLTIP_COLUMN, NULL );
+ g_object_set( G_OBJECT( container_parent ), "tooltip-column", TOOLTIP_COLUMN, NULL );
- selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( parent ));
+ selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( container_parent ));
gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
- g_object_weak_ref( G_OBJECT( parent ), ( GWeakNotify ) tree_view_weak_notify, ( gpointer ) model );
+ g_object_weak_ref( G_OBJECT( container_parent ), ( GWeakNotify ) tree_view_weak_notify, ( gpointer ) model );
}
static void
-tree_view_populate( NAIOptionsList *instance )
+tree_view_populate( const NAIOptionsList *instance, GtkWidget *container_parent, gboolean with_ask )
{
static const gchar *thisfn = "nact_export_format_tree_view_populate";
- GtkWidget *parent;
GtkTreeModel *model;
NAIOption *option;
GList *options, *iopt;
- parent = options_list_get_container_parent( instance );
- g_return_if_fail( GTK_IS_TREE_VIEW( parent ));
+ g_return_if_fail( GTK_IS_TREE_VIEW( container_parent ));
+ g_debug( "%s: instance=%p, container_parent=%p", thisfn, ( void * ) instance, ( void * ) container_parent );
- g_debug( "%s: instance=%p, parent=%p", thisfn, ( void * ) instance, ( void * ) parent );
-
- model = gtk_tree_view_get_model( GTK_TREE_VIEW( parent ));
- options = options_list_get_options( instance );
+ model = gtk_tree_view_get_model( GTK_TREE_VIEW( container_parent ));
+ options = options_list_get_options( instance, container_parent );
for( iopt = options ; iopt ; iopt = iopt->next ){
option = NA_IOPTION( iopt->data );
- tree_view_add_item( GTK_TREE_VIEW( parent ), model, option );
+ tree_view_add_item( GTK_TREE_VIEW( container_parent ), model, option );
}
/* eventually add the 'Ask me' mode
*/
- if( options_list_get_with_ask( instance )){
- option = options_list_get_ask_option( instance );
- tree_view_add_item( GTK_TREE_VIEW( parent ), model, option );
+ if( with_ask ){
+ option = options_list_get_ask_option( instance, container_parent );
+ tree_view_add_item( GTK_TREE_VIEW( container_parent ), model, option );
options_list_free_ask_option( instance, option );
}
}
@@ -717,46 +695,49 @@ tree_view_weak_notify( GtkTreeModel *model, GObject *tree_view )
static const gchar *thisfn = "na_iptions_list_tree_view_weak_notify";
g_debug( "%s: model=%p, tree_view=%p", thisfn, ( void * ) model, ( void * ) tree_view );
-
- gtk_list_store_clear( GTK_LIST_STORE( model ));
}
/*
* na_ioptions_list_set_default:
* @instance: the object which implements this #NAIOptionsList interface.
- * @default_option: the #NAIOption to be set as the default.
+ * @container_parent: the #GtkWidget which embeds our list of values.
+ * @default_id: the string identifier of the #NAIOption to be set as the default.
*
* Set the default, either of the radio button group or of the tree view.
*/
void
-na_ioptions_list_set_default( NAIOptionsList *instance, NAIOption *default_option )
+na_ioptions_list_set_default(
+ const NAIOptionsList *instance, GtkWidget *container_parent, const gchar *default_id )
{
static const gchar *thisfn = "na_ioptions_list_set_default";
- GtkWidget *parent;
GtkTreeModel *model;
- if( st_ioptions_list_iface_initialized && !st_ioptions_list_iface_finalized ){
- g_debug( "%s: instance=%p (%s), default_option=%p (%s)",
- thisfn,
- ( void * ) instance, G_OBJECT_TYPE_NAME( instance ),
- ( void * ) default_option, G_OBJECT_TYPE_NAME( default_option ));
+ g_return_if_fail( st_ioptions_list_iface_initialized && !st_ioptions_list_iface_finalized );
+ check_for_initializations( instance, container_parent );
- parent = options_list_get_container_parent( instance );
- g_return_if_fail( GTK_IS_WIDGET( parent ));
+ g_debug( "%s: instance=%p (%s), container_parent=%p (%s), default_id=%s",
+ thisfn,
+ ( void * ) instance, G_OBJECT_TYPE_NAME( instance ),
+ ( void * ) container_parent, G_OBJECT_TYPE_NAME( container_parent ),
+ default_id );
- options_list_set_option( instance, default_option );
+ set_options_list_option_id( container_parent, default_id );
- if( GTK_IS_BOX( parent )){
- gtk_container_foreach( GTK_CONTAINER( parent ),
- ( GtkCallback ) radio_button_select_iter, instance );
+ if( GTK_IS_BOX( container_parent )){
+ gtk_container_foreach(
+ GTK_CONTAINER( container_parent ),
+ ( GtkCallback ) radio_button_select_iter,
+ container_parent );
- } else if( GTK_IS_TREE_VIEW( parent )){
- model = gtk_tree_view_get_model( GTK_TREE_VIEW( parent ));
- gtk_tree_model_foreach( model, ( GtkTreeModelForeachFunc ) tree_view_select_iter, instance );
+ } else if( GTK_IS_TREE_VIEW( container_parent )){
+ model = gtk_tree_view_get_model( GTK_TREE_VIEW( container_parent ));
+ gtk_tree_model_foreach(
+ model,
+ ( GtkTreeModelForeachFunc ) tree_view_select_iter,
+ container_parent );
- } else {
- g_warning( "%s: unknown parent type: %s", thisfn, G_OBJECT_TYPE_NAME( parent ));
- }
+ } else {
+ g_warning( "%s: unknown container_parent type: %s", thisfn, G_OBJECT_TYPE_NAME( container_parent ));
}
}
@@ -768,51 +749,193 @@ na_ioptions_list_set_default( NAIOptionsList *instance, NAIOption *default_optio
* - activating the button which holds our default value
*/
static void
-radio_button_select_iter( GtkWidget *container_option, NAIOptionsList *instance )
+radio_button_select_iter( GtkWidget *container_option, GtkWidget *container_parent )
{
+ const gchar *default_id;
NAIOption *option;
- NAIOption *default_option;
GtkWidget *button;
gboolean editable, sensitive;
+ gchar *option_id;
button = NULL;
- default_option = options_list_get_option( instance );
- option = options_list_get_container_option( container_option );
+ default_id = get_options_list_option_id( container_parent );
+ option = get_options_list_option( container_option );
+ option_id = na_ioption_get_id( option );
- if( option == default_option ){
+ if( !strcmp( default_id, option_id )){
button = na_gtk_utils_find_widget_by_type( GTK_CONTAINER( container_option ), GTK_TYPE_RADIO_BUTTON );
g_return_if_fail( GTK_IS_RADIO_BUTTON( button ));
- editable = options_list_get_editable( instance );
- sensitive = options_list_get_sensitive( instance );
- na_gtk_utils_radio_set_initial_state( GTK_RADIO_BUTTON( button ),
- NULL, NULL, editable, sensitive );
+ editable = get_options_list_editable( container_parent );
+ sensitive = get_options_list_sensitive( container_parent );
+ na_gtk_utils_radio_set_initial_state( GTK_RADIO_BUTTON( button ), NULL, NULL, editable, sensitive );
}
+
+ g_free( option_id );
}
/*
* walks through the rows of the liststore until the function returns %TRUE
*/
static gboolean
-tree_view_select_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, NAIOptionsList *instance )
+tree_view_select_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkWidget *container_parent )
{
gboolean stop;
GtkTreeView *tree_view;
- NAIOption *default_option, *option;
+ NAIOption *option;
+ const gchar *default_id;
+ gchar *option_id;
GtkTreeSelection *selection;
stop = FALSE;
- tree_view = ( GtkTreeView * ) options_list_get_container_parent( instance );
+ tree_view = ( GtkTreeView * ) container_parent;
g_return_val_if_fail( GTK_IS_TREE_VIEW( tree_view ), TRUE );
- default_option = options_list_get_option( instance );
+ default_id = get_options_list_option_id( container_parent );
gtk_tree_model_get( model, iter, OBJECT_COLUMN, &option, -1 );
g_object_unref( option );
+ option_id = na_ioption_get_id( option );
- if( option == default_option ){
+ if( !strcmp( default_id, option_id )){
selection = gtk_tree_view_get_selection( tree_view );
gtk_tree_selection_select_iter( selection, iter );
stop = TRUE;
}
+ g_free( option_id );
+
return( stop );
}
+
+/*
+ * na_ioptions_list_set_editable:
+ * @instance: the object which implements this #NAIOptionsList interface.
+ * @container_parent: the #GtkWidget which embeds our list of values.
+ * @editable: whether the selectable user's preference is editable;
+ * Most of time, a user's preference is not editable if it is set as mandatory,
+ * or if the whole user's preferences are not writable.
+ *
+ * Set the @editable pseudo-property on the @instance #NAIOptionsList instance.
+ */
+void
+na_ioptions_list_set_editable( const NAIOptionsList *instance, GtkWidget *container_parent, gboolean editable )
+{
+ static const gchar *thisfn = "na_ioptions_list_set_editable";
+
+ g_return_if_fail( st_ioptions_list_iface_initialized && !st_ioptions_list_iface_finalized );
+ check_for_initializations( instance, container_parent );
+
+ g_debug( "%s: instance=%p (%s), container_parent=%p (%s), editable=%s",
+ thisfn,
+ ( void * ) instance, G_OBJECT_TYPE_NAME( instance ),
+ ( void * ) container_parent, G_OBJECT_TYPE_NAME( container_parent ),
+ editable ? "True":"False" );
+
+ set_options_list_editable( container_parent, editable );
+}
+
+/*
+ * na_ioptions_list_set_sensitive:
+ * @instance: the object which implements this #NAIOptionsList interface.
+ * @container_parent: the #GtkWidget which embeds our list of values.
+ * @sensitive: whether the radio button group is to be sensitive;
+ * a widget should not be sensitive if the selectable option is not relevant
+ * in the considered case.
+ *
+ * Set the @sensitive pseudo-property on the @instance #NAIOptionsList instance.
+ */
+void
+na_ioptions_list_set_sensitive( const NAIOptionsList *instance, GtkWidget *container_parent, gboolean sensitive )
+{
+ static const gchar *thisfn = "na_ioptions_list_set_sensitive";
+
+ g_return_if_fail( st_ioptions_list_iface_initialized && !st_ioptions_list_iface_finalized );
+ check_for_initializations( instance, container_parent );
+
+ g_debug( "%s: instance=%p (%s), container_parent=%p (%s), sensitive=%s",
+ thisfn,
+ ( void * ) instance, G_OBJECT_TYPE_NAME( instance ),
+ ( void * ) container_parent, G_OBJECT_TYPE_NAME( container_parent ),
+ sensitive ? "True":"False" );
+
+ set_options_list_sensitive( container_parent, sensitive );
+}
+
+/*
+ * na_ioptions_list_get_selected:
+ * @instance: the object which implements this #NAIOptionsList interface.
+ * @container_parent: the #GtkWidget which embeds our list of values.
+ *
+ * Returns: the currently selected #NAIOption.
+ */
+NAIOption *
+na_ioptions_list_get_selected( const NAIOptionsList *instance, GtkWidget *container_parent )
+{
+ static const gchar *thisfn = "na_ioptions_list_get_selected";
+ NAIOption *option;
+
+ option = NULL;
+
+ g_return_val_if_fail( st_ioptions_list_iface_initialized && !st_ioptions_list_iface_finalized, NULL );
+ check_for_initializations( instance, container_parent );
+
+ g_debug( "%s: instance=%p (%s), container_parent=%p (%s)",
+ thisfn,
+ ( void * ) instance, G_OBJECT_TYPE_NAME( instance ),
+ ( void * ) container_parent, G_OBJECT_TYPE_NAME( container_parent ));
+
+ if( GTK_IS_BOX( container_parent )){
+ gtk_container_foreach( GTK_CONTAINER( container_parent ),
+ ( GtkCallback ) radio_button_get_selected_iter, container_parent );
+ option = get_options_list_option( container_parent );
+
+ } else if( GTK_IS_TREE_VIEW( container_parent )){
+ tree_view_get_selected( instance, container_parent );
+ option = get_options_list_option( container_parent );
+
+ } else {
+ g_warning( "%s: unknown container_parent type: %s", thisfn, G_OBJECT_TYPE_NAME( container_parent ));
+ }
+
+ return( option );
+}
+
+/*
+ * container_mode is a GtkVBox, or a GtkGrid starting with Gtk 3.2
+ */
+static void
+radio_button_get_selected_iter( GtkWidget *container_option, GtkWidget *container_parent )
+{
+ GtkWidget *button;
+ NAIOption *option;
+
+ button = na_gtk_utils_find_widget_by_type( GTK_CONTAINER( container_option ), GTK_TYPE_RADIO_BUTTON );
+ g_return_if_fail( GTK_IS_RADIO_BUTTON( button ));
+
+ if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ))){
+ option = get_options_list_option( container_option );
+ set_options_list_option( container_parent, option );
+ }
+}
+
+static void
+tree_view_get_selected( const NAIOptionsList *instance, GtkWidget *container_parent )
+{
+ GtkTreeSelection *selection;
+ GList *rows;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ NAIOption *option;
+
+ selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( container_parent ));
+ rows = gtk_tree_selection_get_selected_rows( selection, &model );
+ g_return_if_fail( g_list_length( rows ) == 1 );
+
+ gtk_tree_model_get_iter( model, &iter, ( GtkTreePath * ) rows->data );
+ gtk_tree_model_get( model, &iter, OBJECT_COLUMN, &option, -1 );
+ g_object_unref( option );
+
+ g_list_foreach( rows, ( GFunc ) gtk_tree_path_free, NULL );
+ g_list_free( rows );
+
+ set_options_list_option( container_parent, option );
+}
diff --git a/src/core/na-ioptions-list.h b/src/core/na-ioptions-list.h
index 2ba97b7..f1c94f1 100644
--- a/src/core/na-ioptions-list.h
+++ b/src/core/na-ioptions-list.h
@@ -68,9 +68,24 @@
* -derived object, which itself should implement the #NAIOption companion
* interface.
*
- * More, the instance which would want to implement this #NAIOptionsList
- * interface should also implement one of #NAIOptionsRadioButton or
- * #NAIOptionsTreeView interfaces.
+ * Note that the instance which implements this interface is able to provide
+ * several list of values. This is the reason why each list of values is
+ * identified by its container inside of the window's instance.
+ *
+ * Instance initialization
+ *
+ * Rather that having to call a na_ioptions_list_instance_init() on each
+ * instance implementation, we prefer to check when entering in each public
+ * method for an 'initialized' flag both at the instance level and at the
+ * container level.
+ *
+ * Alternative may have be to have the na_ioptions_list_instance_init()
+ * initialization interface method, which itself connect to #BaseWindow
+ * signals. But this would not prevent of initializing for both managed
+ * containers...
+ *
+ * Initialization mainly consists of defining weak references both on
+ * instance and on containers levels.
*
* <refsect2>
* <title>Versions historic</title>
@@ -119,6 +134,10 @@ typedef struct _NAIOptionsListManageImportModeParms NAIOptionsListManageImportMo
* NAIOptionsListInterface:
* @get_version: returns the version of this interface that the
* instance implements.
+ * @get_options: returns the list of #NAIOption.
+ * @free_options: releases the list of #NAIOption.
+ * @get_ask_option: returns the 'Ask me' #NAIOption.
+ * @free_ask_option: releases the 'Ask me' #NAIOption.
*
* This defines the interface that a #NAIOptionsList implementation should provide.
*/
@@ -148,6 +167,7 @@ typedef struct {
/*
* get_options:
* @instance: the #NAIOptionsList instance of the implementation.
+ * @container: the #GtkWidget which embeds the list of values.
*
* This method may be called at more or less early stage of the build
* of the display, either rather early when displaying a radio button
@@ -157,7 +177,7 @@ typedef struct {
*
* Since: 3.2
*/
- GList * ( *get_options ) ( const NAIOptionsList *instance );
+ GList * ( *get_options ) ( const NAIOptionsList *instance, GtkWidget *container );
/*
* free_options:
@@ -178,6 +198,7 @@ typedef struct {
/*
* get_ask_option:
* @instance: the #NAIOptionsList instance of the implementation.
+ * @container: the #GtkWidget which embeds the list of values.
*
* Ask the implementation to provide a #NAIOption which defines the
* 'Ask me' option.
@@ -186,7 +207,7 @@ typedef struct {
*
* Since: 3.2
*/
- NAIOption * ( *get_ask_option ) ( const NAIOptionsList *instance );
+ NAIOption * ( *get_ask_option ) ( const NAIOptionsList *instance, GtkWidget *container );
/*
* free_ask_option:
@@ -205,10 +226,15 @@ typedef struct {
}
NAIOptionsListInterface;
-GType na_ioptions_list_get_type( void );
+GType na_ioptions_list_get_type( void );
+
+void na_ioptions_list_gtk_init ( const NAIOptionsList *instance, GtkWidget *container, gboolean with_ask );
+
+void na_ioptions_list_set_default ( const NAIOptionsList *instance, GtkWidget *container, const gchar *default_id );
+void na_ioptions_list_set_editable ( const NAIOptionsList *instance, GtkWidget *container, gboolean editable );
+void na_ioptions_list_set_sensitive( const NAIOptionsList *instance, GtkWidget *container, gboolean sensitive );
-void na_ioptions_list_display_init( NAIOptionsList *instance, GtkWidget *parent, gboolean with_ask, gboolean editable, gboolean sensitive );
-void na_ioptions_list_set_default ( NAIOptionsList *instance, NAIOption *default_option );
+NAIOption *na_ioptions_list_get_selected ( const NAIOptionsList *instance, GtkWidget *container );
G_END_DECLS
diff --git a/src/io-desktop/nadp-formats.c b/src/io-desktop/nadp-formats.c
index 3b02fd6..76b96b5 100644
--- a/src/io-desktop/nadp-formats.c
+++ b/src/io-desktop/nadp-formats.c
@@ -70,6 +70,10 @@ static NadpExportFormat nadp_formats[] = {
{ NULL }
};
+#if 0
+static void on_pixbuf_finalized( const NAIExporter* exporter, GObject *pixbuf );
+#endif
+
/**
* nadp_formats_get_formats:
* @exporter: this #NAIExporter provider.
@@ -83,6 +87,9 @@ static NadpExportFormat nadp_formats[] = {
GList *
nadp_formats_get_formats( const NAIExporter* exporter )
{
+#if 0
+ static const gchar *thisfn = "nadp_formats_get_formats";
+#endif
GList *str_list;
NAIExporterFormatExt *str;
guint i;
@@ -106,6 +113,17 @@ nadp_formats_get_formats( const NAIExporter* exporter )
fname = g_strdup_printf( "%s/%s", PKGDATADIR, nadp_formats[i].image );
str->pixbuf = gdk_pixbuf_new_from_file_at_size( fname, width, height, NULL );
g_free( fname );
+#if 0
+ /* do not set weak reference on a graphical object provided by a plugin
+ * if the windows does not have its own builder, it may happens that the
+ * graphical object be finalized when destroying toplevels at common
+ * builder finalization time, and so after the plugins have been shutdown
+ */
+ if( str->pixbuf ){
+ g_debug( "%s: allocating pixbuf at %p", thisfn, str->pixbuf );
+ g_object_weak_ref( G_OBJECT( str->pixbuf ), ( GWeakNotify ) on_pixbuf_finalized, ( gpointer ) exporter );
+ }
+#endif
}
str_list = g_list_prepend( str_list, str );
}
@@ -113,6 +131,14 @@ nadp_formats_get_formats( const NAIExporter* exporter )
return( str_list );
}
+#if 0
+static void
+on_pixbuf_finalized( const NAIExporter* exporter, GObject *pixbuf )
+{
+ g_debug( "nadp_formats_on_pixbuf_finalized: exporter=%p, pixbuf=%p", ( void * ) exporter, ( void * ) pixbuf );
+}
+#endif
+
/**
* nadp_formats_free_formats:
* @formats: a #GList to be freed.
@@ -137,6 +163,7 @@ nadp_formats_free_formats( GList *formats )
if( str->pixbuf ){
g_object_unref( str->pixbuf );
}
+ g_free( str );
}
g_list_free( formats );
diff --git a/src/io-xml/naxml-formats.c b/src/io-xml/naxml-formats.c
index 66cef45..8035b74 100644
--- a/src/io-xml/naxml-formats.c
+++ b/src/io-xml/naxml-formats.c
@@ -94,6 +94,10 @@ static NaxmlExportFormat naxml_formats[] = {
{ NULL }
};
+#if 0
+static void on_pixbuf_finalized( const NAIExporter* exporter, GObject *pixbuf );
+#endif
+
/**
* naxml_formats_get_formats:
* @exporter: this #NAIExporter provider.
@@ -107,6 +111,9 @@ static NaxmlExportFormat naxml_formats[] = {
GList *
naxml_formats_get_formats( const NAIExporter* exporter )
{
+#if 0
+ static const gchar *thisfn = "naxml_formats_get_formats";
+#endif
GList *str_list;
NAIExporterFormatExt *str;
guint i;
@@ -130,6 +137,17 @@ naxml_formats_get_formats( const NAIExporter* exporter )
fname = g_strdup_printf( "%s/%s", PKGDATADIR, naxml_formats[i].image );
str->pixbuf = gdk_pixbuf_new_from_file_at_size( fname, width, height, NULL );
g_free( fname );
+#if 0
+ /* do not set weak reference on a graphical object provided by a plugin
+ * if the windows does not have its own builder, it may happens that the
+ * graphical object be finalized when destroying toplevels at common
+ * builder finalization time, and so after the plugins have been shutdown
+ */
+ if( str->pixbuf ){
+ g_debug( "%s: allocating pixbuf at %p", thisfn, str->pixbuf );
+ g_object_weak_ref( G_OBJECT( str->pixbuf ), ( GWeakNotify ) on_pixbuf_finalized, ( gpointer ) exporter );
+ }
+#endif
}
str_list = g_list_prepend( str_list, str );
}
@@ -137,13 +155,19 @@ naxml_formats_get_formats( const NAIExporter* exporter )
return( str_list );
}
+#if 0
+static void
+on_pixbuf_finalized( const NAIExporter* exporter, GObject *pixbuf )
+{
+ g_debug( "naxml_formats_on_pixbuf_finalized: exporter=%p, pixbuf=%p", ( void * ) exporter, ( void * ) pixbuf );
+}
+#endif
+
/**
* naxml_formats_free_formats:
* @formats: a #GList to be freed.
*
- * Returns: a #GList of the #NAIExporterFormatExt supported export formats.
- *
- * This list should be naxml_format_free_formats() by the caller.
+ * Releases the list of managed formats.
*
* Since: 3.2
*/
@@ -161,6 +185,7 @@ naxml_formats_free_formats( GList *formats )
if( str->pixbuf ){
g_object_unref( str->pixbuf );
}
+ g_free( str );
}
g_list_free( formats );
diff --git a/src/nact/Makefile.am b/src/nact/Makefile.am
index 8a212d8..a4cdf4a 100644
--- a/src/nact/Makefile.am
+++ b/src/nact/Makefile.am
@@ -176,6 +176,7 @@ ui_files = \
$(NULL)
images_files = \
+ export-format-ask.png \
import-mode-ask.png \
import-mode-no-import.png \
import-mode-override.png \
diff --git a/src/nact/base-assistant.c b/src/nact/base-assistant.c
index 541769d..01d8b1a 100644
--- a/src/nact/base-assistant.c
+++ b/src/nact/base-assistant.c
@@ -345,7 +345,6 @@ do_run( BaseWindow *window, GtkWindow *toplevel )
( void * ) window, G_OBJECT_TYPE_NAME( window ),
( void * ) toplevel, G_OBJECT_TYPE_NAME( toplevel ));
gtk_main();
- gtk_widget_destroy( GTK_WIDGET( toplevel ));
code = BASE_EXIT_CODE_OK;
}
diff --git a/src/nact/base-builder.c b/src/nact/base-builder.c
index ab8e668..7b7b776 100644
--- a/src/nact/base-builder.c
+++ b/src/nact/base-builder.c
@@ -55,8 +55,8 @@ static GType register_type( void );
static void class_init( BaseBuilderClass *klass );
static void instance_init( GTypeInstance *instance, gpointer klass );
static void instance_dispose( GObject *application );
+static void free_built_object( GObject *object, gpointer user_data );
static void instance_finalize( GObject *application );
-
static gboolean already_loaded( BaseBuilder *builder, const gchar *filename );
GType
@@ -136,6 +136,7 @@ instance_dispose( GObject *instance )
{
static const gchar *thisfn = "base_builder_instance_dispose";
BaseBuilder *self;
+ GSList *objects;
g_return_if_fail( BASE_IS_BUILDER( instance ));
@@ -145,6 +146,10 @@ instance_dispose( GObject *instance )
g_debug( "%s: instance=%p (%s)", thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ));
+ objects = gtk_builder_get_objects( GTK_BUILDER( instance ));
+ g_slist_foreach( objects, ( GFunc ) free_built_object, NULL );
+ g_slist_free( objects );
+
self->private->dispose_has_run = TRUE;
/* chain up to the parent class */
@@ -155,6 +160,23 @@ instance_dispose( GObject *instance )
}
static void
+free_built_object( GObject *object, gpointer user_data )
+{
+ static const gchar *thisfn = "base_builder_free_built_object";
+
+ if( GTK_IS_WIDGET( object )){
+ if( gtk_widget_is_toplevel( GTK_WIDGET( object ))){
+
+ g_debug( "%s: object=%p (%s) %s", thisfn,
+ ( void * ) object, G_OBJECT_TYPE_NAME( object ),
+ gtk_buildable_get_name( GTK_BUILDABLE( object )));
+
+ gtk_widget_destroy( GTK_WIDGET( object ));
+ }
+ }
+}
+
+static void
instance_finalize( GObject *instance )
{
static const gchar *thisfn = "base_builder_instance_finalize";
diff --git a/src/nact/base-window.c b/src/nact/base-window.c
index 6055934..a318a67 100644
--- a/src/nact/base-window.c
+++ b/src/nact/base-window.c
@@ -649,7 +649,7 @@ base_window_init( BaseWindow *window )
/*
* setup the builder of the window as a new one, or use the global one
*
- * A dialog may have its own builder ,sharing the common UI XML definition file
+ * A dialog may have its own builder, sharing the common UI XML definition file
* or a dialog may have its own UI XML definition file, sharing the common builder
* or a dialog may have both its UI XML definition file with its own builder
*/
diff --git a/src/nact/nact-assistant-export.c b/src/nact/nact-assistant-export.c
index 863dc57..48908d0 100644
--- a/src/nact/nact-assistant-export.c
+++ b/src/nact/nact-assistant-export.c
@@ -38,9 +38,11 @@
#include <api/na-core-utils.h>
#include <api/na-object-api.h>
+#include <core/na-exporter.h>
+#include <core/na-export-format.h>
#include <core/na-gtk-utils.h>
+#include <core/na-ioptions-list.h>
#include <core/na-iprefs.h>
-#include <core/na-exporter.h>
#include "nact-application.h"
#include "nact-main-window.h"
@@ -103,25 +105,22 @@ static BaseAssistantClass *st_parent_class = NULL;
static GType register_type( void );
static void class_init( NactAssistantExportClass *klass );
+static void ioptions_list_iface_init( NAIOptionsListInterface *iface );
+static GList *ioptions_list_get_formats( const NAIOptionsList *instance, GtkWidget *container );
+static void ioptions_list_free_formats( const NAIOptionsList *instance, GList *formats );
+static NAIOption *ioptions_list_get_ask_option( const NAIOptionsList *instance, GtkWidget *container );
static void instance_init( GTypeInstance *instance, gpointer klass );
static void instance_constructed( GObject *instance );
static void instance_dispose( GObject *instance );
static void instance_finalize( GObject *instance );
-
static void on_base_initialize_gtk_toplevel( NactAssistantExport *window, GtkAssistant *toplevel, gpointer user_data );
-static void on_items_tree_view_realized( GtkWidget *tree_view, NactAssistantExport *window );
-static void on_folder_chooser_realized( GtkWidget *tree_view, NactAssistantExport *window );
-static void on_format_tree_view_realized( GtkWidget *tree_view, NactAssistantExport *window );
-
+static void items_tree_view_initialize_gtk( NactAssistantExport *window, GtkAssistant *toplevel );
+static void folder_chooser_initialize_gtk( NactAssistantExport *window );
+static void format_tree_view_initialize_gtk( NactAssistantExport *window );
static void on_base_initialize_base_window( NactAssistantExport *window, gpointer user_data );
static void on_base_all_widgets_showed( NactAssistantExport *window, gpointer user_data );
-
static void on_items_tree_view_selection_changed( NactAssistantExport *window, GList *selected_items, gpointer user_data );
static void on_folder_chooser_selection_changed( GtkFileChooser *chooser, NactAssistantExport *window );
-
-static NAExportFormat *get_selected_export_format( NactAssistantExport *window );
-static GtkWidget *get_export_format_treeview( NactAssistantExport *window );
-
static void assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page );
static void assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, GtkWidget *page );
static void assistant_apply( BaseAssistant *window, GtkAssistant *assistant );
@@ -158,10 +157,18 @@ register_type( void )
( GInstanceInitFunc ) instance_init
};
+ static const GInterfaceInfo ioptions_list_iface_info = {
+ ( GInterfaceInitFunc ) ioptions_list_iface_init,
+ NULL,
+ NULL
+ };
+
g_debug( "%s", thisfn );
type = g_type_register_static( BASE_ASSISTANT_TYPE, "NactAssistantExport", &info, 0 );
+ g_type_add_interface_static( type, NA_IOPTIONS_LIST_TYPE, &ioptions_list_iface_info );
+
return( type );
}
@@ -189,6 +196,48 @@ class_init( NactAssistantExportClass *klass )
}
static void
+ioptions_list_iface_init( NAIOptionsListInterface *iface )
+{
+ static const gchar *thisfn = "nact_assistant_export_ioptions_list_iface_init";
+
+ g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
+
+ iface->get_options = ioptions_list_get_formats;
+ iface->free_options = ioptions_list_free_formats;
+ iface->get_ask_option = ioptions_list_get_ask_option;
+}
+
+static GList *
+ioptions_list_get_formats( const NAIOptionsList *instance, GtkWidget *container )
+{
+ NactAssistantExport *window;
+ NactApplication *application;
+ NAUpdater *updater;
+ GList *formats;
+
+ g_return_val_if_fail( NACT_IS_ASSISTANT_EXPORT( instance ), NULL );
+ window = NACT_ASSISTANT_EXPORT( instance );
+
+ application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+ updater = nact_application_get_updater( application );
+ formats = na_exporter_get_formats( NA_PIVOT( updater ));
+
+ return( formats );
+}
+
+static void
+ioptions_list_free_formats( const NAIOptionsList *instance, GList *formats )
+{
+ na_exporter_free_formats( formats );
+}
+
+static NAIOption *
+ioptions_list_get_ask_option( const NAIOptionsList *instance, GtkWidget *container )
+{
+ return( nact_export_format_get_ask_option());
+}
+
+static void
instance_init( GTypeInstance *instance, gpointer klass )
{
static const gchar *thisfn = "nact_assistant_export_instance_init";
@@ -337,8 +386,6 @@ static void
on_base_initialize_gtk_toplevel( NactAssistantExport *window, GtkAssistant *assistant, gpointer user_data )
{
static const gchar *thisfn = "nact_assistant_export_on_base_initialize_gtk_toplevel";
- GtkWidget *page;
- GtkWidget *widget;
gboolean are_locked, mandatory;
g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window ));
@@ -347,33 +394,9 @@ on_base_initialize_gtk_toplevel( NactAssistantExport *window, GtkAssistant *assi
g_debug( "%s: window=%p, assistant=%p, user_data=%p",
thisfn, ( void * ) window, ( void * ) assistant, ( void * ) user_data );
- page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_ACTIONS_SELECTION );
- widget = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "ActionsList" );
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( widget ),
- "realize",
- G_CALLBACK( on_items_tree_view_realized ));
-
- window->private->items_view =
- nact_tree_view_new( BASE_WINDOW( window ),
- GTK_CONTAINER( page ), "ActionsList", TREE_MODE_SELECTION );
-
- page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FOLDER_SELECTION );
- widget = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p2-ExportFolderChooser" );
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( widget ),
- "realize",
- G_CALLBACK( on_folder_chooser_realized ));
-
- page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
- widget = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p3-ExportFormatTreeView" );
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( widget ),
- "realize",
- G_CALLBACK( on_format_tree_view_realized ));
+ items_tree_view_initialize_gtk( window, assistant );
+ folder_chooser_initialize_gtk( window );
+ format_tree_view_initialize_gtk( window );
are_locked = na_settings_get_boolean( NA_IPREFS_ADMIN_PREFERENCES_LOCKED, NULL, &mandatory );
window->private->preferences_locked = are_locked && mandatory;
@@ -381,7 +404,7 @@ on_base_initialize_gtk_toplevel( NactAssistantExport *window, GtkAssistant *assi
#if !GTK_CHECK_VERSION( 3,0,0 )
guint padder = 8;
/* selecting items */
- page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_ACTIONS_SELECTION );
+ GtkWidget *page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_ACTIONS_SELECTION );
GtkWidget *container = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p1-l2-alignment1" );
g_object_set( G_OBJECT( container ), "border_width", padder, NULL );
/* selecting target folder */
@@ -405,50 +428,36 @@ on_base_initialize_gtk_toplevel( NactAssistantExport *window, GtkAssistant *assi
}
static void
-on_items_tree_view_realized( GtkWidget *tree_view, NactAssistantExport *window )
+items_tree_view_initialize_gtk( NactAssistantExport *window, GtkAssistant *assistant )
{
- static const gchar *thisfn = "nact_assistant_export_on_items_tree_view_realized";
- GtkAssistant *assistant;
+ static const gchar *thisfn = "nact_assistant_export_items_tree_view_initialize_gtk";
GtkWidget *page;
- NactMainWindow *main_window;
- NactTreeView *main_items_view;
- GList *items;
- GtkTreePath *path;
- g_debug( "%s: tree_view=%p, window=%p", thisfn, ( void * ) tree_view, ( void * ) window );
+ g_debug( "%s: window=%p, assistant=%p", thisfn, ( void * ) window, ( void * ) assistant );
- assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_ACTIONS_SELECTION );
- /* fill up the tree view
- */
- main_window = NACT_MAIN_WINDOW( base_window_get_parent( BASE_WINDOW( window )));
- main_items_view = nact_main_window_get_items_view( main_window );
- items = nact_tree_view_get_items( main_items_view );
- nact_tree_view_fill( window->private->items_view, items );
-
- /* connect to the 'selection-changed' signal emitted by NactTreeView
- */
- base_window_signal_connect(
- BASE_WINDOW( window ),
- G_OBJECT( window ),
- TREE_SIGNAL_SELECTION_CHANGED,
- G_CALLBACK( on_items_tree_view_selection_changed ));
-
- /* select the first row
- */
- path = gtk_tree_path_new_from_string( "0" );
- nact_tree_view_select_row_at_path( window->private->items_view, path );
- gtk_tree_path_free( path );
+ window->private->items_view =
+ nact_tree_view_new(
+ BASE_WINDOW( window ),
+ GTK_CONTAINER( page ),
+ "ActionsList",
+ TREE_MODE_SELECTION );
}
static void
-on_folder_chooser_realized( GtkWidget *chooser, NactAssistantExport *window )
+folder_chooser_initialize_gtk( NactAssistantExport *window )
{
- static const gchar *thisfn = "nact_assistant_export_on_folder_chooser_realized";
+ static const gchar *thisfn = "nact_assistant_export_folder_chooser_initialize_gtk";
+ GtkAssistant *assistant;
+ GtkWidget *page, *chooser;
gchar *uri;
- g_debug( "%s: chooser=%p, window=%p", thisfn, ( void * ) chooser, ( void * ) window );
+ g_debug( "%s: window=%p", thisfn, ( void * ) window );
+
+ assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
+ page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FOLDER_SELECTION );
+ chooser = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p2-ExportFolderChooser" );
gtk_file_chooser_set_action( GTK_FILE_CHOOSER( chooser ), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
gtk_file_chooser_set_create_folders( GTK_FILE_CHOOSER( chooser ), TRUE );
@@ -468,34 +477,24 @@ on_folder_chooser_realized( GtkWidget *chooser, NactAssistantExport *window )
}
static void
-on_format_tree_view_realized( GtkWidget *tree_view, NactAssistantExport *window )
+format_tree_view_initialize_gtk( NactAssistantExport *window )
{
static const gchar *thisfn = "nact_assistant_export_on_format_tree_view_realized";
- NactApplication *application;
- NAUpdater *updater;
GtkAssistant *assistant;
- GtkWidget *page;
- GQuark format;
- gboolean mandatory;
+ GtkWidget *page, *tree_view;
- g_debug( "%s: tree_view=%p, window=%p", thisfn, ( void * ) tree_view, ( void * ) window );
+ g_debug( "%s: window=%p", thisfn, ( void * ) window );
+
+ assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
+ page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
+ tree_view = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p3-ExportFormatTreeView" );
#ifdef NA_MAINTAINER_MODE
na_gtk_utils_dump_children( GTK_CONTAINER( tree_view ));
#endif
- application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
- updater = nact_application_get_updater( application );
+ na_ioptions_list_gtk_init( NA_IOPTIONS_LIST( window ), tree_view, TRUE );
- nact_export_format_init_display( tree_view,
- NA_PIVOT( updater ), EXPORT_FORMAT_DISPLAY_ASSISTANT, !window->private->preferences_locked );
-
- format = na_iprefs_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, &mandatory );
-
- nact_export_format_select( tree_view, !mandatory, format );
-
- assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
- page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
gtk_assistant_set_page_complete( assistant, page, TRUE );
}
@@ -507,6 +506,9 @@ on_base_initialize_base_window( NactAssistantExport *window, gpointer user_data
GtkWidget *page;
guint pos;
GtkWidget *pane;
+ GQuark format;
+ gboolean mandatory;
+ GtkWidget *tree_view;
g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window ));
@@ -520,7 +522,7 @@ on_base_initialize_base_window( NactAssistantExport *window, gpointer user_data
page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_INTRO );
gtk_assistant_set_page_complete( assistant, page, TRUE );
- /* set the slider position
+ /* set the slider position of the item selection page
*/
pos = na_settings_get_uint( NA_IPREFS_EXPORT_ASSISTANT_PANED, NULL, NULL );
if( pos ){
@@ -528,6 +530,17 @@ on_base_initialize_base_window( NactAssistantExport *window, gpointer user_data
pane = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p1-HPaned" );
gtk_paned_set_position( GTK_PANED( pane ), pos );
}
+
+ /* initialize the export format tree view
+ */
+ page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
+ tree_view = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p3-ExportFormatTreeView" );
+ format = na_iprefs_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, &mandatory );
+ na_ioptions_list_set_editable(
+ NA_IOPTIONS_LIST( window ), tree_view,
+ !mandatory && !window->private->preferences_locked );
+ na_ioptions_list_set_default(
+ NA_IOPTIONS_LIST( window ), tree_view, g_quark_to_string( format ));
}
}
@@ -537,6 +550,10 @@ on_base_all_widgets_showed( NactAssistantExport *window, gpointer user_data )
static const gchar *thisfn = "nact_assistant_export_on_base_all_widgets_showed";
GtkAssistant *assistant;
GtkWidget *page;
+ NactMainWindow *main_window;
+ NactTreeView *main_items_view;
+ GList *items;
+ GtkTreePath *path;
g_return_if_fail( NACT_IS_ASSISTANT_EXPORT( window ));
@@ -545,6 +562,27 @@ on_base_all_widgets_showed( NactAssistantExport *window, gpointer user_data )
assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
+ /* fill up the items tree view
+ */
+ main_window = NACT_MAIN_WINDOW( base_window_get_parent( BASE_WINDOW( window )));
+ main_items_view = nact_main_window_get_items_view( main_window );
+ items = nact_tree_view_get_items( main_items_view );
+ nact_tree_view_fill( window->private->items_view, items );
+
+ /* connect to the 'selection-changed' signal emitted by NactTreeView
+ */
+ base_window_signal_connect(
+ BASE_WINDOW( window ),
+ G_OBJECT( window ),
+ TREE_SIGNAL_SELECTION_CHANGED,
+ G_CALLBACK( on_items_tree_view_selection_changed ));
+
+ /* select the first row
+ */
+ path = gtk_tree_path_new_from_string( "0" );
+ nact_tree_view_select_row_at_path( window->private->items_view, path );
+ gtk_tree_path_free( path );
+
page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_ACTIONS_SELECTION );
gtk_widget_show_all( page );
@@ -627,26 +665,6 @@ on_folder_chooser_selection_changed( GtkFileChooser *chooser, NactAssistantExpor
}
}
-static NAExportFormat *
-get_selected_export_format( NactAssistantExport *window )
-{
- GtkWidget *container;
- NAExportFormat *format;
-
- container = get_export_format_treeview( window );
- format = nact_export_format_get_selected( container );
-
- return( format );
-}
-
-static GtkWidget *
-get_export_format_treeview( NactAssistantExport *window )
-{
- GtkAssistant *assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( window )));
- GtkWidget *page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
- return( na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p3-ExportFormatTreeView" ));
-}
-
static void
assistant_prepare( BaseAssistant *window, GtkAssistant *assistant, GtkWidget *page )
{
@@ -679,8 +697,9 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
gchar *format_label, *format_label2;
gchar *format_description, *format_description2;
GtkWidget *label;
- NAExportFormat *format;
+ NAIOption *format;
GList *it;
+ GtkWidget *format_page, *tree_view;
g_debug( "%s: window=%p, assistant=%p, page=%p",
thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
@@ -716,16 +735,20 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
/* display the target folder
*/
- g_assert( window->private->uri && strlen( window->private->uri ));
+ g_return_if_fail( window->private->uri && strlen( window->private->uri ));
label = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p4-ConfirmTargetFolder" );
g_return_if_fail( GTK_IS_LABEL( label ));
gtk_label_set_text( GTK_LABEL( label ), window->private->uri );
/* display the export format and its description
*/
- format = get_selected_export_format( window );
+ format_page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FORMAT_SELECTION );
+ tree_view = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( format_page ), "p3-ExportFormatTreeView" );
+ g_return_if_fail( GTK_IS_TREE_VIEW( tree_view ));
+ format = na_ioptions_list_get_selected( NA_IOPTIONS_LIST( window ), tree_view );
+ g_return_if_fail( NA_IS_EXPORT_FORMAT( format ));
- format_label = na_export_format_get_label( format );
+ format_label = na_ioption_get_label( format );
format_label2 = na_core_utils_str_remove_char( format_label, "_" );
text = g_strdup_printf( "%s:", format_label2 );
label = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p4-ConfirmExportFormat" );
@@ -735,7 +758,7 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
g_free( format_label2 );
g_free( text );
- format_description = na_export_format_get_description( format );
+ format_description = na_ioption_get_description( format );
format_description2 = na_core_utils_str_remove_char( format_description, "_" );
label = na_gtk_utils_find_widget_by_name( GTK_CONTAINER( page ), "p4-ConfirmExportTooltip" );
g_return_if_fail( GTK_IS_LABEL( label ));
@@ -743,7 +766,7 @@ assist_prepare_confirm( NactAssistantExport *window, GtkAssistant *assistant, Gt
g_free( format_description );
g_free( format_description2 );
- na_iprefs_set_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, na_export_format_get_quark( format ));
+ na_iprefs_set_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, na_export_format_get_quark( NA_EXPORT_FORMAT( format )));
gtk_assistant_set_page_complete( assistant, page, TRUE );
}
diff --git a/src/nact/nact-export-ask.c b/src/nact/nact-export-ask.c
index 2c05efe..57f3e98 100644
--- a/src/nact/nact-export-ask.c
+++ b/src/nact/nact-export-ask.c
@@ -37,7 +37,9 @@
#include <api/na-object-api.h>
#include <core/na-exporter.h>
+#include <core/na-export-format.h>
#include <core/na-gtk-utils.h>
+#include <core/na-ioptions-list.h>
#include <core/na-iprefs.h>
#include "nact-application.h"
@@ -72,10 +74,12 @@ static BaseDialogClass *st_parent_class = NULL;
static GType register_type( void );
static void class_init( NactExportAskClass *klass );
+static void ioptions_list_iface_init( NAIOptionsListInterface *iface );
+static GList *ioptions_list_get_formats( const NAIOptionsList *instance, GtkWidget *container );
+static void ioptions_list_free_formats( const NAIOptionsList *instance, GList *formats );
static void instance_init( GTypeInstance *instance, gpointer klass );
static void instance_dispose( GObject *dialog );
static void instance_finalize( GObject *dialog );
-
static void on_base_initialize_gtk_toplevel( NactExportAsk *editor, GtkDialog *toplevel );
static void on_base_initialize_base_window( NactExportAsk *editor );
static void keep_choice_on_toggled( GtkToggleButton *button, NactExportAsk *editor );
@@ -113,10 +117,18 @@ register_type( void )
( GInstanceInitFunc ) instance_init
};
+ static const GInterfaceInfo ioptions_list_iface_info = {
+ ( GInterfaceInitFunc ) ioptions_list_iface_init,
+ NULL,
+ NULL
+ };
+
g_debug( "%s", thisfn );
type = g_type_register_static( BASE_DIALOG_TYPE, "NactExportAsk", &info, 0 );
+ g_type_add_interface_static( type, NA_IOPTIONS_LIST_TYPE, &ioptions_list_iface_info );
+
return( type );
}
@@ -138,6 +150,41 @@ class_init( NactExportAskClass *klass )
}
static void
+ioptions_list_iface_init( NAIOptionsListInterface *iface )
+{
+ static const gchar *thisfn = "nact_assistant_export_ioptions_list_iface_init";
+
+ g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
+
+ iface->get_options = ioptions_list_get_formats;
+ iface->free_options = ioptions_list_free_formats;
+}
+
+static GList *
+ioptions_list_get_formats( const NAIOptionsList *instance, GtkWidget *container )
+{
+ NactExportAsk *window;
+ NactApplication *application;
+ NAUpdater *updater;
+ GList *formats;
+
+ g_return_val_if_fail( NACT_IS_EXPORT_ASK( instance ), NULL );
+ window = NACT_EXPORT_ASK( instance );
+
+ application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+ updater = nact_application_get_updater( application );
+ formats = na_exporter_get_formats( NA_PIVOT( updater ));
+
+ return( formats );
+}
+
+static void
+ioptions_list_free_formats( const NAIOptionsList *instance, GList *formats )
+{
+ na_exporter_free_formats( formats );
+}
+
+static void
instance_init( GTypeInstance *instance, gpointer klass )
{
static const gchar *thisfn = "nact_export_ask_instance_init";
@@ -285,8 +332,6 @@ static void
on_base_initialize_gtk_toplevel( NactExportAsk *editor, GtkDialog *toplevel )
{
static const gchar *thisfn = "nact_export_ask_on_base_initialize_gtk_toplevel";
- NactApplication *application;
- NAUpdater *updater;
GtkWidget *container;
g_return_if_fail( NACT_IS_EXPORT_ASK( editor ));
@@ -294,12 +339,8 @@ on_base_initialize_gtk_toplevel( NactExportAsk *editor, GtkDialog *toplevel )
if( !editor->private->dispose_has_run ){
g_debug( "%s: editor=%p, toplevel=%p", thisfn, ( void * ) editor, ( void * ) toplevel );
- application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( editor )));
- updater = nact_application_get_updater( application );
container = base_window_get_widget( BASE_WINDOW( editor ), "ExportFormatAskVBox" );
-
- nact_export_format_init_display( container,
- NA_PIVOT( updater ), EXPORT_FORMAT_DISPLAY_ASK, !editor->private->preferences_locked );
+ na_ioptions_list_gtk_init( NA_IOPTIONS_LIST( editor ), container, FALSE );
#if !GTK_CHECK_VERSION( 2,22,0 )
gtk_dialog_set_has_separator( toplevel, FALSE );
@@ -311,7 +352,6 @@ static void
on_base_initialize_base_window( NactExportAsk *editor )
{
static const gchar *thisfn = "nact_export_ask_on_base_initialize_base_window";
- GtkWidget *container;
gchar *item_label, *label;
GtkWidget *widget;
@@ -335,8 +375,13 @@ on_base_initialize_base_window( NactExportAsk *editor )
g_free( label );
g_free( item_label );
- container = base_window_get_widget( BASE_WINDOW( editor ), "ExportFormatAskVBox" );
- nact_export_format_select( container, !editor->private->format_mandatory, editor->private->format );
+ widget = base_window_get_widget( BASE_WINDOW( editor ), "ExportFormatAskVBox" );
+ na_ioptions_list_set_editable(
+ NA_IOPTIONS_LIST( editor ), widget,
+ !editor->private->format_mandatory && !editor->private->preferences_locked );
+ na_ioptions_list_set_default(
+ NA_IOPTIONS_LIST( editor ), widget,
+ g_quark_to_string( editor->private->format ));
base_gtk_utils_toggle_set_initial_state( BASE_WINDOW( editor ),
"AskKeepChoiceButton", G_CALLBACK( keep_choice_on_toggled ),
@@ -395,13 +440,15 @@ on_ok_clicked( GtkButton *button, NactExportAsk *editor )
static GQuark
get_export_format( NactExportAsk *editor )
{
- GtkWidget *container;
- NAExportFormat *format;
+ GtkWidget *widget;
+ NAIOption *format;
GQuark format_quark;
- container = base_window_get_widget( BASE_WINDOW( editor ), "ExportFormatAskVBox" );
- format = nact_export_format_get_selected( container );
- format_quark = na_export_format_get_quark( format );
+ widget = base_window_get_widget( BASE_WINDOW( editor ), "ExportFormatAskVBox" );
+ format = na_ioptions_list_get_selected( NA_IOPTIONS_LIST( editor ), widget );
+ g_return_val_if_fail( NA_IS_EXPORT_FORMAT( format ), 0 );
+
+ format_quark = na_export_format_get_quark( NA_EXPORT_FORMAT( format ));
if( !editor->private->keep_last_choice_mandatory ){
na_settings_set_boolean( NA_IPREFS_EXPORT_ASK_USER_KEEP_LAST_CHOICE, editor->private->keep_last_choice );
diff --git a/src/nact/nact-export-format.c b/src/nact/nact-export-format.c
index 9ba5e8c..c0aeab6 100644
--- a/src/nact/nact-export-format.c
+++ b/src/nact/nact-export-format.c
@@ -33,589 +33,81 @@
#endif
#include <glib/gi18n.h>
+#include <gtk/gtk.h>
-#include <api/na-core-utils.h>
-
-#include <core/na-exporter.h>
-#include <core/na-export-format.h>
+#include "core/na-export-format.h"
#include "nact-export-format.h"
-#include "base-gtk-utils.h"
-
-/* column ordering in the export format treeview
- */
-enum {
- IMAGE_COLUMN = 0,
- LABEL_COLUMN,
- TOOLTIP_COLUMN,
- FORMAT_COLUMN,
- OBJECT_COLUMN,
- N_COLUMN
-};
-/*
- * As of Gtk 3.2.0, GtkHBox and GtkVBox are deprecated. It is adviced
- * to replace them with a GtkGrid.
- * In this dialog box, we have a glade-defined VBox, said 'container_vbox'
- * (which may be a GtkVBox or a GtkTreeView),
- * in which we dynamically embed the radio buttons as a hierarchy of
- * VBoxes and HBoxes.
- * While it is still possible to keep the glade-defined VBoxes, we will
- * stay stuck with our VBox 'container_vbox', replacing only dynamically
- * allocated GtkHBoxes and GtkVBoxes with one GtkGrid.
- */
typedef struct {
- GtkWidget *container_vbox;
- GtkRadioButton *button;
- NAExportFormat *format;
- gulong handler; /* 'toggled' signal handler id */
-}
- VBoxData;
-
-#define EXPORT_FORMAT_PROP_CONTAINER_FORMAT "nact-export-format-prop-container-format"
-#define EXPORT_FORMAT_PROP_CONTAINER_EDITABLE "nact-export-format-prop-container-editable"
-#define EXPORT_FORMAT_PROP_CONTAINER_SENSITIVE "nact-export-format-prop-container-sensitive"
-#define EXPORT_FORMAT_PROP_VBOX_DATA "nact-export-format-prop-vbox-data"
-
-#define ASKME_LABEL N_( "_Ask me" )
-#define ASKME_DESCRIPTION N_( "You will be asked for the format to choose each time an item is about to be exported." )
-
-static const NAIExporterFormatExt st_ask_str =
- { 2, NULL, IPREFS_EXPORT_FORMAT_ASK_ID, ASKME_LABEL, ASKME_DESCRIPTION, NULL };
-
-static void create_radio_button_group( GtkWidget *container_parent, GList *formats, guint mode );
-static void draw_in_vbox( GtkWidget *container, const NAExportFormat *format, guint mode, gint id );
-static void format_weak_notify( VBoxData *vbox_data, GObject *vbox );
-static void create_treeview_model( GtkTreeView *listview );
-static void populate_treeview( GtkTreeView *listview, GList *formats, guint mode );
-static void add_treeview_item( GtkTreeView *listview, GtkTreeModel *model, const NAExportFormat *format );
-static void select_default_iter( GtkWidget *widget, void *quark_ptr );
-static gboolean iter_on_model_for_select( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkTreeView *listview );
-static void on_export_format_toggled( GtkToggleButton *toggle_button, VBoxData *vbox_data );
-static void get_selected_iter( GtkWidget *widget, NAExportFormat **format );
-static gboolean have_ask_option( guint mode );
-static void on_unrealize_container_parent( GtkWidget *container, gpointer user_data );
-
-/**
- * nact_export_format_init_display:
- * @container_parent: the #GtkContainer container in which the display must be drawn;
- * may be a GtkVBox (in a GtkDialog) or a GtkTreeView (in a GtkAssistant).
- * @pivot: the #NAPivot instance.
- * @mode: the type of the display.
- * @sensitive: whether the whole radio button group is sensitive
- * (if not, this is most probably because this preference happens to be
- * mandatory).
- *
- * Displays the available export formats:
- * - if @container_parent is a GtkVBox, then we create a RadioButton group
- * - if @container_parent is a GtkTreeView, then we create the corresponding GtkTreeModel
- * and immediately populate the list view
- *
- * Should only be called once per dialog box instance (e.g. on initial load
- * of the GtkWindow).
- */
-void
-nact_export_format_init_display( GtkWidget *container_parent, const NAPivot *pivot, guint mode, gboolean sensitive )
-{
- static const gchar *thisfn = "nact_export_format_init_display";
- GList *formats;
-
- g_debug( "%s: container_parent=%p, pivot=%p, mode=%u, sensitive=%s",
- thisfn, ( void * ) container_parent, ( void * ) pivot, mode,
- sensitive ? "True":"False" );
-
- formats = na_exporter_get_formats( pivot );
-
- if( GTK_IS_BOX( container_parent )){
- create_radio_button_group( container_parent, formats, mode );
-
- } else if( GTK_IS_TREE_VIEW( container_parent )){
- create_treeview_model( GTK_TREE_VIEW( container_parent ));
- populate_treeview( GTK_TREE_VIEW( container_parent ), formats, mode );
- }
-
- na_exporter_free_formats( formats );
-
- g_object_set_data( G_OBJECT( container_parent ), EXPORT_FORMAT_PROP_CONTAINER_FORMAT, GUINT_TO_POINTER( 0 ));
- g_object_set_data( G_OBJECT( container_parent ), EXPORT_FORMAT_PROP_CONTAINER_SENSITIVE, GUINT_TO_POINTER( sensitive ));
-
- g_signal_connect(
- G_OBJECT( container_parent ),
- "unrealize",
- G_CALLBACK( on_unrealize_container_parent ),
- NULL );
-}
-
-static void
-create_radio_button_group( GtkWidget *container_parent, GList *formats, guint mode )
-{
- GList *ifmt;
- NAExportFormat *format;
-
- /* draw the formats as a group of radio buttons
- */
- for( ifmt = formats ; ifmt ; ifmt = ifmt->next ){
- draw_in_vbox( container_parent, NA_EXPORT_FORMAT( ifmt->data ), mode, -1 );
- }
-
- /* eventually add the 'Ask me' mode
- */
- if( have_ask_option( mode )){
- format = na_export_format_new( &st_ask_str );
- draw_in_vbox( container_parent, format, mode, IPREFS_EXPORT_FORMAT_ASK );
- g_object_unref( format );
- }
-}
-
-/*
- * container used to be a glade-defined GtkVBox in which we dynamically
- * add for each mode:
- * +- vbox
- * | +- radio button
- * | +- hbox
- * | | +- description (assistant mode only)
- *
- * Starting with Gtk 3.2, container is a GtkGrid attached to the
- * glade-defined GtkVBox. For each mode, we are defining:
- * +- grid
- * | +- radio button
- * | +- description (assistant mode only)
- *
- * id=-1 but for the 'Ask me' mode
- */
-static void
-draw_in_vbox( GtkWidget *container, const NAExportFormat *format, guint mode, gint id )
-{
- static const gchar *thisfn = "nact_export_format_draw_in_vbox";
- static GtkRadioButton *first_button = NULL;
- GtkWidget *container_mode;
+ gchar *format;
+ gchar *label;
gchar *description;
- GtkRadioButton *button;
- guint size, spacing;
- gint ypad;
- gfloat yalign;
-#if ! GTK_CHECK_VERSION( 3, 2, 0 )
- GtkWidget *hbox;
-#endif
- gchar *markup, *label;
- GtkLabel *desc_label;
- VBoxData *vbox_data;
-
-#if GTK_CHECK_VERSION( 3, 2, 0 )
- /* create a grid container which will embed two lines */
- container_mode = gtk_grid_new();
-#else
- /* create a vbox which will embed two children */
- container_mode = gtk_vbox_new( FALSE, 0 );
-#endif
- gtk_box_pack_start( GTK_BOX( container ), container_mode, FALSE, TRUE, 0 );
- /*g_object_set( G_OBJECT( container_mode ), "spacing", 6, NULL );*/
- description = na_export_format_get_description( format );
- g_object_set( G_OBJECT( container_mode ), "tooltip-text", description, NULL );
-
- /* first line/children is the radio button
- */
- button = GTK_RADIO_BUTTON( gtk_radio_button_new( NULL ));
- if( first_button ){
- g_object_set( G_OBJECT( button ), "group", first_button, NULL );
- } else {
- first_button = button;
- }
-#if GTK_CHECK_VERSION( 3, 2, 0 )
- gtk_grid_attach( GTK_GRID( container_mode ), GTK_WIDGET( button ), 0, 0, 1, 1 );
-#else
- gtk_box_pack_start( GTK_BOX( container_mode ), GTK_WIDGET( button ), FALSE, TRUE, 0 );
-#endif
-
- label = NULL;
- markup = NULL;
- switch( mode ){
-
- case EXPORT_FORMAT_DISPLAY_ASK:
- case EXPORT_FORMAT_DISPLAY_PREFERENCES:
- case EXPORT_FORMAT_DISPLAY_ASSISTANT:
- label = na_export_format_get_label( format );
- markup = g_markup_printf_escaped( "%s", label );
- gtk_button_set_label( GTK_BUTTON( button ), label );
- gtk_button_set_use_underline( GTK_BUTTON( button ), TRUE );
- break;
-
- /* this work fine, but it appears that this is not consistant with import assistant */
- /*case EXPORT_FORMAT_DISPLAY_ASSISTANT:
- radio_label = GTK_LABEL( gtk_label_new( NULL ));
- label = na_export_format_get_label( format );
- markup = g_markup_printf_escaped( "<b>%s</b>", label );
- gtk_label_set_markup( radio_label, markup );
- gtk_container_add( GTK_CONTAINER( button ), GTK_WIDGET( radio_label ));
- break;*/
- }
-
- desc_label = NULL;
- switch( mode ){
-
- case EXPORT_FORMAT_DISPLAY_ASSISTANT:
- gtk_widget_style_get( GTK_WIDGET( button ), "indicator-size", &size, NULL );
- gtk_widget_style_get( GTK_WIDGET( button ), "indicator-spacing", &spacing, NULL );
- size += 3*spacing;
-
- desc_label = GTK_LABEL( gtk_label_new( description ));
- gtk_misc_get_padding( GTK_MISC( desc_label ), NULL, &ypad );
- gtk_misc_set_padding( GTK_MISC( desc_label ), size, ypad );
- gtk_misc_get_alignment( GTK_MISC( desc_label ), NULL, &yalign );
- gtk_misc_set_alignment( GTK_MISC( desc_label ), 0, yalign );
- gtk_label_set_line_wrap( desc_label, TRUE );
- gtk_label_set_line_wrap_mode( desc_label, PANGO_WRAP_WORD );
-
-#if GTK_CHECK_VERSION( 3, 2, 0 )
- gtk_grid_attach( GTK_GRID( container_mode ), GTK_WIDGET( desc_label ), 0, 1, 1, 1 );
-#else
- hbox = gtk_hbox_new( TRUE, 0 );
- gtk_box_pack_start( GTK_BOX( container_mode ), hbox, FALSE, TRUE, 0 );
- gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( desc_label ), TRUE, TRUE, 4 );
-#endif
- break;
- }
-
- vbox_data = g_new0( VBoxData, 1 );
- g_debug( "%s: container_mode=%p, allocating VBoxData at %p",
- thisfn, ( void * ) container_mode, ( void * ) vbox_data );
-
- vbox_data->container_vbox = container;
- vbox_data->button = button;
- vbox_data->format = g_object_ref(( gpointer ) format );
-
- g_object_set_data( G_OBJECT( container_mode ), EXPORT_FORMAT_PROP_VBOX_DATA, vbox_data );
- g_object_weak_ref( G_OBJECT( container_mode ), ( GWeakNotify ) format_weak_notify, ( gpointer ) vbox_data );
-
- g_free( markup );
- g_free( label );
- g_free( description );
-}
-
-/*
- * release the data structure attached to each individual 'mode' container
- * when destroying the window
- */
-static void
-format_weak_notify( VBoxData *vbox_data, GObject *vbox )
-{
- static const gchar *thisfn = "nact_export_format_weak_notify";
-
- g_debug( "%s: vbox_data=%p, vbox=%p", thisfn, ( void * ) vbox_data, ( void * ) vbox );
-
- g_signal_handler_disconnect( vbox_data->button, vbox_data->handler );
-
- g_object_unref( vbox_data->format );
-
- g_free( vbox_data );
-}
-
-static void
-create_treeview_model( GtkTreeView *listview )
-{
- static const gchar *thisfn = "nact_export_format_create_treeview_model";
- GtkListStore *model;
- GtkTreeViewColumn *column;
- GtkTreeSelection *selection;
-
- g_debug( "%s: listview=%p", thisfn, ( void * ) listview );
-
- model = gtk_list_store_new( N_COLUMN, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_OBJECT );
- gtk_tree_view_set_model( listview, GTK_TREE_MODEL( model ));
- g_object_unref( model );
-
- /* create visible columns on the tree view
- */
- column = gtk_tree_view_column_new_with_attributes(
- "image",
- gtk_cell_renderer_pixbuf_new(),
- "pixbuf", IMAGE_COLUMN,
- NULL );
- gtk_tree_view_append_column( listview, column );
-
- column = gtk_tree_view_column_new_with_attributes(
- "label",
- gtk_cell_renderer_text_new(),
- "text", LABEL_COLUMN,
- NULL );
- gtk_tree_view_append_column( listview, column );
-
- g_object_set( G_OBJECT( listview ), "tooltip-column", TOOLTIP_COLUMN, NULL );
-
- selection = gtk_tree_view_get_selection( listview );
- gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
+ gchar *image;
}
+ NactExportFormatStr;
-static void
-populate_treeview( GtkTreeView *listview, GList *formats, guint mode )
-{
- static const gchar *thisfn = "nact_export_format_populate_treeview";
- GtkTreeModel *model;
- NAExportFormat *format;
- GList *ifm;
-
- g_debug( "%s: listview=%p", thisfn, ( void * ) listview );
-
- model = gtk_tree_view_get_model( listview );
-
- for( ifm = formats ; ifm ; ifm = ifm->next ){
- format = NA_EXPORT_FORMAT( ifm->data );
- add_treeview_item( listview, model, format );
- }
-
- /* eventually add the 'Ask me' mode
- */
- if( have_ask_option( mode )){
- format = na_export_format_new( &st_ask_str );
- add_treeview_item( listview, model, format );
- g_object_unref( format );
- }
-}
-
-static void
-add_treeview_item( GtkTreeView *listview, GtkTreeModel *model, const NAExportFormat *format )
-{
- GtkTreeIter iter;
- gchar *label, *label2, *description;
- GQuark format_id;
- GdkPixbuf *pixbuf;
-
- format_id = na_export_format_get_quark( format );
- label = na_export_format_get_label( format );
- label2 = na_core_utils_str_remove_char( label, "_" );
- description = na_export_format_get_description( format );
- pixbuf = na_export_format_get_pixbuf( format );
- gtk_list_store_append( GTK_LIST_STORE( model ), &iter );
- gtk_list_store_set(
- GTK_LIST_STORE( model ),
- &iter,
- IMAGE_COLUMN, pixbuf,
- LABEL_COLUMN, label2,
- TOOLTIP_COLUMN, description,
- FORMAT_COLUMN, format_id,
- OBJECT_COLUMN, format,
- -1 );
- if( pixbuf ){
- g_object_unref( pixbuf );
- }
- g_free( label );
- g_free( label2 );
- g_free( description );
-}
-
-/**
- * nact_export_format_select:
- * @container_parent: the #GtkVBox in which the display has been drawn.
- * @editable: whether the whole radio button group is activatable.
- * @format: the #GQuark which must be used as a default value.
- *
- * Select the default value.
- *
- * This is to be ran from runtime initialization dialog.
- *
- * Data for each format has been set on the new embedding vbox, previously
- * created in nact_export_format_init_display(). We are iterating on these
- * vbox to setup the initially active radio button.
- *
- * Starting with Gtk 3.2.0, the 'container_parent' no more contains GtkVBoxes,
- * but a grid (one column, n rows) whose each row contains itself one grid
- * for each mode.
- */
-void
-nact_export_format_select( const GtkWidget *container_parent, gboolean editable, GQuark format )
-{
- GtkTreeModel *model;
-
- g_object_set_data( G_OBJECT( container_parent ), EXPORT_FORMAT_PROP_CONTAINER_EDITABLE, GUINT_TO_POINTER( editable ));
- g_object_set_data( G_OBJECT( container_parent ), EXPORT_FORMAT_PROP_CONTAINER_FORMAT, GUINT_TO_POINTER( format ));
-
- if( GTK_IS_BOX( container_parent )){
- gtk_container_foreach( GTK_CONTAINER( container_parent ),
- ( GtkCallback ) select_default_iter, GUINT_TO_POINTER( format ));
-
- } else if( GTK_IS_TREE_VIEW( container_parent )){
- model = gtk_tree_view_get_model( GTK_TREE_VIEW( container_parent ));
- gtk_tree_model_foreach( model, ( GtkTreeModelForeachFunc ) iter_on_model_for_select, ( gpointer ) container_parent );
- }
-}
-
-/*
- * container_mode is a GtkVBox, or a GtkGrid starting with Gtk 3.2
- *
- * iterating through each radio button of the group:
- * - connecting to 'toggled' signal
- * - activating the button which holds our default value
- */
-static void
-select_default_iter( GtkWidget *container_mode, void *quark_ptr )
-{
- static const gchar *thisfn = "nact_export_format_select_default_iter";
- VBoxData *vbox_data;
- GQuark format_quark;
- GtkRadioButton *button;
- gboolean editable, sensitive;
-
- vbox_data = ( VBoxData * )
- g_object_get_data( G_OBJECT( container_mode ), EXPORT_FORMAT_PROP_VBOX_DATA );
- g_debug( "%s: container_mode=%p, retrieving VBoxData at %p",
- thisfn, ( void * ) container_mode, ( void * ) vbox_data );
-
- editable = ( gboolean ) GPOINTER_TO_UINT(
- g_object_get_data( G_OBJECT( vbox_data->container_vbox ), EXPORT_FORMAT_PROP_CONTAINER_EDITABLE ));
-
- sensitive = ( gboolean ) GPOINTER_TO_UINT(
- g_object_get_data( G_OBJECT( vbox_data->container_vbox ), EXPORT_FORMAT_PROP_CONTAINER_SENSITIVE ));
-
- vbox_data->handler = g_signal_connect( G_OBJECT( vbox_data->button ), "toggled", G_CALLBACK( on_export_format_toggled ), vbox_data );
-
- button = NULL;
- format_quark = ( GQuark ) GPOINTER_TO_UINT( quark_ptr );
-
- if( na_export_format_get_quark( vbox_data->format ) == format_quark ){
- button = vbox_data->button;
- }
+static NactExportFormatStr st_format_ask = {
+ IPREFS_EXPORT_FORMAT_ASK_ID,
+ N_( "_Ask me" ),
+ N_( "You will be asked for the format to choose each time an item " \
+ "is about to be exported." ),
+ "export-format-ask.png"
+};
- if( button ){
- base_gtk_utils_radio_set_initial_state( button,
- G_CALLBACK( on_export_format_toggled ), vbox_data, editable, sensitive );
- }
-}
+static void on_pixbuf_finalized( gpointer user_data, GObject *pixbuf );
/*
- * walks through the rows of the model until the function returns %TRUE
- */
-static gboolean
-iter_on_model_for_select( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkTreeView *listview )
-{
- gboolean stop;
- GQuark format;
- GtkTreeSelection *selection;
- GQuark format_quark;
-
- stop = FALSE;
- format_quark = ( GQuark ) GPOINTER_TO_UINT(
- g_object_get_data( G_OBJECT( listview ), EXPORT_FORMAT_PROP_CONTAINER_FORMAT ));
- gtk_tree_model_get( model, iter, FORMAT_COLUMN, &format, -1 );
-
- if( format == format_quark ){
- selection = gtk_tree_view_get_selection( listview );
- gtk_tree_selection_select_iter( selection, iter );
- stop = TRUE;
- }
-
- return( stop );
-}
-
-static void
-on_export_format_toggled( GtkToggleButton *toggle_button, VBoxData *vbox_data )
-{
- gboolean editable, active;
- GQuark format;
-
- editable = ( gboolean ) GPOINTER_TO_UINT(
- g_object_get_data( G_OBJECT( vbox_data->container_vbox ), EXPORT_FORMAT_PROP_CONTAINER_EDITABLE ));
-
- if( editable ){
- active = gtk_toggle_button_get_active( toggle_button );
- if( active ){
- format = na_export_format_get_quark( vbox_data->format );
- g_object_set_data( G_OBJECT( vbox_data->container_vbox ), EXPORT_FORMAT_PROP_CONTAINER_FORMAT, GUINT_TO_POINTER( format ));
- }
- } else {
- base_gtk_utils_radio_reset_initial_state( GTK_RADIO_BUTTON( toggle_button ), NULL );
- }
-}
-
-/**
- * nact_export_format_get_selected:
- * @container_parent: the #GtkVBox in which the display has been drawn.
+ * nact_export_format_get_ask_option:
*
- * Returns: the currently selected value, as a #NAExportFormat object.
+ * Returns the 'Ask me' option.
*
- * The returned #NAExportFormat is owned by #NactExportFormat, and
- * should not be released by the caller.
+ * Since: 3.2
*/
-NAExportFormat *
-nact_export_format_get_selected( const GtkWidget *container_parent )
+NAIOption *
+nact_export_format_get_ask_option( void )
{
+ static const gchar *thisfn = "nact_export_format_get_ask_option";
+ NAIExporterFormatExt *str;
+ gint width, height;
+ gchar *fname;
NAExportFormat *format;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GList *rows;
- format = NULL;
-
- if( GTK_IS_BOX( container_parent )){
- gtk_container_foreach( GTK_CONTAINER( container_parent ), ( GtkCallback ) get_selected_iter, &format );
-
- } else if( GTK_IS_TREE_VIEW( container_parent )){
- selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( container_parent ));
- rows = gtk_tree_selection_get_selected_rows( selection, &model );
- g_return_val_if_fail( g_list_length( rows ) == 1, NULL );
- gtk_tree_model_get_iter( model, &iter, ( GtkTreePath * ) rows->data );
- gtk_tree_model_get( model, &iter, OBJECT_COLUMN, &format, -1 );
- g_object_unref( format );
- g_list_foreach( rows, ( GFunc ) gtk_tree_path_free, NULL );
- g_list_free( rows );
- }
-
- g_debug( "nact_export_format_get_selected: format=%p", ( void * ) format );
-
- return( format );
-}
-
-/*
- * container_mode is a GtkVBox, or a GtkGrid starting with Gtk 3.2
- */
-static void
-get_selected_iter( GtkWidget *container_mode, NAExportFormat **format )
-{
- VBoxData *vbox_data;
-
- if( !( *format )){
- vbox_data = ( VBoxData * ) g_object_get_data( G_OBJECT( container_mode ), EXPORT_FORMAT_PROP_VBOX_DATA );
- if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( vbox_data->button ))){
- *format = vbox_data->format;
+ if( !gtk_icon_size_lookup( GTK_ICON_SIZE_DIALOG, &width, &height )){
+ width = height = 48;
+ }
+
+ str = g_new0( NAIExporterFormatExt, 1 );
+ str->version = 2;
+ str->provider = NULL;
+ str->format = g_strdup( st_format_ask.format );
+ str->label = g_strdup( gettext( st_format_ask.label ));
+ str->description = g_strdup( gettext( st_format_ask.description ));
+ if( st_format_ask.image ){
+ fname = g_strdup_printf( "%s/%s", PKGDATADIR, st_format_ask.image );
+ str->pixbuf = gdk_pixbuf_new_from_file_at_size( fname, width, height, NULL );
+ g_free( fname );
+ if( str->pixbuf ){
+ g_debug( "%s: allocating pixbuf at %p", thisfn, str->pixbuf );
+ g_object_weak_ref( G_OBJECT( str->pixbuf ), ( GWeakNotify ) on_pixbuf_finalized, NULL );
}
}
-}
-
-static gboolean
-have_ask_option( guint mode )
-{
- static const gchar *thisfn = "nact_export_format_have_ask_option";
- gboolean have_ask;
- have_ask = FALSE;
+ format = na_export_format_new( str );
- switch( mode ){
- /* this is the mode to be used when we are about to export an item
- * and the user preference is 'Ask me'; obviously, we don't propose
- * here to ask him another time :)
- */
- case EXPORT_FORMAT_DISPLAY_ASK:
- break;
-
- case EXPORT_FORMAT_DISPLAY_PREFERENCES:
- case EXPORT_FORMAT_DISPLAY_ASSISTANT:
- have_ask = TRUE;
- break;
-
- default:
- g_warning( "%s: mode=%d: unknown mode", thisfn, mode );
+ if( str->pixbuf ){
+ g_object_unref( str->pixbuf );
}
+ g_free( str->description );
+ g_free( str->label );
+ g_free( str->format );
+ g_free( str );
- return( have_ask );
+ return( NA_IOPTION( format ));
}
-/*
- * unrealize signal is seen after finalization of the assistant
- */
static void
-on_unrealize_container_parent( GtkWidget *container, gpointer user_data )
+on_pixbuf_finalized( gpointer user_data /* ==NULL */, GObject *pixbuf )
{
- static const gchar *thisfn = "nact_export_format_on_unrealize_container_parent";
-
- g_debug( "%s: container=%p (%s)", thisfn, ( void * ) container, G_OBJECT_TYPE_NAME( container));
+ g_debug( "nact_export_format_on_pixbuf_finalized: pixbuf=%p", ( void * ) pixbuf );
}
diff --git a/src/nact/nact-export-format.h b/src/nact/nact-export-format.h
index a13730b..6115eab 100644
--- a/src/nact/nact-export-format.h
+++ b/src/nact/nact-export-format.h
@@ -33,62 +33,15 @@
/**
* SECTION: nact_export_format
- * @short_description: Displays the list of available export formats.
+ * @short_description: Provides the 'Ask me' special export format.
* @include: nact/nact-export-format.h
- *
- * This class manages the available export formats, providing functions
- * to display them, and select one of them.
- * Depending on the current display mode, it also features a special
- * 'Ask me' mode.
- *
- * Export formats are defined by their respective I/O providers
- * (see e.g. src/io-xml/naxml-formats.c or src/io-desktop/nadp-formats.c).
- * Each export format must have at least a (short) label, and should have
- * a full description.
*/
-#include <gtk/gtk.h>
-
-#include <core/na-export-format.h>
-#include <core/na-pivot.h>
+#include <core/na-ioption.h>
G_BEGIN_DECLS
-enum {
- /* At export time, when the user has required to be asked for the
- * exact format of each exported item (NactExportAsk dialog):
- * - display the (short) label of the format
- * - do not display the full description (but set the tooltip)
- * - do not propose the 'Ask me' choice
- */
- EXPORT_FORMAT_DISPLAY_ASK = 1,
-
- /* When running the export assistant, display the available export
- * formats to let the user pick one of them (NactAssistantExport):
- * - display the (short) label
- * - display the full description (and set the tooltip)
- * - propose the 'Ask me' choice
- */
- EXPORT_FORMAT_DISPLAY_ASSISTANT,
-
- /* When tuning the user's preferences (NactPreferencesEditor):
- * - display the (short) label
- * - do not display the full description (but set the tooltip)
- * - propose the 'Ask me' choice
- */
- EXPORT_FORMAT_DISPLAY_PREFERENCES,
-};
-
-void nact_export_format_init_display(
- GtkWidget *container_parent,
- const NAPivot *pivot, guint mode, gboolean sensitive );
-
-void nact_export_format_select (
- const GtkWidget *container_parent,
- gboolean editable, GQuark format );
-
-NAExportFormat *nact_export_format_get_selected(
- const GtkWidget *container_parent );
+NAIOption *nact_export_format_get_ask_option( void );
G_END_DECLS
diff --git a/src/nact/nact-preferences-editor.c b/src/nact/nact-preferences-editor.c
index 559d73e..0e01fb9 100644
--- a/src/nact/nact-preferences-editor.c
+++ b/src/nact/nact-preferences-editor.c
@@ -38,7 +38,10 @@
#include <api/na-iimporter.h>
#include <core/na-desktop-environment.h>
+#include <core/na-exporter.h>
+#include <core/na-export-format.h>
#include <core/na-gtk-utils.h>
+#include <core/na-ioptions-list.h>
#include <core/na-iprefs.h>
#include <core/na-tokens.h>
@@ -121,51 +124,54 @@ static const gchar *st_wsp_name = NA_IPREFS_PREFERENCES_WSP;
static GObjectClass *st_parent_class = NULL;
static guint st_last_tab = 0;
-static GType register_type( void );
-static void class_init( NactPreferencesEditorClass *klass );
-static void instance_init( GTypeInstance *instance, gpointer klass );
-static void instance_dispose( GObject *dialog );
-static void instance_finalize( GObject *dialog );
-
-static void on_base_initialize_gtk_toplevel( NactPreferencesEditor *editor, GtkDialog *toplevel );
-static void on_base_initialize_base_window( NactPreferencesEditor *editor );
-static void on_base_all_widgets_showed( NactPreferencesEditor *editor );
-static void order_mode_setup( NactPreferencesEditor *editor );
-static void order_mode_on_alpha_asc_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
-static void order_mode_on_alpha_desc_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
-static void order_mode_on_manual_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
-static void order_mode_on_toggled( NactPreferencesEditor *editor, GtkToggleButton *togglebutton, GCallback cb, guint order_mode );
-static void root_menu_setup( NactPreferencesEditor *editor );
-static void root_menu_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
-static void about_item_setup( NactPreferencesEditor *editor );
-static void about_item_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
-static void terminal_pattern_setup( NactPreferencesEditor *editor );
-static void terminal_pattern_on_changed( GtkEntry *entry, NactPreferencesEditor *editor );
-static void desktop_create_model( NactPreferencesEditor *editor );
-static void desktop_setup( NactPreferencesEditor *editor );
-static void desktop_on_changed( GtkComboBox *combo, NactPreferencesEditor *editor );
-static void relabel_menu_setup( NactPreferencesEditor *editor );
-static void relabel_menu_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
-static void relabel_action_setup( NactPreferencesEditor *editor );
-static void relabel_action_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
-static void relabel_profile_setup( NactPreferencesEditor *editor );
-static void relabel_profile_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
-static void esc_quit_setup( NactPreferencesEditor *editor );
-static void esc_quit_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
-static void esc_confirm_setup( NactPreferencesEditor *editor );
-static void esc_confirm_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
-static void auto_save_setup( NactPreferencesEditor *editor );
-static void auto_save_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
-static void auto_save_period_on_change_value( GtkSpinButton *spinbutton, NactPreferencesEditor *editor );
-static void import_mode_setup( NactPreferencesEditor *editor );
-static void import_mode_on_ask_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
-static void import_mode_on_override_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
-static void import_mode_on_renumber_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
-static void import_mode_on_noimport_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
-static void import_mode_on_toggled( NactPreferencesEditor *editor, GtkToggleButton *togglebutton, GCallback cb, guint import_mode );
-static void on_cancel_clicked( GtkButton *button, NactPreferencesEditor *editor );
-static void on_ok_clicked( GtkButton *button, NactPreferencesEditor *editor );
-static void on_dialog_ok( BaseDialog *dialog );
+static GType register_type( void );
+static void class_init( NactPreferencesEditorClass *klass );
+static void ioptions_list_iface_init( NAIOptionsListInterface *iface );
+static GList *ioptions_list_get_formats( const NAIOptionsList *instance, GtkWidget *container );
+static void ioptions_list_free_formats( const NAIOptionsList *instance, GList *formats );
+static NAIOption *ioptions_list_get_ask_option( const NAIOptionsList *instance, GtkWidget *container );
+static void instance_init( GTypeInstance *instance, gpointer klass );
+static void instance_dispose( GObject *dialog );
+static void instance_finalize( GObject *dialog );
+static void on_base_initialize_gtk_toplevel( NactPreferencesEditor *editor, GtkDialog *toplevel );
+static void on_base_initialize_base_window( NactPreferencesEditor *editor );
+static void on_base_all_widgets_showed( NactPreferencesEditor *editor );
+static void order_mode_setup( NactPreferencesEditor *editor );
+static void order_mode_on_alpha_asc_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
+static void order_mode_on_alpha_desc_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
+static void order_mode_on_manual_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
+static void order_mode_on_toggled( NactPreferencesEditor *editor, GtkToggleButton *togglebutton, GCallback cb, guint order_mode );
+static void root_menu_setup( NactPreferencesEditor *editor );
+static void root_menu_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
+static void about_item_setup( NactPreferencesEditor *editor );
+static void about_item_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
+static void terminal_pattern_setup( NactPreferencesEditor *editor );
+static void terminal_pattern_on_changed( GtkEntry *entry, NactPreferencesEditor *editor );
+static void desktop_create_model( NactPreferencesEditor *editor );
+static void desktop_setup( NactPreferencesEditor *editor );
+static void desktop_on_changed( GtkComboBox *combo, NactPreferencesEditor *editor );
+static void relabel_menu_setup( NactPreferencesEditor *editor );
+static void relabel_menu_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
+static void relabel_action_setup( NactPreferencesEditor *editor );
+static void relabel_action_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
+static void relabel_profile_setup( NactPreferencesEditor *editor );
+static void relabel_profile_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
+static void esc_quit_setup( NactPreferencesEditor *editor );
+static void esc_quit_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
+static void esc_confirm_setup( NactPreferencesEditor *editor );
+static void esc_confirm_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
+static void auto_save_setup( NactPreferencesEditor *editor );
+static void auto_save_on_toggled( GtkToggleButton *button, NactPreferencesEditor *editor );
+static void auto_save_period_on_change_value( GtkSpinButton *spinbutton, NactPreferencesEditor *editor );
+static void import_mode_setup( NactPreferencesEditor *editor );
+static void import_mode_on_ask_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
+static void import_mode_on_override_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
+static void import_mode_on_renumber_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
+static void import_mode_on_noimport_toggled( GtkToggleButton *togglebutton, NactPreferencesEditor *editor );
+static void import_mode_on_toggled( NactPreferencesEditor *editor, GtkToggleButton *togglebutton, GCallback cb, guint import_mode );
+static void on_cancel_clicked( GtkButton *button, NactPreferencesEditor *editor );
+static void on_ok_clicked( GtkButton *button, NactPreferencesEditor *editor );
+static void on_dialog_ok( BaseDialog *dialog );
GType
nact_preferences_editor_get_type( void )
@@ -197,10 +203,18 @@ register_type( void )
( GInstanceInitFunc ) instance_init
};
+ static const GInterfaceInfo ioptions_list_iface_info = {
+ ( GInterfaceInitFunc ) ioptions_list_iface_init,
+ NULL,
+ NULL
+ };
+
g_debug( "%s", thisfn );
type = g_type_register_static( BASE_DIALOG_TYPE, "NactPreferencesEditor", &info, 0 );
+ g_type_add_interface_static( type, NA_IOPTIONS_LIST_TYPE, &ioptions_list_iface_info );
+
return( type );
}
@@ -226,6 +240,48 @@ class_init( NactPreferencesEditorClass *klass )
}
static void
+ioptions_list_iface_init( NAIOptionsListInterface *iface )
+{
+ static const gchar *thisfn = "nact_assistant_export_ioptions_list_iface_init";
+
+ g_debug( "%s: iface=%p", thisfn, ( void * ) iface );
+
+ iface->get_options = ioptions_list_get_formats;
+ iface->free_options = ioptions_list_free_formats;
+ iface->get_ask_option = ioptions_list_get_ask_option;
+}
+
+static GList *
+ioptions_list_get_formats( const NAIOptionsList *instance, GtkWidget *container )
+{
+ NactPreferencesEditor *window;
+ NactApplication *application;
+ NAUpdater *updater;
+ GList *formats;
+
+ g_return_val_if_fail( NACT_IS_PREFERENCES_EDITOR( instance ), NULL );
+ window = NACT_PREFERENCES_EDITOR( instance );
+
+ application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( window )));
+ updater = nact_application_get_updater( application );
+ formats = na_exporter_get_formats( NA_PIVOT( updater ));
+
+ return( formats );
+}
+
+static void
+ioptions_list_free_formats( const NAIOptionsList *instance, GList *formats )
+{
+ na_exporter_free_formats( formats );
+}
+
+static NAIOption *
+ioptions_list_get_ask_option( const NAIOptionsList *instance, GtkWidget *container )
+{
+ return( nact_export_format_get_ask_option());
+}
+
+static void
instance_init( GTypeInstance *instance, gpointer klass )
{
static const gchar *thisfn = "nact_preferences_editor_instance_init";
@@ -316,10 +372,16 @@ nact_preferences_editor_run( BaseWindow *parent )
g_debug( "%s: parent=%p (%s)", thisfn, ( void * ) parent, G_OBJECT_TYPE_NAME( parent ));
editor = g_object_new( NACT_PREFERENCES_EDITOR_TYPE,
- BASE_PROP_PARENT, parent,
- BASE_PROP_XMLUI_FILENAME, st_xmlui_filename,
- BASE_PROP_TOPLEVEL_NAME, st_toplevel_name,
- BASE_PROP_WSP_NAME, st_wsp_name,
+ BASE_PROP_PARENT, parent,
+ BASE_PROP_XMLUI_FILENAME, st_xmlui_filename,
+ /*
+ * having our own builder let us, e.g., set a weak reference on
+ * pixbufs allocated by plugins - but this way we are losing
+ * mutualization of gtk initializations...
+ */
+ /*BASE_PROP_HAS_OWN_BUILDER, TRUE,*/
+ BASE_PROP_TOPLEVEL_NAME, st_toplevel_name,
+ BASE_PROP_WSP_NAME, st_wsp_name,
NULL );
are_locked = na_settings_get_boolean( NA_IPREFS_ADMIN_PREFERENCES_LOCKED, NULL, &mandatory );
@@ -355,9 +417,7 @@ on_base_initialize_gtk_toplevel( NactPreferencesEditor *editor, GtkDialog *tople
desktop_create_model( editor );
container = base_window_get_widget( BASE_WINDOW( editor ), "PreferencesExportFormatVBox" );
- nact_export_format_init_display(
- container, NA_PIVOT( updater ),
- EXPORT_FORMAT_DISPLAY_PREFERENCES, !editor->private->preferences_locked );
+ na_ioptions_list_gtk_init( NA_IOPTIONS_LIST( editor ), container, TRUE );
listview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( editor ), "SchemesTreeView" ));
nact_schemes_list_create_model( listview, SCHEMES_LIST_FOR_PREFERENCES );
@@ -375,8 +435,8 @@ static void
on_base_initialize_base_window( NactPreferencesEditor *editor )
{
static const gchar *thisfn = "nact_preferences_editor_on_base_initialize_base_window";
- GtkWidget *container;
GQuark export_format;
+ GtkWidget *container;
GtkTreeView *listview;
GtkWidget *ok_button;
@@ -411,9 +471,14 @@ on_base_initialize_base_window( NactPreferencesEditor *editor )
/* fifth tab: export format
*/
- export_format = na_iprefs_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, &editor->private->export_format_mandatory );
container = base_window_get_widget( BASE_WINDOW( editor ), "PreferencesExportFormatVBox" );
- nact_export_format_select( container, !editor->private->export_format_mandatory, export_format );
+ export_format = na_iprefs_get_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, &editor->private->export_format_mandatory );
+ na_ioptions_list_set_editable(
+ NA_IOPTIONS_LIST( editor ), container,
+ !editor->private->export_format_mandatory && !editor->private->preferences_locked );
+ na_ioptions_list_set_default(
+ NA_IOPTIONS_LIST( editor ), container,
+ g_quark_to_string( export_format ));
/* sixth tab: default schemes
*/
@@ -1090,8 +1155,8 @@ static void
on_dialog_ok( BaseDialog *dialog )
{
NactPreferencesEditor *editor;
+ NAIOption *export_format;
GtkWidget *container;
- NAExportFormat *export_format;
g_return_if_fail( NACT_IS_PREFERENCES_EDITOR( dialog ));
@@ -1154,8 +1219,9 @@ on_dialog_ok( BaseDialog *dialog )
*/
if( !editor->private->export_format_mandatory ){
container = base_window_get_widget( BASE_WINDOW( editor ), "PreferencesExportFormatVBox" );
- export_format = nact_export_format_get_selected( container );
- na_iprefs_set_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, na_export_format_get_quark( export_format ));
+ export_format = na_ioptions_list_get_selected( NA_IOPTIONS_LIST( editor ), container );
+ g_return_if_fail( NA_IS_EXPORT_FORMAT( export_format ));
+ na_iprefs_set_export_format( NA_IPREFS_EXPORT_PREFERRED_FORMAT, na_export_format_get_quark( NA_EXPORT_FORMAT( export_format )));
}
/* sixth tab: list of default schemes
diff --git a/src/utils/nautilus-actions-print.c b/src/utils/nautilus-actions-print.c
index bb28f45..66da299 100644
--- a/src/utils/nautilus-actions-print.c
+++ b/src/utils/nautilus-actions-print.c
@@ -44,6 +44,7 @@
#include <core/na-exporter.h>
#include <core/na-export-format.h>
+#include <core/na-ioption.h>
#include "console-utils.h"
@@ -138,7 +139,7 @@ main( int argc, char** argv )
for( it = formats_list ; it && !format_found ; it = it->next ){
NAExportFormat *export = NA_EXPORT_FORMAT( it->data );
- gchar *export_id = na_export_format_get_id( export );
+ gchar *export_id = na_ioption_get_id( NA_IOPTION( export ));
format_found = !strcmp( export_id, format );
g_free( export_id );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]