Commit 6fc587c6 authored by Martin Nordholts's avatar Martin Nordholts

app: Add GimpSessionManaged

Add a GimpSessionManaged interface to generalize
gimp_session_info_aux_get_list() and gimp_session_info_aux_set_list().
parent da18c111
......@@ -29,6 +29,7 @@ Core:
a simple API and takes it out of GimpDisplayShell
- Add a GimpIdTable utility class
- Add a GimpDockContainer interface
- Add a GimpSessionManaged interface
GEGL:
......
......@@ -40,6 +40,7 @@
#include "widgets/gimpmenufactory.h"
#include "widgets/gimpsessioninfo.h"
#include "widgets/gimpsessioninfo-aux.h"
#include "widgets/gimpsessionmanaged.h"
#include "widgets/gimptoolbox.h"
#include "dialogs.h"
......@@ -441,9 +442,9 @@ dialogs_restore_dialog (GimpDialogFactory *factory,
GIMP_DIALOG_VISIBILITY_HIDDEN :
GIMP_DIALOG_VISIBILITY_VISIBLE));
if (dialog && gimp_session_info_get_aux_info (info))
gimp_session_info_aux_set_list (dialog,
gimp_session_info_get_aux_info (info));
if (GIMP_IS_SESSION_MANAGED (dialog) && gimp_session_info_get_aux_info (info))
gimp_session_managed_set_aux_info (GIMP_SESSION_MANAGED (dialog),
gimp_session_info_get_aux_info (info));
return dialog;
}
......
......@@ -296,6 +296,8 @@ libappwidgets_a_sources = \
gimpsessioninfo-dockable.c \
gimpsessioninfo-dockable.h \
gimpsessioninfo-private.h \
gimpsessionmanaged.c \
gimpsessionmanaged.h \
gimpsettingsbox.c \
gimpsettingsbox.h \
gimpsettingseditor.c \
......
......@@ -42,6 +42,7 @@
#include "gimphelp-ids.h"
#include "gimppanedbox.h"
#include "gimpsessioninfo-aux.h"
#include "gimpsessionmanaged.h"
#include "gimpuimanager.h"
#include "gimpwidgets-utils.h"
......@@ -80,6 +81,9 @@ struct _GimpDockablePrivate
};
static void gimp_dockable_session_managed_iface_init
(GimpSessionManagedInterface
*iface);
static void gimp_dockable_dispose (GObject *object);
static void gimp_dockable_set_property (GObject *object,
guint property_id,
......@@ -114,13 +118,21 @@ static void gimp_dockable_style_set (GtkWidget *widget,
static void gimp_dockable_add (GtkContainer *container,
GtkWidget *widget);
static GType gimp_dockable_child_type (GtkContainer *container);
static GList * gimp_dockable_get_aux_info (GimpSessionManaged
*session_managed);
static void gimp_dockable_set_aux_info (GimpSessionManaged
*session_managed,
GList *aux_info);
static GimpTabStyle
gimp_dockable_convert_tab_style (GimpDockable *dockable,
GimpTabStyle tab_style);
static gboolean gimp_dockable_blink_timeout (GimpDockable *dockable);
G_DEFINE_TYPE (GimpDockable, gimp_dockable, GTK_TYPE_BIN)
G_DEFINE_TYPE_WITH_CODE (GimpDockable, gimp_dockable, GTK_TYPE_BIN,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_SESSION_MANAGED,
gimp_dockable_session_managed_iface_init))
#define parent_class gimp_dockable_parent_class
......@@ -181,6 +193,13 @@ gimp_dockable_init (GimpDockable *dockable)
GDK_ACTION_MOVE);
}
static void
gimp_dockable_session_managed_iface_init (GimpSessionManagedInterface *iface)
{
iface->get_aux_info = gimp_dockable_get_aux_info;
iface->set_aux_info = gimp_dockable_set_aux_info;
}
static void
gimp_dockable_dispose (GObject *object)
{
......@@ -672,36 +691,6 @@ gimp_dockable_get_drag_handler (GimpDockable *dockable)
return dockable->p->drag_handler;
}
void
gimp_dockable_set_aux_info (GimpDockable *dockable,
GList *aux_info)
{
GtkWidget *child;
g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
child = gtk_bin_get_child (GTK_BIN (dockable));
if (child)
gimp_docked_set_aux_info (GIMP_DOCKED (child), aux_info);
}
GList *
gimp_dockable_get_aux_info (GimpDockable *dockable)
{
GtkWidget *child;
g_return_val_if_fail (GIMP_IS_DOCKABLE (dockable), NULL);
child = gtk_bin_get_child (GTK_BIN (dockable));
if (child)
return gimp_docked_get_aux_info (GIMP_DOCKED (child));
return NULL;
}
void
gimp_dockable_set_locked (GimpDockable *dockable,
gboolean lock)
......@@ -928,6 +917,41 @@ gimp_dockable_blink_cancel (GimpDockable *dockable)
/* private functions */
static GList *
gimp_dockable_get_aux_info (GimpSessionManaged *session_managed)
{
GimpDockable *dockable;
GtkWidget *child;
g_return_val_if_fail (GIMP_IS_DOCKABLE (session_managed), NULL);
dockable = GIMP_DOCKABLE (session_managed);
child = gtk_bin_get_child (GTK_BIN (dockable));
if (child)
return gimp_docked_get_aux_info (GIMP_DOCKED (child));
return NULL;
}
static void
gimp_dockable_set_aux_info (GimpSessionManaged *session_managed,
GList *aux_info)
{
GimpDockable *dockable;
GtkWidget *child;
g_return_if_fail (GIMP_IS_DOCKABLE (session_managed));
dockable = GIMP_DOCKABLE (session_managed);
child = gtk_bin_get_child (GTK_BIN (dockable));
if (child)
gimp_docked_set_aux_info (GIMP_DOCKED (child), aux_info);
}
static GimpTabStyle
gimp_dockable_convert_tab_style (GimpDockable *dockable,
GimpTabStyle tab_style)
......
......@@ -82,10 +82,6 @@ void gimp_dockable_get_drag_pos (GimpDockable *dockable,
gint *drag_y);
GimpPanedBox * gimp_dockable_get_drag_handler (GimpDockable *dockable);
void gimp_dockable_set_aux_info (GimpDockable *dockable,
GList *aux_info);
GList * gimp_dockable_get_aux_info (GimpDockable *dockable);
void gimp_dockable_set_locked (GimpDockable *dockable,
gboolean lock);
gboolean gimp_dockable_is_locked (GimpDockable *dockable);
......
......@@ -54,6 +54,7 @@
#include "gimpmenufactory.h"
#include "gimpsessioninfo-aux.h"
#include "gimpsessioninfo.h"
#include "gimpsessionmanaged.h"
#include "gimptoolbox.h"
#include "gimpuimanager.h"
#include "gimpwidgets-utils.h"
......@@ -110,6 +111,7 @@ struct _GimpDockWindowPrivate
static void gimp_dock_window_dock_container_iface_init (GimpDockContainerInterface *iface);
static void gimp_dock_window_session_managed_iface_init(GimpSessionManagedInterface*iface);
static void gimp_dock_window_constructed (GObject *object);
static void gimp_dock_window_dispose (GObject *object);
static void gimp_dock_window_finalize (GObject *object);
......@@ -130,6 +132,9 @@ static GimpUIManager * gimp_dock_window_get_ui_manager (GimpDockConta
static void gimp_dock_window_add_dock_from_session (GimpDockContainer *dock_container,
GimpDock *dock,
GimpSessionInfoDock *dock_info);
static GList * gimp_dock_window_get_aux_info (GimpSessionManaged *session_managed);
static void gimp_dock_window_set_aux_info (GimpSessionManaged *session_managed,
GList *aux_info);
static GimpAlignmentType
gimp_dock_window_get_dock_side (GimpDockContainer *dock_container,
GimpDock *dock);
......@@ -162,7 +167,9 @@ static void gimp_dock_window_auto_clicked (GtkWidget
G_DEFINE_TYPE_WITH_CODE (GimpDockWindow, gimp_dock_window, GIMP_TYPE_WINDOW,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCK_CONTAINER,
gimp_dock_window_dock_container_iface_init))
gimp_dock_window_dock_container_iface_init)
G_IMPLEMENT_INTERFACE (GIMP_TYPE_SESSION_MANAGED,
gimp_dock_window_session_managed_iface_init))
#define parent_class gimp_dock_window_parent_class
......@@ -272,6 +279,13 @@ gimp_dock_window_dock_container_iface_init (GimpDockContainerInterface *iface)
iface->get_dock_side = gimp_dock_window_get_dock_side;
}
static void
gimp_dock_window_session_managed_iface_init (GimpSessionManagedInterface *iface)
{
iface->get_aux_info = gimp_dock_window_get_aux_info;
iface->set_aux_info = gimp_dock_window_set_aux_info;
}
static void
gimp_dock_window_constructed (GObject *object)
{
......@@ -725,6 +739,74 @@ gimp_dock_window_add_dock_from_session (GimpDockContainer *dock_container,
-1 /*index*/);
}
static GList *
gimp_dock_window_get_aux_info (GimpSessionManaged *session_managed)
{
GimpDockWindow *dock_window;
GList *aux_info = NULL;
GimpSessionInfoAux *aux;
g_return_val_if_fail (GIMP_IS_DOCK_WINDOW (session_managed), NULL);
dock_window = GIMP_DOCK_WINDOW (session_managed);
if (dock_window->p->allow_dockbook_absence)
{
/* Assume it is the toolbox; it does not have aux info */
return NULL;
}
g_return_val_if_fail (GIMP_IS_DOCK_WINDOW (dock_window), NULL);
aux = gimp_session_info_aux_new (AUX_INFO_SHOW_IMAGE_MENU,
dock_window->p->show_image_menu ?
"true" : "false");
aux_info = g_list_append (aux_info, aux);
aux = gimp_session_info_aux_new (AUX_INFO_FOLLOW_ACTIVE_IMAGE,
dock_window->p->auto_follow_active ?
"true" : "false");
aux_info = g_list_append (aux_info, aux);
return aux_info;
}
static void
gimp_dock_window_set_aux_info (GimpSessionManaged *session_managed,
GList *aux_info)
{
GimpDockWindow *dock_window;
GList *list;
gboolean menu_shown;
gboolean auto_follow;
g_return_if_fail (GIMP_IS_DOCK_WINDOW (session_managed));
dock_window = GIMP_DOCK_WINDOW (session_managed);
menu_shown = dock_window->p->show_image_menu;
auto_follow = dock_window->p->auto_follow_active;
for (list = aux_info; list; list = g_list_next (list))
{
GimpSessionInfoAux *aux = list->data;
if (! strcmp (aux->name, AUX_INFO_SHOW_IMAGE_MENU))
{
menu_shown = ! g_ascii_strcasecmp (aux->value, "true");
}
else if (! strcmp (aux->name, AUX_INFO_FOLLOW_ACTIVE_IMAGE))
{
auto_follow = ! g_ascii_strcasecmp (aux->value, "true");
}
}
if (menu_shown != dock_window->p->show_image_menu)
gimp_dock_window_set_show_image_menu (dock_window, menu_shown);
if (auto_follow != dock_window->p->auto_follow_active)
gimp_dock_window_set_auto_follow_active (dock_window, auto_follow);
}
static GimpAlignmentType
gimp_dock_window_get_dock_side (GimpDockContainer *dock_container,
GimpDock *dock)
......@@ -1127,66 +1209,6 @@ gimp_dock_window_setup (GimpDockWindow *dock_window,
template->p->show_image_menu);
}
void
gimp_dock_window_set_aux_info (GimpDockWindow *dock_window,
GList *aux_info)
{
GList *list;
gboolean menu_shown = dock_window->p->show_image_menu;
gboolean auto_follow = dock_window->p->auto_follow_active;
g_return_if_fail (GIMP_IS_DOCK_WINDOW (dock_window));
for (list = aux_info; list; list = g_list_next (list))
{
GimpSessionInfoAux *aux = list->data;
if (! strcmp (aux->name, AUX_INFO_SHOW_IMAGE_MENU))
{
menu_shown = ! g_ascii_strcasecmp (aux->value, "true");
}
else if (! strcmp (aux->name, AUX_INFO_FOLLOW_ACTIVE_IMAGE))
{
auto_follow = ! g_ascii_strcasecmp (aux->value, "true");
}
}
if (menu_shown != dock_window->p->show_image_menu)
gimp_dock_window_set_show_image_menu (dock_window, menu_shown);
if (auto_follow != dock_window->p->auto_follow_active)
gimp_dock_window_set_auto_follow_active (dock_window, auto_follow);
}
GList *
gimp_dock_window_get_aux_info (GimpDockWindow *dock_window)
{
GList *aux_info = NULL;
GimpSessionInfoAux *aux = NULL;
g_return_val_if_fail (GIMP_IS_DOCK_WINDOW (dock_window), NULL);
if (dock_window->p->allow_dockbook_absence)
{
/* Assume it is the toolbox; it does not have aux info */
return NULL;
}
g_return_val_if_fail (GIMP_IS_DOCK_WINDOW (dock_window), NULL);
aux = gimp_session_info_aux_new (AUX_INFO_SHOW_IMAGE_MENU,
dock_window->p->show_image_menu ?
"true" : "false");
aux_info = g_list_append (aux_info, aux);
aux = gimp_session_info_aux_new (AUX_INFO_FOLLOW_ACTIVE_IMAGE,
dock_window->p->auto_follow_active ?
"true" : "false");
aux_info = g_list_append (aux_info, aux);
return aux_info;
}
/**
* gimp_dock_window_has_toolbox:
* @dock_window:
......
......@@ -77,9 +77,6 @@ void gimp_dock_window_set_show_image_menu (GimpDockWindow *
gboolean show);
void gimp_dock_window_setup (GimpDockWindow *dock_window,
GimpDockWindow *template);
void gimp_dock_window_set_aux_info (GimpDockWindow *dock,
GList *aux_info);
GList * gimp_dock_window_get_aux_info (GimpDockWindow *dock);
gboolean gimp_dock_window_has_toolbox (GimpDockWindow *dock_window);
GimpDockWindow * gimp_dock_window_from_dock (GimpDock *dock);
......
......@@ -32,6 +32,7 @@
#include "gimpdockable.h"
#include "gimpdockwindow.h"
#include "gimpsessioninfo-aux.h"
#include "gimpsessionmanaged.h"
/* public functions */
......@@ -281,28 +282,3 @@ gimp_session_info_aux_deserialize (GScanner *scanner,
return token;
}
void
gimp_session_info_aux_set_list (GtkWidget *dialog,
GList *aux_list)
{
/* FIXME: make the aux-info stuff generic */
if (GIMP_IS_DOCK_WINDOW (dialog))
gimp_dock_window_set_aux_info (GIMP_DOCK_WINDOW (dialog), aux_list);
else if (GIMP_IS_DOCKABLE (dialog))
gimp_dockable_set_aux_info (GIMP_DOCKABLE (dialog), aux_list);
}
GList *
gimp_session_info_aux_get_list (GtkWidget *dialog)
{
/* FIXME: make the aux-info stuff generic */
if (GIMP_IS_DOCK_WINDOW (dialog))
return gimp_dock_window_get_aux_info (GIMP_DOCK_WINDOW (dialog));
else if (GIMP_IS_DOCKABLE (dialog))
return gimp_dockable_get_aux_info (GIMP_DOCKABLE (dialog));
return NULL;
}
......@@ -51,9 +51,5 @@ void gimp_session_info_aux_serialize (GimpConfigWriter *writer,
GTokenType gimp_session_info_aux_deserialize (GScanner *scanner,
GList **aux_list);
void gimp_session_info_aux_set_list (GtkWidget *dialog,
GList *aux_info);
GList * gimp_session_info_aux_get_list (GtkWidget *dialog);
#endif /* __GIMP_SESSION_INFO_AUX_H__ */
......@@ -33,6 +33,7 @@
#include "gimpdockable.h"
#include "gimpsessioninfo-aux.h"
#include "gimpsessioninfo-dockable.h"
#include "gimpsessionmanaged.h"
#include "gimptoolbox.h"
......@@ -264,7 +265,9 @@ gimp_session_info_dockable_from_widget (GimpDockable *dockable)
if (view_size > 0 && view_size != entry->view_size)
info->view_size = view_size;
info->aux_info = gimp_session_info_aux_get_list (GTK_WIDGET (dockable));
if (GIMP_IS_SESSION_MANAGED (dockable))
info->aux_info =
gimp_session_managed_get_aux_info (GIMP_SESSION_MANAGED (dockable));
return info;
}
......@@ -301,7 +304,8 @@ gimp_session_info_dockable_restore (GimpSessionInfoDockable *info,
gimp_dockable_set_tab_style (GIMP_DOCKABLE (dockable), info->tab_style);
if (info->aux_info)
gimp_session_info_aux_set_list (dockable, info->aux_info);
gimp_session_managed_set_aux_info (GIMP_SESSION_MANAGED (dockable),
info->aux_info);
}
return GIMP_DOCKABLE (dockable);
......
......@@ -43,7 +43,8 @@
#include "gimpsessioninfo-book.h"
#include "gimpsessioninfo-dock.h"
#include "gimpsessioninfo-private.h"
#include "gimpsessionmanaged.h"
#include "gimp-log.h"
......@@ -748,7 +749,9 @@ gimp_session_info_get_info (GimpSessionInfo *info)
gimp_session_info_read_geometry (info, NULL /*cevent*/);
info->p->aux_info = gimp_session_info_aux_get_list (info->p->widget);
if (GIMP_IS_SESSION_MANAGED (info->p->widget))
info->p->aux_info =
gimp_session_managed_get_aux_info (GIMP_SESSION_MANAGED (info->p->widget));
if (GIMP_IS_DOCK_CONTAINER (info->p->widget))
{
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpsessionmanaged.c
* Copyright (C) 2011 Martin Nordholts <martinn@src.gnome.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "widgets-types.h"
#include "gimpsessionmanaged.h"
static void gimp_session_managed_iface_base_init (GimpSessionManagedInterface *managed_iface);
GType
gimp_session_managed_interface_get_type (void)
{
static GType iface_type = 0;
if (! iface_type)
{
const GTypeInfo iface_info =
{
sizeof (GimpSessionManagedInterface),
(GBaseInitFunc) gimp_session_managed_iface_base_init,
(GBaseFinalizeFunc) NULL,
};
iface_type = g_type_register_static (G_TYPE_INTERFACE,
"GimpSessionManagedInterface",
&iface_info,
0);
g_type_interface_add_prerequisite (iface_type, GTK_TYPE_WIDGET);
}
return iface_type;
}
static void
gimp_session_managed_iface_base_init (GimpSessionManagedInterface *managed_iface)
{
static gboolean initialized = FALSE;
if (initialized)
return;
initialized = TRUE;
managed_iface->get_aux_info = NULL;
managed_iface->set_aux_info = NULL;
}
/**
* gimp_session_managed_get_aux_info:
* @session_managed: A #GimpSessionManaged
*
* Returns: A list of #GimpSessionInfoAux created with
* gimp_session_info_aux_new().
**/
GList *
gimp_session_managed_get_aux_info (GimpSessionManaged *session_managed)
{
GimpSessionManagedInterface *iface;
g_return_val_if_fail (GIMP_IS_SESSION_MANAGED (session_managed), NULL);
iface = GIMP_SESSION_MANAGED_GET_INTERFACE (session_managed);
if (iface->get_aux_info)
return iface->get_aux_info (session_managed);
return NULL;
}
/**
* gimp_session_managed_get_ui_manager:
* @session_managed: A #GimpSessionManaged
* @aux_info A list of #GimpSessionInfoAux
*
* Sets aux data previously returned from
* gimp_session_managed_get_aux_info().
**/
void
gimp_session_managed_set_aux_info (GimpSessionManaged *session_managed,
GList *aux_info)
{
GimpSessionManagedInterface *iface;
g_return_if_fail (GIMP_IS_SESSION_MANAGED (session_managed));
iface = GIMP_SESSION_MANAGED_GET_INTERFACE (session_managed);
if (iface->set_aux_info)
iface->set_aux_info (session_managed, aux_info);
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpsessionmanaged.h
* Copyright (C) 2011 Martin Nordholts <martinn@src.gnome.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_SESSION_MANAGED_H__
#define __GIMP_SESSION_MANAGED_H__
#define GIMP_TYPE_SESSION_MANAGED (gimp_session_managed_interface_get_type ())
#define GIMP_SESSION_MANAGED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_SESSION_MANAGED, GimpSessionManaged))
#define GIMP_IS_SESSION_MANAGED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_SESSION_MANAGED))
#define GIMP_SESSION_MANAGED_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GIMP_TYPE_SESSION_MANAGED, GimpSessionManagedInterface))
typedef struct _GimpSessionManagedInterface GimpSessionManagedInterface;
struct _GimpSessionManagedInterface
{
GTypeInterface base_iface;
/* virtual functions */
GList * (* get_aux_info) (GimpSessionManaged *session_managed);
void (* set_aux_info) (GimpSessionManaged *session_managed,
GList *aux_info);
};
GType gimp_session_managed_interface_get_type (void) G_GNUC_CONST;
GList * gimp_session_managed_get_aux_info (GimpSessionManaged *session_managed);
void gimp_session_managed_set_aux_info (GimpSessionManaged *session_managed,
GList *aux_info);
#endif /* __GIMP_SESSION_MANAGED_H__ */
......@@ -244,6 +244,7 @@ typedef struct _GimpSessionInfoAux GimpSessionInfoAux;
typedef struct _GimpSessionInfoBook GimpSessionInfoBook;
typedef struct _GimpSessionInfoDock GimpSessionInfoDock;
typedef struct _GimpSessionInfoDockable GimpSessionInfoDockable;
typedef struct _GimpSessionManaged GimpSessionManaged;
/* structs */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment