2013-07-31 20:20:16 +02:00
|
|
|
/*
|
|
|
|
* Toxic -- Tox Curses Client
|
|
|
|
*/
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2013-08-11 02:58:15 +02:00
|
|
|
#ifndef _windows_h
|
|
|
|
#define _windows_h
|
2013-07-31 20:20:16 +02:00
|
|
|
|
2013-09-15 22:38:38 +02:00
|
|
|
#ifndef TOXICVER
|
2013-09-21 02:35:03 +02:00
|
|
|
#define TOXICVER "NOVER_" /* Use the -D flag to set this */
|
2013-09-15 22:38:38 +02:00
|
|
|
#endif
|
|
|
|
|
2013-08-11 02:58:15 +02:00
|
|
|
#include <curses.h>
|
2013-08-21 23:19:35 +02:00
|
|
|
#include <wctype.h>
|
|
|
|
#include <wchar.h>
|
2013-08-23 23:03:44 +02:00
|
|
|
|
2013-08-24 04:15:15 +02:00
|
|
|
#include <tox/tox.h>
|
2013-08-23 23:03:44 +02:00
|
|
|
|
2013-11-19 00:52:46 +01:00
|
|
|
#define UNKNOWN_NAME "Unknown"
|
|
|
|
|
2013-08-17 15:40:30 +02:00
|
|
|
#define MAX_WINDOWS_NUM 32
|
2013-08-05 07:57:29 +02:00
|
|
|
#define MAX_FRIENDS_NUM 100
|
2013-08-08 10:51:58 +02:00
|
|
|
#define MAX_STR_SIZE 256
|
|
|
|
#define KEY_SIZE_BYTES 32
|
2013-12-04 07:08:26 +01:00
|
|
|
#define TOXIC_MAX_NAME_LENGTH 32 /* Must be < TOX_MAX_NAME_LENGTH */
|
2013-09-18 02:54:25 +02:00
|
|
|
#define N_DEFAULT_WINS 2 /* number of permanent default windows */
|
2013-11-19 00:52:46 +01:00
|
|
|
#define CURS_Y_OFFSET 3 /* y-axis cursor offset for chat contexts */
|
2013-11-26 23:39:11 +01:00
|
|
|
#define CHATBOX_HEIGHT 4
|
2013-11-19 00:52:46 +01:00
|
|
|
|
2013-09-11 06:02:27 +02:00
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
#define EXIT_FAILURE 1
|
2013-08-14 14:56:29 +02:00
|
|
|
|
2013-12-07 02:56:30 +01:00
|
|
|
/* ASCII key codes */
|
|
|
|
#define T_KEY_KILL 0xB /* ctrl-k */
|
|
|
|
#define T_KEY_DISCARD 0x15 /* ctrl-u */
|
|
|
|
#define T_KEY_NEXT 0x1D /* ctrl-] */
|
|
|
|
#define T_KEY_PREV 0x1B /* ctrl-[ */
|
2013-12-06 04:55:14 +01:00
|
|
|
|
2013-09-05 06:47:33 +02:00
|
|
|
/* Curses foreground colours (background is black) */
|
2013-11-10 07:23:07 +01:00
|
|
|
enum {
|
|
|
|
WHITE,
|
|
|
|
GREEN,
|
|
|
|
CYAN,
|
|
|
|
RED,
|
|
|
|
BLUE,
|
|
|
|
YELLOW,
|
|
|
|
MAGENTA,
|
|
|
|
BLACK,
|
|
|
|
};
|
2013-09-05 06:47:33 +02:00
|
|
|
|
2013-12-07 01:41:53 +01:00
|
|
|
/* tab alert types: lower types take priority */
|
2013-11-29 01:45:28 +01:00
|
|
|
enum {
|
2013-12-07 01:41:53 +01:00
|
|
|
WINDOW_ALERT_0,
|
2013-11-29 01:45:28 +01:00
|
|
|
WINDOW_ALERT_1,
|
|
|
|
WINDOW_ALERT_2,
|
|
|
|
};
|
|
|
|
|
2013-09-26 15:51:21 +02:00
|
|
|
/* Fixes text color problem on some terminals.
|
|
|
|
Uncomment if necessary */
|
|
|
|
//#define URXVT_FIX
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
typedef struct ToxWindow ToxWindow;
|
|
|
|
typedef struct StatusBar StatusBar;
|
2013-12-05 04:33:04 +01:00
|
|
|
typedef struct PromptBuf PromptBuf;
|
2013-11-29 23:48:08 +01:00
|
|
|
typedef struct ChatContext ChatContext;
|
2013-07-30 01:32:39 +02:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
struct ToxWindow {
|
2013-08-23 23:03:44 +02:00
|
|
|
void(*onKey)(ToxWindow *, Tox *, wint_t);
|
|
|
|
void(*onDraw)(ToxWindow *, Tox *);
|
|
|
|
void(*onInit)(ToxWindow *, Tox *);
|
2013-08-16 19:11:09 +02:00
|
|
|
void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t);
|
2013-12-04 07:08:26 +01:00
|
|
|
void(*onFriendAdded)(ToxWindow *, Tox *, int, bool);
|
2013-09-05 03:25:59 +02:00
|
|
|
void(*onConnectionChange)(ToxWindow *, Tox *, int, uint8_t);
|
2013-08-23 23:03:44 +02:00
|
|
|
void(*onMessage)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
|
2013-09-09 07:08:06 +02:00
|
|
|
void(*onNickChange)(ToxWindow *, int, uint8_t *, uint16_t);
|
2013-09-05 03:25:59 +02:00
|
|
|
void(*onStatusChange)(ToxWindow *, Tox *, int, TOX_USERSTATUS);
|
2013-09-03 05:27:34 +02:00
|
|
|
void(*onStatusMessageChange)(ToxWindow *, int, uint8_t *, uint16_t);
|
2013-08-23 23:03:44 +02:00
|
|
|
void(*onAction)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
|
2013-09-18 02:54:25 +02:00
|
|
|
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, uint8_t *, uint16_t);
|
2013-09-15 22:38:38 +02:00
|
|
|
void(*onGroupInvite)(ToxWindow *, Tox *, int, uint8_t *);
|
2013-11-26 00:49:31 +01:00
|
|
|
void(*onGroupNamelistChange)(ToxWindow *, Tox*, int, int, uint8_t);
|
2013-10-10 10:52:05 +02:00
|
|
|
void(*onFileSendRequest)(ToxWindow *, Tox *, int, uint8_t, uint64_t, uint8_t *, uint16_t);
|
|
|
|
void(*onFileControl)(ToxWindow *, Tox *, int, uint8_t, uint8_t, uint8_t, uint8_t *, uint16_t);
|
|
|
|
void(*onFileData)(ToxWindow *, Tox *, int, uint8_t, uint8_t *, uint16_t);
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2013-09-06 00:24:58 +02:00
|
|
|
char name[TOX_MAX_NAME_LENGTH];
|
2013-12-07 02:56:30 +01:00
|
|
|
int num;
|
2013-11-30 11:35:25 +01:00
|
|
|
bool active;
|
2013-12-07 02:56:30 +01:00
|
|
|
int x;
|
|
|
|
|
2013-12-07 01:41:53 +01:00
|
|
|
bool alert0;
|
2013-11-29 01:45:28 +01:00
|
|
|
bool alert1;
|
|
|
|
bool alert2;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *chatwin;
|
2013-12-05 04:33:04 +01:00
|
|
|
PromptBuf *promptbuf;
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *stb;
|
2013-08-16 19:11:09 +02:00
|
|
|
|
|
|
|
WINDOW *window;
|
2013-07-30 01:32:39 +02:00
|
|
|
};
|
2013-08-11 02:58:15 +02:00
|
|
|
|
2013-12-05 04:33:04 +01:00
|
|
|
/* statusbar info holder */
|
2013-11-29 23:48:08 +01:00
|
|
|
struct StatusBar {
|
2013-09-06 08:51:10 +02:00
|
|
|
WINDOW *topline;
|
|
|
|
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
2013-09-10 10:04:13 +02:00
|
|
|
uint16_t statusmsg_len;
|
2013-09-07 01:59:45 +02:00
|
|
|
uint8_t nick[TOX_MAX_NAME_LENGTH];
|
2013-09-18 23:30:35 +02:00
|
|
|
uint16_t nick_len;
|
2013-09-06 08:51:10 +02:00
|
|
|
TOX_USERSTATUS status;
|
|
|
|
bool is_online;
|
2013-11-29 23:48:08 +01:00
|
|
|
};
|
2013-09-06 08:51:10 +02:00
|
|
|
|
2013-12-05 04:33:04 +01:00
|
|
|
/* chat and groupchat window/buffer holder */
|
2013-11-29 23:48:08 +01:00
|
|
|
struct ChatContext {
|
2013-09-15 22:38:38 +02:00
|
|
|
wchar_t line[MAX_STR_SIZE];
|
|
|
|
size_t pos;
|
2013-12-01 04:12:43 +01:00
|
|
|
size_t len;
|
2013-09-15 22:38:38 +02:00
|
|
|
WINDOW *history;
|
|
|
|
WINDOW *linewin;
|
2013-11-24 03:19:59 +01:00
|
|
|
WINDOW *sidebar;
|
2013-11-29 23:48:08 +01:00
|
|
|
};
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2013-12-05 04:33:04 +01:00
|
|
|
/* prompt window/buffer holder */
|
|
|
|
struct PromptBuf {
|
|
|
|
wchar_t line[MAX_STR_SIZE];
|
|
|
|
size_t pos;
|
|
|
|
size_t len;
|
2013-12-06 11:07:35 +01:00
|
|
|
bool at_bottom; /* true if line end is at bottom of window */
|
|
|
|
int orig_y; /* y axis point of line origin */
|
|
|
|
bool scroll; /* used for prompt window hack to determine when to scroll down */
|
2013-12-05 04:33:04 +01:00
|
|
|
WINDOW *linewin;
|
|
|
|
};
|
|
|
|
|
2013-10-11 06:23:39 +02:00
|
|
|
/* Start file transfer code */
|
|
|
|
|
2013-10-18 07:35:08 +02:00
|
|
|
#define MAX_FILES 256
|
2013-10-10 10:52:05 +02:00
|
|
|
#define FILE_PIECE_SIZE 1024
|
2013-11-19 00:54:50 +01:00
|
|
|
#define TIMEOUT_FILESENDER 300
|
2013-11-19 00:52:46 +01:00
|
|
|
#define MAX_PIECES_SEND 100 /* Max number of pieces to send per file per call to do_file_senders() */
|
2013-10-10 10:52:05 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
FILE *file;
|
2013-11-19 22:00:24 +01:00
|
|
|
ToxWindow *toxwin;
|
2013-10-17 12:13:28 +02:00
|
|
|
int friendnum;
|
2013-10-18 07:35:08 +02:00
|
|
|
bool active;
|
2013-10-10 10:52:05 +02:00
|
|
|
uint8_t filenum;
|
|
|
|
uint8_t nextpiece[FILE_PIECE_SIZE];
|
|
|
|
uint16_t piecelen;
|
2013-10-14 01:09:20 +02:00
|
|
|
uint8_t pathname[MAX_STR_SIZE];
|
2013-11-15 01:14:54 +01:00
|
|
|
uint64_t timestamp;
|
2013-10-10 10:52:05 +02:00
|
|
|
} FileSender;
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
struct FileReceiver {
|
2013-11-15 01:14:54 +01:00
|
|
|
uint8_t filenames[MAX_FILES][MAX_STR_SIZE];
|
|
|
|
bool pending[MAX_FILES];
|
2013-11-29 23:48:08 +01:00
|
|
|
};
|
2013-10-11 06:23:39 +02:00
|
|
|
|
|
|
|
/* End file transfer code */
|
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata);
|
2013-09-05 03:25:59 +02:00
|
|
|
void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdata);
|
2013-08-23 23:03:44 +02:00
|
|
|
void on_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
|
|
|
|
void on_action(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
|
|
|
|
void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
|
2013-09-05 03:25:59 +02:00
|
|
|
void on_statuschange(Tox *m, int friendnumber, TOX_USERSTATUS status, void *userdata);
|
2013-09-03 05:27:34 +02:00
|
|
|
void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
|
2013-12-04 07:08:26 +01:00
|
|
|
void on_friendadded(Tox *m, int friendnumber, bool sort);
|
2013-09-18 02:54:25 +02:00
|
|
|
void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata);
|
2013-09-15 22:38:38 +02:00
|
|
|
void on_groupinvite(Tox *m, int friendnumber, uint8_t *group_pub_key, void *userdata);
|
2013-11-26 00:49:31 +01:00
|
|
|
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata);
|
2013-10-14 01:09:20 +02:00
|
|
|
void on_file_sendrequest(Tox *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *pathname, uint16_t pathname_length, void *userdata);
|
2013-10-11 06:23:39 +02:00
|
|
|
void on_file_control(Tox *m, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata);
|
2013-10-10 10:52:05 +02:00
|
|
|
void on_file_data(Tox *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata);
|
|
|
|
|
2013-11-30 11:35:25 +01:00
|
|
|
ToxWindow *init_windows(Tox *m);
|
2013-08-23 23:03:44 +02:00
|
|
|
void draw_active_window(Tox *m);
|
|
|
|
int add_window(Tox *m, ToxWindow w);
|
2013-08-17 10:00:19 +02:00
|
|
|
void del_window(ToxWindow *w);
|
2013-08-13 02:32:09 +02:00
|
|
|
void set_active_window(int ch);
|
2013-11-30 11:35:25 +01:00
|
|
|
int num_active_windows(void);
|
2013-08-11 02:58:15 +02:00
|
|
|
#endif
|