[gtranslator] Moved some functions to TM plugin



commit 63be76ce6989c6618bdc59fb1691e4c4c5dab594
Author: Daniel Mustieles <daniel mustieles gmail com>
Date:   Sat Apr 21 17:52:10 2012 +0200

    Moved some functions to TM plugin

 plugins/translation-memory/Makefile.am             |    2 +
 plugins/translation-memory/gda/Makefile.am         |    2 +
 plugins/translation-memory/gda/gda-utils.c         |  153 +++++++++++++++++
 plugins/translation-memory/gda/gda-utils.h         |   32 ++++
 plugins/translation-memory/gda/gtr-gda.c           |    4 +-
 .../gtr-translation-memory-dialog.c                |    6 +-
 .../gtr-translation-memory-utils.c                 |   97 +++++++++++
 .../gtr-translation-memory-utils.h                 |   32 ++++
 src/gtr-utils.c                                    |  181 --------------------
 src/gtr-utils.h                                    |    5 -
 10 files changed, 323 insertions(+), 191 deletions(-)
---
diff --git a/plugins/translation-memory/Makefile.am b/plugins/translation-memory/Makefile.am
index a6522ad..58f28c0 100644
--- a/plugins/translation-memory/Makefile.am
+++ b/plugins/translation-memory/Makefile.am
@@ -20,6 +20,8 @@ libtranslation_memory_la_SOURCES = \
 	gtr-translation-memory-window-activatable.c \
 	gtr-translation-memory-window-activatable.h \
 	gtr-translation-memory-tab-activatable.c \
+	gtr-translation-memory-utils.c \
+	gtr-translation-memory-utils.h \
 	gtr-translation-memory-tab-activatable.h \
 	gtr-translation-memory-ui.c \
 	gtr-translation-memory-ui.h \
diff --git a/plugins/translation-memory/gda/Makefile.am b/plugins/translation-memory/gda/Makefile.am
index a5d3e04..7779f22 100644
--- a/plugins/translation-memory/gda/Makefile.am
+++ b/plugins/translation-memory/gda/Makefile.am
@@ -13,6 +13,8 @@ noinst_LTLIBRARIES = \
 	libgda.la
 
 libgda_la_SOURCES = \
+	gda-utils.c \
+	gda-utils-h \
 	gtr-gda.c \
 	gtr-gda.h
 
