1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 20:53:01 +01:00

Added sounds

This commit is contained in:
mannol 2014-07-21 01:12:13 +02:00
parent df676423a7
commit 933d46553f
15 changed files with 338 additions and 348 deletions

View File

@ -27,6 +27,7 @@
#include "chat_commands.h"
#include "global_commands.h"
#include "line_info.h"
#include "notify.h"
#include <curses.h>
#include <string.h>
@ -82,17 +83,17 @@ struct _ASettings {
Call calls[MAX_CALLS];
} ASettins;
void callback_recv_invite ( int32_t call_index, void *arg );
void callback_recv_ringing ( int32_t call_index, void *arg );
void callback_recv_starting ( int32_t call_index, void *arg );
void callback_recv_ending ( int32_t call_index, void *arg );
void callback_recv_error ( int32_t call_index, void *arg );
void callback_call_started ( int32_t call_index, void *arg );
void callback_call_canceled ( int32_t call_index, void *arg );
void callback_call_rejected ( int32_t call_index, void *arg );
void callback_call_ended ( int32_t call_index, void *arg );
void callback_requ_timeout ( int32_t call_index, void *arg );
void callback_peer_timeout ( int32_t call_index, void *arg );
void callback_recv_invite ( void* av, int32_t call_index, void *arg );
void callback_recv_ringing ( void* av, int32_t call_index, void *arg );
void callback_recv_starting ( void* av, int32_t call_index, void *arg );
void callback_recv_ending ( void* av, int32_t call_index, void *arg );
void callback_call_started ( void* av, int32_t call_index, void *arg );
void callback_call_canceled ( void* av, int32_t call_index, void *arg );
void callback_call_rejected ( void* av, int32_t call_index, void *arg );
void callback_call_ended ( void* av, int32_t call_index, void *arg );
void callback_requ_timeout ( void* av, int32_t call_index, void *arg );
void callback_peer_timeout ( void* av, int32_t call_index, void *arg );
void callback_media_change ( void* av, int32_t call_index, void *arg );
int stop_transmission(int call_index);
void write_device_callback(ToxAv* av, int32_t call_index, int16_t* data, int size);
@ -127,19 +128,19 @@ ToxAv *init_audio(ToxWindow *self, Tox *tox)
return ASettins.av = NULL;
}
toxav_register_callstate_callback(callback_call_started, av_OnStart, self);
toxav_register_callstate_callback(callback_call_canceled, av_OnCancel, self);
toxav_register_callstate_callback(callback_call_rejected, av_OnReject, self);
toxav_register_callstate_callback(callback_call_ended, av_OnEnd, self);
toxav_register_callstate_callback(callback_recv_invite, av_OnInvite, self);
toxav_register_callstate_callback(ASettins.av, callback_call_started, av_OnStart, self);
toxav_register_callstate_callback(ASettins.av, callback_call_canceled, av_OnCancel, self);
toxav_register_callstate_callback(ASettins.av, callback_call_rejected, av_OnReject, self);
toxav_register_callstate_callback(ASettins.av, callback_call_ended, av_OnEnd, self);
toxav_register_callstate_callback(ASettins.av, callback_recv_invite, av_OnInvite, self);
toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging, self);
toxav_register_callstate_callback(callback_recv_starting, av_OnStarting, self);
toxav_register_callstate_callback(callback_recv_ending, av_OnEnding, self);
toxav_register_callstate_callback(ASettins.av, callback_recv_ringing, av_OnRinging, self);
toxav_register_callstate_callback(ASettins.av, callback_recv_starting, av_OnStarting, self);
toxav_register_callstate_callback(ASettins.av, callback_recv_ending, av_OnEnding, self);
toxav_register_callstate_callback(callback_recv_error, av_OnError, self);
toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, self);
toxav_register_callstate_callback(callback_peer_timeout, av_OnPeerTimeout, self);
toxav_register_callstate_callback(ASettins.av, callback_requ_timeout, av_OnRequestTimeout, self);
toxav_register_callstate_callback(ASettins.av, callback_peer_timeout, av_OnPeerTimeout, self);
toxav_register_callstate_callback(ASettins.av, callback_media_change, av_OnMediaChange, self);
toxav_register_audio_recv_callback(ASettins.av, write_device_callback);
@ -240,15 +241,15 @@ int stop_transmission(int call_index)
#define CB_BODY(call_idx, Arg, onFunc) do { ToxWindow* windows = (Arg); int i;\
for (i = 0; i < MAX_WINDOWS_NUM; ++i) if (windows[i].onFunc != NULL) windows[i].onFunc(&windows[i], ASettins.av, call_idx); } while (0)
void callback_recv_invite ( int32_t call_index, void* arg )
void callback_recv_invite ( void* av, int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onInvite);
}
void callback_recv_ringing ( int32_t call_index, void* arg )
void callback_recv_ringing ( void* av, int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onRinging);
}
void callback_recv_starting ( int32_t call_index, void* arg )
void callback_recv_starting ( void* av, int32_t call_index, void* arg )
{
ToxWindow* windows = arg;
int i;
@ -261,17 +262,13 @@ void callback_recv_starting ( int32_t call_index, void* arg )
return;
}
}
void callback_recv_ending ( int32_t call_index, void* arg )
void callback_recv_ending ( void* av, int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onEnding);
stop_transmission(call_index);
}
void callback_recv_error ( int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onError);
stop_transmission(call_index);
}
void callback_call_started ( int32_t call_index, void* arg )
void callback_call_started ( void* av, int32_t call_index, void* arg )
{
ToxWindow* windows = arg;
int i;
@ -284,28 +281,28 @@ void callback_call_started ( int32_t call_index, void* arg )
}
}
}
void callback_call_canceled ( int32_t call_index, void* arg )
void callback_call_canceled ( void* av, int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onCancel);
/* In case call is active */
stop_transmission(call_index);
}
void callback_call_rejected ( int32_t call_index, void* arg )
void callback_call_rejected ( void* av, int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onReject);
}
void callback_call_ended ( int32_t call_index, void* arg )
void callback_call_ended ( void* av, int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onEnd);
stop_transmission(call_index);
}
void callback_requ_timeout ( int32_t call_index, void* arg )
void callback_requ_timeout ( void* av, int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onRequestTimeout);
}
void callback_peer_timeout ( int32_t call_index, void* arg )
void callback_peer_timeout ( void* av, int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onPeerTimeout);
stop_transmission(call_index);
@ -314,6 +311,10 @@ void callback_peer_timeout ( int32_t call_index, void* arg )
*/
toxav_stop_call(ASettins.av, call_index);
}
void callback_media_change(void* av, int32_t call_index, void* arg)
{
/*... TODO cance all media change requests */
}
/*
* End of Callbacks
*/
@ -476,6 +477,9 @@ void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
goto on_error;
}
stop_sound(self->active_sound);
self->active_sound = -1;
/* Callback will print status... */
return;

