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

use hangup cmd to cancel outgoing call requests

This commit is contained in:
Jfreegman 2014-08-03 23:11:19 -04:00
parent ad23816096
commit 38ed0c86ad
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
6 changed files with 23 additions and 50 deletions

View File

@ -447,7 +447,18 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
goto on_error; goto on_error;
} }
ToxAvError error = toxav_hangup(ASettins.av, self->call_idx); ToxAvError error;
if (toxav_get_call_state(ASettins.av, self->call_idx) == av_CallInviting) {
error = toxav_cancel(ASettins.av, self->call_idx, self->num,
"Only those who appreciate small things know the beauty that is life");
#ifdef _SOUND_NOTIFY
stop_sound(self->ringing_sound);
#endif
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call canceled!");
} else {
error = toxav_hangup(ASettins.av, self->call_idx);
}
if ( error != ErrorNone ) { if ( error != ErrorNone ) {
if ( error == ErrorInvalidState ) error_str = "Cannot hangup in invalid state!"; if ( error == ErrorInvalidState ) error_str = "Cannot hangup in invalid state!";
@ -462,42 +473,6 @@ on_error:
print_err (self, error_str); print_err (self, error_str);
} }
void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
goto on_error;
}
if ( !ASettins.av ) {
error_str = "Audio not supported!";
goto on_error;
}
ToxAvError error = toxav_cancel(ASettins.av, self->call_idx, self->num,
"Only those who appreciate small things know the beauty that is life");
if ( error != ErrorNone ) {
if ( error == ErrorNoCall ) error_str = "No call!";
else if ( error == ErrorInvalidState ) error_str = "Cannot cancel in invalid state!";
else error_str = "Internal error!";
goto on_error;
}
#ifdef _SOUND_NOTIFY
stop_sound(self->ringing_sound);
#endif /* _SOUND_NOTIFY */
/* Callback will print status... */
return;
on_error:
print_err (self, error_str);
}
void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *error_str; const char *error_str;

View File

@ -63,7 +63,7 @@ static void kill_infobox(ToxWindow *self);
#endif /* _AUDIO */ #endif /* _AUDIO */
#ifdef _AUDIO #ifdef _AUDIO
#define AC_NUM_CHAT_COMMANDS 26 #define AC_NUM_CHAT_COMMANDS 25
#else #else
#define AC_NUM_CHAT_COMMANDS 18 #define AC_NUM_CHAT_COMMANDS 18
#endif /* _AUDIO */ #endif /* _AUDIO */
@ -92,7 +92,6 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
#ifdef _AUDIO #ifdef _AUDIO
{ "/call" }, { "/call" },
{ "/cancel" },
{ "/answer" }, { "/answer" },
{ "/reject" }, { "/reject" },
{ "/hangup" }, { "/hangup" },
@ -450,8 +449,8 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
if (!remain || timed_out(friends[num].file_receiver.last_progress[filenum], curtime, 1)) { if (!remain || timed_out(friends[num].file_receiver.last_progress[filenum], curtime, 1)) {
friends[num].file_receiver.last_progress[filenum] = curtime; friends[num].file_receiver.last_progress[filenum] = curtime;
uint64_t size = friends[num].file_receiver.size[filenum]; uint64_t size = friends[num].file_receiver.size[filenum];
double pct_remain = remain > 0 ? (1 - (remain / size)) * 100 : 100; double pct_done = remain > 0 ? (1 - (remain / size)) * 100 : 100;
print_progress_bar(self, filenum, num, pct_remain); print_progress_bar(self, filenum, num, pct_done);
friends[num].file_receiver.bps[filenum] = 0; friends[num].file_receiver.bps[filenum] = 0;
} }
} }
@ -505,7 +504,7 @@ void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
if ( !self || 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, SYS_MSG, 0, 0, "Ringing...\"cancel\" ?"); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Ringing...type \"/hangup\" to cancel it.");
#ifdef _SOUND_NOTIFY #ifdef _SOUND_NOTIFY
if (self->ringing_sound == -1) if (self->ringing_sound == -1)

View File

