gdm r5668 - in trunk: . gui/simple-greeter
- From: halfline svn gnome org
- To: svn-commits-list gnome org
- Subject: gdm r5668 - in trunk: . gui/simple-greeter
- Date: Fri, 1 Feb 2008 15:47:29 +0000 (GMT)
Author: halfline
Date: Fri Feb 1 15:47:29 2008
New Revision: 5668
URL: http://svn.gnome.org/viewvc/gdm?rev=5668&view=rev
Log:
2008-02-01 Ray Strode <rstrode redhat com>
* gui/simple-greeter/gdm-language-option-widget.[ch]:
New subclass of gdm-recent-option-widget that shows
recently used languages.
Added:
trunk/gui/simple-greeter/gdm-language-option-widget.c
trunk/gui/simple-greeter/gdm-language-option-widget.h
Modified:
trunk/ChangeLog
Added: trunk/gui/simple-greeter/gdm-language-option-widget.c
==============================================================================
--- (empty file)
+++ trunk/gui/simple-greeter/gdm-language-option-widget.c Fri Feb 1 15:47:29 2008
@@ -0,0 +1,255 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Written by: Ray Strode <rstrode redhat com>
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gtk/gtk.h>
+
+#include "gdm-languages.h"
+#include "gdm-language-option-widget.h"
+#include "gdm-recent-option-widget.h"
+#include "gdm-language-chooser-dialog.h"
+
+#define GDM_LANGUAGE_OPTION_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_LANGUAGE_OPTION_WIDGET, GdmLanguageOptionWidgetPrivate))
+
+struct GdmLanguageOptionWidgetPrivate
+{
+ GtkWidget *dialog;
+};
+
+enum {
+ LANGUAGE_ACTIVATED,
+ NUMBER_OF_SIGNALS
+};
+
+static guint signals [NUMBER_OF_SIGNALS] = { 0, };
+
+static void gdm_language_option_widget_class_init (GdmLanguageOptionWidgetClass *klass);
+static void gdm_language_option_widget_init (GdmLanguageOptionWidget *language_option_widget);
+static void gdm_language_option_widget_finalize (GObject *object);
+
+G_DEFINE_TYPE (GdmLanguageOptionWidget, gdm_language_option_widget, GDM_TYPE_RECENT_OPTION_WIDGET)
+
+static void
+gdm_language_option_widget_set_language_from_dialog (GdmLanguageOptionWidget *widget)
+{
+ char *language_name;
+
+ language_name = gdm_language_chooser_dialog_get_current_language_name (GDM_LANGUAGE_CHOOSER_DIALOG (widget->priv->dialog));
+ gdm_language_option_widget_set_current_language_name (widget, language_name);
+ g_free (language_name);
+}
+
+static void
+on_dialog_response (GtkDialog *dialog,
+ int response_id,
+ GdmLanguageOptionWidget *widget)
+{
+ switch (response_id) {
+ case GTK_RESPONSE_OK:
+ gdm_language_option_widget_set_language_from_dialog (widget);
+ break;
+
+ default:
+ break;
+ }
+ gtk_widget_hide (GTK_WIDGET (dialog));
+}
+
+static void
+gdm_language_option_widget_show_dialog (GdmLanguageOptionWidget *widget)
+{
+ gdm_language_option_widget_set_language_from_dialog (widget);
+ gtk_widget_show_all (GTK_WIDGET (widget->priv->dialog));
+}
+
+static void
+gdm_language_option_widget_activated (GdmOptionWidget *widget)
+{
+ char *active_item_id;
+
+ active_item_id = gdm_option_widget_get_active_item (GDM_OPTION_WIDGET (widget));
+ if (active_item_id == NULL) {
+ return;
+ }
+
+ if (strcmp (active_item_id, "__other") == 0) {
+ gdm_language_option_widget_show_dialog (GDM_LANGUAGE_OPTION_WIDGET (widget));
+ return;
+ }
+
+ g_signal_emit (G_OBJECT (widget), signals[LANGUAGE_ACTIVATED], 0);
+}
+
+static void
+gdm_language_option_widget_class_init (GdmLanguageOptionWidgetClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GdmOptionWidgetClass *option_widget_class = GDM_OPTION_WIDGET_CLASS (klass);
+
+ object_class->finalize = gdm_language_option_widget_finalize;
+
+ option_widget_class->activated = gdm_language_option_widget_activated;
+
+ signals[LANGUAGE_ACTIVATED] = g_signal_new ("language-activated",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GdmLanguageOptionWidgetClass, language_activated),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ g_type_class_add_private (klass, sizeof (GdmLanguageOptionWidgetPrivate));
+}
+
+static gboolean
+gdm_language_option_widget_lookup_item (GdmRecentOptionWidget *widget,
+ const char *locale,
+ char **name,
+ char **comment)
+{
+ char *language;
+
+ language = gdm_get_language_from_name (locale);
+
+ if (language == NULL) {
+ return FALSE;
+ }
+
+ *name = language;
+ *comment = g_strdup ("");
+
+ return TRUE;
+}
+
+static void
+gdm_language_option_widget_init (GdmLanguageOptionWidget *widget)
+{
+ GError *error;
+
+ widget->priv = GDM_LANGUAGE_OPTION_WIDGET_GET_PRIVATE (widget);
+
+ error = NULL;
+ gdm_recent_option_widget_set_gconf_key (GDM_RECENT_OPTION_WIDGET (widget),
+ "/apps/gdm/simple-greeter/recent-languages",
+ gdm_language_option_widget_lookup_item,
+ &error);
+
+ if (error != NULL) {
+ g_warning ("Could not read recent languages from gconf: %s",
+ error->message);
+ g_error_free (error);
+ }
+
+ gdm_option_widget_add_item (GDM_OPTION_WIDGET (widget),
+ "__other", _("Other..."),
+ _("Choose a language from the "
+ "full list of available languages."), TRUE);
+
+ widget->priv->dialog = gdm_language_chooser_dialog_new ();
+
+ g_signal_connect (GTK_DIALOG (widget->priv->dialog), "response",
+ G_CALLBACK (on_dialog_response), widget);
+
+
+ gdm_language_option_widget_set_language_from_dialog (widget);
+}
+
+static void
+gdm_language_option_widget_finalize (GObject *object)
+{
+ GdmLanguageOptionWidget *language_option_widget;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GDM_IS_LANGUAGE_OPTION_WIDGET (object));
+
+ language_option_widget = GDM_LANGUAGE_OPTION_WIDGET (object);
+
+ g_return_if_fail (language_option_widget->priv != NULL);
+
+ G_OBJECT_CLASS (gdm_language_option_widget_parent_class)->finalize (object);
+}
+
+GtkWidget *
+gdm_language_option_widget_new (void)
+{
+ GObject *object;
+
+ object = g_object_new (GDM_TYPE_LANGUAGE_OPTION_WIDGET,
+ "label-text", _("_Language:"),
+ "max-item-count", 8,
+ NULL);
+
+ return GTK_WIDGET (object);
+}
+
+char *
+gdm_language_option_widget_get_current_language_name (GdmLanguageOptionWidget *widget)
+{
+ char *active_item_id;
+ char *language_name;
+
+ active_item_id = gdm_option_widget_get_active_item (GDM_OPTION_WIDGET (widget));
+ if (active_item_id == NULL) {
+ return NULL;
+ }
+
+ if (strcmp (active_item_id, "__other") == 0) {
+ g_free (active_item_id);
+ return NULL;
+ }
+
+ /* FIXME: this clearly isn't thought through. hard coding .utf8
+ * probably doesn't make sense. we should figure out a way
+ * to propagate the right encoding
+ */
+ language_name = g_strdup_printf ("%s.utf8", active_item_id);
+ g_free (active_item_id);
+
+ return language_name;
+}
+
+void
+gdm_language_option_widget_set_current_language_name (GdmLanguageOptionWidget *widget,
+ const char *lang_name)
+{
+ if (!gdm_option_widget_lookup_item (GDM_OPTION_WIDGET (widget), lang_name,
+ NULL, NULL, NULL)) {
+ gdm_recent_option_widget_add_item (GDM_RECENT_OPTION_WIDGET (widget),
+ lang_name);
+ } else {
+ gdm_option_widget_set_active_item (GDM_OPTION_WIDGET (widget), lang_name);
+ }
+}
Added: trunk/gui/simple-greeter/gdm-language-option-widget.h
==============================================================================
--- (empty file)
+++ trunk/gui/simple-greeter/gdm-language-option-widget.h Fri Feb 1 15:47:29 2008
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Written by: Ray Strode <rstrode redhat com>
+ */
+
+#ifndef __GDM_LANGUAGE_OPTION_WIDGET_H
+#define __GDM_LANGUAGE_OPTION_WIDGET_H
+
+#include <glib-object.h>
+
+#include "gdm-recent-option-widget.h"
+
+G_BEGIN_DECLS
+
+#define GDM_TYPE_LANGUAGE_OPTION_WIDGET (gdm_language_option_widget_get_type ())
+#define GDM_LANGUAGE_OPTION_WIDGET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDM_TYPE_LANGUAGE_OPTION_WIDGET, GdmLanguageOptionWidget))
+#define GDM_LANGUAGE_OPTION_WIDGET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GDM_TYPE_LANGUAGE_OPTION_WIDGET, GdmLanguageOptionWidgetClass))
+#define GDM_IS_LANGUAGE_OPTION_WIDGET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDM_TYPE_LANGUAGE_OPTION_WIDGET))
+#define GDM_IS_LANGUAGE_OPTION_WIDGET_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GDM_TYPE_LANGUAGE_OPTION_WIDGET))
+#define GDM_LANGUAGE_OPTION_WIDGET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDM_TYPE_LANGUAGE_OPTION_WIDGET, GdmLanguageOptionWidgetClass))
+
+typedef struct GdmLanguageOptionWidgetPrivate GdmLanguageOptionWidgetPrivate;
+
+typedef struct
+{
+ GdmRecentOptionWidget parent;
+ GdmLanguageOptionWidgetPrivate *priv;
+} GdmLanguageOptionWidget;
+
+typedef struct
+{
+ GdmRecentOptionWidgetClass parent_class;
+
+ void (* language_activated) (GdmLanguageOptionWidget *widget);
+} GdmLanguageOptionWidgetClass;
+
+GType gdm_language_option_widget_get_type (void);
+GtkWidget * gdm_language_option_widget_new (void);
+
+char * gdm_language_option_widget_get_current_language_name (GdmLanguageOptionWidget *widget);
+void gdm_language_option_widget_set_current_language_name (GdmLanguageOptionWidget *widget,
+ const char *lang_name);
+
+
+
+#endif /* __GDM_LANGUAGE_OPTION_WIDGET_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]