comparison browser/sat_browser/menu.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/browser/sat_browser/menu.py@f2170536ba23
children 2af117bfe6cc
comparison
equal deleted inserted replaced
1123:63a4b8fe9782 1124:28e3eb3bb217
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Libervia: a Salut à Toi frontend
5 # Copyright (C) 2011-2018 Jérôme Poisson <goffi@goffi.org>
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 import pyjd # this is dummy in pyjs
21 from sat.core.log import getLogger
22 log = getLogger(__name__)
23
24 from pyjamas.ui.HTML import HTML
25 from pyjamas.ui.Frame import Frame
26
27 from constants import Const as C
28 import file_tools
29 import xmlui
30 import chat
31 import dialog
32 import contact_group
33 import base_menu
34 from sat_browser import html_tools
35 from sat_browser import web_widget
36
37
38 unicode = str # FIXME: pyjamas workaround
39
40
41 class MainMenuBar(base_menu.GenericMenuBar):
42 """The main menu bar which is displayed on top of the document"""
43
44 ITEM_TPL = "<img src='media/icons/menu/%s_menu_red.png' />%s"
45
46 def __init__(self, host):
47 styles = {'moved_popup': 'menuLastPopup', 'menu_bar': 'mainMenuBar'}
48 base_menu.GenericMenuBar.__init__(self, host, vertical=False, styles=styles)
49
50 @classmethod
51 def getCategoryHTML(cls, category):
52 """Build the html to be used for displaying a category item.
53
54 @param category (quick_menus.MenuCategory): category to add
55 @return unicode: HTML to display
56 """
57 name = html_tools.html_sanitize(category.name)
58 return cls.ITEM_TPL % (category.icon, name) if category.icon is not None else name
59
60 ## callbacks
61
62 # General menu
63
64 def onDisconnect(self):
65 def confirm_cb(answer):
66 if answer:
67 self.host.disconnect(C.PROF_KEY_NONE)
68 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?")
69 _dialog.show()
70
71 #Contact menu
72
73 def onManageContactGroups(self):
74 """Open the contact groups manager."""
75
76 def onCloseCallback():
77 pass
78
79 contact_group.ContactGroupEditor(self.host, None, onCloseCallback)
80
81 #Group menu
82 def onJoinRoom(self):
83
84 def invite(room_jid, contacts):
85 for contact in contacts:
86 self.host.bridge.call('inviteMUC', None, unicode(contact), unicode(room_jid))
87
88 def join(room_jid, contacts):
89 if self.host.whoami:
90 nick = self.host.whoami.node
91 contact_list = self.host.contact_list
92 if room_jid is None or room_jid not in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP):
93 room_jid_s = unicode(room_jid) if room_jid else ''
94 self.host.bridge.joinMUC(room_jid_s, nick, profile=C.PROF_KEY_NONE, callback=lambda room_jid: invite(room_jid, contacts), errback=self.host.onJoinMUCFailure)
95 else:
96 self.host.displayWidget(chat.Chat, room_jid, type_="group")
97 invite(room_jid, contacts)
98
99 dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False))
100
101
102 # Help menu
103
104 def onOfficialChatRoom(self):
105 nick = self.host.whoami.node
106 self.host.bridge.joinMUC(self.host.default_muc, nick, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=self.host.onJoinMUCFailure)
107
108 def onSocialContract(self):
109 _frame = Frame('contrat_social.html')
110 _frame.setStyleName('infoFrame')
111 _dialog = dialog.GenericDialog("Contrat Social", _frame)
112 _dialog.setSize('80%', '80%')
113 _dialog.show()
114
115 def onAbout(self):
116 def gotVersions():
117 _about = HTML("""<b>Libervia</b>, a Salut &agrave; Toi project<br />
118 <br />
119 Libervia is a web frontend for Salut &agrave; Toi<br />
120 <span style='font-style: italic;'>S&agrave;T version:</span> {sat_version}<br/>
121 <span style='font-style: italic;'>Libervia version:</span> {libervia_version}<br/>
122 <br />
123 You can contact the authors at <a href="mailto:contact@salut-a-toi.org">contact@salut-a-toi.org</a><br />
124 Blog available (mainly in french) at <a href="http://www.goffi.org" target="_blank">http://www.goffi.org</a><br />
125 Project page: <a href="http://salut-a-toi.org"target="_blank">http://salut-a-toi.org</a><br />
126 <br />
127 Any help welcome :)
128 <p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p>
129 """.format(sat_version=self.host.sat_version, libervia_version=self.host.libervia_version))
130 _dialog = dialog.GenericDialog("About", _about)
131 _dialog.show()
132 self.host.getVersions(gotVersions)
133
134 #Settings menu
135
136 def onAccount(self):
137 def gotUI(xml_ui):
138 if not xml_ui:
139 return
140 body = xmlui.create(self.host, xml_ui)
141 _dialog = dialog.GenericDialog("Manage your account", body, options=['NO_CLOSE'])
142 body.setCloseCb(_dialog.close)
143 _dialog.show()
144 self.host.bridge.call('getAccountDialogUI', gotUI)
145
146 def onParameters(self):
147 def gotParams(xml_ui):
148 if not xml_ui:
149 return
150 body = xmlui.create(self.host, xml_ui)
151 _dialog = dialog.GenericDialog("Parameters", body, options=['NO_CLOSE'])
152 _dialog.addStyleName("parameters")
153 body.setCloseCb(_dialog.close)
154 _dialog.setSize('80%', '80%')
155 _dialog.show()
156 self.host.bridge.getParamsUI(profile=C.PROF_KEY_NONE, callback=gotParams)
157
158 def removeItemParams(self):
159 """Remove the Parameters item from the Settings menu bar."""
160 self.menu_settings.removeItem(self.item_params)
161
162 def onAvatarUpload(self):
163 body = file_tools.AvatarUpload()
164 _dialog = dialog.GenericDialog("Avatar upload", body, options=['NO_CLOSE'])
165 body.setCloseCb(_dialog.close)
166 _dialog.setWidth('40%')
167 _dialog.show()
168
169 def onPublicBlog(self, contact_box, data, profile):
170 # FIXME: Q&D way to check domain, need to be done in a cleaner way
171 if contact_box.jid.domain != self.host._defaultDomain:
172 self.host.showDialog(u"Public blogs from other domains are not managed yet", "Can't show public blog", "error")
173 return
174
175 url = '{}/blog/{}'.format(self.host.base_location, contact_box.jid.node)
176 widget = self.host.displayWidget(web_widget.WebWidget, url, show_url=False)
177 self.host.setSelected(widget)