aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2013-05-15 20:58:40 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2013-05-15 20:58:40 +0200
commit11c16cc173340c6cc4f3f76fa4f4ba5c98c8aa2e (patch)
tree4ed0e61250117bb4b2aebcc9194f84180d79d9ed /src
parentb8c4d292336404298cc91d35d69522ff8a0a55e3 (diff)
downloadtdv-11c16cc173340c6cc4f3f76fa4f4ba5c98c8aa2e.tar.gz
tdv-11c16cc173340c6cc4f3f76fa4f4ba5c98c8aa2e.tar.xz
tdv-11c16cc173340c6cc4f3f76fa4f4ba5c98c8aa2e.zip
Add Pango parsing.
Diffstat (limited to 'src')
-rw-r--r--src/sdtui.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/sdtui.c b/src/sdtui.c
index 45368e4..88dad87 100644
--- a/src/sdtui.c
+++ b/src/sdtui.c
@@ -29,6 +29,7 @@
#include <glib.h>
#include <gio/gio.h>
+#include <pango/pango.h>
#include <ncurses.h>
#include <unistd.h>
@@ -99,6 +100,17 @@ struct application
};
+/** Splits the entry and adds it to a pointer array. */
+static void
+view_entry_split_add (GPtrArray *out, const gchar *text)
+{
+ gchar **it, **tmp = g_strsplit (text, "\n", -1);
+ for (it = tmp; *it; it++)
+ if (**it)
+ g_ptr_array_add (out, g_strdup (*it));
+ g_strfreev (tmp);
+}
+
/** Decomposes a dictionary entry into the format we want. */
static ViewEntry *
view_entry_new (StardictIterator *iterator)
@@ -113,18 +125,25 @@ view_entry_new (StardictIterator *iterator)
GPtrArray *definitions = g_ptr_array_new ();
const GList *fields = stardict_entry_get_fields (entry);
+ gboolean found_anything_displayable = FALSE;
while (fields)
{
const StardictEntryField *field = fields->data;
switch (field->type)
{
case STARDICT_FIELD_MEANING:
+ view_entry_split_add (definitions, field->data);
+ found_anything_displayable = TRUE;
+ break;
+ case STARDICT_FIELD_PANGO:
{
- gchar **it, **tmp = g_strsplit (field->data, "\n", -1);
- for (it = tmp; *it; it++)
- if (**it)
- g_ptr_array_add (definitions, g_strdup (*it));
- g_strfreev (tmp);
+ char *text;
+ if (!pango_parse_markup (field->data, -1,
+ 0, NULL, &text, NULL, NULL))
+ text = g_strdup_printf ("<%s>", _("error in entry"));
+ view_entry_split_add (definitions, text);
+ found_anything_displayable = TRUE;
+ g_free (text);
break;
}
case STARDICT_FIELD_PHONETIC:
@@ -138,6 +157,10 @@ view_entry_new (StardictIterator *iterator)
}
g_object_unref (entry);
+ if (!found_anything_displayable)
+ g_ptr_array_add (definitions,
+ g_strdup_printf ("<%s>", _("no usable field found")));
+
ve->word = g_string_free (word, FALSE);
ve->definitions_length = definitions->len;
g_ptr_array_add (definitions, NULL);