annotate src/tools/memory.py @ 320:5fc5e6a7e5c3

plugin Tarot: added a launch method to automatically create a new room, invite players and create the game - xep-0249 (direct MUC invitation) is used with a custom attribute to invite other users - bridge: added tarotGameLaunch in frontend side
author Goffi <goffi@goffi.org>
date Fri, 06 May 2011 15:42:26 +0200
parents b544bec477dd
children 0f9925193586
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 SAT: a jabber client
228
b1794cbb88e5 2011 copyright upgrade
Goffi <goffi@goffi.org>
parents: 224
diff changeset
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22 from __future__ import with_statement
goffi@necton2
parents:
diff changeset
23
goffi@necton2
parents:
diff changeset
24 import os.path
goffi@necton2
parents:
diff changeset
25 import time
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
26 import cPickle as pickle
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
27 from xml.dom import minidom
0
goffi@necton2
parents:
diff changeset
28 from logging import debug, info, error
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
29 import pdb
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
30 from twisted.internet import defer
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
31 from twisted.words.protocols.jabber import jid
223
86d249b6d9b7 Files reorganisation
Goffi <goffi@goffi.org>
parents: 214
diff changeset
32 from sat.tools.xml_tools import paramsXml2xmlUI
0
goffi@necton2
parents:
diff changeset
33
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
34 SAVEFILE_PARAM_XML="/param" #xml parameters template
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
35 SAVEFILE_PARAM_DATA="/param" #individual & general parameters; _ind and _gen suffixes will be added
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
36 SAVEFILE_HISTORY="/history"
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
37 SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins)
0
goffi@necton2
parents:
diff changeset
38
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
39 class Param():
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
40 """This class manage parameters with xml"""
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
41 ### TODO: add desciption in params
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
42
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
43 #TODO: move Watched in a plugin
34
a544b376b6f0 use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents: 22
diff changeset
44 default_xml = u"""
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
45 <params>
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
46 <general>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
47 </general>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
48 <individual>
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
49 <category name="Connection" label="%(category_connection)s">
256
f5181f6dd98f Test value replaced by example values for memory params
Goffi <goffi@goffi.org>
parents: 228
diff changeset
50 <param name="JabberID" value="name@example.org/SàT" type="string" />
f5181f6dd98f Test value replaced by example values for memory params
Goffi <goffi@goffi.org>
parents: 228
diff changeset
51 <param name="Password" value="" type="password" />
f5181f6dd98f Test value replaced by example values for memory params
Goffi <goffi@goffi.org>
parents: 228
diff changeset
52 <param name="Server" value="example.org" type="string" />
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
53 <param name="NewAccount" value="%(label_NewAccount)s" type="button" callback_id="registerNewAccount"/>
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
54 <param name="autoconnect" label="%(label_autoconnect)s" value="true" type="bool" />
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
55 <param name="autodisconnect" label="%(label_autodisconnect)s" value="false" type="bool" />
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
56 </category>
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
57 <category name="Misc" label="%(category_misc)s">
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
58 <param name="Watched" value="test@Jabber.goffi.int" type="string" />
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
59 </category>
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
60 </individual>
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
61 </params>
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
62 """ % {'category_connection': _("Connection"),
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
63 'label_NewAccount': _("Register new account"),
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
64 'label_autoconnect': _('Connect on frontend startup'),
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
65 'label_autodisconnect': _('Disconnect on frontend closure'),
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
66 'category_misc': _("Misc")
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
67 }
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
68
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
69 def load_default_params(self):
34
a544b376b6f0 use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents: 22
diff changeset
70 self.dom = minidom.parseString(Param.default_xml.encode('utf-8'))
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
71
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
72 def load_xml(self, file):
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
73 """Load parameters template from file"""
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
74 self.dom = minidom.parse(file)
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
75
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
76 def load_data(self, file):
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
77 """Load parameters data from file"""
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
78 file_ind = file + '_ind'
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
79 file_gen = file + '_gen'
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
80
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
81 if os.path.exists(file_gen):
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
82 try:
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
83 with open(file_gen, 'r') as file_gen_pickle:
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
84 self.params_gen=pickle.load(file_gen_pickle)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
85 debug(_("general params data loaded"))
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
86 except:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
87 error (_("Can't load general params data !"))
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
88
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
89 if os.path.exists(file_ind):
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
90 try:
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
91 with open(file_ind, 'r') as file_ind_pickle:
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
92 self.params=pickle.load(file_ind_pickle)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
93 debug(_("individual params data loaded"))
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
94 except:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
95 error (_("Can't load individual params data !"))
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
96
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
97 def save_xml(self, file):
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
98 """Save parameters template to xml file"""
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
99 with open(file, 'wb') as xml_file:
214
e178e8f6d13a fixed some unicode issue
Goffi <goffi@goffi.org>
parents: 197
diff changeset
100 xml_file.write(self.dom.toxml('utf-8'))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
101
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
102 def save_data(self, file):
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
103 """Save parameters data to file"""
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
104 #TODO: save properly in a separate file/database,
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
105 # use different behaviour depending of the data type (e.g. password encrypted)
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
106
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
107 #general params
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
108 with open(file+'_gen', 'w') as param_gen_pickle:
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
109 pickle.dump(self.params_gen, param_gen_pickle)
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
110
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
111 #then individual params
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
112 with open(file+'_ind', 'w') as param_ind_pickle:
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
113 pickle.dump(self.params, param_ind_pickle)
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
114
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
115 def __init__(self, host):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
116 debug("Parameters init")
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
117 self.host = host
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
118 self.default_profile = None
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 166
diff changeset
119 self.params = {}
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
120 self.params_gen = {}
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
121 host.set_const('savefile_param_xml', SAVEFILE_PARAM_XML)
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
122 host.set_const('savefile_param_data', SAVEFILE_PARAM_DATA)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
123 host.registerGeneralCB("registerNewAccount", host.registerNewAccountCB)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
124
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
125 def getProfilesList(self):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
126 return self.params.keys()
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
127
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
128 def createProfile(self, name):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
129 """Create a new profile
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
130 @param name: Name of the profile"""
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
131 if self.params.has_key(name):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
132 info (_('The profile name already exists'))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
133 return 1
259
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 256
diff changeset
134 if not self.host.trigger.point("ProfileCreation", name):
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 256
diff changeset
135 return 0
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
136 self.params[name]={}
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
137 return 0
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
138
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
139 def deleteProfile(self, name):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
140 """Delete an existing profile
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
141 @param name: Name of the profile"""
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
142 if not self.params.has_key(name):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
143 error (_('Trying to delete an unknown profile'))
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
144 return 1
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
145 del self.params[name]
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
146 return 0
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
147
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
148 def getProfileName(self, profile_key):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
149 """return profile according to profile_key
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
150 @param profile_key: profile name or key which can be
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
151 @ALL@ for all profiles
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
152 @DEFAULT@ for default profile
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
153 @return: requested profile name or None if it doesn't exist"""
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
154 if profile_key=='@DEFAULT@':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
155 if not self.params:
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
156 return ""
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
157 default = self.host.memory.getPrivate('Profile_default')
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
158 if not default or not default in self.params:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
159 info(_('No default profile, returning first one')) #TODO: manage real default profile
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
160 default = self.params.keys()[0]
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
161 self.host.memory.setPrivate('Profile_default', default)
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 166
diff changeset
162 return default #FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
163 if not self.params.has_key(profile_key):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
164 info (_('Trying to access an unknown profile'))
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
165 return ""
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
166 return profile_key
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
167
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
168 def __get_unique_node(self, parent, tag, name):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
169 """return node with given tag
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
170 @param parent: parent of nodes to check (e.g. documentElement)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
171 @param tag: tag to check (e.g. "category")
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
172 @param name: name to check (e.g. "JID")
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
173 @return: node if it exist or None
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
174 """
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
175 for node in parent.childNodes:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
176 if node.nodeName == tag and node.getAttribute("name") == name:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
177 #the node already exists
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
178 return node
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
179 #the node is new
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
180 return None
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
181
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
182 def importParams(self, xml):
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
183 """import xml in parameters, do nothing if the param already exist
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
184 @param xml: parameters in xml form"""
34
a544b376b6f0 use proper utf-8 encoding for parsing xml in parameters
Goffi <goffi@goffi.org>
parents: 22
diff changeset
185 src_dom = minidom.parseString(xml.encode('utf-8'))
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
186
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
187 def import_node(tgt_parent, src_parent):
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
188 for child in src_parent.childNodes:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
189 if child.nodeName == '#text':
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
190 continue
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
191 node = self.__get_unique_node(tgt_parent, child.nodeName, child.getAttribute("name"))
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
192 if not node: #The node is new
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
193 tgt_parent.appendChild(child)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
194 else:
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
195 import_node(node, child)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
196
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
197 import_node(self.dom.documentElement, src_dom.documentElement)
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
198
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
199 def __default_ok(self, value, name, category):
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
200 #FIXME: gof: will not work with individual parameters
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
201 self.setParam(name, value, category) #FIXME: better to set param xml value ???
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
202
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
203 def __default_ko(self, failure, name, category):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
204 error (_("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category':category, 'name':name, 'reason':str(failure.value)})
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
205
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
206 def setDefault(self, name, category, callback, errback=None):
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
207 """Set default value of parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
208 'default_cb' attibute of parameter must be set to 'yes'
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
209 @param name: name of the parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
210 @param category: category of the parameter
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
211 @param callback: must return a string with the value (use deferred if needed)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
212 @param errback: must manage the error with args failure, name, category
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
213 """
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
214 #TODO: send signal param update if value changed
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
215 node = self.__getParamNode(name, category, '@ALL@')
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
216 if not node:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
217 error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name':name, 'category':category})
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
218 return
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
219 if node[1].getAttribute('default_cb') == 'yes':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
220 del node[1].attributes['default_cb']
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
221 d = defer.maybeDeferred(callback)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
222 d.addCallback(self.__default_ok, name, category)
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
223 d.addErrback(errback or self.__default_ko, name, category)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
224
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
225 def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
226 """Helper method to get a specific attribute
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
227 @param name: name of the parameter
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
228 @param category: category of the parameter
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
229 @param attr: name of the attribute (default: "value")
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
230 @param profile: owner of the param (@ALL@ for everyone)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
231
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
232 @return: attribute"""
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
233 node = self.__getParamNode(name, category)
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
234 if not node:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
235 error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name':name, 'category':category})
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
236 return None
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
237
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
238 if node[0] == 'general':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
239 value = self.__getParam(None, category, name, 'general')
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
240 return value or node[1].getAttribute(attr)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
241
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
242 assert(node[0] == 'individual')
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
243
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
244 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
245 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
246 error(_('Requesting a param for an non-existant profile'))
276
a00e87d48213 bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents: 259
diff changeset
247 return ""
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
248
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
249 if attr == "value":
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
250 return self.__getParam(profile, category, name) or node[1].getAttribute(attr)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
251 else:
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
252 return node[1].getAttribute(attr)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
253
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
254
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
255 def __getParam(self, profile, category, name, type='individual'):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
256 """Return the param, or None if it doesn't exist
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
257 @param profile: the profile name (not profile key, i.e. name and not something like @DEFAULT@)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
258 @param category: param category
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
259 @param name: param name
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
260 """
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
261 if type == 'general':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
262 if self.params_gen.has_key((category, name)):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
263 return self.params_gen[(category, name)]
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
264 return None #This general param has the default value
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
265 assert (type == 'individual')
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
266 if not self.params.has_key(profile) or not self.params[profile].has_key((category, name)):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
267 return None
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
268 return self.params[profile][(category, name)]
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
269
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
270 def __constructProfileXml(self, profile):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
271 """Construct xml for asked profile, filling values when needed
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
272 /!\ as noticed in doc, don't forget to unlink the minidom.Document
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
273 @param profile: profile name (not key !)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
274 @return: minidom.Document of the profile xml (cf warning above)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
275 """
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
276 prof_xml = minidom.parseString('<params/>')
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
277
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
278 for type_node in self.dom.documentElement.childNodes:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
279 if type_node.nodeName == 'general' or type_node.nodeName == 'individual': #we use all params, general and individual
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
280 for cat_node in type_node.childNodes:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
281 if cat_node.nodeName == 'category':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
282 category = cat_node.getAttribute('name')
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
283 cat_copy = cat_node.cloneNode(True) #we make a copy for the new xml
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
284 params = cat_copy.getElementsByTagName("param")
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
285 for param_node in params:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
286 name = param_node.getAttribute('name')
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
287 profile_value = self.__getParam(profile, category, name, type_node.nodeName)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
288 if profile_value: #there is a value for this profile, we must change the default
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
289 param_node.setAttribute('value', profile_value)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
290 prof_xml.documentElement.appendChild(cat_copy)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
291 return prof_xml
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
292
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
293
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 106
diff changeset
294 def getParamsUI(self, profile_key='@DEFAULT@'):
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
295 """Return a SàT XMLUI for parameters, with given profile"""
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
296 profile = self.getProfileName(profile_key)
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
297 if not profile:
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
298 error(_("Asking params for inexistant profile"))
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
299 return ""
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
300 param_xml = self.getParams(profile)
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
301 return paramsXml2xmlUI(param_xml)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
302
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
303 def getParams(self, profile_key='@DEFAULT@'):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
304 """Construct xml for asked profile
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
305 Take params xml as skeleton"""
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
306 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
307 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
308 error(_("Asking params for inexistant profile"))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
309 return ""
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
310 prof_xml = self.__constructProfileXml(profile)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
311 return_xml = prof_xml.toxml()
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
312 prof_xml.unlink()
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
313
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
314 return return_xml
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
315
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
316 def getParamsForCategory(self, category, profile_key='@DEFAULT@'):
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
317 """Return node's xml for selected category"""
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
318 #TODO: manage category of general type (without existant profile)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
319 profile = self.getProfileName(profile_key)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
320 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
321 error(_("Asking params for inexistant profile"))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
322 return ""
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
323 prof_xml = self.__constructProfileXml(profile)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
324
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
325 for node in prof_xml.getElementsByTagName("category"):
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
326 if node.nodeName == "category" and node.getAttribute("name") == category:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
327 result = node.toxml()
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
328 prof_xml.unlink()
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
329 return result
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
330
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
331 prof_xml.unlink()
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
332 return "<category />"
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
333
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
334 def __getParamNode(self, name, category, type="@ALL@"): #FIXME: is type useful ?
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
335 """Return a node from the param_xml
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
336 @param name: name of the node
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
337 @param category: category of the node
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
338 @type: keyword for search:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
339 @ALL@ search everywhere
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
340 @GENERAL@ only search in general type
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
341 @INDIVIDUAL@ only search in individual type
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
342 @return: a tuple with the node type and the the node, or None if not found"""
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
343
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
344 for type_node in self.dom.documentElement.childNodes:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
345 if ( ((type == "@ALL@" or type == "@GENERAL@") and type_node.nodeName == 'general')
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
346 or ( (type == "@ALL@" or type == "@INDIVIDUAL@") and type_node.nodeName == 'individual') ):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
347 for node in type_node.getElementsByTagName('category'):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
348 if node.getAttribute("name") == category:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
349 params = node.getElementsByTagName("param")
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
350 for param in params:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
351 if param.getAttribute("name") == name:
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
352 return (type_node.nodeName, param)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
353 return None
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
354
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
355 def getParamsCategories(self):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
356 """return the categories availables"""
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
357 categories=[]
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
358 for cat in self.dom.getElementsByTagName("category"):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
359 categories.append(cat.getAttribute("name"))
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
360 return categories
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
361
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
362 def setParam(self, name, value, category, profile_key='@DEFAULT@'):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
363 """Set a parameter, return None if the parameter is not in param xml"""
197
ca1010f47002 core: fixed forgotten profile in paramUpdate signal
Goffi <goffi@goffi.org>
parents: 183
diff changeset
364 profile = self.getProfileName(profile_key)
ca1010f47002 core: fixed forgotten profile in paramUpdate signal
Goffi <goffi@goffi.org>
parents: 183
diff changeset
365 if not profile:
ca1010f47002 core: fixed forgotten profile in paramUpdate signal
Goffi <goffi@goffi.org>
parents: 183
diff changeset
366 error(_('Trying to set parameter for an unknown profile'))
ca1010f47002 core: fixed forgotten profile in paramUpdate signal
Goffi <goffi@goffi.org>
parents: 183
diff changeset
367 return #TODO: throw an error
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
368
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
369 node = self.__getParamNode(name, category, '@ALL@')
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
370 if not node:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
371 error(_('Requesting an unknown parameter (%(category)s/%(name)s)') % {'category':category, 'name':name})
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
372 return
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
373
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
374 if node[0] == 'general':
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
375 self.params_gen[(category, name)] = value
197
ca1010f47002 core: fixed forgotten profile in paramUpdate signal
Goffi <goffi@goffi.org>
parents: 183
diff changeset
376 self.host.bridge.paramUpdate(name, value, category, profile) #TODO: add profile in signal
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
377 return
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
378
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
379 assert (node[0] == 'individual')
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
380
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
381 type = node[1].getAttribute("type")
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
382 if type=="button":
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
383 print "clique",node.toxml()
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
384 else:
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
385 self.params[profile][(category, name)] = value
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
386 self.host.bridge.paramUpdate(name, value, category, profile) #TODO: add profile in signal
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
387
0
goffi@necton2
parents:
diff changeset
388 class Memory:
goffi@necton2
parents:
diff changeset
389 """This class manage all persistent informations"""
goffi@necton2
parents:
diff changeset
390
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
391 def __init__(self, host):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
392 info (_("Memory manager init"))
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
393 self.host = host
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
394 self.contacts={}
0
goffi@necton2
parents:
diff changeset
395 self.presenceStatus={}
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
396 self.subscriptions={}
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 21
diff changeset
397 self.params=Param(host)
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
398 self.history={} #used to store chat history (key: short jid)
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
399 self.private={} #used to store private value
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
400 self.server_features={} #used to store discovery's informations
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
401 self.server_identities={}
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
402 host.set_const('savefile_history', SAVEFILE_HISTORY)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
403 host.set_const('savefile_private', SAVEFILE_PRIVATE)
0
goffi@necton2
parents:
diff changeset
404 self.load()
goffi@necton2
parents:
diff changeset
405
goffi@necton2
parents:
diff changeset
406 def load(self):
goffi@necton2
parents:
diff changeset
407 """Load parameters and all memory things from file/db"""
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
408 param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
409 self.host.get_const('savefile_param_xml'))
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
410 param_file_data = os.path.expanduser(self.host.get_const('local_dir')+
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
411 self.host.get_const('savefile_param_data'))
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
412 history_file = os.path.expanduser(self.host.get_const('local_dir')+
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
413 self.host.get_const('savefile_history'))
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
414 private_file = os.path.expanduser(self.host.get_const('local_dir')+
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
415 self.host.get_const('savefile_private'))
0
goffi@necton2
parents:
diff changeset
416
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
417 #parameters
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
418 if os.path.exists(param_file_xml):
0
goffi@necton2
parents:
diff changeset
419 try:
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
420 self.params.load_xml(param_file_xml)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
421 debug(_("params template loaded"))
0
goffi@necton2
parents:
diff changeset
422 except:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
423 error (_("Can't load params template !"))
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
424 self.params.load_default_params()
0
goffi@necton2
parents:
diff changeset
425 else:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
426 info (_("No params template, using default template"))
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
427 self.params.load_default_params()
0
goffi@necton2
parents:
diff changeset
428
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
429 try:
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
430 self.params.load_data(param_file_data)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
431 debug(_("params loaded"))
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
432 except:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
433 error (_("Can't load params !"))
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
434
0
goffi@necton2
parents:
diff changeset
435 #history
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
436 if os.path.exists(history_file):
0
goffi@necton2
parents:
diff changeset
437 try:
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
438 with open(history_file, 'r') as history_pickle:
0
goffi@necton2
parents:
diff changeset
439 self.history=pickle.load(history_pickle)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
440 debug(_("history loaded"))
0
goffi@necton2
parents:
diff changeset
441 except:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
442 error (_("Can't load history !"))
0
goffi@necton2
parents:
diff changeset
443
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
444 #private
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
445 if os.path.exists(private_file):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
446 try:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
447 with open(private_file, 'r') as private_pickle:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
448 self.private=pickle.load(private_pickle)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
449 debug(_("private values loaded"))
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
450 except:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
451 error (_("Can't load private values !"))
0
goffi@necton2
parents:
diff changeset
452
goffi@necton2
parents:
diff changeset
453 def save(self):
goffi@necton2
parents:
diff changeset
454 """Save parameters and all memory things to file/db"""
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
455 #TODO: need to encrypt files (at least passwords !) and set permissions
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
456 param_file_xml = os.path.expanduser(self.host.get_const('local_dir')+
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
457 self.host.get_const('savefile_param_xml'))
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
458 param_file_data = os.path.expanduser(self.host.get_const('local_dir')+
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
459 self.host.get_const('savefile_param_data'))
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
460 history_file = os.path.expanduser(self.host.get_const('local_dir')+
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
461 self.host.get_const('savefile_history'))
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
462 private_file = os.path.expanduser(self.host.get_const('local_dir')+
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
463 self.host.get_const('savefile_private'))
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
464
61
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
465 self.params.save_xml(param_file_xml)
58d49fc19639 parameters are saved again
Goffi <goffi@goffi.org>
parents: 60
diff changeset
466 self.params.save_data(param_file_data)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
467 debug(_("params saved"))
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 38
diff changeset
468 with open(history_file, 'w') as history_pickle:
0
goffi@necton2
parents:
diff changeset
469 pickle.dump(self.history, history_pickle)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
470 debug(_("history saved"))
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
471 with open(private_file, 'w') as private_pickle:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
472 pickle.dump(self.private, private_pickle)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
473 debug(_("private values saved"))
0
goffi@necton2
parents:
diff changeset
474
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
475 def getProfilesList(self):
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
476 return self.params.getProfilesList()
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
477
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
478
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
479 def getProfileName(self, profile_key):
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
480 """Return name of profile from keyword
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
481 @param profile_key: can be the profile name or a keywork (like @DEFAULT@)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
482 @return: profile name or None if it doesn't exist"""
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
483 return self.params.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 61
diff changeset
484
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
485 def createProfile(self, name):
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
486 """Create a new profile
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
487 @param name: Profile name
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
488 """
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
489 return self.params.createProfile(name)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
490
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
491 def deleteProfile(self, name):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
492 """Delete an existing profile
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
493 @param name: Name of the profile"""
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
494 return self.params.deleteProfile(name)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 57
diff changeset
495
0
goffi@necton2
parents:
diff changeset
496 def addToHistory(self, me_jid, from_jid, to_jid, type, message):
goffi@necton2
parents:
diff changeset
497 me_short=me_jid.userhost()
goffi@necton2
parents:
diff changeset
498 from_short=from_jid.userhost()
goffi@necton2
parents:
diff changeset
499 to_short=to_jid.userhost()
goffi@necton2
parents:
diff changeset
500
goffi@necton2
parents:
diff changeset
501 if from_jid==me_jid:
goffi@necton2
parents:
diff changeset
502 key=to_short
goffi@necton2
parents:
diff changeset
503 else:
goffi@necton2
parents:
diff changeset
504 key=from_short
goffi@necton2
parents:
diff changeset
505
goffi@necton2
parents:
diff changeset
506 if not self.history.has_key(me_short):
goffi@necton2
parents:
diff changeset
507 self.history[me_short]={}
goffi@necton2
parents:
diff changeset
508 if not self.history[me_short].has_key(key):
goffi@necton2
parents:
diff changeset
509 self.history[me_short][key]={}
goffi@necton2
parents:
diff changeset
510
79
db0a0f000e37 Chat presentation enhancement
Goffi <goffi@goffi.org>
parents: 69
diff changeset
511 self.history[me_short][key][int(time.time())] = (from_jid.full(), message)
0
goffi@necton2
parents:
diff changeset
512
goffi@necton2
parents:
diff changeset
513 def getHistory(self, from_jid, to_jid, size):
goffi@necton2
parents:
diff changeset
514 ret={}
goffi@necton2
parents:
diff changeset
515 if not self.history.has_key(from_jid):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
516 error(_("source JID not found !"))
0
goffi@necton2
parents:
diff changeset
517 #TODO: throw an error here
goffi@necton2
parents:
diff changeset
518 return {}
goffi@necton2
parents:
diff changeset
519 if not self.history[from_jid].has_key(to_jid):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
520 error(_("dest JID not found !"))
0
goffi@necton2
parents:
diff changeset
521 #TODO: throw an error here
goffi@necton2
parents:
diff changeset
522 return {}
goffi@necton2
parents:
diff changeset
523 stamps=self.history[from_jid][to_jid].keys()
goffi@necton2
parents:
diff changeset
524 stamps.sort()
goffi@necton2
parents:
diff changeset
525 for stamp in stamps[-size:]:
goffi@necton2
parents:
diff changeset
526 ret[stamp]=self.history[from_jid][to_jid][stamp]
goffi@necton2
parents:
diff changeset
527
goffi@necton2
parents:
diff changeset
528 return ret
goffi@necton2
parents:
diff changeset
529
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
530 def setPrivate(self, key, value):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
531 """Save a misc private value (mainly useful for plugins)"""
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
532 self.private[key] = value
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
533
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
534 def getPrivate(self, key):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
535 """return a private value
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
536 @param key: name of wanted value
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
537 @return: value or None if value don't exist"""
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
538 if self.private.has_key(key):
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
539 return self.private[key]
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
540 return None
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
541
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
542 def addServerFeature(self, feature, profile):
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
543 """Add a feature discovered from server
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
544 @param feature: string of the feature
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
545 @param profile: which profile is using this server ?"""
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
546 if not self.server_features.has_key(profile):
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
547 self.server_features[profile] = []
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
548 self.server_features[profile].append(feature)
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
549
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
550 def addServerIdentity(self, category, type, entity, profile):
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
551 """Add an identity discovered from server
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
552 @param feature: string of the feature
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
553 @param profile: which profile is using this server ?"""
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
554 if not self.server_identities.has_key(profile):
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
555 self.server_identities[profile] = {}
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
556 if not self.server_identities[profile].has_key((category, type)):
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
557 self.server_identities[profile][(category, type)]=set()
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
558 self.server_identities[profile][(category, type)].add(entity)
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
559
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
560 def getServerServiceEntities(self, category, type, profile):
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
561 """Return all available entities for a service"""
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
562 if self.server_identities.has_key(profile):
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
563 return self.server_identities[profile].get((category, type), set())
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
564 else:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
565 return None
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
566
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 282
diff changeset
567 def getServerServiceEntity(self, category, type, profile):
318
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
568 """Helper method to get first available entity for a service"""
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
569 entities = self.getServerServiceEntities(category, type, profile)
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
570 if entities == None:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
571 warning(_("Entities not available, maybe they haven't been asked to server yet ?"))
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
572 return None
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
573 else:
b544bec477dd core: multiple identities with same category/type are now managed with getServerServiceEntities
Goffi <goffi@goffi.org>
parents: 305
diff changeset
574 return list(entities)[0] if entities else None
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
575
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
576 def hasServerFeature(self, feature, profile_key='@DEFAULT@'):
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
577 """Tell if the server of the profile has the required feature"""
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
578 profile = self.getProfileName(profile_key)
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
579 if not profile:
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
580 error (_('Trying find server feature for a non-existant profile'))
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
581 return
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
582 assert(self.server_features.has_key(profile))
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
583 return feature in self.server_features[profile]
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 276
diff changeset
584
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
585
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
586 def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
587 debug("Memory addContact: %s",contact_jid.userhost())
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
588 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
589 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
590 error (_('Trying to add a contact to a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
591 return
0
goffi@necton2
parents:
diff changeset
592 assert(isinstance(attributes,dict))
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 0
diff changeset
593 assert(isinstance(groups,set))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
594 if not self.contacts.has_key(profile):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
595 self.contacts[profile] = {}
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
596 self.contacts[profile][contact_jid.userhost()]=[attributes, groups]
0
goffi@necton2
parents:
diff changeset
597
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
598 def delContact(self, contact_jid, profile_key='@DEFAULT@'):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
599 debug("Memory delContact: %s",contact_jid.userhost())
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
600 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
601 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
602 error (_('Trying to delete a contact for a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
603 return
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
604 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
605 del self.contacts[profile][contact_jid.userhost()]
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
606
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
607 def getContact(self, contact_jid, profile_key='@DEFAULT@'):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
608 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
609 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
610 error(_('Asking a contact for a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
611 return None
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
612 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
613 self.contacts[profile][contact_jid.userhost()]
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
614 else:
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
615 return None
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
616
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
617 def getContacts(self, profile_key='@DEFAULT@'):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
618 """Return list of contacts for given profile
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
619 @param profile_key: profile key
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
620 @return list of [contact, attr, groups]"""
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
621 debug ("Memory getContact OK (%s)", self.contacts)
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
622 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
623 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
624 error(_('Asking contacts for a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
625 return []
0
goffi@necton2
parents:
diff changeset
626 ret=[]
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
627 for contact in self.contacts[profile]:
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
628 attr, groups = self.contacts[profile][contact]
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
629 ret.append([contact, attr, groups ])
0
goffi@necton2
parents:
diff changeset
630 return ret
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
631
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
632 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
633 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
634 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
635 error(_('Trying to add presence status to a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
636 return
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
637 if not self.presenceStatus.has_key(profile):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
638 self.presenceStatus[profile] = {}
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
639 if not self.presenceStatus[profile].has_key(contact_jid.userhost()):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
640 self.presenceStatus[profile][contact_jid.userhost()] = {}
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
641 resource = jid.parse(contact_jid.full())[2] or ''
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
642 self.presenceStatus[profile][contact_jid.userhost()][resource] = (show, priority, statuses)
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
643
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
644 def addWaitingSub(self, type, contact_jid, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
645 """Called when a subcription request is received"""
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
646 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
647 assert(profile)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
648 if not self.subscriptions.has_key(profile):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
649 self.subscriptions[profile] = {}
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
650 self.subscriptions[profile][contact_jid] = type
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
651
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
652 def delWaitingSub(self, contact_jid, profile_key):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
653 """Called when a subcription request is finished"""
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
654 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
655 assert(profile)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
656 if self.subscriptions.has_key(profile) and self.subscriptions[profile].has_key(contact_jid):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
657 del self.subscriptions[profile][contact_jid]
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
658
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
659 def getWaitingSub(self, profile_key='@DEFAULT@'):
47
9aa2d9dd4045 memory methods improvement
Goffi <goffi@goffi.org>
parents: 41
diff changeset
660 """Called to get a list of currently waiting subscription requests"""
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
661 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
662 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
663 error(_('Asking waiting subscriptions for a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
664 return {}
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
665 if not self.subscriptions.has_key(profile):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
666 return {}
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
667
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
668 return self.subscriptions[profile]
0
goffi@necton2
parents:
diff changeset
669
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
670 def getPresenceStatus(self, profile_key='@DEFAULT@'):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
671 profile = self.getProfileName(profile_key)
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
672 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
673 error(_('Asking contacts for a non-existant profile'))
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
674 return {}
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
675 if not self.presenceStatus.has_key(profile):
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
676 self.presenceStatus[profile] = {}
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
677 debug ("Memory getPresenceStatus (%s)", self.presenceStatus[profile])
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
678 return self.presenceStatus[profile]
0
goffi@necton2
parents:
diff changeset
679
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
680 def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
681 return self.params.getParamA(name, category, attr, profile_key)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
682
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
683 def getParamsUI(self, profile_key='@DEFAULT@'):
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
684 return self.params.getParamsUI(profile_key)
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
685
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
686 def getParams(self, profile_key='@DEFAULT@'):
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 79
diff changeset
687 return self.params.getParams(profile_key)
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
688
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
689 def getParamsForCategory(self, category, profile_key='@DEFAULT@'):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
690 return self.params.getParamsForCategory(category, profile_key)
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
691
0
goffi@necton2
parents:
diff changeset
692 def getParamsCategories(self):
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
693 return self.params.getParamsCategories()
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 14
diff changeset
694
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
695 def setParam(self, name, value, category, profile_key='@DEFAULT@'):
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
696 return self.params.setParam(name, value, category, profile_key)
19
f2a745ca0fbc refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
697
38
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
698 def importParams(self, xml):
3e24753b9e0b Fixed parameters loading/saving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
699 return self.params.importParams(xml)
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
700
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
701 def setDefault(self, name, category, callback, errback=None):
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
702 return self.params.setDefault(name, category, callback, errback)