[gtranslator] Enable deletion of all TM entries



commit 33fcc2a4682982eebd1b466a98eb5f417712e5b7
Author: Marcos Chavarría Teijeiro <chavarria1991 gmail com>
Date:   Tue Apr 16 10:17:05 2013 +0200

    Enable deletion of all TM entries

 plugins/translation-memory/gda/gtr-gda.c           | 36 ++++++++++++++++------
 .../translation-memory/gtr-translation-memory-ui.c | 35 ++++++---------------
 .../translation-memory/gtr-translation-memory.c    |  9 ++----
 .../translation-memory/gtr-translation-memory.h    |  7 ++---
 4 files changed, 42 insertions(+), 45 deletions(-)
---
diff --git a/plugins/translation-memory/gda/gtr-gda.c b/plugins/translation-memory/gda/gtr-gda.c
index 1fa41c7..0c140e0 100644
--- a/plugins/translation-memory/gda/gtr-gda.c
+++ b/plugins/translation-memory/gda/gtr-gda.c
@@ -430,16 +430,16 @@ gtr_gda_store_list (GtrTranslationMemory * tm, GList * msgs)
 
 static void
 gtr_gda_remove (GtrTranslationMemory *tm,
-                const gchar *original,
-                const gchar *translation)
+                gint translation_id)
 {
   GtrGda *self = GTR_GDA (tm);
   GdaSet *params;
   GError *error;
 
-  params = gda_set_new_inline (2,
-                               "original", G_TYPE_STRING, original,
-                               "value", G_TYPE_STRING, translation);
+  params = gda_set_new_inline (1,
+                               "id_trans",
+                               G_TYPE_INT,
+                               translation_id);
 
   error = NULL;
   gda_connection_statement_execute_non_select (self->priv->db,
@@ -474,7 +474,8 @@ build_lookup_query (GtrGda *self, guint word_count)
   g_string_append_printf (query,
                           "select "
                           "    TRANS.VALUE, "
-                          "    100 SCORE "
+                          "    100 SCORE, "
+                         "    TRANS.ID "
                           "from "
                           "     TRANS, ORIG "
                           "where ORIG.ID = TRANS.ORIG_ID "
@@ -482,7 +483,8 @@ build_lookup_query (GtrGda *self, guint word_count)
                           "union "
                           "select "
                           "    TRANS.VALUE, "
-                          "    SC SCORE "
+                          "    SC SCORE, "
+                          "    TRANS.ID "
                           "from TRANS, "
                           "     (select "
                           "          ORIG.ID ORID, "
@@ -616,6 +618,7 @@ gtr_gda_lookup (GtrTranslationMemory * tm, const gchar * phrase)
         const GValue * val;
         gchar *suggestion;
         gint score;
+        gint id;
         GtrTranslationMemoryMatch *match;
 
         inner_error = NULL;
@@ -643,9 +646,24 @@ gtr_gda_lookup (GtrTranslationMemory * tm, const gchar * phrase)
 
         score = g_value_get_int (val);
 
+        inner_error = NULL;
+        val = gda_data_model_get_typed_value_at (model,
+                                                 2, i,
+                                                 G_TYPE_INT,
+                                                 FALSE,
+                                                 &inner_error);
+        if (!val)
+          {
+            g_free (suggestion);
+            goto end;
+          }
+
+        id = g_value_get_int (val);
+
         match = g_slice_new (GtrTranslationMemoryMatch);
         match->match = suggestion;
         match->level = score;
+        match->id = id;
 
         matches = g_list_prepend (matches, match);
       }
@@ -861,9 +879,7 @@ gtr_gda_init (GtrGda * self)
   self->priv->stmt_delete_trans =
     prepare_statement (self->priv->parser,
                        "delete from TRANS "
-                       "where ORIG_ID= "
-                       "(select ID from ORIG where VALUE=##original::string) "
-                       "and VALUE=##value::string");
+                       "where id = ##id_trans::int");
 
   self->priv->max_omits = 0;
   self->priv->max_delta = 0;
diff --git a/plugins/translation-memory/gtr-translation-memory-ui.c 
b/plugins/translation-memory/gtr-translation-memory-ui.c
index 220b88e..68cf456 100644
--- a/plugins/translation-memory/gtr-translation-memory-ui.c
+++ b/plugins/translation-memory/gtr-translation-memory-ui.c
@@ -54,6 +54,7 @@ struct _GtrTranslationMemoryUiPrivate
   GtrTab *tab;
 
   gchar **tm_list;
+  gint *tm_list_id;
 
   GtkWidget *popup_menu;
   GtrMsg *msg;
@@ -161,12 +162,14 @@ showed_message_cb (GtrTab *tab, GtrMsg *msg, GtrTranslationMemoryUi *tm_ui)
 
   gtk_list_store_clear (model);
   tm_ui->priv->tm_list = g_new (gchar *, MAX_ELEMENTS + 1);
+  tm_ui->priv->tm_list_id = g_new (gint, MAX_ELEMENTS + 1);
 
   i = 0;
   for (l = tm_list; l && i < MAX_ELEMENTS; l = l->next)
     {
       GtrTranslationMemoryMatch *match = (GtrTranslationMemoryMatch *) l->data;
 
+      tm_ui->priv->tm_list_id[i] = match->id;
       tm_ui->priv->tm_list[i] = g_strdup (match->match);
       level_column = gtk_tree_view_get_column (GTK_TREE_VIEW (tm_ui->priv->tree_view), 0);
       renderers_list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (level_column));
@@ -284,8 +287,7 @@ popup_menu_remove_from_memory (GtkMenuItem *menuitem,
   GtkTreeSelection *selection;
   GtkTreeModel *model;
   GtkTreeIter iter;
-  gint level;
-  const gchar *original;
+  gint i;
   gchar *translation;
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tm_ui->priv->tree_view));
@@ -293,18 +295,14 @@ popup_menu_remove_from_memory (GtkMenuItem *menuitem,
     return;
 
   gtk_tree_model_get (model, &iter,
-                      LEVEL_COLUMN, &level,
-                      -1);
-
-  if (level != 100)
-    return;
-
-  gtk_tree_model_get (model, &iter,
                       STRING_COLUMN, &translation,
                       -1);
 
-  original = gtr_msg_get_msgid (tm_ui->priv->msg);
-  gtr_translation_memory_remove (tm_ui->priv->translation_memory, original, translation);
+  for (i = 0; tm_ui->priv->tm_list[i]; i++)
+    if (!strcmp (tm_ui->priv->tm_list[i], translation))
+      break;
+
+  gtr_translation_memory_remove (tm_ui->priv->translation_memory, tm_ui->priv->tm_list_id[i]);
 
   g_free (translation);
 
@@ -316,24 +314,11 @@ static GtkWidget *
 create_tree_popup_menu (GtrTranslationMemoryUi *self)
 {
   GtkTreeSelection *selection;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  gboolean remove_available = FALSE;
   GtkWidget *menu;
   GtkWidget *item;
   GtkWidget *image;
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->priv->tree_view));
-  if (selection && gtk_tree_selection_get_selected (selection, &model, &iter))
-    {
-      gint level;
-
-      gtk_tree_model_get (model, &iter,
-                          LEVEL_COLUMN, &level,
-                          -1);
-
-      remove_available = (level == 100);
-    }
 
   menu = gtk_menu_new ();
 
