File: syncthingcompletion.h

package info (click to toggle)
syncthingtray 1.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,804 kB
  • sloc: cpp: 31,085; xml: 1,694; java: 570; sh: 81; javascript: 53; makefile: 25
file content (92 lines) | stat: -rw-r--r-- 2,716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef DATA_SYNCTHING_COMPLETION_H
#define DATA_SYNCTHING_COMPLETION_H

#include "./global.h"

#include <c++utilities/chrono/datetime.h>

#include <QMetaObject>

namespace Data {

using SyncthingEventId = quint64;

struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingCompletion {
    Q_GADGET
    Q_PROPERTY(double percentage MEMBER percentage)
    Q_PROPERTY(quint64 globalBytes MEMBER globalBytes)

public:
    CppUtilities::DateTime lastUpdate;
    double percentage = 0;
    quint64 globalBytes = 0;
    struct Needed {
        quint64 bytes = 0;
        quint64 items = 0;
        quint64 deletes = 0;
        constexpr bool isNull() const;
        constexpr bool operator==(const Needed &other) const;
        constexpr bool operator!=(const Needed &other) const;
        constexpr Needed &operator+=(const Needed &other);
        constexpr Needed &operator-=(const Needed &other);
    } needed;
    SyncthingEventId requestedForEventId = 0;
    constexpr SyncthingCompletion &operator+=(const SyncthingCompletion &other);
    constexpr SyncthingCompletion &operator-=(const SyncthingCompletion &other);
    Q_INVOKABLE void recomputePercentage();
};

constexpr bool SyncthingCompletion::Needed::isNull() const
{
    return bytes == 0 && items == 0 && deletes == 0;
}

constexpr bool SyncthingCompletion::Needed::operator==(const SyncthingCompletion::Needed &other) const
{
    return bytes == other.bytes && items == other.items && deletes == other.deletes;
}

constexpr bool SyncthingCompletion::Needed::operator!=(const SyncthingCompletion::Needed &other) const
{
    return !(*this == other);
}

constexpr SyncthingCompletion::Needed &SyncthingCompletion::Needed::operator+=(const SyncthingCompletion::Needed &other)
{
    bytes += other.bytes;
    items += other.items;
    deletes += other.deletes;
    return *this;
}

constexpr SyncthingCompletion::Needed &SyncthingCompletion::Needed::operator-=(const SyncthingCompletion::Needed &other)
{
    bytes -= other.bytes;
    items -= other.items;
    deletes -= other.deletes;
    return *this;
}

constexpr SyncthingCompletion &SyncthingCompletion::operator+=(const SyncthingCompletion &other)
{
    lastUpdate = std::max(lastUpdate, other.lastUpdate);
    globalBytes += other.globalBytes;
    needed += other.needed;
    return *this;
}

constexpr SyncthingCompletion &SyncthingCompletion::operator-=(const SyncthingCompletion &other)
{
    globalBytes -= other.globalBytes;
    needed -= other.needed;
    return *this;
}

inline void SyncthingCompletion::recomputePercentage()
{
    percentage = (static_cast<double>(globalBytes - needed.bytes) / static_cast<double>(globalBytes)) * 100.0;
}

} // namespace Data

#endif // DATA_SYNCTHING_COMPLETION_H