diff --git a/src/chat.c b/src/chat.c index a4c771d..a4a8362 100644 --- a/src/chat.c +++ b/src/chat.c @@ -448,19 +448,31 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec switch (control_type) { case TOX_FILECONTROL_ACCEPT: - if (receive_send == 1 && file_senders[send_idx].last_progress == 0) { + if (receive_send != 1) + break; + + /* transfer is accepted */ + if (!file_senders[send_idx].started) { + file_senders[send_idx].started = true; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer [%d] for '%s' accepted.", filenum, filename); - /* prep progress bar line */ char progline[MAX_STR_SIZE]; prep_prog_line(progline); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", progline); file_senders[send_idx].line_id = self->chatwin->hst->line_end->id + 2; sound_notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2, NULL); + } else { /* active transfer is paused by receiver */ + file_senders[send_idx].paused = false; } break; + case TOX_FILECONTROL_PAUSE: + if (receive_send == 1) + file_senders[send_idx].paused = true; + + break; + case TOX_FILECONTROL_KILL: snprintf(msg, sizeof(msg), "File transfer for '%s' failed.", filename); diff --git a/src/chat_commands.c b/src/chat_commands.c index b759900..9dfa462 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -264,6 +264,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv if (!file_senders[i].active) { memcpy(file_senders[i].filename, filename, namelen + 1); file_senders[i].active = true; + file_senders[i].started = false; file_senders[i].toxwin = self; file_senders[i].file = file_to_send; file_senders[i].filenum = filenum; diff --git a/src/device.c b/src/device.c index 3842df2..a54c7f3 100644 --- a/src/device.c +++ b/src/device.c @@ -359,8 +359,6 @@ inline__ DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_ if (device_idx >= MAX_DEVICES) return de_InvalidSelection; Device* device = running[output][device_idx]; - if (!device) - fprintf(stderr, "DEVICE IS NULL SILLY\n"); if (!device || device->muted) return de_DeviceNotActive; diff --git a/src/file_senders.c b/src/file_senders.c index f75e8b1..81f2177 100644 --- a/src/file_senders.c +++ b/src/file_senders.c @@ -266,7 +266,8 @@ void do_file_senders(Tox *m) } /* If file transfer has timed out kill transfer and send kill control */ - if (timed_out(file_senders[i].timestamp, get_unix_time(), TIMEOUT_FILESENDER)) { + if (timed_out(file_senders[i].timestamp, get_unix_time(), TIMEOUT_FILESENDER) + && (!file_senders[i].paused || (file_senders[i].paused && file_senders[i].noconnection))) { char msg[MAX_STR_SIZE]; snprintf(msg, sizeof(msg), "File transfer for '%s' timed out.", filename); close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, friendnum); @@ -279,7 +280,7 @@ void do_file_senders(Tox *m) continue; } - if (!file_senders[i].noconnection && !file_senders[i].finished) + if ( !(file_senders[i].paused | file_senders[i].noconnection | file_senders[i].finished) ) send_file_data(self, m, i, friendnum, filenum, filename); file_senders[i].queue_pos = num_active_file_senders - 1; diff --git a/src/file_senders.h b/src/file_senders.h index 479d855..99c51e2 100644 --- a/src/file_senders.h +++ b/src/file_senders.h @@ -32,7 +32,7 @@ #define FILE_PIECE_SIZE 2048 /* must be >= (MAX_CRYPTO_DATA_SIZE - 2) in toxcore/net_crypto.h */ #define MAX_FILES 32 -#define TIMEOUT_FILESENDER 120 +#define TIMEOUT_FILESENDER 10 #define NUM_PROG_MARKS 50 /* number of "#"'s in file transfer progress bar. Keep well below MAX_STR_SIZE */ typedef struct { @@ -40,14 +40,16 @@ typedef struct { ToxWindow *toxwin; int32_t friendnum; bool active; - bool noconnection; - bool finished; + bool noconnection; /* set when the connection has been interrupted */ + bool paused; /* set when transfer has been explicitly paused */ + bool finished; /* set after entire file has been sent but no TOX_FILECONTROL_FINISHED receieved */ + bool started; /* set after TOX_FILECONTROL_ACCEPT received */ int filenum; char nextpiece[FILE_PIECE_SIZE]; uint16_t piecelen; char filename[MAX_STR_SIZE]; - uint64_t timestamp; - uint64_t last_progress; + uint64_t timestamp; /* marks the last time data was successfully transfered */ + uint64_t last_progress; /* marks the last time the progress bar was refreshed */ double bps; uint64_t size; uint32_t line_id; diff --git a/src/groupchat.c b/src/groupchat.c index ac1635d..befc04e 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -815,6 +815,8 @@ static int group_audio_write(int peernum, int groupnum, const int16_t *pcm, unsi static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate) { + return; /* TODO: fix this stuff */ + if (groupnum != self->num) return; @@ -831,7 +833,6 @@ static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int p fprintf(stderr, "ctx is null\n"); group_audio_write(peernum, groupnum, pcm, samples, channels, sample_rate); - // fprintf(stderr, "groupnum: %d, ret: %d\n", groupnum, ret); } #endif /* AUDIO */ diff --git a/src/xtra.c b/src/xtra.c index bb7d391..27a69d7 100644 --- a/src/xtra.c +++ b/src/xtra.c @@ -1,3 +1,25 @@ +/* xtra.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 . + * + */ + #include "xtra.h" #include diff --git a/src/xtra.h b/src/xtra.h index a2acee6..59038de 100644 --- a/src/xtra.h +++ b/src/xtra.h @@ -1,3 +1,25 @@ +/* xtra.h + * + * + * Copyright (C) 2014 Toxic All Rights Reserved. + * + * This file is part of Toxic. + * + * Toxic is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Toxic is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Toxic. If not, see . + * + */ + #ifndef XTRA_H #define XTRA_H