mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 01:43:01 +01:00
properly handle file pausing
This commit is contained in:
parent
5aad8764b1
commit
90985af007
16
src/chat.c
16
src/chat.c
@ -448,19 +448,31 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
|
|||||||
|
|
||||||
switch (control_type) {
|
switch (control_type) {
|
||||||
case TOX_FILECONTROL_ACCEPT:
|
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.",
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer [%d] for '%s' accepted.",
|
||||||
filenum, filename);
|
filenum, filename);
|
||||||
/* prep progress bar line */
|
|
||||||
char progline[MAX_STR_SIZE];
|
char progline[MAX_STR_SIZE];
|
||||||
prep_prog_line(progline);
|
prep_prog_line(progline);
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", 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;
|
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);
|
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;
|
break;
|
||||||
|
|
||||||
|
case TOX_FILECONTROL_PAUSE:
|
||||||
|
if (receive_send == 1)
|
||||||
|
file_senders[send_idx].paused = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case TOX_FILECONTROL_KILL:
|
case TOX_FILECONTROL_KILL:
|
||||||
snprintf(msg, sizeof(msg), "File transfer for '%s' failed.", filename);
|
snprintf(msg, sizeof(msg), "File transfer for '%s' failed.", filename);
|
||||||
|
|
||||||
|
@ -264,6 +264,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
|
|||||||
if (!file_senders[i].active) {
|
if (!file_senders[i].active) {
|
||||||
memcpy(file_senders[i].filename, filename, namelen + 1);
|
memcpy(file_senders[i].filename, filename, namelen + 1);
|
||||||
file_senders[i].active = true;
|
file_senders[i].active = true;
|
||||||
|
file_senders[i].started = false;
|
||||||
file_senders[i].toxwin = self;
|
file_senders[i].toxwin = self;
|
||||||
file_senders[i].file = file_to_send;
|
file_senders[i].file = file_to_send;
|
||||||
file_senders[i].filenum = filenum;
|
file_senders[i].filenum = filenum;
|
||||||
|
@ -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;
|
if (device_idx >= MAX_DEVICES) return de_InvalidSelection;
|
||||||
|
|
||||||
Device* device = running[output][device_idx];
|
Device* device = running[output][device_idx];
|
||||||
if (!device)
|
|
||||||
fprintf(stderr, "DEVICE IS NULL SILLY\n");
|
|
||||||
|
|
||||||
if (!device || device->muted) return de_DeviceNotActive;
|
if (!device || device->muted) return de_DeviceNotActive;
|
||||||
|
|
||||||
|
@ -266,7 +266,8 @@ void do_file_senders(Tox *m)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If file transfer has timed out kill transfer and send kill control */
|
/* 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];
|
char msg[MAX_STR_SIZE];
|
||||||
snprintf(msg, sizeof(msg), "File transfer for '%s' timed out.", filename);
|
snprintf(msg, sizeof(msg), "File transfer for '%s' timed out.", filename);
|
||||||
close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, friendnum);
|
close_file_sender(self, m, i, msg, TOX_FILECONTROL_KILL, filenum, friendnum);
|
||||||
@ -279,7 +280,7 @@ void do_file_senders(Tox *m)
|
|||||||
continue;
|
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);
|
send_file_data(self, m, i, friendnum, filenum, filename);
|
||||||
|
|
||||||
file_senders[i].queue_pos = num_active_file_senders - 1;
|
file_senders[i].queue_pos = num_active_file_senders - 1;
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#define FILE_PIECE_SIZE 2048 /* must be >= (MAX_CRYPTO_DATA_SIZE - 2) in toxcore/net_crypto.h */
|
#define FILE_PIECE_SIZE 2048 /* must be >= (MAX_CRYPTO_DATA_SIZE - 2) in toxcore/net_crypto.h */
|
||||||
#define MAX_FILES 32
|
#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 */
|
#define NUM_PROG_MARKS 50 /* number of "#"'s in file transfer progress bar. Keep well below MAX_STR_SIZE */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -40,14 +40,16 @@ typedef struct {
|
|||||||
ToxWindow *toxwin;
|
ToxWindow *toxwin;
|
||||||
int32_t friendnum;
|
int32_t friendnum;
|
||||||
bool active;
|
bool active;
|
||||||
bool noconnection;
|
bool noconnection; /* set when the connection has been interrupted */
|
||||||
bool finished;
|
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;
|
int filenum;
|
||||||
char nextpiece[FILE_PIECE_SIZE];
|
char nextpiece[FILE_PIECE_SIZE];
|
||||||
uint16_t piecelen;
|
uint16_t piecelen;
|
||||||
char filename[MAX_STR_SIZE];
|
char filename[MAX_STR_SIZE];
|
||||||
uint64_t timestamp;
|
uint64_t timestamp; /* marks the last time data was successfully transfered */
|
||||||
uint64_t last_progress;
|
uint64_t last_progress; /* marks the last time the progress bar was refreshed */
|
||||||
double bps;
|
double bps;
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
uint32_t line_id;
|
uint32_t line_id;
|
||||||
|
@ -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,
|
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)
|
unsigned int samples, uint8_t channels, unsigned int sample_rate)
|
||||||
{
|
{
|
||||||
|
return; /* TODO: fix this stuff */
|
||||||
|
|
||||||
if (groupnum != self->num)
|
if (groupnum != self->num)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -831,7 +833,6 @@ static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int p
|
|||||||
fprintf(stderr, "ctx is null\n");
|
fprintf(stderr, "ctx is null\n");
|
||||||
|
|
||||||
group_audio_write(peernum, groupnum, pcm, samples, channels, sample_rate);
|
group_audio_write(peernum, groupnum, pcm, samples, channels, sample_rate);
|
||||||
// fprintf(stderr, "groupnum: %d, ret: %d\n", groupnum, ret);
|
|
||||||
}
|
}
|
||||||
#endif /* AUDIO */
|
#endif /* AUDIO */
|
||||||
|
|
||||||
|
22
src/xtra.c
22
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "xtra.h"
|
#include "xtra.h"
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
22
src/xtra.h
22
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef XTRA_H
|
#ifndef XTRA_H
|
||||||
#define XTRA_H
|
#define XTRA_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user