@@ -348,7 +333,7 @@ create_tree_popup_menu (GtrTranslationMemoryUi *self)
   g_signal_connect (item, "activate",
                     G_CALLBACK (popup_menu_remove_from_memory), self);
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-  gtk_widget_set_sensitive (item, remove_available);
+  gtk_widget_set_sensitive (item, TRUE);
 
   gtk_widget_show_all (menu);
 
diff --git a/plugins/translation-memory/gtr-translation-memory.c 
b/plugins/translation-memory/gtr-translation-memory.c
index 8627559..95b7c6f 100644
--- a/plugins/translation-memory/gtr-translation-memory.c
+++ b/plugins/translation-memory/gtr-translation-memory.c
@@ -87,20 +87,17 @@ gtr_translation_memory_store_list_default (GtrTranslationMemory * obj,
  */
 void
 gtr_translation_memory_remove (GtrTranslationMemory * obj,
-                              const gchar * original,
-                              const gchar * translation)
+                                                gint  translation_id)
 {
   g_return_if_fail (GTR_IS_TRANSLATION_MEMORY (obj));
   return GTR_TRANSLATION_MEMORY_GET_IFACE (obj)->remove (obj,
-                                                        original,
-                                                        translation);
+                                                        translation_id);
 }
 
 /* Default implementation */
 static void
 gtr_translation_memory_remove_default (GtrTranslationMemory * obj,
-                                       const gchar * original,
-                                       const gchar * translation)
+                                                        gint translation_id)
 {
 }
 
diff --git a/plugins/translation-memory/gtr-translation-memory.h 
b/plugins/translation-memory/gtr-translation-memory.h
index 8292cb8..a3f29ab 100644
--- a/plugins/translation-memory/gtr-translation-memory.h
+++ b/plugins/translation-memory/gtr-translation-memory.h
@@ -37,8 +37,7 @@ struct _GtrTranslationMemoryInterface
   gboolean (*store) (GtrTranslationMemory * obj, GtrMsg * msg);
   gboolean (*store_list) (GtrTranslationMemory * obj, GList * msgs);
   void (*remove) (GtrTranslationMemory *obj,
-                  const gchar          *original,
-                  const gchar          *translation);
+                  gint                 translation_id);
 
   GList *(*lookup) (GtrTranslationMemory * obj, const gchar * phrase);
   void (*set_max_omits) (GtrTranslationMemory * obj, gsize omits);
@@ -51,6 +50,7 @@ struct _GtrTranslationMemoryMatch
 {
   gchar *match;
   gint level;
+  gint id;
 };
 
 GType           gtr_translation_memory_get_type         (void);
@@ -62,8 +62,7 @@ gboolean        gtr_translation_memory_store_list       (GtrTranslationMemory
                                                          GList                  *msg);
 
 void            gtr_translation_memory_remove           (GtrTranslationMemory   *obj,
-                                                         const gchar            *original,
-                                                         const gchar            *translation);
+                                                         gint                  translation_id);
 
 GList          *gtr_translation_memory_lookup           (GtrTranslationMemory   *obj,
                                                          const gchar            *phrase);


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