Back to index

im-sdk  12.3.91
im_settings_daemon.c
Go to the documentation of this file.
00001 /* GNOME INPUT METHOD SETTINGS DAEMON
00002  *
00003  * Copyright 2003 Sun Microsystems Inc.
00004  *
00005  * This is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #include <config.h>
00022 #include "status-placement.h"
00023 
00024 #include <string.h>
00025 #include <glib.h>
00026 #include <glib/gprintf.h>
00027 #include <gtk/gtk.h>
00028 #include <gnome.h>
00029 #include <gconf/gconf-client.h>
00030 #include <stdarg.h>
00031 
00032 #define IM_KEY_DIR    "/desktop/gnome/input_methods"
00033 #define ENABLE_IM_KEY IM_KEY_DIR "/support"
00034 #define ENABLE_STATUS_KEY IM_KEY_DIR "/status"
00035 #define ENABLE_LOOKUP_KEY IM_KEY_DIR "/lookup"
00036 #define STATUS_PLACEMENT_KEY IM_KEY_DIR "/status_placement"
00037 #define GTK_STATUS_STYLE_KEY "/desktop/gnome/interface/gtk-im-status-style"
00038 
00039 typedef enum {
00040   IM_OFF = 0,
00041   IM_ON
00042 } IMEnabled;
00043 
00044 /* static const char *enabled = "enabled"; */
00045 static const char *disabled = "disabled";
00046 
00047 typedef struct {
00048   IMEnabled im_enabled;
00049   IMEnabled status_enabled;
00050   IMEnabled lookup_enabled;
00051   IMStatusPlacement status_placement;
00052 } IMSettings;
00053 
00054 static IMSettings current_setting;
00055 static GdkAtom im_settings_atom = GDK_NONE;
00056 static const char *_IM_SETTINGS = "_IM_SETTINGS";
00057 
00058 static void
00059 set_im_settings_property ()
00060 {
00061   GdkWindow *root_window = gdk_get_default_root_window ();
00062 
00063   if (im_settings_atom == GDK_NONE)
00064     im_settings_atom = gdk_atom_intern (_IM_SETTINGS, FALSE);
00065   if (im_settings_atom == GDK_NONE)
00066     return;
00067 
00068   gdk_property_change (root_window,
00069                      im_settings_atom, im_settings_atom,
00070                      8, GDK_PROP_MODE_REPLACE,
00071                      (guchar *)&current_setting, sizeof (IMSettings));
00072 
00073   {
00074     GdkAtom  type;
00075     guchar   *data = NULL;
00076     gint     format;
00077     gint     length = 0;
00078     gdk_property_get (root_window,
00079                     im_settings_atom, im_settings_atom,
00080                     0, INT_MAX, FALSE,
00081                     &type, &format, &length, &data);
00082     if (data)
00083       {
00084        IMSettings *new_settings = (IMSettings*)data;
00085 
00086        g_printf ("GNOME_IM_ENABLED=%s\n",
00087                 new_settings->im_enabled == IM_ON ? "yes" : "no");
00088        g_printf ("GNOME_IM_STATUS_ENABLED=%s\n", 
00089                 new_settings->status_enabled == IM_ON ? "yes" : "no");
00090        g_printf ("GNOME_IM_LOOKUP_ENABLED=%s\n",
00091                 new_settings->lookup_enabled == IM_ON ? "yes" : "no");
00092        g_printf ("GNOME_IM_STATUS_PLACEMENT=%s\n",
00093                 new_settings->status_placement ? "application" : "panel");
00094        g_free (data);
00095       }
00096   }
00097 }
00098 
00099 
00100 static void
00101 setup ()
00102 {
00103   GConfClient *client;
00104   gboolean im_enabled, status_enabled, lookup_enabled;
00105   char *str = NULL;
00106 
00107   client = gconf_client_get_default ();
00108 
00109   str = NULL;
00110   str = gconf_client_get_string (client,
00111                              ENABLE_IM_KEY, NULL);
00112   if (str && strcmp (str, disabled) == 0)
00113     im_enabled = FALSE;
00114   else
00115     im_enabled = TRUE;
00116   g_free (str);
00117 
00118   str = NULL;
00119   str = gconf_client_get_string (client,
00120                              ENABLE_STATUS_KEY, NULL);
00121   if (str && strcmp (str, disabled) == 0)
00122     status_enabled = FALSE;
00123   else
00124     status_enabled = TRUE;
00125   g_free (str);
00126 
00127   str = NULL;
00128   str = gconf_client_get_string (client,
00129                              ENABLE_LOOKUP_KEY, NULL);
00130   if (str && strcmp (str, disabled) == 0)
00131     lookup_enabled = FALSE;
00132   else
00133     lookup_enabled = TRUE;
00134   g_free (str);
00135 
00136   current_setting.im_enabled = im_enabled ? IM_ON : IM_OFF;
00137   current_setting.status_enabled = status_enabled ? IM_ON : IM_OFF;
00138   current_setting.lookup_enabled = lookup_enabled ? IM_ON : IM_OFF;
00139 
00140   str = NULL;
00141   str = gconf_client_get_string (client,
00142                              STATUS_PLACEMENT_KEY, NULL);
00143   current_setting.status_placement = gimlet_status_placement (str);
00144   g_free (str);
00145 
00146   set_im_settings_property ();
00147 }
00148 
00149 int
00150 main (int argc, char *argv[])
00151 {
00152   bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
00153   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
00154   textdomain (GETTEXT_PACKAGE);
00155 
00156   gnome_program_init ("gnome-im-settings-daemon", VERSION,
00157                     LIBGNOMEUI_MODULE, argc, argv,
00158                     GNOME_PARAM_APP_DATADIR, GNOMECC_DATA_DIR,
00159                     NULL);
00160   setup ();
00161 
00162   return 0;
00163 }