mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 06:03:04 +01:00
Merge pull request #174 from mannol1/master
Make closing window end call
This commit is contained in:
commit
2ed9448b41
@ -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_requ_timeout ( int32_t call_index, void *arg );
|
||||||
void callback_peer_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)
|
static void print_err (ToxWindow *self, uint8_t *error_str)
|
||||||
{
|
{
|
||||||
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
|
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
|
||||||
@ -309,13 +311,11 @@ void callback_recv_ending ( int32_t call_index, void* arg )
|
|||||||
{
|
{
|
||||||
CB_BODY(call_index, arg, onEnding);
|
CB_BODY(call_index, arg, onEnding);
|
||||||
stop_transmission(call_index);
|
stop_transmission(call_index);
|
||||||
((ToxWindow*)arg)->call_idx = -1;
|
|
||||||
}
|
}
|
||||||
void callback_recv_error ( int32_t call_index, void* arg )
|
void callback_recv_error ( int32_t call_index, void* arg )
|
||||||
{
|
{
|
||||||
CB_BODY(call_index, arg, onError);
|
CB_BODY(call_index, arg, onError);
|
||||||
stop_transmission(call_index);
|
stop_transmission(call_index);
|
||||||
((ToxWindow*)arg)->call_idx = -1;
|
|
||||||
}
|
}
|
||||||
void callback_call_started ( int32_t call_index, void* arg )
|
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 */
|
/* In case call is active */
|
||||||
stop_transmission(call_index);
|
stop_transmission(call_index);
|
||||||
((ToxWindow*)arg)->call_idx = -1;
|
|
||||||
}
|
}
|
||||||
void callback_call_rejected ( int32_t call_index, void* arg )
|
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);
|
CB_BODY(call_index, arg, onEnd);
|
||||||
stop_transmission(call_index);
|
stop_transmission(call_index);
|
||||||
((ToxWindow*)arg)->call_idx = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void callback_requ_timeout ( int32_t call_index, void* arg )
|
void callback_requ_timeout ( int32_t call_index, void* arg )
|
||||||
{
|
{
|
||||||
CB_BODY(call_index, arg, onRequestTimeout);
|
CB_BODY(call_index, arg, onRequestTimeout);
|
||||||
((ToxWindow*)arg)->call_idx = -1;
|
|
||||||
}
|
}
|
||||||
void callback_peer_timeout ( int32_t call_index, void* arg )
|
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
|
* actions that one can possibly take on timeout
|
||||||
*/
|
*/
|
||||||
toxav_stop_call(ASettins.av, call_index);
|
toxav_stop_call(ASettins.av, call_index);
|
||||||
((ToxWindow*)arg)->call_idx = -1;
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* End of Callbacks
|
* End of Callbacks
|
||||||
@ -762,3 +758,27 @@ void cmd_sense(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)
|
|||||||
on_error:
|
on_error:
|
||||||
print_err (self, error_str);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -42,7 +42,6 @@ typedef enum _AudioError {
|
|||||||
ToxAv *init_audio(ToxWindow *self, Tox *tox);
|
ToxAv *init_audio(ToxWindow *self, Tox *tox);
|
||||||
void terminate_audio();
|
void terminate_audio();
|
||||||
|
|
||||||
int start_transmission(ToxWindow *self);
|
void stop_current_call(ToxWindow *self);
|
||||||
int stop_transmission(int call_index);
|
|
||||||
|
|
||||||
#endif /* _audio_h */
|
#endif /* _audio_h */
|
||||||
|
30
src/chat.c
30
src/chat.c
@ -24,6 +24,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "toxic.h"
|
#include "toxic.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
@ -115,11 +116,18 @@ void kill_chat_window(ToxWindow *self, Tox *m)
|
|||||||
log_disable(ctx->log);
|
log_disable(ctx->log);
|
||||||
line_info_cleanup(ctx->hst);
|
line_info_cleanup(ctx->hst);
|
||||||
|
|
||||||
|
#ifdef _SUPPORT_AUDIO
|
||||||
|
stop_current_call(self);
|
||||||
|
#endif
|
||||||
|
|
||||||
int f_num = self->num;
|
int f_num = self->num;
|
||||||
|
|
||||||
delwin(ctx->linewin);
|
delwin(ctx->linewin);
|
||||||
delwin(ctx->history);
|
delwin(ctx->history);
|
||||||
delwin(self->window);
|
delwin(self->window);
|
||||||
delwin(statusbar->topline);
|
delwin(statusbar->topline);
|
||||||
|
|
||||||
|
del_window(self);
|
||||||
disable_chatwin(f_num);
|
disable_chatwin(f_num);
|
||||||
|
|
||||||
free(ctx->log);
|
free(ctx->log);
|
||||||
@ -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)
|
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;
|
return;
|
||||||
|
|
||||||
/* call_index is set here and reset on call end */
|
/* 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)
|
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;
|
return;
|
||||||
|
|
||||||
line_info_add(self, NULL, NULL, NULL, "Ringing...\"cancel\" ?", SYS_MSG, 0, 0);
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
init_infobox(self);
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
kill_infobox(self);
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
self->call_idx = -1;
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
init_infobox(self);
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
kill_infobox(self);
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
self->call_idx = -1;
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
kill_infobox(self);
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
self->call_idx = -1;
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
kill_infobox(self);
|
kill_infobox(self);
|
||||||
|
@ -558,6 +558,7 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
|
|||||||
|
|
||||||
if (friends[id].chatwin == -1) {
|
if (friends[id].chatwin == -1) {
|
||||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
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 */
|
||||||
friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
|
friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
|
||||||
} else {
|
} else {
|
||||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||||
|
Loading…
Reference in New Issue
Block a user