app: port gimpconfig-dump.c to GIO

This commit is contained in:
Michael Natterer 2014-08-12 12:59:12 +02:00
parent 416059a3f5
commit 26f45822e7
3 changed files with 50 additions and 29 deletions

View File

@ -178,6 +178,8 @@ gimpconsoleldadd = \
$(PANGOCAIRO_LIBS) \ $(PANGOCAIRO_LIBS) \
$(HARFBUZZ_LIBS) \ $(HARFBUZZ_LIBS) \
$(CAIRO_LIBS) \ $(CAIRO_LIBS) \
$(GIO_UNIX_LIBS) \
$(GIO_WINDOWS_LIBS) \
$(GEGL_LIBS) \ $(GEGL_LIBS) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(GEXIV2_LIBS) \ $(GEXIV2_LIBS) \

View File

@ -14,6 +14,8 @@ AM_CPPFLAGS = \
-I$(top_srcdir) \ -I$(top_srcdir) \
-I$(top_builddir)/app \ -I$(top_builddir)/app \
-I$(top_srcdir)/app \ -I$(top_srcdir)/app \
$(GIO_UNIX_CFLAGS) \
$(GIO_WINDOWS_CFLAGS) \
$(GEGL_CFLAGS) \ $(GEGL_CFLAGS) \
$(CAIRO_CFLAGS) \ $(CAIRO_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \ $(GDK_PIXBUF_CFLAGS) \

View File

@ -23,22 +23,20 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <cairo.h> #include <cairo.h>
#include <gegl.h> #include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#ifdef G_OS_WIN32
#include <gio/gwin32outputstream.h>
#else
#include <gio/gunixoutputstream.h>
#endif
#include "libgimpbase/gimpbase.h" #include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h" #include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h" #include "libgimpconfig/gimpconfig.h"
#ifdef G_OS_WIN32
#include "libgimpbase/gimpwin32-io.h"
#endif
#include "config-types.h" #include "config-types.h"
#include "gimpconfig-dump.h" #include "gimpconfig-dump.h"
@ -48,23 +46,31 @@
static void dump_gimprc_system (GimpConfig *rc, static void dump_gimprc_system (GimpConfig *rc,
GimpConfigWriter *writer, GimpConfigWriter *writer,
gint fd); GOutputStream *output);
static void dump_gimprc_manpage (GimpConfig *rc, static void dump_gimprc_manpage (GimpConfig *rc,
GimpConfigWriter *writer, GimpConfigWriter *writer,
gint fd); GOutputStream *output);
static gchar * dump_describe_param (GParamSpec *param_spec); static gchar * dump_describe_param (GParamSpec *param_spec);
static void dump_with_linebreaks (gint fd, static void dump_with_linebreaks (GOutputStream *output,
const gchar *text); const gchar *text);
gboolean gboolean
gimp_config_dump (GimpConfigDumpFormat format) gimp_config_dump (GimpConfigDumpFormat format)
{ {
GOutputStream *output;
GimpConfigWriter *writer; GimpConfigWriter *writer;
GimpConfig *rc; GimpConfig *rc;
rc = g_object_new (GIMP_TYPE_RC, NULL); rc = g_object_new (GIMP_TYPE_RC, NULL);
writer = gimp_config_writer_new_fd (1);
#ifdef G_OS_WIN32
output = g_win32_output_stream_new ((gpointer) 1, FALSE);
#else
output = g_unix_output_stream_new (1, FALSE);
#endif
writer = gimp_config_writer_new_stream (output, NULL, NULL);
switch (format) switch (format)
{ {
@ -80,15 +86,16 @@ gimp_config_dump (GimpConfigDumpFormat format)
break; break;
case GIMP_CONFIG_DUMP_GIMPRC_SYSTEM: case GIMP_CONFIG_DUMP_GIMPRC_SYSTEM:
dump_gimprc_system (rc, writer, 1); dump_gimprc_system (rc, writer, output);
break; break;
case GIMP_CONFIG_DUMP_GIMPRC_MANPAGE: case GIMP_CONFIG_DUMP_GIMPRC_MANPAGE:
dump_gimprc_manpage (rc, writer, 1); dump_gimprc_manpage (rc, writer, output);
break; break;
} }
gimp_config_writer_finish (writer, NULL, NULL); gimp_config_writer_finish (writer, NULL, NULL);
g_object_unref (output);
g_object_unref (rc); g_object_unref (rc);
return TRUE; return TRUE;
@ -113,7 +120,7 @@ static const gchar system_gimprc_header[] =
static void static void
dump_gimprc_system (GimpConfig *rc, dump_gimprc_system (GimpConfig *rc,
GimpConfigWriter *writer, GimpConfigWriter *writer,
gint fd) GOutputStream *output)
{ {
GObjectClass *klass; GObjectClass *klass;
GParamSpec **property_specs; GParamSpec **property_specs;
@ -244,14 +251,15 @@ static const gchar man_page_footer[] =
static void static void
dump_gimprc_manpage (GimpConfig *rc, dump_gimprc_manpage (GimpConfig *rc,
GimpConfigWriter *writer, GimpConfigWriter *writer,
gint fd) GOutputStream *output)
{ {
GObjectClass *klass; GObjectClass *klass;
GParamSpec **property_specs; GParamSpec **property_specs;
guint n_property_specs; guint n_property_specs;
guint i; guint i;
write (fd, man_page_header, strlen (man_page_header)); gimp_output_stream_printf (output, NULL, NULL, NULL,
"%s", man_page_header);
klass = G_OBJECT_GET_CLASS (rc); klass = G_OBJECT_GET_CLASS (rc);
property_specs = g_object_class_list_properties (klass, &n_property_specs); property_specs = g_object_class_list_properties (klass, &n_property_specs);
@ -267,16 +275,20 @@ dump_gimprc_manpage (GimpConfig *rc,
if (prop_spec->flags & GIMP_CONFIG_PARAM_IGNORE) if (prop_spec->flags & GIMP_CONFIG_PARAM_IGNORE)
continue; continue;
write (fd, ".TP\n", strlen (".TP\n")); gimp_output_stream_printf (output, NULL, NULL, NULL,
".TP\n");
if (gimp_config_serialize_property (rc, prop_spec, writer)) if (gimp_config_serialize_property (rc, prop_spec, writer))
{ {
write (fd, "\n", 1); gimp_output_stream_printf (output, NULL, NULL, NULL,
"\n");
desc = dump_describe_param (prop_spec); desc = dump_describe_param (prop_spec);
dump_with_linebreaks (fd, desc); dump_with_linebreaks (output, desc);
write (fd, "\n", 1);
gimp_output_stream_printf (output, NULL, NULL, NULL,
"\n");
g_free (desc); g_free (desc);
} }
@ -284,8 +296,10 @@ dump_gimprc_manpage (GimpConfig *rc,
g_free (property_specs); g_free (property_specs);
write (fd, man_page_path, strlen (man_page_path)); gimp_output_stream_printf (output, NULL, NULL, NULL,
write (fd, man_page_footer, strlen (man_page_footer)); "%s", man_page_path);
gimp_output_stream_printf (output, NULL, NULL, NULL,
"%s", man_page_footer);
} }
@ -495,7 +509,7 @@ dump_describe_param (GParamSpec *param_spec)
#define LINE_LENGTH 78 #define LINE_LENGTH 78
static void static void
dump_with_linebreaks (gint fd, dump_with_linebreaks (GOutputStream *output,
const gchar *text) const gchar *text)
{ {
gint len = strlen (text); gint len = strlen (text);
@ -507,7 +521,8 @@ dump_with_linebreaks (gint fd,
/* groff doesn't like lines to start with a single quote */ /* groff doesn't like lines to start with a single quote */
if (*text == '\'') if (*text == '\'')
write (fd, "\\&", 2); /* this represents a zero width space */ gimp_output_stream_printf (output, NULL, NULL, NULL,
"\\&"); /* a zero width space */
for (t = text, i = 0, space = 0; for (t = text, i = 0, space = 0;
*t != '\n' && (i <= LINE_LENGTH || space == 0) && i < len; *t != '\n' && (i <= LINE_LENGTH || space == 0) && i < len;
@ -520,11 +535,13 @@ dump_with_linebreaks (gint fd,
if (i > LINE_LENGTH && space && *t != '\n') if (i > LINE_LENGTH && space && *t != '\n')
i = space; i = space;
write (fd, text, i); g_output_stream_write_all (output, text, i, NULL, NULL, NULL);
write (fd, "\n", 1); gimp_output_stream_printf (output, NULL, NULL, NULL,
"\n");
if (*t == '\n') if (*t == '\n')
write (fd, ".br\n", 4); gimp_output_stream_printf (output, NULL, NULL, NULL,
".br\n");
i++; i++;