2007-01-19 22:50:13 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* GimpDBusService
|
|
|
|
* Copyright (C) 2007 Sven Neumann <sven@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"
|
|
|
|
|
|
|
|
#if HAVE_DBUS_GLIB
|
|
|
|
|
2008-06-28 21:32:45 +08:00
|
|
|
#include <gtk/gtk.h>
|
2007-01-19 22:50:13 +08:00
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
|
2008-07-14 03:49:32 +08:00
|
|
|
#include "gui-types.h"
|
2007-01-19 22:50:13 +08:00
|
|
|
|
|
|
|
#include "core/gimp.h"
|
2008-07-14 03:49:32 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2007-01-19 22:50:13 +08:00
|
|
|
|
|
|
|
#include "file/file-open.h"
|
|
|
|
|
2008-07-14 03:49:32 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2007-01-19 22:50:13 +08:00
|
|
|
#include "gimpdbusservice.h"
|
|
|
|
#include "gimpdbusservice-glue.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_dbus_service_class_init (GimpDBusServiceClass *klass);
|
|
|
|
static void gimp_dbus_service_init (GimpDBusService *service);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpDBusService, gimp_dbus_service, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dbus_service_class_init (GimpDBusServiceClass *klass)
|
|
|
|
{
|
|
|
|
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
|
|
|
|
&dbus_glib_gimp_object_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dbus_service_init (GimpDBusService *service)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GObject *
|
|
|
|
gimp_dbus_service_new (Gimp *gimp)
|
|
|
|
{
|
|
|
|
GimpDBusService *service;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
|
|
service = g_object_new (GIMP_TYPE_DBUS_SERVICE, NULL);
|
|
|
|
|
|
|
|
service->gimp = gimp;
|
|
|
|
|
|
|
|
return G_OBJECT (service);
|
|
|
|
}
|
|
|
|
|
2008-08-05 17:02:04 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Gimp *gimp;
|
|
|
|
gchar *uri;
|
|
|
|
gboolean as_new;
|
|
|
|
} IdleData;
|
|
|
|
|
|
|
|
static IdleData *
|
|
|
|
gimp_dbus_service_open_idle_new (GimpDBusService *service,
|
|
|
|
const gchar *uri,
|
|
|
|
gboolean as_new)
|
|
|
|
{
|
|
|
|
IdleData *data = g_slice_new (IdleData);
|
|
|
|
|
|
|
|
data->gimp = g_object_ref (service->gimp);
|
|
|
|
data->uri = g_strdup (uri);
|
|
|
|
data->as_new = as_new;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dbus_service_open_idle_free (IdleData *data)
|
|
|
|
{
|
|
|
|
g_object_unref (data->gimp);
|
|
|
|
g_free (data->uri);
|
|
|
|
|
|
|
|
g_slice_free (IdleData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_dbus_service_open_idle (IdleData *data)
|
|
|
|
{
|
|
|
|
file_open_from_command_line (data->gimp, data->uri, data->as_new);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-01-19 22:50:13 +08:00
|
|
|
gboolean
|
|
|
|
gimp_dbus_service_open (GimpDBusService *service,
|
2007-04-22 02:09:16 +08:00
|
|
|
const gchar *uri,
|
2007-03-28 04:12:44 +08:00
|
|
|
gboolean *success,
|
2007-01-23 05:39:57 +08:00
|
|
|
GError **dbus_error)
|
2007-01-19 22:50:13 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DBUS_SERVICE (service), FALSE);
|
2007-04-22 02:09:16 +08:00
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
2007-03-28 04:12:44 +08:00
|
|
|
g_return_val_if_fail (success != NULL, FALSE);
|
2007-01-19 22:50:13 +08:00
|
|
|
|
2008-08-05 17:02:04 +08:00
|
|
|
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
|
|
|
|
(GSourceFunc) gimp_dbus_service_open_idle,
|
|
|
|
gimp_dbus_service_open_idle_new (service, uri, FALSE),
|
|
|
|
(GDestroyNotify) gimp_dbus_service_open_idle_free);
|
|
|
|
|
|
|
|
/* The call always succeeds as it is handled in one way or another.
|
|
|
|
* Even presenting an error message is considered success ;-)
|
|
|
|
*/
|
|
|
|
*success = TRUE;
|
2007-04-17 23:54:01 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_dbus_service_open_as_new (GimpDBusService *service,
|
2007-04-22 02:09:16 +08:00
|
|
|
const gchar *uri,
|
2007-04-17 23:54:01 +08:00
|
|
|
gboolean *success,
|
|
|
|
GError **dbus_error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DBUS_SERVICE (service), FALSE);
|
2007-04-22 02:09:16 +08:00
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
2007-04-17 23:54:01 +08:00
|
|
|
g_return_val_if_fail (success != NULL, FALSE);
|
|
|
|
|
2008-08-05 17:02:04 +08:00
|
|
|
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
|
|
|
|
(GSourceFunc) gimp_dbus_service_open_idle,
|
|
|
|
gimp_dbus_service_open_idle_new (service, uri, TRUE),
|
|
|
|
(GDestroyNotify) gimp_dbus_service_open_idle_free);
|
|
|
|
|
|
|
|
/* The call always succeeds as it is handled in one way or another.
|
|
|
|
* Even presenting an error message is considered success ;-)
|
|
|
|
*/
|
|
|
|
*success = TRUE;
|
2007-01-19 22:50:13 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-01-23 07:25:37 +08:00
|
|
|
gboolean
|
|
|
|
gimp_dbus_service_activate (GimpDBusService *service,
|
|
|
|
GError **dbus_error)
|
|
|
|
{
|
2008-07-14 03:49:32 +08:00
|
|
|
GimpObject *display;
|
2007-01-23 07:25:37 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DBUS_SERVICE (service), FALSE);
|
|
|
|
|
2008-07-14 03:49:32 +08:00
|
|
|
display = gimp_container_get_first_child (service->gimp->displays);
|
2007-01-23 07:25:37 +08:00
|
|
|
|
2008-07-14 03:49:32 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (GIMP_DISPLAY (display)->shell));
|
2007-01-23 07:25:37 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-01-19 22:50:13 +08:00
|
|
|
|
2008-08-05 17:02:04 +08:00
|
|
|
|
2007-01-19 22:50:13 +08:00
|
|
|
#endif /* HAVE_DBUS_GLIB */
|