@ -68,7 +68,6 @@ static struct cmd_func chat_commands[] = {
#ifdef _AUDIO #ifdef _AUDIO
{ "/call", cmd_call }, { "/call", cmd_call },
{ "/cancel", cmd_cancel },
{ "/answer", cmd_answer }, { "/answer", cmd_answer },
{ "/reject", cmd_reject }, { "/reject", cmd_reject },
{ "/hangup", cmd_hangup }, { "/hangup", cmd_hangup },

View File

@ -30,7 +30,7 @@
#ifdef _AUDIO #ifdef _AUDIO
#define GLOBAL_NUM_COMMANDS 16 #define GLOBAL_NUM_COMMANDS 16
#define CHAT_NUM_COMMANDS 12 #define CHAT_NUM_COMMANDS 11
#else #else
#define GLOBAL_NUM_COMMANDS 14 #define GLOBAL_NUM_COMMANDS 14
#define CHAT_NUM_COMMANDS 4 #define CHAT_NUM_COMMANDS 4

View File

@ -57,7 +57,7 @@ void prep_prog_line(char *progline)
/* prints a progress bar for file transfers. /* prints a progress bar for file transfers.
if friendnum is -1 we're sending the file, otherwise we're receiving. */ if friendnum is -1 we're sending the file, otherwise we're receiving. */
void print_progress_bar(ToxWindow *self, int idx, int friendnum, double pct_remain) void print_progress_bar(ToxWindow *self, int idx, int friendnum, double pct_done)
{ {
double bps; double bps;
uint32_t line_id; uint32_t line_id;
@ -87,7 +87,7 @@ void print_progress_bar(ToxWindow *self, int idx, int friendnum, double pct_rema
char msg[MAX_STR_SIZE]; char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "%.1f %s [", bps, unit); snprintf(msg, sizeof(msg), "%.1f %s [", bps, unit);
int n = pct_remain / (100 / NUM_PROG_MARKS); int n = pct_done / (100 / NUM_PROG_MARKS);
int i; int i;
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
@ -101,7 +101,8 @@ void print_progress_bar(ToxWindow *self, int idx, int friendnum, double pct_rema
strcat(msg, "] "); strcat(msg, "] ");
char pctstr[16]; char pctstr[16];
snprintf(pctstr, sizeof(pctstr), "%.2f%%", pct_remain); const char *frmt = pct_done == 100 ? "%.f%%" : "%.1f%%";
snprintf(pctstr, sizeof(pctstr), frmt, pct_done);
strcat(msg, pctstr); strcat(msg, pctstr);
line_info_set(self, line_id, msg); line_info_set(self, line_id, msg);
@ -168,8 +169,8 @@ static void send_file_data(ToxWindow *self, Tox *m, int i, int32_t friendnum, in
/* refresh line with percentage complete and transfer speed (must be called once per second) */ /* refresh line with percentage complete and transfer speed (must be called once per second) */
if ((self->chatwin != NULL && timed_out(file_senders[i].last_progress, curtime, 1)) || !remain) { if ((self->chatwin != NULL && timed_out(file_senders[i].last_progress, curtime, 1)) || !remain) {
file_senders[i].last_progress = curtime; file_senders[i].last_progress = curtime;
double pct_remain = remain > 0 ? (1 - (remain / file_senders[i].size)) * 100 : 100; double pct_done = remain > 0 ? (1 - (remain / file_senders[i].size)) * 100 : 100;
print_progress_bar(self, i, -1, pct_remain); print_progress_bar(self, i, -1, pct_done);
file_senders[i].bps = 0; file_senders[i].bps = 0;
} }

View File

@ -185,7 +185,6 @@ static void help_draw_chat(ToxWindow *self)
wattroff(win, A_BOLD); wattroff(win, A_BOLD);
wprintw(win, " /call : Audio call\n"); wprintw(win, " /call : Audio call\n");
wprintw(win, " /cancel : Cancel call\n");
wprintw(win, " /answer : Answer incoming call\n"); wprintw(win, " /answer : Answer incoming call\n");
wprintw(win, " /reject : Reject incoming call\n"); wprintw(win, " /reject : Reject incoming call\n");
wprintw(win, " /hangup : Hangup active call\n"); wprintw(win, " /hangup : Hangup active call\n");