annotate frontends/src/primitivus/profile_manager.py @ 1279:d84905c3e124

plugin XEP-0334: first draft
author souliane <souliane@mailoo.org>
date Thu, 25 Dec 2014 12:09:05 +0100
parents 49d39b619e5d
children e3a9ea76de35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
4 # Primitivus: a SAT frontend
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 771
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
10 # (at your option) any later version.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
15 # GNU Affero General Public License for more details.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 751
diff changeset
20 from sat.core.i18n import _
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
21 from sat_frontends.primitivus.constants import Const as C
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import urwid
1019
6a16ec17a458 better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1010
diff changeset
23 from urwid_satext.sat_widgets import AdvancedEdit, Password, List, InputDialog, ConfirmDialog, Alert
1161
344bbe6fd1de primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
24 from sat_frontends.primitivus.keys import action_key_map as a_key
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 class ProfileManager(urwid.WidgetWrap):
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def __init__(self, host):
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 self.host = host
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
31 #profiles list
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 profiles = self.host.bridge.getProfilesList()
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
33 profiles.sort()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
34
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
35 #login & password box must be created before list because of onProfileChange
1019
6a16ec17a458 better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1010
diff changeset
36 self.login_wid = AdvancedEdit(_('Login:'), align='center')
6a16ec17a458 better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1010
diff changeset
37 self.pass_wid = Password(_('Password:'), align='center')
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
38
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
39 self.selected_profile = None # allow to reselect the previous selection until the profile is authenticated
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
40 style = ['single']
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
41 if self.host.options.profile:
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
42 style.append('no_first_select')
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
43 self.list_profile = List(profiles, style=style, align='center', on_change=self.onProfileChange)
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
44
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
45 #new & delete buttons
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
46 buttons = [urwid.Button(_("New"), self.onNewProfile),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
47 urwid.Button(_("Delete"), self.onDeleteProfile)]
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
48 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center')
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
49
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
50 #second part: login information:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
51 divider = urwid.Divider('-')
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
52
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
53 #connect button
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
54 connect_button = urwid.Button(_("Connect"), self.onConnectProfile)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
55
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
56 #we now build the widget
1178
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
57 list_walker = urwid.SimpleFocusListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button])
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
58 frame_body = urwid.ListBox(list_walker)
115
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
59 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title'))
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
60 self.main_widget = urwid.LineBox(frame)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
61 urwid.WidgetWrap.__init__(self, self.main_widget)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
62
1161
344bbe6fd1de primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
63 def keypress(self, size, key):
344bbe6fd1de primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
64 if key == a_key['APP_QUIT']:
344bbe6fd1de primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
65 self.host.onExit()
344bbe6fd1de primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
66 raise urwid.ExitMainLoop()
1178
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
67 elif key in (a_key['FOCUS_UP'], a_key['FOCUS_DOWN']):
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
68 focus_diff = 1 if key==a_key['FOCUS_DOWN'] else -1
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
69 list_box = self.main_widget.base_widget.body
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
70 current_focus = list_box.body.get_focus()[1]
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
71 if current_focus is None:
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
72 return
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
73 while True:
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
74 current_focus += focus_diff
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
75 if current_focus < 0 or current_focus >= len(list_box.body):
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
76 break
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
77 if list_box.body[current_focus].selectable():
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
78 list_box.set_focus(current_focus, 'above' if focus_diff == 1 else 'below')
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
79 list_box._invalidate()
49d39b619e5d primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents: 1161
diff changeset
80 return
1161
344bbe6fd1de primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
81 return super(ProfileManager, self).keypress(size, key)
344bbe6fd1de primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
82
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
83 def __refillProfiles(self):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
84 """Update the list of profiles"""
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
85 profiles = self.host.bridge.getProfilesList()
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
86 profiles.sort()
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
87 self.list_profile.changeValues(profiles)
112
f551e44adb25 Primitivus first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
89 def cancelDialog(self, button):
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 115
diff changeset
90 self.host.removePopUp()
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
91
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
92 def newProfile(self, button, edit):
217
b4dfe15c0b25 primitivus: misc comments
Goffi <goffi@goffi.org>
parents: 173
diff changeset
93 """Create the profile"""
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
94 name = edit.get_edit_text()
421
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
95 self.host.bridge.asyncCreateProfile(name, callback=lambda: self._newProfileCreated(name), errback=self._profileCreationFailure)
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
96
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
97 def _newProfileCreated(self, name):
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
98 self.__refillProfiles()
217
b4dfe15c0b25 primitivus: misc comments
Goffi <goffi@goffi.org>
parents: 173
diff changeset
99 #We select the profile created in the list
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
100 self.list_profile.selectValue(name)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 115
diff changeset
101 self.host.removePopUp()
421
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
102 self.host.redraw()
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
103
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
104 def _profileCreationFailure(self, reason):
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
105 self.host.removePopUp()
1063
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 1034
diff changeset
106 if reason == "ConflictError":
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 1034
diff changeset
107 message = _("A profile with this name already exists")
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 1034
diff changeset
108 elif reason == "CancelError":
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 1034
diff changeset
109 message = _("Profile creation cancelled by backend")
421
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
110 else:
1063
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 1034
diff changeset
111 message = _("Unknown reason (%s)") % reason
421
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
112 popup = Alert(_("Can't create profile"), message, ok_cb=self.host.removePopUp)
28e4299d4553 primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents: 413
diff changeset
113 self.host.showPopUp(popup)
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
114
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
115 def deleteProfile(self, button):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
116 profile_name = self.list_profile.getSelectedValue()
115
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
117 if profile_name:
893
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 811
diff changeset
118 self.host.bridge.asyncDeleteProfile(profile_name, callback=self.__refillProfiles)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 115
diff changeset
119 self.host.removePopUp()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
120
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
121 def onNewProfile(self, e):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
122 pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 115
diff changeset
123 self.host.showPopUp(pop_up_widget)
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
124
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
125 def onDeleteProfile(self, e):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
126 pop_up_widget = ConfirmDialog(_("Are you sure you want to delete the profile %s ?") % self.list_profile.getSelectedValue(), no_cb=self.cancelDialog, yes_cb=self.deleteProfile)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 115
diff changeset
127 self.host.showPopUp(pop_up_widget)
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
128
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
129 def getXMPPParams(self, profile):
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
130 """This is called from PrimitivusApp.launchAction when the profile has been authenticated.
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
131
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
132 @param profile: %(doc_profile)s
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
133 """
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
134 def setJID(jabberID):
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
135 self.login_wid.set_edit_text(jabberID)
446
39a8ca1a2675 Primitivus: fixed redraw on profile change in profile manager
Goffi <goffi@goffi.org>
parents: 423
diff changeset
136 self.host.redraw()
1019
6a16ec17a458 better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1010
diff changeset
137
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
138 def setPassword(password):
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
139 self.pass_wid.set_edit_text(password)
446
39a8ca1a2675 Primitivus: fixed redraw on profile change in profile manager
Goffi <goffi@goffi.org>
parents: 423
diff changeset
140 self.host.redraw()
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
141
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
142 self.list_profile.selectValue(profile, move_focus=False)
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
143 self.selected_profile = profile
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
144 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=setJID, errback=self.getParamError)
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
145 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=setPassword, errback=self.getParamError)
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
146
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
147 def onProfileChange(self, list_wid):
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
148 """This is called when a profile is selected in the profile list.
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
149
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
150 @param list_wid: the List widget who sent the event
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
151 """
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
152 profile_name = list_wid.getSelectedValue()
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
153 if not profile_name or profile_name == self.selected_profile:
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
154 return # avoid infinite loop
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
155 if self.selected_profile:
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
156 list_wid.selectValue(self.selected_profile, move_focus=False)
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
157 else:
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
158 list_wid.unselectAll(invisible=True)
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
159 self.host.redraw()
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
160 self.host.profile = profile_name # FIXME: EXTREMELY DIRTY, needed for sat_frontends.tools.xmlui.XMLUI._xmluiLaunchAction
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
161 self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, {'caller': 'profile_manager'}, profile_key=profile_name)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
162
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents: 112
diff changeset
163 def onConnectProfile(self, button):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
164 profile_name = self.list_profile.getSelectedValue()
1034
5197600a1e13 quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents: 1019
diff changeset
165 assert(profile_name == self.selected_profile) # if not, there's a bug somewhere...
115
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
166 if not profile_name:
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
167 pop_up_widget = Alert(_('No profile selected'), _('You need to create and select a profile before connecting'), ok_cb=self.cancelDialog)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 115
diff changeset
168 self.host.showPopUp(pop_up_widget)
115
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
169 elif profile_name[0] == '@':
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
170 pop_up_widget = Alert(_('Bad profile name'), _("A profile name can't start with a @"), ok_cb=self.cancelDialog)
117
1f0fd6f03e2b misc fixes
Goffi <goffi@goffi.org>
parents: 115
diff changeset
171 self.host.showPopUp(pop_up_widget)
115
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
172 else:
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
173 profile = self.host.bridge.getProfileName(profile_name)
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
174 assert(profile)
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
175 #TODO: move this to quick_app
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
176 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile,
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
177 callback=lambda old_jid: self.__old_jidReceived(old_jid, profile), errback=self.getParamError)
115
eed4f77c942e primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents: 113
diff changeset
178
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
179 def __old_jidReceived(self, old_jid, profile):
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
180 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile,
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
181 callback=lambda old_pass: self.__old_passReceived(old_jid, old_pass, profile), errback=self.getParamError)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
182
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
183 def __old_passReceived(self, old_jid, old_pass, profile):
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
184 """Check if we have new jid/pass, save them if it is the case, and plug profile"""
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
185 new_jid = self.login_wid.get_edit_text()
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
186 new_pass = self.pass_wid.get_edit_text()
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
187
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
188 if old_jid != new_jid:
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 609
diff changeset
189 self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile)
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
190 if old_pass != new_pass:
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 609
diff changeset
191 self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile)
413
dd4caab17008 core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents: 228
diff changeset
192 self.host.plug_profile(profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
193
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
194 def getParamError(self, ignore):
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
195 popup = Alert("Error", _("Can't get profile parameter"), ok_cb=self.host.removePopUp)
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 422
diff changeset
196 self.host.showPopUp(popup)