[gnome-logs] Parse messages from the systemd catalog
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs] Parse messages from the systemd catalog
- Date: Tue, 23 Sep 2014 12:14:22 +0000 (UTC)
commit e409919dffb83c758ab96a0f3d85eaa150808c44
Author: Jonathan Kang <jonathan121537 gmail com>
Date: Tue Sep 9 14:09:10 2014 +0800
Parse messages from the systemd catalog
Use catalogs to explain messages. To implement this feature, I use
strtok function to parse the message named result->catalog, which exists
in the project.
For instance, I use a whitespace to get the field labels and ignore
them. Then I use "\n" to get the detailed message for the current field.
I also use dim-label style class for these field labels.
https://bugzilla.gnome.org/show_bug.cgi?id=709153
data/gl-eventviewdetail.ui | 145 +++++++++++++++++++++++++++++-
data/gl-style.css | 2 +-
src/gl-eventviewdetail.c | 211 +++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 350 insertions(+), 8 deletions(-)
---
diff --git a/data/gl-eventviewdetail.ui b/data/gl-eventviewdetail.ui
index 175e989..35f31c6 100644
--- a/data/gl-eventviewdetail.ui
+++ b/data/gl-eventviewdetail.ui
@@ -187,11 +187,15 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="catalog_label">
- <property name="visible">True</property>
+ <object class="GtkLabel" id="subject_field_label">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
<property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Subject</property>
<style>
- <class name="detail-catalog"/>
+ <class name="detail-field-label"/>
+ <class name="dim-label"/>
</style>
</object>
<packing>
@@ -199,6 +203,141 @@
<property name="top_attach">5</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="subject_label">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="selectable">True</property>
+ <style>
+ <class name="detail-subject"/>
+ <class name="event-monospace"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">5</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="definedby_field_label">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Defined By</property>
+ <style>
+ <class name="detail-field-label"/>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">6</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="definedby_label">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="selectable">True</property>
+ <style>
+ <class name="detail-definedby"/>
+ <class name="event-monospace"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">6</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="support_field_label">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Support</property>
+ <style>
+ <class name="detail-field-label"/>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">7</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="support_label">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="selectable">True</property>
+ <style>
+ <class name="detail-support"/>
+ <class name="event-monospace"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">7</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="documentation_field_label">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Documentation</property>
+ <style>
+ <class name="detail-field-label"/>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">8</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="documentation_label">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="selectable">True</property>
+ <style>
+ <class name="detail-documentation"/>
+ <class name="event-monospace"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">8</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="detailed_message_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="selectable">True</property>
+ <style>
+ <class name="detail-message"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">9</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
</object>
</child>
</template>
diff --git a/data/gl-style.css b/data/gl-style.css
index 0d9f296..b67aba1 100644
--- a/data/gl-style.css
+++ b/data/gl-style.css
@@ -13,7 +13,7 @@
padding: 10px;
}
-.detail-audit_session, .detail-catalog, .detail-kernel_device, .detail-message, .detail-priority,
.detail-time {
+.detail-audit_session, .detail-kernel_device, .detail-message, .detail-priority, .detail-time,
.detail-subject, .detail-definedby, .detail-support, .detail-documentation, .detail-message {
padding: 10px;
}
diff --git a/src/gl-eventviewdetail.c b/src/gl-eventviewdetail.c
index e19f3c1..bda8582 100644
--- a/src/gl-eventviewdetail.c
+++ b/src/gl-eventviewdetail.c
@@ -45,7 +45,15 @@ typedef struct
GtkWidget *device_field_label;
GtkWidget *device_label;
GtkWidget *priority_label;
- GtkWidget *catalog_label;
+ GtkWidget *subject_field_label;
+ GtkWidget *subject_label;
+ GtkWidget *definedby_field_label;
+ GtkWidget *definedby_label;
+ GtkWidget *support_field_label;
+ GtkWidget *support_label;
+ GtkWidget *documentation_field_label;
+ GtkWidget *documentation_label;
+ GtkWidget *detailed_message_label;
} GlEventViewDetailPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GlEventViewDetail, gl_event_view_detail, GTK_TYPE_BIN)
@@ -58,6 +66,9 @@ gl_event_view_detail_create_detail (GlEventViewDetail *detail)
GlEventViewDetailPrivate *priv;
GlJournalResult *result;
gchar *str;
+ gchar *str_field;
+ gchar *str_message;
+ gchar *str_copy;
priv = gl_event_view_detail_get_instance_private (detail);
@@ -69,7 +80,11 @@ gl_event_view_detail_create_detail (GlEventViewDetail *detail)
gtk_widget_set_direction (priv->message_label, GTK_TEXT_DIR_LTR);
gtk_widget_set_direction (priv->audit_label, GTK_TEXT_DIR_LTR);
gtk_widget_set_direction (priv->device_label, GTK_TEXT_DIR_LTR);
- gtk_widget_set_direction (priv->catalog_label, GTK_TEXT_DIR_LTR);
+ gtk_widget_set_direction (priv->subject_label, GTK_TEXT_DIR_LTR);
+ gtk_widget_set_direction (priv->definedby_label, GTK_TEXT_DIR_LTR);
+ gtk_widget_set_direction (priv->support_label, GTK_TEXT_DIR_LTR);
+ gtk_widget_set_direction (priv->documentation_label, GTK_TEXT_DIR_LTR);
+ gtk_widget_set_direction (priv->detailed_message_label, GTK_TEXT_DIR_LTR);
if (result->comm && *result->comm)
{
@@ -125,7 +140,179 @@ gl_event_view_detail_create_detail (GlEventViewDetail *detail)
gtk_label_set_text (GTK_LABEL (priv->priority_label), str);
g_free (str);
- gtk_label_set_text (GTK_LABEL (priv->catalog_label), result->catalog);
+ if (result->catalog != NULL)
+ {
+ gint subject_count = 0;
+ gint definedby_count = 0;
+ gint support_count = 0;
+ gint documentation_count = 0;
+
+ str_copy = g_strdup (result->catalog);
+
+ do
+ {
+ const gchar *label;
+
+ if (subject_count == 0 && definedby_count == 0
+ && support_count == 0 && documentation_count == 0)
+ {
+ str_field = strtok (str_copy, " ");
+ }
+ else
+ {
+ str_field = strtok (NULL, " ");
+ }
+
+ if (g_strcmp0 (str_field, "Subject:") == 0)
+ {
+ subject_count++;
+
+ if (subject_count == 1)
+ {
+ str_message = strtok (NULL, "\n");
+
+ if (str_message && *str_message)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->subject_label),
+ str_message);
+ gtk_widget_show (priv->subject_field_label);
+ gtk_widget_show (priv->subject_label);
+ }
+ }
+ else
+ {
+ str_field = strtok (NULL, "\n");
+ label = gtk_label_get_text (GTK_LABEL (priv->subject_label));
+ str = g_strconcat (label, "\n", str_field, NULL);
+
+ if (str && *str)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->subject_label),
+ str);
+ gtk_widget_show (priv->subject_field_label);
+ gtk_widget_show (priv->subject_label);
+ }
+
+ g_free (str);
+ }
+ }
+ else if (g_strcmp0 (str_field, "Defined-By:") == 0)
+ {
+ definedby_count++;
+
+ if (subject_count == 1)
+ {
+ str_message = strtok (NULL, "\n");
+
+ if (str_message && *str_message)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->definedby_label),
+ str_message);
+ gtk_widget_show (priv->definedby_field_label);
+ gtk_widget_show (priv->definedby_label);
+ }
+ }
+ else
+ {
+ str_field = strtok (NULL, "\n");
+ label = gtk_label_get_text (GTK_LABEL (priv->subject_label));
+ str = g_strconcat (label, "\n", str_field, NULL);
+
+ if (str && *str)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->definedby_label),
+ str);
+ gtk_widget_show (priv->definedby_field_label);
+ gtk_widget_show (priv->definedby_label);
+ }
+
+ g_free (str);
+ }
+ }
+ else if (g_strcmp0 (str_field, "Support:") == 0)
+ {
+ support_count++;
+
+ if (support_count == 1)
+ {
+ str_message = strtok (NULL, "\n");
+
+ if (str_message && *str_message)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->support_label),
+ str_message);
+ gtk_widget_show (priv->support_field_label);
+ gtk_widget_show (priv->support_label);
+ }
+ }
+ else
+ {
+ str_field = strtok (NULL, "\n");
+ label = gtk_label_get_text (GTK_LABEL (priv->subject_label));
+ str = g_strconcat (label, "\n", str_field, NULL);
+
+ if (str && *str)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->support_label),
+ str);
+ gtk_widget_show (priv->support_field_label);
+ gtk_widget_show (priv->support_label);
+ }
+
+ g_free (str);
+ }
+ }
+ else if (g_strcmp0 (str_field, "Documentation:") == 0)
+ {
+ documentation_count++;
+
+ if (documentation_count == 1)
+ {
+ str_message = strtok (NULL, "\n");
+
+ if (str_message && *str_message)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->documentation_label),
+ str_message);
+ gtk_widget_show (priv->documentation_field_label);
+ gtk_widget_show (priv->documentation_label);
+ }
+ }
+ else
+ {
+ str_field = strtok (NULL, "\n");
+ label = gtk_label_get_text (GTK_LABEL (priv->subject_label));
+ str = g_strconcat (label, "\n", str_field, NULL);
+
+ if (str && *str)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->documentation_label),
+ str);
+ gtk_widget_show (priv->documentation_field_label);
+ gtk_widget_show (priv->documentation_label);
+ }
+
+ g_free (str);
+ }
+ }
+ } while (g_strcmp0 (str_field, "Subject:") == 0
+ || g_strcmp0 (str_field, "Defined-By:") == 0
+ || g_strcmp0 (str_field, "Support:") == 0
+ || g_strcmp0 (str_field, "Documentation:") == 0);
+
+ str = strtok (NULL, "\0");
+ str_field = g_strconcat (str_field, " ", str, NULL);
+
+ if (str_field && *str_field)
+ {
+ gtk_label_set_text (GTK_LABEL (priv->detailed_message_label),
+ str_field);
+ gtk_widget_show (priv->detailed_message_label);
+ }
+
+ g_free (str_field);
+ g_free (str_copy);
+ }
}
static void
@@ -246,7 +433,23 @@ gl_event_view_detail_class_init (GlEventViewDetailClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
priority_label);
gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
- catalog_label);
+ subject_field_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
+ subject_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
+ definedby_field_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
+ definedby_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
+ support_field_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
+ support_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
+ documentation_field_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
+ documentation_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GlEventViewDetail,
+ detailed_message_label);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]