source: proiecte/PPPP/gdm/gui/simple-greeter/gdm-remote-login-window.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: 10.2 KB
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
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
21#include "config.h"
22
23#include <stdlib.h>
24#include <stdio.h>
25#include <unistd.h>
26#include <sys/types.h>
27#include <sys/wait.h>
28#include <errno.h>
29
30#include <glib.h>
31#include <glib/gi18n.h>
32#include <glib/gstdio.h>
33#include <glib-object.h>
34
35#include <gdk/gdkx.h>
36#include <gtk/gtk.h>
37
38#include "gdm-remote-login-window.h"
39#include "gdm-common.h"
40
41#define GDM_REMOTE_LOGIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_REMOTE_LOGIN_WINDOW, GdmRemoteLoginWindowPrivate))
42
43struct GdmRemoteLoginWindowPrivate
44{
45        gboolean connected;
46        char    *hostname;
47        char    *display;
48        GPid     xserver_pid;
49        guint    xserver_watch_id;
50};
51
52enum {
53        PROP_0,
54};
55
56enum {
57        DISCONNECTED,
58        LAST_SIGNAL
59};
60
61static guint signals [LAST_SIGNAL] = { 0, };
62
63static void     gdm_remote_login_window_class_init   (GdmRemoteLoginWindowClass *klass);
64static void     gdm_remote_login_window_init         (GdmRemoteLoginWindow      *remote_login_window);
65static void     gdm_remote_login_window_finalize     (GObject                    *object);
66
67G_DEFINE_TYPE (GdmRemoteLoginWindow, gdm_remote_login_window, GTK_TYPE_WINDOW)
68
69static void
70xserver_child_watch (GPid                  pid,
71                     int                   status,
72                     GdmRemoteLoginWindow *login_window)
73{
74        g_debug ("GdmRemoteLoginWindow: **** xserver (pid:%d) done (%s:%d)",
75                 (int) pid,
76                 WIFEXITED (status) ? "status"
77                 : WIFSIGNALED (status) ? "signal"
78                 : "unknown",
79                 WIFEXITED (status) ? WEXITSTATUS (status)
80                 : WIFSIGNALED (status) ? WTERMSIG (status)
81                 : -1);
82
83        g_spawn_close_pid (login_window->priv->xserver_pid);
84
85        login_window->priv->xserver_pid = -1;
86        login_window->priv->xserver_watch_id = 0;
87
88        gtk_widget_destroy (GTK_WIDGET (login_window));
89}
90
91static gboolean
92start_xephyr (GdmRemoteLoginWindow *login_window)
93{
94        GError     *local_error;
95        char      **argv;
96        gboolean    res;
97        gboolean    ret;
98        int         flags;
99        char       *command;
100
101        command = g_strdup_printf ("Xephyr -query %s -parent 0x%x -br -once %s",
102                                   login_window->priv->hostname,
103                                   (unsigned int)GDK_WINDOW_XID (GTK_WIDGET (login_window)->window),
104                                   login_window->priv->display);
105        g_debug ("GdmRemoteLoginWindow: Running: %s", command);
106
107        ret = FALSE;
108
109        argv = NULL;
110        local_error = NULL;
111        res = g_shell_parse_argv (command, NULL, &argv, &local_error);
112        if (! res) {
113                g_warning ("GdmRemoteLoginWindow: Unable to parse command: %s", local_error->message);
114                g_error_free (local_error);
115                goto out;
116        }
117
118        flags = G_SPAWN_SEARCH_PATH
119                | G_SPAWN_DO_NOT_REAP_CHILD;
120
121        local_error = NULL;
122        res = g_spawn_async (NULL,
123                             argv,
124                             NULL,
125                             flags,
126                             NULL,
127                             NULL,
128                             &login_window->priv->xserver_pid,
129                             &local_error);
130        g_strfreev (argv);
131
132        if (! res) {
133                g_warning ("GdmRemoteLoginWindow: Unable to run command %s: %s",
134                           command,
135                           local_error->message);
136                g_error_free (local_error);
137                goto out;
138        }
139
140        g_debug ("GdmRemoteLoginWindow: Started: pid=%d command='%s'",
141                 login_window->priv->xserver_pid,
142                 command);
143
144        login_window->priv->xserver_watch_id = g_child_watch_add (login_window->priv->xserver_pid,
145                                                                  (GChildWatchFunc)xserver_child_watch,
146                                                                  login_window);
147        ret = TRUE;
148
149 out:
150        g_free (command);
151
152        return ret;
153}
154
155static gboolean
156start_xdmx (GdmRemoteLoginWindow *login_window)
157{
158        char    *cmd;
159        gboolean res;
160        GError  *error;
161
162        cmd = g_strdup_printf ("Xdmx -query %s -br -once %s",
163                               login_window->priv->hostname,
164                               login_window->priv->display);
165        g_debug ("Running: %s", cmd);
166
167        error = NULL;
168        res = g_spawn_command_line_async (cmd, &error);
169
170        g_free (cmd);
171
172        if (! res) {
173                g_warning ("Could not start Xdmx X server: %s", error->message);
174                g_error_free (error);
175                return FALSE;
176        }
177
178        return TRUE;
179}
180
181gboolean
182gdm_remote_login_window_connect (GdmRemoteLoginWindow *login_window,
183                                 const char           *hostname)
184{
185        gboolean res;
186        char    *title;
187
188        title = g_strdup_printf (_("Remote Login (Connecting to %s...)"), hostname);
189
190        gtk_window_set_title (GTK_WINDOW (login_window), title);
191
192        login_window->priv->hostname = g_strdup (hostname);
193        login_window->priv->display = g_strdup (":300");
194
195        if (0) {
196                res = start_xdmx (login_window);
197        } else {
198                res = start_xephyr (login_window);
199        }
200
201        if (res) {
202                title = g_strdup_printf (_("Remote Login (Connected to %s)"), hostname);
203                gtk_window_set_title (GTK_WINDOW (login_window), title);
204                g_free (title);
205        }
206
207        return res;
208}
209
210static void
211gdm_remote_login_window_set_property (GObject      *object,
212                                      guint         prop_id,
213                                      const GValue *value,
214                                      GParamSpec   *pspec)
215{
216        switch (prop_id) {
217        default:
218                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
219                break;
220        }
221}
222
223static void
224gdm_remote_login_window_get_property (GObject    *object,
225                                      guint       prop_id,
226                                      GValue     *value,
227                                      GParamSpec *pspec)
228{
229        switch (prop_id) {
230        default:
231                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
232                break;
233        }
234}
235
236static GObject *
237gdm_remote_login_window_constructor (GType                  type,
238                                     guint                  n_construct_properties,
239                                     GObjectConstructParam *construct_properties)
240{
241        GdmRemoteLoginWindow      *login_window;
242
243        login_window = GDM_REMOTE_LOGIN_WINDOW (G_OBJECT_CLASS (gdm_remote_login_window_parent_class)->constructor (type,
244                                                                                                                      n_construct_properties,
245                                                                                                                      construct_properties));
246
247
248        return G_OBJECT (login_window);
249}
250
251static void
252gdm_remote_login_window_class_init (GdmRemoteLoginWindowClass *klass)
253{
254        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
255
256        object_class->get_property = gdm_remote_login_window_get_property;
257        object_class->set_property = gdm_remote_login_window_set_property;
258        object_class->constructor = gdm_remote_login_window_constructor;
259        object_class->finalize = gdm_remote_login_window_finalize;
260
261        signals [DISCONNECTED] =
262                g_signal_new ("disconnected",
263                              G_TYPE_FROM_CLASS (object_class),
264                              G_SIGNAL_RUN_LAST,
265                              G_STRUCT_OFFSET (GdmRemoteLoginWindowClass, disconnected),
266                              NULL,
267                              NULL,
268                              g_cclosure_marshal_VOID__VOID,
269                              G_TYPE_NONE,
270                              0);
271
272        g_type_class_add_private (klass, sizeof (GdmRemoteLoginWindowPrivate));
273}
274
275static void
276gdm_remote_login_window_init (GdmRemoteLoginWindow *login_window)
277{
278        login_window->priv = GDM_REMOTE_LOGIN_WINDOW_GET_PRIVATE (login_window);
279
280        gtk_window_set_position (GTK_WINDOW (login_window), GTK_WIN_POS_CENTER_ALWAYS);
281        gtk_window_set_title (GTK_WINDOW (login_window), _("Remote Login"));
282        gtk_window_set_decorated (GTK_WINDOW (login_window), FALSE);
283        gtk_window_set_skip_taskbar_hint (GTK_WINDOW (login_window), TRUE);
284        gtk_window_set_skip_pager_hint (GTK_WINDOW (login_window), TRUE);
285        gtk_window_stick (GTK_WINDOW (login_window));
286        gtk_window_maximize (GTK_WINDOW (login_window));
287        gtk_window_set_icon_name (GTK_WINDOW (login_window), "computer");
288}
289
290static void
291gdm_remote_login_window_finalize (GObject *object)
292{
293        GdmRemoteLoginWindow *login_window;
294
295        g_return_if_fail (object != NULL);
296        g_return_if_fail (GDM_IS_REMOTE_LOGIN_WINDOW (object));
297
298        login_window = GDM_REMOTE_LOGIN_WINDOW (object);
299
300        g_return_if_fail (login_window->priv != NULL);
301
302        G_OBJECT_CLASS (gdm_remote_login_window_parent_class)->finalize (object);
303}
304
305GtkWidget *
306gdm_remote_login_window_new (gboolean is_local)
307{
308        GObject *object;
309
310        object = g_object_new (GDM_TYPE_REMOTE_LOGIN_WINDOW,
311                               NULL);
312
313        return GTK_WIDGET (object);
314}
Note: See TracBrowser for help on using the repository browser.