2007-01-19 22:50:13 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* GimpDBusService
|
2008-08-06 01:29:19 +08:00
|
|
|
* Copyright (C) 2007, 2008 Sven Neumann <sven@gimp.org>
|
2007-01-19 22:50:13 +08:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gchar *uri;
|
|
|
|
gboolean as_new;
|
|
|
|
} OpenData;
|
|
|
|
|
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
static void gimp_dbus_service_class_init (GimpDBusServiceClass *klass);
|
2008-08-06 00:09:29 +08:00
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
static void gimp_dbus_service_init (GimpDBusService *service);
|
|
|
|
static void gimp_dbus_service_dispose (GObject *object);
|
|
|
|
static void gimp_dbus_service_finalize (GObject *object);
|
2008-08-06 00:09:29 +08:00
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
static gboolean gimp_dbus_service_queue_open (GimpDBusService *service,
|
|
|
|
const gchar *uri,
|
|
|
|
gboolean as_new);
|
|
|
|
|
|
|
|
static gboolean gimp_dbus_service_open_idle (GimpDBusService *service);
|
|
|
|
static OpenData * gimp_dbus_service_open_data_new (GimpDBusService *service,
|
|
|
|
const gchar *uri,
|
|
|
|
gboolean as_new);
|
|
|
|
static void gimp_dbus_service_open_data_free (OpenData *data);
|
2008-08-06 00:09:29 +08:00
|
|
|
|
2007-01-19 22:50:13 +08:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpDBusService, gimp_dbus_service, G_TYPE_OBJECT)
|
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
#define parent_class gimp_dbus_service_parent_class
|
|
|
|
|
2007-01-19 22:50:13 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dbus_service_class_init (GimpDBusServiceClass *klass)
|
|
|
|
{
|
2008-08-06 00:09:29 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = gimp_dbus_service_dispose;
|
|
|
|
object_class->finalize = gimp_dbus_service_finalize;
|
|
|
|
|
2007-01-19 22:50:13 +08:00
|
|
|
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
|
|
|
|
&dbus_glib_gimp_object_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dbus_service_init (GimpDBusService *service)
|
|
|
|
{
|
2008-08-06 00:09:29 +08:00
|
|
|
service->queue = g_queue_new ();
|
2007-01-19 22:50:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06 00:09:29 +08:00
|
|
|
static void
|
|
|
|
gimp_dbus_service_dispose (GObject *object)
|
2008-08-05 17:02:04 +08:00
|
|
|
{
|
2008-08-06 00:09:29 +08:00
|
|
|
GimpDBusService *service = GIMP_DBUS_SERVICE (object);
|
2008-08-05 17:02:04 +08:00
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
if (service->source)
|
|
|
|
{
|
|
|
|
g_source_remove (g_source_get_id (service->source));
|
|
|
|
service->source = NULL;
|
|
|
|
}
|
2008-08-05 17:02:04 +08:00
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
while (! g_queue_is_empty (service->queue))
|
|
|
|
{
|
|
|
|
gimp_dbus_service_open_data_free (g_queue_pop_head (service->queue));
|
|
|
|
}
|
2008-08-05 17:02:04 +08:00
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2008-08-05 17:02:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-08-06 00:09:29 +08:00
|
|
|
gimp_dbus_service_finalize (GObject *object)
|
2008-08-05 17:02:04 +08:00
|
|
|
{
|
2008-08-06 00:09:29 +08:00
|
|
|
GimpDBusService *service = GIMP_DBUS_SERVICE (object);
|
2008-08-05 17:02:04 +08:00
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
if (service->queue)
|
|
|
|
{
|
|
|
|
g_queue_free (service->queue);
|
|
|
|
service->queue = NULL;
|
|
|
|
}
|
2008-08-05 17:02:04 +08:00
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2008-08-05 17:02:04 +08:00
|
|
|
}
|
|
|
|
|
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-06 16:15:36 +08:00
|
|
|
*success = gimp_dbus_service_queue_open (service, uri, FALSE);
|
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-06 16:15:36 +08:00
|
|
|
*success = gimp_dbus_service_queue_open (service, uri, 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-06 16:15:36 +08:00
|
|
|
/*
|
|
|
|
* Adds a request to open a file to the end of the queue and
|
|
|
|
* starts an idle source if it is not already running.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
gimp_dbus_service_queue_open (GimpDBusService *service,
|
|
|
|
const gchar *uri,
|
|
|
|
gboolean as_new)
|
2008-08-06 00:09:29 +08:00
|
|
|
{
|
2008-08-06 16:15:36 +08:00
|
|
|
g_queue_push_tail (service->queue,
|
|
|
|
gimp_dbus_service_open_data_new (service, uri, as_new));
|
2008-08-06 00:09:29 +08:00
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
if (! service->source)
|
|
|
|
{
|
|
|
|
service->source = g_idle_source_new ();
|
2008-08-06 00:09:29 +08:00
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
g_source_set_callback (service->source,
|
|
|
|
(GSourceFunc) gimp_dbus_service_open_idle, service,
|
|
|
|
NULL);
|
|
|
|
g_source_attach (service->source, NULL);
|
|
|
|
g_source_unref (service->source);
|
|
|
|
}
|
2008-08-06 00:09:29 +08:00
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
/* The call always succeeds as it is handled in one way or another.
|
|
|
|
* Even presenting an error message is considered success ;-)
|
|
|
|
*/
|
|
|
|
return TRUE;
|
2008-08-06 00:09:29 +08:00
|
|
|
}
|
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
/*
|
|
|
|
* Idle callback that removes the first request from the queue and
|
|
|
|
* handles it. If there are no more requests, the idle source is
|
|
|
|
* removed.
|
|
|
|
*/
|
2008-08-06 00:09:29 +08:00
|
|
|
static gboolean
|
2008-08-06 01:29:19 +08:00
|
|
|
gimp_dbus_service_open_idle (GimpDBusService *service)
|
2008-08-06 00:09:29 +08:00
|
|
|
{
|
2008-08-06 01:29:19 +08:00
|
|
|
OpenData *data = g_queue_pop_tail (service->queue);
|
2008-08-06 00:09:29 +08:00
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
2008-08-06 01:29:19 +08:00
|
|
|
file_open_from_command_line (service->gimp, data->uri, data->as_new);
|
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
gimp_dbus_service_open_data_free (data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-06 01:29:19 +08:00
|
|
|
service->source = NULL;
|
|
|
|
|
2008-08-06 00:09:29 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
static OpenData *
|
|
|
|
gimp_dbus_service_open_data_new (GimpDBusService *service,
|
|
|
|
const gchar *uri,
|
|
|
|
gboolean as_new)
|
2008-08-06 00:09:29 +08:00
|
|
|
{
|
2008-08-06 16:15:36 +08:00
|
|
|
OpenData *data = g_slice_new (OpenData);
|
2008-08-06 00:09:29 +08:00
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
data->uri = g_strdup (uri);
|
|
|
|
data->as_new = as_new;
|
2008-08-06 00:09:29 +08:00
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
return data;
|
2008-08-06 00:09:29 +08:00
|
|
|
}
|
2008-08-05 17:02:04 +08:00
|
|
|
|
2008-08-06 16:15:36 +08:00
|
|
|
static void
|
|
|
|
gimp_dbus_service_open_data_free (OpenData *data)
|
|
|
|
{
|
|
|
|
g_free (data->uri);
|
|
|
|
g_slice_free (OpenData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-19 22:50:13 +08:00
|
|
|
#endif /* HAVE_DBUS_GLIB */
|