source: proiecte/PPPP/gdm/gui/simple-chooser/gdm-host-chooser.c @ 134

Last change on this file since 134 was 134, checked in by (none), 14 years ago

gdm sources with the modifications for webcam

File size: 7.6 KB
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20#include "config.h"
21
22#include <stdlib.h>
23#include <libintl.h>
24#include <locale.h>
25#include <string.h>
26#include <unistd.h>
27#include <signal.h>
28#include <errno.h>
29
30#include <glib/gi18n.h>
31#include <gdk/gdkx.h>
32#include <gtk/gtk.h>
33#include <gconf/gconf-client.h>
34
35#include "gdm-common.h"
36#include "gdm-log.h"
37#include "gdm-settings-client.h"
38#include "gdm-settings-keys.h"
39
40#include "gdm-chooser-host.h"
41#include "gdm-host-chooser-dialog.h"
42
43#define ACCESSIBILITY_KEY         "/desktop/gnome/interface/accessibility"
44
45static Atom AT_SPI_IOR;
46
47
48static gboolean
49assistive_registry_launch (void)
50{
51        GPid        pid;
52        GError     *error;
53        const char *command;
54        char      **argv;
55        gboolean    res;
56
57        command = AT_SPI_REGISTRYD_DIR "/at-spi-registryd";
58
59        argv = NULL;
60        error = NULL;
61        res = g_shell_parse_argv (command, NULL, &argv, &error);
62        if (! res) {
63                g_warning ("Unable to parse command: %s", error->message);
64                return FALSE;
65        }
66
67        error = NULL;
68        res = g_spawn_async (NULL,
69                             argv,
70                             NULL,
71                             G_SPAWN_SEARCH_PATH
72                             | G_SPAWN_STDOUT_TO_DEV_NULL
73                             | G_SPAWN_STDERR_TO_DEV_NULL,
74                             NULL,
75                             NULL,
76                             &pid,
77                             &error);
78        g_strfreev (argv);
79
80        if (! res) {
81                g_warning ("Unable to run command %s: %s", command, error->message);
82                return FALSE;
83        }
84
85        if (kill (pid, 0) < 0) {
86                g_warning ("at-spi-registryd not running");
87                return FALSE;
88        }
89
90        return TRUE;
91}
92
93static GdkFilterReturn
94filter_watch (GdkXEvent *xevent,
95              GdkEvent  *event,
96              gpointer   data)
97{
98        XEvent *xev = (XEvent *)xevent;
99
100        if (xev->xany.type == PropertyNotify
101            && xev->xproperty.atom == AT_SPI_IOR) {
102                gtk_main_quit ();
103
104                return GDK_FILTER_REMOVE;
105        }
106
107        return GDK_FILTER_CONTINUE;
108}
109
110static gboolean
111filter_timeout (gpointer data)
112{
113        g_warning ("The accessibility registry was not found.");
114
115        gtk_main_quit ();
116
117        return FALSE;
118}
119
120static void
121assistive_registry_start (void)
122{
123        GdkWindow *root;
124        guint      tid;
125
126        root = gdk_get_default_root_window ();
127
128        if ( ! AT_SPI_IOR) {
129                AT_SPI_IOR = XInternAtom (GDK_DISPLAY (), "AT_SPI_IOR", False);
130        }
131
132        gdk_window_set_events (root,  GDK_PROPERTY_CHANGE_MASK);
133
134        if ( ! assistive_registry_launch ()) {
135                g_warning ("The accessibility registry could not be started.");
136                return;
137        }
138
139        gdk_window_add_filter (root, filter_watch, NULL);
140        tid = g_timeout_add_seconds (5, filter_timeout, NULL);
141
142        gtk_main ();
143
144        gdk_window_remove_filter (root, filter_watch, NULL);
145        g_source_remove (tid);
146}
147
148static void
149at_set_gtk_modules (void)
150{
151        GSList     *modules_list;
152        GSList     *l;
153        const char *old;
154        char      **modules;
155        gboolean    found_gail;
156        gboolean    found_atk_bridge;
157        int         n;
158
159        n = 0;
160        modules_list = NULL;
161        found_gail = FALSE;
162        found_atk_bridge = FALSE;
163
164        if ((old = g_getenv ("GTK_MODULES")) != NULL) {
165                modules = g_strsplit (old, ":", -1);
166                for (n = 0; modules[n]; n++) {
167                        if (!strcmp (modules[n], "gail")) {
168                                found_gail = TRUE;
169                        } else if (!strcmp (modules[n], "atk-bridge")) {
170                                found_atk_bridge = TRUE;
171                        }
172
173                        modules_list = g_slist_prepend (modules_list, modules[n]);
174                        modules[n] = NULL;
175                }
176                g_free (modules);
177        }
178
179        if (!found_gail) {
180                modules_list = g_slist_prepend (modules_list, "gail");
181                ++n;
182        }
183
184        if (!found_atk_bridge) {
185                modules_list = g_slist_prepend (modules_list, "atk-bridge");
186                ++n;
187        }
188
189        modules = g_new (char *, n + 1);
190        modules[n--] = NULL;
191        for (l = modules_list; l; l = l->next) {
192                modules[n--] = g_strdup (l->data);
193        }
194
195        g_setenv ("GTK_MODULES", g_strjoinv (":", modules), TRUE);
196        g_strfreev (modules);
197        g_slist_free (modules_list);
198}
199
200static void
201load_a11y (void)
202{
203        const char        *env_a_t_support;
204        gboolean           a_t_support;
205        GConfClient       *gconf_client;
206
207        gconf_client = gconf_client_get_default ();
208
209        env_a_t_support = g_getenv ("GNOME_ACCESSIBILITY");
210        if (env_a_t_support) {
211                a_t_support = atoi (env_a_t_support);
212        } else {
213                a_t_support = gconf_client_get_bool (gconf_client, ACCESSIBILITY_KEY, NULL);
214        }
215
216        if (a_t_support) {
217                assistive_registry_start ();
218                at_set_gtk_modules ();
219        }
220
221        g_object_unref (gconf_client);
222}
223
224int
225main (int argc, char *argv[])
226{
227        GtkWidget        *chooser;
228
229        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
230        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
231        textdomain (GETTEXT_PACKAGE);
232
233        setlocale (LC_ALL, "");
234
235        gdm_set_fatal_warnings_if_unstable ();
236
237        g_type_init ();
238
239        gdm_log_init ();
240        gdm_log_set_debug (TRUE);
241
242        g_debug ("Chooser for display %s xauthority:%s",
243                 g_getenv ("DISPLAY"),
244                 g_getenv ("XAUTHORITY"));
245
246        gdk_init (&argc, &argv);
247
248        load_a11y ();
249
250        gtk_init (&argc, &argv);
251
252        chooser = gdm_host_chooser_dialog_new (GDM_CHOOSER_HOST_KIND_MASK_ALL);
253        gtk_widget_set_size_request (chooser, 480, 600);
254
255        if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) {
256                GdmChooserHost *host;
257
258                host = gdm_host_chooser_dialog_get_host (GDM_HOST_CHOOSER_DIALOG (chooser));
259                if (host != NULL) {
260                        char *hostname;
261                        /* FIXME: handle different host types here? */
262
263                        hostname = NULL;
264                        gdm_address_get_hostname (gdm_chooser_host_get_address (host), &hostname);
265                        /* FIXME: fall back to numerical address? */
266                        if (hostname != NULL) {
267                                g_print ("hostname: %s\n", hostname);
268                                g_free (hostname);
269                        }
270                }
271        }
272
273        gtk_widget_destroy (chooser);
274
275        return 0;
276}
Note: See TracBrowser for help on using the repository browser.