gimp/app/widgets/gimpdbusservice.c

118 lines
3.1 KiB
C
Raw Normal View History

/* 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
#include <dbus/dbus-glib.h>
#include "core/core-types.h"
#include "core/gimp.h"
#include "file/file-open.h"
#include "file/file-utils.h"
#include "gimpdbusservice.h"
#include "gimpdbusservice-glue.h"
#include "gimpuimanager.c"
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);
}
gboolean
gimp_dbus_service_open (GimpDBusService *service,
const gchar **uris,
GError **error)
{
gint i;
g_return_val_if_fail (GIMP_IS_DBUS_SERVICE (service), FALSE);
for (i = 0; uris[i]; i++)
{
GimpImage *image;
gchar *uri;
GimpPDBStatusType status;
/* the method is documented to take URIs but we also accept filenames */
uri = file_utils_any_to_uri (service->gimp, uris[i], error);
if (! uri)
return FALSE;
image = file_open_with_display (service->gimp,
gimp_get_user_context (service->gimp),
NULL,
uris[i],
&status, error);
g_free (uri);
if (! image && status != GIMP_PDB_CANCEL)
return FALSE;
}
/* if no URI is passed, raise the toolbox */
if (i == 0)
{
const GList *managers = gimp_ui_managers_from_name ("<Image>");
if (managers)
gimp_ui_manager_activate_action (managers->data,
"dialogs", "dialogs-toolbox");
}
return TRUE;
}
#endif /* HAVE_DBUS_GLIB */