2008-07-11 17:08:07 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2008-07-11 17:08:07 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2008-07-11 17:08:07 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-07-11 17:08:07 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
#if HAVE_DBUS_GLIB
|
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "core/core-types.h"
|
|
|
|
|
|
|
|
#include "file/file-utils.h"
|
|
|
|
|
|
|
|
#include "unique.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if HAVE_DBUS_GLIB
|
|
|
|
static gboolean gimp_unique_dbus_open (const gchar **filenames,
|
2008-07-11 17:16:23 +08:00
|
|
|
gboolean as_new);
|
2008-07-11 17:08:07 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
static gboolean gimp_unique_win32_open (const gchar **filenames,
|
2008-07-11 17:16:23 +08:00
|
|
|
gboolean as_new);
|
2008-07-11 17:08:07 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_unique_open (const gchar **filenames,
|
2008-07-11 17:16:23 +08:00
|
|
|
gboolean as_new)
|
2008-07-11 17:08:07 +08:00
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
2008-07-11 17:16:23 +08:00
|
|
|
return gimp_unique_win32_open (filenames, as_new);
|
2008-07-11 17:08:07 +08:00
|
|
|
#elif HAVE_DBUS_GLIB
|
2008-07-11 17:16:23 +08:00
|
|
|
return gimp_unique_dbus_open (filenames, as_new);
|
2008-07-11 17:08:07 +08:00
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-07-14 03:49:32 +08:00
|
|
|
#ifndef GIMP_CONSOLE_COMPILATION
|
2008-07-11 18:31:27 +08:00
|
|
|
static gchar *
|
|
|
|
gimp_unique_filename_to_uri (const gchar *filename,
|
|
|
|
const gchar *cwd,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gchar *uri = NULL;
|
|
|
|
|
|
|
|
if (file_utils_filename_is_uri (filename, error))
|
|
|
|
{
|
|
|
|
uri = g_strdup (filename);
|
|
|
|
}
|
2008-07-11 20:38:53 +08:00
|
|
|
else if (! *error)
|
2008-07-11 18:31:27 +08:00
|
|
|
{
|
|
|
|
if (! g_path_is_absolute (filename))
|
|
|
|
{
|
|
|
|
gchar *absolute = g_build_filename (cwd, filename, NULL);
|
|
|
|
|
|
|
|
uri = g_filename_to_uri (absolute, NULL, error);
|
|
|
|
|
|
|
|
g_free (absolute);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uri = g_filename_to_uri (filename, NULL, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
2008-07-14 03:49:32 +08:00
|
|
|
#endif
|
|
|
|
|
2008-07-11 17:08:07 +08:00
|
|
|
|
|
|
|
#if HAVE_DBUS_GLIB
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_unique_dbus_open (const gchar **filenames,
|
2008-07-11 17:16:23 +08:00
|
|
|
gboolean as_new)
|
2008-07-11 17:08:07 +08:00
|
|
|
{
|
|
|
|
#ifndef GIMP_CONSOLE_COMPILATION
|
|
|
|
|
|
|
|
/* for the DBus service names */
|
2008-07-14 03:49:32 +08:00
|
|
|
#include "gui/gimpdbusservice.h"
|
2008-07-11 17:08:07 +08:00
|
|
|
|
|
|
|
DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
|
|
|
|
|
|
|
|
if (connection)
|
|
|
|
{
|
|
|
|
DBusGProxy *proxy;
|
|
|
|
gboolean success;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
proxy = dbus_g_proxy_new_for_name (connection,
|
|
|
|
GIMP_DBUS_SERVICE_NAME,
|
|
|
|
GIMP_DBUS_SERVICE_PATH,
|
|
|
|
GIMP_DBUS_SERVICE_INTERFACE);
|
|
|
|
|
|
|
|
if (filenames)
|
|
|
|
{
|
|
|
|
const gchar *method = as_new ? "OpenAsNew" : "Open";
|
2008-07-11 18:31:27 +08:00
|
|
|
gchar *cwd = g_get_current_dir ();
|
2008-07-11 17:08:07 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0, success = TRUE; filenames[i] && success; i++)
|
|
|
|
{
|
2008-07-11 18:31:27 +08:00
|
|
|
gchar *uri = gimp_unique_filename_to_uri (filenames[i],
|
|
|
|
cwd, &error);
|
2008-07-11 17:08:07 +08:00
|
|
|
|
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
gboolean retval; /* ignored */
|
|
|
|
|
|
|
|
success = dbus_g_proxy_call (proxy, method, &error,
|
|
|
|
G_TYPE_STRING, uri,
|
|
|
|
G_TYPE_INVALID,
|
|
|
|
G_TYPE_BOOLEAN, &retval,
|
|
|
|
G_TYPE_INVALID);
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_printerr ("conversion to uri failed: %s\n", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (cwd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
success = dbus_g_proxy_call (proxy, "Activate", &error,
|
|
|
|
G_TYPE_INVALID, G_TYPE_INVALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (proxy);
|
|
|
|
dbus_g_connection_unref (connection);
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (! (error->domain == DBUS_GERROR &&
|
|
|
|
error->code == DBUS_GERROR_SERVICE_UNKNOWN))
|
|
|
|
{
|
|
|
|
g_print ("%s\n", error->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_DBUS_GLIB */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_unique_win32_open (const gchar **filenames,
|
2008-07-11 17:16:23 +08:00
|
|
|
gboolean as_new)
|
2008-07-11 17:08:07 +08:00
|
|
|
{
|
|
|
|
#ifndef GIMP_CONSOLE_COMPILATION
|
|
|
|
|
2008-07-11 18:31:27 +08:00
|
|
|
/* for the proxy window names */
|
|
|
|
#include "gui/gui-unique.h"
|
|
|
|
|
|
|
|
HWND window_handle = FindWindowW (GIMP_UNIQUE_WIN32_WINDOW_CLASS,
|
|
|
|
GIMP_UNIQUE_WIN32_WINDOW_NAME);
|
|
|
|
|
|
|
|
if (window_handle)
|
|
|
|
{
|
2008-07-14 03:04:38 +08:00
|
|
|
COPYDATASTRUCT copydata = { 0, };
|
2008-07-14 02:00:06 +08:00
|
|
|
|
2008-07-14 03:04:38 +08:00
|
|
|
if (filenames)
|
|
|
|
{
|
|
|
|
gchar *cwd = g_get_current_dir ();
|
|
|
|
GError *error = NULL;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; filenames[i]; i++)
|
|
|
|
{
|
|
|
|
gchar *uri;
|
2008-07-11 18:31:27 +08:00
|
|
|
|
2008-07-14 03:04:38 +08:00
|
|
|
uri = gimp_unique_filename_to_uri (filenames[i], cwd, &error);
|
|
|
|
|
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
copydata.lpData = uri;
|
|
|
|
copydata.cbData = strlen (uri) + 1; /* size in bytes */
|
|
|
|
copydata.dwData = (long) as_new;
|
|
|
|
|
|
|
|
SendMessage (window_handle,
|
2009-12-19 16:29:07 +08:00
|
|
|
WM_COPYDATA, (WPARAM) window_handle, (LPARAM) ©data);
|
2008-07-14 03:04:38 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_printerr ("conversion to uri failed: %s\n", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (cwd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SendMessage (window_handle,
|
2009-12-19 16:29:07 +08:00
|
|
|
WM_COPYDATA, (WPARAM) window_handle, (LPARAM) ©data);
|
2008-07-14 03:04:38 +08:00
|
|
|
}
|
2008-07-11 18:31:27 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-07-11 17:08:07 +08:00
|
|
|
#endif
|
|
|
|
|
2008-07-11 20:38:53 +08:00
|
|
|
return FALSE;
|
2008-07-11 17:08:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* G_OS_WIN32 */
|