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

Merge pull request #174 from mannol1/master

Make closing window end call
This commit is contained in:
mannol1 2014-07-06 22:52:11 +02:00
commit 2ed9448b41
4 changed files with 56 additions and 28 deletions

View File

@ -94,6 +94,8 @@ 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 );
int stop_transmission(int call_index);
static void print_err (ToxWindow *self, uint8_t *error_str)
{
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
@ -245,17 +247,17 @@ int start_transmission(ToxWindow *self)
}
if ( !toxav_capability_supported(ASettins.av, self->call_idx, AudioDecoding) ||
!toxav_capability_supported(ASettins.av, self->call_idx, AudioEncoding) )
!toxav_capability_supported(ASettins.av, self->call_idx, AudioEncoding) )
return -1;
set_call(&ASettins.calls[self->call_idx], _True);
if ( 0 != pthread_create(&ASettins.calls[self->call_idx].ttid, NULL, transmission, self ) &&
0 != pthread_detach(ASettins.calls[self->call_idx].ttid) ) {
0 != pthread_detach(ASettins.calls[self->call_idx].ttid) ) {
return -1;
}
return 0;
}
return 0;
}
int stop_transmission(int call_index)
@ -265,7 +267,7 @@ int stop_transmission(int call_index)
ASettins.calls[call_index].ttas = _False;
return 0;
}
return -1;
}
/*
@ -309,13 +311,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 +336,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 +345,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 +359,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 +758,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"
@ -115,13 +116,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);
@ -426,7 +434,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 */
@ -440,7 +448,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);
@ -448,7 +456,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);
@ -458,7 +466,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);
@ -468,7 +476,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;
@ -477,7 +485,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);
@ -487,7 +495,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);
@ -497,7 +505,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;
@ -506,7 +514,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);
@ -516,7 +524,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;
@ -525,7 +533,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

@ -558,7 +558,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);