[nautilus-actions] Refactoring: update export treatments
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Refactoring: update export treatments
- Date: Fri, 19 Feb 2010 02:27:41 +0000 (UTC)
commit 956fb45dac268a7cc19325bc188055bab618321e
Author: Pierre Wieser <pwieser trychlos org>
Date: Wed Feb 17 10:35:40 2010 +0100
Refactoring: update export treatments
ChangeLog | 5 +
src/core/na-exporter.c | 134 +++++++++++++++++
src/core/na-exporter.h | 53 +++++++
src/nact/nact-export-format.c | 331 +++++++++++++++++++++++++++++++++++++++++
src/nact/nact-export-format.h | 71 +++++++++
5 files changed, 594 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2f8b0ae..db6860e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2009-02-17 Pierre Wieser <pwieser trychlos org>
+ * src/nact/nact-export-format.h:
+ * src/nact/nact-export-format.c:
+ * src/core/na-exporter.h:
+ * src/core/na-exporter.c: Update export treatements.
+
* src/api/na-iexporter.h:
* src/core/na-iexporter.c:
* src/io-xml/naxml-module.c:
diff --git a/src/core/na-exporter.c b/src/core/na-exporter.c
new file mode 100644
index 0000000..1a78bc0
--- /dev/null
+++ b/src/core/na-exporter.c
@@ -0,0 +1,134 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ * Frederic Ruaudel <grumz grumz net>
+ * Rodrigo Moya <rodrigo gnome-db org>
+ * Pierre Wieser <pwieser trychlos org>
+ * ... and many others (see AUTHORS)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <api/na-iexporter.h>
+
+#include "na-exporter.h"
+#include "na-export-format.h"
+
+extern gboolean iexporter_initialized;
+extern gboolean iexporter_finalized;
+
+static const NAExporterStr *exporter_get_formats( const NAIExporter *exporter );
+
+/**
+ * na_exporter_get_formats:
+ * @pivot: the #NAPivot instance.
+ *
+ * Returns: a list of #NAExportFormat objects, each of them addressing an
+ * available export format, i.e. a format provided by a module which
+ * implement the #NAIExporter interface.
+ */
+GList *
+na_exporter_get_formats( const NAPivot *pivot )
+{
+ GList *iexporters, *imod;
+ GList *formats;
+ const NAExporterStr *str;
+ NAExportFormat *format;
+
+ formats = NULL;
+
+ if( iexporter_initialized && !iexporter_finalized ){
+
+ iexporters = na_pivot_get_providers( pivot, NA_IEXPORTER_TYPE );
+ for( imod = iexporters ; imod ; imod = imod->next ){
+
+ str = exporter_get_formats( NA_IEXPORTER( imod->data ));
+ while( str->format ){
+
+ format = na_export_format_new( str, NA_IEXPORTER( imod->data ));
+ formats = g_list_prepend( formats, format );
+ }
+ }
+
+ na_pivot_free_providers( iexporters );
+ }
+
+ return( formats );
+}
+
+static const NAExporterStr *
+exporter_get_formats( const NAIExporter *exporter )
+{
+ const NAExporterStr *str;
+
+ str = NULL;
+
+ if( NA_IEXPORTER_GET_INTERFACE( exporter )->get_formats ){
+ str = NA_IEXPORTER_GET_INTERFACE( exporter )->get_formats( exporter );
+ }
+
+ return( str );
+}
+
+/**
+ * na_exporter_free_formats:
+ * @formats: a list of available export formats, as returned by
+ * #na_exporter_get_formats().
+ *
+ * Release the @formats #GList.
+ */
+void
+na_exporter_free_formats( GList *formats )
+{
+ g_list_foreach( formats, ( GFunc ) g_object_unref, NULL );
+ g_list_free( formats );
+}
+
+/**
+ * na_exporter_export:
+ * @item: a #NAObjectItem-derived object.
+ * @uri: the target URI.
+ * @format: the target format.
+ * @messages: a pointer to a #GSList list of strings; the provider
+ * may append messages to this list, but shouldn't reinitialize it.
+ *
+ * Exports the specified @item to the target @uri in the required @format.
+ *
+ * Returns: the URI of the exportered file, as a newly allocated string which
+ * should be g_free() by the caller, or %NULL if an error has been detected.
+ */
+gchar *
+na_exporter_export( const NAObjectItem *item, const gchar *uri, guint format, GSList **messages )
+{
+ gchar *fname;
+
+ fname = NULL;
+
+ if( iexporter_initialized && !iexporter_finalized ){
+ }
+
+ return( fname );
+}
diff --git a/src/core/na-exporter.h b/src/core/na-exporter.h
new file mode 100644
index 0000000..588874a
--- /dev/null
+++ b/src/core/na-exporter.h
@@ -0,0 +1,53 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ * Frederic Ruaudel <grumz grumz net>
+ * Rodrigo Moya <rodrigo gnome-db org>
+ * Pierre Wieser <pwieser trychlos org>
+ * ... and many others (see AUTHORS)
+ */
+
+#ifndef __CORE_NA_EXPORTER_H__
+#define __CORE_NA_EXPORTER_H__
+
+/**
+ * SECTION: na_iexporter
+ * @short_description: #NAIExporter internal functions.
+ * @include: core/na-exporter.h
+ */
+
+#include <api/na-object-item.h>
+
+#include <core/na-pivot.h>
+
+G_BEGIN_DECLS
+
+GList *na_exporter_get_formats ( const NAPivot *pivot );
+void na_exporter_free_formats( GList *formats );
+
+gchar *na_exporter_export( const NAObjectItem *item, const gchar *uri, guint format, GSList **messages );
+
+G_END_DECLS
+
+#endif /* __CORE_NA_EXPORTER_H__ */
diff --git a/src/nact/nact-export-format.c b/src/nact/nact-export-format.c
new file mode 100755
index 0000000..47efc8b
--- /dev/null
+++ b/src/nact/nact-export-format.c
@@ -0,0 +1,331 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ * Frederic Ruaudel <grumz grumz net>
+ * Rodrigo Moya <rodrigo gnome-db org>
+ * Pierre Wieser <pwieser trychlos org>
+ * ... and many others (see AUTHORS)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+
+#include <core/na-exporter.h>
+#include <core/na-export-format.h>
+
+#define EXPORT_FORMAT_PROP_QUARK_ID "nact-export-format-prop-quark-id"
+#define EXPORT_FORMAT_PROP_BUTTON "nact-export-format-prop-button"
+#define EXPORT_FORMAT_PROP_LABEL "nact-export-format-prop-label"
+#define EXPORT_FORMAT_PROP_DESCRIPTION "nact-export-format-prop-description"
+
+#define ASKME_LABEL N_( "Ask me" )
+#define ASKME_DESCRIPTION N_( "You will be asked each time an item is about to be exported." )
+
+/* structure used when iterating on container's children
+ */
+typedef struct {
+ GQuark format;
+ gboolean found;
+ gchar *label;
+ guint prop;
+}
+ NactExportFormatStr;
+
+static void draw_in_vbox( const NAExportFormat *format, GtkWidget *vbox, guint mode );
+static void select_default_iter( GtkWidget *widget, NactExportFormatStr *str );
+static void get_selected_iter( GtkWidget *widget, NactExportFormatStr *str );
+static void get_label_iter( GtkWidget *widget, NactExportFormatStr *str );
+
+/**
+ * nact_export_format_display:
+ * @pivot: the #NAPivot instance.
+ * @vbox: the #GtkVBox in which the display must be drawn.
+ * @mode: the type of the display.
+ *
+ * Displays the available export formats in the VBox
+ */
+void
+nact_export_format_display( const NAPivot *pivot, GtkWidget *vbox, guint mode )
+{
+ GList *formats, *ifmt;
+ NAExporterStr *str;
+
+ formats = na_exporter_get_formats( pivot );
+
+ for( ifmt = formats ; ifmt ; ifmt = ifmt->next ){
+ draw_in_vbox( NA_EXPORT_FORMAT( ifmt->data ), vbox, mode );
+ }
+
+ na_exporter_free_formats( formats );
+}
+
+/*
+ * container
+ * +- vbox
+ * | +- hbox
+ * | | +- radio button
+ * | | +- label
+ * | +- hbox
+ * | | +- description
+ */
+static void
+draw_in_vbox( const NAExportFormat *format, GtkWidget *container, guint mode )
+{
+ static const gchar *thisfn = "nact_export_format_draw_in_vbox";
+ static GtkRadioButton first_button = NULL;
+ GtkVBox *vbox;
+ gchar *description;
+ GtkHBox *hbox1, *hbox2;
+ GtkRadioButton *button;
+ guint indicator_size;
+ GtkLabel *radio_label;
+ gchar *markup, *label;
+ GtkLabel *desc_label;
+
+ vbox = GTK_VBOX( gtk_vbox_new( FALSE, 0 ));
+ gtk_box_pack_start( container, GTK_WIDGET( vbox ), FALSE, TRUE, 0 );
+ description = na_export_format_get_description( format );
+ g_object_set( G_OBJECT( vbox ), "tooltip-text", description, NULL );
+
+ hbox1 = GTK_HBOX( gtk_hbox_new( FALSE, 0 ));
+ gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox1 ), FALSE, TRUE, 0 );
+
+ 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;
+ }
+ gtk_box_pack_start( GTK_BOX( hbox1 ), GTK_WIDGET( button ), FALSE, TRUE, 0 );
+
+ radio_label = GTK_LABEL( gtk_label_new( NULL ));
+ label = NULL;
+ markup = NULL;
+ switch( mode ){
+
+ case EXPORT_FORMAT_DISPLAY_ASK:
+ label = na_export_format_get_ask_label( format );
+ markup = g_markup_printf_escaped( "%s", label );
+ break;
+
+ case EXPORT_FORMAT_DISPLAY_ASSISTANT:
+ label = na_export_format_get_label( format );
+ markup = g_markup_printf_escaped( "<b>%s</b>", label );
+ break;
+
+ default:
+ g_warning( "%s: mode=%d: unknown mode", thisfn, mode );
+ }
+ if( markup ){
+ gtk_label_set_markup( radio_label, markup );
+ g_free( markup );
+ }
+ gtk_box_pack_start( GTK_BOX( hbox1 ), GTK_WIDGET( radio_label ), FALSE, TRUE, 0 );
+
+ desc_label = NULL;
+ switch( mode ){
+
+ case EXPORT_FORMAT_DISPLAY_ASSISTANT:
+ /* TODO: get radio button indicator size */
+ /*g_object_get( G_OBJECT( GTK_CHECK_BUTTON( button )), "indicator-size", &indicator_size, NULL );*/
+ indicator_size = 17;
+ hbox2 = GTK_HBOX( gtk_hbox_new( TRUE, 0 ));
+ gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox2 ), FALSE, TRUE, 0 );
+ desc_label = GTK_LABEL( gtk_label_new( description ));
+ g_object_set( G_OBJECT( desc_label ), "xpad", indicator_size, NULL );
+ gtk_box_pack_start( GTK_BOX( hbox2 ), GTK_WIDGET( desc_label ), TRUE, TRUE, 4 );
+ break;
+ }
+
+ g_object_set_data( G_OBJECT( vbox ), EXPORT_FORMAT_PROP_QUARK_ID, GUINT_TO_POINTER( na_export_format_get_id( format )));
+ g_object_set_data( G_OBJECT( vbox ), EXPORT_FORMAT_PROP_BUTTON, button );
+ g_object_set_data( G_OBJECT( vbox ), EXPORT_FORMAT_PROP_LABEL, radio_label );
+ g_object_set_data( G_OBJECT( vbox ), EXPORT_FORMAT_PROP_DESCRIPTION, desc_label );
+
+ g_free( label );
+ g_free( description );
+}
+
+/**
+ * nact_export_format_select:
+ * @container: the #GtkVBox in which the display has been drawn.
+ * @format: the #GQuark which must be used as a default value.
+ *
+ * Select the default value.
+ */
+void
+nact_export_format_select( GtkWidget *container, GQuark format )
+{
+ NactExportFormatStr *str;
+
+ str = g_new0( NactExportFormatStr, 1 );
+ str->format = format;
+ str->found = FALSE;
+
+ gtk_container_foreach( GTK_CONTAINER( container ), G_CALLBACK( select_default_iter ), str );
+
+ g_free( str );
+}
+
+static void
+select_default_iter( GtkWidget *widget, NactExportFormatStr *str )
+{
+ GQuark format;
+ GtkRadioButton *button;
+
+ if( !str->found ){
+ format = ( GQuark ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( widget ), EXPORT_FORMAT_PROP_QUARK_ID ));
+ if( format == str->format ){
+ str->found = TRUE;
+ button = GTK_RADIO_BUTTON( g_object_get_data( G_OBJECT( widget ), EXPORT_FORMAT_PROP_BUTTON ));
+ gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
+ }
+ }
+}
+
+/**
+ * nact_export_format_get_select:
+ * @container: the #GtkVBox in which the display has been drawn.
+ *
+ * Returns: the currently selected value, as a #GQuark.
+ */
+GQuark
+nact_export_format_get_select( GtkWidget *container )
+{
+ GQuark format;
+ NactExportFormatStr *str;
+
+ format = 0;
+
+ str = g_new0( NactExportFormatStr, 1 );
+ str->format = 0;
+ str->found = FALSE;
+
+ gtk_container_foreach( GTK_CONTAINER( container ), G_CALLBACK( get_selected_iter ), str );
+
+ if( str->found ){
+ format = str->format;
+ }
+
+ g_free( str );
+
+ return( format );
+}
+
+static void
+get_selected_iter( GtkWidget *widget, NactExportFormatStr *str )
+{
+ GQuark format;
+ GtkRadioButton *button;
+
+ if( !str->found ){
+ button = GTK_RADIO_BUTTON( g_object_get_data( G_OBJECT( widget ), EXPORT_FORMAT_PROP_BUTTON ));
+ if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( button ))){
+ str->found = TRUE;
+ str->format = ( GQuark ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( widget ), EXPORT_FORMAT_PROP_QUARK_ID ));
+ }
+ }
+}
+
+/**
+ * nact_export_format_get_label:
+ * @format: the #GQuark selected format.
+ *
+ * Returns: the label of the @format, as a newly allocated string which
+ * should be g_free() by the caller.
+ */
+gchar *
+nact_export_format_get_label( GQuark format )
+{
+ gchar *label;
+ NactExportFormatStr *str;
+
+ label = NULL;
+
+ str = g_new0( NactExportFormatStr, 1 );
+ str->format = format;
+ str->found = FALSE;
+ str->prop = EXPORT_FORMAT_PROP_LABEL;
+
+ gtk_container_foreach( GTK_CONTAINER( container ), G_CALLBACK( get_label_iter ), str );
+
+ if( str->found ){
+ label = str->label;
+ }
+
+ g_free( str );
+
+ return( label );
+}
+
+/**
+ * nact_export_format_get_description:
+ * @format: the #GQuark selected format.
+ *
+ * Returns: the description of the @format, as a newly allocated string which
+ * should be g_free() by the caller.
+ */
+gchar *
+nact_export_format_get_description( GQuark format )
+{
+ gchar *label;
+ NactExportFormatStr *str;
+
+ label = NULL;
+
+ str = g_new0( NactExportFormatStr, 1 );
+ str->format = format;
+ str->found = FALSE;
+ str->prop = EXPORT_FORMAT_PROP_DESCRIPTION;
+
+ gtk_container_foreach( GTK_CONTAINER( container ), G_CALLBACK( get_label_iter ), str );
+
+ if( str->found ){
+ label = str->label;
+ }
+
+ g_free( str );
+
+ return( label );
+}
+
+static void
+get_label_iter( GtkWidget *widget, NactExportFormatStr *str )
+{
+ GQuark format;
+ GtkLabel *gtk_label;
+ gchar *label;
+
+ if( !str->found ){
+ format = ( GQuark ) GPOINTER_TO_UINT( g_object_get_data( G_OBJECT( widget ), EXPORT_FORMAT_PROP_QUARK_ID ));
+ if( format == str->format ){
+ str->found = TRUE;
+ gtk_label = GTK_LABEL( g_object_get_data( G_OBJECT( widget ), str->prop ));
+ str->label = g_strdup( gtk_label_get_text( gtk_label ));
+ }
+ }
+}
diff --git a/src/nact/nact-export-format.h b/src/nact/nact-export-format.h
new file mode 100644
index 0000000..6459af1
--- /dev/null
+++ b/src/nact/nact-export-format.h
@@ -0,0 +1,71 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * This Program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this Library; see the file COPYING. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ * Frederic Ruaudel <grumz grumz net>
+ * Rodrigo Moya <rodrigo gnome-db org>
+ * Pierre Wieser <pwieser trychlos org>
+ * ... and many others (see AUTHORS)
+ */
+
+#ifndef __NACT_EXPORT_FORMAT_H__
+#define __NACT_EXPORT_FORMAT_H__
+
+/**
+ * SECTION: nact_export_format
+ * @short_description: Displays the list of available export formats.
+ * @include: nact/nact-export-format.h
+ */
+
+#include <gtk/gtk.h>
+
+#include <core/na-pivot.h>
+
+G_BEGIN_DECLS
+
+enum {
+ /* ask for export format dialog box
+ * only display the 'ask_label' short export format label
+ * do not display the full description
+ * do not propose the 'Ask me' choice
+ */
+ EXPORT_FORMAT_DISPLAY_ASK = 1,
+
+ /* export assistant
+ * display the assistant short label in bold
+ * display the full description
+ * propose the 'Ask me' choice
+ */
+ EXPORT_FORMAT_DISPLAY_ASSISTANT,
+};
+
+void nact_export_format_display( const NAPivot *pivot, GtkWidget *container, guint mode );
+void nact_export_format_select( GtkWidget *container, GQuark format );
+GQuark nact_export_format_get_select( GtkWidget *container );
+
+gchar *nact_export_format_get_label( GQuark format );
+gchar *nact_export_format_get_description( GQuark format );
+
+G_END_DECLS
+
+#endif /* __NACT_EXPORT_FORMAT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]