View File

@ -40,6 +40,7 @@
#ifdef _SUPPORT_AUDIO
#include "audio_call.h"
#include "notify.h"
#endif /* _SUPPORT_AUDIO */
extern char *DATA_FILE;
@ -48,7 +49,7 @@ extern FileSender file_senders[MAX_FILES];
extern ToxicFriend friends[MAX_FRIENDS_NUM];
extern struct _Winthread Winthread;
extern struct user_settings *user_settings;
extern struct user_settings *user_settings_;
#ifdef _SUPPORT_AUDIO
static void init_infobox(ToxWindow *self);
@ -155,7 +156,8 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *msg
line_info_add(self, timefrmt, nick, NULL, msg, IN_MSG, 0, 0);
write_to_log(msg, nick, ctx->log, false);
alert_window(self, WINDOW_ALERT_1, true);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS);
}
static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
@ -165,12 +167,14 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_
StatusBar *statusbar = self->stb;
if (status == 1) {
if (status == 1) { /* Friend shows online */
statusbar->is_online = true;
friends[num].is_typing = tox_get_is_typing(m, num);
} else {
notify(self, user_log_in, NT_NOFOCUS);
} else { /* Friend goes offline */
statusbar->is_online = false;
friends[num].is_typing = 0;
notify(self, user_log_out, NT_NOFOCUS);
}
}
@ -197,7 +201,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const char *acti
line_info_add(self, timefrmt, nick, NULL, action, ACTION, 0, 0);
write_to_log(action, nick, ctx->log, true);
alert_window(self, WINDOW_ALERT_1, true);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS);
}
static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *nick, uint16_t len)
@ -267,9 +271,9 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
}
/* use specified path in config if possible */
if (user_settings->download_path[0]) {
snprintf(filename_path, sizeof(filename_path), "%s%s", user_settings->download_path, filename_nopath);
len += strlen(user_settings->download_path);
if (user_settings_->download_path[0]) {
snprintf(filename_path, sizeof(filename_path), "%s%s", user_settings_->download_path, filename_nopath);
len += strlen(user_settings_->download_path);
}
if (len >= sizeof(friends[num].file_receiver.filenames[filenum])) {
@ -317,7 +321,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
friends[num].file_receiver.size[filenum] = filesize;
strcpy(friends[num].file_receiver.filenames[filenum], filename);
alert_window(self, WINDOW_ALERT_2, true);
notify(self, transfer_pending, NT_WNDALERT_2 | NT_NOFOCUS);
}
static void chat_close_file_receiver(int32_t num, uint8_t filenum)
@ -356,6 +360,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
if (receive_send == 1) {
snprintf(msg, sizeof(msg), "File transfer for '%s' accepted (%.1f%%)", filename, 0.0);
file_senders[i].line_id = self->chatwin->hst->line_end->id + 1;
notify(self, unknown, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2);
}
break;
@ -366,19 +371,20 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
if (receive_send == 0)
chat_close_file_receiver(num, filenum);
notify(self, error, NT_NOFOCUS | NT_WNDALERT_2);
break;
case TOX_FILECONTROL_FINISHED:
if (receive_send == 0) {
snprintf(msg, sizeof(msg), "File transfer for '%s' complete.", filename);
chat_close_file_receiver(num, filenum);
notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2);
}
break;
}
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
alert_window(self, WINDOW_ALERT_2, true);
}
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const char *data,
@ -431,7 +437,8 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, co
sizeof(friends[friendnumber].groupchat_key));
friends[friendnumber].groupchat_pending = true;
alert_window(self, WINDOW_ALERT_2, true);
notify(self, generic_message, NT_WNDALERT_2);
}
/* Av Stuff */
@ -446,7 +453,9 @@ void chat_onInvite (ToxWindow *self, ToxAv *av, int call_index)
self->call_idx = call_index;
line_info_add(self, NULL, NULL, NULL, "Incoming audio call! Type: \"/answer\" or \"/reject\"", SYS_MSG, 0, 0);
alert_window(self, WINDOW_ALERT_0, true);
if (self->active_sound == -1)
self->active_sound = notify(self, call_incoming, NT_LOOP | NT_WNDALERT_0);
}
void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
@ -455,6 +464,9 @@ void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
return;
line_info_add(self, NULL, NULL, NULL, "Ringing...\"cancel\" ?", SYS_MSG, 0, 0);
if (self->active_sound == -1)
self->active_sound = notify(self, call_outgoing, NT_LOOP);
}
void chat_onStarting (ToxWindow *self, ToxAv *av, int call_index)
@ -465,6 +477,8 @@ void chat_onStarting (ToxWindow *self, ToxAv *av, int call_index)
init_infobox(self);
line_info_add(self, NULL, NULL, NULL, "Call started! Type: \"/hangup\" to end it.", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
void chat_onEnding (ToxWindow *self, ToxAv *av, int call_index)
@ -475,6 +489,8 @@ void chat_onEnding (ToxWindow *self, ToxAv *av, int call_index)
kill_infobox(self);
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Call ended!", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
void chat_onError (ToxWindow *self, ToxAv *av, int call_index)
@ -484,6 +500,8 @@ void chat_onError (ToxWindow *self, ToxAv *av, int call_index)
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Error!", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
@ -494,6 +512,8 @@ void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
init_infobox(self);
line_info_add(self, NULL, NULL, NULL, "Call started! Type: \"/hangup\" to end it.", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
void chat_onCancel (ToxWindow *self, ToxAv *av, int call_index)
@ -504,6 +524,8 @@ void chat_onCancel (ToxWindow *self, ToxAv *av, int call_index)
kill_infobox(self);
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Call canceled!", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
void chat_onReject (ToxWindow *self, ToxAv *av, int call_index)
@ -513,6 +535,8 @@ void chat_onReject (ToxWindow *self, ToxAv *av, int call_index)
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Rejected!", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
void chat_onEnd (ToxWindow *self, ToxAv *av, int call_index)
@ -523,6 +547,8 @@ void chat_onEnd (ToxWindow *self, ToxAv *av, int call_index)
kill_infobox(self);
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Call ended!", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
@ -532,6 +558,8 @@ void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "No answer!", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
@ -542,6 +570,8 @@ void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
kill_infobox(self);
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Peer disconnected; call ended!", SYS_MSG, 0, 0);
stop_sound(self->active_sound);
self->active_sound = -1;
}
static void init_infobox(ToxWindow *self)
@ -692,8 +722,9 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} else {
wmove(self->window, y, x + diff);
}
} else beep();
} else beep();
} else notify(self, error, 0);
} else notify(self, error, 0);
} else if (key == '\n') {
rm_trailing_spaces_buf(ctx);
@ -950,6 +981,8 @@ ToxWindow new_chat(Tox *m, int32_t friendnum)
ret.device_selection[0] = ret.device_selection[1] = -1;
#endif /* _SUPPORT_AUDIO */
ret.active_sound = -1;
char nick[TOX_MAX_NAME_LENGTH];
int n_len = get_nick_truncate(m, nick, friendnum);
chat_set_window_name(&ret, nick, n_len);

View File

@ -31,6 +31,7 @@
#include "global_commands.h"
#include "line_info.h"
#include "misc_tools.h"
#include "notify.h"
struct cmd_func {
const char *name;
@ -158,5 +159,7 @@ void execute(WINDOW *w, ToxWindow *self, Tox *m, char *cmd, int mode)
if (do_command(w, self, m, num_args, GLOBAL_NUM_COMMANDS, global_commands, args) == 0)
return;
line_info_add(self, NULL, NULL, NULL, "Invalid command.", SYS_MSG, 0, 0);
/* Just play sound instead */
/*line_info_add(self, NULL, NULL, NULL, "Invalid command.", SYS_MSG, 0, 0);*/
notify(self, error, 0);
}

View File

@ -30,6 +30,7 @@
#include "file_senders.h"
#include "line_info.h"
#include "misc_tools.h"
#include "notify.h"
FileSender file_senders[MAX_FILES];
uint8_t max_file_senders_index;
@ -48,10 +49,9 @@ static void set_max_file_senders_index(void)
static void close_file_sender(ToxWindow *self, Tox *m, int i, char *msg, int CTRL, int filenum, int32_t friendnum)
{
if (self->chatwin != NULL) {
if (self->chatwin != NULL)
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
alert_window(file_senders[i].toxwin, WINDOW_ALERT_2, true);
}
tox_file_send_control(m, friendnum, 0, filenum, CTRL, 0, 0);
fclose(file_senders[i].file);
@ -94,6 +94,7 @@ void do_file_senders(Tox *m)
if (timed_out(file_senders[i].timestamp, get_unix_time(), TIMEOUT_FILESENDER)) {
snprintf(msg, sizeof(msg), "File transfer for '%s' timed out.", pathname);
close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, friendnum);
notify(self, error, NT_NOFOCUS | NT_WNDALERT_2);
continue;
}
@ -122,6 +123,7 @@ void do_file_senders(Tox *m)
if (file_senders[i].piecelen == 0) {
snprintf(msg, sizeof(msg), "File '%s' successfuly sent.", pathname);
close_file_sender(self, m, i, msg, TOX_FILECONTROL_FINISHED, filenum, friendnum);
notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2);
break;
}
}

