1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-01 16:07:46 +02:00
toxic/src/toxic_windows.h

262 lines
8.2 KiB
C
Raw Normal View History

2014-02-25 08:28:24 +01:00
/* toxic_windows.h
*
*
* Copyright (C) 2014 Toxic All Rights Reserved.
*
* This file is part of Toxic.
*
* Toxic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Toxic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
*
*/
2013-09-15 22:38:38 +02:00
#ifndef _windows_h
#define _windows_h
2013-09-15 22:38:38 +02:00
#ifndef TOXICVER
#define TOXICVER "NOVER_" /* Use the -D flag to set this */
2013-09-15 22:38:38 +02:00
#endif
#include <curses.h>
#include <wctype.h>
#include <wchar.h>
2013-08-23 23:03:44 +02:00
#include <tox/tox.h>
2013-08-23 23:03:44 +02:00
2014-03-07 03:14:04 +01:00
#ifdef _SUPPORT_AUDIO
#include <tox/toxav.h>
#endif /* _SUPPORT_AUDIO */
2014-03-11 18:09:20 +01:00
#define UNKNOWN_NAME "Anonymous"
2013-11-19 00:52:46 +01:00
#define MAX_WINDOWS_NUM 32
#define MAX_FRIENDS_NUM 100
2013-08-08 10:51:58 +02:00
#define MAX_STR_SIZE 256
2013-12-09 00:14:57 +01:00
#define MAX_CMDNAME_SIZE 64
2013-08-08 10:51:58 +02:00
#define KEY_SIZE_BYTES 32
2013-12-14 21:38:21 +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
2014-02-22 23:58:36 +01:00
#define KEY_IDENT_DIGITS 2 /* number of hex digits to display for the pub-key based identifier */
2013-11-19 00:52:46 +01: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 */
2013-12-07 04:07:37 +01:00
#define T_KEY_NEXT 0x10 /* ctrl-p */
2013-12-14 06:36:06 +01:00
#define T_KEY_PREV 0x0F /* ctrl-o */
#define T_KEY_C_E 0x05 /* ctrl-e */
#define T_KEY_C_A 0x01 /* ctrl-a */
2013-12-06 04:55:14 +01:00
/* Curses foreground colours (background is black) */
2013-11-10 07:23:07 +01:00
enum {
WHITE,
GREEN,
CYAN,
RED,
BLUE,
YELLOW,
MAGENTA,
BLACK,
};
/* tab alert types: lower types take priority */
2013-11-29 01:45:28 +01:00
enum {
WINDOW_ALERT_0,
2013-11-29 01:45:28 +01:00
WINDOW_ALERT_1,
WINDOW_ALERT_2,
};
/* Fixes text color problem on some terminals.
Uncomment if necessary */
//#define URXVT_FIX
typedef struct ToxWindow ToxWindow;
typedef struct StatusBar StatusBar;
typedef struct PromptBuf PromptBuf;
typedef struct ChatContext ChatContext;
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);
void(*onFriendAdded)(ToxWindow *, Tox *, int, bool);
void(*onConnectionChange)(ToxWindow *, Tox *, int, uint8_t);
2013-08-23 23:03:44 +02:00
void(*onMessage)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
void(*onNickChange)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
void(*onStatusChange)(ToxWindow *, Tox *, int, TOX_USERSTATUS);
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-12-14 02:57:32 +01:00
void(*onGroupAction)(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);
2014-02-23 10:28:33 +01:00
void(*onTypingChange)(ToxWindow *, Tox *, int, int);
2013-08-16 19:11:09 +02:00
2014-03-07 03:14:04 +01:00
#ifdef _SUPPORT_AUDIO
void(*onInvite)(ToxWindow *, ToxAv *);
void(*onRinging)(ToxWindow *, ToxAv *);
void(*onStarting)(ToxWindow *, ToxAv *);
void(*onEnding)(ToxWindow *, ToxAv *);
void(*onError)(ToxWindow *, ToxAv *);
void(*onStart)(ToxWindow *, ToxAv *);
void(*onCancel)(ToxWindow *, ToxAv *);
void(*onReject)(ToxWindow *, ToxAv *);
void(*onEnd)(ToxWindow *, ToxAv *);
void(*onTimeout)(ToxWindow *, ToxAv *);
#endif /* _SUPPORT_AUDIO */
char name[TOX_MAX_NAME_LENGTH];
2013-12-07 02:56:30 +01:00
int num;
bool active;
2013-12-07 02:56:30 +01:00
int x;
2014-02-26 11:23:11 +01:00
/* window type identifiers */
bool is_chat;
bool is_groupchat;
2014-03-02 00:06:35 +01:00
bool is_prompt;
2014-02-26 11:23:11 +01:00
bool alert0;
2013-11-29 01:45:28 +01:00
bool alert1;
bool alert2;
ChatContext *chatwin;
PromptBuf *promptbuf;
StatusBar *stb;
2013-08-16 19:11:09 +02:00
2014-03-09 05:57:21 +01:00
WINDOW *popup;
2013-08-16 19:11:09 +02:00
WINDOW *window;
};
/* statusbar info holder */
struct StatusBar {
WINDOW *topline;
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
uint16_t statusmsg_len;
uint8_t nick[TOX_MAX_NAME_LENGTH];
uint16_t nick_len;
TOX_USERSTATUS status;
bool is_online;
};
2014-03-04 01:21:52 +01:00
#define LOG_FLUSH_LIMIT 2 /* limits calls to fflush(logfile) to a max of one per LOG_FLUSH_LIMIT seconds */
2014-02-26 07:51:06 +01:00
struct chatlog {
2014-03-04 01:21:52 +01:00
FILE *file;
uint64_t lastwrite;
2014-02-26 07:51:06 +01:00
int pos;
bool log_on; /* specific to current chat window */
2014-02-26 07:51:06 +01:00
};
2013-12-19 02:18:38 +01:00
#define MAX_LINE_HIST 128
2013-12-11 06:10:09 +01:00
/* chat and groupchat window/buffer holder */
struct ChatContext {
2013-09-15 22:38:38 +02:00
wchar_t line[MAX_STR_SIZE];
size_t pos;
size_t len;
2013-12-11 06:10:09 +01:00
wchar_t ln_history[MAX_LINE_HIST][MAX_STR_SIZE];
int hst_pos;
int hst_tot;
2014-02-23 10:28:33 +01:00
bool self_is_typing;
struct chatlog *log;
2014-02-26 07:51:06 +01:00
2013-09-15 22:38:38 +02:00
WINDOW *history;
WINDOW *linewin;
WINDOW *sidebar;
};
2013-09-15 22:38:38 +02:00
/* prompt window/buffer holder */
struct PromptBuf {
wchar_t line[MAX_STR_SIZE];
size_t pos;
size_t len;
2014-02-27 01:00:13 +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-11 06:10:09 +01:00
wchar_t ln_history[MAX_LINE_HIST][MAX_STR_SIZE];
int hst_pos;
int hst_tot;
2014-03-02 00:06:35 +01:00
struct chatlog *log;
WINDOW *linewin;
};
2013-10-11 06:23:39 +02:00
/* Start file transfer code */
#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-10-10 10:52:05 +02:00
typedef struct {
FILE *file;
2013-11-19 22:00:24 +01:00
ToxWindow *toxwin;
int friendnum;
bool active;
2013-10-10 10:52:05 +02:00
uint8_t filenum;
uint8_t nextpiece[FILE_PIECE_SIZE];
uint16_t piecelen;
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;
struct FileReceiver {
2013-11-15 01:14:54 +01:00
uint8_t filenames[MAX_FILES][MAX_STR_SIZE];
FILE *files[MAX_FILES];
2013-11-15 01:14:54 +01:00
bool pending[MAX_FILES];
};
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);
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);
void on_statuschange(Tox *m, int friendnumber, TOX_USERSTATUS status, void *userdata);
void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
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-12-14 02:57:32 +01:00
void on_groupaction(Tox *m, int groupnumber, int peernumber, uint8_t *action, 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);
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);
2014-02-23 10:28:33 +01:00
void on_typing_change(Tox *m, int friendnumber, int is_typing, void *userdata);
2013-10-10 10:52:05 +02: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);
void del_window(ToxWindow *w);
void set_active_window(int ch);
2014-03-07 01:39:57 +01:00
int get_num_active_windows(void);
2014-02-26 11:23:11 +01:00
/* cleans up all chat and groupchat windows (should only be called on shutdown) */
2014-02-26 11:23:11 +01:00
void kill_all_windows(void);
#endif