Exemplo n.º 1
0
/*
 * Pick the right starting directory. First try the name passed on the
 * command-line, then $HOME, and finally fall back to / .
 */
static char *
getdir(int argc, char *argv[])
{
	GFile		*g_dir;
	const char	*cwd;
	char		*dir;

	dir = NULL;

	if (argc > 0) {
		if ((cwd = getcwd(NULL, 0)) == NULL)
			warnx("could not get the current working directory");
		else {
			g_dir = g_file_new_for_commandline_arg_and_cwd(
			    argv[0], cwd);
			if ((dir = g_file_get_path(g_dir)) == NULL)
				warnx("no such directory: %s", argv[0]);

			g_object_unref(g_dir);
		}
	} else
		dir = getenv("HOME");

	if (dir == NULL)
		dir = "/";

	return dir;
}
Exemplo n.º 2
0
static gboolean
gimp_unique_dbus_open (const gchar **filenames,
		       gboolean      as_new)
{
#ifndef GIMP_CONSOLE_COMPILATION

/*  for the DBus service names  */
#include "gui/gimpdbusservice.h"

  GDBusConnection *connection;
  GError          *error = NULL;

  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);

  if (connection)
    {
      gboolean success = TRUE;

      if (filenames)
        {
          const gchar *method = as_new ? "OpenAsNew" : "Open";
          gchar       *cwd    = g_get_current_dir ();
          gint         i;

          for (i = 0; filenames[i] && success; i++)
            {
              GFile *file;

              file = g_file_new_for_commandline_arg_and_cwd (filenames[i], cwd);

              if (file)
                {
                  GVariant *result;
                  gchar    *uri = g_file_get_uri (file);

                  result = g_dbus_connection_call_sync (connection,
                                                        GIMP_DBUS_SERVICE_NAME,
                                                        GIMP_DBUS_SERVICE_PATH,
                                                        GIMP_DBUS_INTERFACE_NAME,
                                                        method,
                                                        g_variant_new ("(s)",
                                                                       uri),
                                                        NULL,
                                                        G_DBUS_CALL_FLAGS_NO_AUTO_START,
                                                        -1,
                                                        NULL, NULL);

                  g_free (uri);

                  if (result)
                    g_variant_unref (result);
                  else
                    success = FALSE;

                  g_object_unref (file);
                }
              else
                {
                  g_printerr ("conversion to uri failed for '%s'\n",
                              filenames[i]);
                }
            }

          g_free (cwd);
        }
      else
        {
          GVariant *result;

          result = g_dbus_connection_call_sync (connection,
                                                GIMP_DBUS_SERVICE_NAME,
                                                GIMP_DBUS_SERVICE_PATH,
                                                GIMP_DBUS_INTERFACE_NAME,
                                                "Activate",
                                                NULL,
                                                NULL,
                                                G_DBUS_CALL_FLAGS_NO_AUTO_START,
                                                -1,
                                                NULL, NULL);
          if (result)
            g_variant_unref (result);
          else
            success = FALSE;
        }

      g_object_unref (connection);

      return success;
    }
  else
    {
      g_printerr ("%s\n", error->message);
      g_clear_error (&error);
    }
#endif

  return FALSE;
}
Exemplo n.º 3
0
static gboolean
gimp_unique_win32_open (const gchar **filenames,
			gboolean      as_new)
{
#ifndef GIMP_CONSOLE_COMPILATION

/*  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)
    {
      COPYDATASTRUCT  copydata = { 0, };

      if (filenames)
        {
          gchar  *cwd   = g_get_current_dir ();
          gint    i;

          for (i = 0; filenames[i]; i++)
            {
              GFile *file;
              file = g_file_new_for_commandline_arg_and_cwd (filenames[i], cwd);

              if (file)
                {
                  gchar *uri = g_file_get_uri (file);

                  copydata.lpData = uri;
                  copydata.cbData = strlen (uri) + 1;  /* size in bytes   */
                  copydata.dwData = (long) as_new;

                  SendMessage (window_handle,
                               WM_COPYDATA, (WPARAM) window_handle, (LPARAM) &copydata);

                  g_free (uri);
                  g_object_unref (file);
                }
              else
                {
                  g_printerr ("conversion to uri failed for '%s'\n",
                              filenames[i]);
                }
            }

          g_free (cwd);
        }
      else
        {
          SendMessage (window_handle,
                       WM_COPYDATA, (WPARAM) window_handle, (LPARAM) &copydata);
        }

      return TRUE;
    }

#endif

  return FALSE;
}