View File

@ -37,6 +37,7 @@
#ifdef _SUPPORT_AUDIO
#include "audio_call.h"
#include "notify.h"
#endif
extern char *DATA_FILE;
@ -47,7 +48,7 @@ static int num_selected = 0;
static int num_friends = 0;
extern struct _Winthread Winthread;
extern struct user_settings *user_settings;
extern struct user_settings *user_settings_;
ToxicFriend friends[MAX_FRIENDS_NUM];
static int friendlist_index[MAX_FRIENDS_NUM] = {0};
@ -91,7 +92,7 @@ static void update_friend_last_online(int32_t num, uint64_t timestamp)
friends[num].last_online.tm = *localtime((const time_t*)&timestamp);
/* if the format changes make sure TIME_STR_SIZE is the correct size */
const char *t = user_settings->time == TIME_12 ? "%I:%M %p" : "%H:%M";
const char *t = user_settings_->time == TIME_12 ? "%I:%M %p" : "%H:%M";
strftime(friends[num].last_online.hour_min_str, TIME_STR_SIZE, t,
&friends[num].last_online.tm);
}
@ -104,6 +105,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const cha
if (friends[num].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
notify(self, generic_message, NT_NOFOCUS);
} else {
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
@ -115,7 +117,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const cha
char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
notify(prompt, error, NT_WNDALERT_1);
}
}
}
@ -126,6 +128,7 @@ static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int32_t num,
return;
friends[num].online = status;
notify(self, status==1 ? user_log_in : user_log_out, NT_RESTOL | NT_NOTIFWND );
update_friend_last_online(num, get_unix_time());
store_data(m, DATA_FILE);
sort_friendlist_index();
@ -176,7 +179,7 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
friends[i].chatwin = -1;
friends[i].online = false;
friends[i].status = TOX_USERSTATUS_NONE;
friends[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
friends[i].logging_on = (bool) user_settings_->autolog == AUTOLOG_ON;
tox_get_client_id(m, num, (uint8_t *) friends[i].pub_key);
update_friend_last_online(i, tox_get_last_online(m, i));
@ -213,6 +216,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
if (friends[num].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
notify(self, transfer_pending, NT_NOFOCUS);
} else {
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
@ -222,8 +226,8 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "* File transfer from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
notify(prompt, error, NT_WNDALERT_1);
}
}
}
@ -236,6 +240,8 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const
if (friends[num].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
notify(self, generic_message, NT_NOFOCUS);
} else {
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
@ -243,8 +249,8 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "* Group chat invite from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
notify(prompt, error, NT_WNDALERT_1);
}
}
}
@ -348,7 +354,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
notify(prompt, error, NT_WNDALERT_1);
}
} else if (key == KEY_DC) {
del_friend_activate(self, m, f);
@ -558,8 +564,9 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
if (friends[id].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
if (toxav_get_call_state(av, call_index) == av_CallStarting) /* Only open windows when call is incoming */
if (toxav_get_call_state(av, call_index) == av_CallStarting) { /* Only open windows when call is incoming */
friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
}
} else {
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, friends[id].num);
@ -570,8 +577,8 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
char *errmsg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_0, true);
notify(prompt, error, NT_WNDALERT_1);
}
}
}
@ -614,6 +621,8 @@ ToxWindow new_friendlist(void)
ret.device_selection[0] = ret.device_selection[1] = -1;
#endif /* _SUPPORT_AUDIO */
ret.active_sound = -1;
strcpy(ret.name, "friends");
return ret;
}

