1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 05:43:03 +01:00

tweaks and fixes

This commit is contained in:
Jfreegman 2013-09-09 00:56:47 -04:00
parent 9798dd6b95
commit fde8059a4c
6 changed files with 39 additions and 33 deletions

View File

@ -98,7 +98,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
beep(); beep();
} }
static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t len) static void chat_onNickChange(ToxWindow *self, Tox *m, int num, uint8_t *nick, uint16_t len)
{ {
if (self->friendnum != num) if (self->friendnum != num)
return; return;
@ -276,6 +276,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd)
else if (!strcmp(cmd, "/quit") || !strcmp(cmd, "/exit") || !strcmp(cmd, "/q")) { else if (!strcmp(cmd, "/quit") || !strcmp(cmd, "/exit") || !strcmp(cmd, "/q")) {
endwin(); endwin();
store_data(m, DATA_FILE); store_data(m, DATA_FILE);
free(DATA_FILE);
tox_kill(m); tox_kill(m);
exit(0); exit(0);
} }

View File

@ -56,13 +56,12 @@ void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t sta
friends[num].online = false; friends[num].online = false;
} }
void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t len) void friendlist_onNickChange(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len)
{ {
if (len >= TOX_MAX_NAME_LENGTH || num < 0 || num >= num_friends) if (len >= TOX_MAX_NAME_LENGTH || num < 0 || num >= num_friends)
return; return;
memcpy((char *) &friends[num].name, (char *) str, len); memcpy((char *) &friends[num].name, (char *) str, len);
friends[num].name[len] = 0;
} }
void friendlist_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS status) void friendlist_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS status)
@ -78,8 +77,6 @@ void friendlist_onStatusMessageChange(ToxWindow *self, int num, uint8_t *str, ui
if (len >= TOX_MAX_STATUSMESSAGE_LENGTH || num < 0 || num >= num_friends) if (len >= TOX_MAX_STATUSMESSAGE_LENGTH || num < 0 || num >= num_friends)
return; return;
/* Ignore default "Online" status message */
if (strncmp(str, "Online", strlen(str)))
memcpy((char *) &friends[num].statusmsg, (char *) str, len); memcpy((char *) &friends[num].statusmsg, (char *) str, len);
} }
@ -219,14 +216,9 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
wattron(self->window, COLOR_PAIR(colour) | A_BOLD); wattron(self->window, COLOR_PAIR(colour) | A_BOLD);
wprintw(self->window, "O"); wprintw(self->window, "O");
wattroff(self->window, COLOR_PAIR(colour) | A_BOLD); wattroff(self->window, COLOR_PAIR(colour) | A_BOLD);
wprintw(self->window, "]%s", friends[i].name); wprintw(self->window, "]%s (%s)\n", friends[i].name, friends[i].statusmsg);
if (friends[i].statusmsg[0])
wprintw(self->window, " (%s)\n", friends[i].statusmsg);
else
wprintw(self->window, "\n");
} else { } else {
wprintw(self->window, "[O]%s\n", friends[i].name); wprintw(self->window, "[O]%s\n", friends[i].name, friends[i].statusmsg);
} }
} }
} }

View File

@ -41,6 +41,7 @@
#ifndef PACKAGE_DATADIR #ifndef PACKAGE_DATADIR
#define PACKAGE_DATADIR "." #define PACKAGE_DATADIR "."
#endif #endif
/* Export for use in Callbacks */ /* Export for use in Callbacks */
char *DATA_FILE = NULL; char *DATA_FILE = NULL;
char *SRVLIST_FILE = NULL; char *SRVLIST_FILE = NULL;
@ -254,15 +255,19 @@ int f_loadfromfile;
/* /*
* Store Messenger to given location * Store Messenger to given location
* Return 0 stored successfully * Return 0 stored successfully
* Return 1 malloc failed * Return 1 file path is NULL
* Return 2 opening path failed * Return 2 malloc failed
* Return 3 fwrite failed * Return 3 opening path failed
* Return 4 fwrite failed
*/ */
int store_data(Tox *m, char *path) int store_data(Tox *m, char *path)
{ {
if (f_loadfromfile == 0) /*If file loading/saving is disabled*/ if (f_loadfromfile == 0) /*If file loading/saving is disabled*/
return 0; return 0;
if (path == NULL)
return 1;
FILE *fd; FILE *fd;
size_t len; size_t len;
uint8_t *buf; uint8_t *buf;
@ -271,7 +276,7 @@ int store_data(Tox *m, char *path)
buf = malloc(len); buf = malloc(len);
if (buf == NULL) { if (buf == NULL) {
return 1; return 2;
} }
tox_save(m, buf); tox_save(m, buf);
@ -280,13 +285,13 @@ int store_data(Tox *m, char *path)
if (fd == NULL) { if (fd == NULL) {
free(buf); free(buf);
return 2; return 3;
} }
if (fwrite(buf, len, 1, fd) != 1) { if (fwrite(buf, len, 1, fd) != 1) {
free(buf); free(buf);
fclose(fd); fclose(fd);
return 3; return 4;
} }
free(buf); free(buf);
@ -380,16 +385,20 @@ int main(int argc, char *argv[])
SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers"); SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers");
} else { } else {
DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
if (DATA_FILE != NULL) {
strcpy(DATA_FILE, user_config_dir); strcpy(DATA_FILE, user_config_dir);
strcat(DATA_FILE, CONFIGDIR); strcat(DATA_FILE, CONFIGDIR);
strcat(DATA_FILE, "data"); strcat(DATA_FILE, "data");
}
SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1);
if (SRVLIST_FILE != NULL) {
strcpy(SRVLIST_FILE, user_config_dir); strcpy(SRVLIST_FILE, user_config_dir);
strcat(SRVLIST_FILE, CONFIGDIR); strcat(SRVLIST_FILE, CONFIGDIR);
strcat(SRVLIST_FILE, "DHTservers"); strcat(SRVLIST_FILE, "DHTservers");
} }
} }
}
free(user_config_dir); free(user_config_dir);

