1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 20:23:25 +01:00

make audio messages compatible with new printing method

This commit is contained in:
Jfreegman 2014-03-25 04:39:44 -04:00
parent 5e941427d3
commit 2f981ecb12
5 changed files with 101 additions and 68 deletions

View File

@ -11,6 +11,7 @@
#include "chat_commands.h"
#include "global_commands.h"
#include "toxic_windows.h"
#include "line_info.h"
#include <curses.h>
#include <AL/al.h>
@ -51,7 +52,6 @@ struct _ASettings {
int ttas; /* Transmission thread active status (0 - stopped, 1- running) */
} ASettins;
void callback_recv_invite ( void *arg );
void callback_recv_ringing ( void *arg );
void callback_recv_starting ( void *arg );
@ -65,16 +65,24 @@ void callback_requ_timeout ( void *arg );
void callback_peer_timeout ( void* arg );
static void print_err (ToxWindow *self, char *error_str)
{
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
}
/* Opens device under current index
*/
int device_open (WINDOW *window, _Devices type)
int device_open (ToxWindow *self, _Devices type)
{
WINDOW *window = self->chatwin->history;
/* Do not error if no device */
if ( !ASettins.device[type].size ) return 0;
ALCdevice* prev_device = ASettins.device[type].dhndl;
const char* error = NULL;
uint8_t msg[MAX_STR_SIZE];
uint8_t* error = NULL;
if ( type == input ) {
ASettins.device[type].dhndl = alcCaptureOpenDevice(
@ -101,7 +109,10 @@ int device_open (WINDOW *window, _Devices type)
if ( prev_device )
alcCaptureCloseDevice(prev_device);
if ( window ) wprintw(window, "Input device: %s\n", ASettins.device[type].devices[ASettins.device[type].index]);
if ( window ) {
snprintf(msg, sizeof(msg), "Input device: %s", ASettins.device[type].devices[ASettins.device[type].index]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
}
ASettins.device[type].ctx = NULL;
@ -136,20 +147,27 @@ int device_open (WINDOW *window, _Devices type)
ASettins.device[type].ctx = alcCreateContext(ASettins.device[type].dhndl, NULL);
if ( window ) wprintw(window, "Output device: %s\n", ASettins.device[type].devices[ASettins.device[type].index]);
if ( window ) {
snprintf(msg, sizeof(msg), "Output device: %s", ASettins.device[type].devices[ASettins.device[type].index]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
}
}
if ( error ) {
if ( window ) wprintw(window, "Error: %s\n", error);
if ( window ) {
snprintf(msg, sizeof(msg), "Error: %s", error);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
return -1;
}
else return 0;
}
int device_close (WINDOW *window, _Devices type)
int device_close (ToxWindow *self, _Devices type)
{
const char* device = NULL;
uint8_t* device = NULL;
if ( ASettins.device[type].dhndl ) {
if (type == input) {
@ -169,11 +187,14 @@ int device_close (WINDOW *window, _Devices type)
ASettins.device[type].index = ASettins.device[type].dix;
}
if ( window && device ) wprintw(window, "Closed %s device\n", device);
if ( self && device ) {
uint8_t msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Closed %s device", device);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
}
ToxAv* init_audio(ToxWindow* window, Tox* tox)
ToxAv* init_audio(ToxWindow* self, Tox* tox)
{
ASettins.errors = NoError;
ASettins.ttas = 0; /* Not running */
@ -214,7 +235,8 @@ ToxAv* init_audio(ToxWindow* window, Tox* tox)
}
if (!ASettins.device[input].size && !ASettins.device[output].size) {
wprintw(window->window, "No devices: disabling audio!\n");
uint8_t *msg = "No devices: disabling audio!";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
ASettins.av = NULL;
}
else {
@ -226,19 +248,19 @@ ToxAv* init_audio(ToxWindow* window, Tox* tox)
return NULL;
}
toxav_register_callstate_callback(callback_call_started, av_OnStart, window);
toxav_register_callstate_callback(callback_call_canceled, av_OnCancel, window);
toxav_register_callstate_callback(callback_call_rejected, av_OnReject, window);
toxav_register_callstate_callback(callback_call_ended, av_OnEnd, window);
toxav_register_callstate_callback(callback_recv_invite, av_OnInvite, window);
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(callback_recv_ringing, av_OnRinging, window);
toxav_register_callstate_callback(callback_recv_starting, av_OnStarting, window);
toxav_register_callstate_callback(callback_recv_ending, av_OnEnding, window);
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(callback_recv_error, av_OnError, window);
toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, window);
toxav_register_callstate_callback(callback_peer_timeout, av_OnPeerTimeout, window);
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);
}
return ASettins.av;
@ -371,7 +393,7 @@ cleanup:
_cbend;
}
int start_transmission()
int start_transmission(ToxWindow *self)
{
if ( !ASettins.av ) return -1;
@ -380,9 +402,9 @@ int start_transmission()
return -1;
/* Now open our devices */
if ( -1 == device_open(NULL, input) )
if ( -1 == device_open(self, input) )
return -1;
if ( -1 == device_open(NULL, output))
if ( -1 == device_open(self, output))
return -1;
/* Don't provide support for video */
@ -478,7 +500,8 @@ void callback_peer_timeout ( void* arg )
*/
void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char* error_str;
uint8_t msg[MAX_STR_SIZE];
uint8_t* error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
@ -492,17 +515,19 @@ void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
goto on_error;
}
wprintw(window, "Calling...\n");
error_str = "Calling...";
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
return;
on_error:
wprintw(window, "%s %d\n", error_str, argc);
on_error:
snprintf(msg ,sizeof(msg), "%s %d", error_str, argc);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
void cmd_answer(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char* error_str;
uint8_t* error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
@ -522,12 +547,12 @@ void cmd_answer(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
return;
on_error:
wprintw(window, "%s\n", error_str);
print_err (self, error_str);
}
void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char* error_str;
uint8_t* error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
@ -545,12 +570,12 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
return;
on_error:
wprintw(window, "%s\n", 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;
uint8_t* error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
@ -569,13 +594,14 @@ void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
return;
on_error:
wprintw(window, "%s\n", error_str);
print_err (self, error_str);
}
void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char* error_str;
uint8_t msg[MAX_STR_SIZE];
uint8_t* error_str;
if ( argc != 1 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -593,22 +619,26 @@ void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*
type = output;
else {
wprintw(window, "Invalid type: %s\n", argv[1]);
snprintf(msg, sizeof(msg), "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
return;
}
int i = 0;
for ( ; i < ASettins.device[type].size; i ++)
wprintw(window, "%d: %s\n", i, ASettins.device[type].devices[i]);
for ( ; i < ASettins.device[type].size; i ++) {
snprintf(msg, sizeof(msg), "%d: %s", i, ASettins.device[type].devices[i]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
return;
on_error:
wprintw(window, "%s\n", error_str);
print_err (self, error_str);
}
void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char* error_str;
uint8_t msg[MAX_STR_SIZE];
uint8_t* error_str;
if ( argc != 2 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -632,7 +662,8 @@ void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
type = output;
else {
wprintw(window, "Invalid type: %s\n", argv[1]);
snprintf(msg, sizeof(msg), "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
return;
}
@ -651,9 +682,10 @@ void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
}
ASettins.device[type].index = selection;
wprintw(window, "Selected: %s\n", ASettins.device[type].devices[selection]);
snprintf(msg, sizeof(msg), "Selected: %s", ASettins.device[type].devices[selection]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
return;
on_error:
wprintw(window, "%s\n", error_str);
}
print_err (self, error_str);
}

View File

@ -20,11 +20,11 @@ typedef enum _AudioError
/* You will have to pass pointer to first member of 'windows'
* declared in windows.c otherwise undefined behaviour will
*/
ToxAv* init_audio(ToxWindow* window, Tox* tox);
ToxAv* init_audio(ToxWindow* self, Tox* tox);
void terminate_audio();
int errors();
int start_transmission();
int start_transmission(ToxWindow *self);
#endif /* _audio_h */

View File

@ -364,7 +364,7 @@ void chat_onStarting (ToxWindow *self, ToxAv *av)
uint8_t *msg;
if ( 0 != start_transmission() ) {/* YEAH! */
if ( 0 != start_transmission(self) ) {/* YEAH! */
msg = "Error starting transmission!";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
return;
@ -401,7 +401,7 @@ void chat_onStart (ToxWindow *self, ToxAv *av)
uint8_t *msg;
if ( 0 != start_transmission() ) {/* YEAH! */
if ( 0 != start_transmission(self) ) {/* YEAH! */
msg = "Error starting transmission!";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
return;
@ -687,6 +687,9 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
ChatContext *ctx = self->chatwin;
if (!ctx->hst->scroll_mode)
curs_set(1);
wclear(ctx->linewin);
line_info_print(self);
@ -790,7 +793,6 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
static void chat_onInit(ToxWindow *self, Tox *m)
{
curs_set(1);
int x2, y2;
getmaxyx(self->window, y2, x2);
self->x = x2;

View File

@ -518,19 +518,18 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
#ifdef _SUPPORT_AUDIO
uint8_t *msg;
attron(COLOR_PAIR(RED) | A_BOLD);
wprintw(prompt->window, "Starting audio...\n");
attroff(COLOR_PAIR(RED) | A_BOLD);
#ifdef _SUPPORT_AUDIO
av = init_audio(prompt, m);
if ( errors() == NoError )
wprintw(prompt->window, "Audio started with no problems.\n");
msg = "Audio started with no problems.";
else /* Get error code and stuff */
wprintw(prompt->window, "Error starting audio!\n");
msg = "Error starting audio!";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
#endif /* _SUPPORT_AUDIO */
@ -538,17 +537,13 @@ int main(int argc, char *argv[])
load_data(m, DATA_FILE);
if (f_flag == -1) {
attron(COLOR_PAIR(RED) | A_BOLD);
wprintw(prompt->window, "You passed '-f' without giving an argument.\n"
"defaulting to 'data' for a keyfile...\n");
attroff(COLOR_PAIR(RED) | A_BOLD);
msg = "You passed '-f' without giving an argument. Defaulting to 'data' for a keyfile...";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
if (config_err) {
attron(COLOR_PAIR(RED) | A_BOLD);
wprintw(prompt->window, "Unable to determine configuration directory.\n"
"defaulting to 'data' for a keyfile...\n");
attroff(COLOR_PAIR(RED) | A_BOLD);
msg = "Unable to determine configuration directory. Defaulting to 'data' for a keyfile...";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
sort_friendlist_index();

View File

@ -273,6 +273,10 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
int x, y, x2, y2;
getyx(ctx->history, y, x);
getmaxyx(ctx->history, y2, x2);
if (!ctx->hst->scroll_mode)
curs_set(1);
line_info_print(self);
/* if len is >= screen width offset max x by X_OFST to account for prompt char */