mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-14 19:40:24 +00:00
Added panel!
- minor refactoring - TODO: panel & cnc should really use unique keys. maybe add config file?
This commit is contained in:
93
panel/include/panel.h
Normal file
93
panel/include/panel.h
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef PANELMENU_H
|
||||
#define PANELMENU_H
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define PANEL_CURSES_TIMEOUT 100
|
||||
#define COMMONPANELLIST tPanel_list list;
|
||||
|
||||
typedef void (*panelCallback)(void *uData);
|
||||
|
||||
typedef enum {
|
||||
LIST_LIST,
|
||||
LIST_TABS,
|
||||
LIST_MENU,
|
||||
LIST_NONE
|
||||
} LISTTYPE;
|
||||
|
||||
struct sPanel_list;
|
||||
typedef struct sPanel_listItem {
|
||||
panelCallback callback;
|
||||
struct sPanel_list *child;
|
||||
void *uData;
|
||||
char *name;
|
||||
struct sPanel_listItem *next;
|
||||
struct sPanel_listItem *last;
|
||||
int x, y, width, height;
|
||||
} tPanel_listItem;
|
||||
|
||||
typedef struct sPanel_list {
|
||||
tPanel_listItem *itemHead, *selectedItem;
|
||||
WINDOW *win;
|
||||
int x, y, width, height;
|
||||
LISTTYPE type;
|
||||
bool hidden;
|
||||
} tPanel_list;
|
||||
|
||||
typedef struct sPanel_tabs {
|
||||
COMMONPANELLIST;
|
||||
char *title;
|
||||
} tPanel_tabs;
|
||||
|
||||
typedef struct sPanel_menu {
|
||||
COMMONPANELLIST;
|
||||
char *title;
|
||||
} tPanel_menu;
|
||||
|
||||
extern WINDOW *wmain;
|
||||
extern tPanel_list *panel_botList;
|
||||
extern tPanel_tabs *panel_tabList;
|
||||
|
||||
void panel_init(void);
|
||||
void panel_cleanUp(void);
|
||||
|
||||
tPanel_list *panel_getActiveList(void);
|
||||
int panel_getChar(void);
|
||||
void panel_pushActiveList(tPanel_list *list);
|
||||
void panel_popActiveList(void); /* also free's the item */
|
||||
void panel_draw(void);
|
||||
bool panel_tick(int input); /* ticks activeList list, returns true if input was accepted/valid */
|
||||
void panel_setTimeout(int timeout);
|
||||
|
||||
tPanel_listItem *panelL_newListItem(tPanel_list *list, tPanel_list *child, char *name, panelCallback callback, void *uData);
|
||||
void panelL_freeListItem(tPanel_list *list, tPanel_listItem *item);
|
||||
|
||||
/* call *after* adding listItems with panelL_newListItem */
|
||||
void panelL_init(tPanel_list *list);
|
||||
void panelL_draw(tPanel_list *list);
|
||||
void panelL_free(tPanel_list *list);
|
||||
bool panelL_tick(tPanel_list *list, int ch);
|
||||
void panelL_setHidden(tPanel_list *list, bool hidden);
|
||||
void panelL_setTimeout(tPanel_list *list, int timeout);
|
||||
|
||||
/* handles selection */
|
||||
void panelL_nextItem(tPanel_list *list);
|
||||
void panelL_prevItem(tPanel_list *list);
|
||||
void panelL_selectItem(tPanel_list *list); /* calls select item's callback */
|
||||
|
||||
/* center list */
|
||||
tPanel_list *panelL_newList(void);
|
||||
void panelL_freeList(tPanel_list *list);
|
||||
|
||||
/* top tabs */
|
||||
tPanel_tabs *panelL_newTabs(char *title);
|
||||
void panelL_freeTabs(tPanel_tabs *tabs);
|
||||
|
||||
/* menu popup */
|
||||
tPanel_menu *panelL_newMenu(char *title);
|
||||
void panelL_freeMenu(tPanel_menu *menu);
|
||||
|
||||
#undef COMMONPANELLIST
|
||||
|
||||
#endif
|
24
panel/include/pbot.h
Normal file
24
panel/include/pbot.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef PBOT_H
|
||||
#define PBOT_H
|
||||
|
||||
#include "laika.h"
|
||||
#include "lpeer.h"
|
||||
#include "lrsa.h"
|
||||
|
||||
#include "panel.h"
|
||||
|
||||
typedef struct sPanel_bot {
|
||||
uint8_t pub[crypto_kx_PUBLICKEYBYTES];
|
||||
PEERTYPE type;
|
||||
tPanel_listItem *item;
|
||||
char *name; /* heap allocated string */
|
||||
} tPanel_bot;
|
||||
|
||||
tPanel_bot *panelB_newBot(uint8_t *pubKey);
|
||||
void panelB_freeBot(tPanel_bot *bot);
|
||||
|
||||
/* search connected bots by public key */
|
||||
tPanel_bot *panelB_getBot(uint8_t *pubKey);
|
||||
void panelB_setItem(tPanel_bot *bot, tPanel_listItem *item);
|
||||
|
||||
#endif
|
24
panel/include/pclient.h
Normal file
24
panel/include/pclient.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef PCLIENT_H
|
||||
#define PCLIENT_H
|
||||
|
||||
#include "laika.h"
|
||||
#include "lpeer.h"
|
||||
#include "lpolllist.h"
|
||||
#include "pbot.h"
|
||||
|
||||
typedef struct sPanel_client {
|
||||
uint8_t priv[crypto_kx_SECRETKEYBYTES], pub[crypto_kx_PUBLICKEYBYTES];
|
||||
struct sLaika_pollList pList;
|
||||
struct sLaika_peer *peer;
|
||||
} tPanel_client;
|
||||
|
||||
tPanel_client *panelC_newClient();
|
||||
void panelC_freeClient(tPanel_client *client);
|
||||
|
||||
void panelC_connectToCNC(tPanel_client *client, char *ip, char *port); /* can throw a LAIKA_ERROR */
|
||||
bool panelC_poll(tPanel_client *client, int timeout);
|
||||
|
||||
void panelC_addBot(tPanel_bot *bot);
|
||||
void panelC_rmvBot(tPanel_bot *bot);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user