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

General cleanup

Signed-off-by: Sean Qureshi <sean@tox.im>
This commit is contained in:
Sean Qureshi 2014-04-19 14:58:13 -07:00
parent 7f5dc0a756
commit 4cac797b40
No known key found for this signature in database
GPG Key ID: 13D2043169D25DF4
23 changed files with 806 additions and 723 deletions

View File

@ -108,16 +108,13 @@ int device_open (ToxWindow *self, _Devices type)
error = "Error starting input device!";
ASettins.errors |= ErrorStartingCaptureDevice;
}
else {
} else {
error = "Could not start input device, falling back to previous";
/* NOTE: What if device is opened? */
ASettins.device[type].dhndl = prev_device;
}
}
else
{
} else {
/* Close previous */
if ( prev_device )
alcCaptureCloseDevice(prev_device);
@ -129,8 +126,7 @@ int device_open (ToxWindow *self, _Devices type)
}
ASettins.device[type].ctx = NULL;
}
else {
} else {
ASettins.device[type].dhndl = alcOpenDevice(ASettins.device[type].devices[ASettins.device[type].index]);
if (alcGetError(ASettins.device[type].dhndl) != AL_NO_ERROR) {
@ -141,15 +137,13 @@ int device_open (ToxWindow *self, _Devices type)
ASettins.errors |= ErrorStartingOutputDevice;
ASettins.device[type].ctx = NULL;
}
else {
} else {
error = "Could not start output device, falling back to previous";
/* NOTE: What if device is opened? */
ASettins.device[type].dhndl = prev_device;
}
}
else {
} else {
/* Close previous */
if ( prev_device ) {
@ -174,8 +168,7 @@ int device_open (ToxWindow *self, _Devices type)
}
return -1;
}
else return 0;
} else return 0;
}
int device_close (ToxWindow *self, _Devices type)
@ -186,8 +179,7 @@ int device_close (ToxWindow *self, _Devices type)
if (type == input) {
alcCaptureCloseDevice(ASettins.device[type].dhndl);
device = "input";
}
else {
} else {
alcCloseDevice(ASettins.device[type].dhndl);
alcMakeContextCurrent(NULL);
@ -251,8 +243,7 @@ ToxAv* init_audio(ToxWindow* self, Tox* tox)
uint8_t *msg = "No devices: disabling audio!";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
ASettins.av = NULL;
}
else {
} else {
/* Streaming stuff from core */
ToxAvCodecSettings cs = av_DefaultSettings;
@ -335,6 +326,7 @@ void* transmission(void* arg)
int16_t PCM[AUDIO_FRAME_SIZE];
int32_t i = 0;
for (; i < openal_buffers; ++i) {
alBufferData(buffers[i], AL_FORMAT_MONO16, zeros, AUDIO_FRAME_SIZE, 48000);
}
@ -421,6 +413,7 @@ int start_transmission(ToxWindow *self)
/* Now open our devices */
if ( -1 == device_open(self, input) )
return -1;
if ( -1 == device_open(self, output))
return -1;
@ -520,9 +513,15 @@ void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
uint8_t msg[MAX_STR_SIZE];
uint8_t *error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
if (argc != 0) {
error_str = "Invalid syntax!";
goto on_error;
}
if ( !ASettins.av ) { error_str = "Audio not supported!"; goto on_error; }
if ( !ASettins.av ) {
error_str = "Audio not supported!";
goto on_error;
}
ToxAvError error = toxav_call(ASettins.av, self->num, TypeAudio, 30);
@ -546,9 +545,15 @@ void cmd_answer(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
{
uint8_t *error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
if (argc != 0) {
error_str = "Invalid syntax!";
goto on_error;
}
if ( !ASettins.av ) { error_str = "Audio not supported!"; goto on_error; }
if ( !ASettins.av ) {
error_str = "Audio not supported!";
goto on_error;
}
ToxAvError error = toxav_answer(ASettins.av, TypeAudio);
@ -571,9 +576,15 @@ void cmd_reject(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
{
uint8_t *error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
if (argc != 0) {
error_str = "Invalid syntax!";
goto on_error;
}
if ( !ASettins.av ) { error_str = "Audio not supported!"; goto on_error; }
if ( !ASettins.av ) {
error_str = "Audio not supported!";
goto on_error;
}
ToxAvError error = toxav_reject(ASettins.av, "Why not?");
@ -596,9 +607,15 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
{
uint8_t *error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
if (argc != 0) {
error_str = "Invalid syntax!";
goto on_error;
}
if ( !ASettins.av ) { error_str = "Audio not supported!"; goto on_error; }
if ( !ASettins.av ) {
error_str = "Audio not supported!";
goto on_error;
}
ToxAvError error = toxav_hangup(ASettins.av);
@ -619,11 +636,18 @@ void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
{
uint8_t *error_str;
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
if (argc != 0) {
error_str = "Invalid syntax!";
goto on_error;
}
if ( !ASettins.av ) { error_str = "Audio not supported!"; goto on_error; }
if ( !ASettins.av ) {
error_str = "Audio not supported!";
goto on_error;
}
ToxAvError error = toxav_cancel(ASettins.av, self->num, "Only those who appreciate small things know the beauty of life");
ToxAvError error = toxav_cancel(ASettins.av, self->num,
"Only those who appreciate small things know the beauty of life");
if ( error != ErrorNone ) {
if ( error == ErrorNoCall ) error_str = "No call!";
@ -667,6 +691,7 @@ void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*
}
int i = 0;
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);

View File

@ -9,16 +9,14 @@
#define MAX_DEVICES 32
typedef enum _AudioError
{
typedef enum _AudioError {
NoError = 0,
ErrorStartingCaptureDevice = 1 << 0,
ErrorStartingOutputDevice = 1 << 1,
ErrorStartingCoreAudio = 1 << 2
} AudioError;
typedef enum _Devices
{
typedef enum _Devices {
input,
output,
} _Devices;

View File

@ -299,14 +299,18 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
snprintf(msg, sizeof(msg), "File transfer for '%s' accepted (%.1f%%)", filename, 0.0);
file_senders[filenum].line_id = self->chatwin->hst->line_end->id + 1;
break;
/*case TOX_FILECONTROL_PAUSE:
wprintw(ctx->history, "File transfer for '%s' paused.\n", filename);
break; */
case TOX_FILECONTROL_KILL:
snprintf(msg, sizeof(msg), "File transfer for '%s' failed.", filename);
if (receive_send == 0)
chat_close_file_receiver(num, filenum);
break;
case TOX_FILECONTROL_FINISHED:
snprintf(msg, sizeof(msg), "File transfer for '%s' complete.", filename);
chat_close_file_receiver(num, filenum);
@ -492,7 +496,8 @@ void chat_onPeerTimeout (ToxWindow *self, ToxAv *av)
#endif /* _SUPPORT_AUDIO */
static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action) {
static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action)
{
if (action == NULL)
return;
@ -757,14 +762,17 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
status_text = "Online";
colour = GREEN;
break;
case TOX_USERSTATUS_AWAY:
status_text = "Away";
colour = YELLOW;
break;
case TOX_USERSTATUS_BUSY:
status_text = "Busy";
colour = RED;
break;
case TOX_USERSTATUS_INVALID:
status_text = "ERROR";
colour = MAGENTA;
@ -808,6 +816,7 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
/* Truncate note if it doesn't fit in statusbar */
uint16_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 7;
if (statusbar->statusmsg_len > maxlen) {
statusbar->statusmsg[maxlen] = '\0';
statusbar->statusmsg_len = maxlen;

View File

@ -110,6 +110,7 @@ char *get_user_config_dir(void)
# else /* __APPLE__ */
const char *tmp;
if (!(tmp = getenv("XDG_CONFIG_HOME"))) {
len = strlen(home) + strlen("/.config") + 1;
user_config_dir = malloc(len);

View File

@ -147,6 +147,7 @@ void execute(WINDOW* w, ToxWindow *self, Tox *m, char *cmd, int mode)
case CHAT_COMMAND_MODE:
if (do_command(w, self, m, num_args, CHAT_NUM_COMMANDS, chat_commands, args) == 0)
return;
break;
case GROUPCHAT_COMMAND_MODE:

View File

@ -436,12 +436,15 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
case TOX_USERSTATUS_NONE:
colour = GREEN;
break;
case TOX_USERSTATUS_AWAY:
colour = YELLOW;
break;
case TOX_USERSTATUS_BUSY:
colour = RED;
break;
case TOX_USERSTATUS_INVALID:
colour = MAGENTA;
break;
@ -477,6 +480,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
/* Truncate note if it doesn't fit on one line */
uint16_t maxlen = x2 - getcurx(self->window) - 2;
if (friends[f].statusmsg_len > maxlen) {
friends[f].statusmsg[maxlen - 3] = '\0';
strcat(friends[f].statusmsg, "...");
@ -511,9 +515,11 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
case 0:
wprintw(self->window, " Last seen: Today %s\n", hourmin);
break;
case 1:
wprintw(self->window, " Last seen: Yesterday %s\n", hourmin);
break;
default:
wprintw(self->window, " Last seen: %d days ago\n", day_dist);
break;
@ -539,6 +545,7 @@ void disable_chatwin(int32_t f_num)
static void friendlist_onAv(ToxWindow *self, ToxAv *av)
{
int id = toxav_get_peer_id(av, 0);
/*id++;*/
if ( id != ErrorInternal && id >= max_friends_index)
return;

View File

@ -154,24 +154,31 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
case TOX_FAERR_TOOLONG:
errmsg = "Message is too long.";
break;
case TOX_FAERR_NOMESSAGE:
errmsg = "Please add a message to your request.";
break;
case TOX_FAERR_OWNKEY:
errmsg = "That appears to be your own ID.";
break;
case TOX_FAERR_ALREADYSENT:
errmsg = "Friend request has already been sent.";
break;
case TOX_FAERR_UNKNOWN:
errmsg = "Undefined error when adding friend.";
break;
case TOX_FAERR_BADCHECKSUM:
errmsg = "Bad checksum in address.";
break;
case TOX_FAERR_SETNEWNOSPAM:
errmsg = "Nospam was different (is this contact already added?";
break;
default:
errmsg = "Friend request sent.";
on_friendadded(m, f_num, true);

View File

@ -360,7 +360,8 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
alert_window(self, WINDOW_ALERT_2, false);
}
static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action) {
static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action)
{
if (action == NULL) {
wprintw(ctx->history, "Invalid syntax.\n");
return;

View File

@ -128,6 +128,7 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na
case ACTION:
len += 3;
break;
default:
len += 2;
break;
@ -136,13 +137,19 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na
if (msg) {
memcpy(new_line->msg, msg, sizeof(new_line->msg));
len += strlen(msg);
} if (tmstmp) {
}
if (tmstmp) {
memcpy(new_line->timestamp, tmstmp, sizeof(new_line->timestamp));
len += strlen(tmstmp);
} if (name1) {
}
if (name1) {
memcpy(new_line->name1, name1, sizeof(new_line->name1));
len += strlen(name1);
} if (name2) {
}
if (name2) {
memcpy(new_line->name2, name2, sizeof(new_line->name2));
len += strlen(name2);
}
@ -274,6 +281,7 @@ void line_info_print(ToxWindow *self)
if (line->bold)
wattron(win, A_BOLD);
if (line->colour)
wattron(win, COLOR_PAIR(line->colour));
@ -281,6 +289,7 @@ void line_info_print(ToxWindow *self)
if (line->bold)
wattroff(win, A_BOLD);
if (line->colour)
wattroff(win, COLOR_PAIR(line->colour));
@ -398,18 +407,23 @@ void line_info_onKey(ToxWindow *self, wint_t key)
case KEY_PPAGE:
line_info_page_up(self, hst);
break;
case KEY_NPAGE:
line_info_page_down(self, hst);
break;
case KEY_UP:
line_info_scroll_up(hst);
break;
case KEY_DOWN:
line_info_scroll_down(hst);
break;
case KEY_HOME:
line_info_goto_root(hst);
break;
case KEY_END:
line_info_reset_start(hst);
break;

View File

@ -95,11 +95,13 @@ static void init_term(void)
/* Setup terminal */
signal(SIGWINCH, on_window_resize);
#if HAVE_WIDECHAR
if (setlocale(LC_ALL, "") == NULL) {
fprintf(stderr, "Could not set your locale, plese check your locale settings or"
"disable wide char support\n");
exit(EXIT_FAILURE);
}
#endif
initscr();
cbreak();
@ -199,11 +201,13 @@ static int nodelist_load(char *filename)
return 1;
char line[MAXLINE];
while (fgets(line, sizeof(line), fp) && linecnt < MAXNODES) {
if (strlen(line) > MINLINE) {
char *name = strtok(line, " ");
char *port = strtok(NULL, " ");
char *key_ascii = strtok(NULL, " ");
/* invalid line */
if (name == NULL || port == NULL || key_ascii == NULL)
continue;
@ -484,11 +488,13 @@ int main(int argc, char *argv[])
}
config_err = create_user_config_dir(user_config_dir);
if (DATA_FILE == NULL ) {
if (config_err) {
DATA_FILE = strdup("data");
} else {
DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
if (DATA_FILE != NULL) {
strcpy(DATA_FILE, user_config_dir);
strcat(DATA_FILE, CONFIGDIR);

View File

@ -179,9 +179,11 @@ void alert_window(ToxWindow *self, int type, bool is_beep)
case WINDOW_ALERT_0:
self->alert0 = true;
break;
case WINDOW_ALERT_1:
self->alert1 = true;
break;
case WINDOW_ALERT_2:
self->alert2 = true;
break;
@ -214,6 +216,7 @@ int valid_nick(uint8_t *nick)
for (i = 0; nick[i]; ++i) {
if (nick[i] == ' ' && nick[i + 1] == ' ')
return 0;
if (nick[i] == '/')
return 0;
}

View File

@ -329,19 +329,23 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
status_text = "Online";
colour = GREEN;
break;
case TOX_USERSTATUS_AWAY:
status_text = "Away";
colour = YELLOW;
break;
case TOX_USERSTATUS_BUSY:
status_text = "Busy";
colour = RED;
break;
case TOX_USERSTATUS_INVALID:
status_text = "ERROR";
colour = MAGENTA;
break;
}
wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
wprintw(statusbar->topline, " [%s]", status_text);
wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);

View File

@ -186,6 +186,7 @@ int complete_line(wchar_t *buf, size_t *pos, size_t *len, const void *list, int
const uint8_t *L = (uint8_t *) list;
uint8_t ubuf[MAX_STR_SIZE];
/* work with multibyte string copy of buf for simplicity */
if (wcs_to_mbs_buf(ubuf, buf, MAX_STR_SIZE) == -1)
return -1;
@ -199,6 +200,7 @@ int complete_line(wchar_t *buf, size_t *pos, size_t *len, const void *list, int
if (!sub++) {
sub = tmp;
if (sub[0] != '/') /* make sure it's not a command */
n_endchrs = 2;
}
@ -214,6 +216,7 @@ int complete_line(wchar_t *buf, size_t *pos, size_t *len, const void *list, int
/* look for a match in list */
for (i = 0; i < n_items; ++i) {
match = &L[i * size];
if (is_match = strncasecmp(match, sub, s_len) == 0)
break;
}

View File

@ -239,8 +239,10 @@ void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message,
void on_groupaction(Tox *m, int groupnumber, int peernumber, uint8_t *action, uint16_t length, void *userdata);
void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t *group_pub_key, void *userdata);
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata);
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *pathname, uint16_t pathname_length, void *userdata);
void on_file_control(Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata);
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *pathname,
uint16_t pathname_length, void *userdata);
void on_file_control(Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type,
uint8_t *data, uint16_t length, void *userdata);
void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata);
void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata);

View File

@ -236,6 +236,7 @@ int add_window(Tox *m, ToxWindow w)
if (w.window == NULL)
return -1;
#ifdef URXVT_FIX
/* Fixes text color problem on some terminals. */
wbkgd(w.window, COLOR_PAIR(6));
@ -405,6 +406,7 @@ void draw_active_window(Tox *m)
ltr = iswprint(ch);
else /* if (status == KEY_CODE_YES) */
ltr = false;
#else
ch = getch();