[gnome-control-center/wip/input-sources: 2/14] Some initial ibus code



commit eaad1b2ff6e2d1b002d320e7d4a36988098c9001
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Oct 21 23:17:14 2011 -0400

    Some initial ibus code
    
    Populate the list of active input sources, and wire up
    some of the buttons.

 configure.ac                             |    1 +
 panels/region/Makefile.am                |    2 +
 panels/region/cc-region-panel.c          |    2 +
 panels/region/gnome-region-panel-input.c |  276 ++++++++++++++++++++++++++++++
 panels/region/gnome-region-panel-input.h |   34 ++++
 panels/region/gnome-region-panel.ui      |  131 ++++++--------
 6 files changed, 372 insertions(+), 74 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7560be1..dfb774f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,7 @@ PKG_CHECK_MODULES(PRINTERS_PANEL, $COMMON_MODULES
                   polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
 PKG_CHECK_MODULES(REGION_PANEL, $COMMON_MODULES libgnomekbd >= 2.91.91
                   polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
+                  ibus-1.0
                   libxklavier >= 5.1 libgnomekbdui >= 2.91.91)
 PKG_CHECK_MODULES(SCREEN_PANEL, $COMMON_MODULES)
 PKG_CHECK_MODULES(SOUND_PANEL, $COMMON_MODULES libxml-2.0
diff --git a/panels/region/Makefile.am b/panels/region/Makefile.am
index ca747d5..190e770 100644
--- a/panels/region/Makefile.am
+++ b/panels/region/Makefile.am
@@ -23,6 +23,8 @@ libregion_la_SOURCES =	\
 	gnome-region-panel-lang.h \
 	gnome-region-panel-system.c \
 	gnome-region-panel-system.h \
+	gnome-region-panel-input.c \
+	gnome-region-panel-input.h \
 	gnome-region-panel-xkb.c \
 	gnome-region-panel-xkblt.c \
 	gnome-region-panel-xkbltadd.c \
diff --git a/panels/region/cc-region-panel.c b/panels/region/cc-region-panel.c
index 8d01399..714f300 100644
--- a/panels/region/cc-region-panel.c
+++ b/panels/region/cc-region-panel.c
@@ -23,6 +23,7 @@
 #include <gtk/gtk.h>
 
 #include "gnome-region-panel-xkb.h"
+#include "gnome-region-panel-input.h"
 #include "gnome-region-panel-lang.h"
 #include "gnome-region-panel-formats.h"
 #include "gnome-region-panel-system.h"
@@ -152,6 +153,7 @@ cc_region_panel_init (CcRegionPanel * self)
 	gtk_widget_reparent (prefs_widget, GTK_WIDGET (self));
 
 	setup_xkb_tabs (priv->builder);
+        setup_input_tabs (priv->builder);
 	setup_language (priv->builder);
 	setup_formats (priv->builder);
 	setup_system (priv->builder);
diff --git a/panels/region/gnome-region-panel-input.c b/panels/region/gnome-region-panel-input.c
new file mode 100644
index 0000000..b261ff7
--- /dev/null
+++ b/panels/region/gnome-region-panel-input.c
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * Written by: Matthias Clasen <mclasen redhat com>
+ *
+ * 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, 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.
+ */
+
+#include <config.h>
+
+#include <string.h>
+
+#include <ibus.h>
+
+#include "gnome-region-panel-input.h"
+
+#define WID(s) GTK_WIDGET(gtk_builder_get_object (builder, s))
+
+
+/* another ibus bus: ibusutil.h is not included in ibus.h */
+#define IBUS_COMPILATION
+#include <ibusutil.h>
+#undef IBUS_COMPILATION
+
+static void
+get_active_engines (GtkListStore *store)
+{
+  IBusBus *bus;
+  GList *list, *l;
+  IBusEngineDesc *desc;
+  GType type;
+  const gchar *name;
+  GtkTreeIter iter;
+
+  bus = ibus_bus_new ();
+
+  /* work around a bug in IBus which forgets to register
+   * its types properly
+   */
+  type = ibus_engine_desc_get_type ();
+
+  list = ibus_bus_list_active_engines (bus);
+
+  for (l = list; l; l = l->next)
+    {
+      desc = (IBusEngineDesc *)l->data;
+
+      name = ibus_engine_desc_get_name (desc);
+      if (g_str_has_prefix (name, "xkb:layout:default:#"))
+        continue;
+
+      gtk_list_store_append (store, &iter);
+      gtk_list_store_set (store, &iter,
+                          0, name,
+                          1, ibus_get_language_name (ibus_engine_desc_get_language (desc)),
+                          2, ibus_engine_desc_get_layout (desc),
+                          3, g_str_has_prefix (name, "xkb:layout:"),
+                          -1);
+    }
+
+  g_list_free (list);
+}
+
+static gboolean
+get_selected_iter (GtkBuilder    *builder,
+                   GtkTreeModel **model,
+                   GtkTreeIter   *iter)
+{
+  GtkTreeSelection *selection;
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (WID ("active_input_sources")));
+
+  return gtk_tree_selection_get_selected (selection, model, iter);
+}
+
+static gint
+find_selected_layout_idx (GtkBuilder *builder)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  GtkTreePath *path;
+  gint idx;
+
+  if (!get_selected_iter (builder, &model, &iter))
+    return -1;
+
+  path = gtk_tree_model_get_path (model, &iter);
+  if (path == NULL)
+    return -1;
+
+  idx = gtk_tree_path_get_indices (path)[0];
+  gtk_tree_path_free (path);
+
+  return idx;
+}
+
+static void
+update_button_sensitivity (GtkBuilder *builder)
+{
+  GtkWidget *remove_button;
+  GtkWidget *up_button;
+  GtkWidget *down_button;
+  GtkWidget *show_button;
+  GtkTreeView *tv;
+  GtkTreeSelection *selection;
+  gint n_active;
+  gint index;
+
+  remove_button = WID("input_source_remove");
+  show_button = WID("input_source_show");
+  up_button = WID("input_source_move_up");
+  down_button = WID("input_source_move_down");
+
+  tv = GTK_TREE_VIEW (WID ("active_input_sources"));
+  selection = gtk_tree_view_get_selection (tv);
+
+  n_active = gtk_tree_model_iter_n_children (gtk_tree_view_get_model (tv), NULL);
+  index = find_selected_layout_idx (builder);
+
+  gtk_widget_set_sensitive (remove_button, index >= 0 && n_active > 1);
+  gtk_widget_set_sensitive (show_button, index >= 0);
+  gtk_widget_set_sensitive (up_button, index > 0);
+  gtk_widget_set_sensitive (down_button, index >= 0 && index < n_active - 1);
+}
+
+static void
+set_selected_path (GtkBuilder  *builder,
+                   GtkTreePath *path)
+{
+  GtkTreeSelection *selection;
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (WID ("active_input_sources")));
+
+  gtk_tree_selection_select_path (selection, path);
+}
+
+static void
+add_input (GtkButton *button, gpointer data)
+{
+  GtkBuilder *builder = data;
+
+  g_debug ("add an input source");
+}
+
+static void
+remove_selected_input (GtkButton *button, gpointer data)
+{
+  GtkBuilder *builder = data;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  g_debug ("remove selected input source");
+
+  if (get_selected_iter (builder, &model, &iter) == FALSE)
+    return;
+
+  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+  update_button_sensitivity (builder);
+  /* update_layouts_list (model, dialog); */
+}
+
+static void
+move_selected_input_up (GtkButton *button, gpointer data)
+{
+  GtkBuilder *builder = data;
+  GtkTreeModel *model;
+  GtkTreeIter iter, prev;
+  GtkTreePath *path;
+
+  g_debug ("move selected input source up");
+
+  if (!get_selected_iter (builder, &model, &iter))
+    return;
+
+  prev = iter;
+  if (!gtk_tree_model_iter_previous (model, &prev))
+    return;
+
+  path = gtk_tree_model_get_path (model, &prev);
+
+  gtk_list_store_swap (GTK_LIST_STORE (model), &iter, &prev);
+  update_button_sensitivity (builder);
+  /* update_layouts_list (model, dialog); */
+  set_selected_path (builder, path);
+
+  gtk_tree_path_free (path);
+}
+
+static void
+move_selected_input_down (GtkButton *button, gpointer data)
+{
+  GtkBuilder *builder = data;
+  GtkTreeModel *model;
+  GtkTreeIter iter, next;
+  GtkTreePath *path;
+
+  g_debug ("move selected input source down");
+
+  if (!get_selected_iter (builder, &model, &iter))
+    return;
+
+  next = iter;
+  if (!gtk_tree_model_iter_next (model, &next))
+    return;
+
+  path = gtk_tree_model_get_path (model, &next);
+
+  gtk_list_store_swap (GTK_LIST_STORE (model), &iter, &next);
+  update_button_sensitivity (builder);
+  /* update_layouts_list (model, dialog); */
+  set_selected_path (builder, path);
+
+  gtk_tree_path_free (path);
+}
+
+static void
+show_selected_layout (GtkButton *button, gpointer data)
+{
+  GtkBuilder *builder = data;
+
+  g_debug ("show selected layout");
+}
+
+void
+setup_input_tabs (GtkBuilder *builder)
+{
+  GtkWidget *treeview;
+  GtkTreeViewColumn *column;
+  GtkCellRenderer *cell;
+  GtkListStore *store;
+  GtkTreeSelection *selection;
+
+  /* set up the list of active inputs */
+  treeview = WID("active_input_sources");
+  column = gtk_tree_view_column_new ();
+  cell = gtk_cell_renderer_text_new ();
+  gtk_tree_view_column_pack_start (column, cell, TRUE);
+  gtk_tree_view_column_add_attribute (column, cell, "text", 1);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+  /* id, name, layout, xkb? */
+  store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
+
+  get_active_engines (store);
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  g_signal_connect_swapped (selection, "changed",
+                            G_CALLBACK (update_button_sensitivity), builder);
+
+  gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
+
+  /* set up the buttons */
+  g_signal_connect (WID("input_source_add"), "clicked",
+                    G_CALLBACK (add_input), builder);
+  g_signal_connect (WID("input_source_remove"), "clicked",
+                    G_CALLBACK (remove_selected_input), builder);
+  g_signal_connect (WID("input_source_move_up"), "clicked",
+                    G_CALLBACK (move_selected_input_up), builder);
+  g_signal_connect (WID("input_source_move_down"), "clicked",
+                    G_CALLBACK (move_selected_input_down), builder);
+  g_signal_connect (WID("input_source_show"), "clicked",
+                    G_CALLBACK (show_selected_layout), builder);
+}
diff --git a/panels/region/gnome-region-panel-input.h b/panels/region/gnome-region-panel-input.h
new file mode 100644
index 0000000..987bce6
--- /dev/null
+++ b/panels/region/gnome-region-panel-input.h
@@ -0,0 +1,34 @@
+/* gnome-region-panel-input.h
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * Written by Matthias Clasen
+ *
+ * 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, 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.
+ */
+
+#ifndef __GNOME_KEYBOARD_PROPERTY_INPUT_H
+#define __GNOME_KEYBOARD_PROPERTY_INPUT_H
+
+#include <gtk/gtk.h>
+
+
+G_BEGIN_DECLS
+
+extern void setup_input_tabs (GtkBuilder * dialog);
+
+G_END_DECLS
+
+#endif  /* __GNOME_KEYBOARD_PROPERTY_INPUT_H */
diff --git a/panels/region/gnome-region-panel.ui b/panels/region/gnome-region-panel.ui
index 9b4b9be..15987f1 100644
--- a/panels/region/gnome-region-panel.ui
+++ b/panels/region/gnome-region-panel.ui
@@ -1068,13 +1068,10 @@ default settings</property>
                                 <property name="can_focus">True</property>
                                 <property name="shadow_type">in</property>
                                 <child>
