mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 19:53:25 +01:00
reduce syntactic complexity - these don't need to be void
This commit is contained in:
parent
e4e7ed7e4e
commit
7ad520f128
31
src/chat.c
31
src/chat.c
@ -13,6 +13,7 @@
|
||||
#include "toxic_windows.h"
|
||||
#include "execute.h"
|
||||
#include "misc_tools.h"
|
||||
#include "friendlist.h"
|
||||
|
||||
extern char *DATA_FILE;
|
||||
extern int store_data(Tox *m, char *path);
|
||||
@ -23,7 +24,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint1
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, num, nick);
|
||||
@ -49,7 +50,7 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t st
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
StatusBar *statusbar = self->stb;
|
||||
statusbar->is_online = status == 1 ? true : false;
|
||||
}
|
||||
|
||||
@ -58,7 +59,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, num, nick);
|
||||
@ -87,7 +88,7 @@ static void chat_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
StatusBar *statusbar = self->stb;
|
||||
statusbar->status = status;
|
||||
}
|
||||
|
||||
@ -96,7 +97,7 @@ static void chat_onStatusMessageChange(ToxWindow *self, int num, uint8_t *status
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
StatusBar *statusbar = self->stb;
|
||||
statusbar->statusmsg_len = len;
|
||||
memcpy(statusbar->statusmsg, status, len);
|
||||
}
|
||||
@ -107,7 +108,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
int idx = strlen(pathname) - 1;
|
||||
while (pathname[idx] == '/' && idx >= 0) {
|
||||
@ -167,7 +168,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int num, uint8_t receive
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
uint8_t *filename;
|
||||
|
||||
if (receive_send == 0)
|
||||
@ -200,7 +201,7 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, u
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
uint8_t *filename = friends[num].file_receiver.filenames[filenum];
|
||||
FILE *file_to_save = fopen(filename, "a");
|
||||
@ -227,7 +228,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_
|
||||
if (self->num != friendnumber)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
|
||||
if (tox_get_name(m, friendnumber, name) == -1)
|
||||
@ -268,8 +269,8 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *acti
|
||||
|
||||
static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
StatusBar *statusbar = self->stb;
|
||||
|
||||
int x, y, y2, x2;
|
||||
getyx(self->window, y, x);
|
||||
@ -363,10 +364,10 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
||||
int x, y;
|
||||
getmaxyx(self->window, y, x);
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
/* Draw status bar */
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
StatusBar *statusbar = self->stb;
|
||||
mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x);
|
||||
wmove(statusbar->topline, 0, 0);
|
||||
|
||||
@ -441,7 +442,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
self->x = x;
|
||||
|
||||
/* Init statusbar info */
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
StatusBar *statusbar = self->stb;
|
||||
statusbar->status = tox_get_user_status(m, self->num);
|
||||
statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;
|
||||
|
||||
@ -451,7 +452,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
statusbar->statusmsg_len = tox_get_status_message_size(m, self->num);
|
||||
|
||||
/* Init subwindows */
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
statusbar->topline = subwin(self->window, 2, x, 0, 0);
|
||||
ctx->history = subwin(self->window, y-CHATBOX_HEIGHT+1, x, 0, 0);
|
||||
scrollok(ctx->history, 1);
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "toxic_windows.h"
|
||||
#include "misc_tools.h"
|
||||
#include "friendlist.h"
|
||||
|
||||
extern ToxWindow *prompt;
|
||||
extern int num_groupchats;
|
||||
|
@ -165,7 +165,7 @@ static void select_friend(ToxWindow *self, Tox *m, wint_t key)
|
||||
static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
|
||||
{
|
||||
tox_del_friend(m, f_num);
|
||||
memset(&friends[f_num], 0, sizeof(friend_t));
|
||||
memset(&friends[f_num], 0, sizeof(ToxicFriend));
|
||||
|
||||
int i;
|
||||
|
||||
|
@ -102,7 +102,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
if (self->num != groupnum)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_group_peername(m, groupnum, peernum, nick);
|
||||
@ -180,7 +180,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
||||
|
||||
qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, name_compare);
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
print_time(ctx->history);
|
||||
|
||||
switch (change) {
|
||||
@ -220,7 +220,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
||||
|
||||
static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
int x, y, y2, x2;
|
||||
getyx(self->window, y, x);
|
||||
@ -307,7 +307,7 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||
int x, y;
|
||||
getmaxyx(self->window, y, x);
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
wclrtobot(ctx->sidebar);
|
||||
mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x);
|
||||
mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y-CHATBOX_HEIGHT);
|
||||
@ -341,7 +341,7 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
|
||||
int x, y;
|
||||
getmaxyx(self->window, y, x);
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
ChatContext *ctx = self->chatwin;
|
||||
ctx->history = subwin(self->window, y-CHATBOX_HEIGHT+1, x-SIDEBAR_WIDTH-1, 0, 0);
|
||||
scrollok(ctx->history, 1);
|
||||
ctx->linewin = subwin(self->window, 2, x, y-CHATBOX_HEIGHT, 0);
|
||||
|
@ -89,7 +89,7 @@ static void init_term(void)
|
||||
refresh();
|
||||
}
|
||||
|
||||
static Tox *init_tox()
|
||||
static Tox *init_tox(void)
|
||||
{
|
||||
/* Init core */
|
||||
Tox *m = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
||||
@ -380,7 +380,7 @@ static void do_file_senders(Tox *m)
|
||||
|
||||
/* If file transfer has timed out kill transfer and send kill control */
|
||||
if (timed_out(file_senders[i].timestamp, current_time, TIMEOUT_FILESENDER)) {
|
||||
ChatContext *ctx = (ChatContext *) file_senders[i].toxwin->chatwin;
|
||||
ChatContext *ctx = file_senders[i].toxwin->chatwin;
|
||||
|
||||
if (ctx != NULL) {
|
||||
wprintw(ctx->history, "File transfer for '%s' timed out.\n", pathname);
|
||||
@ -404,7 +404,7 @@ static void do_file_senders(Tox *m)
|
||||
tox_file_data_size(m, friendnum), fp);
|
||||
|
||||
if (file_senders[i].piecelen == 0) {
|
||||
ChatContext *ctx = (ChatContext *) file_senders[i].toxwin->chatwin;
|
||||
ChatContext *ctx = file_senders[i].toxwin->chatwin;
|
||||
|
||||
if (ctx != NULL) {
|
||||
wprintw(ctx->history, "File '%s' successfuly sent.\n", pathname);
|
||||
|
12
src/prompt.c
12
src/prompt.c
@ -23,7 +23,7 @@ static int prompt_buf_pos = 0;
|
||||
/* Updates own nick in prompt statusbar */
|
||||
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len)
|
||||
{
|
||||
StatusBar *statusbar = (StatusBar *) prompt->stb;
|
||||
StatusBar *statusbar = prompt->stb;
|
||||
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
||||
statusbar->nick_len = len;
|
||||
}
|
||||
@ -31,7 +31,7 @@ void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len)
|
||||
/* Updates own statusmessage in prompt statusbar */
|
||||
void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len)
|
||||
{
|
||||
StatusBar *statusbar = (StatusBar *) prompt->stb;
|
||||
StatusBar *statusbar = prompt->stb;
|
||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||
statusbar->statusmsg_len = len;
|
||||
}
|
||||
@ -39,14 +39,14 @@ void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t
|
||||
/* Updates own status in prompt statusbar */
|
||||
void prompt_update_status(ToxWindow *prompt, TOX_USERSTATUS status)
|
||||
{
|
||||
StatusBar *statusbar = (StatusBar *) prompt->stb;
|
||||
StatusBar *statusbar = prompt->stb;
|
||||
statusbar->status = status;
|
||||
}
|
||||
|
||||
/* Updates own connection status in prompt statusbar */
|
||||
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
|
||||
{
|
||||
StatusBar *statusbar = (StatusBar *) prompt->stb;
|
||||
StatusBar *statusbar = prompt->stb;
|
||||
statusbar->is_online = is_connected;
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
--y;
|
||||
}
|
||||
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
StatusBar *statusbar = self->stb;
|
||||
werase(statusbar->topline);
|
||||
mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x2);
|
||||
wmove(statusbar->topline, 0, 0);
|
||||
@ -239,7 +239,7 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
|
||||
getmaxyx(self->window, y, x);
|
||||
|
||||
/* Init statusbar info */
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
StatusBar *statusbar = self->stb;
|
||||
statusbar->status = TOX_USERSTATUS_NONE;
|
||||
statusbar->is_online = false;
|
||||
|
||||
|
@ -51,9 +51,11 @@ enum {
|
||||
Uncomment if necessary */
|
||||
//#define URXVT_FIX
|
||||
|
||||
typedef struct ToxWindow_ ToxWindow;
|
||||
typedef struct ToxWindow ToxWindow;
|
||||
typedef struct StatusBar StatusBar;
|
||||
typedef struct ChatContext ChatContext;
|
||||
|
||||
struct ToxWindow_ {
|
||||
struct ToxWindow {
|
||||
void(*onKey)(ToxWindow *, Tox *, wint_t);
|
||||
void(*onDraw)(ToxWindow *, Tox *);
|
||||
void(*onInit)(ToxWindow *, Tox *);
|
||||
@ -78,13 +80,13 @@ struct ToxWindow_ {
|
||||
int num;
|
||||
int x;
|
||||
|
||||
void *chatwin;
|
||||
void *stb;
|
||||
ChatContext *chatwin;
|
||||
StatusBar *stb;
|
||||
|
||||
WINDOW *window;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct StatusBar {
|
||||
WINDOW *topline;
|
||||
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||
uint16_t statusmsg_len;
|
||||
@ -92,15 +94,15 @@ typedef struct {
|
||||
uint16_t nick_len;
|
||||
TOX_USERSTATUS status;
|
||||
bool is_online;
|
||||
} StatusBar;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct ChatContext {
|
||||
wchar_t line[MAX_STR_SIZE];
|
||||
size_t pos;
|
||||
WINDOW *history;
|
||||
WINDOW *linewin;
|
||||
WINDOW *sidebar;
|
||||
} ChatContext;
|
||||
};
|
||||
|
||||
/* Start file transfer code */
|
||||
|
||||
@ -124,10 +126,10 @@ typedef struct {
|
||||
FileSender file_senders[MAX_FILES];
|
||||
uint8_t max_file_senders_index;
|
||||
|
||||
typedef struct {
|
||||
struct FileReceiver {
|
||||
uint8_t filenames[MAX_FILES][MAX_STR_SIZE];
|
||||
bool pending[MAX_FILES];
|
||||
} FileReceiver;
|
||||
};
|
||||
|
||||
/* End file transfer code */
|
||||
|
||||
@ -142,10 +144,10 @@ typedef struct {
|
||||
bool active;
|
||||
bool online;
|
||||
TOX_USERSTATUS status;
|
||||
FileReceiver file_receiver;
|
||||
} friend_t;
|
||||
struct FileReceiver file_receiver;
|
||||
} ToxicFriend;
|
||||
|
||||
friend_t friends[MAX_FRIENDS_NUM];
|
||||
ToxicFriend friends[MAX_FRIENDS_NUM];
|
||||
|
||||
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata);
|
||||
void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdata);
|
||||
|
Loading…
Reference in New Issue
Block a user