[gnome-flashback] input-sources: move display_name and short_name to subclasses
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] input-sources: move display_name and short_name to subclasses
- Date: Thu, 2 Jan 2020 10:57:45 +0000 (UTC)
commit 18fc80eec31d7472416527872d9463cf253f3e16
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Jan 2 04:37:55 2020 +0200
input-sources: move display_name and short_name to subclasses
.../libinput-sources/gf-input-source-ibus.c | 107 +++++++++++++++++++++
.../libinput-sources/gf-input-source-manager.c | 86 ++---------------
.../libinput-sources/gf-input-source-xkb.c | 93 ++++++++++++++++++
gnome-flashback/libinput-sources/gf-input-source.c | 67 +------------
gnome-flashback/libinput-sources/gf-input-source.h | 9 +-
5 files changed, 218 insertions(+), 144 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-input-source-ibus.c
b/gnome-flashback/libinput-sources/gf-input-source-ibus.c
index b0138d8..02dfee6 100644
--- a/gnome-flashback/libinput-sources/gf-input-source-ibus.c
+++ b/gnome-flashback/libinput-sources/gf-input-source-ibus.c
@@ -28,6 +28,9 @@ struct _GfInputSourceIBus
IBusPropList *prop_list;
+ char *display_name;
+ char *short_name;
+
char *xkb_id;
};
@@ -44,12 +47,63 @@ static GParamSpec *ibus_properties[LAST_PROP] = { NULL };
G_DEFINE_TYPE (GfInputSourceIBus, gf_input_source_ibus, GF_TYPE_INPUT_SOURCE)
+static gchar *
+get_symbol_from_char_code (gunichar code)
+{
+ gchar buffer[6];
+ gint length;
+
+ length = g_unichar_to_utf8 (code, buffer);
+ buffer[length] = '\0';
+
+ return g_strdup_printf ("%s", buffer);
+}
+
+static gchar *
+make_engine_short_name (IBusEngineDesc *engine_desc)
+{
+ const gchar *symbol;
+ const gchar *language;
+
+ symbol = ibus_engine_desc_get_symbol (engine_desc);
+
+ if (symbol != NULL && symbol[0] != '\0')
+ return g_strdup (symbol);
+
+ language = ibus_engine_desc_get_language (engine_desc);
+
+ if (language != NULL && language[0] != '\0')
+ {
+ gchar **codes;
+
+ codes = g_strsplit (language, "_", 2);
+
+ if (strlen (codes[0]) == 2 || strlen (codes[0]) == 3)
+ {
+ gchar *short_name;
+
+ short_name = g_ascii_strdown (codes[0], -1);
+ g_strfreev (codes);
+
+ return short_name;
+ }
+
+ g_strfreev (codes);
+ }
+
+ return get_symbol_from_char_code (0x2328);
+}
+
static void
gf_input_source_ibus_constructed (GObject *object)
{
GfInputSourceIBus *self;
const char *id;
IBusEngineDesc *engine_desc;
+ const char *language_code;
+ const char *language;
+ const char *longname;
+ const char *textdomain;
const char *layout_variant;
const char *layout;
@@ -62,6 +116,17 @@ gf_input_source_ibus_constructed (GObject *object)
engine_desc = gf_ibus_manager_get_engine_desc (self->ibus_manager, id);
g_assert (engine_desc != NULL);
+ language_code = ibus_engine_desc_get_language (engine_desc);
+ language = ibus_get_language_name (language_code);
+ longname = ibus_engine_desc_get_longname (engine_desc);
+ textdomain = ibus_engine_desc_get_textdomain (engine_desc);
+
+ if (*textdomain != '\0' && *longname != '\0')
+ longname = g_dgettext (textdomain, longname);
+
+ self->display_name = g_strdup_printf ("%s (%s)", language, longname);
+ self->short_name = make_engine_short_name (engine_desc);
+
layout = ibus_engine_desc_get_layout (engine_desc);
layout_variant = ibus_engine_desc_get_layout_variant (engine_desc);
@@ -91,6 +156,8 @@ gf_input_source_ibus_finalize (GObject *object)
self = GF_INPUT_SOURCE_IBUS (object);
+ g_clear_pointer (&self->display_name, g_free);
+ g_clear_pointer (&self->short_name, g_free);
g_clear_pointer (&self->xkb_id, g_free);
G_OBJECT_CLASS (gf_input_source_ibus_parent_class)->finalize (object);
@@ -118,6 +185,43 @@ gf_input_source_ibus_set_property (GObject *object,
}
}
+static const char *
+gf_input_source_ibus_get_display_name (GfInputSource *input_source)
+{
+ GfInputSourceIBus *self;
+
+ self = GF_INPUT_SOURCE_IBUS (input_source);
+
+ return self->display_name;
+}
+
+static const char *
+gf_input_source_ibus_get_short_name (GfInputSource *input_source)
+{
+ GfInputSourceIBus *self;
+
+ self = GF_INPUT_SOURCE_IBUS (input_source);
+
+ return self->short_name;
+}
+
+static gboolean
+gf_input_source_ibus_set_short_name (GfInputSource *input_source,
+ const char *short_name)
+{
+ GfInputSourceIBus *self;
+
+ self = GF_INPUT_SOURCE_IBUS (input_source);
+
+ if (g_strcmp0 (self->short_name, short_name) == 0)
+ return FALSE;
+
+ g_clear_pointer (&self->short_name, g_free);
+ self->short_name = g_strdup (short_name);
+
+ return TRUE;
+}
+
static const char *
gf_input_source_ibus_get_xkb_id (GfInputSource *input_source)
{
@@ -157,6 +261,9 @@ gf_input_source_ibus_class_init (GfInputSourceIBusClass *self_class)
object_class->finalize = gf_input_source_ibus_finalize;
object_class->set_property = gf_input_source_ibus_set_property;
+ input_source_class->get_display_name = gf_input_source_ibus_get_display_name;
+ input_source_class->get_short_name = gf_input_source_ibus_get_short_name;
+ input_source_class->set_short_name = gf_input_source_ibus_set_short_name;
input_source_class->get_xkb_id = gf_input_source_ibus_get_xkb_id;
install_properties (object_class);
diff --git a/gnome-flashback/libinput-sources/gf-input-source-manager.c
b/gnome-flashback/libinput-sources/gf-input-source-manager.c
index e3ec666..b021cbc 100644
--- a/gnome-flashback/libinput-sources/gf-input-source-manager.c
+++ b/gnome-flashback/libinput-sources/gf-input-source-manager.c
@@ -45,9 +45,6 @@ struct _SourceInfo
gchar *id;
- gchar *display_name;
- gchar *short_name;
-
char *icon_file;
};
@@ -398,9 +395,7 @@ get_symbol_from_char_code (gunichar code)
static SourceInfo *
source_info_new (const gchar *type,
- const gchar *id,
- const gchar *display_name,
- const gchar *short_name)
+ const gchar *id)
{
SourceInfo *info;
@@ -408,8 +403,6 @@ source_info_new (const gchar *type,
info->type = g_strdup (type);
info->id = g_strdup (id);
- info->display_name = g_strdup (display_name);
- info->short_name = g_strdup (short_name);
return info;
}
@@ -423,8 +416,6 @@ source_info_free (gpointer data)
g_free (info->type);
g_free (info->id);
- g_free (info->display_name);
- g_free (info->short_name);
g_free (info->icon_file);
g_free (info);
@@ -672,41 +663,6 @@ keybindings_init (GfInputSourceManager *manager)
switch_input_backward_changed_cb (manager->wm_keybindings, NULL, manager);
}
-static gchar *
-make_engine_short_name (IBusEngineDesc *engine_desc)
-{
- const gchar *symbol;
- const gchar *language;
-
- symbol = ibus_engine_desc_get_symbol (engine_desc);
-
- if (symbol != NULL && symbol[0] != '\0')
- return g_strdup (symbol);
-
- language = ibus_engine_desc_get_language (engine_desc);
-
- if (language != NULL && language[0] != '\0')
- {
- gchar **codes;
-
- codes = g_strsplit (language, "_", 2);
-
- if (strlen (codes[0]) == 2 || strlen (codes[0]) == 3)
- {
- gchar *short_name;
-
- short_name = g_ascii_strdown (codes[0], -1);
- g_strfreev (codes);
-
- return short_name;
- }
-
- g_strfreev (codes);
- }
-
- return get_symbol_from_char_code (0x2328);
-}
-
static GList *
get_source_info_list (GfInputSourceManager *manager)
{
@@ -734,25 +690,17 @@ get_source_info_list (GfInputSourceManager *manager)
if (g_strcmp0 (type, INPUT_SOURCE_TYPE_XKB) == 0)
{
gboolean exists;
- const gchar *display_name;
- const gchar *short_name;
- exists = gnome_xkb_info_get_layout_info (xkb_info, id, &display_name,
- &short_name, NULL, NULL);
+ exists = gnome_xkb_info_get_layout_info (xkb_info, id, NULL,
+ NULL, NULL, NULL);
if (exists)
- info = source_info_new (type, id, display_name, short_name);
+ info = source_info_new (type, id);
}
else if (g_strcmp0 (type, INPUT_SOURCE_TYPE_IBUS) == 0)
{
IBusEngineDesc *engine_desc;
- const gchar *language_code;
- const gchar *language;
- const gchar *longname;
- const gchar *textdomain;
const char *icon;
- gchar *display_name;
- gchar *short_name;
if (manager->disable_ibus)
continue;
@@ -763,23 +711,10 @@ get_source_info_list (GfInputSourceManager *manager)
if (engine_desc == NULL)
continue;
- language_code = ibus_engine_desc_get_language (engine_desc);
- language = ibus_get_language_name (language_code);
- longname = ibus_engine_desc_get_longname (engine_desc);
- textdomain = ibus_engine_desc_get_textdomain (engine_desc);
icon = ibus_engine_desc_get_icon (engine_desc);
- if (*textdomain != '\0' && *longname != '\0')
- longname = g_dgettext (textdomain, longname);
-
- display_name = g_strdup_printf ("%s (%s)", language, longname);
- short_name = make_engine_short_name (engine_desc);
-
- info = source_info_new (type, id, display_name, short_name);
+ info = source_info_new (type, id);
info->icon_file = g_strdup (icon);
-
- g_free (display_name);
- g_free (short_name);
}
if (info != NULL)
@@ -792,17 +727,12 @@ get_source_info_list (GfInputSourceManager *manager)
{
const gchar *type;
const gchar *id;
- const gchar *display_name;
- const gchar *short_name;
SourceInfo *info;
type = INPUT_SOURCE_TYPE_XKB;
id = gf_keyboard_manager_get_default_layout (manager->keyboard_manager);
- gnome_xkb_info_get_layout_info (xkb_info, id, &display_name,
- &short_name, NULL, NULL);
-
- info = source_info_new (type, id, display_name, short_name);
+ info = source_info_new (type, id);
list = g_list_append (list, info);
}
@@ -1200,8 +1130,6 @@ sources_changed_cb (GfInputSourceSettings *settings,
"ibus-manager", manager->ibus_manager,
"type", info->type,
"id", info->id,
- "display-name", info->display_name,
- "short-name", info->short_name,
"index", position,
NULL);
}
@@ -1215,8 +1143,6 @@ sources_changed_cb (GfInputSourceSettings *settings,
"xkb-info", xkb_info,
"type", info->type,
"id", info->id,
- "display-name", info->display_name,
- "short-name", info->short_name,
"index", position,
NULL);
}
diff --git a/gnome-flashback/libinput-sources/gf-input-source-xkb.c
b/gnome-flashback/libinput-sources/gf-input-source-xkb.c
index c4359de..afadd85 100644
--- a/gnome-flashback/libinput-sources/gf-input-source-xkb.c
+++ b/gnome-flashback/libinput-sources/gf-input-source-xkb.c
@@ -25,6 +25,9 @@ struct _GfInputSourceXkb
GfInputSource parent;
GnomeXkbInfo *xkb_info;
+
+ char *display_name;
+ char *short_name;
};
enum
@@ -40,6 +43,31 @@ static GParamSpec *xkb_properties[LAST_PROP] = { NULL };
G_DEFINE_TYPE (GfInputSourceXkb, gf_input_source_xkb, GF_TYPE_INPUT_SOURCE)
+static void
+gf_input_source_xkb_constructed (GObject *object)
+{
+ GfInputSourceXkb *self;
+ const char *id;
+ const char *display_name;
+ const char *short_name;
+
+ self = GF_INPUT_SOURCE_XKB (object);
+
+ G_OBJECT_CLASS (gf_input_source_xkb_parent_class)->constructed (object);
+
+ id = gf_input_source_get_id (GF_INPUT_SOURCE (self));
+
+ gnome_xkb_info_get_layout_info (self->xkb_info,
+ id,
+ &display_name,
+ &short_name,
+ NULL,
+ NULL);
+
+ self->display_name = g_strdup (display_name);
+ self->short_name = g_strdup (short_name);
+}
+
static void
gf_input_source_xkb_dispose (GObject *object)
{
@@ -52,6 +80,19 @@ gf_input_source_xkb_dispose (GObject *object)
G_OBJECT_CLASS (gf_input_source_xkb_parent_class)->dispose (object);
}
+static void
+gf_input_source_xkb_finalize (GObject *object)
+{
+ GfInputSourceXkb *self;
+
+ self = GF_INPUT_SOURCE_XKB (object);
+
+ g_clear_pointer (&self->display_name, g_free);
+ g_clear_pointer (&self->short_name, g_free);
+
+ G_OBJECT_CLASS (gf_input_source_xkb_parent_class)->finalize (object);
+}
+
static void
gf_input_source_xkb_set_property (GObject *object,
unsigned int prop_id,
@@ -74,6 +115,49 @@ gf_input_source_xkb_set_property (GObject *object,
}
}
+static const char *
+gf_input_source_xkb_get_display_name (GfInputSource *input_source)
+{
+ GfInputSourceXkb *self;
+
+ self = GF_INPUT_SOURCE_XKB (input_source);
+
+ return self->display_name;
+}
+
+static const char *
+gf_input_source_xkb_get_short_name (GfInputSource *input_source)
+{
+ GfInputSourceXkb *self;
+
+ self = GF_INPUT_SOURCE_XKB (input_source);
+
+ return self->short_name;
+}
+
+static gboolean
+gf_input_source_xkb_set_short_name (GfInputSource *input_source,
+ const char *short_name)
+{
+ GfInputSourceXkb *self;
+
+ self = GF_INPUT_SOURCE_XKB (input_source);
+
+ if (g_strcmp0 (self->short_name, short_name) == 0)
+ return FALSE;
+
+ g_clear_pointer (&self->short_name, g_free);
+ self->short_name = g_strdup (short_name);
+
+ return TRUE;
+}
+
+static const char *
+gf_input_source_xkb_get_xkb_id (GfInputSource *input_source)
+{
+ return gf_input_source_get_id (input_source);
+}
+
static void
install_properties (GObjectClass *object_class)
{
@@ -93,12 +177,21 @@ static void
gf_input_source_xkb_class_init (GfInputSourceXkbClass *self_class)
{
GObjectClass *object_class;
+ GfInputSourceClass *input_source_class;
object_class = G_OBJECT_CLASS (self_class);
+ input_source_class = GF_INPUT_SOURCE_CLASS (self_class);
+ object_class->constructed = gf_input_source_xkb_constructed;
object_class->dispose = gf_input_source_xkb_dispose;
+ object_class->finalize = gf_input_source_xkb_finalize;
object_class->set_property = gf_input_source_xkb_set_property;
+ input_source_class->get_display_name = gf_input_source_xkb_get_display_name;
+ input_source_class->get_short_name = gf_input_source_xkb_get_short_name;
+ input_source_class->set_short_name = gf_input_source_xkb_set_short_name;
+ input_source_class->get_xkb_id = gf_input_source_xkb_get_xkb_id;
+
install_properties (object_class);
}
diff --git a/gnome-flashback/libinput-sources/gf-input-source.c
b/gnome-flashback/libinput-sources/gf-input-source.c
index 01c810f..ac77a44 100644
--- a/gnome-flashback/libinput-sources/gf-input-source.c
+++ b/gnome-flashback/libinput-sources/gf-input-source.c
@@ -25,8 +25,6 @@ typedef struct
{
gchar *type;
gchar *id;
- gchar *display_name;
- gchar *short_name;
guint index;
char *icon_file;
@@ -48,8 +46,6 @@ enum
PROP_TYPE,
PROP_ID,
- PROP_DISPLAY_NAME,
- PROP_SHORT_NAME,
PROP_INDEX,
LAST_PROP
@@ -81,14 +77,6 @@ gf_input_source_get_property (GObject *object,
g_value_set_string (value, priv->id);
break;
- case PROP_DISPLAY_NAME:
- g_value_set_string (value, priv->display_name);
- break;
-
- case PROP_SHORT_NAME:
- g_value_set_string (value, priv->short_name);
- break;
-
case PROP_INDEX:
g_value_set_uint (value, priv->index);
break;
@@ -121,14 +109,6 @@ gf_input_source_set_property (GObject *object,
priv->id = g_value_dup_string (value);
break;
- case PROP_DISPLAY_NAME:
- priv->display_name = g_value_dup_string (value);
- break;
-
- case PROP_SHORT_NAME:
- priv->short_name = g_value_dup_string (value);
- break;
-
case PROP_INDEX:
priv->index = g_value_get_uint (value);
break;
@@ -150,8 +130,6 @@ gf_input_source_finalize (GObject *object)
g_free (priv->type);
g_free (priv->id);
- g_free (priv->display_name);
- g_free (priv->short_name);
g_free (priv->icon_file);
G_OBJECT_CLASS (gf_input_source_parent_class)->finalize (object);
@@ -187,18 +165,6 @@ gf_input_source_class_init (GfInputSourceClass *source_class)
NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
- properties[PROP_DISPLAY_NAME] =
- g_param_spec_string ("display-name", "Display name",
- "The display name of the input source",
- NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS);
-
- properties[PROP_SHORT_NAME] =
- g_param_spec_string ("short-name", "Short name",
- "The short name of the input source",
- NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS);
-
properties[PROP_INDEX] =
g_param_spec_uint ("index", "Index", "The index of the input source",
0, G_MAXUINT, 0,
@@ -236,37 +202,22 @@ gf_input_source_get_id (GfInputSource *source)
const gchar *
gf_input_source_get_display_name (GfInputSource *source)
{
- GfInputSourcePrivate *priv;
-
- priv = gf_input_source_get_instance_private (source);
-
- return priv->display_name;
+ return GF_INPUT_SOURCE_GET_CLASS (source)->get_display_name (source);
}
const gchar *
gf_input_source_get_short_name (GfInputSource *source)
{
- GfInputSourcePrivate *priv;
-
- priv = gf_input_source_get_instance_private (source);
-
- return priv->short_name;
+ return GF_INPUT_SOURCE_GET_CLASS (source)->get_short_name (source);
}
void
gf_input_source_set_short_name (GfInputSource *source,
const gchar *short_name)
{
- GfInputSourcePrivate *priv;
-
- priv = gf_input_source_get_instance_private (source);
-
- if (g_strcmp0 (priv->short_name, short_name) == 0)
+ if (!GF_INPUT_SOURCE_GET_CLASS (source)->set_short_name (source, short_name))
return;
- g_free (priv->short_name);
- priv->short_name = g_strdup (short_name);
-
g_signal_emit (source, signals[SIGNAL_CHANGED], 0);
}
@@ -283,17 +234,7 @@ gf_input_source_get_index (GfInputSource *source)
const gchar *
gf_input_source_get_xkb_id (GfInputSource *source)
{
- GfInputSourceClass *input_source_class;
- GfInputSourcePrivate *priv;
-
- input_source_class = GF_INPUT_SOURCE_GET_CLASS (source);
-
- if (input_source_class->get_xkb_id != NULL)
- return input_source_class->get_xkb_id (source);
-
- priv = gf_input_source_get_instance_private (source);
-
- return priv->id;
+ return GF_INPUT_SOURCE_GET_CLASS (source)->get_xkb_id (source);
}
void
diff --git a/gnome-flashback/libinput-sources/gf-input-source.h
b/gnome-flashback/libinput-sources/gf-input-source.h
index 45e1b38..a1807ae 100644
--- a/gnome-flashback/libinput-sources/gf-input-source.h
+++ b/gnome-flashback/libinput-sources/gf-input-source.h
@@ -31,7 +31,14 @@ struct _GfInputSourceClass
{
GObjectClass parent_class;
- const char * (* get_xkb_id) (GfInputSource *self);
+ const char * (* get_display_name) (GfInputSource *self);
+
+ const char * (* get_short_name) (GfInputSource *self);
+
+ gboolean (* set_short_name) (GfInputSource *self,
+ const char *short_name);
+
+ const char * (* get_xkb_id) (GfInputSource *self);
};
const gchar *gf_input_source_get_source_type (GfInputSource *source);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]