Jannis Pohlmann wrote:
> Hi all,

Hey Jannis,

> Benny, I didn't make the plugin resistent, as there seem to be no
> problems unloading TagLib, as far as I can see. 

Probably, tho I'm not sure about the taglib_tag_free_strings() function,
looks like TagLib allocates static data.

> There still may be memory leaks I have not yet detected, so feel free
> to send a mail or file a bug report on BerliOS.

Attached is a patch to fix a few mem leaks. It also uses shorter labels
for the check buttons, otherwise the widget gets too large (IMHO). And
it strips additional whitespace from ID3.

The renamer works like a charm, good work.

> Thanks - and have fun,
> Jannis

Benedikt

PS: Can you please renamer the ThunarSbrTagRenamer and
ThunarSbrTagRenamerProvider classes, else we may run into name conflicts
later. At best, external plugins shouldn't use the "Thunar" name prefix
for GTypes.
--- thunar-sbr-tag-renamer.c.orig	Thu Mar 23 15:50:34 2006
+++ thunar-sbr-tag-renamer.c	Thu Mar 23 16:02:31 2006
@@ -232,7 +232,7 @@
   tag_renamer->tooltips = gtk_tooltips_new ();
   exo_gtk_object_ref_sink (GTK_OBJECT (tag_renamer->tooltips));
 
-  table = gtk_table_new (4, 3, FALSE);
+  table = gtk_table_new (2, 3, FALSE);
   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
   gtk_table_set_col_spacings (GTK_TABLE (table), 12);
   gtk_box_pack_start (GTK_BOX (tag_renamer), table, FALSE, FALSE, 0);
@@ -262,14 +262,14 @@
   atk_relation_set_add (relations, relation);
   g_object_unref (G_OBJECT (relation));
 
-  button = gtk_check_button_new_with_mnemonic (_("_Replace spaces with underscores"));
+  button = gtk_check_button_new_with_mnemonic (_("Use _underscores"));
   exo_mutual_binding_new (G_OBJECT (button), "active", G_OBJECT (tag_renamer), "replace-spaces");
   gtk_tooltips_set_tip (tag_renamer->tooltips, button, _("Activating this option will replace all spaces in the target filename "
         "with underscores."), NULL);
   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1, GTK_FILL, 0, 0, 0);
   gtk_widget_show (button);
 
-  button = gtk_check_button_new_with_mnemonic (_("Convert to _lowercase"));
+  button = gtk_check_button_new_with_mnemonic (_("Use _lowercase"));
   exo_mutual_binding_new (G_OBJECT (button), "active", G_OBJECT (tag_renamer), "lowercase");
   gtk_tooltips_set_tip (tag_renamer->tooltips, button, _("If you activate this, the resulting filename will not contain any "
         "uppercase letters."), NULL);
@@ -310,6 +310,9 @@
 {
   ThunarSbrTagRenamer *tag_renamer = THUNAR_SBR_TAG_RENAMER (object);
 
+  /* release the tooltips */
+  g_object_unref (G_OBJECT (tag_renamer->tooltips));
+
   /* Free strings */
   g_free (tag_renamer->artist);
   g_free (tag_renamer->title);
@@ -422,9 +425,12 @@
   gchar *title;
   guint  track_num;
   gchar *track;
+  gchar *uri;
   
   /* Strip of the file:// from the URI */
-  filename = g_filename_from_uri (thunarx_file_info_get_uri (file), NULL, NULL);
+  uri = thunarx_file_info_get_uri (file);
+  filename = g_filename_from_uri (uri, NULL, NULL);
+  g_free (uri);
 
   /* Return if URI could not be resolved */
   if (G_UNLIKELY (filename == NULL))
@@ -435,14 +441,21 @@
 
   /* Don't change anything if taglib file could not be allocated */
   if (G_UNLIKELY (taglib_file == NULL))
-    return g_strdup (text);
+    {
+      g_free (filename);
+      return g_strdup (text);
+    }
 
   /* Load tag info */
   taglib_tag = taglib_file_tag (taglib_file);
 
   /* Abort if tag info could not be loaded */
   if (G_UNLIKELY (taglib_tag == NULL))
-    return g_strdup (text);
+    {
+      taglib_file_free (taglib_file);
+      g_free (filename);
+      return g_strdup (text);
+    }
 
   /* Load tag properties */
   taglib_properties = taglib_file_audioproperties (taglib_file);
@@ -452,6 +465,10 @@
   title = g_strdup (taglib_tag_title (taglib_tag));
   track_num = taglib_tag_track (taglib_tag);
 
+  /* stip additional whitespace from the tags */
+  g_strstrip (artist);
+  g_strstrip (title);
+
   /* Replace missing artist tag */
   if (G_UNLIKELY (g_utf8_strlen (artist, -1) == 0))
     artist = g_strdup (thunar_sbr_tag_renamer_get_artist (tag_renamer));
@@ -466,9 +483,9 @@
     track = g_strdup_printf ("%02d", taglib_tag_track (taglib_tag));
 
   /* Replace special chars with underscores */
-  artist = g_strdelimit (artist, "/", '_');
-  title = g_strdelimit (title, "/", '_');
-  track = g_strdelimit (track, "/", '_');
+  artist = g_strdelimit (artist, G_DIR_SEPARATOR_S, '_');
+  title = g_strdelimit (title, G_DIR_SEPARATOR_S, '_');
+  track = g_strdelimit (track, G_DIR_SEPARATOR_S, '_');
 
   switch (thunar_sbr_tag_renamer_get_scheme (tag_renamer))
     {
_______________________________________________
Thunar-dev mailing list
Thunar-dev@xfce.org
http://foo-projects.org/mailman/listinfo/thunar-dev

Reply via email to