Mercurial > libervia-backend
annotate frontends/src/primitivus/profile_manager.py @ 853:c2f6ada7858f
core (sqlite): automatic database update:
- new Updater class check database consistency (by calculating a hash on the .schema), and updates base if necessary
- database now has a version (1 for current, 0 will be for 0.3's database), for each change this version will be increased
- creation statements and update statements are in the form of dict of dict with tuples. There is a help text at the top of the module to explain how it works
- if we are on a development version, the updater try to update the database automaticaly (without deleting table or columns). The Updater.generateUpdateData method can be used to ease the creation of update data (i.e. the dictionary at the top, see the one for the key 1 for an example).
- if there is an inconsistency, an exception is raised, and a message indicate the SQL statements that should fix the situation.
- well... this is rather complicated, a KISS method would maybe have been better. The future will say if we need to simplify it :-/
- new DatabaseError exception
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 23 Feb 2014 23:30:32 +0100 |
parents | 1fe00f0c9a91 |
children | 308a96bc7c1b |
rev | line source |
---|---|
112 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
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 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
112 | 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 | 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 | 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 | 19 |
771 | 20 from sat.core.i18n import _ |
112 | 21 import urwid |
422
5a18c5f08d9b
Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents:
421
diff
changeset
|
22 from urwid_satext.sat_widgets import AdvancedEdit,Password,List,InputDialog,ConfirmDialog,Alert,FocusFrame |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
23 from sat.tools.jid import JID |
112 | 24 |
25 | |
26 class ProfileManager(urwid.WidgetWrap): | |
27 | |
28 def __init__(self, host): | |
29 self.host = host | |
113 | 30 #profiles list |
112 | 31 profiles = self.host.bridge.getProfilesList() |
113 | 32 profiles.sort() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
33 |
113 | 34 #login & password box must be created before list because of onProfileChange |
422
5a18c5f08d9b
Primitivus: Profile Manager: fixed redraw on profile change + use of AdvandedEdit for login field
Goffi <goffi@goffi.org>
parents:
421
diff
changeset
|
35 self.login_wid = AdvancedEdit(_('Login:'),align='center') |
113 | 36 self.pass_wid = Password(_('Password:'),align='center') |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
37 |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
38 self.list_profile = List(profiles, style=['single'], align='center', on_change=self.onProfileChange) |
113 | 39 |
40 #new & delete buttons | |
41 buttons = [urwid.Button(_("New"), self.onNewProfile), | |
42 urwid.Button(_("Delete"), self.onDeleteProfile)] | |
43 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center') | |
44 | |
45 #second part: login information: | |
46 divider = urwid.Divider('-') | |
47 | |
48 #connect button | |
49 connect_button = urwid.Button(_("Connect"), self.onConnectProfile) | |
50 | |
51 #we now build the widget | |
52 body_content = urwid.SimpleListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button]) | |
53 frame_body = urwid.ListBox(body_content) | |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
54 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title')) |
113 | 55 self.main_widget = urwid.LineBox(frame) |
56 urwid.WidgetWrap.__init__(self, self.main_widget) | |
57 | |
58 def __refillProfiles(self): | |
59 """Update the list of profiles""" | |
60 profiles = self.host.bridge.getProfilesList() | |
61 profiles.sort() | |
62 self.list_profile.changeValues(profiles) | |
112 | 63 |
113 | 64 def cancelDialog(self, button): |
117 | 65 self.host.removePopUp() |
113 | 66 |
67 def newProfile(self, button, edit): | |
217 | 68 """Create the profile""" |
113 | 69 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
|
70 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
|
71 |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
72 def _newProfileCreated(self, name): |
113 | 73 self.__refillProfiles() |
217 | 74 #We select the profile created in the list |
113 | 75 self.list_profile.selectValue(name) |
117 | 76 self.host.removePopUp() |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
77 self.host.redraw() |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
78 |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
79 def _profileCreationFailure(self, reason): |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
80 self.host.removePopUp() |
751
1def5b7edf9f
core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents:
641
diff
changeset
|
81 if reason=="ConflictError": |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
82 message=_("A profile with this name already exists") |
751
1def5b7edf9f
core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents:
641
diff
changeset
|
83 elif reason=="CancelError": |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
84 message=_("Profile creation cancelled by backend") |
751
1def5b7edf9f
core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents:
641
diff
changeset
|
85 elif reason=="DATABASE": # FIXME: doesn't seem to exist ! |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
86 message=_("Database error") |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
87 else: |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
88 message=_("Unknown reason (%s)") % reason |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
89 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
|
90 self.host.showPopUp(popup) |
113 | 91 |
92 def deleteProfile(self, button): | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
93 profile_name = self.list_profile.getSelectedValue() |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
94 if profile_name: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
95 self.host.bridge.deleteProfile(profile_name) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
96 self.__refillProfiles() |
117 | 97 self.host.removePopUp() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
98 |
113 | 99 def onNewProfile(self, e): |
100 pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile) | |
117 | 101 self.host.showPopUp(pop_up_widget) |
113 | 102 |
103 def onDeleteProfile(self, e): | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
104 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 | 105 self.host.showPopUp(pop_up_widget) |
113 | 106 |
107 def onProfileChange(self, list_wid): | |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
108 def setJID(jabberID): |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
109 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
|
110 self.host.redraw() |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
111 def setPassword(password): |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
112 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
|
113 self.host.redraw() |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
114 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
115 profile_name = list_wid.getSelectedValue() |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
116 if profile_name: |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
117 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile_name, callback=setJID, errback=self.getParamError) |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
118 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile_name, callback=setPassword, errback=self.getParamError) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
119 |
113 | 120 def onConnectProfile(self, button): |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
121 profile_name = self.list_profile.getSelectedValue() |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
122 if not profile_name: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
123 pop_up_widget = Alert(_('No profile selected'), _('You need to create and select a profile before connecting'), ok_cb=self.cancelDialog) |
117 | 124 self.host.showPopUp(pop_up_widget) |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
125 elif profile_name[0] == '@': |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
126 pop_up_widget = Alert(_('Bad profile name'), _("A profile name can't start with a @"), ok_cb=self.cancelDialog) |
117 | 127 self.host.showPopUp(pop_up_widget) |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
128 else: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
129 profile = self.host.bridge.getProfileName(profile_name) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
130 assert(profile) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
131 #TODO: move this to quick_app |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
132 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
133 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
|
134 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
135 def __old_jidReceived(self, old_jid, profile): |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
136 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
137 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
|
138 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
139 def __old_passReceived(self, old_jid, old_pass, profile): |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
140 """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
|
141 new_jid = self.login_wid.get_edit_text() |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
142 new_pass = self.pass_wid.get_edit_text() |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
143 |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
144 if old_jid != new_jid: |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
145 self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile) |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
146 self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile_key=profile) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
147 if old_pass != new_pass: |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
148 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
|
149 self.host.plug_profile(profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
150 |
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
|
151 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
|
152 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
|
153 self.host.showPopUp(popup) |