[Easytag-mailing] [PATCH 2/3] Add a new option to trim spaces when renaming files
- From: "Christoph J. Thompson" <cjsthompson gmail com>
- To: easytag-mailing lists sourceforge net
- Subject: [Easytag-mailing] [PATCH 2/3] Add a new option to trim spaces when renaming files
- Date: Fri, 16 Mar 2012 18:05:12 +0100
Add a new option to trim spaces when renaming files. This has been
throroughly tested with many thousand files for over two years.
modified: src/misc.c
modified: src/prefs.c
modified: src/prefs.h
modified: src/scan.c
modified: src/scan.h
modified: src/setting.c
modified: src/setting.h
---
src/misc.c | 4 ++++
src/prefs.c | 17 +++++++----------
src/prefs.h | 1 +
src/scan.c | 36 ++++++++++++++++++++++++++++++++----
src/scan.h | 1 +
src/setting.c | 2 ++
src/setting.h | 1 +
7 files changed, 48 insertions(+), 14 deletions(-)
diff --git a/src/misc.c b/src/misc.c
index cc57887..dd33c13 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1578,6 +1578,10 @@ void Playlist_Write_Button_Pressed (void)
{
Scan_Convert_Space_Into_Undescore(playlist_basename_utf8);
}
+ if (RFS_REMOVE_SPACES)
+ {
+ Scan_Remove_Spaces(playlist_basename_utf8);
+ }
}else // PLAYLIST_USE_DIR_NAME
{
diff --git a/src/prefs.c b/src/prefs.c
index 6bea8ee..19775b5 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -1016,25 +1016,23 @@ void Open_OptionsWindow (void)
vbox = gtk_vbox_new(FALSE,2);
gtk_container_add(GTK_CONTAINER(Frame),vbox);
gtk_container_set_border_width(GTK_CONTAINER(vbox),2);
-
- RFSConvertUnderscoreAndP20IntoSpace = gtk_check_button_new_with_label(_("Convert underscore "
- "character '_' and string '%20' to space ' '"));
- RFSConvertSpaceIntoUnderscore = gtk_check_button_new_with_label(_("Convert space ' ' to underscore '_'"));
+ RFSConvertUnderscoreAndP20IntoSpace = gtk_radio_button_new_with_label(NULL, _("Convert underscore " "character '_' and string '%20' to space ' '"));
+ RFSConvertSpaceIntoUnderscore = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(RFSConvertUnderscoreAndP20IntoSpace), _("Convert space ' ' to underscore '_'"));
+ RFSRemoveSpaces = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(RFSConvertUnderscoreAndP20IntoSpace), _("Remove spaces"));
gtk_box_pack_start(GTK_BOX(vbox),RFSConvertUnderscoreAndP20IntoSpace,FALSE,FALSE,0);
gtk_box_pack_start(GTK_BOX(vbox),RFSConvertSpaceIntoUnderscore, FALSE,FALSE,0);
- g_signal_connect_swapped(G_OBJECT(RFSConvertUnderscoreAndP20IntoSpace),"toggled",
- G_CALLBACK(Scanner_Convert_Check_Button_Toggled_1),G_OBJECT(RFSConvertSpaceIntoUnderscore));
- g_signal_connect_swapped(G_OBJECT(RFSConvertSpaceIntoUnderscore),"toggled",
- G_CALLBACK(Scanner_Convert_Check_Button_Toggled_1),G_OBJECT(RFSConvertUnderscoreAndP20IntoSpace));
-
+ gtk_box_pack_start(GTK_BOX(vbox),RFSRemoveSpaces, FALSE,FALSE,0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(RFSConvertUnderscoreAndP20IntoSpace),
RFS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(RFSConvertSpaceIntoUnderscore),
RFS_CONVERT_SPACE_INTO_UNDERSCORE);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(RFSRemoveSpaces),
+ RFS_REMOVE_SPACES);
gtk_tooltips_set_tip(Tips,RFSConvertUnderscoreAndP20IntoSpace,_("If activated, this conversion "
"will be used when applying a mask from the scanner for filenames."),NULL);
gtk_tooltips_set_tip(Tips,RFSConvertSpaceIntoUnderscore,_("If activated, this conversion "
"will be used when applying a mask from the scanner for filenames."),NULL);
+ gtk_tooltips_set_tip(Tips,RFSRemoveSpaces,_("If activated, this conversion " "will be used when applying a mask from the scanner for filenames."),NULL);
/* Character conversion for the 'Process Fields' scanner (=> PFS...) */
Frame = gtk_frame_new (_("Process Fields Scanner - Character Conversion"));
@@ -1927,7 +1925,6 @@ void Scanner_Convert_Check_Button_Toggled_1 (GtkObject *object_rec, GtkObject *o
}
-
void DefaultPathToMp3_Combo_Add_String (void)
{
const gchar *path;
diff --git a/src/prefs.h b/src/prefs.h
index 7e3f42e..08d6d3b 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -121,6 +121,7 @@ GtkWidget *FTSConvertUnderscoreAndP20IntoSpace;
GtkWidget *FTSConvertSpaceIntoUnderscore;
GtkWidget *RFSConvertUnderscoreAndP20IntoSpace;
GtkWidget *RFSConvertSpaceIntoUnderscore;
+GtkWidget *RFSRemoveSpaces;
GtkWidget *PFSDontUpperSomeWords;
GtkWidget *OverwriteTagField;
GtkWidget *OpenScannerWindowOnStartup;
diff --git a/src/scan.c b/src/scan.c
index b41769c..4b73b4c 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -798,7 +798,13 @@ gchar *Scan_Generate_New_Filename_From_Mask (ET_File *ETFile, gchar *mask, gbool
Scan_Convert_P20_Into_Space(mask_item->string);
}
if (RFS_CONVERT_SPACE_INTO_UNDERSCORE)
+ {
Scan_Convert_Space_Into_Undescore(mask_item->string);
+ }
+ if (RFS_REMOVE_SPACES)
+ {
+ Scan_Remove_Spaces(mask_item->string);
+ }
}else
{
mask_item->type = EMPTY_FIELD;
@@ -1669,7 +1675,7 @@ void Scan_Process_Fields_Insert_Space (gchar **string)
/*
* The function removes the duplicated spaces
- * No needed to reallocate
+ * No need to reallocate
*/
void Scan_Process_Fields_Keep_One_Space (gchar *string)
{
@@ -1693,7 +1699,7 @@ void Scan_Process_Fields_Keep_One_Space (gchar *string)
/*
* Function to replace underscore '_' by a space
- * No needed to reallocate
+ * No need to reallocate
*/
void Scan_Convert_Underscore_Into_Space (gchar *string)
{
@@ -1705,7 +1711,7 @@ void Scan_Convert_Underscore_Into_Space (gchar *string)
/*
* Function to replace %20 by a space
- * No needed to reallocate
+ * No need to reallocate
*/
void Scan_Convert_P20_Into_Space (gchar *string)
{
@@ -1722,8 +1728,30 @@ void Scan_Convert_P20_Into_Space (gchar *string)
}
/*
+ * Function to remove spaces
+ * No need to reallocate
+ */
+void Scan_Remove_Spaces (gchar *string)
+{
+ int nextnotspace = 0, pos = 0;
+
+ while(string[pos] != '\0')
+ {
+ if(string[pos] == ' ')
+ {
+ nextnotspace = pos;
+ while(string[++nextnotspace] == ' ');
+ string[pos] = string[nextnotspace];
+ string[nextnotspace] = ' ';
+ continue;
+ }
+ pos++;
+ }
+}
+
+/*
* Function to replace space by '_'
- * No needed to reallocate
+ * No need to reallocate
*/
void Scan_Convert_Space_Into_Undescore (gchar *string)
{
diff --git a/src/scan.h b/src/scan.h
index de151a2..9dd13df 100644
--- a/src/scan.h
+++ b/src/scan.h
@@ -79,6 +79,7 @@ void Scan_Convert_Underscore_Into_Space (gchar *string);
void Scan_Convert_P20_Into_Space (gchar *string);
void Scan_Convert_Space_Into_Undescore (gchar *string);
void Scan_Convert_Character (gchar **string);
+void Scan_Remove_Spaces (gchar *string);
void Init_ScannerWindow (void);
void Open_ScannerWindow (gint scanner_type);
diff --git a/src/setting.c b/src/setting.c
index b252724..1662c11 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -185,6 +185,7 @@ tConfigVariable Config_Variables[] =
{"fts_convert_space_into_underscore", CV_TYPE_BOOL,&FTS_CONVERT_SPACE_INTO_UNDERSCORE },
{"rfs_convert_underscore_and_p20_into_space",CV_TYPE_BOOL,&RFS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE },
{"rfs_convert_space_into_underscore", CV_TYPE_BOOL,&RFS_CONVERT_SPACE_INTO_UNDERSCORE },
+ {"rfs_remove_spaces", CV_TYPE_BOOL,&RFS_REMOVE_SPACES },
{"pfs_dont_upper_some_words", CV_TYPE_BOOL,&PFS_DONT_UPPER_SOME_WORDS },
{"overwrite_tag_field", CV_TYPE_BOOL, &OVERWRITE_TAG_FIELD },
{"set_default_comment", CV_TYPE_BOOL, &SET_DEFAULT_COMMENT },
@@ -741,6 +742,7 @@ void Apply_Changes_Of_Preferences_Window (void)
// Rename File Scanner
RFS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE = GTK_TOGGLE_BUTTON(RFSConvertUnderscoreAndP20IntoSpace)->active;
RFS_CONVERT_SPACE_INTO_UNDERSCORE = GTK_TOGGLE_BUTTON(RFSConvertSpaceIntoUnderscore)->active;
+ RFS_REMOVE_SPACES = GTK_TOGGLE_BUTTON(RFSRemoveSpaces)->active;
// Process File Scanner
PFS_DONT_UPPER_SOME_WORDS = GTK_TOGGLE_BUTTON(PFSDontUpperSomeWords)->active;
diff --git a/src/setting.h b/src/setting.h
index fb2e6f4..822cca9 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -139,6 +139,7 @@ gint FTS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE;
gint FTS_CONVERT_SPACE_INTO_UNDERSCORE;
gint RFS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE;
gint RFS_CONVERT_SPACE_INTO_UNDERSCORE;
+gint RFS_REMOVE_SPACES;
gint PFS_DONT_UPPER_SOME_WORDS;
gint OVERWRITE_TAG_FIELD;
gint SET_DEFAULT_COMMENT;
--
1.7.4.4
--
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]