annotate frontends/quick_frontend/quick_app.py @ 70:8f2ed279784b

i18n - gettext support added in frontends - first draft of frontends french translation
author Goffi <goffi@goffi.org>
date Fri, 05 Mar 2010 20:33:10 +1100
parents 9b842086d915
children efe81b61673c
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 helper class for making a SAT frontend
57
a5b5fb5fc9fd updated README and copyright note
Goffi <goffi@goffi.org>
parents: 53
diff changeset
6 Copyright (C) 2009, 2010 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 logging import debug, info, error
goffi@necton2
parents:
diff changeset
23 from tools.jid import JID
goffi@necton2
parents:
diff changeset
24 from sat_bridge_frontend.DBus import DBusBridgeFrontend
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
25 import pdb
0
goffi@necton2
parents:
diff changeset
26
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
27 import gettext
Goffi <goffi@goffi.org>
parents: 68
diff changeset
28 gettext.install('sat_frontend', "../i18n", unicode=True)
Goffi <goffi@goffi.org>
parents: 68
diff changeset
29
0
goffi@necton2
parents:
diff changeset
30 class QuickApp():
goffi@necton2
parents:
diff changeset
31 """This class contain the main methods needed for the frontend"""
goffi@necton2
parents:
diff changeset
32
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
33 def __init__(self, single_profile=True):
0
goffi@necton2
parents:
diff changeset
34 self.rosterList = {}
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
35 self.profiles = {}
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
36 self.single_profile = single_profile
0
goffi@necton2
parents:
diff changeset
37
goffi@necton2
parents:
diff changeset
38 ## bridge ##
goffi@necton2
parents:
diff changeset
39 self.bridge=DBusBridgeFrontend()
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
40 self.bridge.register("connected", self.connected)
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
41 self.bridge.register("disconnected", self.disconnected)
0
goffi@necton2
parents:
diff changeset
42 self.bridge.register("newContact", self.newContact)
goffi@necton2
parents:
diff changeset
43 self.bridge.register("newMessage", self.newMessage)
goffi@necton2
parents:
diff changeset
44 self.bridge.register("presenceUpdate", self.presenceUpdate)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
45 self.bridge.register("subscribe", self.subscribe)
0
goffi@necton2
parents:
diff changeset
46 self.bridge.register("paramUpdate", self.paramUpdate)
goffi@necton2
parents:
diff changeset
47 self.bridge.register("contactDeleted", self.contactDeleted)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
48 self.bridge.register("updatedValue", self.updatedValue, "request")
0
goffi@necton2
parents:
diff changeset
49 self.bridge.register("askConfirmation", self.askConfirmation, "request")
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
50 self.bridge.register("actionResult", self.actionResult, "request")
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
51 self.bridge.register("actionResultExt", self.actionResult, "request")
0
goffi@necton2
parents:
diff changeset
52
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
53 self.current_action_ids = set()
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
54 self.current_action_ids_cb = {}
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
55
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
56 def __check_profile(self, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
57 """Tell if the profile is currently followed by the application"""
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
58 return profile in self.profiles.keys()
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
59
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
60 def plug_profile(self, profile_key='@DEFAULT@'):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
61 """Tell application which profile must be used"""
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
62 if self.single_profile and self.profiles:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
63 error(_('There is already one profile plugged (we are in single profile mode) !'))
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
64 return
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
65 profile = self.bridge.getProfileName(profile_key)
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
66 if not profile:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
67 error(_("The profile asked doesn't exist"))
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
68 return
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
69 if self.profiles.has_key(profile):
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
70 warning(_("The profile is already plugged"))
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
71 return
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
72 self.profiles[profile]={}
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
73 if self.single_profile:
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
74 self.profile = profile
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
75
0
goffi@necton2
parents:
diff changeset
76 ###now we get the essential params###
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
77 self.profiles[profile]['whoami']=JID(self.bridge.getParamA("JabberID","Connection", profile))
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
78 self.profiles[profile]['watched']=self.bridge.getParamA("Watched", "Misc", profile).split() #TODO: put this in a plugin
0
goffi@necton2
parents:
diff changeset
79
goffi@necton2
parents:
diff changeset
80 ## misc ##
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
81 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary
0
goffi@necton2
parents:
diff changeset
82
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
83 #TODO: managed multi-profiles here
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
84 if self.bridge.isConnected(profile):
0
goffi@necton2
parents:
diff changeset
85 self.setStatusOnline(True)
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
86 else:
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
87 self.setStatusOnline(False)
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
88 return
0
goffi@necton2
parents:
diff changeset
89
goffi@necton2
parents:
diff changeset
90 ### now we fill the contact list ###
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
91 for contact in self.bridge.getContacts(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
92 self.newContact(contact[0], contact[1], contact[2], profile)
0
goffi@necton2
parents:
diff changeset
93
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
94 presences = self.bridge.getPresenceStatus(profile)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
95 for contact in presences:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
96 for res in presences[contact]:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
97 jabber_id = contact+('/'+res if res else '')
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
98 show = presences[contact][res][0]
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
99 priority = presences[contact][res][1]
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
100 statuses = presences[contact][res][2]
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
101 self.presenceUpdate(jabber_id, show, priority, statuses, profile)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
102
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
103 waitingSub = self.bridge.getWaitingSub(profile)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
104 for sub in waitingSub:
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
105 self.subscribe(waitingSub[sub], sub, profile)
0
goffi@necton2
parents:
diff changeset
106
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
107 def unplug_profile(self, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
108 """Tell the application to not follow anymore the profile"""
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
109 if not profile in self.profiles:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
110 warning (_("This profile is not plugged"))
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
111 return
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
112 self.profiles.remove(profile)
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
113
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
114 def clear_profile(self):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
115 self.profiles.clear()
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
116
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
117 def connected(self, profile):
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
118 """called when the connection is made"""
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
119 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
120 return
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
121 debug(_("Connected"))
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
122 self.setStatusOnline(True)
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
123
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
124 def disconnected(self, profile):
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
125 """called when the connection is closed"""
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
126 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
127 return
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
128 debug(_("Disconnected"))
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
129 self.CM.clear()
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
130 self.contactList.clear_contacts()
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
131 self.setStatusOnline(False)
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
132
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
133 def newContact(self, JabberId, attributes, groups, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
134 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
135 return
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
136 entity=JID(JabberId)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
137 self.rosterList[entity.short]=(dict(attributes), list(groups))
0
goffi@necton2
parents:
diff changeset
138
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
139 def newMessage(self, from_jid, msg, type, to_jid, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
140 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
141 return
0
goffi@necton2
parents:
diff changeset
142 sender=JID(from_jid)
goffi@necton2
parents:
diff changeset
143 addr=JID(to_jid)
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
144 win = addr if sender.short == self.profiles[profile]['whoami'].short else sender
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
145 self.current_action_ids = set()
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
146 self.current_action_ids_cb = {}
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
147 self.chat_wins[win.short].printMessage(sender, msg, profile)
0
goffi@necton2
parents:
diff changeset
148
goffi@necton2
parents:
diff changeset
149 def setStatusOnline(self, online=True):
goffi@necton2
parents:
diff changeset
150 pass
goffi@necton2
parents:
diff changeset
151
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
152 def presenceUpdate(self, jabber_id, show, priority, statuses, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
153 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
154 return
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
155 print "check ok"
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
156 debug (_("presence update for %(jid)s (show=%(show)s, statuses=%(statuses)s)") % {'jid':jabber_id, 'show':show, 'statuses':statuses});
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
157 from_jid=JID(jabber_id)
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
158 debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short})
0
goffi@necton2
parents:
diff changeset
159
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
160 if from_jid.short==self.profiles[profile]['whoami'].short:
0
goffi@necton2
parents:
diff changeset
161 if not type:
goffi@necton2
parents:
diff changeset
162 self.setStatusOnline(True)
goffi@necton2
parents:
diff changeset
163 elif type=="unavailable":
goffi@necton2
parents:
diff changeset
164 self.setStatusOnline(False)
goffi@necton2
parents:
diff changeset
165 return
goffi@necton2
parents:
diff changeset
166
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
167 if show != 'unavailable':
0
goffi@necton2
parents:
diff changeset
168 name=""
53
6dfe5bb10008 Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents: 52
diff changeset
169 groups = []
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
170 if self.rosterList.has_key(from_jid.short):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
171 if self.rosterList[from_jid.short][0].has_key("name"):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
172 name=self.rosterList[from_jid.short][0]["name"]
53
6dfe5bb10008 Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents: 52
diff changeset
173 groups=self.rosterList[from_jid.short][1]
0
goffi@necton2
parents:
diff changeset
174
goffi@necton2
parents:
diff changeset
175 #FIXME: must be moved in a plugin
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
176 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
177 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short)
0
goffi@necton2
parents:
diff changeset
178
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
179 self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
180 self.CM.add(from_jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
181 self.CM.update(from_jid, 'name', name)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
182 self.CM.update(from_jid, 'show', show)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
183 self.CM.update(from_jid, 'statuses', statuses)
53
6dfe5bb10008 Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents: 52
diff changeset
184 self.CM.update(from_jid, 'groups', groups)
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 57
diff changeset
185 cache = self.bridge.getCardCache(from_jid)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
186 if cache.has_key('nick'):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
187 self.CM.update(from_jid, 'nick', cache['nick'])
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
188 if cache.has_key('avatar'):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
189 self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar']))
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
190 self.contactList.replace(from_jid)
0
goffi@necton2
parents:
diff changeset
191
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
192 if show=="unavailable" and from_jid in self.profiles[profile]['onlineContact']:
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
193 self.profiles[profile]['onlineContact'].remove(from_jid)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
194 self.CM.remove(from_jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
195 if not self.CM.isConnected(from_jid):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
196 self.contactList.disconnect(from_jid)
0
goffi@necton2
parents:
diff changeset
197
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
198 def subscribe(self, type, raw_jid, profile):
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
199 """Called when a subsciption maangement signal is received"""
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
200 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
201 return
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
202 entity = JID(raw_jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
203 if type=="subscribed":
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
204 # this is a subscription confirmation, we just have to inform user
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
205 self.showDialog(_("The contact %s has accepted your subscription") % entity.short, _('Subscription confirmation'))
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
206 elif type=="unsubscribed":
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
207 # this is a subscription refusal, we just have to inform user
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
208 self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error')
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
209 elif type=="subscribe":
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
210 # this is a subscriptionn request, we have to ask for user confirmation
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
211 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no')
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
212 if answer:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
213 self.bridge.subscription("subscribed", entity.short)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
214 else:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
215 self.bridge.subscribed("unsubscribed", entity.short)
0
goffi@necton2
parents:
diff changeset
216
goffi@necton2
parents:
diff changeset
217 def showDialog(self, message, title, type="info"):
goffi@necton2
parents:
diff changeset
218 raise NotImplementedError
goffi@necton2
parents:
diff changeset
219
goffi@necton2
parents:
diff changeset
220 def showAlert(self, message):
goffi@necton2
parents:
diff changeset
221 pass #FIXME
goffi@necton2
parents:
diff changeset
222
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
223 def paramUpdate(self, name, value, namespace, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
224 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
225 return
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
226 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value})
0
goffi@necton2
parents:
diff changeset
227 if (namespace,name) == ("Connection", "JabberID"):
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
228 debug (_("Changing JID to %s"), value)
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
229 self.profiles[profile]['whoami']=JID(value)
0
goffi@necton2
parents:
diff changeset
230 elif (namespace,name) == ("Misc", "Watched"):
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
231 self.profiles[profile]['watched']=value.split()
0
goffi@necton2
parents:
diff changeset
232
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
233 def contactDeleted(self, jid, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
234 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
235 return
0
goffi@necton2
parents:
diff changeset
236 target = JID(jid)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
237 self.CM.remove(target)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
238 self.contactList.remove(self.CM.get_full(target))
0
goffi@necton2
parents:
diff changeset
239 try:
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
240 self.profiles[profile]['onlineContact'].remove(target.short)
0
goffi@necton2
parents:
diff changeset
241 except KeyError:
goffi@necton2
parents:
diff changeset
242 pass
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
243
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
244 def updatedValue(self, name, data, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
245 if not self.__check_profile(profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
246 return
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
247 if name == "card_nick":
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
248 target = JID(data['jid'])
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
249 self.CM.update(target, 'nick', data['nick'])
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
250 self.contactList.replace(target)
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
251 elif name == "card_avatar":
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
252 target = JID(data['jid'])
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
253 filename = self.bridge.getAvatarFile(data['avatar'])
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
254 self.CM.update(target, 'avatar', filename)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
255 self.contactList.replace(target)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
256
0
goffi@necton2
parents:
diff changeset
257 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
258 raise NotImplementedError
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
259
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
260 def actionResult(self, type, id, data):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
261 raise NotImplementedError