[gtranslator] Some cleanup on GtrMsg
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Some cleanup on GtrMsg
- Date: Fri, 6 Apr 2012 21:48:34 +0000 (UTC)
commit 19869f98994dfb43c0f9e6f739023397382d1742
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Fri Apr 6 23:51:11 2012 +0200
Some cleanup on GtrMsg
src/gtr-header.c | 4 +-
src/gtr-message-table.c | 9 ++--
src/gtr-msg.c | 112 +++++++++-----------------------------------
src/gtr-msg.h | 117 +++++++++++++++++++++-------------------------
src/gtr-po.c | 2 +-
5 files changed, 83 insertions(+), 161 deletions(-)
---
diff --git a/src/gtr-header.c b/src/gtr-header.c
index e52f519..130626e 100644
--- a/src/gtr-header.c
+++ b/src/gtr-header.c
@@ -223,7 +223,7 @@ gtr_header_get_comments (GtrHeader * header)
{
g_return_val_if_fail (GTR_IS_HEADER (header), NULL);
- return po_message_comments (gtr_msg_get_message (GTR_MSG (header)));
+ return po_message_comments (_gtr_msg_get_message (GTR_MSG (header)));
}
void
@@ -232,7 +232,7 @@ gtr_header_set_comments (GtrHeader * header, const gchar * comments)
g_return_if_fail (GTR_IS_HEADER (header));
g_return_if_fail (comments != NULL);
- po_message_set_comments (gtr_msg_get_message (GTR_MSG (header)), comments);
+ po_message_set_comments (_gtr_msg_get_message (GTR_MSG (header)), comments);
}
gchar *
diff --git a/src/gtr-message-table.c b/src/gtr-message-table.c
index 0553720..7841028 100644
--- a/src/gtr-message-table.c
+++ b/src/gtr-message-table.c
@@ -60,10 +60,9 @@ showed_message_cb (GtrTab * tab, GtrMsg * msg, GtrMessageTable * table)
GtkTreeSelection *selection;
GtkTreeIter iter;
- selection =
- gtk_tree_view_get_selection (GTK_TREE_VIEW (table->priv->treeview));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (table->priv->treeview));
- path = gtk_tree_row_reference_get_path (gtr_msg_get_row_reference (msg));
+ path = gtk_tree_row_reference_get_path (_gtr_msg_get_row_reference (msg));
gtk_tree_model_get_iter (table->priv->sort_model, &iter, path);
@@ -112,7 +111,7 @@ message_changed_cb (GtrTab * tab, GtrMsg * msg, GtrMessageTable * table)
GtkTreePath *sort_path, *path;
GtkTreeRowReference *row;
- row = gtr_msg_get_row_reference (msg);
+ row = _gtr_msg_get_row_reference (msg);
sort_path = gtk_tree_row_reference_get_path (row);
path =
@@ -434,7 +433,7 @@ gtr_message_table_populate (GtrMessageTable * table, GList * messages)
row = gtk_tree_row_reference_new (table->priv->sort_model, path);
gtk_tree_path_free (path);
- gtr_msg_set_row_reference (GTR_MSG (messages->data), row);
+ _gtr_msg_set_row_reference (GTR_MSG (messages->data), row);
messages = g_list_next (messages);
}
diff --git a/src/gtr-msg.c b/src/gtr-msg.c
index 88d8267..1f6a1e6 100644
--- a/src/gtr-msg.c
+++ b/src/gtr-msg.c
@@ -53,58 +53,9 @@ struct _GtrMsgPrivate
gint po_position;
};
-enum
-{
- PROP_0,
- PROP_GETTEXT_ITER,
- PROP_GETTEXT_MSG
-};
-
static gchar *message_error = NULL;
static void
-gtr_msg_set_property (GObject * object,
- guint prop_id,
- const GValue * value,
- GParamSpec * pspec)
-{
- GtrMsg *msg = GTR_MSG (object);
-
- switch (prop_id)
- {
- case PROP_GETTEXT_ITER:
- gtr_msg_set_iterator (msg, g_value_get_pointer (value));
- break;
- case PROP_GETTEXT_MSG:
- gtr_msg_set_message (msg, g_value_get_pointer (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtr_msg_get_property (GObject * object,
- guint prop_id, GValue * value, GParamSpec * pspec)
-{
- GtrMsg *msg = GTR_MSG (object);
-
- switch (prop_id)
- {
- case PROP_GETTEXT_ITER:
- g_value_set_pointer (value, gtr_msg_get_iterator (msg));
- break;
- case PROP_GETTEXT_MSG:
- g_value_set_pointer (value, gtr_msg_get_message (msg));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
gtr_msg_init (GtrMsg * msg)
{
msg->priv = GTR_MSG_GET_PRIVATE (msg);
@@ -124,22 +75,6 @@ gtr_msg_class_init (GtrMsgClass * klass)
g_type_class_add_private (klass, sizeof (GtrMsgPrivate));
object_class->finalize = gtr_msg_finalize;
- object_class->set_property = gtr_msg_set_property;
- object_class->get_property = gtr_msg_get_property;
-
- g_object_class_install_property (object_class,
- PROP_GETTEXT_MSG,
- g_param_spec_pointer ("gettext-iter",
- "Gettext iterator",
- "The po_message_iterator_t pointer",
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_GETTEXT_MSG,
- g_param_spec_pointer ("gettext-msg",
- "Gettext msg",
- "The po_message_t pointer",
- G_PARAM_READWRITE));
}
/***************************** Public funcs ***********************************/
@@ -154,7 +89,7 @@ gtr_msg_class_init (GtrMsgClass * klass)
* Return value: (transfer full): a new #GtrMsg object
**/
GtrMsg *
-gtr_msg_new (po_message_iterator_t iter, po_message_t message)
+_gtr_msg_new (po_message_iterator_t iter, po_message_t message)
{
GtrMsg *msg;
@@ -162,8 +97,8 @@ gtr_msg_new (po_message_iterator_t iter, po_message_t message)
msg = g_object_new (GTR_TYPE_MSG, NULL);
- gtr_msg_set_iterator (msg, iter);
- gtr_msg_set_message (msg, message);
+ _gtr_msg_set_iterator (msg, iter);
+ _gtr_msg_set_message (msg, message);
/* Set the status */
if (gtr_msg_is_fuzzy (msg))
@@ -183,7 +118,7 @@ gtr_msg_new (po_message_iterator_t iter, po_message_t message)
* Return value: the message iterator in gettext format
**/
po_message_iterator_t
-gtr_msg_get_iterator (GtrMsg * msg)
+_gtr_msg_get_iterator (GtrMsg * msg)
{
g_return_val_if_fail (GTR_IS_MSG (msg), NULL);
@@ -198,13 +133,11 @@ gtr_msg_get_iterator (GtrMsg * msg)
* Sets the iterator into the #GtrMsg class.
**/
void
-gtr_msg_set_iterator (GtrMsg * msg, po_message_iterator_t iter)
+_gtr_msg_set_iterator (GtrMsg * msg, po_message_iterator_t iter)
{
g_return_if_fail (GTR_IS_MSG (msg));
msg->priv->iterator = iter;
-
- g_object_notify (G_OBJECT (msg), "gettext-iter");
}
/**
@@ -214,7 +147,7 @@ gtr_msg_set_iterator (GtrMsg * msg, po_message_iterator_t iter)
* Return value: the message in gettext format
**/
po_message_t
-gtr_msg_get_message (GtrMsg * msg)
+_gtr_msg_get_message (GtrMsg * msg)
{
g_return_val_if_fail (GTR_IS_MSG (msg), NULL);
@@ -229,14 +162,12 @@ gtr_msg_get_message (GtrMsg * msg)
* Sets the message into the #GtrMsg class.
**/
void
-gtr_msg_set_message (GtrMsg * msg, po_message_t message)
+_gtr_msg_set_message (GtrMsg * msg, po_message_t message)
{
g_return_if_fail (GTR_IS_MSG (msg));
g_return_if_fail (message != NULL);
msg->priv->message = message;
-
- g_object_notify (G_OBJECT (msg), "gettext-msg");
}
/**
@@ -247,7 +178,7 @@ gtr_msg_set_message (GtrMsg * msg, po_message_t message)
* in the message table
*/
GtkTreeRowReference *
-gtr_msg_get_row_reference (GtrMsg * msg)
+_gtr_msg_get_row_reference (GtrMsg * msg)
{
g_return_val_if_fail (GTR_IS_MSG (msg), NULL);
@@ -255,14 +186,14 @@ gtr_msg_get_row_reference (GtrMsg * msg)
}
/**
- * gtr_msg_set_row_reference:
+ * _gtr_msg_set_row_reference:
* @msg: a #GtrMsg
* @row_reference: the GtkTreeRowReference corresponding to position in the message table
*
* Sets the GtkTreeRowReference from the messages table for the given message
**/
void
-gtr_msg_set_row_reference (GtrMsg * msg, GtkTreeRowReference * row_reference)
+_gtr_msg_set_row_reference (GtrMsg * msg, GtkTreeRowReference * row_reference)
{
g_return_if_fail (GTR_IS_MSG (msg));
@@ -270,29 +201,32 @@ gtr_msg_set_row_reference (GtrMsg * msg, GtkTreeRowReference * row_reference)
}
/**
- * po_message_is_translated:
+ * gtr_msg_is_translated:
* @msg: a #GtrMsg
- *
- * Return value: TRUE if the message is translated
+ *
+ * Gets whether or not the message is translated. See that a fuzzy message
+ * is also counted as translated so it must be checked first that the message
+ * is fuzzy.
+ *
+ * Return value: %TRUE if the message is translated
**/
gboolean
-gtr_msg_is_translated (GtrMsg * msg)
+gtr_msg_is_translated (GtrMsg *msg)
{
g_return_val_if_fail (GTR_IS_MSG (msg), FALSE);
- if (po_message_msgid_plural (msg->priv->message) == NULL)
- return po_message_msgstr (msg->priv->message)[0] != '\0';
+ if (gtr_msg_get_msgid_plural (msg) == NULL)
+ return gtr_msg_get_msgstr (msg)[0] != '\0';
else
{
gint i;
for (i = 0;; i++)
{
- const gchar *str_i =
- po_message_msgstr_plural (msg->priv->message, i);
- if (str_i == NULL)
+ const gchar *msgstr_i = gtr_msg_get_msgstr_plural (msg, i);
+ if (msgstr_i == NULL)
break;
- if (str_i[0] == '\0')
+ if (msgstr_i[0] == '\0')
return FALSE;
}
diff --git a/src/gtr-msg.h b/src/gtr-msg.h
index fa2d03c..e06fe0d 100644
--- a/src/gtr-msg.h
+++ b/src/gtr-msg.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Ignacio Casal Quinteiro <nacho resa gmail com>
+ * Copyright (C) 2007-2012 Ignacio Casal Quinteiro <icq gnome org>
* 2008 Igalia
*
* This program is free software: you can redistribute it and/or modify
@@ -20,8 +20,8 @@
* Pablo Sanxiao <psanxiao gmail com>
*/
-#ifndef __MSG_H__
-#define __MSG_H__
+#ifndef __GTR_MSG_H__
+#define __GTR_MSG_H__
#include <glib.h>
#include <glib-object.h>
@@ -29,22 +29,17 @@
#include <gettext-po.h>
G_BEGIN_DECLS
-/*
- * Type checking and casting macros
- */
+
#define GTR_TYPE_MSG (gtr_msg_get_type ())
#define GTR_MSG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTR_TYPE_MSG, GtrMsg))
#define GTR_MSG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GTR_TYPE_MSG, GtrMsgClass))
#define GTR_IS_MSG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTR_TYPE_MSG))
#define GTR_IS_MSG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTR_TYPE_MSG))
#define GTR_MSG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTR_TYPE_MSG, GtrMsgClass))
-/* Private structure type */
-typedef struct _GtrMsgPrivate GtrMsgPrivate;
-/*
- * Main object structure
- */
-typedef struct _GtrMsg GtrMsg;
+typedef struct _GtrMsg GtrMsg;
+typedef struct _GtrMsgClass GtrMsgClass;
+typedef struct _GtrMsgPrivate GtrMsgPrivate;
struct _GtrMsg
{
@@ -54,11 +49,6 @@ struct _GtrMsg
GtrMsgPrivate *priv;
};
-/*
- * Class definition
- */
-typedef struct _GtrMsgClass GtrMsgClass;
-
struct _GtrMsgClass
{
GObjectClass parent_class;
@@ -71,73 +61,72 @@ typedef enum
GTR_MSG_STATUS_TRANSLATED
} GtrMsgStatus;
-/*
- * Public methods
- */
-GType
-gtr_msg_get_type (void)
- G_GNUC_CONST;
-
- GType gtr_msg_register_type (GTypeModule * module);
-
- GtrMsg *gtr_msg_new (po_message_iterator_t iter, po_message_t message);
-
-po_message_iterator_t
-gtr_msg_get_iterator (GtrMsg * msg);
-
- void gtr_msg_set_iterator (GtrMsg * msg, po_message_iterator_t iter);
-
- po_message_t gtr_msg_get_message (GtrMsg * msg);
-
- void gtr_msg_set_message (GtrMsg * msg, po_message_t message);
-
- GtkTreeRowReference *gtr_msg_get_row_reference (GtrMsg * msg);
-
- void gtr_msg_set_row_reference (GtrMsg * msg,
- GtkTreeRowReference * row_reference);
+/* Public methods */
+GType gtr_msg_get_type (void) G_GNUC_CONST;
- gboolean gtr_msg_is_translated (GtrMsg * msg);
+gboolean gtr_msg_is_translated (GtrMsg *msg);
- gboolean gtr_msg_is_fuzzy (GtrMsg * msg);
+gboolean gtr_msg_is_fuzzy (GtrMsg *msg);
+void gtr_msg_set_fuzzy (GtrMsg *msg,
+ gboolean fuzzy);
- void gtr_msg_set_fuzzy (GtrMsg * msg, gboolean fuzzy);
+GtrMsgStatus gtr_msg_get_status (GtrMsg *msg);
+void gtr_msg_set_status (GtrMsg *msg,
+ GtrMsgStatus status);
- void gtr_msg_set_status (GtrMsg * msg, GtrMsgStatus status);
+const gchar *gtr_msg_get_msgid (GtrMsg *msg);
- GtrMsgStatus gtr_msg_get_status (GtrMsg * msg);
+const gchar *gtr_msg_get_msgid_plural (GtrMsg *msg);
- const gchar *gtr_msg_get_msgid (GtrMsg * msg);
+const gchar *gtr_msg_get_msgstr (GtrMsg *msg);
+void gtr_msg_set_msgstr (GtrMsg *msg,
+ const gchar *msgstr);
- const gchar *gtr_msg_get_msgid_plural (GtrMsg * msg);
+const gchar *gtr_msg_get_msgstr_plural (GtrMsg *msg,
+ gint index);
+void gtr_msg_set_msgstr_plural (GtrMsg *msg,
+ gint index,
+ const gchar *msgstr);
- const gchar *gtr_msg_get_msgstr (GtrMsg * msg);
+const gchar *gtr_msg_get_comment (GtrMsg *msg);
+void gtr_msg_set_comment (GtrMsg *msg,
+ const gchar *comment);
- void gtr_msg_set_msgstr (GtrMsg * msg, const gchar * msgstr);
+gint gtr_msg_get_po_position (GtrMsg *msg);
+void gtr_msg_set_po_position (GtrMsg *msg,
+ gint po_position);
- const gchar *gtr_msg_get_msgstr_plural (GtrMsg * msg, gint index);
+const gchar *gtr_msg_get_extracted_comments (GtrMsg *msg);
- void gtr_msg_set_msgstr_plural (GtrMsg * msg,
- gint index, const gchar * msgstr);
+const gchar *gtr_msg_get_filename (GtrMsg *msg,
+ gint i);
- const gchar *gtr_msg_get_comment (GtrMsg * msg);
+gint *gtr_msg_get_file_line (GtrMsg *msg,
+ gint i);
- void gtr_msg_set_comment (GtrMsg * msg, const gchar * comment);
+const gchar *gtr_msg_get_msgctxt (GtrMsg *msg);
- gint gtr_msg_get_po_position (GtrMsg * msg);
+const gchar *gtr_msg_get_format (GtrMsg *msg);
- void gtr_msg_set_po_position (GtrMsg * msg, gint po_position);
+gchar *gtr_msg_check (GtrMsg *msg);
- const gchar *gtr_msg_get_extracted_comments (GtrMsg * msg);
+/* Semi-private methods */
+GtrMsg *_gtr_msg_new (po_message_iterator_t iter,
+ po_message_t message);
- const gchar *gtr_msg_get_filename (GtrMsg * msg, gint i);
+po_message_iterator_t _gtr_msg_get_iterator (GtrMsg *msg);
+void _gtr_msg_set_iterator (GtrMsg *msg,
+ po_message_iterator_t iter);
- gint *gtr_msg_get_file_line (GtrMsg * msg, gint i);
+po_message_t _gtr_msg_get_message (GtrMsg *msg);
- const gchar *gtr_msg_get_msgctxt (GtrMsg * msg);
+void _gtr_msg_set_message (GtrMsg *msg,
+ po_message_t message);
- const gchar *gtr_msg_get_format (GtrMsg * msg);
+GtkTreeRowReference *_gtr_msg_get_row_reference (GtrMsg *msg);
- gchar *gtr_msg_check (GtrMsg * msg);
+void _gtr_msg_set_row_reference (GtrMsg *msg,
+ GtkTreeRowReference *row_reference);
G_END_DECLS
-#endif /* __MSG_H__ */
+#endif /* __GTR_MSG_H__ */
diff --git a/src/gtr-po.c b/src/gtr-po.c
index 6f863ef..abb6d01 100644
--- a/src/gtr-po.c
+++ b/src/gtr-po.c
@@ -480,7 +480,7 @@ gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
if (!po_message_is_obsolete (message))
{
/* Unpack into a GtrMsg */
- msg = gtr_msg_new (iter, message);
+ msg = _gtr_msg_new (iter, message);
/* Set position in PO file */
gtr_msg_set_po_position (msg, pos++);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]