2014-03-05 11:06:21 +01:00
|
|
|
/* file_senders.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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifndef FILESENDERS_H
|
|
|
|
#define FILESENDERS_H
|
2014-06-12 00:06:55 +02:00
|
|
|
|
2014-06-28 18:14:43 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
#define KiB 1024
|
|
|
|
#define MiB 1048576 /* 1024 ^ 2 */
|
|
|
|
#define GiB 1073741824 /* 1024 ^ 3 */
|
|
|
|
|
2014-06-12 00:06:55 +02:00
|
|
|
#define FILE_PIECE_SIZE 2048 /* must be >= (MAX_CRYPTO_DATA_SIZE - 2) in toxcore/net_crypto.h */
|
2014-08-07 19:05:42 +02:00
|
|
|
#define MAX_FILES 32
|
2014-12-05 19:47:47 +01:00
|
|
|
#define TIMEOUT_FILESENDER 120
|
2014-06-12 00:06:55 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
FILE *file;
|
|
|
|
ToxWindow *toxwin;
|
|
|
|
int32_t friendnum;
|
|
|
|
bool active;
|
2014-12-05 19:23:45 +01:00
|
|
|
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 */
|
2014-06-12 00:06:55 +02:00
|
|
|
int filenum;
|
2014-07-07 04:15:35 +02:00
|
|
|
char nextpiece[FILE_PIECE_SIZE];
|
2014-06-12 00:06:55 +02:00
|
|
|
uint16_t piecelen;
|
2014-08-03 21:12:55 +02:00
|
|
|
char filename[MAX_STR_SIZE];
|
2014-12-05 19:23:45 +01:00
|
|
|
uint64_t timestamp; /* marks the last time data was successfully transfered */
|
|
|
|
uint64_t last_progress; /* marks the last time the progress bar was refreshed */
|
2014-07-27 23:14:28 +02:00
|
|
|
double bps;
|
2014-06-12 00:06:55 +02:00
|
|
|
uint64_t size;
|
|
|
|
uint32_t line_id;
|
2014-07-28 03:19:17 +02:00
|
|
|
uint8_t queue_pos;
|
2014-06-28 18:14:43 +02:00
|
|
|
} FileSender;
|
2014-06-12 00:06:55 +02:00
|
|
|
|
2014-07-28 03:19:17 +02:00
|
|
|
/* creates initial progress line that will be updated during file transfer.
|
|
|
|
Assumes progline is of size MAX_STR_SIZE */
|
2014-07-27 23:14:28 +02:00
|
|
|
void prep_prog_line(char *progline);
|
|
|
|
|
|
|
|
/* prints a progress bar for file transfers.
|
|
|
|
if friendnum is -1 we're sending the file, otherwise we're receiving. */
|
|
|
|
void print_progress_bar(ToxWindow *self, int idx, int friendnum, double pct_remain);
|
|
|
|
|
2014-08-04 22:22:29 +02:00
|
|
|
/* set CTRL to -1 if we don't want to send a control signal.
|
|
|
|
set msg to NULL if we don't want to display a message */
|
2014-08-04 07:56:43 +02:00
|
|
|
void close_file_sender(ToxWindow *self, Tox *m, int i, const char *msg, int CTRL, int filenum, int32_t friendnum);
|
2014-08-04 22:22:29 +02:00
|
|
|
|
2014-08-05 23:38:33 +02:00
|
|
|
/* called whenever a file sender is opened or closed */
|
|
|
|
void reset_file_sender_queue(void);
|
|
|
|
|
2014-06-28 18:55:05 +02:00
|
|
|
void close_all_file_senders(Tox *m);
|
2014-06-28 18:14:43 +02:00
|
|
|
void do_file_senders(Tox *m);
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* #define FILESENDERS_H */
|