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>
|
2015-03-28 07:56:54 +01:00
|
|
|
#include <limits.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"
|
2015-03-28 07:56:54 +01:00
|
|
|
#include "file_transfers.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-09-06 19:18:42 +02:00
|
|
|
#include "message_queue.h"
|
2014-07-21 03:25:21 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2016-09-25 03:07:04 +02:00
|
|
|
#include "audio_call.h"
|
2015-11-12 11:01:28 +01:00
|
|
|
#ifdef VIDEO
|
2016-09-25 03:07:04 +02:00
|
|
|
#include "video_call.h"
|
2018-10-08 19:39:04 +02:00
|
|
|
#endif /* VIDEO */
|
|
|
|
#endif /* AUDIO */
|
2013-07-31 19:20:03 +02:00
|
|
|
|
2013-09-04 08:05:36 +02:00
|
|
|
extern char *DATA_FILE;
|
2014-09-28 23:49:48 +02:00
|
|
|
extern FriendsList Friends;
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
extern struct Winthread Winthread;
|
|
|
|
extern struct user_settings *user_settings;
|
2014-03-07 03:27:48 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-06-24 00:54:23 +02:00
|
|
|
static void init_infobox(ToxWindow *self);
|
|
|
|
static void kill_infobox(ToxWindow *self);
|
2018-10-08 19:39:04 +02:00
|
|
|
#endif /* AUDIO */
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2018-06-16 05:07:16 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
#define AC_NUM_CHAT_COMMANDS_AUDIO 9
|
2014-03-07 03:27:48 +01:00
|
|
|
#else
|
2018-06-16 05:07:16 +02:00
|
|
|
#define AC_NUM_CHAT_COMMANDS_AUDIO 0
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2018-06-16 05:07:16 +02:00
|
|
|
#ifdef PYTHON
|
|
|
|
#define AC_NUM_CHAT_COMMANDS_PYTHON 1
|
|
|
|
#else
|
|
|
|
#define AC_NUM_CHAT_COMMANDS_PYTHON 0
|
|
|
|
#endif /* PYTHON */
|
|
|
|
#ifdef QRCODE
|
|
|
|
#define AC_NUM_CHAT_COMMANDS_QRCODE 1
|
|
|
|
#else
|
|
|
|
#define AC_NUM_CHAT_COMMANDS_QRCODE 0
|
|
|
|
#endif /* QRCODE */
|
|
|
|
#define AC_NUM_CHAT_COMMANDS (21 + AC_NUM_CHAT_COMMANDS_AUDIO + AC_NUM_CHAT_COMMANDS_PYTHON + AC_NUM_CHAT_COMMANDS_QRCODE)
|
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" },
|
2014-09-26 09:10:44 +02:00
|
|
|
{ "/avatar" },
|
2014-08-04 07:56:43 +02:00
|
|
|
{ "/cancel" },
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/clear" },
|
|
|
|
{ "/close" },
|
|
|
|
{ "/connect" },
|
|
|
|
{ "/exit" },
|
2014-11-15 21:55:45 +01:00
|
|
|
{ "/group" },
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/help" },
|
|
|
|
{ "/invite" },
|
|
|
|
{ "/join" },
|
2014-02-27 01:00:13 +01:00
|
|
|
{ "/log" },
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/myid" },
|
2018-06-16 05:07:16 +02:00
|
|
|
#ifdef QRCODE
|
2015-11-09 04:51:46 +01:00
|
|
|
{ "/myqr" },
|
2018-06-16 05:07:16 +02:00
|
|
|
#endif /* QRCODE */
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/nick" },
|
|
|
|
{ "/note" },
|
2015-10-23 01:44:05 +02:00
|
|
|
{ "/nospam" },
|
2013-12-09 23:56:20 +01:00
|
|
|
{ "/quit" },
|
|
|
|
{ "/savefile" },
|
|
|
|
{ "/sendfile" },
|
|
|
|
{ "/status" },
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
{ "/call" },
|
|
|
|
{ "/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" },
|
2015-11-12 23:14:10 +01:00
|
|
|
{ "/video" },
|
2017-06-30 00:26:06 +02:00
|
|
|
{ "/bitrate" },
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2017-05-23 02:47:56 +02:00
|
|
|
|
|
|
|
#ifdef PYTHON
|
|
|
|
|
|
|
|
{ "/run" },
|
|
|
|
|
|
|
|
#endif /* PYTHON */
|
2013-12-09 23:56:20 +01:00
|
|
|
};
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void set_self_typingstatus(ToxWindow *self, Tox *m, bool is_typing)
|
2014-02-23 10:28:33 +01:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (user_settings->show_typing_self == SHOW_TYPING_OFF) {
|
2014-07-30 02:10:28 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-30 02:10:28 +02:00
|
|
|
|
2014-02-23 10:28:33 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_self_set_typing(m, self->num, is_typing, NULL);
|
2014-02-23 10:28:33 +01:00
|
|
|
ctx->self_is_typing = is_typing;
|
|
|
|
}
|
|
|
|
|
2014-08-05 23:38:33 +02:00
|
|
|
void kill_chat_window(ToxWindow *self, Tox *m)
|
2014-02-26 11:23:11 +01:00
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
StatusBar *statusbar = self->stb;
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2015-11-12 11:01:28 +01:00
|
|
|
#ifdef VIDEO
|
|
|
|
stop_video_stream(self);
|
2018-10-08 19:39:04 +02:00
|
|
|
#endif /* VIDEO */
|
2014-07-04 18:04:03 +02:00
|
|
|
stop_current_call(self);
|
2018-10-08 19:39:04 +02:00
|
|
|
#endif /* AUDIO */
|
2014-07-04 18:04:03 +02:00
|
|
|
|
2015-11-20 05:49:58 +01:00
|
|
|
kill_all_file_transfers_friend(m, self->num);
|
|
|
|
log_disable(ctx->log);
|
|
|
|
line_info_cleanup(ctx->hst);
|
|
|
|
cqueue_cleanup(ctx->cqueue);
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2020-03-15 19:57:00 +01:00
|
|
|
static void recv_message_helper(ToxWindow *self, const char *msg, const char *nick, const char *timefrmt)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2014-08-02 21:35:57 +02:00
|
|
|
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, 0, "%s", msg);
|
2014-03-04 01:21:52 +01:00
|
|
|
write_to_log(msg, nick, ctx->log, false);
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2018-07-18 17:56:21 +02:00
|
|
|
if (self->active_box != -1) {
|
2016-07-21 11:25:40 +02:00
|
|
|
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | user_settings->bell_on_message,
|
2016-09-25 03:07:04 +02:00
|
|
|
self->active_box, "%s", msg);
|
2018-07-18 17:56:21 +02:00
|
|
|
} else {
|
2016-07-21 11:25:40 +02:00
|
|
|
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | user_settings->bell_on_message,
|
2016-09-25 03:07:04 +02:00
|
|
|
&self->active_box, nick, "%s", msg);
|
2018-07-18 17:56:21 +02:00
|
|
|
}
|
2015-03-26 03:56:45 +01:00
|
|
|
}
|
|
|
|
|
2020-03-15 19:57:00 +01:00
|
|
|
static void recv_action_helper(ToxWindow *self, const char *action, const char *nick, const char *timefrmt)
|
2015-03-26 03:56:45 +01:00
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
|
|
|
line_info_add(self, timefrmt, nick, NULL, IN_ACTION, 0, 0, "%s", action);
|
|
|
|
write_to_log(action, nick, ctx->log, true);
|
|
|
|
|
2018-07-18 17:56:21 +02:00
|
|
|
if (self->active_box != -1) {
|
2016-07-21 11:25:40 +02:00
|
|
|
box_notify2(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | user_settings->bell_on_message,
|
2018-07-18 17:33:16 +02:00
|
|
|
self->active_box, "* %s %s", nick, action);
|
2018-07-18 17:56:21 +02:00
|
|
|
} else {
|
2016-07-21 11:25:40 +02:00
|
|
|
box_notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | user_settings->bell_on_message,
|
2018-07-18 17:33:16 +02:00
|
|
|
&self->active_box, self->name, "* %s %s", nick, action);
|
2018-07-18 17:56:21 +02:00
|
|
|
}
|
2015-03-26 03:56:45 +01:00
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
static void chat_onMessage(ToxWindow *self, Tox *m, uint32_t num, Tox_Message_Type type, const char *msg, size_t len)
|
2015-03-26 03:56:45 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(len);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->num != num) {
|
2015-03-26 03:56:45 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, nick, num);
|
|
|
|
|
|
|
|
char timefrmt[TIME_STR_SIZE];
|
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (type == TOX_MESSAGE_TYPE_NORMAL) {
|
2020-03-15 19:57:00 +01:00
|
|
|
recv_message_helper(self, msg, nick, timefrmt);
|
2018-09-08 19:23:07 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (type == TOX_MESSAGE_TYPE_ACTION) {
|
2020-03-15 19:57:00 +01:00
|
|
|
recv_action_helper(self, msg, nick, timefrmt);
|
2018-09-08 19:23:07 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|
|
|
|
|
2020-03-15 19:57:00 +01:00
|
|
|
static void chat_pause_file_transfers(uint32_t friendnum);
|
2015-08-10 20:22:13 +02:00
|
|
|
static void chat_resume_file_senders(ToxWindow *self, Tox *m, uint32_t fnum);
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
static void chat_onConnectionChange(ToxWindow *self, Tox *m, uint32_t num, Tox_Connection connection_status)
|
2013-09-05 03:25:59 +02:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->num != num) {
|
2013-09-05 03:25:59 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-05 03:25:59 +02:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
StatusBar *statusbar = self->stb;
|
2014-08-31 20:17:33 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
const char *msg;
|
|
|
|
|
|
|
|
char timefrmt[TIME_STR_SIZE];
|
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
|
|
|
|
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, nick, num);
|
2014-02-23 10:28:33 +01:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Connection prev_status = statusbar->connection;
|
2016-03-12 08:29:59 +01:00
|
|
|
statusbar->connection = connection_status;
|
|
|
|
|
2016-02-25 23:06:49 +01:00
|
|
|
if (user_settings->show_connection_msg == SHOW_WELCOME_MSG_OFF) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:50:28 +02:00
|
|
|
if (prev_status == TOX_CONNECTION_NONE) {
|
2015-08-10 20:22:13 +02:00
|
|
|
chat_resume_file_senders(self, m, num);
|
2014-08-31 20:17:33 +02:00
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
msg = "has come online";
|
2014-08-31 20:17:33 +02:00
|
|
|
line_info_add(self, timefrmt, nick, NULL, CONNECTION, 0, GREEN, msg);
|
|
|
|
write_to_log(msg, nick, ctx->log, true);
|
2015-04-01 03:56:11 +02:00
|
|
|
} else if (connection_status == TOX_CONNECTION_NONE) {
|
2015-03-26 03:56:45 +01:00
|
|
|
Friends.list[num].is_typing = false;
|
2014-07-30 02:10:28 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->chatwin->self_is_typing) {
|
2014-07-30 02:10:28 +02:00
|
|
|
set_self_typingstatus(self, m, 0);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2020-03-15 19:57:00 +01:00
|
|
|
chat_pause_file_transfers(num);
|
2014-08-31 20:17:33 +02:00
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
msg = "has gone offline";
|
2015-02-08 13:49:05 +01:00
|
|
|
line_info_add(self, timefrmt, nick, NULL, DISCONNECTION, 0, RED, msg);
|
2014-08-31 20:17:33 +02:00
|
|
|
write_to_log(msg, nick, ctx->log, true);
|
2014-02-23 10:28:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void chat_onTypingChange(ToxWindow *self, Tox *m, uint32_t num, bool is_typing)
|
2014-02-23 10:28:33 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->num != num) {
|
2014-02-23 10:28:33 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-02-23 10:28:33 +01:00
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[num].is_typing = is_typing;
|
2013-09-05 03:25:59 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void chat_onNickChange(ToxWindow *self, Tox *m, uint32_t num, const char *nick, size_t length)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->num != num) {
|
2013-08-16 19:11:09 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2014-07-08 01:08:33 +02:00
|
|
|
StatusBar *statusbar = self->stb;
|
|
|
|
|
2014-10-03 23:53:50 +02:00
|
|
|
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
2015-03-26 03:56:45 +01:00
|
|
|
length = strlen(statusbar->nick);
|
|
|
|
statusbar->nick_len = length;
|
2014-07-08 01:08:33 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
set_window_title(self, statusbar->nick, length);
|
2013-07-31 19:20:03 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
static void chat_onStatusChange(ToxWindow *self, Tox *m, uint32_t num, Tox_User_Status status)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->num != num) {
|
2013-08-16 19:11:09 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-08-16 19:11:09 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void chat_onStatusMessageChange(ToxWindow *self, uint32_t num, const char *status, size_t length)
|
2013-09-05 03:25:59 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(length);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->num != num) {
|
2013-09-05 03:25:59 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-05 03:25:59 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void chat_onReadReceipt(ToxWindow *self, Tox *m, uint32_t num, uint32_t receipt)
|
2014-09-07 08:43:53 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(num);
|
|
|
|
|
2014-09-11 07:36:33 +02:00
|
|
|
cqueue_remove(self, m, receipt);
|
2014-09-07 08:43:53 +02:00
|
|
|
}
|
|
|
|
|
2015-08-10 20:22:13 +02:00
|
|
|
/* Stops active file transfers for this friend. Called when a friend goes offline */
|
2020-03-15 19:57:00 +01:00
|
|
|
static void chat_pause_file_transfers(uint32_t friendnum)
|
2013-10-11 06:23:39 +02:00
|
|
|
{
|
2015-08-10 20:22:13 +02:00
|
|
|
ToxicFriend *friend = &Friends.list[friendnum];
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_FILES; ++i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (friend->file_sender[i].state >= FILE_TRANSFER_STARTED) {
|
2015-08-10 20:22:13 +02:00
|
|
|
friend->file_sender[i].state = FILE_TRANSFER_PAUSED;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (friend->file_receiver[i].state >= FILE_TRANSFER_STARTED) {
|
2015-08-10 20:22:13 +02:00
|
|
|
friend->file_receiver[i].state = FILE_TRANSFER_PAUSED;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
}
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2015-08-10 20:22:13 +02:00
|
|
|
/* Tries to resume broken file senders. Called when a friend comes online */
|
|
|
|
static void chat_resume_file_senders(ToxWindow *self, Tox *m, uint32_t friendnum)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2015-08-10 20:22:13 +02:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_FILES; ++i) {
|
|
|
|
struct FileTransfer *ft = &Friends.list[friendnum].file_sender[i];
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ft->state != FILE_TRANSFER_PAUSED) {
|
2015-08-10 20:22:13 +02:00
|
|
|
continue;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_File_Send err;
|
2015-08-10 20:22:13 +02:00
|
|
|
ft->filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, ft->file_size, ft->file_id,
|
|
|
|
(uint8_t *) ft->file_name, strlen(ft->file_name), &err);
|
|
|
|
|
|
|
|
if (err != TOX_ERR_FILE_SEND_OK) {
|
|
|
|
char msg[MAX_STR_SIZE];
|
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed.", ft->file_name);
|
2015-08-11 02:41:11 +02:00
|
|
|
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
|
2015-08-10 20:22:13 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
}
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
static void chat_onFileChunkRequest(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_t filenum, uint64_t position,
|
2015-03-28 07:56:54 +01:00
|
|
|
size_t length)
|
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (friendnum != self->num) {
|
2013-10-11 06:23:39 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
struct FileTransfer *ft = get_file_transfer_struct(friendnum, filenum);
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!ft) {
|
2014-06-22 02:18:23 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ft->state != FILE_TRANSFER_STARTED) {
|
2015-03-30 00:33:51 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-12 08:18:43 +01:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
char msg[MAX_STR_SIZE];
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
if (length == 0) {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "File '%s' successfully sent.", ft->file_name);
|
2015-03-30 00:33:51 +02:00
|
|
|
print_progress_bar(self, ft->bps, 100.0, ft->line_id);
|
|
|
|
close_file_transfer(self, m, ft, -1, msg, transfer_completed);
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
if (ft->file == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Null file pointer.", ft->file_name);
|
2015-03-30 00:33:51 +02:00
|
|
|
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-11-12 08:18:43 +01:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
if (ft->position != position) {
|
|
|
|
if (fseek(ft->file, position, SEEK_SET) == -1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Seek fail.", ft->file_name);
|
2015-03-30 00:33:51 +02:00
|
|
|
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
|
2013-11-12 08:18:43 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
ft->position = position;
|
2013-10-18 04:20:40 +02:00
|
|
|
}
|
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
uint8_t send_data[length];
|
2015-03-30 00:33:51 +02:00
|
|
|
size_t send_length = fread(send_data, 1, sizeof(send_data), ft->file);
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
if (send_length != length) {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Read fail.", ft->file_name);
|
2015-03-30 00:33:51 +02:00
|
|
|
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_File_Send_Chunk err;
|
2015-04-04 09:26:38 +02:00
|
|
|
tox_file_send_chunk(m, ft->friendnum, ft->filenum, position, send_data, send_length, &err);
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (err != TOX_ERR_FILE_SEND_CHUNK_OK) {
|
2015-07-04 07:19:16 +02:00
|
|
|
fprintf(stderr, "tox_file_send_chunk failed in chat callback (error %d)\n", err);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
ft->position += send_length;
|
|
|
|
ft->bps += send_length;
|
2015-08-18 21:12:48 +02:00
|
|
|
ft->last_keep_alive = get_unix_time();
|
2014-08-16 23:20:53 +02:00
|
|
|
}
|
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
static void chat_onFileRecvChunk(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_t filenum, uint64_t position,
|
2015-03-28 07:56:54 +01:00
|
|
|
const char *data, size_t length)
|
2014-08-16 23:20:53 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(position);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (friendnum != self->num) {
|
2014-08-16 23:20:53 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
struct FileTransfer *ft = get_file_transfer_struct(friendnum, filenum);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!ft) {
|
2015-03-30 00:33:51 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ft->state != FILE_TRANSFER_STARTED) {
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-05 09:31:12 +01:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
char msg[MAX_STR_SIZE];
|
2014-08-05 23:38:33 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
if (length == 0) {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "File '%s' successfully received.", ft->file_name);
|
2015-03-30 00:33:51 +02:00
|
|
|
print_progress_bar(self, ft->bps, 100.0, ft->line_id);
|
|
|
|
close_file_transfer(self, m, ft, -1, msg, transfer_completed);
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-08-05 23:38:33 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
if (ft->file == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Invalid file pointer.", ft->file_name);
|
2015-03-30 00:33:51 +02:00
|
|
|
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
2014-06-28 18:14:43 +02:00
|
|
|
}
|
2015-03-26 03:56:45 +01:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
if (fwrite(data, length, 1, ft->file) != 1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed: Write fail.", ft->file_name);
|
2015-03-30 00:33:51 +02:00
|
|
|
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
2015-03-26 03:56:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
ft->bps += length;
|
|
|
|
ft->position += length;
|
2015-08-18 21:12:48 +02:00
|
|
|
ft->last_keep_alive = get_unix_time();
|
2015-03-26 03:56:45 +01:00
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
static void chat_onFileControl(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_t filenum, Tox_File_Control control)
|
2013-10-11 06:23:39 +02:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (friendnum != self->num) {
|
2013-10-11 06:23:39 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
struct FileTransfer *ft = get_file_transfer_struct(friendnum, filenum);
|
2014-08-20 19:10:21 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!ft) {
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
char msg[MAX_STR_SIZE];
|
2014-08-12 21:27:42 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
switch (control) {
|
2015-08-18 21:12:48 +02:00
|
|
|
case TOX_FILE_CONTROL_RESUME: {
|
|
|
|
ft->last_keep_alive = get_unix_time();
|
|
|
|
|
2014-12-05 19:23:45 +01:00
|
|
|
/* transfer is accepted */
|
2015-03-30 00:33:51 +02:00
|
|
|
if (ft->state == FILE_TRANSFER_PENDING) {
|
|
|
|
ft->state = FILE_TRANSFER_STARTED;
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer [%d] for '%s' accepted.",
|
2016-09-25 03:07:04 +02:00
|
|
|
ft->index, ft->file_name);
|
2014-07-27 23:14:28 +02:00
|
|
|
char progline[MAX_STR_SIZE];
|
2015-08-18 21:12:48 +02:00
|
|
|
init_progress_bar(progline);
|
2014-08-02 21:35:57 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", progline);
|
2016-07-21 11:25:40 +02:00
|
|
|
sound_notify(self, silent, NT_NOFOCUS | user_settings->bell_on_filetrans_accept | NT_WNDALERT_2, NULL);
|
2015-03-30 00:33:51 +02:00
|
|
|
ft->line_id = self->chatwin->hst->line_end->id + 2;
|
2015-04-04 09:26:38 +02:00
|
|
|
} else if (ft->state == FILE_TRANSFER_PAUSED) { /* transfer is resumed */
|
2015-03-30 00:33:51 +02:00
|
|
|
ft->state = FILE_TRANSFER_STARTED;
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
2015-08-18 21:12:48 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-08-18 21:12:48 +02:00
|
|
|
case TOX_FILE_CONTROL_PAUSE: {
|
2015-04-04 09:26:38 +02:00
|
|
|
ft->state = FILE_TRANSFER_PAUSED;
|
2014-12-05 19:23:45 +01:00
|
|
|
break;
|
2015-08-18 21:12:48 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-08-18 21:12:48 +02:00
|
|
|
case TOX_FILE_CONTROL_CANCEL: {
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' was aborted.", ft->file_name);
|
2015-03-30 00:33:51 +02:00
|
|
|
close_file_transfer(self, m, ft, -1, msg, notif_error);
|
2015-03-28 07:56:54 +01:00
|
|
|
break;
|
2015-08-18 21:12:48 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
}
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-08-10 20:22:13 +02:00
|
|
|
/* Attempts to resume a broken inbound file transfer.
|
|
|
|
*
|
|
|
|
* Returns true if resume is successful.
|
|
|
|
*/
|
|
|
|
static bool chat_resume_broken_ft(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_t filenum)
|
|
|
|
{
|
|
|
|
char msg[MAX_STR_SIZE];
|
|
|
|
uint8_t file_id[TOX_FILE_ID_LENGTH];
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!tox_file_get_file_id(m, friendnum, filenum, file_id, NULL)) {
|
2015-08-10 20:22:13 +02:00
|
|
|
return false;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
|
|
|
|
bool resuming = false;
|
|
|
|
struct FileTransfer *ft = NULL;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_FILES; ++i) {
|
|
|
|
ft = &Friends.list[friendnum].file_receiver[i];
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ft->state == FILE_TRANSFER_INACTIVE) {
|
2015-08-10 20:22:13 +02:00
|
|
|
continue;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
|
|
|
|
if (memcmp(ft->file_id, file_id, TOX_FILE_ID_LENGTH) == 0) {
|
|
|
|
ft->filenum = filenum;
|
2015-08-18 21:12:48 +02:00
|
|
|
ft->state = FILE_TRANSFER_STARTED;
|
|
|
|
ft->last_keep_alive = get_unix_time();
|
2015-08-10 20:22:13 +02:00
|
|
|
resuming = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!resuming || !ft) {
|
2015-08-10 20:22:13 +02:00
|
|
|
return false;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!tox_file_seek(m, ft->friendnum, ft->filenum, ft->position, NULL)) {
|
2015-08-10 20:22:13 +02:00
|
|
|
goto on_error;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!tox_file_control(m, ft->friendnum, ft->filenum, TOX_FILE_CONTROL_RESUME, NULL)) {
|
2015-08-10 20:22:13 +02:00
|
|
|
goto on_error;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
on_error:
|
|
|
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed.", ft->file_name);
|
2015-08-11 02:41:11 +02:00
|
|
|
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, notif_error);
|
2015-08-10 20:22:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_t filenum, uint64_t file_size,
|
|
|
|
const char *filename, size_t name_length)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->num != friendnum) {
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-04 22:22:29 +02:00
|
|
|
|
2015-08-10 20:22:13 +02:00
|
|
|
/* first check if we need to resume a broken transfer */
|
2018-07-18 17:33:16 +02:00
|
|
|
if (chat_resume_broken_ft(self, m, friendnum, filenum)) {
|
2015-08-10 20:22:13 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 20:22:13 +02:00
|
|
|
|
2015-08-18 21:12:48 +02:00
|
|
|
struct FileTransfer *ft = new_file_transfer(self, friendnum, filenum, FILE_TRANSFER_RECV, TOX_FILE_KIND_DATA);
|
2014-08-04 22:22:29 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
if (!ft) {
|
|
|
|
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL);
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer failed: Too many concurrent file transfers.");
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-09-06 19:18:42 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
char sizestr[32];
|
|
|
|
bytes_convert_str(sizestr, sizeof(sizestr), file_size);
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer request for '%s' (%s)", filename, sizestr);
|
2014-06-22 02:18:23 +02:00
|
|
|
|
2017-09-01 23:36:17 +02:00
|
|
|
char file_path[PATH_MAX + name_length + 1];
|
2015-03-28 07:56:54 +01:00
|
|
|
size_t path_len = name_length;
|
2014-08-04 22:22:29 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
/* use specified download path in config if possible */
|
|
|
|
if (!string_is_empty(user_settings->download_path)) {
|
|
|
|
snprintf(file_path, sizeof(file_path), "%s%s", user_settings->download_path, filename);
|
|
|
|
path_len += strlen(user_settings->download_path);
|
|
|
|
} else {
|
|
|
|
snprintf(file_path, sizeof(file_path), "%s", filename);
|
|
|
|
}
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2015-08-27 09:38:08 +02:00
|
|
|
if (path_len >= sizeof(file_path) || path_len >= sizeof(ft->file_path) || name_length >= sizeof(ft->file_name)) {
|
2015-03-30 00:33:51 +02:00
|
|
|
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL);
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer faield: File path too long.");
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
/* Append a number to duplicate file names */
|
|
|
|
FILE *filecheck = NULL;
|
|
|
|
int count = 1;
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
while ((filecheck = fopen(file_path, "r"))) {
|
|
|
|
fclose(filecheck);
|
|
|
|
file_path[path_len] = '\0';
|
|
|
|
char d[9];
|
|
|
|
sprintf(d, "(%d)", count);
|
|
|
|
++count;
|
|
|
|
size_t d_len = strlen(d);
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
if (path_len + d_len >= sizeof(file_path)) {
|
|
|
|
path_len -= d_len;
|
|
|
|
file_path[path_len] = '\0';
|
|
|
|
}
|
2014-08-16 23:20:53 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
strcat(file_path, d);
|
|
|
|
file_path[path_len + d_len] = '\0';
|
2014-09-24 04:51:56 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
if (count > 999) {
|
2015-03-30 00:33:51 +02:00
|
|
|
tox_file_control(m, friendnum, filenum, TOX_FILE_CONTROL_CANCEL, NULL);
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer failed: invalid file path.");
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-10-11 06:23:39 +02:00
|
|
|
}
|
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type '/savefile %d' to accept the file transfer.", ft->index);
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
ft->file_size = file_size;
|
|
|
|
snprintf(ft->file_path, sizeof(ft->file_path), "%s", file_path);
|
|
|
|
snprintf(ft->file_name, sizeof(ft->file_name), "%s", filename);
|
2015-08-10 20:22:13 +02:00
|
|
|
tox_file_get_file_id(m, friendnum, filenum, ft->file_id, NULL);
|
2014-03-28 04:05:50 +01:00
|
|
|
|
2018-07-18 17:56:21 +02:00
|
|
|
if (self->active_box != -1) {
|
2016-07-21 11:25:40 +02:00
|
|
|
box_notify2(self, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS | user_settings->bell_on_filetrans,
|
2018-07-18 17:33:16 +02:00
|
|
|
self->active_box, "Incoming file: %s", filename);
|
2018-07-18 17:56:21 +02:00
|
|
|
} else {
|
2016-07-21 11:25:40 +02:00
|
|
|
box_notify(self, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS | user_settings->bell_on_filetrans,
|
2018-07-18 17:33:16 +02:00
|
|
|
&self->active_box, self->name, "Incoming file: %s", filename);
|
2018-07-18 17:56:21 +02:00
|
|
|
}
|
2013-10-11 06:23:39 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 00:30:23 +01:00
|
|
|
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t type, const char *group_pub_key,
|
2015-03-28 07:56:54 +01:00
|
|
|
uint16_t length)
|
2013-10-14 01:09:20 +02:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->num != friendnumber) {
|
2013-10-14 01:09:20 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-10-14 01:09:20 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[friendnumber].group_invite.key != NULL) {
|
2014-09-28 04:50:20 +02:00
|
|
|
free(Friends.list[friendnumber].group_invite.key);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-01 08:48:37 +02:00
|
|
|
|
2014-09-28 04:50:20 +02:00
|
|
|
char *k = malloc(length);
|
2014-07-02 19:46:57 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (k == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
exit_toxic_err("Failed in chat_onGroupInvite", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-28 04:50:20 +02:00
|
|
|
|
|
|
|
memcpy(k, group_pub_key, length);
|
|
|
|
Friends.list[friendnumber].group_invite.key = k;
|
|
|
|
Friends.list[friendnumber].group_invite.pending = true;
|
|
|
|
Friends.list[friendnumber].group_invite.length = length;
|
2014-11-12 02:49:05 +01:00
|
|
|
Friends.list[friendnumber].group_invite.type = type;
|
2014-09-28 04:50:20 +02:00
|
|
|
|
2016-07-21 11:25:40 +02:00
|
|
|
sound_notify(self, generic_message, NT_WNDALERT_2 | user_settings->bell_on_invite, NULL);
|
2014-09-28 04:50:20 +02:00
|
|
|
|
2014-11-12 02:49:05 +01:00
|
|
|
char name[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, name, friendnumber);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->active_box != -1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
box_silent_notify2(self, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box, "invites you to join group chat");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2015-07-04 07:19:16 +02:00
|
|
|
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join group chat");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-28 04:50:20 +02:00
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s has invited you to a group chat.", name);
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/join\" to join the chat.");
|
2013-08-04 10:42:17 +02:00
|
|
|
}
|
2013-08-03 16:00:48 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
/* AV Stuff */
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onInvite(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
/* call is flagged active here */
|
|
|
|
self->is_call = true;
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Incoming audio call! Type: \"/answer\" or \"/reject\"");
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->ringing_sound == -1) {
|
2016-07-21 11:25:40 +02:00
|
|
|
sound_notify(self, call_incoming, NT_LOOP | user_settings->bell_on_invite, &self->ringing_sound);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->active_box != -1) {
|
2015-07-04 07:19:16 +02:00
|
|
|
box_silent_notify2(self, NT_NOFOCUS | NT_WNDALERT_0, self->active_box, "Incoming audio call!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2015-07-04 07:19:16 +02:00
|
|
|
box_silent_notify(self, NT_NOFOCUS | NT_WNDALERT_0, &self->active_box, self->name, "Incoming audio call!");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onRinging(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Ringing...type \"/hangup\" to cancel it.");
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->ringing_sound == -1) {
|
2014-08-02 00:37:02 +02:00
|
|
|
sound_notify(self, call_outgoing, NT_LOOP, &self->ringing_sound);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onStarting(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
init_infobox(self);
|
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
/* call is flagged active here */
|
|
|
|
self->is_call = true;
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2014-08-02 00:37:02 +02:00
|
|
|
stop_sound(self->ringing_sound);
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onEnding(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
kill_infobox(self);
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call ended!");
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
self->is_call = false;
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2014-08-02 00:37:02 +02:00
|
|
|
stop_sound(self->ringing_sound);
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onError(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
self->is_call = false;
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error!");
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2014-08-02 00:37:02 +02:00
|
|
|
stop_sound(self->ringing_sound);
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onStart(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
/* call is flagged active here */
|
|
|
|
self->is_call = true;
|
2014-06-24 00:54:23 +02:00
|
|
|
|
|
|
|
init_infobox(self);
|
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2014-08-02 00:37:02 +02:00
|
|
|
stop_sound(self->ringing_sound);
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onCancel(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
self->is_call = false;
|
2014-06-24 04:02:22 +02:00
|
|
|
kill_infobox(self);
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call canceled!");
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2014-08-02 00:37:02 +02:00
|
|
|
stop_sound(self->ringing_sound);
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onReject(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Rejected!");
|
2015-08-10 13:14:38 +02:00
|
|
|
self->is_call = false;
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2014-08-02 00:37:02 +02:00
|
|
|
stop_sound(self->ringing_sound);
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
void chat_onEnd(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(state);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || self->num != friend_number) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
kill_infobox(self);
|
2015-07-04 07:19:16 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call ended!");
|
2015-08-10 13:14:38 +02:00
|
|
|
self->is_call = false;
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2014-08-02 00:37:02 +02:00
|
|
|
stop_sound(self->ringing_sound);
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* SOUND_NOTIFY */
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
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);
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
2015-11-08 09:57:01 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2020-03-30 18:56:42 +02:00
|
|
|
UNUSED_VAR(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-09-23 03:24:45 +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
|
|
|
}
|
|
|
|
|
|
|
|
static void kill_infobox(ToxWindow *self)
|
|
|
|
{
|
2014-06-24 07:54:08 +02:00
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!ctx->infobox.win) {
|
2014-06-24 00:54:23 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-06-24 00:54:23 +02:00
|
|
|
|
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
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (infobox->win == NULL) {
|
2014-06-24 00:54:23 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-06-24 00:54:23 +02:00
|
|
|
|
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (x2 < INFOBOX_WIDTH || y2 < INFOBOX_HEIGHT) {
|
2014-06-24 00:54:23 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2016-09-23 00:31:52 +02:00
|
|
|
time_t curtime = get_unix_time();
|
2014-06-24 00:54:23 +02:00
|
|
|
|
|
|
|
/* update elapsed time string once per second */
|
2018-07-18 17:33:16 +02:00
|
|
|
if (curtime > infobox->lastupdate) {
|
2014-06-24 07:54:08 +02:00
|
|
|
get_elapsed_time_str(infobox->timestr, sizeof(infobox->timestr), curtime - infobox->starttime);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
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
|
|
|
|
2015-07-04 07:19:16 +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);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(infobox->win, " Call Active\n");
|
2014-06-24 07:54:08 +02:00
|
|
|
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);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(infobox->win, " Duration: ");
|
2014-06-24 07:54:08 +02:00
|
|
|
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);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(infobox->win, " In muted: ");
|
2014-06-24 07:54:08 +02:00
|
|
|
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);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(infobox->win, " Out muted: ");
|
2014-06-24 07:54:08 +02:00
|
|
|
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);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(infobox->win, " VAD level: ");
|
2014-06-24 07:54:08 +02:00
|
|
|
wattroff(infobox->win, A_BOLD);
|
2018-09-14 01:47:47 +02:00
|
|
|
wprintw(infobox->win, "%.2f\n", (double) 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, ' ');
|
2016-07-27 02:39:31 +02:00
|
|
|
wnoutrefresh(infobox->win);
|
2014-06-24 00:54:23 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 03:24:45 +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
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (action == NULL) {
|
2013-09-19 12:37:42 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-02 07:14:51 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char selfname[TOX_MAX_NAME_LENGTH];
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_self_get_name(m, (uint8_t *) selfname);
|
|
|
|
|
|
|
|
size_t len = tox_self_get_name_size(m);
|
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
|
|
|
|
2017-06-01 22:46:12 +02:00
|
|
|
int id = line_info_add(self, timefrmt, selfname, NULL, OUT_ACTION, 0, 0, "%s", action);
|
|
|
|
cqueue_add(ctx->cqueue, action, strlen(action), OUT_ACTION, id);
|
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
|
|
|
|
2020-03-30 18:56:42 +02:00
|
|
|
UNUSED_VAR(y);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
2014-03-24 12:18:58 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->pastemode && key == '\r') {
|
2016-01-17 15:10:46 +01:00
|
|
|
key = '\n';
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-01-17 15:10:46 +01:00
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
if (self->help->active) {
|
|
|
|
help_onKey(self, key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
if (ltr || key == '\n') { /* char is printable */
|
2020-03-15 19:57:00 +01:00
|
|
|
input_new_char(self, key, x, x2);
|
2013-12-01 22:57:05 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->line[0] != '/' && !ctx->self_is_typing && statusbar->connection != TOX_CONNECTION_NONE) {
|
2014-07-30 02:10:28 +02:00
|
|
|
set_self_typingstatus(self, m, 1);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
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
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (line_info_onKey(self, key)) {
|
2014-06-26 08:33:09 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-01 04:12:43 +01:00
|
|
|
|
2020-03-15 19:57:00 +01:00
|
|
|
input_handle(self, key, x, x2);
|
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;
|
|
|
|
|
2014-09-26 09:10:44 +02:00
|
|
|
/* TODO: make this not suck */
|
2018-10-08 06:47:51 +02:00
|
|
|
if (wcsncmp(ctx->line, L"/sendfile ", wcslen(L"/sendfile ")) == 0) {
|
2014-09-26 09:10:44 +02:00
|
|
|
diff = dir_match(self, m, ctx->line, L"/sendfile");
|
2018-10-08 06:47:51 +02:00
|
|
|
} else if (wcsncmp(ctx->line, L"/avatar ", wcslen(L"/avatar ")) == 0) {
|
2014-09-26 09:10:44 +02:00
|
|
|
diff = dir_match(self, m, ctx->line, L"/avatar");
|
2017-05-23 02:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PYTHON
|
2018-10-08 06:47:51 +02:00
|
|
|
else if (wcsncmp(ctx->line, L"/run ", wcslen(L"/run ")) == 0) {
|
2017-05-23 02:47:56 +02:00
|
|
|
diff = dir_match(self, m, ctx->line, L"/run");
|
|
|
|
}
|
2017-06-01 22:46:12 +02:00
|
|
|
|
2017-05-23 02:47:56 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
else if (wcsncmp(ctx->line, L"/status ", wcslen(L"/status ")) == 0) {
|
2015-03-17 20:25:15 +01:00
|
|
|
const char status_cmd_list[3][8] = {
|
2016-09-25 03:07:04 +02:00
|
|
|
{"online"},
|
|
|
|
{"away"},
|
|
|
|
{"busy"},
|
2015-03-17 20:25:15 +01:00
|
|
|
};
|
|
|
|
diff = complete_line(self, status_cmd_list, 3, 8);
|
2014-07-18 07:29:46 +02:00
|
|
|
} 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) {
|
2015-08-27 09:38:08 +02:00
|
|
|
int wlen = MAX(0, wcswidth(ctx->line, sizeof(ctx->line) / sizeof(wchar_t)));
|
2014-07-18 18:42:53 +02:00
|
|
|
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
|
|
|
|
}
|
2014-07-18 07:29:46 +02:00
|
|
|
} else {
|
2015-03-26 03:56:45 +01:00
|
|
|
sound_notify(self, notif_error, 0, NULL);
|
2014-07-18 07:29:46 +02:00
|
|
|
}
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
} else if (key == '\r') {
|
2014-06-26 08:33:09 +02:00
|
|
|
rm_trailing_spaces_buf(ctx);
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
if (!wstring_is_empty(ctx->line)) {
|
2015-12-04 20:15:31 +01:00
|
|
|
add_line_to_hist(ctx);
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
wstrsubst(ctx->line, L'¶', L'\n');
|
2013-12-01 04:12:43 +01:00
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
char line[MAX_STR_SIZE] = {0};
|
2014-02-23 10:28:33 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
|
2015-12-04 20:15:31 +01:00
|
|
|
memset(&line, 0, sizeof(line));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-12-04 20:15:31 +01:00
|
|
|
|
|
|
|
if (line[0] == '/') {
|
|
|
|
if (strcmp(line, "/close") == 0) {
|
|
|
|
kill_chat_window(self, m);
|
|
|
|
return;
|
|
|
|
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
|
|
|
|
send_action(self, ctx, m, line + strlen("/me "));
|
|
|
|
} else {
|
|
|
|
execute(ctx->history, self, m, line, CHAT_COMMAND_MODE);
|
|
|
|
}
|
2014-03-30 22:40:13 +02:00
|
|
|
} else {
|
2015-12-04 20:15:31 +01:00
|
|
|
char selfname[TOX_MAX_NAME_LENGTH];
|
|
|
|
tox_self_get_name(m, (uint8_t *) selfname);
|
2015-03-26 03:56:45 +01:00
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
size_t len = tox_self_get_name_size(m);
|
|
|
|
selfname[len] = '\0';
|
2013-10-23 09:24:08 +02:00
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
char timefrmt[TIME_STR_SIZE];
|
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2017-06-01 22:46:12 +02:00
|
|
|
int id = line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, "%s", line);
|
|
|
|
cqueue_add(ctx->cqueue, line, strlen(line), OUT_MSG, id);
|
2015-12-04 20:15:31 +01: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
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->len <= 0 && ctx->self_is_typing) {
|
2014-07-30 02:10:28 +02:00
|
|
|
set_self_typingstatus(self, m, 0);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
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
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
2015-11-08 09:57:01 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-09-10 10:04:13 +02:00
|
|
|
|
2015-07-01 04:40:45 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_print(self);
|
2015-07-01 04:40:45 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
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
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->len > 0) {
|
2014-06-26 08:33:09 +02:00
|
|
|
mvwprintw(ctx->linewin, 1, 0, "%ls", &ctx->line[ctx->start]);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
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 */
|
2015-03-26 03:56:45 +01:00
|
|
|
if (statusbar->connection != TOX_CONNECTION_NONE) {
|
|
|
|
int colour = MAGENTA;
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_User_Status status = statusbar->status;
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2013-11-12 07:50:04 +01:00
|
|
|
switch (status) {
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_USER_STATUS_NONE:
|
2014-04-19 23:58:13 +02:00
|
|
|
colour = GREEN;
|
|
|
|
break;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_USER_STATUS_AWAY:
|
2014-04-19 23:58:13 +02:00
|
|
|
colour = YELLOW;
|
|
|
|
break;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_USER_STATUS_BUSY:
|
2014-04-19 23:58:13 +02:00
|
|
|
colour = RED;
|
|
|
|
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-07-27 01:16:07 +02:00
|
|
|
wprintw(statusbar->topline, " %s", ONLINE_CHAR);
|
2014-03-15 12:40:13 +01:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[self->num].is_typing) {
|
2014-02-23 10:28:33 +01:00
|
|
|
wattron(statusbar->topline, COLOR_PAIR(YELLOW));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-02-23 10:28:33 +01:00
|
|
|
|
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
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[self->num].is_typing) {
|
2014-02-23 10:28:33 +01:00
|
|
|
wattroff(statusbar->topline, COLOR_PAIR(YELLOW));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-06 00:24:58 +02:00
|
|
|
} else {
|
2014-07-27 01:16:07 +02:00
|
|
|
wprintw(statusbar->topline, " %s", OFFLINE_CHAR);
|
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) {
|
2015-03-26 03:56:45 +01:00
|
|
|
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH] = {'\0'};
|
2014-03-13 11:06:53 +01:00
|
|
|
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_friend_get_status_message(m, self->num, (uint8_t *) statusmsg, NULL);
|
|
|
|
size_t s_len = tox_friend_get_status_message_size(m, self->num, NULL);
|
2014-03-13 11:06:53 +01:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-04-01 04:00:17 +02:00
|
|
|
|
2014-10-07 22:18:06 +02:00
|
|
|
filter_str(statusmsg, s_len);
|
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 */
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 6;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2013-09-10 10:04:13 +02:00
|
|
|
if (statusbar->statusmsg_len > maxlen) {
|
2014-08-10 06:29:18 +02:00
|
|
|
statusbar->statusmsg[maxlen - 3] = '\0';
|
|
|
|
strcat(statusbar->statusmsg, "...");
|
2013-09-10 10:04:13 +02:00
|
|
|
statusbar->statusmsg_len = maxlen;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (statusbar->statusmsg[0]) {
|
2014-09-25 10:31:45 +02:00
|
|
|
wprintw(statusbar->topline, ": %s ", statusbar->statusmsg);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
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, "{");
|
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
size_t i;
|
2014-02-22 23:58:36 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
for (i = 0; i < KEY_IDENT_DIGITS; ++i) {
|
2014-08-07 19:05:42 +02:00
|
|
|
wprintw(statusbar->topline, "%02X", Friends.list[self->num].pub_key[i] & 0xff);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-02-22 23:58:36 +01:00
|
|
|
|
|
|
|
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);
|
2020-03-30 18:56:42 +02:00
|
|
|
|
|
|
|
UNUSED_VAR(x);
|
|
|
|
|
2015-08-27 09:38:08 +02:00
|
|
|
int new_x = ctx->start ? x2 - 1 : MAX(0, 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
|
|
|
|
2016-07-27 02:39:31 +02:00
|
|
|
wnoutrefresh(self->window);
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2016-09-25 03:07:04 +02:00
|
|
|
|
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
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
#endif
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->help->active) {
|
2014-07-04 09:24:29 +02:00
|
|
|
help_onDraw(self);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2020-03-15 19:57:00 +01:00
|
|
|
refresh_file_transfer_progress(self, self->num);
|
2015-03-28 07:56:54 +01:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
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);
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
2015-11-08 09:57:01 +01:00
|
|
|
exit_toxic_err("failed in chat_onInit", FATALERR_CURSES);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2013-12-12 06:37:29 +01:00
|
|
|
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;
|
2018-02-25 06:00:06 +01:00
|
|
|
statusbar->status = get_friend_status(self->num);
|
|
|
|
statusbar->connection = get_friend_connection_status(self->num);
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
|
|
|
tox_friend_get_status_message(m, self->num, (uint8_t *) statusmsg, NULL);
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t s_len = tox_friend_get_status_message_size(m, self->num, NULL);
|
2014-04-01 04:00:17 +02:00
|
|
|
statusmsg[s_len] = '\0';
|
2014-10-07 22:18:06 +02:00
|
|
|
|
|
|
|
filter_str(statusmsg, s_len);
|
2013-09-08 09:18:34 +02:00
|
|
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
2014-10-07 22:18:06 +02:00
|
|
|
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
2013-09-06 00:24:58 +02:00
|
|
|
|
2014-10-03 23:53:50 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH + 1];
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t 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-09-06 19:18:42 +02:00
|
|
|
ctx->cqueue = calloc(1, sizeof(struct chat_queue));
|
2014-03-01 13:10:44 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->log == NULL || ctx->hst == NULL || ctx->cqueue == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
exit_toxic_err("failed in chat_onInit", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-01 13:10:44 +01:00
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
line_info_init(ctx->hst);
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
char myid[TOX_ADDRESS_SIZE];
|
|
|
|
tox_self_get_address(m, (uint8_t *) myid);
|
2014-09-22 23:09:39 +02:00
|
|
|
|
2015-08-19 06:42:28 +02:00
|
|
|
int log_ret = log_enable(nick, myid, Friends.list[self->num].pub_key, ctx->log, LOG_CHAT);
|
2014-09-22 10:29:28 +02:00
|
|
|
load_chat_history(self, ctx->log);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!Friends.list[self->num].logging_on) {
|
2014-09-22 10:29:28 +02:00
|
|
|
log_disable(ctx->log);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (log_ret == -1) {
|
2015-08-19 06:42:28 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ToxWindow *new_chat(Tox *m, uint32_t friendnum)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2018-10-10 00:59:25 +02:00
|
|
|
ToxWindow *ret = calloc(1, sizeof(ToxWindow));
|
|
|
|
|
|
|
|
if (ret == NULL) {
|
|
|
|
exit_toxic_err("failed in new_chat", FATALERR_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->is_chat = true;
|
|
|
|
|
|
|
|
ret->onKey = &chat_onKey;
|
|
|
|
ret->onDraw = &chat_onDraw;
|
|
|
|
ret->onInit = &chat_onInit;
|
|
|
|
ret->onMessage = &chat_onMessage;
|
|
|
|
ret->onConnectionChange = &chat_onConnectionChange;
|
|
|
|
ret->onTypingChange = & chat_onTypingChange;
|
|
|
|
ret->onGroupInvite = &chat_onGroupInvite;
|
|
|
|
ret->onNickChange = &chat_onNickChange;
|
|
|
|
ret->onStatusChange = &chat_onStatusChange;
|
|
|
|
ret->onStatusMessageChange = &chat_onStatusMessageChange;
|
|
|
|
ret->onFileChunkRequest = &chat_onFileChunkRequest;
|
|
|
|
ret->onFileRecvChunk = &chat_onFileRecvChunk;
|
|
|
|
ret->onFileControl = &chat_onFileControl;
|
|
|
|
ret->onFileRecv = &chat_onFileRecv;
|
|
|
|
ret->onReadReceipt = &chat_onReadReceipt;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2018-10-10 00:59:25 +02: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;
|
|
|
|
|
|
|
|
ret->is_call = false;
|
|
|
|
ret->device_selection[0] = ret->device_selection[1] = -1;
|
|
|
|
ret->ringing_sound = -1;
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->active_box = -1;
|
2015-03-17 20:25:15 +01:00
|
|
|
|
2014-07-08 01:39:33 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t n_len = get_nick_truncate(m, nick, friendnum);
|
2018-10-10 00:59:25 +02:00
|
|
|
set_window_title(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
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (stb == NULL || chatwin == NULL || help == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
exit_toxic_err("failed in new_chat", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-04 09:24:29 +02:00
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->chatwin = chatwin;
|
|
|
|
ret->stb = stb;
|
|
|
|
ret->help = help;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2018-10-10 00:59:25 +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
|
|
|
}
|