2
* Copyright (C) 2003 Sun Microsystems, Inc.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
20
* Mark McLoughlin <mark@skynet.ie>
27
#include <glib/gi18n.h>
29
#include <libgnome/gnome-program.h>
30
#include <libgnomeui/gnome-client.h>
31
#include <libgnomeui/gnome-ui-init.h>
33
#include "gsm-protocol.h"
35
static GSList *clients;
36
static gboolean do_list;
38
/* The number of names of programs we've seen. */
39
static int program_count;
41
/* The names of the programs we're looking to remove. */
42
static char **program_names;
44
/* A count of the number of client programs we are trying to
46
static int remove_count;
48
static const GOptionEntry gsm_remove_opts[] = {
49
{ "list", 0, 0, G_OPTION_ARG_NONE, &do_list,
50
N_("List registered clients, then exit"), NULL },
51
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
52
&program_names, NULL, N_("PROGRAM...") },
57
client_factory (gpointer user_data)
61
client = g_object_new (GSM_TYPE_CLIENT, NULL);
63
clients = g_slist_prepend (clients, client);
71
if (--remove_count == 0)
76
find_program (char *name)
81
for (i = 0; i < program_count; ++i)
82
if (program_names[i] && ! strcmp (name, program_names[i]))
89
session_initialized (GsmSession *session, void *ignore)
94
for (l = clients; l; l = l->next)
96
GsmClient *client = l->data;
97
char *client_program = NULL;
99
if (client->program != NULL)
100
client_program = g_strdup (client->program);
101
else if (client->command != NULL)
106
if (g_shell_parse_argv (client->command, &argc, &argv, NULL))
108
client_program = g_strdup (argv[0]);
118
&& strcmp (client_program, "gnome-session-remove"))
119
g_print (" %s\n", client_program);
123
int index = find_program (client_program);
128
program_names[index] = NULL;
129
g_print ("Removing '%s' from the session\n", client_program);
130
gsm_client_commit_remove (client);
131
g_signal_connect (client, "remove",
132
G_CALLBACK (client_removed), NULL);
137
g_free (client_program);
145
main (int argc, char **argv)
148
GsmProtocol *protocol;
150
GOptionContext *option_context;
152
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
153
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
154
textdomain (GETTEXT_PACKAGE);
156
option_context = g_option_context_new ("");
157
g_option_context_add_main_entries (option_context, gsm_remove_opts,
160
gnome_program_init ("gnome-session-remove",
161
VERSION, LIBGNOMEUI_MODULE,
163
GNOME_PARAM_GOPTION_CONTEXT, option_context,
164
GNOME_PROGRAM_STANDARD_PROPERTIES,
168
program_names = g_strdupv (program_names);
169
for (program_count = 0;
170
program_names && program_names[program_count];
174
if (!do_list && program_count < 1)
176
g_printerr (_("You must specify at least one program to remove. You can list the programs with --list.\n"));
180
client = gnome_master_client ();
181
if (!GNOME_CLIENT_CONNECTED (client))
183
g_printerr (_("Error: could not connect to the session manager\n"));
187
gnome_client_set_restart_style (client, GNOME_RESTART_NEVER);
189
protocol = gsm_protocol_new (client);
190
gsm_protocol_get_current_session (GSM_PROTOCOL (protocol));
192
session = gsm_session_live ((GsmClientFactory) client_factory, NULL);
193
g_signal_connect (session, "initialized",
194
G_CALLBACK (session_initialized), NULL);
197
g_print (_("Currently registered clients:\n"));
204
for (i = 0; i < program_count; ++i)
206
if (program_names[i])
207
g_print (_("Couldn't find program %s in session\n"),