diff --git a/plugins/translation-memory/gda/gda-utils.c b/plugins/translation-memory/gda/gda-utils.c
new file mode 100644
index 0000000..d8d151b
--- /dev/null
+++ b/plugins/translation-memory/gda/gda-utils.c
@@ -0,0 +1,153 @@
+/*
+ * (C) 2001     Fatih Demir <kabalak kabalak net>
+ *     2012	Ignacio Casal Quinteiro <icq gnome org>
+ *
+ * gtranslator 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 2 of the License, or   
+ * (at your option) any later version.
+ *
+ * gtranslator 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors:
+ *   Ignacio Casal Quinteiro <icq gnome org>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gda-utils.h"
+
+#include <string.h>
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+
+static const gchar *badwords[] = {
+  "a",
+  //"all",
+  "an",
+  //"are",
+  //"can",
+  //"for",
+  //"from",
+  "have",
+  //"it",
+  //"may",
+  //"not",
+  "of",
+  //"that",
+  "the",
+  //"this",
+  //"was",
+  "will",
+  //"with",
+  //"you",
+  //"your",
+  NULL
+};
+
+static gboolean
+check_good_word (const gchar * word, gchar ** badwords)
+{
+  gboolean check = TRUE;
+  gchar *lower = g_utf8_strdown (word, -1);
+  gint i = 0;
+
+  while (badwords[i] != NULL)
+    {
+      gchar *lower_collate = g_utf8_collate_key (lower, -1);
+
+      if (strcmp (lower_collate, badwords[i]) == 0)
+        {
+          check = FALSE;
+          g_free (lower_collate);
+          break;
+        }
+      i++;
+      g_free (lower_collate);
+    }
+  return check;
+}
+
+
+/**
+ * gtr_gda_utils_split_string_in_words:
+ * @string: the text to process
+ *
+ * Process a text and split it in words using pango.
+ * 
+ * Returns: an array of words of the processed text
+ */
+gchar **
+gtr_gda_utils_split_string_in_words (const gchar * string)
+{
+  PangoLanguage *lang = pango_language_from_string ("en");
+  PangoLogAttr *attrs;
+  GPtrArray *array;
+  gint char_len;
+  gint i = 0;
+  gchar *s;
+  gchar *start = NULL;
+  static gchar **badwords_collate = NULL;
+
+  if (badwords_collate == NULL)
+    {
+      gint words_size = g_strv_length ((gchar **) badwords);
+      gint x = 0;
+
+      badwords_collate = g_new0 (gchar *, words_size + 1);
+
+      while (badwords[x] != NULL)
+        {
+          badwords_collate[x] = g_utf8_collate_key (badwords[x], -1);
+          x++;
+        }
+      badwords_collate[x] = NULL;
+    }
+
+  char_len = g_utf8_strlen (string, -1);
+  attrs = g_new (PangoLogAttr, char_len + 1);
+
+  pango_get_log_attrs (string,
+                       strlen (string), -1, lang, attrs, char_len + 1);
+
+  array = g_ptr_array_new ();
+
+  s = (gchar *) string;
+  while (i <= char_len)
+    {
+      gchar *end;
+
+      if (attrs[i].is_word_start)
+        start = s;
+      if (attrs[i].is_word_end)
+        {
+          gchar *word;
+
+          end = s;
+          word = g_strndup (start, end - start);
+
+          if (check_good_word (word, badwords_collate))
+            g_ptr_array_add (array, word);
+        }
+
+      i++;
+      s = g_utf8_next_char (s);
+    }
+
+  g_free (attrs);
+  g_ptr_array_add (array, NULL);
+
+  return (gchar **) g_ptr_array_free (array, FALSE);
+}
+
diff --git a/plugins/translation-memory/gda/gda-utils.h b/plugins/translation-memory/gda/gda-utils.h
new file mode 100644
index 0000000..52ef13b
--- /dev/null
+++ b/plugins/translation-memory/gda/gda-utils.h
@@ -0,0 +1,32 @@
+/*
+ * (C) 2001     Fatih Demir <kabalak kabalak net>
+ *     2012     Ignacio Casal Quinteiro <icq gnome org>
+ *
+ * gtranslator 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 2 of the License, or   
+ * (at your option) any later version.
+ *
+ * gtranslator 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors:
+ *   Fatih Demir <kabalak kabalak net>
+ *   Ignacio Casal Quinteiro <icq gnome org>
+ */
+
+#ifndef GDA_UTILS_H
+#define GDA_UTILS_H 1
+
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+
+gchar **gtr_gda_utils_split_string_in_words (const gchar * string);
+
+#endif
diff --git a/plugins/translation-memory/gda/gtr-gda.c b/plugins/translation-memory/gda/gtr-gda.c
index d1920cd..1fa41c7 100644
--- a/plugins/translation-memory/gda/gtr-gda.c
+++ b/plugins/translation-memory/gda/gtr-gda.c
@@ -24,7 +24,7 @@
 #include "gtr-gda.h"
 #include "gtr-translation-memory.h"
 #include "gtr-dirs.h"
-#include "gtr-utils.h"
+#include "gda-utils.h"
 
 #include <glib.h>
 #include <glib-object.h>
