Welcome to mirror list, hosted at ThFree Co, Russian Federation.

filetransfer.py « common « gajim - dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c34d1bf2583d47a4bb6de2279af23b41e150dd6 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# This file is part of Gajim.
#
# Gajim 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; version 3 only.
#
# Gajim 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 Gajim. If not, see <http://www.gnu.org/licenses/>.

from typing import Optional

from gajim.common.const import FTState
from gajim.common.helpers import Observable


class FileTransfer(Observable):

    _state_descriptions: dict[FTState, str] = {}

    def __init__(self, account: str) -> None:
        Observable.__init__(self)

        self._account = account

        self._progress = 0

        self._state = FTState.INIT
        self._error_text: str = ''
        self._error_domain: Optional[str] = None

    @property
    def account(self) -> str:
        return self._account

    @property
    def state(self) -> FTState:
        return self._state

    @property
    def filename(self) -> str:
        raise NotImplementedError

    @property
    def error_text(self) -> str:
        return self._error_text

    @property
    def error_domain(self) -> Optional[str]:
        return self._error_domain

    def get_progress(self) -> float:
        return self._progress

    def set_progress(self, progress: float) -> None:
        self._progress = progress
        self.update_progress()

    def get_state_description(self) -> str:
        return self._state_descriptions.get(self._state, '')

    def set_preparing(self) -> None:
        self._state = FTState.PREPARING
        self.notify('state-changed', FTState.PREPARING)

    def set_encrypting(self) -> None:
        self._state = FTState.ENCRYPTING
        self.notify('state-changed', FTState.ENCRYPTING)

    def set_decrypting(self) -> None:
        self._state = FTState.DECRYPTING
        self.notify('state-changed', FTState.DECRYPTING)

    def set_started(self) -> None:
        self._state = FTState.STARTED
        self.notify('state-changed', FTState.STARTED)

    def set_error(self, domain: str, text: str = '') -> None:
        self._error_text = text
        self._error_domain = domain
        self._state = FTState.ERROR
        self.notify('state-changed', FTState.ERROR)
        self.disconnect_signals()

    def set_cancelled(self) -> None:
        self._state = FTState.CANCELLED
        self.notify('state-changed', FTState.CANCELLED)
        self.disconnect_signals()

    def set_in_progress(self) -> None:
        self._state = FTState.IN_PROGRESS
        self.notify('state-changed', FTState.IN_PROGRESS)

    def set_finished(self) -> None:
        self._state = FTState.FINISHED
        self.notify('state-changed', FTState.FINISHED)
        self.disconnect_signals()

    def update_progress(self) -> None:
        self.notify('progress')

    def cancel(self) -> None:
        self.notify('cancel')