qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
toxfileprogress.h
Go to the documentation of this file.
1 /*
2  Copyright © 2018-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <QTime>
23 
24 #include <array>
25 
27 {
28 public:
29  ToxFileProgress(uint64_t filesize, int samplePeriodMs = 4000);
30 
31  QTime lastSampleTime() const;
32  bool addSample(uint64_t bytesSent, QTime now = QTime::currentTime());
33  void resetSpeed();
34 
35  uint64_t getBytesSent() const;
36  uint64_t getFileSize() const { return filesize; }
37  double getProgress() const;
38  double getSpeed() const;
39  double getTimeLeftSeconds() const;
40 
41 private:
42  // Should never be modified, but do not want to lose assignment operators
43  uint64_t filesize;
46 
47  struct Sample
48  {
49  uint64_t bytesSent = 0;
50  QTime timestamp;
51  };
52 
53  std::array<Sample, 2> samples;
54  uint8_t activeSample = 0;
55 };
ToxFileProgress::getSpeed
double getSpeed() const
Definition: toxfileprogress.cpp:99
ToxFileProgress::Sample::bytesSent
uint64_t bytesSent
Definition: toxfileprogress.h:49
ToxFileProgress::Sample
Definition: toxfileprogress.h:47
ToxFileProgress::Sample::timestamp
QTime timestamp
Definition: toxfileprogress.h:50
ToxFileProgress::ToxFileProgress
ToxFileProgress(uint64_t filesize, int samplePeriodMs=4000)
Definition: toxfileprogress.cpp:24
ToxFileProgress::getProgress
double getProgress() const
Definition: toxfileprogress.cpp:94
ToxFileProgress::activeSample
uint8_t activeSample
Definition: toxfileprogress.h:54
ToxFileProgress::filesize
uint64_t filesize
Definition: toxfileprogress.h:43
ToxFileProgress::speedSampleCount
size_t speedSampleCount
Definition: toxfileprogress.h:44
ToxFileProgress::resetSpeed
void resetSpeed()
Definition: toxfileprogress.cpp:82
ToxFileProgress::samples
std::array< Sample, 2 > samples
Definition: toxfileprogress.h:53
ToxFileProgress::getFileSize
uint64_t getFileSize() const
Definition: toxfileprogress.h:36
ToxFileProgress::getTimeLeftSeconds
double getTimeLeftSeconds() const
Definition: toxfileprogress.cpp:124
ToxFileProgress
Definition: toxfileprogress.h:26
ToxFileProgress::getBytesSent
uint64_t getBytesSent() const
Definition: toxfileprogress.cpp:89
ToxFileProgress::addSample
bool addSample(uint64_t bytesSent, QTime now=QTime::currentTime())
Definition: toxfileprogress.cpp:39
ToxFileProgress::lastSampleTime
QTime lastSampleTime() const
Definition: toxfileprogress.cpp:34
ToxFileProgress::samplePeriodMs
int samplePeriodMs
Definition: toxfileprogress.h:45