[easytag/wip/disc-number: 4/11] Automatically split and combine disc numbers
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/disc-number: 4/11] Automatically split and combine disc numbers
- Date: Mon, 22 Jul 2013 21:27:18 +0000 (UTC)
commit 6361a53a5fc896786aeb092dc73a82d984d78be1
Author: David King <amigadave amigadave com>
Date: Sat Jul 13 20:03:58 2013 +0100
Automatically split and combine disc numbers
Using '/' as the separator, split the disc number text entry field into
a disc number and the total number of discs. Combine the two tag fields
into one for display in the UI.
src/easytag.c | 20 ++++++++++++++--
src/et_core.c | 67 +++++++++++++++++++++++++++++----------------------------
2 files changed, 51 insertions(+), 36 deletions(-)
---
diff --git a/src/easytag.c b/src/easytag.c
index a252ff0..cc5e14d 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1397,9 +1397,23 @@ Mini_Button_Clicked (GObject *object)
}
else if (object == G_OBJECT (DiscNumberEntry))
{
- /* FIXME: Split discs field into disc number and disc total. */
- string_to_set = g_strdup (gtk_entry_get_text (GTK_ENTRY (DiscNumberEntry)));
- string_to_set1 = NULL;
+ const gchar *entry_text;
+ gchar *separator;
+
+ entry_text = gtk_entry_get_text (GTK_ENTRY (DiscNumberEntry));
+ separator = g_utf8_strchr (entry_text, -1, '/');
+
+ if (separator)
+ {
+ string_to_set1 = g_strdup (separator + 1);
+ string_to_set = g_strndup (entry_text,
+ separator - entry_text);
+ }
+ else
+ {
+ string_to_set = g_strdup (entry_text);
+ string_to_set1 = NULL;
+ }
for (l = etfilelist; l != NULL; l = g_list_next (l))
{
diff --git a/src/et_core.c b/src/et_core.c
index bb85ef7..89e5db3 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -2943,24 +2943,25 @@ ET_Display_File_Tag_To_UI (ET_File *ETFile)
}else
gtk_entry_set_text(GTK_ENTRY(AlbumEntry),"");
- /* Show disc_number */
- /* FIXME: Combine disc number and disc total into a single string. */
+ /* Show disc number and number of discs. */
if (FileTag && FileTag->disc_number)
{
- gchar *tmp = Try_To_Validate_Utf8_String(FileTag->disc_number);
- gtk_entry_set_text (GTK_ENTRY (DiscNumberEntry), tmp);
- g_free (tmp);
- }
- else
- {
- gtk_entry_set_text (GTK_ENTRY (DiscNumberEntry), "");
- }
+ gchar *tmp;
+
+ if (FileTag->disc_total)
+ {
+ gchar *total;
+
+ total = g_strjoin ("/", FileTag->disc_number, FileTag->disc_total,
+ NULL);
+ tmp = Try_To_Validate_Utf8_String (total);
+ g_free (total);
+ }
+ else
+ {
+ tmp = Try_To_Validate_Utf8_String (FileTag->disc_number);
+ }
- /* Show number of discs of the album. */
-#if 0
- if (FileTag && FileTag->disc_total)
- {
- gchar *tmp = Try_To_Validate_Utf8_String (FileTag->disc_total);
gtk_entry_set_text (GTK_ENTRY (DiscNumberEntry), tmp);
g_free (tmp);
}
@@ -2968,7 +2969,6 @@ ET_Display_File_Tag_To_UI (ET_File *ETFile)
{
gtk_entry_set_text (GTK_ENTRY (DiscNumberEntry), "");
}
-#endif
/* Show year */
if (FileTag && FileTag->year)
@@ -3461,35 +3461,36 @@ ET_Save_File_Tag_From_UI (File_Tag *FileTag)
g_free(buffer);
}
- /* Disc Number */
- /* FIXME: Take single disc string and split into disc number and disc total. */
+ /* Disc number and total number of discs. */
buffer = g_strdup (gtk_entry_get_text (GTK_ENTRY (DiscNumberEntry)));
g_strstrip (buffer);
- if ( g_utf8_strlen(buffer, -1) > 0 )
- FileTag->disc_number = buffer;
- else
+ if (g_utf8_strlen (buffer, -1) > 0)
{
- FileTag->disc_number = NULL;
- g_free(buffer);
- }
+ gchar *separator;
- /* Discs Total */
-#if 0
- buffer = g_strdup (gtk_entry_get_text (GTK_ENTRY (DiscNumberEntry)));
- g_strstrip (buffer);
+ separator = g_utf8_strchr (buffer, -1, '/');
- if (g_utf8_strlen (buffer, -1) > 0)
- {
- FileTag->disc_total = et_disc_number_to_string (atoi (buffer));
- g_free (buffer);
+ if (separator != NULL && g_utf8_strlen (separator + 1, -1) > 0)
+ {
+ /* Copy before the separator for the disc number, beyond the
+ * separator for the total number of discs. */
+ FileTag->disc_number = g_strndup (buffer, separator - buffer);
+ FileTag->disc_total = g_strdup (separator + 1);
+ g_free (buffer);
+ }
+ else
+ {
+ FileTag->disc_number = buffer;
+ FileTag->disc_total = NULL;
+ }
}
else
{
+ FileTag->disc_number = NULL;
FileTag->disc_total = NULL;
g_free (buffer);
}
-#endif
/* Year */
buffer = g_strdup(gtk_entry_get_text(GTK_ENTRY(YearEntry)));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]