[gtranslator] Progress widget to show the percentage translated
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Progress widget to show the percentage translated
- Date: Wed, 12 Sep 2018 11:54:36 +0000 (UTC)
commit 5b3e11ddc76030c3a70414565faa9e87d886cd07
Author: Daniel GarcĂa Moreno <danigm wadobo com>
Date: Tue Sep 11 11:54:56 2018 +0200
Progress widget to show the percentage translated
This new widget shows a progress circle, copied from the nautilus copy
file progress button. The circle show in blue the translated messages
and in orange the fuzzy messages and when you click in the button a
popover is shown with the real numbers of translated messages.
src/gtr-notebook.c | 45 +++++++++
src/gtr-notebook.h | 2 +
src/gtr-notebook.ui | 100 ++++++++++++++++++-
src/gtr-progress.c | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gtr-progress.h | 39 ++++++++
src/gtr-window.c | 3 +
src/meson.build | 1 +
7 files changed, 461 insertions(+), 1 deletion(-)
---
diff --git a/src/gtr-notebook.c b/src/gtr-notebook.c
index 18d40940..bb1af634 100644
--- a/src/gtr-notebook.c
+++ b/src/gtr-notebook.c
@@ -24,6 +24,7 @@
#include "gtr-tab.h"
#include "gtr-tab-label.h"
#include "gtr-debug.h"
+#include "gtr-progress.h"
#include <glib.h>
#include <glib-object.h>
@@ -33,6 +34,12 @@
typedef struct
{
GtkWidget *titlebar;
+ GtkWidget *progress_button;
+ GtkWidget *progress_percentage;
+ GtkWidget *progress_trans;
+ GtkWidget *progress_fuzzy;
+ GtkWidget *progress_untrans;
+ GtrProgress *progress;
} GtrNotebookPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GtrNotebook, gtr_notebook, GTK_TYPE_NOTEBOOK)
@@ -105,7 +112,12 @@ update_tabs_visibility (GtrNotebook *nb)
static void
gtr_notebook_init (GtrNotebook * notebook)
{
+ GtrNotebookPrivate *priv = gtr_notebook_get_instance_private (notebook);
gtk_widget_init_template (GTK_WIDGET (notebook));
+
+ priv->progress = gtr_progress_new ();
+ gtk_widget_show (GTK_WIDGET (priv->progress));
+ gtk_container_add (GTK_CONTAINER (priv->progress_button), GTK_WIDGET (priv->progress));
}
static void
@@ -135,6 +147,11 @@ gtr_notebook_class_init (GtrNotebookClass * klass)
"/org/gnome/translator/gtr-notebook.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, titlebar);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_trans);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_fuzzy);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_untrans);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_percentage);
}
/***************************** Public funcs ***********************************/
@@ -245,3 +262,31 @@ gtr_notebook_get_header (GtrNotebook *notebook)
GtrNotebookPrivate *priv = gtr_notebook_get_instance_private (notebook);
return priv->titlebar;
}
+
+void
+gtr_notebook_set_progress (GtrNotebook *notebook,
+ gint trans,
+ gint untrans,
+ gint fuzzy)
+{
+ GtrNotebookPrivate *priv = gtr_notebook_get_instance_private (notebook);
+ gchar *percentage, *trans_text, *fuzzy_text, *untrans_text;
+
+ gtr_progress_set (priv->progress, trans, untrans, fuzzy);
+
+ percentage = g_strdup_printf (_("Translated: %0.2f%%"), (float)trans * 100 / (float)(trans + untrans +
fuzzy));
+ trans_text = g_strdup_printf (_("Translated: %d"), trans);
+ untrans_text = g_strdup_printf (_("Untranslated: %d"), untrans);
+ fuzzy_text = g_strdup_printf (_("Fuzzy: %d"), fuzzy);
+
+ gtk_label_set_text (GTK_LABEL (priv->progress_percentage), percentage);
+ gtk_label_set_text (GTK_LABEL (priv->progress_fuzzy), fuzzy_text);
+ gtk_label_set_text (GTK_LABEL (priv->progress_untrans), untrans_text);
+ gtk_label_set_text (GTK_LABEL (priv->progress_trans), trans_text);
+
+ g_free (percentage);
+ g_free (trans_text);
+ g_free (fuzzy_text);
+ g_free (untrans_text);
+}
+
diff --git a/src/gtr-notebook.h b/src/gtr-notebook.h
index 8d569f1f..3d199092 100644
--- a/src/gtr-notebook.h
+++ b/src/gtr-notebook.h
@@ -75,5 +75,7 @@ GtrTab *gtr_notebook_get_page (GtrNotebook * notebook);
GtkWidget *gtr_notebook_get_header (GtrNotebook *notebook);
+void gtr_notebook_set_progress (GtrNotebook *notebook, gint trans, gint untrans, gint fuzzy);
+
G_END_DECLS
#endif /* __NOTEBOOK_H__ */
diff --git a/src/gtr-notebook.ui b/src/gtr-notebook.ui
index 40fa4208..8dd83dca 100644
--- a/src/gtr-notebook.ui
+++ b/src/gtr-notebook.ui
@@ -93,6 +93,84 @@
</packing>
</child>
</object>
+ <object class="GtkPopover" id="progress_popover">
+ <property name="can_focus">False</property>
+ <property name="position">bottom</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">6</property>
+ <property name="margin_right">6</property>
+ <property name="margin_top">6</property>
+ <property name="margin_bottom">6</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="progress_percentage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">translated: 0.00%</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparator">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="progress_untrans">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">fuzzy: 0</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="progress_fuzzy">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">untranslated: 0</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="progress_trans">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Translated: 0</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
<object class="GtkHeaderBar" id="titlebar">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -318,7 +396,7 @@
</child>
<child internal-child="accessible">
<object class="AtkObject" id="main_menu-atkobject">
- <property name="AtkObject::accessible-name" translatable="yes">Room Menu</property>
+ <property name="AtkObject::accessible-name" translatable="yes">Main Menu</property>
</object>
</child>
</object>
@@ -327,6 +405,26 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkMenuButton" id="progress_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="popover">progress_popover</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="progress_button-atkobject">
+ <property name="AtkObject::accessible-name" translatable="yes">Progress button</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ <property name="position">6</property>
+ </packing>
+ </child>
<child>
<object class="GtkButtonBox">
<property name="visible">True</property>
diff --git a/src/gtr-progress.c b/src/gtr-progress.c
new file mode 100644
index 00000000..710daf9e
--- /dev/null
+++ b/src/gtr-progress.c
@@ -0,0 +1,272 @@
+/*
+ * Copyright (C) 2018 Daniel Garcia Moreno <danigm gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gtr-progress.h"
+
+#include <glib/gi18n.h>
+
+typedef struct
+{
+ gint trans;
+ gint untrans;
+ gint fuzzy;
+} GtrProgressPrivate;
+
+struct _GtrProgress
+{
+ GtkDrawingArea parent_instance;
+};
+
+enum
+{
+ PROP_TRANS,
+ PROP_UNTRANS,
+ PROP_FUZZY,
+ N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL, };
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtrProgress, gtr_progress, GTK_TYPE_DRAWING_AREA)
+
+static void
+gtr_progress_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (gtr_progress_parent_class)->dispose (object);
+}
+
+static void
+gtr_progress_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gtr_progress_parent_class)->finalize (object);
+}
+
+static void
+gtr_progress_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtrProgressPrivate *priv = gtr_progress_get_instance_private (GTR_PROGRESS (object));
+
+ switch (prop_id) {
+ case PROP_TRANS:
+ priv->trans = g_value_get_int (value);
+ break;
+ case PROP_UNTRANS:
+ priv->untrans = g_value_get_int (value);
+ break;
+ case PROP_FUZZY:
+ priv->fuzzy = g_value_get_int (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtr_progress_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtrProgressPrivate *priv = gtr_progress_get_instance_private (GTR_PROGRESS (object));
+
+ switch (prop_id) {
+ case PROP_TRANS:
+ g_value_set_int (value, priv->trans);
+ break;
+ case PROP_UNTRANS:
+ g_value_set_int (value, priv->untrans);
+ break;
+ case PROP_FUZZY:
+ g_value_set_int (value, priv->fuzzy);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+on_draw (GtkWidget *widget,
+ cairo_t *cr,
+ gpointer data)
+{
+ GtrProgressPrivate *priv = gtr_progress_get_instance_private (GTR_PROGRESS (widget));
+
+ gdouble ratio, ratio_fuzzy;
+ guint width;
+ guint height;
+ GdkRGBA background;
+ GdkRGBA foreground;
+ GdkRGBA fuzzy_color;
+ GtkStyleContext *style_context;
+ gfloat percentage = 0.0;
+ gint total = priv->trans + priv->untrans + priv->fuzzy;
+
+ style_context = gtk_widget_get_style_context (widget);
+ gtk_style_context_lookup_color (style_context, "theme_selected_bg_color", &foreground);
+ gtk_style_context_lookup_color (style_context, "warning_color", &fuzzy_color);
+ gtk_style_context_get_color (style_context, gtk_widget_get_state_flags (widget), &background);
+ background.alpha *= 0.3;
+
+ percentage = (float) (priv->trans * 100) / (float) total;
+ ratio = percentage / 100.0;
+
+ percentage = (float) (priv->fuzzy * 100) / (float) total;
+ ratio_fuzzy = percentage / 100.0;
+
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+
+ gdk_cairo_set_source_rgba (cr, &background);
+ cairo_arc (cr,
+ width / 2.0, height / 2.0,
+ MIN (width, height) / 2.0,
+ 0, 2 * G_PI);
+ cairo_fill (cr);
+
+ cairo_move_to (cr, width / 2.0, height / 2.0);
+ gdk_cairo_set_source_rgba (cr, &foreground);
+ cairo_arc (cr,
+ width / 2.0, height / 2.0,
+ MIN (width, height) / 2.0,
+ -G_PI / 2.0, ratio * 2 * G_PI - G_PI / 2.0);
+ cairo_fill (cr);
+
+ cairo_move_to (cr, width / 2.0, height / 2.0);
+ gdk_cairo_set_source_rgba (cr, &fuzzy_color);
+ cairo_arc (cr,
+ width / 2.0, height / 2.0,
+ MIN (width, height) / 2.0,
+ ratio * 2 * G_PI - G_PI / 2.0,
+ (ratio + ratio_fuzzy) * 2 * G_PI - G_PI / 2.0);
+
+ cairo_fill (cr);
+}
+
+static void
+gtr_progress_class_init (GtrProgressClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gtr_progress_finalize;
+ object_class->dispose = gtr_progress_dispose;
+ object_class->set_property = gtr_progress_set_property;
+ object_class->get_property = gtr_progress_get_property;
+
+ properties[PROP_TRANS] =
+ g_param_spec_int ("translated",
+ "Translated",
+ "Translated messages",
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+ properties[PROP_UNTRANS] =
+ g_param_spec_int ("untranslated",
+ "Untranslated",
+ "Untranslated messages",
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+ properties[PROP_FUZZY] =
+ g_param_spec_int ("fuzzy",
+ "Fuzzy",
+ "Fuzzy messages",
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+static void
+gtr_progress_init (GtrProgress *self)
+{
+ GtrProgressPrivate *priv = gtr_progress_get_instance_private (self);
+ priv->trans = 0;
+ priv->untrans = 0;
+ priv->fuzzy = 0;
+
+ gtk_widget_set_size_request (GTK_WIDGET (self), 16, 16);
+ g_signal_connect (G_OBJECT (self), "draw",
+ G_CALLBACK (on_draw), NULL);
+}
+
+GtrProgress*
+gtr_progress_new () {
+ GtrProgress *self = g_object_new (GTR_TYPE_PROGRESS, NULL);
+ return self;
+}
+
+void
+gtr_progress_set (GtrProgress *self,
+ gint trans,
+ gint untrans,
+ gint fuzzy)
+{
+ GtrProgressPrivate *priv = gtr_progress_get_instance_private (self);
+ if (trans != priv->trans)
+ {
+ priv->trans = trans;
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TRANS]);
+ }
+ if (untrans != priv->untrans)
+ {
+ priv->untrans = untrans;
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_UNTRANS]);
+ }
+ if (fuzzy != priv->fuzzy)
+ {
+ priv->fuzzy = fuzzy;
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FUZZY]);
+ }
+
+ gtk_widget_queue_draw (self);
+}
+
+gint
+gtr_progress_get_trans (GtrProgress *self)
+{
+ GtrProgressPrivate *priv = gtr_progress_get_instance_private (self);
+ return priv->trans;
+}
+
+gint
+gtr_progress_get_untrans (GtrProgress *self)
+{
+ GtrProgressPrivate *priv = gtr_progress_get_instance_private (self);
+ return priv->untrans;
+}
+
+gint
+gtr_progress_get_fuzzy (GtrProgress *self)
+{
+ GtrProgressPrivate *priv = gtr_progress_get_instance_private (self);
+ return priv->fuzzy;
+}
+
diff --git a/src/gtr-progress.h b/src/gtr-progress.h
new file mode 100644
index 00000000..b269dd71
--- /dev/null
+++ b/src/gtr-progress.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2018 Daniel Garcia Moreno <danigm gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTR_TYPE_PROGRESS (gtr_progress_get_type())
+
+G_DECLARE_FINAL_TYPE (GtrProgress, gtr_progress, GTR, PROGRESS, GtkDrawingArea)
+
+GtrProgress* gtr_progress_new ();
+void gtr_progress_set (GtrProgress *self,
+ gint trans,
+ gint untrans,
+ gint fuzzy);
+gint gtr_progress_get_trans (GtrProgress *self);
+gint gtr_progress_get_untrans (GtrProgress *self);
+gint gtr_progress_get_fuzzy (GtrProgress *self);
+
+G_END_DECLS
+
diff --git a/src/gtr-window.c b/src/gtr-window.c
index d1787beb..7bb97591 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -135,6 +135,9 @@ gtr_window_update_statusbar_message_count (GtrTab * tab,
untranslated = gtr_po_get_untranslated_count (po);
status = NULL;
+ gtr_notebook_set_progress (GTR_NOTEBOOK (priv->notebook),
+ translated, untranslated, fuzzy);
+
switch (gtr_msg_get_status (message))
{
case GTR_MSG_STATUS_UNTRANSLATED:
diff --git a/src/meson.build b/src/meson.build
index f500d6b6..5401513a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -51,6 +51,7 @@ sources = files(
'gtr-utils.c',
'gtr-view.c',
'gtr-projects.c',
+ 'gtr-progress.c',
'gtr-window.c'
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]