View File

@ -77,7 +77,7 @@ void prompt_update_status(ToxWindow *prompt, TOX_USERSTATUS status)
statusbar->status = status; statusbar->status = status;
} }
/* Updates own connection status */ /* Updates own connection status in prompt statusbar */
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected) void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
{ {
StatusBar *statusbar = (StatusBar *) prompt->s; StatusBar *statusbar = (StatusBar *) prompt->s;
@ -296,6 +296,7 @@ void cmd_quit(ToxWindow *self, Tox *m, int argc, char **argv)
{ {
endwin(); endwin();
store_data(m, DATA_FILE); store_data(m, DATA_FILE);
free(DATA_FILE);
tox_kill(m); tox_kill(m);
exit(0); exit(0);
} }
@ -625,7 +626,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
} }
wattron(statusbar->topline, A_BOLD); wattron(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, "%s ", statusbar->nick); wprintw(statusbar->topline, " %s ", statusbar->nick);
wattron(statusbar->topline, A_BOLD); wattron(statusbar->topline, A_BOLD);
wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD); wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
wprintw(statusbar->topline, "[%s]", status_text); wprintw(statusbar->topline, "[%s]", status_text);
@ -638,7 +639,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
} }
wattron(statusbar->topline, A_BOLD); wattron(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, " | %s", statusbar->statusmsg); wprintw(statusbar->topline, " | %s |", statusbar->statusmsg);
wattroff(statusbar->topline, A_BOLD); wattroff(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, "\n"); wprintw(statusbar->topline, "\n");
@ -676,7 +677,7 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
/* temporary until statusmessage saving works */ /* temporary until statusmessage saving works */
uint8_t *statusmsg = "Toxing on Toxic v0.2.0"; uint8_t *statusmsg = "Toxing on Toxic v0.2.0";
// tox_copy_self_statusmessage(m, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH); m_set_statusmessage(m, statusmsg, strlen(statusmsg) + 1);
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg); snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
/* Init statusbar subwindow */ /* Init statusbar subwindow */

View File

@ -43,7 +43,7 @@ struct ToxWindow_ {
void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t); void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t);
void(*onConnectionChange)(ToxWindow *, Tox *, int, uint8_t); void(*onConnectionChange)(ToxWindow *, Tox *, int, uint8_t);
void(*onMessage)(ToxWindow *, Tox *, int, uint8_t *, uint16_t); void(*onMessage)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
void(*onNickChange)(ToxWindow *, int, uint8_t *, uint16_t); void(*onNickChange)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
void(*onStatusChange)(ToxWindow *, Tox *, int, TOX_USERSTATUS); void(*onStatusChange)(ToxWindow *, Tox *, int, TOX_USERSTATUS);
void(*onStatusMessageChange)(ToxWindow *, int, uint8_t *, uint16_t); void(*onStatusMessageChange)(ToxWindow *, int, uint8_t *, uint16_t);
void(*onAction)(ToxWindow *, Tox *, int, uint8_t *, uint16_t); void(*onAction)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);

View File

@ -88,8 +88,11 @@ void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, v
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onNickChange != NULL) if (windows[i].onNickChange != NULL)
windows[i].onNickChange(&windows[i], friendnumber, string, length); windows[i].onNickChange(&windows[i], m, friendnumber, string, length);
} }
if (store_data(m, DATA_FILE))
wprintw(prompt->window, "\nCould not store Tox data\n");
} }
void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata)