2014-02-25 08:28:24 +01:00
|
|
|
/* chat.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-07-31 20:20:16 +02:00
|
|
|
*/
|
|
|
|
|
2014-07-14 20:32:38 +02:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE /* needed for wcswidth() */
|
|
|
|
#endif
|
|
|
|
|
2013-07-31 19:20:03 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-08-03 01:44:32 +02:00
|
|
|
#include <time.h>
|
2014-06-22 03:41:38 +02:00
|
|
|
#include <wchar.h>
|
2014-07-04 18:04:03 +02:00
|
|
|
#include <assert.h>
|
2013-07-31 19:20:03 +02:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.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-11-29 23:48:08 +01:00
|
|
|
#include "friendlist.h"
|
2013-12-10 09:03:45 +01:00
|
|
|
#include "toxic_strings.h"
|
2014-03-01 13:10:44 +01:00
|
|
|
#include "log.h"
|
2014-03-24 12:18:58 +01:00
|
|
|
#include "line_info.h"
|
2014-04-07 10:42:10 +02:00
|
|
|
#include "settings.h"
|
2014-06-26 08:33:09 +02:00
|
|
|
#include "input.h"
|
2014-07-04 09:24:29 +02:00
|
|
|
#include "help.h"
|
2014-07-18 07:29:46 +02:00
|
|
|
#include "autocomplete.h"
|
2014-07-21 01:12:13 +02:00
|
|
|
#include "notify.h"
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _AUDIO
|
|
|
|
#include "audio_call.h"
|
|
|
|
#endif /* _AUDIO */
|
2013-07-31 19:20:03 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2013-09-04 08:05:36 +02:00
|
|
|
extern char *DATA_FILE;
|
|
|
|
|
2014-06-28 18:14:43 +02:00
|
|
|
extern FileSender file_senders[MAX_FILES];
|
2013-11-30 00:52:21 +01:00
|
|
|
extern ToxicFriend friends[MAX_FRIENDS_NUM];
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2014-03-13 11:06:53 +01:00
|
|
|
extern struct _Winthread Winthread;
|
2014-07-21 01:12:13 +02:00
|
|
|
extern struct user_settings *user_settings_;
|
2014-03-07 03:27:48 +01:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _AUDIO
|
2014-06-24 00:54:23 +02:00
|
|
|
static void init_infobox(ToxWindow *self);
|
|
|
|
static void kill_infobox(ToxWindow *self);
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _AUDIO */
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _AUDIO
|
2014-06-22 02:18:23 +02:00
|
|
|
#define AC_NUM_CHAT_COMMANDS 26
|
2014-03-07 03:27:48 +01:00
|
|
|
#else
|
2014-04-19 23:58:13 +02:00
|
|
|
#define AC_NUM_CHAT_COMMANDS 18
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _AUDIO */
|
2013-12-09 23:56:20 +01:00
|
|
|
|
|
|
|
/* Array of chat command names used for tab completion. */
|
2014-07-07 04:15:35 +02:00
|
|
|
static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/accept" },
|
|
|
|
{ "/add" },
|
|
|
|
{ "/clear" },
|
|
|
|
{ "/close" },
|
|
|
|
{ "/connect" },
|
|
|
|
{ "/exit" },
|
|
|
|
{ "/groupchat" },
|
|
|
|
{ "/help" },
|
|
|
|
{ "/invite" },
|
|
|
|
{ "/join" },
|
2014-02-27 01:00:13 +01:00
|
|
|
{ "/log" },
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/myid" },
|
|
|
|
{ "/nick" },
|
|
|
|
{ "/note" },
|
|
|
|
{ "/quit" },
|
|
|
|
{ "/savefile" },
|
|
|
|
{ "/sendfile" },
|
|
|
|
{ "/status" },
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _AUDIO
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
{ "/call" },
|
|
|
|
{ "/cancel" },
|
|
|
|
{ "/answer" },
|
2014-03-23 22:54:56 +01:00
|
|
|
{ "/reject" },
|
2014-03-07 03:14:04 +01:00
|
|
|
{ "/hangup" },
|
2014-06-21 01:58:00 +02:00
|
|
|
{ "/sdev" },
|
2014-06-22 02:18:23 +02:00
|
|
|
{ "/mute" },
|
|
|
|
{ "/sense" },
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _AUDIO */
|
2013-12-09 23:56:20 +01:00
|
|
|
};
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2014-03-21 01:50:48 +01:00
|
|
|
static void set_typingstatus(ToxWindow *self, Tox *m, uint8_t is_typing)
|
2014-02-23 10:28:33 +01:00
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
|
|
|
tox_set_user_is_typing(m, self->num, is_typing);
|
|
|
|
ctx->self_is_typing = is_typing;
|
|
|
|
}
|
|
|
|
|
2014-07-08 01:39:33 +02:00
|
|
|
static void chat_set_window_name(ToxWindow *self, char *nick, int len)
|
|
|
|
{
|
|
|
|
if (len > MAX_WINDOW_NAME_LENGTH) {
|
|
|
|
strcpy(&nick[MAX_WINDOW_NAME_LENGTH - 3], "...");
|
|
|
|
nick[MAX_WINDOW_NAME_LENGTH] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(self->name, sizeof(self->name), "%s", nick);
|
|
|
|
}
|
|
|
|
|
2014-07-09 01:24:44 +02:00
|
|
|
void kill_chat_window(ToxWindow *self)
|
2014-02-26 11:23:11 +01:00
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
StatusBar *statusbar = self->stb;
|
|
|
|
|
2014-03-01 13:10:44 +01:00
|
|
|
log_disable(ctx->log);
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_cleanup(ctx->hst);
|
2014-02-26 11:23:11 +01:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _AUDIO
|
2014-07-04 18:04:03 +02:00
|
|
|
stop_current_call(self);
|
|
|
|
#endif
|
|
|
|
|
2014-02-26 11:23:11 +01:00
|
|
|
delwin(ctx->linewin);
|
2014-07-01 05:56:47 +02:00
|
|
|
delwin(ctx->history);
|
2014-02-26 11:23:11 +01:00
|
|
|
delwin(statusbar->topline);
|
2014-07-09 01:24:44 +02:00
|
|
|
|
2014-03-01 13:10:44 +01:00
|
|
|
free(ctx->log);
|
2014-03-24 12:18:58 +01:00
|
|
|
free(ctx->hst);
|
2014-02-26 11:23:11 +01:00
|
|
|
free(ctx);
|
2014-07-04 09:24:29 +02:00
|
|
|
free(self->help);
|
2014-02-26 11:23:11 +01:00
|
|
|
free(statusbar);
|
2014-07-09 01:24:44 +02:00
|
|
|
|
|
|
|
disable_chatwin(self->num);
|
2014-07-04 09:24:29 +02:00
|
|
|
del_window(self);
|
2014-02-26 11:23:11 +01:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *msg, uint16_t len)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2013-09-15 22:38:38 +02:00
|
|
|
if (self->num != num)
|
2013-09-06 00:24:58 +02:00
|
|
|
return;
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2014-07-08 20:31:59 +02:00
|
|
|
get_nick_truncate(m, nick, num);
|
2013-08-16 19:11:09 +02: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));
|
2013-09-26 06:33:51 +02:00
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_add(self, timefrmt, nick, NULL, msg, IN_MSG, 0, 0);
|
2014-03-04 01:21:52 +01:00
|
|
|
write_to_log(msg, nick, ctx->log, false);
|
2014-07-21 01:12:13 +02:00
|
|
|
|
|
|
|
notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS);
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|
|
|
|
|
2014-03-19 02:48:26 +01:00
|
|
|
static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
2013-09-05 03:25:59 +02:00
|
|
|
{
|
2013-09-15 22:38:38 +02:00
|
|
|
if (self->num != num)
|
2013-09-05 03:25:59 +02:00
|
|
|
return;
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2014-02-23 10:28:33 +01:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
if (status == 1) { /* Friend shows online */
|
2014-02-23 10:28:33 +01:00
|
|
|
statusbar->is_online = true;
|
|
|
|
friends[num].is_typing = tox_get_is_typing(m, num);
|
2014-07-21 01:12:13 +02:00
|
|
|
notify(self, user_log_in, NT_NOFOCUS);
|
|
|
|
} else { /* Friend goes offline */
|
2014-02-23 10:28:33 +01:00
|
|
|
statusbar->is_online = false;
|
2014-03-21 01:50:48 +01:00
|
|
|
friends[num].is_typing = 0;
|
2014-07-21 01:12:13 +02:00
|
|
|
notify(self, user_log_out, NT_NOFOCUS);
|
2014-02-23 10:28:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 01:50:48 +01:00
|
|
|
static void chat_onTypingChange(ToxWindow *self, Tox *m, int32_t num, uint8_t is_typing)
|
2014-02-23 10:28:33 +01:00
|
|
|
{
|
|
|
|
if (self->num != num)
|
|
|
|
return;
|
|
|
|
|
|
|
|
friends[num].is_typing = is_typing;
|
2013-09-05 03:25:59 +02:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const char *action, uint16_t len)
|
2013-08-08 21:01:33 +02:00
|
|
|
{
|
2013-09-15 22:38:38 +02:00
|
|
|
if (self->num != num)
|
2013-09-06 00:24:58 +02:00
|
|
|
return;
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-08-08 21:01:33 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2014-07-08 20:31:59 +02:00
|
|
|
get_nick_truncate(m, nick, num);
|
2013-08-31 08:22:07 +02: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));
|
2013-08-08 21:01:33 +02:00
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_add(self, timefrmt, nick, NULL, action, ACTION, 0, 0);
|
2014-03-04 01:21:52 +01:00
|
|
|
write_to_log(action, nick, ctx->log, true);
|
2014-07-21 01:12:13 +02:00
|
|
|
notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS);
|
2013-08-08 21:01:33 +02:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *nick, uint16_t len)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2013-09-15 22:38:38 +02:00
|
|
|
if (self->num != num)
|
2013-08-16 19:11:09 +02:00
|
|
|
return;
|
|
|
|
|
2014-07-08 01:39:33 +02:00
|
|
|
if (len > TOX_MAX_NAME_LENGTH)
|
|
|
|
return;
|
|
|
|
|
2014-07-08 01:08:33 +02:00
|
|
|
StatusBar *statusbar = self->stb;
|
|
|
|
|
|
|
|
char tmpname[TOX_MAX_NAME_LENGTH];
|
|
|
|
strcpy(tmpname, nick);
|
|
|
|
int n_len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
|
|
|
tmpname[n_len] = '\0';
|
|
|
|
|
|
|
|
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", tmpname);
|
2014-07-08 01:39:33 +02:00
|
|
|
chat_set_window_name(self, tmpname, n_len);
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|
|
|
|
|
2014-03-19 02:48:26 +01:00
|
|
|
static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2013-09-15 22:38:38 +02:00
|
|
|
if (self->num != num)
|
2013-08-16 19:11:09 +02:00
|
|
|
return;
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2013-09-06 00:24:58 +02:00
|
|
|
statusbar->status = status;
|
2013-09-05 03:25:59 +02:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, const char *status, uint16_t len)
|
2013-09-05 03:25:59 +02:00
|
|
|
{
|
2013-09-15 22:38:38 +02:00
|
|
|
if (self->num != num)
|
2013-09-05 03:25:59 +02:00
|
|
|
return;
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2014-06-22 02:18:23 +02:00
|
|
|
|
|
|
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", status);
|
2014-07-02 23:30:31 +02:00
|
|
|
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
|
2014-07-07 04:15:35 +02:00
|
|
|
uint64_t filesize, const char *pathname, uint16_t path_len)
|
2013-10-11 06:23:39 +02:00
|
|
|
{
|
2013-10-17 12:13:28 +02:00
|
|
|
if (self->num != num)
|
2013-10-11 06:23:39 +02:00
|
|
|
return;
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char msg[MAX_STR_SIZE * 2];
|
|
|
|
char *errmsg;
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
/* holds the filename appended to the user specified path */
|
2014-07-07 04:15:35 +02:00
|
|
|
char filename_path[MAX_STR_SIZE] = {0};
|
2014-06-22 02:18:23 +02:00
|
|
|
|
|
|
|
/* holds the lone filename */
|
2014-07-07 04:15:35 +02:00
|
|
|
char filename_nopath[MAX_STR_SIZE];
|
2014-07-09 06:05:13 +02:00
|
|
|
get_file_name(filename_nopath, sizeof(filename_nopath), pathname);
|
2014-06-22 02:18:23 +02:00
|
|
|
int len = strlen(filename_nopath);
|
|
|
|
|
|
|
|
snprintf(msg, sizeof(msg), "File transfer request for '%s' (%llu bytes).", filename_nopath,
|
2014-04-19 23:58:13 +02:00
|
|
|
(long long unsigned int)filesize);
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2013-10-18 07:35:08 +02:00
|
|
|
if (filenum >= MAX_FILES) {
|
2014-03-24 12:18:58 +01:00
|
|
|
errmsg = "Too many pending file requests; discarding.";
|
|
|
|
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
|
2013-10-11 06:23:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
/* use specified path in config if possible */
|
2014-07-21 01:12:13 +02:00
|
|
|
if (user_settings_->download_path[0]) {
|
|
|
|
snprintf(filename_path, sizeof(filename_path), "%s%s", user_settings_->download_path, filename_nopath);
|
|
|
|
len += strlen(user_settings_->download_path);
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (len >= sizeof(friends[num].file_receiver.filenames[filenum])) {
|
|
|
|
errmsg = "File name too long; discarding.";
|
|
|
|
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char filename[MAX_STR_SIZE];
|
2014-06-22 02:18:23 +02:00
|
|
|
|
|
|
|
if (filename_path[0])
|
|
|
|
strcpy(filename, filename_path);
|
|
|
|
else
|
|
|
|
strcpy(filename, filename_nopath);
|
|
|
|
|
2013-11-12 22:53:41 +01:00
|
|
|
/* Append a number to duplicate file names */
|
2013-10-18 04:20:40 +02:00
|
|
|
FILE *filecheck = NULL;
|
2013-11-12 08:18:43 +01:00
|
|
|
int count = 1;
|
|
|
|
|
|
|
|
while ((filecheck = fopen(filename, "r"))) {
|
|
|
|
filename[len] = '\0';
|
|
|
|
char d[9];
|
2014-04-19 23:58:13 +02:00
|
|
|
sprintf(d, "(%d)", count++);
|
2014-06-22 02:18:23 +02:00
|
|
|
int d_len = strlen(d);
|
|
|
|
|
|
|
|
if (len + d_len >= sizeof(filename)) {
|
|
|
|
len -= d_len;
|
|
|
|
filename[len] = '\0';
|
|
|
|
}
|
|
|
|
|
2013-11-12 08:18:43 +01:00
|
|
|
strcat(filename, d);
|
2014-06-22 02:18:23 +02:00
|
|
|
filename[len + d_len] = '\0';
|
2013-11-12 08:18:43 +01:00
|
|
|
|
2014-03-05 09:31:12 +01:00
|
|
|
if (count > 999) {
|
2014-03-24 12:18:58 +01:00
|
|
|
errmsg = "Error saving file to disk.";
|
|
|
|
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
|
2013-11-12 08:18:43 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-10-18 04:20:40 +02:00
|
|
|
}
|
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
snprintf(msg, sizeof(msg), "Type '/savefile %d' to accept the file transfer.", filenum);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2013-10-18 07:35:08 +02:00
|
|
|
friends[num].file_receiver.pending[filenum] = true;
|
2014-03-28 04:05:50 +01:00
|
|
|
friends[num].file_receiver.size[filenum] = filesize;
|
2013-10-18 01:53:29 +02:00
|
|
|
strcpy(friends[num].file_receiver.filenames[filenum], filename);
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
notify(self, transfer_pending, NT_WNDALERT_2 | NT_NOFOCUS);
|
2013-10-11 06:23:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-28 18:14:43 +02:00
|
|
|
static void chat_close_file_receiver(int32_t num, uint8_t filenum)
|
2014-03-05 09:31:12 +01:00
|
|
|
{
|
|
|
|
FILE *file = friends[num].file_receiver.files[filenum];
|
|
|
|
|
2014-06-28 18:14:43 +02:00
|
|
|
if (file != NULL) {
|
2014-03-05 09:31:12 +01:00
|
|
|
fclose(file);
|
2014-06-28 18:14:43 +02:00
|
|
|
friends[num].file_receiver.files[filenum] = NULL;
|
|
|
|
}
|
2014-03-05 09:31:12 +01:00
|
|
|
}
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t receive_send,
|
2014-07-07 04:15:35 +02:00
|
|
|
uint8_t filenum, uint8_t control_type, const char *data, uint16_t length)
|
2013-10-11 06:23:39 +02:00
|
|
|
{
|
|
|
|
if (self->num != num)
|
|
|
|
return;
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
const char *filename;
|
|
|
|
char msg[MAX_STR_SIZE] = {0};
|
|
|
|
int i = 0; /* file_sender index */
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
if (receive_send == 0) {
|
2013-10-18 04:20:40 +02:00
|
|
|
filename = friends[num].file_receiver.filenames[filenum];
|
2014-06-22 02:18:23 +02:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < MAX_FILES; ++i) {
|
|
|
|
if (file_senders[i].filenum == filenum)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
filename = file_senders[i].pathname;
|
|
|
|
}
|
2013-10-18 01:53:29 +02:00
|
|
|
|
2013-11-12 07:50:04 +01:00
|
|
|
switch (control_type) {
|
2014-04-19 23:58:13 +02:00
|
|
|
case TOX_FILECONTROL_ACCEPT:
|
2014-06-22 02:18:23 +02:00
|
|
|
if (receive_send == 1) {
|
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' accepted (%.1f%%)", filename, 0.0);
|
|
|
|
file_senders[i].line_id = self->chatwin->hst->line_end->id + 1;
|
2014-07-21 03:25:21 +02:00
|
|
|
notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2);
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_FILECONTROL_KILL:
|
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed.", filename);
|
|
|
|
|
|
|
|
if (receive_send == 0)
|
|
|
|
chat_close_file_receiver(num, filenum);
|
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
notify(self, error, NT_NOFOCUS | NT_WNDALERT_2);
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_FILECONTROL_FINISHED:
|
2014-06-22 02:18:23 +02:00
|
|
|
if (receive_send == 0) {
|
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' complete.", filename);
|
|
|
|
chat_close_file_receiver(num, filenum);
|
2014-07-21 01:12:13 +02:00
|
|
|
notify(self, transfer_completed, NT_NOFOCUS | NT_WNDALERT_2);
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
2013-10-11 06:23:39 +02:00
|
|
|
}
|
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
|
2013-10-11 06:23:39 +02:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const char *data,
|
2013-10-11 10:42:30 +02:00
|
|
|
uint16_t length)
|
2013-10-11 06:23:39 +02:00
|
|
|
{
|
|
|
|
if (self->num != num)
|
|
|
|
return;
|
|
|
|
|
2014-06-28 18:14:43 +02:00
|
|
|
FILE *fp = friends[num].file_receiver.files[filenum];
|
|
|
|
|
|
|
|
if (fp) {
|
2014-06-28 18:55:05 +02:00
|
|
|
if (fwrite(data, length, 1, fp) != 1) {
|
2014-07-01 05:56:47 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, " * Error writing to file.", SYS_MSG, 0, RED);
|
2014-06-28 18:14:43 +02:00
|
|
|
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
|
|
|
chat_close_file_receiver(num, filenum);
|
|
|
|
}
|
2013-11-27 20:31:10 +01:00
|
|
|
}
|
2014-03-28 04:05:50 +01:00
|
|
|
|
2014-03-28 04:13:38 +01:00
|
|
|
long double remain = (long double) tox_file_data_remaining(m, num, filenum, 1);
|
2014-06-30 20:15:24 +02:00
|
|
|
uint64_t curtime = get_unix_time();
|
2014-03-28 04:05:50 +01:00
|
|
|
|
2014-06-30 20:15:24 +02:00
|
|
|
/* refresh line with percentage complete */
|
|
|
|
if (!remain || timed_out(friends[num].file_receiver.last_progress[filenum], curtime, 1)) {
|
|
|
|
friends[num].file_receiver.last_progress[filenum] = curtime;
|
|
|
|
uint64_t size = friends[num].file_receiver.size[filenum];
|
|
|
|
long double pct_remain = remain ? (1 - (remain / size)) * 100 : 100;
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char msg[MAX_STR_SIZE];
|
|
|
|
const char *name = friends[num].file_receiver.filenames[filenum];
|
2014-06-30 20:15:24 +02:00
|
|
|
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1Lf%%)", name, pct_remain);
|
|
|
|
line_info_set(self, friends[num].file_receiver.line_id[filenum], msg);
|
|
|
|
}
|
2013-10-11 06:23:39 +02:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, const char *group_pub_key)
|
2013-10-14 01:09:20 +02:00
|
|
|
{
|
2013-11-12 23:26:13 +01:00
|
|
|
if (self->num != friendnumber)
|
2013-10-14 01:09:20 +02:00
|
|
|
return;
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char msg[MAX_STR_SIZE + TOX_MAX_NAME_LENGTH];
|
2014-07-08 20:31:59 +02:00
|
|
|
|
|
|
|
char name[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, name, friendnumber);
|
2014-04-01 08:48:37 +02:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
snprintf(msg, sizeof(msg), "%s has invited you to a group chat.", name);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
|
2014-07-02 19:46:57 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Type \"/join\" to join the chat.", SYS_MSG, 0, 0);
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
memcpy(friends[friendnumber].groupchat_key, group_pub_key,
|
|
|
|
sizeof(friends[friendnumber].groupchat_key));
|
2014-07-02 19:46:57 +02:00
|
|
|
friends[friendnumber].groupchat_pending = true;
|
2013-10-14 01:09:20 +02:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
|
|
|
|
notify(self, generic_message, NT_WNDALERT_2);
|
2013-08-04 10:42:17 +02:00
|
|
|
}
|
2013-08-03 16:00:48 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
/* Av Stuff */
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _AUDIO
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onInvite (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if (!self || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
/* call_index is set here and reset on call end */
|
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
self->call_idx = call_index;
|
2014-06-14 07:43:59 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Incoming audio call! Type: \"/answer\" or \"/reject\"", SYS_MSG, 0, 0);
|
2014-07-21 01:12:13 +02:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
if (self->active_sound == -1)
|
|
|
|
self->active_sound = notify(self, call_incoming, NT_LOOP | NT_WNDALERT_0);
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Ringing...\"cancel\" ?", SYS_MSG, 0, 0);
|
2014-07-21 01:12:13 +02:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
if (self->active_sound == -1)
|
|
|
|
self->active_sound = notify(self, call_outgoing, NT_LOOP);
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onStarting (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
init_infobox(self);
|
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Call started! Type: \"/hangup\" to end it.", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onEnding (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
kill_infobox(self);
|
2014-06-21 01:58:00 +02:00
|
|
|
self->call_idx = -1;
|
2014-05-16 20:00:01 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Call ended!", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onError (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
self->call_idx = -1;
|
2014-05-16 20:00:01 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Error!", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
init_infobox(self);
|
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Call started! Type: \"/hangup\" to end it.", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onCancel (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 04:02:22 +02:00
|
|
|
kill_infobox(self);
|
2014-06-21 01:58:00 +02:00
|
|
|
self->call_idx = -1;
|
2014-05-16 20:00:01 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Call canceled!", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onReject (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
self->call_idx = -1;
|
2014-05-16 20:00:01 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Rejected!", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onEnd (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
kill_infobox(self);
|
2014-06-21 01:58:00 +02:00
|
|
|
self->call_idx = -1;
|
2014-05-16 20:00:01 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Call ended!", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
self->call_idx = -1;
|
2014-05-16 20:00:01 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "No answer!", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
|
2014-03-14 23:08:08 +01:00
|
|
|
{
|
2014-07-04 18:04:03 +02:00
|
|
|
if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
|
2014-03-14 23:08:08 +01:00
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
kill_infobox(self);
|
2014-06-21 01:58:00 +02:00
|
|
|
self->call_idx = -1;
|
2014-05-16 20:00:01 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, "Peer disconnected; call ended!", SYS_MSG, 0, 0);
|
2014-07-21 03:25:21 +02:00
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
stop_sound(self->active_sound);
|
|
|
|
self->active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-03-14 23:08:08 +01:00
|
|
|
}
|
|
|
|
|
2014-07-21 23:48:39 +02:00
|
|
|
#ifdef _AUDIO
|
2014-06-24 00:54:23 +02:00
|
|
|
static void init_infobox(ToxWindow *self)
|
|
|
|
{
|
2014-06-24 07:54:08 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-07-07 04:15:35 +02:00
|
|
|
(void) y2;
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
memset(&ctx->infobox, 0, sizeof(struct infobox));
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
ctx->infobox.win = newwin(INFOBOX_HEIGHT, INFOBOX_WIDTH + 1, 1, x2 - INFOBOX_WIDTH);
|
|
|
|
ctx->infobox.starttime = get_unix_time();
|
2014-07-21 23:48:39 +02:00
|
|
|
ctx->infobox.vad_lvl = user_settings_->VAD_treshold;
|
2014-06-24 07:54:08 +02:00
|
|
|
ctx->infobox.active = true;
|
|
|
|
strcpy(ctx->infobox.timestr, "00");
|
2014-06-24 00:54:23 +02:00
|
|
|
}
|
2014-07-21 23:48:39 +02:00
|
|
|
#endif
|
2014-06-24 00:54:23 +02:00
|
|
|
|
|
|
|
static void kill_infobox(ToxWindow *self)
|
|
|
|
{
|
2014-06-24 07:54:08 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
|
|
|
if (!ctx->infobox.win)
|
2014-06-24 00:54:23 +02:00
|
|
|
return;
|
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
delwin(ctx->infobox.win);
|
|
|
|
memset(&ctx->infobox, 0, sizeof(struct infobox));
|
2014-06-24 00:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update infobox info and draw in respective chat window */
|
|
|
|
static void draw_infobox(ToxWindow *self)
|
|
|
|
{
|
2014-06-24 07:54:08 +02:00
|
|
|
struct infobox *infobox = &self->chatwin->infobox;
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
if (infobox->win == NULL)
|
2014-06-24 00:54:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
|
|
|
|
|
|
|
if (x2 < INFOBOX_WIDTH || y2 < INFOBOX_HEIGHT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint64_t curtime = get_unix_time();
|
|
|
|
|
|
|
|
/* update elapsed time string once per second */
|
2014-06-24 07:54:08 +02:00
|
|
|
if (curtime > infobox->lastupdate)
|
|
|
|
get_elapsed_time_str(infobox->timestr, sizeof(infobox->timestr), curtime - infobox->starttime);
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
infobox->lastupdate = curtime;
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
const char *in_is_muted = infobox->in_is_muted ? "yes" : "no";
|
|
|
|
const char *out_is_muted = infobox->out_is_muted ? "yes" : "no";
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
wmove(infobox->win, 1, 1);
|
|
|
|
wattron(infobox->win, COLOR_PAIR(RED) | A_BOLD);
|
|
|
|
wprintw(infobox->win, " Call Active\n");
|
|
|
|
wattroff(infobox->win, COLOR_PAIR(RED) | A_BOLD);
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
wattron(infobox->win, A_BOLD);
|
|
|
|
wprintw(infobox->win, " Duration: ");
|
|
|
|
wattroff(infobox->win, A_BOLD);
|
|
|
|
wprintw(infobox->win, "%s\n", infobox->timestr);
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
wattron(infobox->win, A_BOLD);
|
|
|
|
wprintw(infobox->win, " In muted: ");
|
|
|
|
wattroff(infobox->win, A_BOLD);
|
|
|
|
wprintw(infobox->win, "%s\n", in_is_muted);
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
wattron(infobox->win, A_BOLD);
|
|
|
|
wprintw(infobox->win, " Out muted: ");
|
|
|
|
wattroff(infobox->win, A_BOLD);
|
|
|
|
wprintw(infobox->win, "%s\n", out_is_muted);
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
wattron(infobox->win, A_BOLD);
|
|
|
|
wprintw(infobox->win, " VAD level: ");
|
|
|
|
wattroff(infobox->win, A_BOLD);
|
|
|
|
wprintw(infobox->win, "%.2f\n", infobox->vad_lvl);
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-06-24 07:54:08 +02:00
|
|
|
wborder(infobox->win, ACS_VLINE, ' ', ACS_HLINE, ACS_HLINE, ACS_TTEE, ' ', ACS_LLCORNER, ' ');
|
|
|
|
wrefresh(infobox->win);
|
2014-06-24 00:54:23 +02:00
|
|
|
}
|
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _AUDIO */
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2014-03-24 12:18:58 +01:00
|
|
|
if (action == NULL)
|
2013-09-19 12:37:42 +02:00
|
|
|
return;
|
2013-09-02 07:14:51 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char selfname[TOX_MAX_NAME_LENGTH];
|
|
|
|
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
|
2014-04-01 04:00:17 +02:00
|
|
|
selfname[len] = '\0';
|
2013-08-16 19:11:09 +02: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-24 12:18:58 +01:00
|
|
|
|
|
|
|
line_info_add(self, timefrmt, selfname, NULL, action, ACTION, 0, 0);
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
if (tox_send_action(m, self->num, (uint8_t *) action, strlen(action)) == 0) {
|
|
|
|
char *errmsg = " * Failed to send action.";
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_add(self, NULL, selfname, NULL, errmsg, SYS_MSG, 0, RED);
|
2014-02-26 09:51:26 +01:00
|
|
|
} else {
|
2014-03-04 01:21:52 +01:00
|
|
|
write_to_log(action, selfname, ctx->log, true);
|
2013-08-04 10:42:17 +02:00
|
|
|
}
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|
|
|
|
|
2014-03-30 22:40:13 +02:00
|
|
|
static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
2013-09-10 10:04:13 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
StatusBar *statusbar = self->stb;
|
2013-09-10 10:04:13 +02:00
|
|
|
|
|
|
|
int x, y, y2, x2;
|
|
|
|
getyx(self->window, y, x);
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
if (x2 <= 0)
|
2014-03-24 12:18:58 +01:00
|
|
|
return;
|
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
if (self->help->active) {
|
|
|
|
help_onKey(self, key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-25 03:02:16 +02:00
|
|
|
if (ltr) { /* char is printable */
|
2014-06-26 08:33:09 +02:00
|
|
|
input_new_char(self, key, x, y, x2, y2);
|
2013-12-01 22:57:05 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
if (ctx->line[0] != '/')
|
2014-03-30 22:40:13 +02:00
|
|
|
set_typingstatus(self, m, 1);
|
2013-12-01 22:57:05 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-12-01 22:57:05 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
if (line_info_onKey(self, key))
|
|
|
|
return;
|
2013-12-01 04:12:43 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
input_handle(self, key, x, y, x2, y2);
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2014-07-18 07:29:46 +02:00
|
|
|
if (key == '\t' && ctx->len > 1 && ctx->line[0] == '/') { /* TAB key: auto-complete */
|
|
|
|
int diff = -1;
|
|
|
|
int sf_len = 11;
|
|
|
|
|
|
|
|
if (wcsncmp(ctx->line, L"/sendfile \"", sf_len) == 0) {
|
|
|
|
diff = dir_match(self, m, &ctx->line[sf_len]);
|
|
|
|
} else {
|
2014-07-18 18:42:53 +02:00
|
|
|
diff = complete_line(self, chat_cmd_list, AC_NUM_CHAT_COMMANDS, MAX_CMDNAME_SIZE);
|
2014-07-18 07:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (diff != -1) {
|
2014-07-18 18:42:53 +02:00
|
|
|
if (x + diff > x2 - 1) {
|
|
|
|
int wlen = wcswidth(ctx->line, sizeof(ctx->line));
|
|
|
|
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
|
|
|
|
}
|
2014-07-18 07:29:46 +02:00
|
|
|
} else {
|
2014-07-21 03:25:21 +02:00
|
|
|
notify(self, error, 0);
|
2014-07-18 07:29:46 +02:00
|
|
|
}
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2014-06-26 08:33:09 +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];
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1)
|
|
|
|
memset(&line, 0, sizeof(line));
|
2013-12-01 04:12:43 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
if (!string_is_empty(line))
|
|
|
|
add_line_to_hist(ctx);
|
2014-02-23 10:28:33 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
if (line[0] == '/') {
|
|
|
|
if (strcmp(line, "/close") == 0) {
|
2014-07-09 01:24:44 +02:00
|
|
|
kill_chat_window(self);
|
2014-06-26 08:33:09 +02:00
|
|
|
return;
|
|
|
|
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
|
|
|
|
send_action(self, ctx, m, line + strlen("/me "));
|
2014-03-30 22:40:13 +02:00
|
|
|
} else {
|
2014-06-26 08:33:09 +02:00
|
|
|
execute(ctx->history, self, m, line, CHAT_COMMAND_MODE);
|
2014-03-30 22:40:13 +02:00
|
|
|
}
|
2014-06-26 08:33:09 +02:00
|
|
|
} else if (!string_is_empty(line)) {
|
2014-07-07 04:15:35 +02:00
|
|
|
char selfname[TOX_MAX_NAME_LENGTH];
|
|
|
|
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
|
2014-06-26 08:33:09 +02:00
|
|
|
selfname[len] = '\0';
|
2013-10-23 09:24:08 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char timefrmt[TIME_STR_SIZE];
|
2014-06-26 08:33:09 +02:00
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
line_info_add(self, timefrmt, selfname, NULL, line, OUT_MSG, 0, 0);
|
2014-02-26 11:23:11 +01:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
if (!statusbar->is_online || tox_send_message(m, self->num, (uint8_t *) line, strlen(line)) == 0) {
|
2014-07-13 21:34:09 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, " * Failed to send message.", SYS_MSG, 0, RED);
|
2014-06-26 08:33:09 +02:00
|
|
|
} else {
|
|
|
|
write_to_log(line, selfname, ctx->log, false);
|
2013-09-10 10:04:13 +02:00
|
|
|
}
|
2014-03-30 22:40:13 +02:00
|
|
|
}
|
2014-06-26 08:33:09 +02:00
|
|
|
|
|
|
|
wclear(ctx->linewin);
|
|
|
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
|
|
|
reset_buf(ctx);
|
2013-09-10 10:04:13 +02:00
|
|
|
}
|
2014-02-23 11:38:44 +01:00
|
|
|
|
2014-02-26 11:23:11 +01:00
|
|
|
if (ctx->len <= 0 && ctx->self_is_typing)
|
2014-03-21 01:50:48 +01:00
|
|
|
set_typingstatus(self, m, 0);
|
2013-09-10 10:04:13 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 23:03:44 +02:00
|
|
|
static void chat_onDraw(ToxWindow *self, Tox *m)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2013-12-12 06:37:29 +01:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-09-10 10:04:13 +02:00
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_print(self);
|
2014-03-27 10:08:48 +01:00
|
|
|
wclear(ctx->linewin);
|
2013-12-08 10:16:49 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
curs_set(1);
|
2014-03-27 10:08:48 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
if (ctx->len > 0)
|
|
|
|
mvwprintw(ctx->linewin, 1, 0, "%ls", &ctx->line[ctx->start]);
|
2013-12-01 04:12:43 +01:00
|
|
|
|
2013-09-06 00:24:58 +02:00
|
|
|
/* Draw status bar */
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2013-12-12 06:37:29 +01:00
|
|
|
mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x2);
|
2013-09-06 00:24:58 +02:00
|
|
|
wmove(statusbar->topline, 0, 0);
|
|
|
|
|
|
|
|
/* Draw name, status and note in statusbar */
|
|
|
|
if (statusbar->is_online) {
|
|
|
|
int colour = WHITE;
|
2014-03-19 02:48:26 +01:00
|
|
|
uint8_t status = statusbar->status;
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2013-11-12 07:50:04 +01:00
|
|
|
switch (status) {
|
2014-04-19 23:58:13 +02:00
|
|
|
case TOX_USERSTATUS_NONE:
|
|
|
|
colour = GREEN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_USERSTATUS_AWAY:
|
|
|
|
colour = YELLOW;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_USERSTATUS_BUSY:
|
|
|
|
colour = RED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOX_USERSTATUS_INVALID:
|
|
|
|
colour = MAGENTA;
|
|
|
|
break;
|
2013-09-06 00:24:58 +02:00
|
|
|
}
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2014-03-15 12:40:13 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
|
2014-06-29 00:40:22 +02:00
|
|
|
wprintw(statusbar->topline, " O");
|
2014-03-15 12:40:13 +01:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
|
|
|
|
|
2014-02-23 10:28:33 +01:00
|
|
|
if (friends[self->num].is_typing)
|
|
|
|
wattron(statusbar->topline, COLOR_PAIR(YELLOW));
|
|
|
|
|
2013-09-06 00:24:58 +02:00
|
|
|
wattron(statusbar->topline, A_BOLD);
|
2014-07-08 01:08:33 +02:00
|
|
|
wprintw(statusbar->topline, " %s ", statusbar->nick);
|
2013-09-06 00:24:58 +02:00
|
|
|
wattroff(statusbar->topline, A_BOLD);
|
2014-02-23 10:28:33 +01:00
|
|
|
|
|
|
|
if (friends[self->num].is_typing)
|
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(YELLOW));
|
2013-09-06 00:24:58 +02:00
|
|
|
} else {
|
2014-06-29 00:40:22 +02:00
|
|
|
wprintw(statusbar->topline, " o");
|
2013-09-06 00:24:58 +02:00
|
|
|
wattron(statusbar->topline, A_BOLD);
|
2014-07-08 01:08:33 +02:00
|
|
|
wprintw(statusbar->topline, " %s ", statusbar->nick);
|
2013-09-06 00:24:58 +02:00
|
|
|
wattroff(statusbar->topline, A_BOLD);
|
|
|
|
}
|
|
|
|
|
2013-09-13 08:02:49 +02:00
|
|
|
/* Reset statusbar->statusmsg on window resize */
|
2013-12-12 06:37:29 +01:00
|
|
|
if (x2 != self->x) {
|
2014-07-07 04:15:35 +02:00
|
|
|
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
|
2014-03-13 11:06:53 +01:00
|
|
|
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-07-07 04:15:35 +02:00
|
|
|
tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
2014-03-13 11:06:53 +01:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-04-01 04:00:17 +02:00
|
|
|
|
2013-09-13 08:02:49 +02:00
|
|
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
2014-07-02 23:30:31 +02:00
|
|
|
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
2013-09-13 08:02:49 +02:00
|
|
|
}
|
|
|
|
|
2013-12-12 06:37:29 +01:00
|
|
|
self->x = x2;
|
2013-09-13 08:02:49 +02:00
|
|
|
|
2013-09-10 10:04:13 +02:00
|
|
|
/* Truncate note if it doesn't fit in statusbar */
|
2014-02-22 23:58:36 +01:00
|
|
|
uint16_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 7;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2013-09-10 10:04:13 +02:00
|
|
|
if (statusbar->statusmsg_len > maxlen) {
|
|
|
|
statusbar->statusmsg[maxlen] = '\0';
|
|
|
|
statusbar->statusmsg_len = maxlen;
|
|
|
|
}
|
|
|
|
|
2014-03-15 12:40:13 +01:00
|
|
|
if (statusbar->statusmsg[0])
|
|
|
|
wprintw(statusbar->topline, "- %s ", statusbar->statusmsg);
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2014-02-22 23:58:36 +01:00
|
|
|
wclrtoeol(statusbar->topline);
|
|
|
|
wmove(statusbar->topline, 0, x2 - (KEY_IDENT_DIGITS * 2) - 3);
|
|
|
|
wprintw(statusbar->topline, "{");
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < KEY_IDENT_DIGITS; ++i)
|
|
|
|
wprintw(statusbar->topline, "%02X", friends[self->num].pub_key[i] & 0xff);
|
|
|
|
|
|
|
|
wprintw(statusbar->topline, "}\n");
|
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-06-24 00:54:23 +02:00
|
|
|
|
|
|
|
wrefresh(self->window);
|
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _AUDIO
|
2014-07-05 21:20:33 +02:00
|
|
|
if (ctx->infobox.active) {
|
2014-06-24 00:54:23 +02:00
|
|
|
draw_infobox(self);
|
2014-07-05 21:20:33 +02:00
|
|
|
wrefresh(self->window);
|
|
|
|
}
|
2014-06-24 00:54:23 +02:00
|
|
|
#endif
|
|
|
|
|
2014-07-05 21:20:33 +02:00
|
|
|
if (self->help->active)
|
2014-07-04 09:24:29 +02:00
|
|
|
help_onDraw(self);
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 23:03:44 +02:00
|
|
|
static void chat_onInit(ToxWindow *self, Tox *m)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2014-03-25 13:21:50 +01:00
|
|
|
curs_set(1);
|
2013-12-12 06:37:29 +01:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
|
|
|
self->x = x2;
|
2013-09-06 00:24:58 +02:00
|
|
|
|
|
|
|
/* Init statusbar info */
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2013-11-29 16:14:59 +01:00
|
|
|
statusbar->status = tox_get_user_status(m, self->num);
|
|
|
|
statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
|
|
|
|
uint16_t s_len = tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
2014-04-01 04:00:17 +02:00
|
|
|
statusmsg[s_len] = '\0';
|
2013-09-08 09:18:34 +02:00
|
|
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
2014-04-01 04:00:17 +02:00
|
|
|
statusbar->statusmsg_len = s_len;
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2014-07-08 01:08:33 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2014-07-08 20:31:59 +02:00
|
|
|
int n_len = get_nick_truncate(m, nick, self->num);
|
2014-07-08 01:08:33 +02:00
|
|
|
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
|
|
|
statusbar->nick_len = n_len;
|
|
|
|
|
2013-09-06 00:24:58 +02:00
|
|
|
/* Init subwindows */
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2013-12-12 06:37:29 +01:00
|
|
|
statusbar->topline = subwin(self->window, 2, x2, 0, 0);
|
2014-04-19 23:58:13 +02:00
|
|
|
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-02-28 05:33:00 +01:00
|
|
|
|
2014-07-04 19:24:18 +02:00
|
|
|
ctx->hst = calloc(1, sizeof(struct history));
|
|
|
|
ctx->log = calloc(1, sizeof(struct chatlog));
|
2014-03-01 13:10:44 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
if (ctx->log == NULL || ctx->hst == NULL)
|
|
|
|
exit_toxic_err("failed in chat_onInit", FATALERR_MEMORY);
|
2014-03-01 13:10:44 +01:00
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_init(ctx->hst);
|
|
|
|
|
2014-02-28 05:33:00 +01:00
|
|
|
if (friends[self->num].logging_on)
|
2014-07-10 08:54:56 +02:00
|
|
|
log_enable(nick, friends[self->num].pub_key, ctx->log);
|
2014-02-28 05:33:00 +01:00
|
|
|
|
2014-02-27 01:00:13 +01:00
|
|
|
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
|
2014-03-01 13:10:44 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
scrollok(ctx->history, 0);
|
2013-12-12 06:37:29 +01:00
|
|
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|
|
|
|
|
2014-03-19 08:14:08 +01:00
|
|
|
ToxWindow new_chat(Tox *m, int32_t friendnum)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2013-08-16 19:11:09 +02:00
|
|
|
ToxWindow ret;
|
|
|
|
memset(&ret, 0, sizeof(ret));
|
|
|
|
|
2013-11-30 11:35:25 +01:00
|
|
|
ret.active = true;
|
2014-02-26 11:23:11 +01:00
|
|
|
ret.is_chat = true;
|
2013-11-30 11:35:25 +01:00
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
ret.onKey = &chat_onKey;
|
|
|
|
ret.onDraw = &chat_onDraw;
|
|
|
|
ret.onInit = &chat_onInit;
|
|
|
|
ret.onMessage = &chat_onMessage;
|
2013-09-05 03:25:59 +02:00
|
|
|
ret.onConnectionChange = &chat_onConnectionChange;
|
2014-02-23 10:28:33 +01:00
|
|
|
ret.onTypingChange = & chat_onTypingChange;
|
2013-11-10 03:43:56 +01:00
|
|
|
ret.onGroupInvite = &chat_onGroupInvite;
|
2013-08-16 19:11:09 +02:00
|
|
|
ret.onNickChange = &chat_onNickChange;
|
2013-09-05 03:25:59 +02:00
|
|
|
ret.onStatusChange = &chat_onStatusChange;
|
2013-09-03 05:27:34 +02:00
|
|
|
ret.onStatusMessageChange = &chat_onStatusMessageChange;
|
2013-08-16 19:11:09 +02:00
|
|
|
ret.onAction = &chat_onAction;
|
2013-10-11 06:23:39 +02:00
|
|
|
ret.onFileSendRequest = &chat_onFileSendRequest;
|
|
|
|
ret.onFileControl = &chat_onFileControl;
|
|
|
|
ret.onFileData = &chat_onFileData;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
#ifdef _AUDIO
|
2014-03-07 03:14:04 +01:00
|
|
|
ret.onInvite = &chat_onInvite;
|
|
|
|
ret.onRinging = &chat_onRinging;
|
|
|
|
ret.onStarting = &chat_onStarting;
|
|
|
|
ret.onEnding = &chat_onEnding;
|
|
|
|
ret.onError = &chat_onError;
|
|
|
|
ret.onStart = &chat_onStart;
|
|
|
|
ret.onCancel = &chat_onCancel;
|
|
|
|
ret.onReject = &chat_onReject;
|
|
|
|
ret.onEnd = &chat_onEnd;
|
2014-03-14 23:08:08 +01:00
|
|
|
ret.onRequestTimeout = &chat_onRequestTimeout;
|
|
|
|
ret.onPeerTimeout = &chat_onPeerTimeout;
|
2014-05-16 20:00:01 +02:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
ret.call_idx = -1;
|
|
|
|
ret.device_selection[0] = ret.device_selection[1] = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _AUDIO */
|
|
|
|
|
|
|
|
#ifdef _SOUND_NOTIFY
|
2014-07-21 01:12:13 +02:00
|
|
|
ret.active_sound = -1;
|
2014-07-21 03:25:21 +02:00
|
|
|
#endif /* _SOUND_NOTIFY */
|
2014-07-21 01:12:13 +02:00
|
|
|
|
2014-07-08 01:39:33 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2014-07-08 20:31:59 +02:00
|
|
|
int n_len = get_nick_truncate(m, nick, friendnum);
|
2014-07-08 01:39:33 +02:00
|
|
|
chat_set_window_name(&ret, nick, n_len);
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2013-09-13 08:02:49 +02:00
|
|
|
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
|
|
|
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-22 02:18:23 +02:00
|
|
|
exit_toxic_err("failed in new_chat", FATALERR_MEMORY);
|
2014-07-04 09:24:29 +02:00
|
|
|
|
|
|
|
ret.chatwin = chatwin;
|
|
|
|
ret.stb = stb;
|
|
|
|
ret.help = help;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2013-09-15 22:38:38 +02:00
|
|
|
ret.num = friendnum;
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
return ret;
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|