View File

@ -41,13 +41,14 @@
#include "settings.h"
#include "input.h"
#include "help.h"
#include "notify.h"
extern char *DATA_FILE;
static GroupChat groupchats[MAX_GROUPCHAT_NUM];
static int max_groupchat_index = 0;
extern struct user_settings *user_settings;
extern struct user_settings *user_settings_;
/* temporary until group chats have unique commands */
extern const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE];
@ -134,25 +135,18 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); /* enforce client max name length */
nick[n_len] = '\0';
/* check if message contains own name and alert appropriately */
int alert_type = WINDOW_ALERT_1;
bool beep = false;
char selfnick[TOX_MAX_NAME_LENGTH];
uint16_t sn_len = tox_get_self_name(m, (uint8_t *) selfnick);
selfnick[sn_len] = '\0';
int nick_clr = strcmp(nick, selfnick) == 0 ? GREEN : CYAN;
bool nick_match = strcasestr(msg, selfnick) && strncmp(selfnick, nick, TOXIC_MAX_NAME_LENGTH - 1);
if (nick_match) {
alert_type = WINDOW_ALERT_0;
beep = true;
/* Only play sound if mentioned */
if (strcasestr(msg, selfnick) && strncmp(selfnick, nick, TOXIC_MAX_NAME_LENGTH - 1)) {
notify(self, generic_message, NT_WNDALERT_0);
nick_clr = RED;
}
alert_window(self, alert_type, beep);
else notify(self, unknown, NT_WNDALERT_1);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
@ -169,22 +163,14 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
ChatContext *ctx = self->chatwin;
/* check if message contains own name and alert appropriately */
int alert_type = WINDOW_ALERT_1;
bool beep = false;
char selfnick[TOX_MAX_NAME_LENGTH];
uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfnick);
selfnick[n_len] = '\0';
bool nick_match = strcasestr(action, selfnick);
if (nick_match) {
alert_type = WINDOW_ALERT_0;
beep = true;
if (strcasestr(action, selfnick)) {
notify(self, generic_message, NT_WNDALERT_0);
}
alert_window(self, alert_type, beep);
else notify(self, unknown, NT_WNDALERT_1);
char nick[TOX_MAX_NAME_LENGTH];
n_len = tox_group_peername(m, groupnum, peernum, (uint8_t *) nick);
@ -317,7 +303,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
break;
}
alert_window(self, WINDOW_ALERT_2, false);
notify(self, unknown, NT_WNDALERT_2);
}
static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
@ -502,7 +488,7 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
line_info_init(ctx->hst);
if (user_settings->autolog == AUTOLOG_ON)
if (user_settings_->autolog == AUTOLOG_ON)
log_enable(self->name, NULL, ctx->log);
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);

