Charmap plugin little improvement



I send patch for little improvement charmap plugin. It remember current
character on exit and on start restore position to this char.

Regards
Marv 
diff --recursive -c gtranslator/plugins/charmap/charmap-panel.c gtranslator.new/plugins/charmap/charmap-panel.c
*** gtranslator/plugins/charmap/charmap-panel.c	2009-11-22 18:07:57.000000000 +0100
--- gtranslator.new/plugins/charmap/charmap-panel.c	2009-11-28 02:44:14.000000000 +0100
***************
*** 25,36 ****
--- 25,40 ----
  #include "plugin.h"
  #include "charmap-panel.h"
  
+ #include <errno.h>
+ #include <gconf/gconf-client.h>
  #ifdef HAVE_GUCHARMAP_2
  #include <gucharmap/gucharmap.h>
  #else
  #include <gucharmap/gucharmap-script-chapters.h>
  #endif
  
+ #define UNICHAR_MAX 0x0000FFFFUL
+ 
  #define GTR_CHARMAP_PANEL_GET_PRIVATE(object)	(G_TYPE_INSTANCE_GET_PRIVATE ( \
  						 (object),		       \
  						 GTR_TYPE_CHARMAP_PANEL,     \
***************
*** 38,43 ****
--- 42,48 ----
  
  struct _GtranslatorCharmapPanelPrivate
  {
+   GConfClient *gconf_client;
  #ifdef HAVE_GUCHARMAP_2
    GucharmapChaptersView *chapters_view;
    GucharmapChartable *chartable;
***************
*** 47,52 ****
--- 52,59 ----
  #endif
  };
  
+ static GtkWidgetClass *parent_class = NULL;
+ 
  GTR_PLUGIN_DEFINE_TYPE (GtranslatorCharmapPanel, gtranslator_charmap_panel,
  			GTK_TYPE_VBOX)
  #ifdef HAVE_GUCHARMAP_2
***************
*** 78,83 ****
--- 85,125 ----
  }
  #endif /* HAVE_GUCHARMAP_2 */
  
