Commit 30cc37c5 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/Makefile.am new files containing functionality to check for an already

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

	* app/Makefile.am 
	* app/unique.[ch]: new files containing functionality to check 
for
	an already running instance of GIMP of notifying it about files 
to
	open. Code split out of main.c.

	* app/main.c: changed accordingly.


svn path=/trunk/; revision=26117
parent c6260c55
2008-07-11 Sven Neumann <sven@gimp.org>
* app/Makefile.am
* app/unique.[ch]: new files containing functionality to check for
an already running instance of GIMP of notifying it about files to
open. Code split out of main.c.
* app/main.c: changed accordingly.
2008-07-11 Sven Neumann <sven@gimp.org>
* app/main.c (gimp_init_malloc): removed misleading comment.
......
......@@ -49,6 +49,8 @@ app_sources = \
main.c \
sanity.c \
sanity.h \
unique.c \
unique.h \
units.c \
units.h \
version.c \
......
......@@ -64,6 +64,7 @@
#include "gimp-intl.h"
/* local prototypes */
static void app_init_update_none (const gchar *text1,
......
......@@ -41,14 +41,6 @@
#include <io.h> /* get_osfhandle */
#endif
#if HAVE_DBUS_GLIB
#include <dbus/dbus-glib.h>
#endif
#ifndef GIMP_CONSOLE_COMPILATION
#include <gdk/gdk.h>
#endif
#include "libgimpbase/gimpbase.h"
#include "core/core-types.h"
......@@ -59,14 +51,11 @@
#include "core/gimp.h"
#include "file/file-utils.h"
#include "widgets/gimpdbusservice.h"
#include "about.h"
#include "app.h"
#include "errors.h"
#include "sanity.h"
#include "unique.h"
#include "units.h"
#include "version.h"
......@@ -113,11 +102,6 @@ static void gimp_open_console_window (void);
#define gimp_open_console_window() /* as nothing */
#endif
static gboolean gimp_dbus_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose);
static const gchar *system_gimprc = NULL;
static const gchar *user_gimprc = NULL;
static const gchar *session_name = NULL;
......@@ -388,7 +372,7 @@ main (int argc,
if (! new_instance)
{
if (gimp_dbus_open (filenames, as_new, be_verbose))
if (gimp_unique_open (filenames, as_new, be_verbose))
return EXIT_SUCCESS;
}
......@@ -695,113 +679,3 @@ gimp_sigfatal_handler (gint sig_num)
}
#endif /* ! G_OS_WIN32 */
static gboolean
gimp_dbus_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose)
{
#ifndef GIMP_CONSOLE_COMPILATION
#if HAVE_DBUS_GLIB
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";
gchar *cwd = NULL;
gint i;
for (i = 0, success = TRUE; filenames[i] && success; i++)
{
const gchar *filename = filenames[i];
gchar *uri = NULL;
if (file_utils_filename_is_uri (filename, &error))
{
uri = g_strdup (filename);
}
else if (! error)
{
if (! g_path_is_absolute (filename))
{
gchar *absolute;
if (! cwd)
cwd = g_get_current_dir ();
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);
}
}
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)
{
if (be_verbose)
g_print ("%s\n",
_("Another GIMP instance is already running."));
gdk_notify_startup_complete ();
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
#endif
return FALSE;
}
/* 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
#include <dbus/dbus-glib.h>
#endif
#ifdef G_OS_WIN32
#include <windows.h>
#endif
#ifndef GIMP_CONSOLE_COMPILATION
#include <gdk/gdk.h>
#endif
#include "core/core-types.h"
#include "file/file-utils.h"
#include "unique.h"
#include "gimp-intl.h"
#if HAVE_DBUS_GLIB
static gboolean gimp_unique_dbus_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose);
#endif
#ifdef G_OS_WIN32
static gboolean gimp_unique_win32_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose);
#endif
gboolean
gimp_unique_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose)
{
#ifdef G_OS_WIN32
return gimp_unique_win32_open (filenames, as_new, be_verbose);
#elif HAVE_DBUS_GLIB
return gimp_unique_dbus_open (filenames, as_new, be_verbose);
#else
return FALSE;
#endif
}
#if HAVE_DBUS_GLIB
static gboolean
gimp_unique_dbus_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose)
{
#ifndef GIMP_CONSOLE_COMPILATION
/* for the DBus service names */
#include "widgets/gimpdbusservice.h"
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";
gchar *cwd = NULL;
gint i;
for (i = 0, success = TRUE; filenames[i] && success; i++)
{
const gchar *filename = filenames[i];
gchar *uri = NULL;
if (file_utils_filename_is_uri (filename, &error))
{
uri = g_strdup (filename);
}
else if (! error)
{
if (! g_path_is_absolute (filename))
{
gchar *absolute;
if (! cwd)
cwd = g_get_current_dir ();
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);
}
}
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)
{
if (be_verbose)
g_print ("%s\n",
_("Another GIMP instance is already running."));
gdk_notify_startup_complete ();
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,
gboolean as_new,
gboolean be_verbose)
{
#ifndef GIMP_CONSOLE_COMPILATION
#endif
return FALSE
}
#endif /* G_OS_WIN32 */
/* 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 __UNIQUE_H__
#define __UNIQUE_H__
gboolean gimp_unique_open (const gchar **filenames,
gboolean as_new,
gboolean be_verbose);
#endif /* __UNIQUE_H__ */
......@@ -8,6 +8,7 @@ app/app.c
app/batch.c
app/main.c
app/sanity.c
app/unique.c
app/version.c
app/actions/actions.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment