Commit b68ffea6 authored by Brian Cameron's avatar Brian Cameron Committed by Brian Cameron

This further improves GDM configuration so that now only the GDM daemon

2005-11-21  Brian Cameron <Brian.Cameron@sun.com>

        This further improves GDM configuration so that
        now only the GDM daemon parses and manages the
        configuration file.  Most client programs use
        the GET_CONFIG command to access needed data.
        This simplifies the configuration logic and
        puts all configuration parsing in one place
        and gets rid of a lot of global variables that
        were making the code look messy.  This also
        gets rid of several places where gnome_config
        deprecated functions were being used.  I have
        cleaned up the code so that the vicious-extensions
        code is more localized in gui/gdmconfig.[ch].
        Some work is left to do:  gdmflexiserver still
        uses gnome_config functions and gdmconfig should
        use the new functions for reading from the
        configuration file.  Some compile issues fixed
        as highlghted by dmacks@netspace.org to fix
        bug #322083.

        * NEWS: Fixed comment.
        * daemon/gdm.h: Further cleanup of #define's so
          that they better match the names of the config
          keys.
        * daemon/gdm.c: Now GET_CONFIG returns "OK" if
          the key is valid but has no value when it
          is a string.  Now free return value from
          gdm_config_to_string.
        * daemon/Makefile.am, gui/greeter/Makefile.am:
          Now the daemon validates the greeter's theme
          directory, so pass the default value into the
          daemon and not the greeter.
        * daemon/gdmconfig.h: Added gdm_is_valid_key
          and corrected prototype for
          gdm_set_user_session_lang.
        * daemon/slave.c: Fix warning and compile errors.
        * daemon/gdmconfig.c: Further fleshed out.
          Now it supports a few additional keys I
          overlooked.  It now validates all keys used
          by the slaves.  Now handles translated string.
          Further refactored the code.
        * gui/Makefile.am: Added gdmconfig.[ch] to
          common library.
        * gui/gdmconfig.[ch]: New functions for
          accessing configuration data for slaves.
        * gui/gdmXnestchooser.c, gui/gdmlanguages.c,
          gui/gdmsession.h, gui/gdmuser.h, gui/gdmwm.c,
          gui/misc.c, gui/greeter/greeter_item_capslock.c:
          gui/greeter/greeter_item_pam.c: No longer include
          vicious.h/viciousui.h, instead gdmconfig.h.
        * gui/gdmcomm.c: Fix gdm_check_comm to no
          longer require passing in the config file
          name.
        * gui/gdmcommon.[ch]: Get rid of old
          gdm_common_*_same functions that are
          replaced with new gui/gdmconfig logic.
          Now functions that access config data
          use the new functions.
        * gui/gdmflexiserver.c: Now displays the
          localized string when you use GET_CONFIG
          to access a translatable string.
        * gui/gdmconfig.c: Now calls update_key in
          addition to update_greeters when updating
          greeter config data, since the daemon needs
          to update the values now when they change.
        * gui/gdmchooser.c, gui/gdmdynamic.c,
          gui/gdmlogin.c, gui/gdmphotosetup.c,
          gui/gdmsession.c, gui/gdmuser.c,
          gui/gdm/gdmXnestchooser.c,
          gui/greeter/greeter.c,
          gui/greeter/greeter_action_language.c,
          gui/greeter/greeter_canvas_item.c,
          gui/greeter/greeter_item.c,
          gui/greeter/greeter_item_customlist.c,
          gui/greeter/greeter_item_timed.c,
          gui/greeter/greeter_item_list.c,
          gui/greeter/greeter_parser.c,
          gui/greeter/greeter_session.c,
          gui/greeter/greeter_system.c:  Updated to
          use new configuration functions.
        * vicious-extensions/glade-helper.c: Now
          include stdlib.h to avoid compiler warnings.
        * gui/greeter/greeter.c: Remove unused
          gdm_kill_thingies function.
