app/gui/Makefile.am new files providing functionality to ensure a unique

2008-07-11  Sven Neumann  <sven@gimp.org>

	* app/gui/Makefile.am
	* app/gui/gui-unique.[ch]: new files providing functionality to
	ensure a unique GUI instance of GIMP. Code split out of gui.c.

	* app/gui/gui.c: changed accordingly.


svn path=/trunk/; revision=26119
This commit is contained in:
Sven Neumann 2008-07-11 09:40:09 +00:00 committed by Sven Neumann
parent 0cf63ba421
commit 681b788626
5 changed files with 160 additions and 60 deletions

View File

@ -1,3 +1,11 @@
2008-07-11 Sven Neumann <sven@gimp.org>
* app/gui/Makefile.am
* app/gui/gui-unique.[ch]: new files providing functionality to
ensure a unique GUI instance of GIMP. Code split out of gui.c.
* app/gui/gui.c: changed accordingly.
2008-07-11 Sven Neumann <sven@gimp.org>
* app/Makefile.am

View File

@ -22,6 +22,8 @@ libappgui_a_SOURCES = \
gui.h \
gui-message.c \
gui-message.h \
gui-unique.c \
gui-unique.h \
gui-vtable.c \
gui-vtable.h \
gui-types.h \

118
app/gui/gui-unique.c Normal file
View File

@ -0,0 +1,118 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <glib-object.h>
#if HAVE_DBUS_GLIB
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#endif
#include "core/core-types.h"
#include "core/gimp.h"
#include "widgets/gimpdbusservice.h"
#include "gui-unique.h"
#if HAVE_DBUS_GLIB
static void gui_dbus_service_init (Gimp *gimp);
static void gui_dbus_service_exit (void);
static DBusGConnection *dbus_connection = NULL;
#endif
#ifdef G_OS_WIN32
static void gui_unique_win32_init (Gimp *gimp);
#endif
void
gui_unique_init (Gimp *gimp)
{
#ifdef G_OS_WIN32
gui_unique_win32_init (gimp);
#elif HAVE_DBUS_GLIB
gui_dbus_service_init (gimp);
#endif
}
void
gui_unique_exit (void)
{
#if HAVE_DBUS_GLIB
gui_dbus_service_exit ();
#endif
}
#if HAVE_DBUS_GLIB
static void
gui_dbus_service_init (Gimp *gimp)
{
GError *error = NULL;
g_return_if_fail (dbus_connection == NULL);
dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (dbus_connection)
{
GObject *service = gimp_dbus_service_new (gimp);
dbus_bus_request_name (dbus_g_connection_get_connection (dbus_connection),
GIMP_DBUS_SERVICE_NAME, 0, NULL);
dbus_g_connection_register_g_object (dbus_connection,
GIMP_DBUS_SERVICE_PATH, service);
}
else
{
g_printerr ("%s\n", error->message);
g_error_free (error);
}
}
static void
gui_dbus_service_exit (void)
{
if (dbus_connection)
{
dbus_g_connection_unref (dbus_connection);
dbus_connection = NULL;
}
}
#endif /* HAVE_DBUS_GLIB */
#ifdef G_OS_WIN32
static void
gui_unique_win32_init (Gimp *gimp)
{
}
#endif /* G_OS_WIN32 */

27
app/gui/gui-unique.h Normal file
View File

@ -0,0 +1,27 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 __GUI_UNIQUE_H__
#define __GUI_UNIQUE_H__
void gui_unique_init (Gimp *gimp);
void gui_unique_exit (void);
#endif /* __GUI_UNIQUE_H__ */

View File

@ -22,12 +22,6 @@
#include <gtk/gtk.h>
#if HAVE_DBUS_GLIB
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#endif
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimpwidgets/gimpwidgets-private.h"
@ -57,7 +51,6 @@
#include "widgets/gimpclipboard.h"
#include "widgets/gimpcolorselectorpalette.h"
#include "widgets/gimpcontrollers.h"
#include "widgets/gimpdbusservice.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpdevicestatus.h"
#include "widgets/gimpdialogfactory.h"
@ -80,6 +73,7 @@
#include "color-history.h"
#include "gui.h"
#include "gui-unique.h"
#include "gui-vtable.h"
#include "session.h"
#include "splash.h"
@ -136,18 +130,11 @@ static void gui_display_changed (GimpContext *context,
Gimp *gimp);
static void gui_display_remove (GimpContainer *displays);
static void gui_dbus_service_init (Gimp *gimp);
static void gui_dbus_service_exit (void);
/* private variables */
static Gimp *the_gui_gimp = NULL;
static GimpUIManager *image_ui_manager = NULL;
#if HAVE_DBUS_GLIB
static DBusGConnection *dbus_connection = NULL;
#endif
static Gimp *the_gui_gimp = NULL;
static GimpUIManager *image_ui_manager = NULL;
/* public functions */
@ -525,7 +512,7 @@ gui_restore_after_callback (Gimp *gimp,
display = GIMP_DISPLAY (gimp_create_display (gimp,
NULL, GIMP_UNIT_PIXEL, 1.0));
gui_dbus_service_init (gimp);
gui_unique_init (gimp);
if (gui_config->restore_session)
session_restore (gimp);
@ -559,9 +546,7 @@ gui_exit_callback (Gimp *gimp,
gimp->message_handler = GIMP_CONSOLE;
#if HAVE_DBUS_GLIB
gui_dbus_service_exit ();
#endif
gui_unique_exit ();
if (gui_config->save_session_info)
session_save (gimp, FALSE);
@ -761,43 +746,3 @@ gui_display_remove (GimpContainer *displays)
if (gimp_container_is_empty (displays))
windows_show_toolbox ();
}
static void
gui_dbus_service_init (Gimp *gimp)
{
#if HAVE_DBUS_GLIB
GError *error = NULL;
g_return_if_fail (dbus_connection == NULL);
dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (dbus_connection)
{
GObject *service = gimp_dbus_service_new (gimp);
dbus_bus_request_name (dbus_g_connection_get_connection (dbus_connection),
GIMP_DBUS_SERVICE_NAME, 0, NULL);
dbus_g_connection_register_g_object (dbus_connection,
GIMP_DBUS_SERVICE_PATH, service);
}
else
{
g_printerr ("%s\n", error->message);
g_error_free (error);
}
#endif
}
static void
gui_dbus_service_exit (void)
{
#if HAVE_DBUS_GLIB
if (dbus_connection)
{
dbus_g_connection_unref (dbus_connection);
dbus_connection = NULL;
}
#endif
}