-                                  <object class="GtkTreeView" id="input_sources_selected">
+                                  <object class="GtkTreeView" id="active_input_sources">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="headers_visible">False</property>
-                                    <child internal-child="selection">
-                                      <object class="GtkTreeSelection" id="input-sources-selection"/>
-                                    </child>
                                   </object>
                                 </child>
                               </object>
@@ -1085,98 +1082,84 @@ default settings</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkToolbar" id="input-sources-toolbar">
+                              <object class="GtkToolbar" id="input-toolbar">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="toolbar_style">both-horiz</property>
+                                <property name="toolbar_style">icons</property>
                                 <property name="show_arrow">False</property>
                                 <property name="icon_size">1</property>
                                 <style>
                                   <class name="inline-toolbar"/>
                                 </style>
                                 <child>
-                                  <object class="GtkToolItem" id="input_sources_addremove">
+                                  <object class="GtkToolButton" id="input_source_add">
+                                    <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <child>
-                                      <object class="GtkBox" id="input_sources_addremove_box">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <child>
-                                          <object class="GtkButton" id="input_sources_add">
-                                            <property name="use_action_appearance">False</property>
-                                            <property name="visible">True</property>
-                                            <property name="can_focus">True</property>
-                                            <property name="use_action_appearance">False</property>
-                                            <child>
-                                               <object class="GtkImage" id="input_sources_add_image">
-                                                 <property name="visible">True</property>
-                                                 <property name="icon_name">list-add-symbolic</property>
-                                                 <property name="icon_size">1</property>
-                                                </object>
-                                            </child>
-                                          </object>
-                                          <packing>
-                                            <property name="expand">False</property>
-                                            <property name="fill">True</property>
-                                          </packing>
-                                        </child>
-                                        <child>
-                                          <object class="GtkButton" id="input_sources_remove">
-                                            <property name="use_action_appearance">False</property>
-                                            <property name="visible">True</property>
-                                            <property name="can_focus">True</property>
-                                            <property name="use_action_appearance">False</property>
-                                            <child>
-                                               <object class="GtkImage" id="input_sources_remove_image">
-                                                 <property name="visible">True</property>
-                                                 <property name="icon_name">list-remove-symbolic</property>
-                                                 <property name="icon_size">1</property>
-                                                </object>
-                                            </child>
-                                          </object>
-                                          <packing>
-                                            <property name="expand">False</property>
-                                            <property name="fill">True</property>
-                                          </packing>
-                                        </child>
-                                      </object>
-                                    </child>
+                                    <property name="can_focus">True</property>
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="icon_name">list-add-symbolic</property>
                                   </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkSeparatorToolItem" id="toolbutton1">
+                                  <object class="GtkToolButton" id="input_source_remove">
                                     <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <property name="hexpand">True</property>
+                                    <property name="can_focus">True</property>
                                     <property name="use_action_appearance">False</property>
-                                    <property name="draw">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="icon_name">list-remove-symbolic</property>
                                   </object>
                                   <packing>
-                                    <property name="expand">True</property>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkToolItem" id="input_sources_show">
-
+                                  <object class="GtkToolButton" id="input_source_move_up">
+                                    <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
-                                    <property name="can_focus">False</property>
-                                    <child>
-                                      <object class="GtkBox" id="input_sources_show_box">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <child>
-                                          <object class="GtkButton" id="input_sources_show_button">
-                                            <property name="visible">True</property>
-                                            <property name="can_focus">True</property>
-                                            <property name="label" translatable="yes">_Preview</property>
-                                            <property name="use_underline">True</property>
-                                          </object>
-                                        </child>
-                                      </object>
-                                    </child>
+                                    <property name="can_focus">True</property>
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="icon_name">go-up-symbolic</property>
                                   </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="input_source_move_down">
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="icon_name">go-down-symbolic</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="input_source_show">
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="icon_name">input-keyboard-symbolic</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
                                 </child>
                               </object>
                               <packing>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]