di.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * cdebconf - An implementation of the Debian Configuration Management
00004  *            System
00005  *
00006  * $Id$
00007  *
00008  * cdebconf is (c) 2000-2007 Randolph Chung and others under the following
00009  * license.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  *
00015  * 1. Redistributions of source code must retain the above copyright
00016  * notice, this list of conditions and the following disclaimer.
00017  *
00018  * 2. Redistributions in binary form must reproduce the above copyright
00019  * notice, this list of conditions and the following disclaimer in the
00020  * documentation and/or other materials provided with the distribution.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  *****************************************************************************/
00035 
00040 #include "di.h"
00041 
00042 #include <string.h>
00043 #include <sys/types.h>
00044 #include <unistd.h>
00045 #include <syslog.h>
00046 
00047 #include <directfb.h>
00048 /* for dfb_input_device_reload_keymap() and dfb_input_device_at() */
00049 #include <core/input.h>
00050 #include <gtk/gtk.h>
00051 
00052 #include "question.h"
00053 #include "database.h"
00054 
00055 #include "fe_gtk.h"
00056 #include "fe_data.h"
00057 #include "ui.h"
00058 #include "screenshot.h"
00059 
00061 struct di_data {
00063     char * previous_keymap;
00065     char * previous_language;
00066 };
00067 
00072 static void fix_gtk_settings(void)
00073 {
00074     GtkSettings * settings = gtk_settings_get_default();
00075     gtk_settings_set_long_property(settings, "gtk-dnd-drag-threshold",
00076                                    1000, "g-i");
00077 }
00078 
00088 static gchar * get_question_value(struct frontend * fe, const char * template)
00089 {
00090     struct question * question = fe->qdb->methods.get(fe->qdb, template);
00091     const char * result = NULL;
00092 
00093     if (NULL != question) {
00094         result = question_getvalue(question, "" /* no language */);
00095     }
00096     if (NULL == result) {
00097         result = "";
00098     }
00099     return g_strdup(result);
00100 }
00101 
00106 static void print_to_syslog(const gchar * string)
00107 {
00108     syslog(LOG_USER | LOG_DEBUG, "%s", string);
00109 }
00110 
00117 static const char * get_prefix(GLogLevelFlags log_level)
00118 {
00119     switch (log_level & G_LOG_LEVEL_MASK) {
00120         case G_LOG_LEVEL_ERROR: return "ERROR";
00121         case G_LOG_LEVEL_CRITICAL: return "CRITICAL";
00122         case G_LOG_LEVEL_WARNING: return "WARNING";
00123         case G_LOG_LEVEL_MESSAGE: return "Message";
00124         case G_LOG_LEVEL_INFO: return "INFO";
00125         case G_LOG_LEVEL_DEBUG: return "DEBUG";
00126         default: return "(unknown)";
00127     }
00128 }
00129 
00140 static void log_glib_to_syslog(const gchar * log_domain,
00141                                GLogLevelFlags log_level, gchar const * message,
00142                                gpointer user_data)
00143 {
00144     GString * gstring;
00145     gchar * string;
00146 
00147     gstring = g_string_new(NULL);
00148     g_string_append_printf(gstring, "fe_gtk ");
00149     g_string_append_printf(gstring, "(process:%lu): ", (gulong) getpid());
00150     if (NULL != log_domain) {
00151         g_string_append_printf(gstring, "%s - ", log_domain);
00152     }
00153     g_string_append_printf(gstring, "%s: ", get_prefix(log_level));
00154     g_string_append(gstring, message);
00155     string = g_string_free(gstring, FALSE);
00156     print_to_syslog(string);
00157     g_free(string);
00158 }
00159 
00164 static void make_fullscreen(GtkWidget * window)
00165 {
00166     GdkScreen * screen;
00167 
00168     screen = gtk_window_get_screen(GTK_WINDOW(window));
00169     gtk_widget_set_size_request(window, gdk_screen_get_width(screen),
00170                                 gdk_screen_get_height(screen));
00171 }
00172 
00184 gboolean fe_gtk_di_setup(struct frontend * fe)
00185 {
00186     struct frontend_data * fe_data = fe->data;
00187     struct di_data * di_data;
00188 
00189     /* XXX: redirect glib debug functions to syslog */
00190 
00191     g_assert(NULL == fe_data->di_data);
00192     if (NULL == (di_data = g_malloc0(sizeof (struct di_data)))) {
00193         return FALSE;
00194     }
00195     di_data->previous_keymap = get_question_value(
00196         fe, "debian-installer/keymap");
00197     di_data->previous_language = get_question_value(fe, "debconf/language");
00198 
00199     fe_data->di_data = di_data;
00200 
00201     (void) g_set_printerr_handler(print_to_syslog);
00202     (void) g_log_set_default_handler(log_glib_to_syslog,  NULL);
00203 
00204     make_fullscreen(fe_data->window);
00205     fe_gtk_add_screenshot_shortcut(fe);
00206 
00207     fix_gtk_settings();
00208 
00209     return TRUE;
00210 }
00211 
00220 static void refresh_keymap(struct frontend * fe)
00221 {
00222     dfb_input_device_reload_keymap(dfb_input_device_at(DIDID_KEYBOARD));
00223 }
00224 
00230 static GtkTextDirection get_text_direction(struct frontend * fe)
00231 {
00232     char * dirstr;
00233     GtkTextDirection direction;
00234     
00235     dirstr = fe_gtk_get_text(fe, "debconf/text-direction", "LTR - default");
00236 
00237     if ('R' == dirstr[0]) {
00238         direction = GTK_TEXT_DIR_RTL;
00239     } else {
00240         direction = GTK_TEXT_DIR_LTR;
00241     }
00242     g_free(dirstr);
00243     return direction;
00244 }
00245 
00250 static void refresh_language(struct frontend * fe)
00251 {
00252     /* This will enable different fonts to be used for different language. */
00253     gtk_rc_reparse_all();
00254     /* Adapt text direction. */
00255     gtk_widget_set_default_direction(get_text_direction(fe));
00256 }
00257 
00264 void fe_gtk_di_run_dialog(struct frontend * fe)
00265 {
00266     struct frontend_data * fe_data = fe->data;
00267     struct di_data * di_data = fe_data->di_data;
00268     char * keymap;
00269     char * language;
00270 
00271     g_assert(NULL != di_data);
00272 
00273     fe_gtk_update_frontend_title(fe);
00274     keymap = get_question_value(fe, "debian-installer/keymap");
00275     if (0 != strcmp(keymap, di_data->previous_keymap)) {
00276         refresh_keymap(fe);
00277         g_free(di_data->previous_keymap);
00278         di_data->previous_keymap = keymap;
00279     } else {
00280         g_free(keymap);
00281     }
00282 
00283     language = get_question_value(fe, "debconf/language");
00284     if (0 != strcmp(language, di_data->previous_language)) {
00285         refresh_language(fe);
00286         g_free(di_data->previous_language);
00287         di_data->previous_language = language;
00288     } else {
00289         g_free(language);
00290     }
00291 }
00292 
00297 void fe_gtk_di_shutdown(struct frontend * fe)
00298 {
00299     struct frontend_data * fe_data = fe->data;
00300     struct di_data * di_data = fe_data->di_data;
00301 
00302     if (NULL != di_data) {
00303         fe_data->di_data = NULL;
00304         if (NULL != di_data->previous_keymap) {
00305             g_free(di_data->previous_keymap);
00306         }
00307         if (NULL != di_data->previous_language) {
00308             g_free(di_data->previous_language);
00309         }
00310         g_free(di_data);
00311     }
00312 }
00313 
00314 /* vim: et sw=4 si
00315  */

Generated on Sat Jul 7 23:41:41 2007 for fe_gtk by  doxygen 1.5.1