[gtranslator/dl-workflow: 3/5] gtr-header: Load custom headers from a local file
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator/dl-workflow: 3/5] gtr-header: Load custom headers from a local file
- Date: Tue, 2 Feb 2021 10:19:21 +0000 (UTC)
commit 9587f578676211a49fc682d6baeef104a6842ac3
Author: Amanda Shafack <shafack likhene gmail com>
Date: Mon Jan 18 08:16:56 2021 +0100
gtr-header: Load custom headers from a local file
Load the Damned lies information contained in the custom headers
of a local po file.
Show the DL info in the header dialog on a separate tab and
enable users to modify as required.
src/gtr-header-dialog.c | 64 +++++++++++++++++++
src/gtr-header-dialog.ui | 157 +++++++++++++++++++++++++++++++++++++++++++++++
src/gtr-header.c | 107 ++++++++++++++++++++++++++++++++
src/gtr-header.h | 12 ++++
src/gtr-po.c | 42 +++++++++----
src/gtr-po.h | 4 +-
6 files changed, 371 insertions(+), 15 deletions(-)
---
diff --git a/src/gtr-header-dialog.c b/src/gtr-header-dialog.c
index 677f866f..39c616f8 100644
--- a/src/gtr-header-dialog.c
+++ b/src/gtr-header-dialog.c
@@ -60,6 +60,12 @@ typedef struct
GtkWidget *charset;
GtkWidget *encoding;
+ GtkWidget *team;
+ GtkWidget *module;
+ GtkWidget *branch;
+ GtkWidget *domain;
+ GtkWidget *state;
+
GtrPo *po;
} GtrHeaderDialogPrivate;
@@ -201,6 +207,24 @@ language_changed (GtkWidget * widget, GtrHeaderDialog * dlg)
}
}
+static void
+dl_changed (GtkWidget * widget, GtrHeaderDialog * dlg)
+{
+ const gchar *team, *module, *branch, *domain;
+ GtrHeaderDialogPrivate *priv = gtr_header_dialog_get_instance_private (dlg);
+
+ team = gtk_entry_get_text (GTK_ENTRY (priv->team));
+ module = gtk_entry_get_text (GTK_ENTRY (priv->module));
+ branch = gtk_entry_get_text (GTK_ENTRY (priv->branch));
+ domain = gtk_entry_get_text (GTK_ENTRY (priv->domain));
+
+ gtr_header_set_dl_info (gtr_po_get_header (priv->po),
+ team, module, branch,
+ domain);
+
+ po_state_set_modified (priv->po);
+}
+
static void
gtr_header_dialog_fill_from_header (GtrHeaderDialog * dlg)
{
@@ -259,6 +283,27 @@ gtr_header_dialog_fill_from_header (GtrHeaderDialog * dlg)
text = gtr_header_get_encoding (header);
gtk_entry_set_text (GTK_ENTRY (priv->encoding), text);
g_free (text);
+
+ /* Damned Lies Information */
+ text = gtr_header_get_dl_team (header);
+ gtk_entry_set_text (GTK_ENTRY (priv->team), text);
+ g_free (text);
+
+ text = gtr_header_get_dl_module (header);
+ gtk_entry_set_text (GTK_ENTRY (priv->module), text);
+ g_free (text);
+
+ text = gtr_header_get_dl_branch (header);
+ gtk_entry_set_text (GTK_ENTRY (priv->branch), text);
+ g_free (text);
+
+ text = gtr_header_get_dl_domain (header);
+ gtk_entry_set_text (GTK_ENTRY (priv->domain), text);
+ g_free (text);
+
+ text = gtr_header_get_dl_state (header);
+ gtk_entry_set_text (GTK_ENTRY (priv->state), text);
+ g_free (text);
}
static void
@@ -309,6 +354,12 @@ gtr_header_dialog_init (GtrHeaderDialog * dlg)
priv->lg_email = GTK_WIDGET (gtk_builder_get_object (builder, "lg_email_entry"));
priv->charset = GTK_WIDGET (gtk_builder_get_object (builder, "charset_entry"));
priv->encoding = GTK_WIDGET (gtk_builder_get_object (builder, "encoding_entry"));
+ priv->team = GTK_WIDGET (gtk_builder_get_object (builder, "team"));
+ priv->module = GTK_WIDGET (gtk_builder_get_object (builder, "module"));
+ priv->branch = GTK_WIDGET (gtk_builder_get_object (builder, "branch"));
+ priv->domain = GTK_WIDGET (gtk_builder_get_object (builder, "domain"));
+ priv->state = GTK_WIDGET (gtk_builder_get_object (builder, "state"));
+
g_object_unref (builder);
gtk_box_pack_start (content_area, priv->main_box, FALSE, FALSE, 0);
@@ -324,6 +375,7 @@ gtr_header_dialog_init (GtrHeaderDialog * dlg)
gtk_widget_set_sensitive (priv->pot_date, FALSE);
gtk_widget_set_sensitive (priv->po_date, FALSE);
gtk_widget_set_sensitive (priv->charset, FALSE);
+ gtk_widget_set_sensitive (priv->state, FALSE);
if (gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (priv->take_my_options)))
@@ -385,6 +437,18 @@ set_default_values (GtrHeaderDialog * dlg, GtrWindow * window)
g_signal_connect (priv->lg_email, "changed",
G_CALLBACK (language_changed), dlg);
+
+ g_signal_connect (priv->team, "changed",
+ G_CALLBACK (dl_changed), dlg);
+
+ g_signal_connect (priv->module, "changed",
+ G_CALLBACK (dl_changed), dlg);
+
+ g_signal_connect (priv->branch, "changed",
+ G_CALLBACK (dl_changed), dlg);
+
+ g_signal_connect (priv->domain, "changed",
+ G_CALLBACK (dl_changed), dlg);
}
void
diff --git a/src/gtr-header-dialog.ui b/src/gtr-header-dialog.ui
index 2f4820c1..0d70e405 100644
--- a/src/gtr-header-dialog.ui
+++ b/src/gtr-header-dialog.ui
@@ -434,6 +434,163 @@
<property name="tab_fill">False</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">6</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">2</property>
+ <property name="column_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label43">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">DL Team:</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label44">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">DL Module:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">module</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label45">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">DL Branch:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">branch</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label46">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">DL Domain:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">domain</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label47">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">DL State:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">state</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="team">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="module">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="branch">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="domain">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="state">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Damned Lies Info</property>
+ </object>
+ <packing>
+ <property name="position">3</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/gtr-header.c b/src/gtr-header.c
index 6981802a..d42ea5ee 100644
--- a/src/gtr-header.c
+++ b/src/gtr-header.c
@@ -521,6 +521,113 @@ gtr_header_set_encoding (GtrHeader * header, const gchar * encoding)
gtr_header_set_field (header, "Content-Transfer-Encoding", encoding);
}
+void
+gtr_header_set_dl_info (GtrHeader * header,
+ const gchar * team,
+ const gchar * module_name,
+ const gchar * branch,
+ const gchar * domain)
+{
+
+ g_return_if_fail (GTR_IS_HEADER (header));
+
+ gtr_header_set_field (header, "X-DL-Team", team);
+ gtr_header_set_field (header, "X-DL-Module", module_name);
+ gtr_header_set_field (header, "X-DL-Branch", branch);
+ gtr_header_set_field (header, "X-DL-Domain", domain);
+
+}
+
+/**
+ * gtr_header_get_dl_team:
+ * @header: a #GtrHeader
+ *
+ * Gets the damned lies team of the header
+ *
+ * Return value: (transfer full): a newly allocated string representing the
+ * damned lies team of the header
+ */
+gchar *
+gtr_header_get_dl_team (GtrHeader * header)
+{
+ g_return_val_if_fail (GTR_IS_HEADER (header), NULL);
+
+ return po_header_field (gtr_msg_get_msgstr (GTR_MSG (header)),
+ "X-DL-Team");
+}
+
+/**
+ * gtr_header_get_dl_module:
+ * @header: a #GtrHeader
+ *
+ * Gets the damned lies module of the header
+ *
+ * Return value: (transfer full): a newly allocated string representing the
+ * damned lies module of the header
+ */
+gchar *
+gtr_header_get_dl_module (GtrHeader * header)
+{
+ g_return_val_if_fail (GTR_IS_HEADER (header), NULL);
+
+ return po_header_field (gtr_msg_get_msgstr (GTR_MSG (header)),
+ "X-DL-Module");
+}
+
+/**
+ * gtr_header_get_dl_branch:
+ * @header: a #GtrHeader
+ *
+ * Gets the damned lies branch of the header
+ *
+ * Return value: (transfer full): a newly allocated string representing the
+ * damned lies branch of the header
+ */
+gchar *
+gtr_header_get_dl_branch (GtrHeader * header)
+{
+ g_return_val_if_fail (GTR_IS_HEADER (header), NULL);
+
+ return po_header_field (gtr_msg_get_msgstr (GTR_MSG (header)),
+ "X-DL-Branch");
+}
+
+/**
+ * gtr_header_get_dl_domain:
+ * @header: a #GtrHeader
+ *
+ * Gets the damned lies domain of the header
+ *
+ * Return value: (transfer full): a newly allocated string representing the
+ * damned lies domain of the header
+ */
+gchar *
+gtr_header_get_dl_domain (GtrHeader * header)
+{
+ g_return_val_if_fail (GTR_IS_HEADER (header), NULL);
+
+ return po_header_field (gtr_msg_get_msgstr (GTR_MSG (header)),
+ "X-DL-Domain");
+}
+
+/**
+ * gtr_header_get_dl_state:
+ * @header: a #GtrHeader
+ *
+ * Gets the damned lies module state of the header
+ *
+ * Return value: (transfer full): a newly allocated string representing the
+ * damned lies module state of the header
+ */
+gchar *
+gtr_header_get_dl_state (GtrHeader * header)
+{
+ g_return_val_if_fail (GTR_IS_HEADER (header), NULL);
+
+ return po_header_field (gtr_msg_get_msgstr (GTR_MSG (header)),
+ "X-DL-State");
+}
+
/**
* gtr_header_get_plural_forms:
* @header: a #GtrHeader.
diff --git a/src/gtr-header.h b/src/gtr-header.h
index b5132848..47d29559 100644
--- a/src/gtr-header.h
+++ b/src/gtr-header.h
@@ -115,6 +115,18 @@ GtrProfile *gtr_header_get_profile (GtrHeader *header);
gchar *gtr_header_get_language_code (GtrHeader * header);
+gchar *gtr_header_get_dl_team (GtrHeader * header);
+gchar *gtr_header_get_dl_module (GtrHeader * header);
+gchar *gtr_header_get_dl_branch (GtrHeader * header);
+gchar *gtr_header_get_dl_domain (GtrHeader * header);
+gchar *gtr_header_get_dl_state (GtrHeader * header);
+
+void gtr_header_set_dl_info (GtrHeader * header,
+ const gchar * team,
+ const gchar * module_name,
+ const gchar * branch,
+ const gchar * domain);
+
G_END_DECLS
#endif /* __HEADER_H__ */
diff --git a/src/gtr-po.c b/src/gtr-po.c
index af16be20..1d3941f5 100644
--- a/src/gtr-po.c
+++ b/src/gtr-po.c
@@ -94,19 +94,19 @@ typedef struct
GtrPoState state;
/* Damned Lies(DL) teams are stored here */
- const char *dl_team;
+ gchar *dl_team;
/* DL modules */
- const char *dl_module;
+ gchar *dl_module;
/* DL branches */
- const char *dl_branch;
+ gchar *dl_branch;
/* DL domains */
- const char *dl_domain;
+ gchar *dl_domain;
/* The state of a DL module */
- const char *dl_state;
+ gchar *dl_state;
/* Marks if the file was changed; */
guint file_changed : 1;
@@ -216,6 +216,11 @@ gtr_po_init (GtrPo * po)
priv->location = NULL;
priv->gettext_po_file = NULL;
+ priv->dl_team = NULL;
+ priv->dl_module = NULL;
+ priv->dl_branch = NULL;
+ priv->dl_domain = NULL;
+ priv->dl_state = NULL;
}
static void
@@ -231,6 +236,17 @@ gtr_po_finalize (GObject * object)
if (priv->gettext_po_file)
po_file_free (priv->gettext_po_file);
+ if (priv->dl_team)
+ g_free (priv->dl_team);
+ if (priv->dl_module)
+ g_free (priv->dl_module);
+ if (priv->dl_branch)
+ g_free (priv->dl_branch);
+ if (priv->dl_domain)
+ g_free (priv->dl_domain);
+ if (priv->dl_state)
+ g_free (priv->dl_state);
+
G_OBJECT_CLASS (gtr_po_parent_class)->finalize (object);
}
@@ -942,21 +958,21 @@ gtr_po_set_state (GtrPo * po, GtrPoState state)
g_object_notify (G_OBJECT (po), "state");
}
-void gtr_po_set_dl_info(GtrPo * po, const char * team, const char * module_name,
- const char * branch, const char * domain, const char * module_state)
+void gtr_po_set_dl_info (GtrPo * po, gchar * team, gchar * module_name,
+ gchar * branch, gchar * domain, gchar * module_state)
{
- GtrPoPrivate *priv = gtr_po_get_instance_private(po);
+ GtrPoPrivate *priv = gtr_po_get_instance_private (po);
priv->dl_team = g_strdup (team);
priv->dl_module = g_strdup (module_name);
priv->dl_branch = g_strdup (branch);
priv->dl_domain = g_strdup (domain);
priv->dl_state = g_strdup (module_state);
- gtr_header_set_field(priv->header, "X-DL-Team", team);
- gtr_header_set_field(priv->header, "X-DL-Module", module_name);
- gtr_header_set_field(priv->header, "X-DL-Branch", branch);
- gtr_header_set_field(priv->header, "X-DL-Domain", domain);
- gtr_header_set_field(priv->header, "X-DL-State", module_state);
+ gtr_header_set_field (priv->header, "X-DL-Team", team);
+ gtr_header_set_field (priv->header, "X-DL-Module", module_name);
+ gtr_header_set_field (priv->header, "X-DL-Branch", branch);
+ gtr_header_set_field (priv->header, "X-DL-Domain", domain);
+ gtr_header_set_field (priv->header, "X-DL-State", module_state);
}
/*
* FIXME: We are not using this func.
diff --git a/src/gtr-po.h b/src/gtr-po.h
index b92661cd..2f5a9e4d 100644
--- a/src/gtr-po.h
+++ b/src/gtr-po.h
@@ -104,8 +104,8 @@ gtr_po_get_type (void)
void gtr_po_set_state (GtrPo * po, GtrPoState state);
- void gtr_po_set_dl_info(GtrPo *po, const char *team, const char *module_name,
- const char *branch, const char *domain, const char *module_state);
+ void gtr_po_set_dl_info (GtrPo * po, gchar * team, gchar * module_name,
+ gchar * branch, gchar * domain, gchar * module_state);
GFile *gtr_po_get_location (GtrPo * po);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]