View File

@ -30,7 +30,7 @@
#include "groupchat.h"
#include "settings.h"
extern struct user_settings *user_settings;
extern struct user_settings *user_settings_;
void line_info_init(struct history *hst)
{
@ -207,7 +207,7 @@ static void line_info_check_queue(ToxWindow *self)
if (line == NULL)
return;
if (hst->start_id > user_settings->history_size)
if (hst->start_id > user_settings_->history_size)
line_info_root_fwd(hst);
line->id = hst->line_end->id + 1;

View File

@ -31,7 +31,7 @@
#include "log.h"
#include "settings.h"
extern struct user_settings *user_settings;
extern struct user_settings *user_settings_;
/* Creates/fetches log file by appending to the config dir the name and a pseudo-unique identity */
void init_logging_session(char *name, char *key, struct chatlog *log)
@ -99,7 +99,7 @@ void write_to_log(const char *msg, char *name, struct chatlog *log, bool event)
else
snprintf(name_frmt, sizeof(name_frmt), "%s:", name);
const char *t = user_settings->time == TIME_12 ? "%Y/%m/%d [%I:%M:%S %p]" : "%Y/%m/%d [%H:%M:%S]";
const char *t = user_settings_->time == TIME_12 ? "%Y/%m/%d [%I:%M:%S %p]" : "%Y/%m/%d [%H:%M:%S]";
char s[MAX_STR_SIZE];
strftime(s, MAX_STR_SIZE, t, get_time());
fprintf(log->file, "%s %s %s\n", s, name_frmt, msg);

View File

@ -32,7 +32,7 @@
#include "settings.h"
extern ToxWindow *prompt;
extern struct user_settings *user_settings;
extern struct user_settings *user_settings_;
static uint64_t current_unix_time;
@ -64,12 +64,12 @@ struct tm *get_time(void)
/*Puts the current time in buf in the format of [HH:mm:ss] */
void get_time_str(char *buf, int bufsize)
{
if (user_settings->timestamps == TIMESTAMPS_OFF) {
if (user_settings_->timestamps == TIMESTAMPS_OFF) {
buf[0] = '\0';
return;
}
const char *t = user_settings->time == TIME_12 ? "[%-I:%M:%S] " : "[%H:%M:%S] ";
const char *t = user_settings_->time == TIME_12 ? "[%-I:%M:%S] " : "[%H:%M:%S] ";
strftime(buf, bufsize, t, get_time());
}
@ -141,29 +141,6 @@ int wcs_to_mbs_buf(char *buf, const wchar_t *string, size_t n)
return len;
}
/* Colours the window tab according to type. Beeps if is_beep is true */
void alert_window(ToxWindow *self, int type, bool is_beep)
{
switch (type) {
case WINDOW_ALERT_0:
self->alert0 = true;
break;
case WINDOW_ALERT_1:
self->alert1 = true;
break;
case WINDOW_ALERT_2:
self->alert2 = true;
break;
}
StatusBar *stb = prompt->stb;
if (is_beep && stb->status != TOX_USERSTATUS_BUSY && user_settings->alerts == ALERTS_ENABLED)
beep();
}
/* case-insensitive string compare function for use with qsort */
int qsort_strcasecmp_hlpr(const void *nick1, const void *nick2)
{
@ -233,4 +210,4 @@ int get_nick_truncate(Tox *m, char *buf, int friendnum)
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
buf[len] = '\0';
return len;
}
}

View File

