mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
major plugin revamp based on x-fixer's code
This commit is contained in:
@@ -135,36 +135,14 @@ const CharsetInfo charset_trans_array[] = {
|
||||
/*
|
||||
* Commons conversion functions
|
||||
*/
|
||||
char *convert_from_file_to_user(const char *string)
|
||||
char *convert_from_utf8_to_user(const char *string)
|
||||
{
|
||||
return FLAC_plugin__charset_convert_string(string, flac_cfg.title.file_char_set, flac_cfg.title.user_char_set);
|
||||
return FLAC_plugin__charset_convert_string(string, "UTF-8", flac_cfg.title.user_char_set);
|
||||
}
|
||||
|
||||
char *convert_from_user_to_file(const char *string)
|
||||
char *convert_from_user_to_utf8(const char *string)
|
||||
{
|
||||
return FLAC_plugin__charset_convert_string(string, flac_cfg.title.user_char_set, flac_cfg.title.file_char_set);
|
||||
}
|
||||
|
||||
void convert_from_file_to_user_in_place(char **string)
|
||||
{
|
||||
if(0 != *string) {
|
||||
char *tmp;
|
||||
|
||||
tmp = convert_from_file_to_user(*string);
|
||||
free(*string);
|
||||
*string = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void convert_from_user_to_file_in_place(char **string)
|
||||
{
|
||||
if(0 != *string) {
|
||||
char *tmp;
|
||||
|
||||
tmp = convert_from_user_to_file(*string);
|
||||
free(*string);
|
||||
*string = tmp;
|
||||
}
|
||||
return FLAC_plugin__charset_convert_string(string, flac_cfg.title.user_char_set, "UTF-8");
|
||||
}
|
||||
|
||||
GList *Charset_Create_List (void)
|
||||
|
||||
@@ -41,10 +41,11 @@ extern const CharsetInfo charset_trans_array[];
|
||||
* Prototypes *
|
||||
**************/
|
||||
|
||||
char *convert_from_file_to_user(const char *string);
|
||||
char *convert_from_user_to_file(const char *string);
|
||||
void convert_from_file_to_user_in_place(char **string);
|
||||
void convert_from_user_to_file_in_place(char **string);
|
||||
/*
|
||||
* The returned strings are malloc()ed an must be free()d by the caller
|
||||
*/
|
||||
char *convert_from_utf8_to_user(const char *string);
|
||||
char *convert_from_user_to_utf8(const char *string);
|
||||
|
||||
GList *Charset_Create_List (void);
|
||||
gchar *Charset_Get_Name_From_Title (gchar *charset_title);
|
||||
|
||||
@@ -48,7 +48,6 @@ flac_config_t flac_cfg = {
|
||||
FALSE, /* tag_override */
|
||||
NULL, /* tag_format */
|
||||
FALSE, /* convert_char_set */
|
||||
NULL, /* file_char_set */
|
||||
NULL /* user_char_set */
|
||||
},
|
||||
/* output */
|
||||
@@ -108,7 +107,6 @@ static void flac_configurewin_ok(GtkWidget * widget, gpointer data)
|
||||
(void)widget, (void)data; /* unused arguments */
|
||||
g_free(flac_cfg.title.tag_format);
|
||||
flac_cfg.title.tag_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(title_tag_entry)));
|
||||
flac_cfg.title.file_char_set = Charset_Get_Name_From_Title(gtk_entry_get_text_1(fileCharacterSetEntry));
|
||||
flac_cfg.title.user_char_set = Charset_Get_Name_From_Title(gtk_entry_get_text_1(userCharacterSetEntry));
|
||||
|
||||
filename = g_strconcat(g_get_home_dir(), "/.xmms/config", NULL);
|
||||
@@ -119,7 +117,6 @@ static void flac_configurewin_ok(GtkWidget * widget, gpointer data)
|
||||
xmms_cfg_write_boolean(cfg, "flac", "title.tag_override", flac_cfg.title.tag_override);
|
||||
xmms_cfg_write_string(cfg, "flac", "title.tag_format", flac_cfg.title.tag_format);
|
||||
xmms_cfg_write_boolean(cfg, "flac", "title.convert_char_set", flac_cfg.title.convert_char_set);
|
||||
xmms_cfg_write_string(cfg, "flac", "title.file_char_set", flac_cfg.title.file_char_set);
|
||||
xmms_cfg_write_string(cfg, "flac", "title.user_char_set", flac_cfg.title.user_char_set);
|
||||
/* output */
|
||||
xmms_cfg_write_boolean(cfg, "flac", "output.replaygain.enable", flac_cfg.output.replaygain.enable);
|
||||
@@ -293,7 +290,6 @@ void FLAC_XMMS__configure(void)
|
||||
list = Charset_Create_List();
|
||||
gtk_combo_set_popdown_strings(GTK_COMBO(fileCharacterSetEntry),list);
|
||||
gtk_combo_set_popdown_strings(GTK_COMBO(userCharacterSetEntry),list);
|
||||
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(fileCharacterSetEntry)->entry),Charset_Get_Title_From_Name(flac_cfg.title.file_char_set));
|
||||
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(userCharacterSetEntry)->entry),Charset_Get_Title_From_Name(flac_cfg.title.user_char_set));
|
||||
gtk_widget_set_sensitive(fileCharacterSetEntry, flac_cfg.title.convert_char_set);
|
||||
gtk_widget_set_sensitive(userCharacterSetEntry, flac_cfg.title.convert_char_set);
|
||||
|
||||
@@ -28,7 +28,6 @@ typedef struct {
|
||||
gboolean tag_override;
|
||||
gchar *tag_format;
|
||||
gboolean convert_char_set;
|
||||
gchar *file_char_set;
|
||||
gchar *user_char_set;
|
||||
} title;
|
||||
|
||||
|
||||
@@ -88,12 +88,6 @@ static const gchar *vorbis_genres[] =
|
||||
N_("Anime"), N_("JPop"), N_("Synthpop")
|
||||
};
|
||||
|
||||
static void local__safe_free(void *object)
|
||||
{
|
||||
if(0 != object)
|
||||
free(object);
|
||||
}
|
||||
|
||||
static void label_set_text(GtkWidget * label, char *str, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -107,45 +101,53 @@ static void label_set_text(GtkWidget * label, char *str, ...)
|
||||
g_free(tempstr);
|
||||
}
|
||||
|
||||
static void set_entry_tag(GtkEntry * entry, gchar * tag)
|
||||
static void set_entry_tag(GtkEntry * entry, const wchar_t * tag)
|
||||
{
|
||||
char *text;
|
||||
|
||||
if(tag) {
|
||||
char *utf8 = FLAC_plugin__convert_ucs2_to_utf8(tag);
|
||||
if(flac_cfg.title.convert_char_set) {
|
||||
text = convert_from_file_to_user(tag);
|
||||
char *text = convert_from_utf8_to_user(utf8);
|
||||
gtk_entry_set_text(entry, text);
|
||||
free(text);
|
||||
}
|
||||
else
|
||||
gtk_entry_set_text(entry, tag);
|
||||
else {
|
||||
gtk_entry_set_text(entry, utf8);
|
||||
}
|
||||
free(utf8);
|
||||
}
|
||||
else
|
||||
gtk_entry_set_text(entry, "");
|
||||
}
|
||||
|
||||
static char *get_entry_tag(GtkEntry * entry)
|
||||
static void get_entry_tag(GtkEntry * entry, const char *name)
|
||||
{
|
||||
gchar *text;
|
||||
char *utf8;
|
||||
|
||||
text = gtk_entry_get_text(entry);
|
||||
if (!text || strlen(text) == 0)
|
||||
return 0;
|
||||
return;
|
||||
if(flac_cfg.title.convert_char_set)
|
||||
return convert_from_user_to_file(text);
|
||||
utf8 = convert_from_user_to_utf8(text);
|
||||
else
|
||||
return strdup(text);
|
||||
utf8 = text;
|
||||
|
||||
FLAC_plugin__canonical_add_utf8(canonical_tag, name, utf8, (unsigned)(-1), (unsigned)(-1), /*sep=*/0);
|
||||
|
||||
if(flac_cfg.title.convert_char_set)
|
||||
free(utf8);
|
||||
}
|
||||
|
||||
static void show_tag()
|
||||
{
|
||||
set_entry_tag(GTK_ENTRY(title_entry), canonical_tag->title);
|
||||
set_entry_tag(GTK_ENTRY(artist_entry), canonical_tag->composer);
|
||||
set_entry_tag(GTK_ENTRY(album_entry), canonical_tag->album);
|
||||
set_entry_tag(GTK_ENTRY(date_entry), canonical_tag->year_recorded);
|
||||
set_entry_tag(GTK_ENTRY(tracknum_entry), canonical_tag->track_number);
|
||||
set_entry_tag(GTK_ENTRY(comment_entry), canonical_tag->comment);
|
||||
set_entry_tag(GTK_ENTRY(GTK_COMBO(genre_combo)->entry), canonical_tag->genre);
|
||||
set_entry_tag(GTK_ENTRY(title_entry) , FLAC_plugin__canonical_get(canonical_tag, L"TITLE"));
|
||||
set_entry_tag(GTK_ENTRY(artist_entry) , FLAC_plugin__canonical_get(canonical_tag, L"ARTIST"));
|
||||
set_entry_tag(GTK_ENTRY(album_entry) , FLAC_plugin__canonical_get(canonical_tag, L"ALBUM"));
|
||||
set_entry_tag(GTK_ENTRY(date_entry) , FLAC_plugin__canonical_get(canonical_tag, L"DATE"));
|
||||
set_entry_tag(GTK_ENTRY(tracknum_entry) , FLAC_plugin__canonical_get(canonical_tag, L"TRACKNUMBER"));
|
||||
set_entry_tag(GTK_ENTRY(comment_entry) , FLAC_plugin__canonical_get(canonical_tag, L"DESCRIPTION"));
|
||||
set_entry_tag(GTK_ENTRY(GTK_COMBO(genre_combo)->entry), FLAC_plugin__canonical_get(canonical_tag, L"GENRE"));
|
||||
}
|
||||
|
||||
static void save_tag(GtkWidget * w, gpointer data)
|
||||
@@ -153,21 +155,22 @@ static void save_tag(GtkWidget * w, gpointer data)
|
||||
(void)w;
|
||||
(void)data;
|
||||
|
||||
local__safe_free(canonical_tag->title);
|
||||
local__safe_free(canonical_tag->composer);
|
||||
local__safe_free(canonical_tag->album);
|
||||
local__safe_free(canonical_tag->year_recorded);
|
||||
local__safe_free(canonical_tag->track_number);
|
||||
local__safe_free(canonical_tag->comment);
|
||||
local__safe_free(canonical_tag->genre);
|
||||
canonical_tag->title = get_entry_tag(GTK_ENTRY(title_entry));
|
||||
canonical_tag->composer = get_entry_tag(GTK_ENTRY(artist_entry));
|
||||
canonical_tag->album = get_entry_tag(GTK_ENTRY(album_entry));
|
||||
canonical_tag->year_recorded = get_entry_tag(GTK_ENTRY(date_entry));
|
||||
canonical_tag->track_number = get_entry_tag(GTK_ENTRY(tracknum_entry));
|
||||
canonical_tag->comment = get_entry_tag(GTK_ENTRY(comment_entry));
|
||||
canonical_tag->genre = get_entry_tag(GTK_ENTRY(GTK_COMBO(genre_combo)->entry));
|
||||
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"TITLE")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"ARTIST")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"ALBUM")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"DATE")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"TRACKNUMBER")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"DESCRIPTION")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"GENRE")) ;
|
||||
|
||||
get_entry_tag(GTK_ENTRY(title_entry) , "TITLE");
|
||||
get_entry_tag(GTK_ENTRY(artist_entry) , "ARTIST");
|
||||
get_entry_tag(GTK_ENTRY(album_entry) , "ALBUM");
|
||||
get_entry_tag(GTK_ENTRY(date_entry) , "DATE");
|
||||
get_entry_tag(GTK_ENTRY(tracknum_entry) , "TRACKNUMBER");
|
||||
get_entry_tag(GTK_ENTRY(comment_entry) , "DESCRIPTION");
|
||||
get_entry_tag(GTK_ENTRY(GTK_COMBO(genre_combo)->entry), "GENRE");
|
||||
|
||||
FLAC_plugin__vorbiscomment_set(current_filename, canonical_tag);
|
||||
gtk_widget_destroy(window);
|
||||
}
|
||||
@@ -177,15 +180,13 @@ static void remove_tag(GtkWidget * w, gpointer data)
|
||||
(void)w;
|
||||
(void)data;
|
||||
|
||||
local__safe_free(canonical_tag->title);
|
||||
local__safe_free(canonical_tag->composer);
|
||||
local__safe_free(canonical_tag->album);
|
||||
local__safe_free(canonical_tag->year_recorded);
|
||||
local__safe_free(canonical_tag->track_number);
|
||||
local__safe_free(canonical_tag->comment);
|
||||
local__safe_free(canonical_tag->genre);
|
||||
|
||||
canonical_tag->title = canonical_tag->composer = canonical_tag->album = canonical_tag->year_recorded = canonical_tag->track_number = canonical_tag->comment = canonical_tag->genre = 0;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"TITLE")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"ARTIST")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"ALBUM")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"DATE")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"TRACKNUMBER")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"DESCRIPTION")) ;
|
||||
while (FLAC_plugin__canonical_remove(canonical_tag, L"GENRE")) ;
|
||||
|
||||
FLAC_plugin__vorbiscomment_set(current_filename, canonical_tag);
|
||||
gtk_widget_destroy(window);
|
||||
@@ -419,7 +420,7 @@ void FLAC_XMMS__file_info_box(char *filename)
|
||||
else
|
||||
canonical_tag = FLAC_plugin__canonical_tag_new();
|
||||
|
||||
FLAC_plugin__vorbiscomment_get(current_filename, canonical_tag);
|
||||
FLAC_plugin__vorbiscomment_get(current_filename, canonical_tag, /*sep=*/0);
|
||||
|
||||
show_tag();
|
||||
show_file_info();
|
||||
|
||||
@@ -167,9 +167,6 @@ void FLAC_XMMS__init()
|
||||
|
||||
xmms_cfg_read_boolean(cfg, "flac", "title.convert_char_set", &flac_cfg.title.convert_char_set);
|
||||
|
||||
if(!xmms_cfg_read_string(cfg, "flac", "title.file_char_set", &flac_cfg.title.file_char_set))
|
||||
flac_cfg.title.file_char_set = FLAC_plugin__charset_get_current();
|
||||
|
||||
if(!xmms_cfg_read_string(cfg, "flac", "title.user_char_set", &flac_cfg.title.user_char_set))
|
||||
flac_cfg.title.user_char_set = FLAC_plugin__charset_get_current();
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
#include <xmms/titlestring.h>
|
||||
|
||||
#include "FLAC/metadata.h"
|
||||
#include "plugin_common/id3v1.h"
|
||||
#include "plugin_common/id3v2.h"
|
||||
#include "plugin_common/canonical_tag.h"
|
||||
#include "charset.h"
|
||||
#include "configure.h"
|
||||
|
||||
@@ -65,6 +64,29 @@ static int local__getnum(char* str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *local__getfield(FLAC_Plugin__CanonicalTag *tag, const wchar_t *name)
|
||||
{
|
||||
const wchar_t *ucs2 = FLAC_plugin__canonical_get(tag, name);
|
||||
if (0 != ucs2) {
|
||||
char *utf8 = FLAC_plugin__convert_ucs2_to_utf8(FLAC_plugin__canonical_get(tag, name));
|
||||
if(flac_cfg.title.convert_char_set) {
|
||||
char *user = convert_from_utf8_to_user(utf8);
|
||||
free(utf8);
|
||||
return user;
|
||||
}
|
||||
else
|
||||
return utf8;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void local__safe_free(char *s)
|
||||
{
|
||||
if (0 != s)
|
||||
free(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function flac_format_song_title (tag, filename)
|
||||
*
|
||||
@@ -77,35 +99,32 @@ char *flac_format_song_title(char *filename)
|
||||
char *ret = NULL;
|
||||
TitleInput *input = NULL;
|
||||
FLAC_Plugin__CanonicalTag tag;
|
||||
char *title, *artist, *performer, *album, *date, *tracknumber, *genre, *description;
|
||||
|
||||
FLAC_plugin__canonical_tag_init(&tag);
|
||||
|
||||
FLAC_plugin__canonical_tag_get_combined(filename, &tag);
|
||||
FLAC_plugin__canonical_tag_get_combined(filename, &tag, /*sep=*/0);
|
||||
|
||||
if(flac_cfg.title.convert_char_set) {
|
||||
convert_from_file_to_user_in_place(&tag.title);
|
||||
convert_from_file_to_user_in_place(&tag.composer);
|
||||
convert_from_file_to_user_in_place(&tag.performer);
|
||||
convert_from_file_to_user_in_place(&tag.album);
|
||||
convert_from_file_to_user_in_place(&tag.year_recorded);
|
||||
convert_from_file_to_user_in_place(&tag.year_performed);
|
||||
convert_from_file_to_user_in_place(&tag.track_number);
|
||||
convert_from_file_to_user_in_place(&tag.tracks_in_album);
|
||||
convert_from_file_to_user_in_place(&tag.genre);
|
||||
convert_from_file_to_user_in_place(&tag.comment);
|
||||
}
|
||||
title = local__getfield(&tag, L"TITLE");
|
||||
artist = local__getfield(&tag, L"ARTIST");
|
||||
performer = local__getfield(&tag, L"PERFORMER");
|
||||
album = local__getfield(&tag, L"ALBUM");
|
||||
date = local__getfield(&tag, L"DATE");
|
||||
tracknumber = local__getfield(&tag, L"TRACKNUMBER");
|
||||
genre = local__getfield(&tag, L"GENRE");
|
||||
description = local__getfield(&tag, L"DESCRIPTION");
|
||||
|
||||
XMMS_NEW_TITLEINPUT(input);
|
||||
|
||||
input->performer = local__getstr(tag.performer);
|
||||
input->performer = local__getstr(performer);
|
||||
if(!input->performer)
|
||||
input->performer = local__getstr(tag.composer);
|
||||
input->album_name = local__getstr(tag.album);
|
||||
input->track_name = local__getstr(tag.title);
|
||||
input->track_number = local__getnum(tag.track_number);
|
||||
input->year = local__getnum(tag.year_recorded);
|
||||
input->genre = local__getstr(tag.genre);
|
||||
input->comment = local__getstr(tag.comment);
|
||||
input->performer = local__getstr(artist);
|
||||
input->album_name = local__getstr(album);
|
||||
input->track_name = local__getstr(title);
|
||||
input->track_number = local__getnum(tracknumber);
|
||||
input->year = local__getnum(date);
|
||||
input->genre = local__getstr(genre);
|
||||
input->comment = local__getstr(description);
|
||||
|
||||
input->file_name = g_basename(filename);
|
||||
input->file_path = filename;
|
||||
@@ -123,5 +142,13 @@ char *flac_format_song_title(char *filename)
|
||||
}
|
||||
|
||||
FLAC_plugin__canonical_tag_clear(&tag);
|
||||
local__safe_free(title);
|
||||
local__safe_free(artist);
|
||||
local__safe_free(performer);
|
||||
local__safe_free(album);
|
||||
local__safe_free(date);
|
||||
local__safe_free(tracknumber);
|
||||
local__safe_free(genre);
|
||||
local__safe_free(description);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user