Commit 616ba659 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

removed lots of code...

2007-05-24  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpsessioninfo.[ch]: removed lots of code...

	* app/widgets/Makefile.am
	* app/widgets/gimpsessioninfoaux.[ch]
	* app/widgets/gimpsessioninfobook.[ch]
	* app/widgets/gimpsessioninfodockable.[ch]: ...and added it here.
	Also allocate all structs using GSLice.

	* app/widgets/gimpcoloreditor.c
	* app/widgets/gimpcursorview.c
	* app/widgets/gimpdataeditor.c
	* app/widgets/gimpdialogfactory.c
	* app/widgets/gimpdocked.c
	* app/widgets/gimphistogrameditor.c
	* app/widgets/gimpmenudock.c
	* app/widgets/gimppaletteeditor.c: changed accordingly.


svn path=/trunk/; revision=22603
parent dfc676e2
2007-05-24 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpsessioninfo.[ch]: removed lots of code...
* app/widgets/Makefile.am
* app/widgets/gimpsessioninfoaux.[ch]
* app/widgets/gimpsessioninfobook.[ch]
* app/widgets/gimpsessioninfodockable.[ch]: ...and added it here.
Also allocate all structs using GSLice.
* app/widgets/gimpcoloreditor.c
* app/widgets/gimpcursorview.c
* app/widgets/gimpdataeditor.c
* app/widgets/gimpdialogfactory.c
* app/widgets/gimpdocked.c
* app/widgets/gimphistogrameditor.c
* app/widgets/gimpmenudock.c
* app/widgets/gimppaletteeditor.c: changed accordingly.
2007-05-24 Sven Neumann <sven@gimp.org>
* plug-ins/common/bumpmap.c: formatting, added const qualifiers.
......@@ -228,6 +228,12 @@ libappwidgets_a_sources = \
gimpselectioneditor.h \
gimpsessioninfo.c \
gimpsessioninfo.h \
gimpsessioninfoaux.c \
gimpsessioninfoaux.h \
gimpsessioninfobook.c \
gimpsessioninfobook.h \
gimpsessioninfodockable.c \
gimpsessioninfodockable.h \
gimpsizebox.c \
gimpsizebox.h \
gimpstringaction.c \
......
......@@ -40,7 +40,7 @@
#include "gimpdocked.h"
#include "gimpfgbgeditor.h"
#include "gimpfgbgview.h"
#include "gimpsessioninfo.h"
#include "gimpsessioninfoaux.h"
#include "gimp-intl.h"
......
......@@ -41,7 +41,7 @@
#include "gimpcursorview.h"
#include "gimpdocked.h"
#include "gimpmenufactory.h"
#include "gimpsessioninfo.h"
#include "gimpsessioninfoaux.h"
#include "gimp-intl.h"
......
......@@ -39,7 +39,7 @@
#include "gimpdataeditor.h"
#include "gimpdocked.h"
#include "gimpmenufactory.h"
#include "gimpsessioninfo.h"
#include "gimpsessioninfoaux.h"
#include "gimpuimanager.h"
#include "gimp-intl.h"
......
......@@ -799,7 +799,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
if (! list) /* didn't find a session info */
{
info = g_new0 (GimpSessionInfo, 1);
info = gimp_session_info_new ();
info->widget = dialog;
......@@ -858,7 +858,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
if (! list) /* didn't find a session info */
{
info = g_new0 (GimpSessionInfo, 1);
info = gimp_session_info_new ();
info->widget = dialog;
......@@ -995,7 +995,7 @@ gimp_dialog_factory_remove_dialog (GimpDialogFactory *factory,
factory->session_infos = g_list_remove (factory->session_infos,
session_info);
g_free (session_info);
gimp_session_info_free (session_info);
}
break;
......
......@@ -31,7 +31,7 @@
#include "core/gimpmarshal.h"
#include "gimpdocked.h"
#include "gimpsessioninfo.h"
#include "gimpsessioninfoaux.h"
enum
......
......@@ -37,7 +37,7 @@
#include "gimphistogrambox.h"
#include "gimphistogrameditor.h"
#include "gimphistogramview.h"
#include "gimpsessioninfo.h"
#include "gimpsessioninfoaux.h"
#include "gimpwidgets-utils.h"
#include "gimp-intl.h"
......
......@@ -42,7 +42,7 @@
#include "gimpdockbook.h"
#include "gimphelp-ids.h"
#include "gimpmenudock.h"
#include "gimpsessioninfo.h"
#include "gimpsessioninfoaux.h"
#include "gimp-intl.h"
......
......@@ -40,7 +40,7 @@
#include "gimphelp-ids.h"
#include "gimppaletteeditor.h"
#include "gimppaletteview.h"
#include "gimpsessioninfo.h"
#include "gimpsessioninfoaux.h"
#include "gimpuimanager.h"
#include "gimpviewrendererpalette.h"
#include "gimpwidgets-utils.h"
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpsessioninfo.h
* Copyright (C) 2001-2003 Michael Natterer <mitch@gimp.org>
* Copyright (C) 2001-2007 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -45,48 +45,10 @@ struct _GimpSessionInfo
GList *books;
};
struct _GimpSessionInfoBook
{
gint position;
gint current_page;
GtkWidget *widget;
/* list of GimpSessionInfoDockable */
GList *dockables;
};
struct _GimpSessionInfoDockable
{
gchar *identifier;
GimpTabStyle tab_style;
gint view_size;
/* dialog specific list of GimpSessionInfoAux */
GList *aux_info;
};
struct _GimpSessionInfoAux
{
gchar *name;
gchar *value;
};
GimpSessionInfo *
gimp_session_info_new (void);
void gimp_session_info_free (GimpSessionInfo *info);
void gimp_session_info_book_free (GimpSessionInfoBook *book);
void gimp_session_info_dockable_free (GimpSessionInfoDockable *dockable);
GimpSessionInfoAux *
gimp_session_info_aux_new (const gchar *name,
const gchar *value);
void gimp_session_info_aux_free (GimpSessionInfoAux *aux);
GList * gimp_session_info_aux_new_from_props (GObject *object,
...) G_GNUC_NULL_TERMINATED;
void gimp_session_info_aux_set_props (GObject *object,
GList *aux,
...) G_GNUC_NULL_TERMINATED;
void gimp_session_info_save (GimpSessionInfo *info,
const gchar *factory_name,
......@@ -100,4 +62,4 @@ void gimp_session_info_set_geometry (GimpSessionInfo *info);
void gimp_session_info_get_geometry (GimpSessionInfo *info);
#endif /* __GIMP_SESSION_INFO_H__ */
#endif /* __GIMP_SESSION_INFO_H__ */
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpsessioninfoaux.c
* Copyright (C) 2001-2007 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 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 program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
#include "widgets-types.h"
#include "gimpdock.h"
#include "gimpdockable.h"
#include "gimpsessioninfoaux.h"
/* public functions */
GimpSessionInfoAux *
gimp_session_info_aux_new (const gchar *name,
const gchar *value)
{
GimpSessionInfoAux *aux;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (value != NULL, NULL);
aux = g_slice_new0 (GimpSessionInfoAux);
aux->name = g_strdup (name);
aux->value = g_strdup (value);
return aux;
}
void
gimp_session_info_aux_free (GimpSessionInfoAux *aux)
{
g_return_if_fail (aux != NULL);
g_free (aux->name);
g_free (aux->value);
g_slice_free (GimpSessionInfoAux, aux);
}
GList *
gimp_session_info_aux_new_from_props (GObject *object,
...)
{
GList *list = NULL;
const gchar *prop_name;
va_list args;
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
va_start (args, object);
for (prop_name = va_arg (args, const gchar *);
prop_name;
prop_name = va_arg (args, const gchar *))
{
GObjectClass *class = G_OBJECT_GET_CLASS (object);
GParamSpec *pspec = g_object_class_find_property (class, prop_name);
if (pspec)
{
GString *str = g_string_new (NULL);
GValue value = { 0, };
g_value_init (&value, pspec->value_type);
g_object_get_property (object, pspec->name, &value);
if (! g_param_value_defaults (pspec, &value) &&
gimp_config_serialize_value (&value, str, TRUE))
{
list = g_list_prepend (list,
gimp_session_info_aux_new (prop_name,
str->str));
}
g_value_unset (&value);
}
else
{
g_warning ("%s: no property named '%s' for %s",
G_STRFUNC,
prop_name, G_OBJECT_CLASS_NAME (class));
}
}
va_end (args);
return g_list_reverse (list);
}
void
gimp_session_info_aux_set_props (GObject *object,
GList *auxs,
...)
{
const gchar *prop_name;
va_list args;
g_return_if_fail (G_IS_OBJECT (object));
va_start (args, auxs);
for (prop_name = va_arg (args, const gchar *);
prop_name;
prop_name = va_arg (args, const gchar *))
{
GList *list;
for (list = auxs; list; list = g_list_next (list))
{
GimpSessionInfoAux *aux = list->data;
if (strcmp (aux->name, prop_name) == 0)
{
GObjectClass *class = G_OBJECT_GET_CLASS (object);
GParamSpec *pspec = g_object_class_find_property (class,
prop_name);
if (pspec)
{
GValue value = { 0, };
g_value_init (&value, pspec->value_type);
if (G_VALUE_HOLDS_ENUM (&value))
{
GEnumClass *enum_class;
GEnumValue *enum_value;
enum_class = g_type_class_peek (pspec->value_type);
enum_value = g_enum_get_value_by_nick (enum_class,
aux->value);
if (enum_value)
{
g_value_set_enum (&value, enum_value->value);
g_object_set_property (object, pspec->name, &value);
}
else
{
g_warning ("%s: unknown enum value in '%s' for %s",
G_STRFUNC,
prop_name, G_OBJECT_CLASS_NAME (class));
}
}
else
{
GValue str_value = { 0, };
g_value_init (&str_value, G_TYPE_STRING);
g_value_set_static_string (&str_value, aux->value);
if (g_value_transform (&str_value, &value))
g_object_set_property (object, pspec->name, &value);
else
g_warning ("%s: cannot convert property '%s' for %s",
G_STRFUNC,
prop_name, G_OBJECT_CLASS_NAME (class));
g_value_unset (&str_value);
}
g_value_unset (&value);
}
else
{
g_warning ("%s: no property named '%s' for %s",
G_STRFUNC,
prop_name, G_OBJECT_CLASS_NAME (class));
}
}
}
}
va_end (args);
}
void
gimp_session_info_aux_serialize (GimpConfigWriter *writer,
GtkWidget *widget)
{
GList *aux_info;
g_return_if_fail (writer != NULL);
g_return_if_fail (GTK_IS_WIDGET (widget));
aux_info = gimp_session_info_get_aux_info (widget);
if (aux_info)
{
GList *list;
gimp_config_writer_open (writer, "aux-info");
for (list = aux_info; list; list = g_list_next (list))
{
GimpSessionInfoAux *aux = list->data;
gimp_config_writer_open (writer, aux->name);
gimp_config_writer_string (writer, aux->value);
gimp_config_writer_close (writer);
}
gimp_config_writer_close (writer);
g_list_foreach (aux_info, (GFunc) gimp_session_info_aux_free, NULL);
g_list_free (aux_info);
}
}
GTokenType
gimp_session_info_aux_deserialize (GScanner *scanner,
GList **aux_list)
{
GimpSessionInfoAux *aux_info = NULL;
GTokenType token = G_TOKEN_LEFT_PAREN;
g_return_val_if_fail (scanner != NULL, G_TOKEN_LEFT_PAREN);
g_return_val_if_fail (aux_list != NULL, G_TOKEN_LEFT_PAREN);
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_IDENTIFIER;
break;
case G_TOKEN_IDENTIFIER:
{
aux_info = g_slice_new0 (GimpSessionInfoAux);
aux_info->name = g_strdup (scanner->value.v_identifier);
token = G_TOKEN_STRING;
if (g_scanner_peek_next_token (scanner) != token)
goto error;
if (! gimp_scanner_parse_string (scanner, &aux_info->value))
goto error;
*aux_list = g_list_append (*aux_list, aux_info);
aux_info = NULL;
}
token = G_TOKEN_RIGHT_PAREN;
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_LEFT_PAREN;
break;
default:
break;
}
}
return token;
error:
if (aux_info)
gimp_session_info_aux_free (aux_info);
return token;
}
void
gimp_session_info_set_aux_info (GtkWidget *dialog,
GList *aux_info)
{
/* FIXME: make the aux-info stuff generic */
if (GIMP_IS_DOCK (dialog))
gimp_dock_set_aux_info (GIMP_DOCK (dialog), aux_info);
else if (GIMP_IS_DOCKABLE (dialog))
gimp_dockable_set_aux_info (GIMP_DOCKABLE (dialog), aux_info);
}
GList *
gimp_session_info_get_aux_info (GtkWidget *dialog)
{
/* FIXME: make the aux-info stuff generic */
if (GIMP_IS_DOCK (dialog))
return gimp_dock_get_aux_info (GIMP_DOCK (dialog));
else if (GIMP_IS_DOCKABLE (dialog))
return gimp_dockable_get_aux_info (GIMP_DOCKABLE (dialog));
return NULL;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpsessioninfoaux.h
* Copyright (C) 2001-2007 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 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 program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_SESSION_INFO_AUX_H__
#define __GIMP_SESSION_INFO_AUX_H__
struct _GimpSessionInfoAux
{
gchar *name;
gchar *value;
};
GimpSessionInfoAux *
gimp_session_info_aux_new (const gchar *name,
const gchar *value);
void gimp_session_info_aux_free (GimpSessionInfoAux *aux);
GList * gimp_session_info_aux_new_from_props (GObject *object,
...) G_GNUC_NULL_TERMINATED;
void gimp_session_info_aux_set_props (GObject *object,
GList *aux,
...) G_GNUC_NULL_TERMINATED;
void gimp_session_info_aux_serialize (GimpConfigWriter *writer,
GtkWidget *widget);
GTokenType gimp_session_info_aux_deserialize (GScanner *scanner,
GList **aux_list);
void gimp_session_info_set_aux_info (GtkWidget *dialog,
GList *aux_info);
GList * gimp_session_info_get_aux_info (GtkWidget *dialog);
#endif /* __GIMP_SESSION_INFO_AUX_H__ */
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpsessioninfobook.c
* Copyright (C) 2001-2007 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 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 program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
#include "widgets-types.h"
#include "gimpdialogfactory.h"
#include "gimpdock.h"
#include "gimpdockbook.h"
#include "gimpsessioninfo.h"
#include "gimpsessioninfobook.h"
#include "gimpsessioninfodockable.h"
enum
{
SESSION_INFO_BOOK_POSITION,
SESSION_INFO_BOOK_CURRENT_PAGE,
SESSION_INFO_BOOK_DOCKABLE
};
/* public functions */
GimpSessionInfoBook *
gimp_session_info_book_new (void)
{
return g_slice_new0 (GimpSessionInfoBook);
}
void
gimp_session_info_book_free (GimpSessionInfoBook *book)
{
g_return_if_fail (book != NULL);
if (book->dockables)
{
g_list_foreach (book->dockables, (GFunc) gimp_session_info_dockable_free,
NULL);
g_list_free (book->dockables);
}
g_slice_free (GimpSessionInfoBook, book);
}
void
gimp_session_info_book_serialize (GimpConfigWriter *writer,
GimpDockbook *dockbook)
{
GList *children;
GList *pages;
gint current_page;
g_return_if_fail (writer != NULL);
g_return_if_fail (GIMP_IS_DOCKBOOK (dockbook));
gimp_config_writer_open (writer, "book");
if (GTK_IS_VPANED (GTK_WIDGET (dockbook)->parent))
{
GtkPaned *paned = GTK_PANED (GTK_WIDGET (dockbook)->parent);
if (GTK_WIDGET (dockbook) == paned->child2)
{
gimp_config_writer_open (writer, "position");
gimp_config_writer_printf (writer, "%d",
gtk_paned_get_position (paned));
gimp_config_writer_close (writer);
}
}
current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
gimp_config_writer_open (writer, "current-page");
gimp_config_writer_printf (writer, "%d", current_page);
gimp_config_writer_close (writer);
children = gtk_container_get_children (GTK_CONTAINER (dockbook));
for (pages = children; pages; pages = g_list_next (pages))
gimp_session_info_dockable_serialize (writer, pages->data);
g_list_free (children);
gimp_config_writer_close (writer);
}
GTokenType
gimp_session_info_book_deserialize (GScanner *scanner,
gint scope,
GimpSessionInfo *info)
{
GimpSessionInfoBook *book;
GTokenType token;
g_return_val_if_fail (scanner != NULL, G_TOKEN_LEFT_PAREN);
g_return_val_if_fail (info != NULL, G_TOKEN_LEFT_PAREN);
g_scanner_scope_add_symbol (scanner, scope, "position",
GINT_TO_POINTER (SESSION_INFO_BOOK_POSITION));
g_scanner_scope_add_symbol (scanner, scope, "current-page",
GINT_TO_POINTER (SESSION_INFO_BOOK_CURRENT_PAGE));
g_scanner_scope_add_symbol (scanner, scope, "dockable",
GINT_TO_POINTER (SESSION_INFO_BOOK_DOCKABLE));
book = gimp_session_info_book_new ();
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_SYMBOL;
break;
case G_TOKEN_SYMBOL:
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
{
case SESSION_INFO_BOOK_POSITION:
token = G_TOKEN_INT;
if (! gimp_scanner_parse_int (scanner, &book->position))
goto error;
break;
case SESSION_INFO_BOOK_CURRENT_PAGE:
token = G_TOKEN_INT;
if (! gimp_scanner_parse_int (scanner, &book->current_page))
goto error;
break;
case SESSION_INFO_BOOK_DOCKABLE:
g_scanner_set_scope (scanner, scope + 1);
token = gimp_session_info_dockable_deserialize (scanner,
scope + 1,
book);
if (token == G_TOKEN_LEFT_PAREN)
g_scanner_set_scope (scanner, scope);
else
goto error;
break;
default:
goto error;