@ -35,13 +35,14 @@
#include "settings.h"
#include "input.h"
#include "help.h"
#include "notify.h"
char pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
uint16_t num_frnd_requests = 0;
extern ToxWindow *prompt;
struct _Winthread Winthread;
extern struct user_settings *user_settings;
extern struct user_settings *user_settings_;
/* Array of global command names used for tab completion. */
const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
@ -304,11 +305,13 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
msg = "has come online";
line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, GREEN);
write_to_log(msg, nick, ctx->log, true);
alert_window(self, WINDOW_ALERT_2, false);
notify(self, user_log_in, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL);
} else {
msg = "has gone offline";
line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, RED);
write_to_log(msg, nick, ctx->log, true);
notify(self, user_log_out, NT_WNDALERT_2 | NT_NOTIFWND | NT_RESTOL);
}
}
@ -336,7 +339,7 @@ static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, con
snprintf(msg, sizeof(msg), "Type \"/accept %d\" to accept it.", n);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
alert_window(self, WINDOW_ALERT_1, true);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOTIFWND);
}
void prompt_init_statusbar(ToxWindow *self, Tox *m)
@ -415,7 +418,7 @@ static void prompt_onInit(ToxWindow *self, Tox *m)
line_info_init(ctx->hst);
if (user_settings->autolog == AUTOLOG_ON) {
if (user_settings_->autolog == AUTOLOG_ON) {
char myid[TOX_FRIEND_ADDRESS_SIZE];
tox_get_address(m, (uint8_t *) myid);
log_enable(self->name, myid, ctx->log);

View File

@ -22,10 +22,12 @@
#include <stdlib.h>
#include <string.h>
#include <libconfig.h>
#include "toxic.h"
#include "windows.h"
#include "configdir.h"
#include "notify.h"
#ifdef _SUPPORT_AUDIO
#include "device.h"
@ -34,195 +36,180 @@
#include "settings.h"
#include "line_info.h"
static void uset_autolog(struct user_settings *s, const char *val);
static void uset_time(struct user_settings *s, const char *val);
static void uset_timestamps(struct user_settings *s, const char *val);
static void uset_alerts(struct user_settings *s, const char *val);
static void uset_colours(struct user_settings *s, const char *val);
static void uset_hst_size(struct user_settings *s, const char *val);
static void uset_dwnld_path(struct user_settings *s, const char *val);
const struct _ui_strings {
const char* self;
const char* timestamps;
const char* alerts;
const char* native_colors;
const char* autolog;
const char* time_format;
const char* history_size;
} ui_strings = {
"ui",
"timestamps",
"alerts",
"native_colors",
"autolog",
"time_format",
"history_size"
};
static void ui_defaults(struct user_settings* settings)
{
settings->timestamps = TIMESTAMPS_ON;
settings->time = TIME_24;
settings->autolog = AUTOLOG_OFF;
settings->alerts = ALERTS_ENABLED;
settings->colour_theme = DFLT_COLS;
settings->history_size = 700;
}
#ifdef _SUPPORT_AUDIO
static void uset_ain_dev(struct user_settings *s, const char *val);
static void uset_aout_dev(struct user_settings *s, const char *val);
#endif
struct {
const char *key;
void (*func)(struct user_settings *s, const char *val);
} user_settings_list[] = {
{ "autolog", uset_autolog },
{ "time", uset_time },
{ "timestamps", uset_timestamps },
{ "alerts", uset_alerts },
{ "colour_theme", uset_colours },
{ "history_size", uset_hst_size },
{ "download_path", uset_dwnld_path },
#ifdef _SUPPORT_AUDIO
{ "audio_in_dev", uset_ain_dev },
{ "audio_out_dev", uset_aout_dev },
#endif
const struct _tox_strings {
const char* self;
const char* download_path;
} tox_strings = {
"tox",
"download_path",
};
static void uset_autolog(struct user_settings *s, const char *val)
static void tox_defaults(struct user_settings* settings)
{
int n = atoi(val);
/* default off if invalid value */
s->autolog = n == AUTOLOG_ON ? AUTOLOG_ON : AUTOLOG_OFF;
}
static void uset_time(struct user_settings *s, const char *val)
{
int n = atoi(val);
/* default to 24 hour time if invalid value */
s->time = n == TIME_12 ? TIME_12 : TIME_24;
}
static void uset_timestamps(struct user_settings *s, const char *val)
{
int n = atoi(val);
/* default on if invalid value */
s->timestamps = n == TIMESTAMPS_OFF ? TIMESTAMPS_OFF : TIMESTAMPS_ON;
}
static void uset_alerts(struct user_settings *s, const char *val)
{
int n = atoi(val);
/* alerts default on if invalid value */
s->alerts = n == ALERTS_DISABLED ? ALERTS_DISABLED : ALERTS_ENABLED;
}
static void uset_colours(struct user_settings *s, const char *val)
{
int n = atoi(val);
/* use default toxic colours if invalid value */
s->colour_theme = n == NATIVE_COLS ? NATIVE_COLS : DFLT_COLS;
/*settings->download_path;*/ /* TODO: Set this? */
}
#ifdef _SUPPORT_AUDIO
static void uset_ain_dev(struct user_settings *s, const char *val)
const struct _audio_strings {
const char* self;
const char* input_device;
const char* output_device;
const char* VAD_treshold;
} audio_strings = {
"audio",
"input_device",
"output_device",
"VAD_treshold",
};
static void audio_defaults(struct user_settings* settings)
{
int n = atoi(val);
if (n < 0 || n > MAX_DEVICES)
n = (long int) 0;
s->audio_in_dev = (long int) n;
settings->audio_in_dev = 0;
settings->audio_out_dev = 0;
settings->VAD_treshold = 40.0;
}
static void uset_aout_dev(struct user_settings *s, const char *val)
{
int n = atoi(val);
if (n < 0 || n > MAX_DEVICES)
n = (long int) 0;
s->audio_out_dev = (long int) n;
}
#endif /* _SUPPORT_AUDIO */
static void uset_hst_size(struct user_settings *s, const char *val)
{
int n = atoi(val);
/* if val is out of range use default history size */
s->history_size = (n > MAX_HISTORY || n < MIN_HISTORY) ? DFLT_HST_SIZE : n;
}
static void uset_dwnld_path(struct user_settings *s, const char *val)
{
memset(s->download_path, 0, sizeof(s->download_path));
if (val == NULL)
return;
int len = strlen(val);
if (len >= sizeof(s->download_path) - 2) /* leave room for null and '/' */
return;
FILE *fp = fopen(val, "r");
if (fp == NULL)
return;
strcpy(s->download_path, val);
if (val[len - 1] != '/')
strcat(s->download_path, "/");
}
static void set_default_settings(struct user_settings *s)
{
/* see settings_values enum in settings.h for defaults */
uset_autolog(s, "0");
uset_time(s, "24");
uset_timestamps(s, "1");
uset_alerts(s, "1");
uset_colours(s, "0");
uset_hst_size(s, "700");
uset_dwnld_path(s, NULL);
#ifdef _SUPPORT_AUDIO
uset_ain_dev(s, "0");
uset_aout_dev(s, "0");
#endif
}
#ifdef _ENABLE_SOUND_NOTIFY
const struct _sound_strings {
const char* self;
const char* error;
const char* self_log_in;
const char* self_log_out;
const char* user_log_in;
const char* user_log_out;
const char* call_incoming;
const char* call_outgoing;
const char* generic_message;
const char* transfer_pending;
const char* transfer_completed;
} sound_strings = {
"sounds",
"error",
"self_log_in",
"self_log_out",
"user_log_in",
"user_log_out",
"call_incoming",
"call_outgoing",
"generic_message",
"transfer_pending",
"transfer_completed",
};
#endif
int settings_load(struct user_settings *s, char *path)
{
char *user_config_dir = get_user_config_dir();
FILE *fp = NULL;
char dflt_path[MAX_STR_SIZE];
if (path) {
fp = fopen(path, "r");
} else {
snprintf(dflt_path, sizeof(dflt_path), "%s%stoxic.conf", user_config_dir, CONFIGDIR);
fp = fopen(dflt_path, "r");
}
free(user_config_dir);
set_default_settings(s);
if (fp == NULL && !path) {
if ((fp = fopen(dflt_path, "w")) == NULL)
return -1;
} else if (fp == NULL && path) {
config_t cfg[1];
config_setting_t *setting;
const char *str;
/* Load default settings */
ui_defaults(s);
tox_defaults(s);
#ifdef _SUPPORT_AUDIO
audio_defaults(s);
#endif
config_init(cfg);
if(!config_read_file(cfg, path))
{
config_destroy(cfg);
return -1;
}
char line[MAX_STR_SIZE];
while (fgets(line, sizeof(line), fp)) {
if (line[0] == '#' || !line[0])
continue;
const char *key = strtok(line, ":");
const char *val = strtok(NULL, ";");
if (key == NULL || val == NULL)
continue;
int i;
for (i = 0; i < NUM_SETTINGS; ++i) {
if (strcmp(user_settings_list[i].key, key) == 0) {
(user_settings_list[i].func)(s, val);
break;
}
/* ui */
if ((setting = config_lookup(cfg, ui_strings.self)) != NULL) {
config_setting_lookup_bool(setting, ui_strings.timestamps, &s->timestamps);
config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts);
config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog);
config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme);
config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
config_setting_lookup_int(setting, ui_strings.time_format, &s->time);
s->time = s->time == TIME_24 || s->time == TIME_12 ? s->time : TIME_24; /* Check defaults */
}
if ((setting = config_lookup(cfg, tox_strings.self)) != NULL) {
if ( config_setting_lookup_string(setting, tox_strings.download_path, &str) ) {
s->download_path = calloc(1, strlen(str) + 1);
strcpy(s->download_path, str);
}
}
#ifdef _SUPPORT_AUDIO
if ((setting = config_lookup(cfg, audio_strings.self)) != NULL) {
config_setting_lookup_int(setting, audio_strings.input_device, &s->audio_in_dev);
s->audio_in_dev = s->audio_in_dev < 0 || s->audio_in_dev > MAX_DEVICES ? 0 : s->audio_in_dev;
config_setting_lookup_int(setting, audio_strings.output_device, &s->audio_out_dev);
s->audio_out_dev = s->audio_out_dev < 0 || s->audio_out_dev > MAX_DEVICES ? 0 : s->audio_out_dev;
config_setting_lookup_float(setting, audio_strings.VAD_treshold, &s->VAD_treshold);
}
#endif
fclose(fp);
#ifdef _ENABLE_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.self_log_in, &str) )
set_sound(self_log_in, str);
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_out, &str) )
set_sound(self_log_out, str);
if ( config_setting_lookup_string(setting, sound_strings.call_incoming, &str) )
set_sound(call_incoming, str);
if ( config_setting_lookup_string(setting, sound_strings.call_outgoing, &str) )
set_sound(call_outgoing, str);
if ( config_setting_lookup_string(setting, sound_strings.generic_message, &str) )
set_sound(generic_message, str);
if ( config_setting_lookup_string(setting, sound_strings.transfer_pending, &str) )
set_sound(transfer_pending, str);
if ( config_setting_lookup_string(setting, sound_strings.transfer_completed, &str) )
set_sound(transfer_completed, str);
}
#endif
config_destroy(cfg);
return 0;
}
}