+ 
+ static void
+ gtranslator_charmap_panel_save_last_char (GtranslatorCharmapPanel * panel, gunichar ch)
+ {
+   char str[11];
+ 
+   g_snprintf (str, sizeof (str), "U+%04X", ch);
+   gconf_client_set_string (panel->priv->gconf_client, LAST_CHAR_KEY, str, NULL);
+ }
+ 
+ static gunichar
+ gtranslator_charmap_panel_fetch_last_char (GtranslatorCharmapPanel * panel)
+ {
+   gchar *str, *endptr;
+   guint64 value;
+   
+   str = gconf_client_get_string (panel->priv->gconf_client, LAST_CHAR_KEY, NULL);
+   if (!str || !g_str_has_prefix (str, "U+")) {
+     g_free (str);
+     return gucharmap_unicode_get_locale_character ();
+   }
+   
+   endptr = NULL;
+   errno = 0;
+   value = g_ascii_strtoull (str + 2 /* skip the "U+" */, &endptr, 16);
+   if (errno || endptr == str || value > UNICHAR_MAX) {
+     g_free (str);
+     return gucharmap_unicode_get_locale_character  ();
+   }
+   
+   g_free (str);
+   
+   return (gunichar) value;
+ }
+ 
  static void
  gtranslator_charmap_panel_init (GtranslatorCharmapPanel * panel)
  {
***************
*** 90,98 ****
--- 132,143 ----
  #else
    GucharmapCodepointList *codepoint_list;
  #endif
+   gunichar lastchar;
  
    priv = panel->priv = GTR_CHARMAP_PANEL_GET_PRIVATE (panel);
  
+   priv->gconf_client = gconf_client_get_default ();
+ 
    paned = GTK_PANED (gtk_vpaned_new ());
  
  #ifdef HAVE_GUCHARMAP_2
***************
*** 134,140 ****
    gtk_paned_pack2 (paned, scrolled_window, TRUE, TRUE);
    gtk_widget_show (scrolled_window);
  
!   gucharmap_chapters_view_select_locale (priv->chapters_view);
  #else
    priv->chapters = gucharmap_script_chapters_new ();
    g_signal_connect (priv->chapters,
--- 179,187 ----
    gtk_paned_pack2 (paned, scrolled_window, TRUE, TRUE);
    gtk_widget_show (scrolled_window);
  
!   lastchar = gtranslator_charmap_panel_fetch_last_char (panel);
!   gucharmap_chapters_view_select_character (priv->chapters_view, lastchar);
!   gucharmap_chartable_set_active_character (priv->chartable, lastchar);
  #else
    priv->chapters = gucharmap_script_chapters_new ();
    g_signal_connect (priv->chapters,
***************
*** 152,157 ****
--- 199,208 ----
    gucharmap_table_set_codepoint_list (GUCHARMAP_TABLE (priv->table),
  				      codepoint_list);
  
+   lastchar = gtranslator_charmap_panel_fetch_last_char (panel);
+   gucharmap_chapters_view_select_character (priv->chapters, lastchar);
+   gucharmap_chartable_set_active_character (priv->table, lastchar);
+ 
    gtk_paned_pack1 (paned, priv->chapters, FALSE, TRUE);
    gtk_paned_pack2 (paned, priv->table, TRUE, TRUE);
  #endif /* HAVE_GUCHARMAP_2 */
***************
*** 162,167 ****
--- 213,239 ----
  }
  
  static void
+ gtranslator_charmap_panel_unrealize (GtkWidget *widget)
+ {
+   gunichar lastchar;
+ #ifdef HAVE_GUCHARMAP_2
+   GucharmapChartable *chartable;
+   
+   chartable = gtranslator_charmap_panel_get_chartable (GTR_CHARMAP_PANEL(widget));
+   lastchar = gucharmap_chartable_get_active_character (chartable);
+ #else /* HAVE_GUCHARMAP_2 */
+   GucharmapTable *table;
+   
+   table = gtranslator_charmap_panel_get_table (GTR_CHARMAP_PANEL(widget));
+   lastchar = gucharmap_table_get_active_character (table);
+ #endif /* HAVE_GUCHARMAP_2 */
+   gtranslator_charmap_panel_save_last_char(GTR_CHARMAP_PANEL(widget), lastchar);
+   
+   if (GTK_WIDGET_CLASS(parent_class)->unrealize)
+     (* GTK_WIDGET_CLASS(parent_class)->unrealize) (widget);
+ }
+ 
+ static void
  gtranslator_charmap_panel_finalize (GObject * object)
  {
    G_OBJECT_CLASS (gtranslator_charmap_panel_parent_class)->finalize (object);
***************
*** 171,180 ****
  gtranslator_charmap_panel_class_init (GtranslatorCharmapPanelClass * klass)
  {
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
  
!   g_type_class_add_private (klass, sizeof (GtranslatorCharmapPanelPrivate));
  
    object_class->finalize = gtranslator_charmap_panel_finalize;
  }
  
  GtkWidget *
--- 243,257 ----
  gtranslator_charmap_panel_class_init (GtranslatorCharmapPanelClass * klass)
  {
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
+   GtkWidgetClass *gtk_widget_class = GTK_WIDGET_CLASS (klass);
  
!   parent_class = gtk_type_class (gtk_widget_get_type ());
  
+   g_type_class_add_private (klass, sizeof (GtranslatorCharmapPanelPrivate));
+   
    object_class->finalize = gtranslator_charmap_panel_finalize;
+   
+   gtk_widget_class->unrealize = gtranslator_charmap_panel_unrealize;
  }
  
  GtkWidget *
diff --recursive -c gtranslator/plugins/charmap/charmap-panel.h gtranslator.new/plugins/charmap/charmap-panel.h
*** gtranslator/plugins/charmap/charmap-panel.h	2009-11-22 18:07:57.000000000 +0100
--- gtranslator.new/plugins/charmap/charmap-panel.h	2009-11-28 02:08:08.000000000 +0100
***************
*** 43,48 ****
--- 43,51 ----
  #define GTR_IS_CHARMAP_PANEL(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GTR_TYPE_CHARMAP_PANEL))
  #define GTR_IS_CHARMAP_PANEL_CLASS(k)		(G_TYPE_CHECK_CLASS_TYPE ((k), GTR_TYPE_CHARMAP_PANEL))
  #define GTR_CHARMAP_PANEL_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GTR_TYPE_CHARMAP_PANEL, GtranslatorCharmapPanelClass))
+ /* Gconf keys */
+ #define CHARMAP_BASE_KEY "/apps/gtranslator/plugins/charmap"
+ #define LAST_CHAR_KEY CHARMAP_BASE_KEY "/last_char"
  /* Private structure type */
  typedef struct _GtranslatorCharmapPanelPrivate GtranslatorCharmapPanelPrivate;
  


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