Store just the filename if the sound file comes from the default sound dir

And get rid of some hardcoding while we're at it
This commit is contained in:
Berke Viktor 2013-04-28 04:12:00 +02:00
parent ea48d18130
commit a3ba8d575e
4 changed files with 18 additions and 4 deletions

View File

@ -840,7 +840,7 @@ load_config (void)
g_mkdir (buf, 0700); g_mkdir (buf, 0700);
g_free (buf); g_free (buf);
buf = g_build_filename (get_xdir (), "sounds", NULL); buf = g_build_filename (get_xdir (), HEXCHAT_SOUND_DIR, NULL);
g_mkdir (buf, 0700); g_mkdir (buf, 0700);
g_free (buf); g_free (buf);
} }

View File

@ -69,4 +69,6 @@ struct prefs
#define TYPE_INT 1 #define TYPE_INT 1
#define TYPE_BOOL 2 #define TYPE_BOOL 2
#define HEXCHAT_SOUND_DIR "sounds"
#endif #endif

View File

@ -2231,7 +2231,7 @@ sound_play (const char *file, gboolean quiet)
} }
else else
{ {
wavfile = g_build_filename (get_xdir (), "sounds", file, NULL); wavfile = g_build_filename (get_xdir (), HEXCHAT_SOUND_DIR, file, NULL);
} }
if (g_access (wavfile, R_OK) == 0) if (g_access (wavfile, R_OK) == 0)

View File

@ -1618,14 +1618,26 @@ setup_snd_filereq_cb (GtkWidget *entry, char *file)
if (file) if (file)
{ {
if (file[0]) if (file[0])
{
/* Use just the filename if the given sound file is in the default <config>/sounds directory.
* We're comparing absolute paths so this won't work in portable mode which uses a relative path.
*/
if (!strcmp (g_path_get_dirname (file), g_build_filename (get_xdir (), HEXCHAT_SOUND_DIR, NULL)))
{
gtk_entry_set_text (GTK_ENTRY (entry), g_path_get_basename (file));
}
else
{
gtk_entry_set_text (GTK_ENTRY (entry), file); gtk_entry_set_text (GTK_ENTRY (entry), file);
} }
} }
}
}
static void static void
setup_snd_browse_cb (GtkWidget *button, GtkEntry *entry) setup_snd_browse_cb (GtkWidget *button, GtkEntry *entry)
{ {
char *sounds_dir = g_build_filename (get_xdir (), "sounds", NULL); char *sounds_dir = g_build_filename (get_xdir (), HEXCHAT_SOUND_DIR, NULL);
gtkutil_file_req (_("Select a sound file"), setup_snd_filereq_cb, entry, sounds_dir, NULL, FRF_FILTERISINITIAL); gtkutil_file_req (_("Select a sound file"), setup_snd_filereq_cb, entry, sounds_dir, NULL, FRF_FILTERISINITIAL);
g_free (sounds_dir); g_free (sounds_dir);
} }