View File

@ -23,14 +23,6 @@
#ifndef _settings_h
#define _settings_h
#include "toxic.h"
#ifdef _SUPPORT_AUDIO
#define NUM_SETTINGS 9
#else
#define NUM_SETTINGS 7
#endif /* _SUPPORT_AUDIO */
/* holds user setting values */
struct user_settings {
int autolog; /* boolean */
@ -39,11 +31,12 @@ struct user_settings {
int timestamps; /* boolean */
int colour_theme; /* boolean (0 for default toxic colours) */
int history_size; /* int between MIN_HISTORY and MAX_HISTORY */
char download_path[MAX_STR_SIZE];
char* download_path;
#ifdef _SUPPORT_AUDIO
long int audio_in_dev;
long int audio_out_dev;
int audio_in_dev;
int audio_out_dev;
double VAD_treshold;
#endif
};

View File

@ -50,6 +50,7 @@
#include "line_info.h"
#include "settings.h"
#include "log.h"
#include "notify.h"
#ifdef _SUPPORT_AUDIO
#include "audio_call.h"
@ -78,7 +79,7 @@ struct arg_opts {
} arg_opts;
struct _Winthread Winthread;
struct user_settings *user_settings = NULL;
struct user_settings *user_settings_ = NULL;
static void catch_SIGINT(int sig)
{
@ -97,8 +98,10 @@ void exit_toxic_success(Tox *m)
kill_all_windows();
free(DATA_FILE);
free(user_settings);
free(user_settings_);
notify(NULL, self_log_out, NT_ALWAYS);
terminate_notify();
#ifdef _SUPPORT_AUDIO
terminate_audio();
#endif /* _SUPPORT_AUDIO */
@ -141,7 +144,7 @@ static void init_term(void)
short bg_color = COLOR_BLACK;
start_color();
if (user_settings->colour_theme == NATIVE_COLS) {
if (user_settings_->colour_theme == NATIVE_COLS) {
if (assume_default_colors(-1, -1) == OK)
bg_color = -1;
}
@ -568,7 +571,7 @@ int main(int argc, char *argv[])
/* Make sure all written files are read/writeable only by the current user. */
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
signal(SIGINT, catch_SIGINT);
// signal(SIGINT, catch_SIGINT);
config_err = create_user_config_dir(user_config_dir);
@ -590,15 +593,13 @@ int main(int argc, char *argv[])
free(user_config_dir);
/* init user_settings struct and load settings from conf file */
user_settings = malloc(sizeof(struct user_settings));
user_settings_ = calloc(1, sizeof(struct user_settings));
if (user_settings == NULL)
if (user_settings_ == NULL)
exit_toxic_err("failed in main", FATALERR_MEMORY);
memset(user_settings, 0, sizeof(struct user_settings));
char *p = arg_opts.config_path[0] ? arg_opts.config_path : NULL;
int settings_err = settings_load(user_settings, p);
int settings_err = settings_load(user_settings_, p);
Tox *m = init_tox(arg_opts.use_ipv4);
init_term();
@ -625,11 +626,14 @@ int main(int argc, char *argv[])
av = init_audio(prompt, m);
set_primary_device(input, user_settings->audio_in_dev);
set_primary_device(output, user_settings->audio_out_dev);
set_primary_device(input, user_settings_->audio_in_dev);
set_primary_device(output, user_settings_->audio_out_dev);
#endif /* _SUPPORT_AUDIO */
init_notify(60);
notify(prompt, self_log_in, 0);
if (config_err) {
msg = "Unable to determine configuration directory. Defaulting to 'data' for a keyfile...";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);

View File

@ -366,23 +366,11 @@ void on_window_resize(void)
static void draw_window_tab(ToxWindow toxwin)
{
/* alert0 takes priority */
if (toxwin.alert0)
attron(COLOR_PAIR(GREEN));
else if (toxwin.alert1)
attron(COLOR_PAIR(RED));
else if (toxwin.alert2)
attron(COLOR_PAIR(MAGENTA));
if (toxwin.alert) attron(COLOR_PAIR(toxwin.alert));
clrtoeol();
printw(" [%s]", toxwin.name);
if (toxwin.alert0)
attroff(COLOR_PAIR(GREEN));
else if (toxwin.alert1)
attroff(COLOR_PAIR(RED));
else if (toxwin.alert2)
attroff(COLOR_PAIR(MAGENTA));
if (toxwin.alert) attroff(COLOR_PAIR(toxwin.alert));
}
static void draw_bar(void)
@ -430,9 +418,7 @@ static void draw_bar(void)
void draw_active_window(Tox *m)
{
ToxWindow *a = active_window;
a->alert0 = false;
a->alert1 = false;
a->alert2 = false;
a->alert = WINDOW_ALERT_NONE;
wint_t ch = 0;
@ -505,4 +491,4 @@ void kill_all_windows(void)
else if (windows[i].is_groupchat)
kill_groupchat_window(&windows[i]);
}
}
}

View File

@ -53,10 +53,11 @@ enum {
} C_COLOURS;
/* tab alert types: lower types take priority */
enum {
WINDOW_ALERT_0,
WINDOW_ALERT_1,
WINDOW_ALERT_2,
typedef enum {
WINDOW_ALERT_NONE = 0,
WINDOW_ALERT_0 = GREEN,
WINDOW_ALERT_1 = RED,
WINDOW_ALERT_2 = MAGENTA,
} WINDOW_ALERTS;
/* Fixes text color problem on some terminals.
@ -117,6 +118,10 @@ struct ToxWindow {
#endif /* _SUPPORT_AUDIO */
#ifdef _ENABLE_SOUND_NOTIFY
int active_sound;
#endif
char name[TOXIC_MAX_NAME_LENGTH];
int32_t num; /* corresponds to friendnumber in chat windows */
bool active;
@ -127,9 +132,7 @@ struct ToxWindow {
bool is_prompt;
bool is_friendlist;
bool alert0;
bool alert1;
bool alert2;
WINDOW_ALERTS alert;
ChatContext *chatwin;
StatusBar *stb;