1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-06-20 10:26:37 +02:00

Now closing the window will end the call

This commit is contained in:
mannol
2014-07-04 18:04:03 +02:00
parent 10d0e99d72
commit 65e726a51a
5 changed files with 735 additions and 128 deletions

View File

@ -309,13 +309,11 @@ void callback_recv_ending ( int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onEnding);
stop_transmission(call_index);
((ToxWindow*)arg)->call_idx = -1;
}
void callback_recv_error ( int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onError);
stop_transmission(call_index);
((ToxWindow*)arg)->call_idx = -1;
}
void callback_call_started ( int32_t call_index, void* arg )
{
@ -336,7 +334,6 @@ void callback_call_canceled ( int32_t call_index, void* arg )
/* In case call is active */
stop_transmission(call_index);
((ToxWindow*)arg)->call_idx = -1;
}
void callback_call_rejected ( int32_t call_index, void* arg )
{
@ -346,13 +343,11 @@ void callback_call_ended ( int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onEnd);
stop_transmission(call_index);
((ToxWindow*)arg)->call_idx = -1;
}
void callback_requ_timeout ( int32_t call_index, void* arg )
{
CB_BODY(call_index, arg, onRequestTimeout);
((ToxWindow*)arg)->call_idx = -1;
}
void callback_peer_timeout ( int32_t call_index, void* arg )
{
@ -362,7 +357,6 @@ void callback_peer_timeout ( int32_t call_index, void* arg )
* actions that one can possibly take on timeout
*/
toxav_stop_call(ASettins.av, call_index);
((ToxWindow*)arg)->call_idx = -1;
}
/*
* End of Callbacks
@ -762,3 +756,27 @@ void cmd_sense(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)
on_error:
print_err (self, error_str);
}
void stop_current_call(ToxWindow* self)
{
ToxAvCallState callstate;
if ( ASettins.av != NULL && self->call_idx != -1 &&
( callstate = toxav_get_call_state(ASettins.av, self->call_idx) ) != av_CallNonExistant) {
switch (callstate)
{
case av_CallActive:
case av_CallHold:
toxav_hangup(ASettins.av, self->call_idx);
break;
case av_CallInviting:
toxav_cancel(ASettins.av, self->call_idx, 0, "Not interested anymore");
break;
case av_CallStarting:
toxav_reject(ASettins.av, self->call_idx, "Not interested");
break;
default:
break;
}
}
}

View File

@ -42,7 +42,6 @@ typedef enum _AudioError {
ToxAv *init_audio(ToxWindow *self, Tox *tox);
void terminate_audio();
int start_transmission(ToxWindow *self);
int stop_transmission(int call_index);
void stop_current_call(ToxWindow *self);
#endif /* _audio_h */

View File

@ -24,6 +24,7 @@
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <assert.h>
#include "toxic.h"
#include "windows.h"
@ -114,14 +115,20 @@ void kill_chat_window(ToxWindow *self, Tox *m)
log_disable(ctx->log);
line_info_cleanup(ctx->hst);
#ifdef _SUPPORT_AUDIO
stop_current_call(self);
#endif
int f_num = self->num;
delwin(ctx->linewin);
delwin(ctx->history);
delwin(self->window);
delwin(statusbar->topline);
del_window(self);
disable_chatwin(f_num);
free(ctx->log);
free(ctx->hst);
free(ctx);
@ -424,7 +431,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, co
void chat_onInvite (ToxWindow *self, ToxAv *av, int call_index)
{
if (self->num != toxav_get_peer_id(av, call_index, 0))
if (!self || self->num != toxav_get_peer_id(av, call_index, 0))
return;
/* call_index is set here and reset on call end */
@ -438,7 +445,7 @@ void chat_onInvite (ToxWindow *self, ToxAv *av, int call_index)
void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
{
if ( self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
line_info_add(self, NULL, NULL, NULL, "Ringing...\"cancel\" ?", SYS_MSG, 0, 0);
@ -446,7 +453,7 @@ void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
void chat_onStarting (ToxWindow *self, ToxAv *av, int call_index)
{
if ( self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
init_infobox(self);
@ -456,7 +463,7 @@ void chat_onStarting (ToxWindow *self, ToxAv *av, int call_index)
void chat_onEnding (ToxWindow *self, ToxAv *av, int call_index)
{
if (self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
kill_infobox(self);
@ -466,7 +473,7 @@ void chat_onEnding (ToxWindow *self, ToxAv *av, int call_index)
void chat_onError (ToxWindow *self, ToxAv *av, int call_index)
{
if (self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
self->call_idx = -1;
@ -475,7 +482,7 @@ void chat_onError (ToxWindow *self, ToxAv *av, int call_index)
void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
{
if ( self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
init_infobox(self);
@ -485,7 +492,7 @@ void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
void chat_onCancel (ToxWindow *self, ToxAv *av, int call_index)
{
if ( self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
kill_infobox(self);
@ -495,7 +502,7 @@ void chat_onCancel (ToxWindow *self, ToxAv *av, int call_index)
void chat_onReject (ToxWindow *self, ToxAv *av, int call_index)
{
if (self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
self->call_idx = -1;
@ -504,7 +511,7 @@ void chat_onReject (ToxWindow *self, ToxAv *av, int call_index)
void chat_onEnd (ToxWindow *self, ToxAv *av, int call_index)
{
if (self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
kill_infobox(self);
@ -514,7 +521,7 @@ void chat_onEnd (ToxWindow *self, ToxAv *av, int call_index)
void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
{
if (self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
self->call_idx = -1;
@ -523,7 +530,7 @@ void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
{
if (self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
kill_infobox(self);

View File

@ -560,7 +560,8 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
if (friends[id].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
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 {
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
int n_len = tox_get_name(m, id, nick);