2000-08-01 20:22:57 +00:00
|
|
|
/* -*- mode: c; style: linux -*- */
|
|
|
|
|
|
|
|
/* main.c
|
2001-10-15 16:06:56 +00:00
|
|
|
* Copyright (C) 2000, 2001 Ximian, Inc.
|
2000-08-01 20:22:57 +00:00
|
|
|
*
|
2001-10-15 16:06:56 +00:00
|
|
|
* Written by Bradford Hovinen <hovinen@ximian.com>
|
2000-08-01 20:22:57 +00: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, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-02-04 17:48:43 +00:00
|
|
|
#include <string.h>
|
2000-08-01 20:22:57 +00:00
|
|
|
#include <gnome.h>
|
2000-08-11 19:17:30 +00:00
|
|
|
#include <glade/glade.h>
|
2001-07-13 17:19:50 +00:00
|
|
|
#include <gconf/gconf.h>
|
2002-01-21 22:44:12 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <gdk/gdkx.h>
|
2001-07-13 17:19:50 +00:00
|
|
|
|
2000-08-01 20:22:57 +00:00
|
|
|
#include "capplet-dir.h"
|
2000-08-11 19:17:30 +00:00
|
|
|
#include "capplet-dir-view.h"
|
2000-08-01 20:22:57 +00:00
|
|
|
|
2002-02-09 01:33:32 +00:00
|
|
|
static gint use_shell = 0;
|
|
|
|
|
|
|
|
static struct poptOption cap_options[] = {
|
|
|
|
{"use-shell", '\0', POPT_ARG_NONE, &use_shell, 0,
|
|
|
|
N_("Use shell even if nautilus is running."), NULL},
|
|
|
|
{NULL, '\0', 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2002-01-21 22:44:12 +00:00
|
|
|
static gboolean
|
|
|
|
is_nautilus_running (void)
|
|
|
|
{
|
|
|
|
Atom window_id_atom;
|
|
|
|
Window nautilus_xid;
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *data;
|
|
|
|
int retval;
|
|
|
|
Atom wmclass_atom;
|
|
|
|
gboolean running;
|
|
|
|
gint error;
|
|
|
|
|
|
|
|
window_id_atom = XInternAtom (GDK_DISPLAY (),
|
|
|
|
"NAUTILUS_DESKTOP_WINDOW_ID", True);
|
|
|
|
|
|
|
|
if (window_id_atom == None) return FALSE;
|
|
|
|
|
|
|
|
retval = XGetWindowProperty (GDK_DISPLAY (), GDK_ROOT_WINDOW (),
|
|
|
|
window_id_atom, 0, 1, False, XA_WINDOW,
|
|
|
|
&actual_type, &actual_format, &nitems,
|
|
|
|
&bytes_after, &data);
|
|
|
|
|
|
|
|
if (data != NULL) {
|
|
|
|
nautilus_xid = *(Window *) data;
|
|
|
|
XFree (data);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actual_type != XA_WINDOW) return FALSE;
|
|
|
|
if (actual_format != 32) return FALSE;
|
|
|
|
|
|
|
|
wmclass_atom = XInternAtom (GDK_DISPLAY (), "WM_CLASS", False);
|
|
|
|
|
|
|
|
gdk_error_trap_push ();
|
|
|
|
|
|
|
|
retval = XGetWindowProperty (GDK_DISPLAY (), nautilus_xid,
|
|
|
|
wmclass_atom, 0, 24, False, XA_STRING,
|
|
|
|
&actual_type, &actual_format, &nitems,
|
|
|
|
&bytes_after, &data);
|
|
|
|
|
|
|
|
error = gdk_error_trap_pop ();
|
|
|
|
|
|
|
|
if (error == BadWindow) return FALSE;
|
|
|
|
|
|
|
|
if (actual_type == XA_STRING &&
|
|
|
|
nitems == 24 &&
|
|
|
|
bytes_after == 0 &&
|
|
|
|
actual_format == 8 &&
|
|
|
|
data != NULL &&
|
|
|
|
!strcmp (data, "desktop_window") &&
|
|
|
|
!strcmp (data + strlen (data) + 1, "Nautilus"))
|
|
|
|
running = TRUE;
|
|
|
|
else
|
|
|
|
running = FALSE;
|
|
|
|
|
|
|
|
if (data != NULL)
|
|
|
|
XFree (data);
|
|
|
|
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
2002-02-19 21:15:21 +00:00
|
|
|
static gboolean
|
|
|
|
gnome_cc_save_yourself (GnomeClient *client, gint phase, GnomeSaveStyle save_style,
|
|
|
|
gboolean shutdown, GnomeInteractStyle interact_style,
|
|
|
|
gboolean fast, gchar *argv0)
|
|
|
|
{
|
|
|
|
gchar *argv[3];
|
|
|
|
gint argc;
|
|
|
|
|
|
|
|
argv[0] = argv0;
|
|
|
|
argv[1] = "--use-shell";
|
|
|
|
argc = 2;
|
|
|
|
gnome_client_set_clone_command (client, argc, argv);
|
|
|
|
gnome_client_set_restart_command (client, argc, argv);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnome_cc_die (GnomeClient *client, gpointer data)
|
|
|
|
{
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
2000-08-01 20:22:57 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2001-07-25 17:44:07 +00:00
|
|
|
CappletDirEntry *entry;
|
|
|
|
CappletDir *dir;
|
2002-02-19 21:15:21 +00:00
|
|
|
GnomeClient *client;
|
2001-07-25 17:44:07 +00:00
|
|
|
|
2002-02-27 22:20:28 +00:00
|
|
|
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain (GETTEXT_PACKAGE);
|
2000-08-01 20:22:57 +00:00
|
|
|
|
2001-11-26 17:06:41 +00:00
|
|
|
gnome_program_init ("control-center", VERSION, LIBGNOMEUI_MODULE,
|
2002-01-14 20:50:44 +00:00
|
|
|
argc, argv,
|
|
|
|
GNOME_PARAM_APP_DATADIR, GNOMECC_DATA_DIR,
|
2002-02-09 01:33:32 +00:00
|
|
|
GNOME_PARAM_POPT_TABLE, cap_options,
|
2002-01-14 20:50:44 +00:00
|
|
|
NULL);
|
2001-06-29 20:48:29 +00:00
|
|
|
|
2002-02-09 01:33:32 +00:00
|
|
|
if (!use_shell && is_nautilus_running ())
|
2002-01-21 22:44:12 +00:00
|
|
|
execlp ("nautilus", "nautilus", "preferences:///", NULL);
|
|
|
|
|
2001-12-17 20:33:19 +00:00
|
|
|
gnomecc_init ();
|
|
|
|
dir = get_root_capplet_dir ();
|
|
|
|
if (dir == NULL)
|
|
|
|
return -1;
|
|
|
|
entry = CAPPLET_DIR_ENTRY (dir);
|
|
|
|
if (entry == NULL)
|
|
|
|
return -1;
|
|
|
|
capplet_dir_entry_activate (entry, NULL);
|
2000-08-01 20:22:57 +00:00
|
|
|
|
2002-02-19 21:15:21 +00:00
|
|
|
client = gnome_master_client ();
|
|
|
|
g_signal_connect (G_OBJECT (client), "save_yourself",
|
|
|
|
G_CALLBACK (gnome_cc_save_yourself), argv[0]);
|
|
|
|
g_signal_connect (G_OBJECT (client), "die",
|
|
|
|
G_CALLBACK (gnome_cc_die), NULL);
|
|
|
|
|
2001-12-14 01:27:14 +00:00
|
|
|
gtk_main ();
|
2000-08-01 20:22:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|