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 <gtk/gtk.h> |
---|
32 | |
---|
33 | #include "gdm-remote-login-window.h" |
---|
34 | |
---|
35 | int |
---|
36 | main (int argc, char *argv[]) |
---|
37 | { |
---|
38 | GtkWidget *login_window; |
---|
39 | char *std_out; |
---|
40 | char *hostname; |
---|
41 | GRegex *re; |
---|
42 | GMatchInfo *match_info = NULL; |
---|
43 | gboolean res; |
---|
44 | GError *error; |
---|
45 | |
---|
46 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
---|
47 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
---|
48 | textdomain (GETTEXT_PACKAGE); |
---|
49 | |
---|
50 | std_out = NULL; |
---|
51 | g_spawn_command_line_sync (LIBEXECDIR "/gdm-host-chooser", |
---|
52 | &std_out, |
---|
53 | NULL, NULL, NULL); |
---|
54 | if (std_out == NULL) { |
---|
55 | exit (1); |
---|
56 | } |
---|
57 | |
---|
58 | error = NULL; |
---|
59 | re = g_regex_new ("hostname: (?P<hostname>[a-zA-Z0-9.-]+)", 0, 0, &error); |
---|
60 | if (re == NULL) { |
---|
61 | g_warning ("%s", error->message); |
---|
62 | goto out; |
---|
63 | } |
---|
64 | |
---|
65 | g_regex_match (re, std_out, 0, &match_info); |
---|
66 | |
---|
67 | res = g_match_info_matches (match_info); |
---|
68 | if (! res) { |
---|
69 | g_warning ("Unable to parse output: %s", std_out); |
---|
70 | goto out; |
---|
71 | } |
---|
72 | |
---|
73 | hostname = g_match_info_fetch_named (match_info, "hostname"); |
---|
74 | |
---|
75 | g_debug ("Got %s", hostname); |
---|
76 | |
---|
77 | setlocale (LC_ALL, ""); |
---|
78 | |
---|
79 | gtk_init (&argc, &argv); |
---|
80 | |
---|
81 | login_window = gdm_remote_login_window_new (TRUE); |
---|
82 | g_signal_connect (login_window, "destroy", G_CALLBACK (gtk_main_quit), NULL); |
---|
83 | gtk_widget_show (login_window); |
---|
84 | |
---|
85 | gdm_remote_login_window_connect (GDM_REMOTE_LOGIN_WINDOW (login_window), hostname); |
---|
86 | |
---|
87 | gtk_main (); |
---|
88 | out: |
---|
89 | |
---|
90 | if (match_info != NULL) { |
---|
91 | g_match_info_free (match_info); |
---|
92 | } |
---|
93 | if (re != NULL) { |
---|
94 | g_regex_unref (re); |
---|
95 | } |
---|
96 | |
---|
97 | g_free (std_out); |
---|
98 | |
---|
99 | return 0; |
---|
100 | } |
---|