Skip to content

Commit 04fbf5f

Browse files
author
mannol1
committed
Merge pull request #195 from Ansa89/notify-fix
Add hardcoded path for sound notifications
2 parents 50fca4c + 3cc629c commit 04fbf5f

3 files changed

Lines changed: 55 additions & 25 deletions

File tree

src/notify.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <stdio.h>
3030
#include <unistd.h>
3131
#include <time.h>
32+
#include <sys/stat.h>
3233

3334
#ifdef __APPLE__
3435
#include <OpenAL/al.h>
@@ -232,13 +233,16 @@ void terminate_notify()
232233
}
233234

234235
#ifdef _SOUND_NOTIFY
235-
void set_sound(Notification sound, const char* value)
236+
int set_sound(Notification sound, const char* value)
236237
{
237238
free(Control.sounds[sound]);
238239

239240
size_t len = strlen(value) + 1;
240241
Control.sounds[sound] = calloc(1, len);
241242
memcpy(Control.sounds[sound], value, len);
243+
244+
struct stat buf;
245+
return stat(value, &buf) == 0;
242246
}
243247

244248
int play_sound_internal(Notification what, _Bool loop)

src/notify.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ void terminate_notify();
6666
int notify(ToxWindow* self, Notification notif, uint64_t flags);
6767

6868
#ifdef _SOUND_NOTIFY
69-
void set_sound(Notification sound, const char* value);
69+
int set_sound(Notification sound, const char* value);
7070
void stop_sound(int sound);
7171
#endif /* _SOUND_NOTIFY */
7272

73-
#endif /* _notify_h */
73+
#endif /* _notify_h */

src/settings.c

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include "settings.h"
3737
#include "line_info.h"
3838

39+
#ifndef PACKAGE_DATADIR
40+
#define PACKAGE_DATADIR "."
41+
#endif
42+
3943
const struct _ui_strings {
4044
const char* self;
4145
const char* timestamps;
@@ -197,38 +201,60 @@ int settings_load(struct user_settings *s, const char *patharg)
197201

198202
#ifdef _SOUND_NOTIFY
199203
if ((setting = config_lookup(cfg, sound_strings.self)) != NULL) {
200-
if ( config_setting_lookup_string(setting, sound_strings.error, &str) == CONFIG_TRUE )
201-
set_sound(error, str);
202-
203-
if ( config_setting_lookup_string(setting, sound_strings.user_log_in, &str) )
204-
set_sound(user_log_in, str);
204+
if ( (config_setting_lookup_string(setting, sound_strings.error, &str) != CONFIG_TRUE) ||
205+
!set_sound(error, str) )
206+
set_sound(error, PACKAGE_DATADIR "/sounds/Error.wav");
207+
208+
if ( !config_setting_lookup_string(setting, sound_strings.user_log_in, &str) ||
209+
!set_sound(user_log_in, str) )
210+
set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ContactLogsIn.wav");
205211

206-
if ( config_setting_lookup_string(setting, sound_strings.self_log_in, &str) )
207-
set_sound(self_log_in, str);
212+
if ( !config_setting_lookup_string(setting, sound_strings.self_log_in, &str) ||
213+
!set_sound(self_log_in, str) )
214+
set_sound(self_log_in, PACKAGE_DATADIR "/sounds/LogIn.wav");
208215

209-
if ( config_setting_lookup_string(setting, sound_strings.user_log_out, &str) )
210-
set_sound(user_log_out, str);
216+
if ( !config_setting_lookup_string(setting, sound_strings.user_log_out, &str) ||
217+
!set_sound(user_log_out, str) )
218+
set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ContactLogsOut.wav");
211219

212-
if ( config_setting_lookup_string(setting, sound_strings.self_log_out, &str) )
213-
set_sound(self_log_out, str);
220+
if ( !config_setting_lookup_string(setting, sound_strings.self_log_out, &str) ||
221+
!set_sound(self_log_out, str) )
222+
set_sound(self_log_out, PACKAGE_DATADIR "/sounds/LogOut.wav");
214223

215-
if ( config_setting_lookup_string(setting, sound_strings.call_incoming, &str) )
216-
set_sound(call_incoming, str);
224+
if ( !config_setting_lookup_string(setting, sound_strings.call_incoming, &str) ||
225+
!set_sound(call_incoming, str) )
226+
set_sound(call_incoming, PACKAGE_DATADIR "/sounds/IncomingCall.wav");
217227

218-
if ( config_setting_lookup_string(setting, sound_strings.call_outgoing, &str) )
219-
set_sound(call_outgoing, str);
228+
if ( !config_setting_lookup_string(setting, sound_strings.call_outgoing, &str) ||
229+
!set_sound(call_outgoing, str) )
230+
set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/OutgoingCall.wav");
220231

221-
if ( config_setting_lookup_string(setting, sound_strings.generic_message, &str) )
222-
set_sound(generic_message, str);
232+
if ( config_setting_lookup_string(setting, sound_strings.generic_message, &str) ||
233+
!set_sound(generic_message, str) )
234+
set_sound(generic_message, PACKAGE_DATADIR "/sounds/NewMessage.wav");
223235

224-
if ( config_setting_lookup_string(setting, sound_strings.transfer_pending, &str) )
225-
set_sound(transfer_pending, str);
236+
if ( !config_setting_lookup_string(setting, sound_strings.transfer_pending, &str) ||
237+
!set_sound(transfer_pending, str) )
238+
set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/TransferPending.wav");
226239

227-
if ( config_setting_lookup_string(setting, sound_strings.transfer_completed, &str) )
228-
set_sound(transfer_completed, str);
240+
if ( !config_setting_lookup_string(setting, sound_strings.transfer_completed, &str) ||
241+
!set_sound(transfer_completed, str) )
242+
set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/TransferComplete.wav");
243+
}
244+
else {
245+
set_sound(error, PACKAGE_DATADIR "/sounds/Error.wav");
246+
set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ContactLogsIn.wav");
247+
set_sound(self_log_in, PACKAGE_DATADIR "/sounds/LogIn.wav");
248+
set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ContactLogsOut.wav");
249+
set_sound(self_log_out, PACKAGE_DATADIR "/sounds/LogOut.wav");
250+
set_sound(call_incoming, PACKAGE_DATADIR "/sounds/IncomingCall.wav");
251+
set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/OutgoingCall.wav");
252+
set_sound(generic_message, PACKAGE_DATADIR "/sounds/NewMessage.wav");
253+
set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/TransferPending.wav");
254+
set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/TransferComplete.wav");
229255
}
230256
#endif
231257

232258
config_destroy(cfg);
233259
return 0;
234-
}
260+
}

0 commit comments

Comments
 (0)