2014-02-25 08:28:24 +01:00
|
|
|
/* prompt.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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-02 19:19:25 +02:00
|
|
|
*/
|
2013-07-30 01:32:39 +02:00
|
|
|
|
2014-07-14 20:32:38 +02:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE /* needed for wcswidth() */
|
|
|
|
#endif
|
|
|
|
|
2013-07-30 01:32:39 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-06-22 03:41:38 +02:00
|
|
|
#include <wchar.h>
|
2013-07-30 01:32:39 +02:00
|
|
|
|
2014-06-12 00:06:55 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
2013-08-13 00:50:43 +02:00
|
|
|
#include "prompt.h"
|
2013-11-10 03:43:56 +01:00
|
|
|
#include "execute.h"
|
2013-09-21 02:35:03 +02:00
|
|
|
#include "misc_tools.h"
|
2013-12-10 09:03:45 +01:00
|
|
|
#include "toxic_strings.h"
|
2014-03-25 13:25:10 +01:00
|
|
|
#include "log.h"
|
2014-03-24 12:37:52 +01:00
|
|
|
#include "line_info.h"
|
2014-04-07 10:42:10 +02:00
|
|
|
#include "settings.h"
|
2014-06-29 00:40:22 +02:00
|
|
|
#include "input.h"
|
2014-07-04 09:24:29 +02:00
|
|
|
#include "help.h"
|
2013-08-17 11:59:28 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
|
|
|
|
uint16_t num_frnd_requests = 0;
|
2013-12-06 11:07:35 +01:00
|
|
|
extern ToxWindow *prompt;
|
2014-03-13 12:34:14 +01:00
|
|
|
struct _Winthread Winthread;
|
2013-12-09 23:56:20 +01:00
|
|
|
|
2014-04-07 10:42:10 +02:00
|
|
|
extern struct user_settings *user_settings;
|
|
|
|
|
2013-12-09 23:56:20 +01:00
|
|
|
/* Array of global command names used for tab completion. */
|
2014-07-07 04:15:35 +02:00
|
|
|
const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/accept" },
|
|
|
|
{ "/add" },
|
|
|
|
{ "/clear" },
|
|
|
|
{ "/close" }, /* rm /close when groupchats gets its own list */
|
|
|
|
{ "/connect" },
|
|
|
|
{ "/exit" },
|
|
|
|
{ "/groupchat" },
|
|
|
|
{ "/help" },
|
|
|
|
{ "/join" },
|
2014-02-27 01:00:13 +01:00
|
|
|
{ "/log" },
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/myid" },
|
|
|
|
{ "/nick" },
|
|
|
|
{ "/note" },
|
|
|
|
{ "/quit" },
|
|
|
|
{ "/status" },
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
#ifdef _SUPPORT_AUDIO
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
{ "/lsdev" },
|
|
|
|
{ "/sdev" },
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
#endif /* _SUPPORT_AUDIO */
|
2013-12-09 23:56:20 +01:00
|
|
|
};
|
2013-12-06 11:07:35 +01:00
|
|
|
|
2014-07-10 04:11:31 +02:00
|
|
|
void kill_prompt_window(ToxWindow *self)
|
|
|
|
{
|
2014-07-09 01:24:44 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
StatusBar *statusbar = self->stb;
|
|
|
|
|
|
|
|
log_disable(ctx->log);
|
|
|
|
line_info_cleanup(ctx->hst);
|
|
|
|
|
|
|
|
delwin(ctx->linewin);
|
|
|
|
delwin(ctx->history);
|
|
|
|
delwin(statusbar->topline);
|
|
|
|
|
|
|
|
free(ctx->log);
|
|
|
|
free(ctx->hst);
|
|
|
|
free(ctx);
|
|
|
|
free(self->help);
|
|
|
|
free(statusbar);
|
|
|
|
|
|
|
|
del_window(self);
|
|
|
|
}
|
|
|
|
|
2013-09-07 01:59:45 +02:00
|
|
|
/* Updates own nick in prompt statusbar */
|
2014-07-07 04:15:35 +02:00
|
|
|
void prompt_update_nick(ToxWindow *prompt, char *nick)
|
2013-09-07 01:59:45 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = prompt->stb;
|
2013-09-07 01:59:45 +02:00
|
|
|
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
2014-06-01 19:36:23 +02:00
|
|
|
statusbar->nick_len = strlen(statusbar->nick);
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Updates own statusmessage in prompt statusbar */
|
2014-07-07 04:15:35 +02:00
|
|
|
void prompt_update_statusmessage(ToxWindow *prompt, char *statusmsg)
|
2013-09-07 01:59:45 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = prompt->stb;
|
2013-09-07 01:59:45 +02:00
|
|
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
2014-06-01 19:36:23 +02:00
|
|
|
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Updates own status in prompt statusbar */
|
2014-03-19 02:48:26 +01:00
|
|
|
void prompt_update_status(ToxWindow *prompt, uint8_t status)
|
2013-09-07 01:59:45 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = prompt->stb;
|
2013-09-07 01:59:45 +02:00
|
|
|
statusbar->status = status;
|
|
|
|
}
|
|
|
|
|
2013-09-09 06:56:47 +02:00
|
|
|
/* Updates own connection status in prompt statusbar */
|
2013-09-07 03:37:16 +02:00
|
|
|
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
|
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = prompt->stb;
|
2013-09-07 03:37:16 +02:00
|
|
|
statusbar->is_online = is_connected;
|
|
|
|
}
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
/* Adds friend request to pending friend requests.
|
2013-10-16 23:59:56 +02:00
|
|
|
Returns request number on success, -1 if queue is full or other error. */
|
2014-07-07 04:15:35 +02:00
|
|
|
static int add_friend_request(const char *public_key)
|
2013-09-06 08:51:10 +02:00
|
|
|
{
|
2013-12-01 22:57:05 +01:00
|
|
|
if (num_frnd_requests >= MAX_FRIENDS_NUM)
|
2013-12-01 23:08:57 +01:00
|
|
|
return -1;
|
2013-12-01 22:57:05 +01:00
|
|
|
|
|
|
|
int i;
|
2013-10-16 23:59:56 +02:00
|
|
|
|
2013-12-01 22:57:05 +01:00
|
|
|
for (i = 0; i <= num_frnd_requests; ++i) {
|
|
|
|
if (!strlen(pending_frnd_requests[i])) {
|
|
|
|
memcpy(pending_frnd_requests[i], public_key, TOX_CLIENT_ID_SIZE);
|
2013-10-16 23:59:56 +02:00
|
|
|
|
2013-12-01 22:57:05 +01:00
|
|
|
if (i == num_frnd_requests)
|
|
|
|
++num_frnd_requests;
|
2013-10-16 23:59:56 +02:00
|
|
|
|
2013-12-01 22:57:05 +01:00
|
|
|
return i;
|
2013-10-16 23:59:56 +02:00
|
|
|
}
|
2013-09-16 06:28:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2013-09-06 08:51:10 +02:00
|
|
|
}
|
|
|
|
|
2014-03-30 22:40:13 +02:00
|
|
|
static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2014-03-24 12:37:52 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-12-04 09:57:03 +01:00
|
|
|
|
2013-10-23 09:24:08 +02:00
|
|
|
int x, y, y2, x2;
|
2014-06-29 00:40:22 +02:00
|
|
|
getyx(self->window, y, x);
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (x2 <= 0)
|
|
|
|
return;
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
/* ignore non-menu related input if active */
|
|
|
|
if (self->help->active) {
|
|
|
|
help_onKey(self, key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (ltr) { /* char is printable */
|
|
|
|
input_new_char(self, key, x, y, x2, y2);
|
|
|
|
return;
|
|
|
|
}
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (line_info_onKey(self, key))
|
|
|
|
return;
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
input_handle(self, key, x, y, x2, y2);
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (key == '\t') { /* TAB key: auto-completes command */
|
|
|
|
if (ctx->len > 1 && ctx->line[0] == '/') {
|
2014-06-29 22:54:27 +02:00
|
|
|
int diff = complete_line(ctx, glob_cmd_list, AC_NUM_GLOB_COMMANDS, MAX_CMDNAME_SIZE);
|
|
|
|
|
|
|
|
if (diff != -1) {
|
|
|
|
if (x + diff > x2 - 1) {
|
|
|
|
wmove(self->window, y, x + diff);
|
|
|
|
ctx->start += diff;
|
|
|
|
} else {
|
|
|
|
wmove(self->window, y, x + diff);
|
|
|
|
}
|
|
|
|
} else {
|
2013-12-16 02:52:10 +01:00
|
|
|
beep();
|
2014-06-29 22:54:27 +02:00
|
|
|
}
|
2014-06-29 00:40:22 +02:00
|
|
|
} else {
|
|
|
|
beep();
|
2013-12-16 02:52:10 +01:00
|
|
|
}
|
2014-06-29 00:40:22 +02:00
|
|
|
} else if (key == '\n') {
|
|
|
|
rm_trailing_spaces_buf(ctx);
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char line[MAX_STR_SIZE] = {0};
|
2014-06-04 02:35:00 +02:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1)
|
|
|
|
memset(&line, 0, sizeof(line));
|
2013-12-08 10:16:49 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (!string_is_empty(line))
|
|
|
|
add_line_to_hist(ctx);
|
2013-12-08 10:16:49 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, line, PROMPT, 0, 0);
|
|
|
|
execute(ctx->history, self, m, line, GLOBAL_COMMAND_MODE);
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
wclear(ctx->linewin);
|
|
|
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
|
|
|
reset_buf(ctx);
|
2013-07-30 01:32:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 23:03:44 +02:00
|
|
|
static void prompt_onDraw(ToxWindow *self, Tox *m)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2014-06-29 00:40:22 +02:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2014-03-24 12:37:52 +01:00
|
|
|
line_info_print(self);
|
2014-06-29 00:40:22 +02:00
|
|
|
wclear(ctx->linewin);
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
curs_set(1);
|
2013-12-04 22:14:33 +01:00
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
if (ctx->len > 0)
|
|
|
|
mvwprintw(ctx->linewin, 1, 0, "%ls", &ctx->line[ctx->start]);
|
2013-12-06 04:55:14 +01:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2013-11-24 05:46:46 +01:00
|
|
|
mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x2);
|
2013-09-28 01:55:11 +02:00
|
|
|
wmove(statusbar->topline, 0, 0);
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2013-09-07 03:37:16 +02:00
|
|
|
if (statusbar->is_online) {
|
2013-09-07 01:59:45 +02:00
|
|
|
int colour = WHITE;
|
2014-07-07 04:15:35 +02:00
|
|
|
const char *status_text = "Unknown";
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2013-11-12 07:50:04 +01:00
|
|
|
switch (statusbar->status) {
|
2014-04-19 23:58:13 +02:00
|
|
|
case TOX_USERSTATUS_NONE:
|
|
|
|
status_text = "Online";
|
|
|
|
colour = GREEN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_USERSTATUS_AWAY:
|
|
|
|
status_text = "Away";
|
|
|
|
colour = YELLOW;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_USERSTATUS_BUSY:
|
|
|
|
status_text = "Busy";
|
|
|
|
colour = RED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_USERSTATUS_INVALID:
|
|
|
|
status_text = "ERROR";
|
|
|
|
colour = MAGENTA;
|
|
|
|
break;
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2013-09-07 01:59:45 +02:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
|
2014-03-15 12:40:13 +01:00
|
|
|
wprintw(statusbar->topline, " [%s]", status_text);
|
2013-09-07 01:59:45 +02:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
|
2014-03-15 12:40:13 +01:00
|
|
|
|
|
|
|
wattron(statusbar->topline, A_BOLD);
|
|
|
|
wprintw(statusbar->topline, " %s", statusbar->nick);
|
|
|
|
wattroff(statusbar->topline, A_BOLD);
|
2013-09-07 01:59:45 +02:00
|
|
|
} else {
|
2014-07-09 06:05:13 +02:00
|
|
|
wprintw(statusbar->topline, " [Offline]");
|
2013-09-07 01:59:45 +02:00
|
|
|
wattron(statusbar->topline, A_BOLD);
|
2013-11-19 00:52:46 +01:00
|
|
|
wprintw(statusbar->topline, " %s ", statusbar->nick);
|
2013-09-07 01:59:45 +02:00
|
|
|
wattroff(statusbar->topline, A_BOLD);
|
|
|
|
}
|
|
|
|
|
2014-03-15 12:40:13 +01:00
|
|
|
if (statusbar->statusmsg[0])
|
|
|
|
wprintw(statusbar->topline, " - %s", statusbar->statusmsg);
|
|
|
|
|
2014-07-01 05:56:47 +02:00
|
|
|
mvwhline(self->window, y2 - CHATBOX_HEIGHT, 0, ACS_HLINE, x2);
|
|
|
|
|
|
|
|
int y, x;
|
|
|
|
getyx(self->window, y, x);
|
2014-07-07 04:15:35 +02:00
|
|
|
(void) x;
|
|
|
|
|
2014-07-14 20:32:38 +02:00
|
|
|
int new_x = ctx->start ? x2 - 1 : wcswidth(ctx->line, ctx->pos);
|
2014-07-01 05:56:47 +02:00
|
|
|
wmove(self->window, y + 1, new_x);
|
2014-07-04 09:24:29 +02:00
|
|
|
|
2014-07-05 20:46:16 +02:00
|
|
|
wrefresh(self->window);
|
|
|
|
|
|
|
|
if (self->help->active)
|
2014-07-04 09:24:29 +02:00
|
|
|
help_onDraw(self);
|
2013-07-30 01:32:39 +02:00
|
|
|
}
|
|
|
|
|
2014-03-19 02:48:26 +01:00
|
|
|
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum , uint8_t status)
|
2013-09-23 07:22:21 +02:00
|
|
|
{
|
|
|
|
if (friendnum < 0)
|
|
|
|
return;
|
|
|
|
|
2014-03-24 12:37:52 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-12-06 11:07:35 +01:00
|
|
|
|
2014-07-08 20:31:59 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH] = {0}; /* stop removing this initiation */
|
|
|
|
get_nick_truncate(m, nick, friendnum);
|
2014-04-01 08:48:37 +02:00
|
|
|
|
2014-07-08 20:31:59 +02:00
|
|
|
if (!nick[0])
|
2013-09-23 07:22:21 +02:00
|
|
|
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char timefrmt[TIME_STR_SIZE];
|
2014-06-24 00:54:23 +02:00
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
2014-07-07 04:15:35 +02:00
|
|
|
char *msg;
|
2014-03-02 00:06:35 +01:00
|
|
|
|
2013-09-23 07:22:21 +02:00
|
|
|
if (status == 1) {
|
2014-03-04 01:21:52 +01:00
|
|
|
msg = "has come online";
|
2014-03-25 08:17:22 +01:00
|
|
|
line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, GREEN);
|
2014-03-24 12:37:52 +01:00
|
|
|
write_to_log(msg, nick, ctx->log, true);
|
2014-02-13 12:24:58 +01:00
|
|
|
alert_window(self, WINDOW_ALERT_2, false);
|
2013-09-23 07:22:21 +02:00
|
|
|
} else {
|
2014-03-04 01:21:52 +01:00
|
|
|
msg = "has gone offline";
|
2014-03-25 08:17:22 +01:00
|
|
|
line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, RED);
|
2014-03-24 12:37:52 +01:00
|
|
|
write_to_log(msg, nick, ctx->log, true);
|
2013-09-23 07:22:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, const char *data,
|
2014-06-12 02:04:20 +02:00
|
|
|
uint16_t length)
|
2013-09-15 22:38:38 +02:00
|
|
|
{
|
2014-03-24 12:37:52 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2014-03-02 00:06:35 +01:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char timefrmt[TIME_STR_SIZE];
|
2014-06-24 00:54:23 +02:00
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
2014-03-02 00:06:35 +01:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char msg[MAX_STR_SIZE];
|
2014-03-25 13:21:50 +01:00
|
|
|
snprintf(msg, sizeof(msg), "Friend request with the message '%s'", data);
|
|
|
|
line_info_add(self, timefrmt, NULL, NULL, msg, SYS_MSG, 0, 0);
|
2014-03-24 12:37:52 +01:00
|
|
|
write_to_log(msg, "", ctx->log, true);
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2013-10-16 23:59:56 +02:00
|
|
|
int n = add_friend_request(key);
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2013-09-22 10:32:51 +02:00
|
|
|
if (n == -1) {
|
2014-07-07 04:15:35 +02:00
|
|
|
char *errmsg = "Friend request queue is full. Discarding request.";
|
2014-03-25 13:21:50 +01:00
|
|
|
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
|
2014-03-24 12:37:52 +01:00
|
|
|
write_to_log(errmsg, "", ctx->log, true);
|
2013-09-22 10:32:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-25 13:21:50 +01:00
|
|
|
snprintf(msg, sizeof(msg), "Type \"/accept %d\" to accept it.", n);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
|
2014-02-13 12:24:58 +01:00
|
|
|
alert_window(self, WINDOW_ALERT_1, true);
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
|
2013-09-07 01:59:45 +02:00
|
|
|
void prompt_init_statusbar(ToxWindow *self, Tox *m)
|
|
|
|
{
|
2014-03-25 08:17:22 +01:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-07-07 04:15:35 +02:00
|
|
|
(void) y2;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
|
|
|
/* Init statusbar info */
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2013-09-07 01:59:45 +02:00
|
|
|
statusbar->status = TOX_USERSTATUS_NONE;
|
2013-09-07 03:39:22 +02:00
|
|
|
statusbar->is_online = false;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
char statusmsg[MAX_STR_SIZE];
|
2014-03-13 12:34:14 +01:00
|
|
|
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-07-07 04:15:35 +02:00
|
|
|
uint16_t n_len = tox_get_self_name(m, (uint8_t *) nick);
|
|
|
|
uint16_t s_len = tox_get_self_status_message(m, (uint8_t *) statusmsg, MAX_STR_SIZE);
|
2014-03-19 02:48:26 +01:00
|
|
|
uint8_t status = tox_get_self_user_status(m);
|
2014-03-13 12:34:14 +01:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
2014-04-01 04:00:17 +02:00
|
|
|
nick[n_len] = '\0';
|
|
|
|
statusmsg[s_len] = '\0';
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2014-03-14 04:30:44 +01:00
|
|
|
/* load prev status message or show toxic version if it has never been set */
|
2014-07-07 04:15:35 +02:00
|
|
|
char ver[strlen(TOXICVER) + 1];
|
2014-02-22 10:46:35 +01:00
|
|
|
strcpy(ver, TOXICVER);
|
2014-07-07 04:15:35 +02:00
|
|
|
const char *toxic_ver = strtok(ver, "_");
|
2014-02-22 10:50:47 +01:00
|
|
|
|
2014-04-01 04:00:17 +02:00
|
|
|
if ( (!strcmp("Online", statusmsg) || !strncmp("Toxing on Toxic", statusmsg, 15)) && toxic_ver != NULL) {
|
2014-07-09 06:05:13 +02:00
|
|
|
snprintf(statusmsg, MAX_STR_SIZE, "Toxing on Toxic v.%s", toxic_ver);
|
2014-04-19 23:58:13 +02:00
|
|
|
s_len = strlen(statusmsg);
|
2014-04-01 04:00:17 +02:00
|
|
|
statusmsg[s_len] = '\0';
|
|
|
|
}
|
2014-02-22 10:46:35 +01:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
prompt_update_statusmessage(prompt, statusmsg);
|
2014-03-15 12:40:13 +01:00
|
|
|
prompt_update_status(prompt, status);
|
2014-07-07 04:15:35 +02:00
|
|
|
prompt_update_nick(prompt, nick);
|
2013-09-07 01:59:45 +02:00
|
|
|
|
|
|
|
/* Init statusbar subwindow */
|
2014-03-25 08:17:22 +01:00
|
|
|
statusbar->topline = subwin(self->window, 2, x2, 0, 0);
|
|
|
|
}
|
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
static void print_welcome_msg(ToxWindow *self)
|
|
|
|
{
|
2014-07-04 19:24:18 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, " _____ _____ _____ ____ ", SYS_MSG, 1, BLUE);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, " |_ _/ _ \\ \\/ /_ _/ ___|", SYS_MSG, 1, BLUE);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, " | || | | \\ / | | | ", SYS_MSG, 1, BLUE);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, " | || |_| / \\ | | |___ ", SYS_MSG, 1, BLUE);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, " |_| \\___/_/\\_\\___\\____|", SYS_MSG, 1, BLUE);
|
2014-07-04 09:24:29 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "", SYS_MSG, 0, 0);
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char *msg = "Welcome to Toxic, a free, open source Tox-based instant messenging client.";
|
2014-07-04 19:24:18 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
|
|
|
|
msg = "Type \"/help\" for assistance. Further help may be found via the man page.";
|
|
|
|
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, "", SYS_MSG, 0, 0);
|
2014-07-04 09:24:29 +02:00
|
|
|
}
|
|
|
|
|
2014-03-25 08:17:22 +01:00
|
|
|
static void prompt_onInit(ToxWindow *self, Tox *m)
|
|
|
|
{
|
|
|
|
curs_set(1);
|
|
|
|
int y2, x2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
|
|
|
|
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-07-04 19:24:18 +02:00
|
|
|
ctx->log = calloc(1, sizeof(struct chatlog));
|
|
|
|
ctx->hst = calloc(1, sizeof(struct history));
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-06-18 21:54:05 +02:00
|
|
|
if (ctx->log == NULL || ctx->hst == NULL)
|
|
|
|
exit_toxic_err("failed in prompt_onInit", FATALERR_MEMORY);
|
2014-03-25 08:17:22 +01:00
|
|
|
|
|
|
|
line_info_init(ctx->hst);
|
2014-04-07 10:42:10 +02:00
|
|
|
|
|
|
|
if (user_settings->autolog == AUTOLOG_ON) {
|
2014-07-07 04:15:35 +02:00
|
|
|
char myid[TOX_FRIEND_ADDRESS_SIZE];
|
|
|
|
tox_get_address(m, (uint8_t *) myid);
|
2014-04-07 10:42:10 +02:00
|
|
|
log_enable(self->name, myid, ctx->log);
|
|
|
|
}
|
|
|
|
|
2014-06-29 00:40:22 +02:00
|
|
|
scrollok(ctx->history, 0);
|
|
|
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
2014-07-04 09:24:29 +02:00
|
|
|
|
|
|
|
print_welcome_msg(self);
|
2013-09-07 01:59:45 +02:00
|
|
|
}
|
|
|
|
|
2013-09-19 23:03:22 +02:00
|
|
|
ToxWindow new_prompt(void)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2013-08-16 19:11:09 +02:00
|
|
|
ToxWindow ret;
|
|
|
|
memset(&ret, 0, sizeof(ret));
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2013-11-30 11:35:25 +01:00
|
|
|
ret.active = true;
|
2014-03-02 00:06:35 +01:00
|
|
|
ret.is_prompt = true;
|
2013-11-30 11:35:25 +01:00
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
ret.onKey = &prompt_onKey;
|
|
|
|
ret.onDraw = &prompt_onDraw;
|
|
|
|
ret.onInit = &prompt_onInit;
|
2013-09-23 07:22:21 +02:00
|
|
|
ret.onConnectionChange = &prompt_onConnectionChange;
|
2013-09-06 08:51:10 +02:00
|
|
|
ret.onFriendRequest = &prompt_onFriendRequest;
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2014-07-13 21:34:09 +02:00
|
|
|
strcpy(ret.name, "home");
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2014-03-24 12:37:52 +01:00
|
|
|
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
2013-09-13 08:02:49 +02:00
|
|
|
StatusBar *stb = calloc(1, sizeof(StatusBar));
|
2014-07-04 09:24:29 +02:00
|
|
|
Help *help = calloc(1, sizeof(Help));
|
2013-09-12 00:07:26 +02:00
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
if (stb == NULL || chatwin == NULL || help == NULL)
|
2014-06-18 21:54:05 +02:00
|
|
|
exit_toxic_err("failed in new_prompt", FATALERR_MEMORY);
|
|
|
|
|
|
|
|
ret.chatwin = chatwin;
|
|
|
|
ret.stb = stb;
|
2014-07-04 09:24:29 +02:00
|
|
|
ret.help = help;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
return ret;
|
2013-12-01 22:59:46 +01:00
|
|
|
}
|