parent b370db3d
2005-11-21 Brian Cameron <Brian.Cameron@sun.com>
This further improves GDM configuration so that
now only the GDM daemon parses and manages the
configuration file. Most client programs use
the GET_CONFIG command to access needed data.
This simplifies the configuration logic and
puts all configuration parsing in one place
and gets rid of a lot of global variables that
were making the code look messy. This also
gets rid of several places where gnome_config
deprecated functions were being used. I have
cleaned up the code so that the vicious-extensions
code is more localized in gui/gdmconfig.[ch].
Some work is left to do: gdmflexiserver still
uses gnome_config functions and gdmconfig should
use the new functions for reading from the
configuration file. Some compile issues fixed
as highlghted by dmacks@netspace.org to fix
bug #322083.
* NEWS: Fixed comment.
* daemon/gdm.h: Further cleanup of #define's so
that they better match the names of the config
keys.
* daemon/gdm.c: Now GET_CONFIG returns "OK" if
the key is valid but has no value when it
is a string. Now free return value from
gdm_config_to_string.
* daemon/Makefile.am, gui/greeter/Makefile.am:
Now the daemon validates the greeter's theme
directory, so pass the default value into the
daemon and not the greeter.
* daemon/gdmconfig.h: Added gdm_is_valid_key
and corrected prototype for
gdm_set_user_session_lang.
* daemon/slave.c: Fix warning and compile errors.
* daemon/gdmconfig.c: Further fleshed out.
Now it supports a few additional keys I
overlooked. It now validates all keys used
by the slaves. Now handles translated string.
Further refactored the code.
* gui/Makefile.am: Added gdmconfig.[ch] to
common library.
* gui/gdmconfig.[ch]: New functions for
accessing configuration data for slaves.
* gui/gdmXnestchooser.c, gui/gdmlanguages.c,
gui/gdmsession.h, gui/gdmuser.h, gui/gdmwm.c,
gui/misc.c, gui/greeter/greeter_item_capslock.c:
gui/greeter/greeter_item_pam.c: No longer include
vicious.h/viciousui.h, instead gdmconfig.h.
* gui/gdmcomm.c: Fix gdm_check_comm to no
longer require passing in the config file
name.
* gui/gdmcommon.[ch]: Get rid of old
gdm_common_*_same functions that are
replaced with new gui/gdmconfig logic.
Now functions that access config data
use the new functions.
* gui/gdmflexiserver.c: Now displays the
localized string when you use GET_CONFIG
to access a translatable string.
* gui/gdmconfig.c: Now calls update_key in
addition to update_greeters when updating
greeter config data, since the daemon needs
to update the values now when they change.
* gui/gdmchooser.c, gui/gdmdynamic.c,
gui/gdmlogin.c, gui/gdmphotosetup.c,
gui/gdmsession.c, gui/gdmuser.c,
gui/gdm/gdmXnestchooser.c,
gui/greeter/greeter.c,
gui/greeter/greeter_action_language.c,
gui/greeter/greeter_canvas_item.c,
gui/greeter/greeter_item.c,
gui/greeter/greeter_item_customlist.c,
gui/greeter/greeter_item_timed.c,
gui/greeter/greeter_item_list.c,
gui/greeter/greeter_parser.c,
gui/greeter/greeter_session.c,
gui/greeter/greeter_system.c: Updated to
use new configuration functions.
* vicious-extensions/glade-helper.c: Now
include stdlib.h to avoid compiler warnings.
* gui/greeter/greeter.c: Remove unused
gdm_kill_thingies function.
2005-11-19 Jürg Billeter <j@bitron.ch>
* configure.ac: Really check for X server in prefix /usr
......
......@@ -26,6 +26,7 @@ Ahh news...
die. See bug #113902. (Vaclav Smilauer).
- GDM now uses VT_GETSTATE for peeking VT freeness
(Samuel Thibault)
- Now GDM warns correctly about caps lock if an
alternate keymap is enabled. kbGetState is used
......
......@@ -12,7 +12,8 @@ INCLUDES = \
$(GUI_CFLAGS) \
$(DAEMON_CFLAGS) \
-DPAM_PREFIX=\"$(PAM_PREFIX)\" \
$(GNOME_INCLUDEDIR)
$(GNOME_INCLUDEDIR) \
-DGREETERTHEMEDIR=\""$(datadir)/gdm/themes"\"
#
# -DG_DISABLE_DEPRECATED \
......
......@@ -3028,20 +3028,25 @@ gdm_handle_user_message (GdmConnection *conn, const char *msg, gpointer data)
&msg[strlen (GDM_SUP_UPDATE_CONFIG " ")];
char *val;
if (! gdm_update_config (key))
if (! gdm_update_config ((gchar *)key))
gdm_connection_printf (conn, "ERROR 50 Unsupported key <%s>\n", key);
else
gdm_connection_write (conn, "OK\n");
} else if (strncmp (msg, GDM_SUP_GET_CONFIG " ",
strlen (GDM_SUP_GET_CONFIG " ")) == 0) {
const char *key = &msg[strlen (GDM_SUP_GET_CONFIG " ")];
char *retval;
gchar *retval;
gdm_config_to_string (key, &retval);
gdm_config_to_string ((gchar *)key, &retval);
if (retval != NULL)
gdm_connection_printf (conn, "OK %s", retval);
else
gdm_connection_printf (conn, "ERROR 50 Unsupported key <%s>\n", key);
gdm_connection_printf (conn, "OK %s\n", retval);
else {
if (gdm_is_valid_key ((gchar *)key))
gdm_connection_printf (conn, "OK \n");
else
gdm_connection_printf (conn, "ERROR 50 Unsupported key <%s>\n", key);
}
g_free (retval);
} else if (strcmp (msg, GDM_SUP_GET_CONFIG_FILE) == 0) {
GString *msg;
GSList *li;
......
......@@ -139,8 +139,7 @@ enum {
/*
* The following section contains keys used by the gdm.conf configuration file.
* Options exposed in this file are Stable, and should not change in ways that
* are not backwards incompatible. Note how GDM_KEY_DEFAULTWELCOME_BACKTEST
* works to see how backwards compatibility can be handled.
* are not backwards incompatible.
*
* Developers who add new configuration options should ensure that they do the
* following:
......@@ -291,8 +290,8 @@ enum {
#define GDM_KEY_GTK_THEME "gui/GtkTheme=Default"
#define GDM_KEY_GTKRC "gui/GtkRC=" EXPANDED_DATADIR "/themes/Default/gtk-2.0/gtkrc"
#define GDM_KEY_ICON_WIDTH "gui/MaxIconWidth=128"
#define GDM_KEY_ICON_HEIGHT "gui/MaxIconHeight=128"
#define GDM_KEY_MAX_ICON_WIDTH "gui/MaxIconWidth=128"
#define GDM_KEY_MAX_ICON_HEIGHT "gui/MaxIconHeight=128"
#define GDM_KEY_ALLOW_GTK_THEME_CHANGE "gui/AllowGtkThemeChange=true"
#define GDM_KEY_GTK_THEMES_TO_ALLOW "gui/GtkThemesToAllow=all"
......@@ -302,8 +301,8 @@ enum {
#define GDM_KEY_EXCLUDE "greeter/Exclude=bin,daemon,adm,lp,sync,shutdown,halt,mail,news,uucp,operator,nobody,gdm,postgres,pvm,rpm,nfsnobody,pcap"
#define GDM_KEY_INCLUDE_ALL "greeter/IncludeAll=false"
#define GDM_KEY_MINIMAL_UID "greeter/MinimalUID=100"
#define GDM_KEY_FACE "greeter/DefaultFace=" EXPANDED_PIXMAPDIR "/nobody.png"
#define GDM_KEY_FACE_DIR "greeter/GlobalFaceDir=" EXPANDED_DATADIR "/pixmaps/faces/"
#define GDM_KEY_DEFAULT_FACE "greeter/DefaultFace=" EXPANDED_PIXMAPDIR "/nobody.png"
#define GDM_KEY_GLOBAL_FACE_DIR "greeter/GlobalFaceDir=" EXPANDED_DATADIR "/pixmaps/faces/"
#define GDM_KEY_LOCALE_FILE "greeter/LocaleFile=" EXPANDED_LOCALEDIR "/locale.alias"
#define GDM_KEY_LOGO "greeter/Logo=" EXPANDED_PIXMAPDIR "/gdm-foot-logo.png"
#define GDM_KEY_CHOOSER_BUTTON_LOGO "greeter/ChooserButtonLogo=" EXPANDED_PIXMAPDIR "/gdm-foot-logo.png"
......@@ -313,10 +312,20 @@ enum {
#define GDM_KEY_CONFIG_AVAILABLE "greeter/ConfigAvailable=true"
#define GDM_KEY_CHOOSER_BUTTON "greeter/ChooserButton=true"
#define GDM_KEY_TITLE_BAR "greeter/TitleBar=true"
#define GDM_KEY_DEFAULT_WELCOME "greeter/DefaultWelcome=true"
#define GDM_KEY_DEFAULT_WELCOME_BACKTEST "greeter/DefaultWelcome="
#define GDM_KEY_DEFAULT_REMOTE_WELCOME "greeter/DefaultRemoteWelcome=true"
#define GDM_KEY_DEFAULT_REMOTE_WELCOME_BACKTEST "greeter/DefaultRemoteWelcome="
/*
* For backwards compatibility, do not set values for DEFAULT_WELCOME or
* DEFAULT_REMOTEWELCOME. This will cause these values to always be
* read from the config file, and will cause them to return FALSE if
* no value is set in the config file. If Welcome or RemoteWelcome are
* not set in the config file, then GDM will set them back to the default
* value. Note the reason we don't specify the default value in the
* config file anymore is because it is easier to maintain the l10n
* strings when the string is compiled into the source code instaed of
* supplied in the configuration file.
*/
#define GDM_KEY_DEFAULT_WELCOME "greeter/DefaultWelcome="
#define GDM_KEY_DEFAULT_REMOTE_WELCOME "greeter/DefaultRemoteWelcome="
#define GDM_KEY_WELCOME "greeter/Welcome="
#define GDM_KEY_REMOTE_WELCOME "greeter/RemoteWelcome="
#define GDM_KEY_XINERAMA_SCREEN "greeter/XineramaScreen=0"
......@@ -346,10 +355,10 @@ enum {
#define GDM_KEY_INFO_MSG_FILE "greeter/InfoMsgFile="
#define GDM_KEY_INFO_MSG_FONT "greeter/InfoMsgFont="
#define GDM_KEY_SOUND_ON_LOGIN_READY "greeter/SoundOnLogin=true"
#define GDM_KEY_SOUND_ON_LOGIN "greeter/SoundOnLogin=true"
#define GDM_KEY_SOUND_ON_LOGIN_SUCCESS "greeter/SoundOnLoginSuccess=false"
#define GDM_KEY_SOUND_ON_LOGIN_FAILURE "greeter/SoundOnLoginFailure=false"
#define GDM_KEY_SOUND_ON_LOGIN_READY_FILE "greeter/SoundOnLoginFile="
#define GDM_KEY_SOUND_ON_LOGIN_FILE "greeter/SoundOnLoginFile="
#define GDM_KEY_SOUND_ON_LOGIN_SUCCESS_FILE "greeter/SoundOnLoginSuccessFile="
#define GDM_KEY_SOUND_ON_LOGIN_FAILURE_FILE "greeter/SoundOnLoginFailureFile="
#define GDM_KEY_SOUND_PROGRAM "daemon/SoundProgram=" SOUND_PROGRAM
......@@ -682,7 +691,7 @@ void gdm_final_cleanup (void);
#define GDM_NOTIFY_TIMED_LOGIN "TimedLogin" /* <login> */
#define GDM_NOTIFY_TIMED_LOGIN_DELAY "TimedLoginDelay" /* <seconds> */
#define GDM_NOTIFY_DISALLOW_TCP "DisallowTCP" /* <true/false as int> */
#define GDM_NOTIFY_SOUND_ON_LOGIN_READY_FILE "SoundOnLoginFile" /* <sound file> */
#define GDM_NOTIFY_SOUND_ON_LOGIN_FILE "SoundOnLoginFile" /* <sound file> */
#define GDM_NOTIFY_SOUND_ON_LOGIN_SUCCESS_FILE "SoundOnLoginSuccessFile" /* <sound file> */
#define GDM_NOTIFY_SOUND_ON_LOGIN_FAILURE_FILE "SoundOnLoginFailureFile" /* <sound file> */
#define GDM_NOTIFY_ADD_GTK_MODULES "AddGtkModules" /* <true/false as int> */
......
This diff is collapsed.
......@@ -33,7 +33,7 @@ void gdm_set_value_bool (gchar *key,
void gdm_set_value_int (gchar *key,
gint value);
gboolean gdm_config_to_string (gchar *key,
gchar *retval);
gchar **retval);
gboolean gdm_update_config (gchar *key);
void gdm_config_init (void);
void gdm_config_parse (void);
......@@ -45,6 +45,7 @@ uid_t gdm_get_gdmgid (void);
gint gdm_get_high_display_num (void);
void gdm_set_high_display_num (gint val);
void gdm_print_all_config (void);
gboolean gdm_is_valid_key (gchar *key);
gboolean gdm_signal_terminthup_was_notified (void);
gchar* gdm_get_facefile_from_home
......@@ -58,11 +59,11 @@ void gdm_get_user_session_lang
char **usrlang,
const char *homedir,
gboolean *savesess);
void gdm_set_user_session (gboolean savesess,
gboolean savelang,
const char *homedir,
const char *save_session,
const char *save_language);
void gdm_set_user_session_lang (gboolean savesess,
gboolean savelang,
const char *home_dir,
const char *save_session,
const char *save_language);
char* gdm_get_session_exec (const char *session_name,
gboolean check_try_exec);
......@@ -4741,7 +4741,7 @@ check_for_interruption (const char *msg)
return TRUE;
case GDM_INTERRUPT_LOGIN_SOUND:
if (d->attached &&
! play_login_sound (gdm_get_value_string (GDM_KEY_SOUND_ON_LOGIN_READY_FILE))) {
! play_login_sound (gdm_get_value_string (GDM_KEY_SOUND_ON_LOGIN_FILE))) {
gdm_error (_("Login sound requested on non-local display or the play software "
"cannot be run or the sound does not exist"));
}
......@@ -5309,7 +5309,7 @@ gdm_slave_handle_notify (const char *msg)
remanage_asap = TRUE;
} else if (strncmp (msg, GDM_NOTIFY_GREETER " ",
strlen (GDM_NOTIFY_GREETER) + 1) == 0) {
gdm_set_value_string (GDM_KEY_GREETER, (&msg[strlen (GDM_NOTIFY_GREETER) + 1]));
gdm_set_value_string (GDM_KEY_GREETER, ((gchar *)&msg[strlen (GDM_NOTIFY_GREETER) + 1]));
if (d->attached) {
do_restart_greeter = TRUE;
......@@ -5328,7 +5328,7 @@ gdm_slave_handle_notify (const char *msg)
} else if (strncmp (msg, GDM_NOTIFY_REMOTE_GREETER " ",
strlen (GDM_NOTIFY_REMOTE_GREETER) + 1) == 0) {
gdm_set_value_string (GDM_KEY_REMOTE_GREETER,
(&msg[strlen (GDM_NOTIFY_REMOTE_GREETER) + 1]));
(gchar *)(&msg[strlen (GDM_NOTIFY_REMOTE_GREETER) + 1]));
if ( ! d->attached) {
do_restart_greeter = TRUE;
if (restart_greeter_now) {
......@@ -5359,28 +5359,28 @@ gdm_slave_handle_notify (const char *msg)
gdm_set_value_int (GDM_KEY_TIMED_LOGIN_DELAY, val);
if (d->greetpid > 1)
kill (d->greetpid, SIGHUP);
} else if (strncmp (msg, GDM_NOTIFY_SOUND_ON_LOGIN_READY_FILE " ",
strlen (GDM_NOTIFY_SOUND_ON_LOGIN_READY_FILE) + 1) == 0) {
gdm_set_value_string (GDM_KEY_SOUND_ON_LOGIN_READY_FILE,
(&msg[strlen (GDM_NOTIFY_SOUND_ON_LOGIN_READY_FILE) + 1]));
} else if (strncmp (msg, GDM_NOTIFY_SOUND_ON_LOGIN_FILE " ",
strlen (GDM_NOTIFY_SOUND_ON_LOGIN_FILE) + 1) == 0) {
gdm_set_value_string (GDM_KEY_SOUND_ON_LOGIN_FILE,
(gchar *)(&msg[strlen (GDM_NOTIFY_SOUND_ON_LOGIN_FILE) + 1]));
if (d->greetpid > 1)
kill (d->greetpid, SIGHUP);
} else if (strncmp (msg, GDM_NOTIFY_SOUND_ON_LOGIN_SUCCESS_FILE " ",
strlen (GDM_NOTIFY_SOUND_ON_LOGIN_SUCCESS_FILE) + 1) == 0) {
gdm_set_value_string (GDM_KEY_SOUND_ON_LOGIN_SUCCESS_FILE,
(&msg[strlen (GDM_NOTIFY_SOUND_ON_LOGIN_SUCCESS_FILE) + 1]));
(gchar *)(&msg[strlen (GDM_NOTIFY_SOUND_ON_LOGIN_SUCCESS_FILE) + 1]));
if (d->greetpid > 1)
kill (d->greetpid, SIGHUP);
} else if (strncmp (msg, GDM_NOTIFY_SOUND_ON_LOGIN_FAILURE_FILE " ",
strlen (GDM_NOTIFY_SOUND_ON_LOGIN_FAILURE_FILE) + 1) == 0) {
gdm_set_value_string (GDM_KEY_SOUND_ON_LOGIN_FAILURE_FILE,
(&msg[strlen (GDM_NOTIFY_SOUND_ON_LOGIN_FAILURE_FILE) + 1]));
(gchar *)(&msg[strlen (GDM_NOTIFY_SOUND_ON_LOGIN_FAILURE_FILE) + 1]));
if (d->greetpid > 1)
kill (d->greetpid, SIGHUP);
} else if (strncmp (msg, GDM_NOTIFY_GTK_MODULES_LIST " ",
strlen (GDM_NOTIFY_GTK_MODULES_LIST) + 1) == 0) {
gdm_set_value_string (GDM_KEY_GTK_MODULES_LIST,
(&msg[strlen (GDM_NOTIFY_GTK_MODULES_LIST) + 1]));
(gchar *)(&msg[strlen (GDM_NOTIFY_GTK_MODULES_LIST) + 1]));
if (gdm_get_value_bool (GDM_KEY_ADD_GTK_MODULES)) {
do_restart_greeter = TRUE;
......
This diff is collapsed.
This diff is collapsed.
......@@ -69,6 +69,8 @@ libgdmcommon_a_SOURCES = \
misc.h \
gdmcomm.c \
gdmcomm.h \
gdmconfig.c \
gdmconfig.h \
gdmcommon.c \
gdmcommon.h
......
......@@ -36,11 +36,10 @@
#include <errno.h>
#include <X11/Xauth.h>
#include <viciousui.h>
#include "gdm.h"
#include "gdmcomm.h"
#include "gdmcommon.h"
#include "gdmconfig.h"
static pid_t xnest_pid = 0;
......@@ -504,25 +503,14 @@ main (int argc, char *argv[])
if (args != NULL && args[0] != NULL)
host = args[0];
config_file = gdm_common_get_config_file ();
if (config_file == NULL) {
g_print (_("Could not access GDM configuration file.\n"));
_exit (1);
}
config_prefix = g_strdup_printf("=%s=/", config_file);
gnome_config_push_prefix (config_prefix);
xdmcp_enabled = gnome_config_get_bool (GDM_KEY_XDMCP);
honor_indirect = gnome_config_get_bool (GDM_KEY_INDIRECT);
pidfile = gnome_config_get_string (GDM_KEY_PID_FILE);
xnest = gnome_config_get_string (GDM_KEY_XNEST);
gnome_config_pop_prefix ();
g_free (config_file);
g_free (config_prefix);
xdmcp_enabled = gdm_config_get_bool (GDM_KEY_XDMCP);
honor_indirect = gdm_config_get_bool (GDM_KEY_INDIRECT);
pidfile = gdm_config_get_string (GDM_KEY_PID_FILE);
xnest = gdm_config_get_string (GDM_KEY_XNEST);
/* complex and wonderous way to get the exec vector */
execvec = make_us_an_exec_vector (xnest);
g_free (xnest);
if (execvec == NULL) {
GtkWidget *d;
......@@ -587,7 +575,6 @@ main (int argc, char *argv[])
pid = 0;
if (pidfile != NULL) {
VE_IGNORE_EINTR (fp = fopen (pidfile, "r"));
g_free (pidfile);
}
if (fp != NULL) {
int r;
......
......@@ -21,9 +21,7 @@
* selected hostname will be printed on stdout. */
#include <config.h>
#include <libgnome/libgnome.h>
#include <libgnomeui/libgnomeui.h>
#include <glade/glade.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
......@@ -48,12 +46,17 @@
#include <sys/sockio.h>
#endif
#include <viciousui.h>
#include <libgnome/libgnome.h>
#include <libgnomeui/libgnomeui.h>
#include <glade/glade.h>
#include "gdm.h"
#include "misc.h"
#include "gdmwm.h"
#include "gdmcommon.h"
#include "gdmconfig.h"
#include "viciousui.h"
static gchar *config_file;
......@@ -147,44 +150,14 @@ static XdmcpBuffer querybuf;
static GSList *bcaddr;
static GSList *queryaddr;
static gint GdmXineramaScreen;
static gint GdmIconMaxHeight;
static gint GdmIconMaxWidth;
static gboolean GdmDebug;
static gint GdmScanTime;
static gchar *GdmHostIconDir;
static gchar *GdmHostDefaultIcon;
static gchar *GdmGtkRC;
static gchar *GdmGtkTheme;
static gchar *GdmHosts;
static gchar *GdmHostsOrig;
static gboolean GdmBroadcast;
static gboolean GdmAllowAdd;
static gchar *GdmBackgroundColor;
static int GdmBackgroundType;
static gboolean GdmMulticast;
static gchar *GdmMulticastAddr;
/* HACK: for gdmcommon, else it complains */
/* */ gchar *GdmInfoMsgFile;
/* */ gchar *GdmInfoMsgFont;
/* */ gchar *GdmSoundProgram;
/* */ gboolean GdmSoundOnLoginReady;
/* */ gchar *GdmSoundOnLoginReadyFile;
/* */ void
/* */ gdm_kill_thingies (void)
/* */ {
/* */ ; /* nothing */
/* */ }
enum {
GDM_BACKGROUND_NONE = 0,
GDM_BACKGROUND_IMAGE = 1,
GDM_BACKGROUND_COLOR = 2
};
static gchar *GdmHosts;
static GladeXML *chooser_app;
static GtkWidget *chooser, *manage, *rescan, *cancel, *add_entry, *add_button;
static GtkWidget *status_label;
......@@ -241,6 +214,7 @@ gdm_chooser_host_alloc (const char *hostname,
GdmChooserHost *host;
GdkPixbuf *img;
gchar *hostimg;
gchar *hostimgdir;
host = g_new0 (GdmChooserHost, 1);
host->name = g_strdup (hostname);
......@@ -259,25 +233,29 @@ gdm_chooser_host_alloc (const char *hostname,
if ( ! willing)
return host;
hostimg = g_strconcat (GdmHostIconDir, "/", hostname, NULL);
hostimgdir = gdm_config_get_string (GDM_KEY_HOST_IMAGE_DIR);
hostimg = g_strconcat (hostimgdir, "/", hostname, NULL);
if (access (hostimg, R_OK) != 0) {
g_free (hostimg);
hostimg = g_strconcat (GdmHostIconDir, "/", hostname, ".png", NULL);
hostimg = g_strconcat (hostimgdir, "/", hostname, ".png", NULL);
}
if (access (hostimg, R_OK) == 0 &&
(img = gdk_pixbuf_new_from_file (hostimg, NULL)) != NULL) {
gint w, h;
gint w, h, maxw, maxh;
w = gdk_pixbuf_get_width (img);
h = gdk_pixbuf_get_height (img);
if (w>h && w>GdmIconMaxWidth) {
h = h * ((gfloat) GdmIconMaxWidth/w);
w = GdmIconMaxWidth;
} else if (h>GdmIconMaxHeight) {
w = w * ((gfloat) GdmIconMaxHeight/h);
h = GdmIconMaxHeight;
maxw = gdm_config_get_int (GDM_KEY_MAX_ICON_WIDTH);
maxh = gdm_config_get_int (GDM_KEY_MAX_ICON_HEIGHT);
if (w > h && w > maxw) {
h = h * ((gfloat) maxw / w);
w = maxw;
} else if (h > maxh) {
w = w * ((gfloat) maxh / h);
h = maxh;
}
......@@ -800,8 +778,11 @@ gdm_chooser_find_mcaddr (void)
sin6->sin6_family = AF_INET6;
sin6->sin6_port = htons (XDM_UDP_PORT);
sin6->sin6_scope_id = ifindex;
inet_pton (AF_INET6, GdmMulticastAddr, &sin6->sin6_addr);
bcaddr = g_slist_append (bcaddr, sin6); /* bcaddr is also serving for multicast address for IPv6 */
inet_pton (AF_INET6, gdm_config_get_string (GDM_KEY_MULTICAST_ADDR),
&sin6->sin6_addr);
/* bcaddr is also serving for multicast address for IPv6 */
bcaddr = g_slist_append (bcaddr, sin6);
}
}
#endif
......@@ -957,7 +938,7 @@ gdm_chooser_xdmcp_discover (void)
if (scan_time_handler > 0)
g_source_remove (scan_time_handler);
scan_time_handler = g_timeout_add (GdmScanTime * 1000,
scan_time_handler = g_timeout_add (gdm_config_get_int (GDM_KEY_SCAN_TIME) * 1000,
chooser_scan_time_update, NULL);
/* Note we already used up one try */
......@@ -1597,62 +1578,6 @@ gdm_chooser_warn (const gchar *format, ...)
g_free (s);
}
static void
gdm_chooser_parse_config (void)
{
VeConfig *cfg;
cfg = ve_config_get (config_file);
GdmXineramaScreen = ve_config_get_int (cfg, GDM_KEY_XINERAMA_SCREEN);
GdmGtkRC = ve_config_get_string (cfg, GDM_KEY_GTKRC);
GdmGtkTheme = ve_config_get_string (cfg, GDM_KEY_GTK_THEME);
GdmScanTime = ve_config_get_int (cfg, GDM_KEY_SCAN_TIME);
GdmHostDefaultIcon = ve_config_get_string (cfg, GDM_KEY_DEFAULT_HOST_IMG);
GdmHostIconDir = ve_config_get_string (cfg, GDM_KEY_HOST_IMAGE_DIR);
GdmIconMaxWidth = ve_config_get_int (cfg, GDM_KEY_ICON_WIDTH);
GdmIconMaxHeight = ve_config_get_int (cfg, GDM_KEY_ICON_HEIGHT);
GdmDebug = ve_config_get_bool (cfg, GDM_KEY_DEBUG);
GdmBackgroundColor = ve_config_get_string (cfg, GDM_KEY_BACKGROUND_COLOR);
GdmBackgroundType = ve_config_get_int (cfg, GDM_KEY_BACKGROUND_TYPE);
GdmMulticast = ve_config_get_bool (cfg, GDM_KEY_MULTICAST);
GdmMulticastAddr = ve_config_get_string (cfg, GDM_KEY_MULTICAST_ADDR);
GdmAllowAdd = ve_config_get_bool (cfg, GDM_KEY_ALLOW_ADD);
/* note that command line arguments will prevail over these */
GdmHosts = ve_config_get_string (cfg, GDM_KEY_HOSTS);
GdmHostsOrig = g_strdup (GdmHosts);
GdmBroadcast = ve_config_get_bool (cfg, GDM_KEY_BROADCAST);
/* if broadcasting, then append BROADCAST to hosts */
if (GdmBroadcast) {
if (ve_string_empty (GdmHosts)) {
g_free (GdmHosts);
GdmHosts = "BROADCAST";
} else {
char *tmp = g_strconcat (GdmHosts, ",BROADCAST", NULL);
g_free (GdmHosts);
GdmHosts = tmp;
}
}
#ifdef ENABLE_IPV6
if (GdmMulticast) {
if (ve_string_empty (GdmHosts)) {
g_free (GdmHosts);
GdmHosts = "MULTICAST";
} else {
GdmHosts = g_strconcat (GdmHosts, ",MULTICAST", NULL);
}
}
#endif
if (GdmScanTime < 1) GdmScanTime = 1;
if (GdmIconMaxWidth < 0) GdmIconMaxWidth = 128;
if (GdmIconMaxHeight < 0) GdmIconMaxHeight = 128;
}
static void
host_selected (GtkTreeSelection *selection, gpointer data)
{
......@@ -1710,10 +1635,11 @@ display_chooser_information (void)
static void
gdm_chooser_gui_init (void)
{
int width;
int height;
GtkTreeSelection *selection;
GtkTreeViewColumn *column;
gchar *defaulthosticon;
int width;
int height;
glade_helper_add_glade_directory (GDM_GLADE_DIR);
glade_helper_search_gnome_dirs (FALSE);
......@@ -1722,21 +1648,23 @@ gdm_chooser_gui_init (void)
if (RUNNING_UNDER_GDM) {
const char *theme_name;
if( ! ve_string_empty (GdmGtkRC))
gtk_rc_parse (GdmGtkRC);
if ( ! ve_string_empty (gdm_config_get_string (GDM_KEY_GTKRC)))
gtk_rc_parse (gdm_config_get_string (GDM_KEY_GTKRC));
theme_name = g_getenv ("GDM_GTK_THEME");
if (ve_string_empty (theme_name))
theme_name = GdmGtkTheme;
theme_name = gdm_config_get_string (GDM_KEY_GTK_THEME);
if ( ! ve_string_empty (theme_name)) {
gdm_set_theme (theme_name);
}
}
defaulthosticon = gdm_config_get_string (GDM_KEY_DEFAULT_HOST_IMG);
/* Load default host image */
if (access (GdmHostDefaultIcon, R_OK) != 0) {
gdm_chooser_warn (_("Can't open default host icon: %s"), GdmHostDefaultIcon);
if (access (defaulthosticon, R_OK) != 0) {
gdm_chooser_warn (_("Can't open default host icon: %s"), defaulthosticon);
/* bogus image */
defhostimg = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
FALSE /* has_alpha */,
......@@ -1744,7 +1672,7 @@ gdm_chooser_gui_init (void)
48 /* width */,
48 /* height */);
} else {
defhostimg = gdk_pixbuf_new_from_file (GdmHostDefaultIcon, NULL);
defhostimg = gdk_pixbuf_new_from_file (defaulthosticon, NULL);
}
/* Main window */
......@@ -1810,7 +1738,7 @@ gdm_chooser_gui_init (void)
GTK_SORT_ASCENDING);
if ( ! GdmAllowAdd) {
if ( ! gdm_config_get_bool (GDM_KEY_ALLOW_ADD)) {
GtkWidget *w = glade_helper_get (chooser_app, "add_hbox",
GTK_TYPE_HBOX);
gtk_widget_hide (w);
......@@ -1847,64 +1775,28 @@ gdm_chooser_gui_init (void)
}
}
static gboolean
string_same (VeConfig *config, const char *cur, const char *key)
{
char *val = ve_config_get_string (config, key);
if (strcmp (ve_sure_string (cur), ve_sure_string (val)) == 0) {
g_free (val);
return TRUE;
} else {
g_free (val);
return FALSE;
}
}
static gboolean
bool_same (VeConfig *config, gboolean cur, const char *key)
{
gboolean val = ve_config_get_bool (config, key);
if (ve_bool_equal (cur, val)) {
return TRUE;
} else {
return FALSE;
}
}
static gboolean
int_same (VeConfig *config, int cur, const char *key)
{
int val = ve_config_get_int (config, key);
if (cur == val) {
return TRUE;
} else {
return FALSE;
}
}
static gboolean
gdm_reread_config (int sig, gpointer data)
{
VeConfig *config;
/* reparse config stuff here. At least ones we care about */
config = ve_config_get (config_file);
/* FIXME: The following is evil, we should update on the fly rather
* then just restarting */
/* Also we may not need to check ALL those keys but just a few */
if ( ! string_same (config, GdmHostsOrig, GDM_KEY_HOSTS) ||
! string_same (config, GdmGtkRC, GDM_KEY_GTKRC) ||
! string_same (config, GdmGtkTheme, GDM_KEY_GTK_THEME) ||
! string_same (config, GdmHostDefaultIcon, GDM_KEY_DEFAULT_HOST_IMG) ||
! string_same (config, GdmHostIconDir, GDM_KEY_HOST_IMAGE_DIR) ||
! int_same (config,
GdmXineramaScreen, GDM_KEY_XINERAMA_SCREEN) ||
! int_same (config, GdmIconMaxWidth, GDM_KEY_ICON_WIDTH) ||
! int_same (config, GdmIconMaxHeight, GDM_KEY_ICON_HEIGHT) ||
! int_same (config, GdmScanTime, GDM_KEY_SCAN_TIME) ||
! bool_same (config, GdmDebug, GDM_KEY_DEBUG)) {
if (gdm_config_reload_string (GDM_KEY_HOSTS) ||
gdm_config_reload_string (GDM_KEY_GTKRC) ||
gdm_config_reload_string (GDM_KEY_GTK_THEME) ||
gdm_config_reload_string (GDM_KEY_DEFAULT_HOST_IMG) ||
gdm_config_reload_string (GDM_KEY_HOST_IMAGE_DIR) ||
gdm_config_reload_string (GDM_KEY_MULTICAST_ADDR) ||
gdm_config_reload_int (GDM_KEY_XINERAMA_SCREEN) ||
gdm_config_reload_int (GDM_KEY_MAX_ICON_WIDTH) ||
gdm_config_reload_int (GDM_KEY_MAX_ICON_HEIGHT) ||
gdm_config_reload_int (GDM_KEY_SCAN_TIME) ||
gdm_config_reload_bool (GDM_KEY_ALLOW_ADD) ||
gdm_config_reload_bool (GDM_KEY_MULTICAST) ||
gdm_config_reload_bool (GDM_KEY_DEBUG)) {
if (RUNNING_UNDER_GDM) {
/* Set busy cursor */
gdm_common_setup_cursor (GDK_WATCH);
......@@ -1918,12 +1810,11 @@ gdm_reread_config (int sig, gpointer data)
}
/* we only use the color and do it for all types except NONE */
if ( ! string_same (config, GdmBackgroundColor, GDM_KEY_BACKGROUND_COLOR) ||
! int_same (config, GdmBackgroundType, GDM_KEY_BACKGROUND_TYPE)) {
if (gdm_config_reload_string (GDM_KEY_BACKGROUND_COLOR) ||
gdm_config_reload_int (GDM_KEY_BACKGROUND_TYPE)) {