diff --git a/src/notify.c b/src/notify.c index b867374..df3e7af 100644 --- a/src/notify.c +++ b/src/notify.c @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef __APPLE__ #include @@ -232,13 +233,16 @@ void terminate_notify() } #ifdef _SOUND_NOTIFY -void set_sound(Notification sound, const char* value) +int set_sound(Notification sound, const char* value) { free(Control.sounds[sound]); size_t len = strlen(value) + 1; Control.sounds[sound] = calloc(1, len); memcpy(Control.sounds[sound], value, len); + + struct stat buf; + return stat(value, &buf) == 0; } int play_sound_internal(Notification what, _Bool loop) diff --git a/src/notify.h b/src/notify.h index 1a3089c..6df75e6 100644 --- a/src/notify.h +++ b/src/notify.h @@ -66,8 +66,8 @@ void terminate_notify(); int notify(ToxWindow* self, Notification notif, uint64_t flags); #ifdef _SOUND_NOTIFY -void set_sound(Notification sound, const char* value); +int set_sound(Notification sound, const char* value); void stop_sound(int sound); #endif /* _SOUND_NOTIFY */ -#endif /* _notify_h */ \ No newline at end of file +#endif /* _notify_h */ diff --git a/src/settings.c b/src/settings.c index ac4c915..4ab5276 100644 --- a/src/settings.c +++ b/src/settings.c @@ -36,6 +36,10 @@ #include "settings.h" #include "line_info.h" +#ifndef PACKAGE_DATADIR + #define PACKAGE_DATADIR "." +#endif + const struct _ui_strings { const char* self; const char* timestamps; @@ -197,38 +201,60 @@ int settings_load(struct user_settings *s, const char *patharg) #ifdef _SOUND_NOTIFY if ((setting = config_lookup(cfg, sound_strings.self)) != NULL) { - if ( config_setting_lookup_string(setting, sound_strings.error, &str) == CONFIG_TRUE ) - set_sound(error, str); - - if ( config_setting_lookup_string(setting, sound_strings.user_log_in, &str) ) - set_sound(user_log_in, str); + if ( (config_setting_lookup_string(setting, sound_strings.error, &str) != CONFIG_TRUE) || + !set_sound(error, str) ) + set_sound(error, PACKAGE_DATADIR "/sounds/Error.wav"); - if ( config_setting_lookup_string(setting, sound_strings.self_log_in, &str) ) - set_sound(self_log_in, str); + if ( !config_setting_lookup_string(setting, sound_strings.user_log_in, &str) || + !set_sound(user_log_in, str) ) + set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ContactLogsIn.wav"); - if ( config_setting_lookup_string(setting, sound_strings.user_log_out, &str) ) - set_sound(user_log_out, str); + if ( !config_setting_lookup_string(setting, sound_strings.self_log_in, &str) || + !set_sound(self_log_in, str) ) + set_sound(self_log_in, PACKAGE_DATADIR "/sounds/LogIn.wav"); - if ( config_setting_lookup_string(setting, sound_strings.self_log_out, &str) ) - set_sound(self_log_out, str); + if ( !config_setting_lookup_string(setting, sound_strings.user_log_out, &str) || + !set_sound(user_log_out, str) ) + set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ContactLogsOut.wav"); - if ( config_setting_lookup_string(setting, sound_strings.call_incoming, &str) ) - set_sound(call_incoming, str); + if ( !config_setting_lookup_string(setting, sound_strings.self_log_out, &str) || + !set_sound(self_log_out, str) ) + set_sound(self_log_out, PACKAGE_DATADIR "/sounds/LogOut.wav"); - if ( config_setting_lookup_string(setting, sound_strings.call_outgoing, &str) ) - set_sound(call_outgoing, str); + if ( !config_setting_lookup_string(setting, sound_strings.call_incoming, &str) || + !set_sound(call_incoming, str) ) + set_sound(call_incoming, PACKAGE_DATADIR "/sounds/IncomingCall.wav"); - if ( config_setting_lookup_string(setting, sound_strings.generic_message, &str) ) - set_sound(generic_message, str); + if ( !config_setting_lookup_string(setting, sound_strings.call_outgoing, &str) || + !set_sound(call_outgoing, str) ) + set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/OutgoingCall.wav"); - if ( config_setting_lookup_string(setting, sound_strings.transfer_pending, &str) ) - set_sound(transfer_pending, str); + if ( config_setting_lookup_string(setting, sound_strings.generic_message, &str) || + !set_sound(generic_message, str) ) + set_sound(generic_message, PACKAGE_DATADIR "/sounds/NewMessage.wav"); - if ( config_setting_lookup_string(setting, sound_strings.transfer_completed, &str) ) - set_sound(transfer_completed, str); + if ( !config_setting_lookup_string(setting, sound_strings.transfer_pending, &str) || + !set_sound(transfer_pending, str) ) + set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/TransferPending.wav"); + + if ( !config_setting_lookup_string(setting, sound_strings.transfer_completed, &str) || + !set_sound(transfer_completed, str) ) + set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/TransferComplete.wav"); + } + else { + set_sound(error, PACKAGE_DATADIR "/sounds/Error.wav"); + set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ContactLogsIn.wav"); + set_sound(self_log_in, PACKAGE_DATADIR "/sounds/LogIn.wav"); + set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ContactLogsOut.wav"); + set_sound(self_log_out, PACKAGE_DATADIR "/sounds/LogOut.wav"); + set_sound(call_incoming, PACKAGE_DATADIR "/sounds/IncomingCall.wav"); + set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/OutgoingCall.wav"); + set_sound(generic_message, PACKAGE_DATADIR "/sounds/NewMessage.wav"); + set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/TransferPending.wav"); + set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/TransferComplete.wav"); } #endif config_destroy(cfg); return 0; -} \ No newline at end of file +}