annotate sat_frontends/primitivus/status.py @ 2694:a8ec00731ce7

core: removed whitespace ping (not needed anymore as we handle XMPP ping)
author Goffi <goffi@goffi.org>
date Mon, 19 Nov 2018 21:08:25 +0100
parents 56f94936df1e
children e6806aaab16d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
3
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # Primitivus: a SAT frontend
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1434
diff changeset
5 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
6
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # (at your option) any later version.
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
11
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
16
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 766
diff changeset
20 from sat.core.i18n import _
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
21 import urwid
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
22 from urwid_satext import sat_widgets
1327
89dc29afe01c frontends: merge sat_frontends.constants to sat_frontends.quick_frontend.constants
souliane <souliane@mailoo.org>
parents: 1184
diff changeset
23 from sat_frontends.quick_frontend.constants import Const as commonConst
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
24 from sat_frontends.primitivus.constants import Const as C
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
25
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
26
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
27 class StatusBar(urwid.Columns):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
28 def __init__(self, host):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
29 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
30 self.presence = sat_widgets.ClickableText("")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
31 status_prefix = urwid.Text("[")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
32 status_suffix = urwid.Text("]")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 self.status = sat_widgets.ClickableText("")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, "")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 urwid.Columns.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 ("weight", 1, self.presence),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 ("weight", 1, status_prefix),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 ("weight", 9, self.status),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 ("weight", 1, status_suffix),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
44 urwid.connect_signal(self.presence, "click", self.onPresenceClick)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 urwid.connect_signal(self.status, "click", self.onStatusClick)
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
46
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
47 def onPresenceClick(self, sender=None):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 if not self.host.bridge.isConnected(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 self.host.current_profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 ): # FIXME: manage multi-profiles
937
255e6953b2c3 primitivus: do not display the presence/status dialog if the profile is not connected
souliane <souliane@mailoo.org>
parents: 811
diff changeset
51 return
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
52 options = [commonConst.PRESENCE[presence] for presence in commonConst.PRESENCE]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 list_widget = sat_widgets.GenericList(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 options=options, option_type=sat_widgets.ClickableText, on_click=self.onChange
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 decorated = sat_widgets.LabelLine(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 list_widget, sat_widgets.SurroundedText(_("Set your presence"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 )
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
59 self.host.showPopUp(decorated)
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
60
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
61 def onStatusClick(self, sender=None):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 if not self.host.bridge.isConnected(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 self.host.current_profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 ): # FIXME: manage multi-profiles
937
255e6953b2c3 primitivus: do not display the presence/status dialog if the profile is not connected
souliane <souliane@mailoo.org>
parents: 811
diff changeset
65 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 pop_up_widget = sat_widgets.InputDialog(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 _("Set your status"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 _("New status"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 default_txt=self.status.get_text(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 cancel_cb=self.host.removePopUp,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 ok_cb=self.onChange,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 )
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
73 self.host.showPopUp(pop_up_widget)
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
74
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
75 def onChange(self, sender=None, user_data=None):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
76 new_value = user_data.get_text()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 previous = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 [key for key in C.PRESENCE if C.PRESENCE[key][0] == self.presence.get_text()][
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 0
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 self.status.get_text(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 )
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
83 if isinstance(user_data, sat_widgets.ClickableText):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 new = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 for key in commonConst.PRESENCE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 if commonConst.PRESENCE[key] == new_value
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 ][0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 previous[1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 )
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
92 elif isinstance(user_data, sat_widgets.AdvancedEdit):
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
93 new = (previous[0], new_value[0])
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
94 if new != previous:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 statuses = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 C.PRESENCE_STATUSES_DEFAULT: new[1]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 } # FIXME: manage multilingual statuses
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 for (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 ) in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 self.host.profiles
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 ): # FIXME: for now all the profiles share the same status
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 self.host.bridge.setPresence(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 show=new[0], statuses=statuses, profile_key=profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 )
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
106 self.setPresenceStatus(new[0], new[1])
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
107 self.host.removePopUp()
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
108
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
diff changeset
109 def setPresenceStatus(self, show, status):
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
110 show_icon, show_attr = C.PRESENCE.get(show)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 self.presence.set_text(("show_normal", show_icon))
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
112 if status is not None:
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
113 self.status.set_text((show_attr, status))
766
6c36149524ed primitivus: redraw after changing the presence or status
souliane <souliane@mailoo.org>
parents: 737
diff changeset
114 self.host.redraw()