@@ -156,7 +156,7 @@ string_comparator (const void *s1, const void *s2)
 static gchar **
 gtr_gda_split_string_in_words (const gchar *phrase)
 {
-  gchar **words = gtr_utils_split_string_in_words (phrase);
+  gchar **words = gtr_gda_utils_split_string_in_words (phrase);
   gsize count = g_strv_length (words);
   gint w;
   gint r;
diff --git a/plugins/translation-memory/gtr-translation-memory-dialog.c b/plugins/translation-memory/gtr-translation-memory-dialog.c
index 59c1d65..5652c6c 100644
--- a/plugins/translation-memory/gtr-translation-memory-dialog.c
+++ b/plugins/translation-memory/gtr-translation-memory-dialog.c
@@ -17,7 +17,7 @@
 
 #include "gtr-translation-memory-dialog.h"
 #include "gtr-profile-manager.h"
-#include "gtr-utils.h"
+#include "gtr-translation-memory-utils.h"
 #include "gtr-po.h"
 
 #include <glib/gi18n.h>
@@ -239,11 +239,11 @@ on_add_database_button_clicked (GtkButton                  *button,
 
       restriction = g_settings_get_string (dlg->priv->tm_settings,
                                            "filename-restriction");
-      gtr_utils_scan_dir (dir, &data->list, restriction);
+      gtr_scan_dir (dir, &data->list, restriction);
       g_free (restriction);
     }
   else
-    gtr_utils_scan_dir (dir, &data->list, NULL);
+    gtr_scan_dir (dir, &data->list, NULL);
 
   data->tm = dlg->priv->translation_memory;
   data->progress = GTK_PROGRESS_BAR (dlg->priv->add_database_progressbar);
diff --git a/plugins/translation-memory/gtr-translation-memory-utils.c b/plugins/translation-memory/gtr-translation-memory-utils.c
new file mode 100644
index 0000000..cef0113
--- /dev/null
+++ b/plugins/translation-memory/gtr-translation-memory-utils.c
@@ -0,0 +1,97 @@
+/*
+ * (C) 2001     Fatih Demir <kabalak kabalak net>
+ *     2012	Ignacio Casal Quinteiro <icq gnome org>
+ *
+ * gtranslator 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 2 of the License, or   
+ * (at your option) any later version.
+ *
+ * gtranslator 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors:
+ *   Ignacio Casal Quinteiro <icq gnome org>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gtr-translation-memory-utils.h"
+
+#include <string.h>
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+
+/**
+ * gtr_scan_dir:
+ * @dir: the dir to parse
+ * @list: the list where to store the GFiles
+ * @po_name: the name of the specific po file to search or NULL.
+ *
+ * Scans the directory and subdirectories of @dir looking for filenames remained
+ * with .po or files that matches @po_name. @list must be freed with
+ * g_slist_free_full (list, g_object_unref).
+ */
+void
+gtr_scan_dir (GFile * dir, GSList ** list, const gchar * po_name)
+{
+  GFileInfo *info;
+  GError *error;
+  GFile *file;
+  GFileEnumerator *enumerator;
+
+  error = NULL;
+  enumerator = g_file_enumerate_children (dir,
+                                          G_FILE_ATTRIBUTE_STANDARD_NAME,
+                                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                          NULL, &error);
+  if (enumerator)
+    {
+      error = NULL;
+
+      while ((info =
+              g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL)
+        {
+          const gchar *name;
+          gchar *filename;
+
+          name = g_file_info_get_name (info);
+          file = g_file_get_child (dir, name);
+
+          if (po_name != NULL)
+            {
+              if (g_str_has_suffix (po_name, ".po"))
+                filename = g_strdup (po_name);
+              else
+                filename = g_strconcat (po_name, ".po", NULL);
+            }
+          else
+            filename = g_strdup (".po");
+
+          if (g_str_has_suffix (name, filename))
+            *list = g_slist_prepend (*list, file);
+          g_free (filename);
+
+          gtr_scan_dir (file, list, po_name);
+          g_object_unref (info);
+        }
+      g_file_enumerator_close (enumerator, NULL, NULL);
+      g_object_unref (enumerator);
+
+      if (error)
+        {
+          g_warning ("%s", error->message);
+        }
+    }
+}
+
diff --git a/plugins/translation-memory/gtr-translation-memory-utils.h b/plugins/translation-memory/gtr-translation-memory-utils.h
new file mode 100644
index 0000000..a8433a2
--- /dev/null
+++ b/plugins/translation-memory/gtr-translation-memory-utils.h
@@ -0,0 +1,32 @@
+/*
+ * (C) 2001     Fatih Demir <kabalak kabalak net>
+ *     2012     Ignacio Casal Quinteiro <icq gnome org>
+ *
+ * gtranslator 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 2 of the License, or   
+ * (at your option) any later version.
+ *
+ * gtranslator 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors:
+ *   Fatih Demir <kabalak kabalak net>
+ *   Ignacio Casal Quinteiro <icq gnome org>
+ */
+
+#ifndef GTR_TRANSLATION_MEMORY_UTILS_H
+#define GTR_TRANSLATION_MEMORY_UTILS_H 1
+
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+
+void gtr_scan_dir (GFile * dir,
+		   GSList ** list, const gchar * po_name);
+#endif
diff --git a/src/gtr-utils.c b/src/gtr-utils.c
index fbd51cd..c0fe102 100644
--- a/src/gtr-utils.c
+++ b/src/gtr-utils.c
@@ -41,124 +41,6 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
-static const gchar *badwords[] = {
-  "a",
-  //"all",
-  "an",
-  //"are",
-  //"can",
-  //"for",
-  //"from",
-  "have",
-  //"it",
-  //"may",
-  //"not",
-  "of",
-  //"that",
-  "the",
-  //"this",
-  //"was",
-  "will",
-  //"with",
-  //"you",
-  //"your",
-  NULL
-};
-
-static gboolean
-check_good_word (const gchar * word, gchar ** badwords)
-{
-  gboolean check = TRUE;
-  gchar *lower = g_utf8_strdown (word, -1);
-  gint i = 0;
-
-  while (badwords[i] != NULL)
-    {
-      gchar *lower_collate = g_utf8_collate_key (lower, -1);
-
-      if (strcmp (lower_collate, badwords[i]) == 0)
-        {
-          check = FALSE;
-          g_free (lower_collate);
-          break;
-        }
-      i++;
-      g_free (lower_collate);
-    }
-  return check;
-}
-
-/**
- * gtr_utils_split_string_in_words:
- * @string: the text to process
- *
- * Process a text and split it in words using pango.
- * 
- * Returns: an array of words of the processed text
- */
-gchar **
-gtr_utils_split_string_in_words (const gchar * string)
-{
-  PangoLanguage *lang = pango_language_from_string ("en");
-  PangoLogAttr *attrs;
-  GPtrArray *array;
-  gint char_len;
-  gint i = 0;
-  gchar *s;
-  gchar *start = NULL;
-  static gchar **badwords_collate = NULL;
-
-  if (badwords_collate == NULL)
-    {
-      gint words_size = g_strv_length ((gchar **) badwords);
-      gint x = 0;
-
-      badwords_collate = g_new0 (gchar *, words_size + 1);
-
-      while (badwords[x] != NULL)
-        {
-          badwords_collate[x] = g_utf8_collate_key (badwords[x], -1);
-          x++;
-        }
-      badwords_collate[x] = NULL;
-    }
-
-  char_len = g_utf8_strlen (string, -1);
-  attrs = g_new (PangoLogAttr, char_len + 1);
-
-  pango_get_log_attrs (string,
-                       strlen (string), -1, lang, attrs, char_len + 1);
-
-  array = g_ptr_array_new ();
-
-  s = (gchar *) string;
-  while (i <= char_len)
-    {
-      gchar *end;
-
-      if (attrs[i].is_word_start)
-        start = s;
-      if (attrs[i].is_word_end)
-        {
-          gchar *word;
-
-          end = s;
-          word = g_strndup (start, end - start);
-
-          if (check_good_word (word, badwords_collate))
-            g_ptr_array_add (array, word);
-        }
-
-      i++;
-      s = g_utf8_next_char (s);
-    }
-
-  g_free (attrs);
-  g_ptr_array_add (array, NULL);
-
-  return (gchar **) g_ptr_array_free (array, FALSE);
-}
-
 xmlDocPtr
 gtr_xml_new_doc (const gchar * name)
 {
@@ -699,69 +581,6 @@ gtr_utils_get_current_year (void)
   return year;
 }
 
-/**
- * gtr_utils_scan_dir:
- * @dir: the dir to parse
- * @list: the list where to store the GFiles
- * @po_name: the name of the specific po file to search or NULL.
- *
- * Scans the directory and subdirectories of @dir looking for filenames remained
- * with .po or files that matches @po_name. @list must be freed with
- * g_slist_free_full (list, g_object_unref).
- */
-void
-gtr_utils_scan_dir (GFile * dir, GSList ** list, const gchar * po_name)
-{
-  GFileInfo *info;
-  GError *error;
-  GFile *file;
-  GFileEnumerator *enumerator;
-
-  error = NULL;
-  enumerator = g_file_enumerate_children (dir,
-                                          G_FILE_ATTRIBUTE_STANDARD_NAME,
-                                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                          NULL, &error);
-  if (enumerator)
-    {
-      error = NULL;
-
-      while ((info =
-              g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL)
-        {
-          const gchar *name;
-          gchar *filename;
-
-          name = g_file_info_get_name (info);
-          file = g_file_get_child (dir, name);
-
-          if (po_name != NULL)
-            {
-              if (g_str_has_suffix (po_name, ".po"))
-                filename = g_strdup (po_name);
-              else
-                filename = g_strconcat (po_name, ".po", NULL);
-            }
-          else
-            filename = g_strdup (".po");
-
-          if (g_str_has_suffix (name, filename))
-            *list = g_slist_prepend (*list, file);
-          g_free (filename);
-
-          gtr_utils_scan_dir (file, list, po_name);
-          g_object_unref (info);
-        }
-      g_file_enumerator_close (enumerator, NULL, NULL);
-      g_object_unref (enumerator);
-
-      if (error)
-        {
-          g_warning ("%s", error->message);
-        }
-    }
-}
-
 gchar *
 gtr_utils_reduce_path (const gchar * path)
 {
diff --git a/src/gtr-utils.h b/src/gtr-utils.h
index 2653d3d..4a84f19 100644
--- a/src/gtr-utils.h
+++ b/src/gtr-utils.h
@@ -28,8 +28,6 @@
 #include <libxml/tree.h>
 #include <gio/gio.h>
 
-gchar **gtr_utils_split_string_in_words (const gchar * string);
-
 xmlDocPtr gtr_xml_new_doc (const gchar * name);
 
 xmlDocPtr gtr_xml_open_file (const gchar * filename);
@@ -70,9 +68,6 @@ void gtr_utils_menu_position_under_tree_view (GtkMenu * menu,
 
      gchar *gtr_utils_get_current_year (void);
 
-     void gtr_utils_scan_dir (GFile * dir,
-                              GSList ** list, const gchar * po_name);
-
      gchar *gtr_utils_reduce_path (const gchar * path);
 
      gchar *gtr_utils_escape_underscores (const gchar * text, gssize length);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]