| ... |
... |
@@ -14,6 +14,7 @@ |
|
14
|
14
|
from gajim.common import ged
|
|
15
|
15
|
from gajim.common.const import AvatarSize
|
|
16
|
16
|
from gajim.common.const import StyleAttr
|
|
|
17
|
+from gajim.common.const import PresenceShowExt
|
|
17
|
18
|
from gajim.common.helpers import jid_is_blocked
|
|
18
|
19
|
from gajim.common.helpers import event_filter
|
|
19
|
20
|
from gajim.common.i18n import _
|
| ... |
... |
@@ -39,6 +40,7 @@ class Column(IntEnum): |
|
39
|
40
|
TEXT = 1
|
|
40
|
41
|
IS_CONTACT = 2
|
|
41
|
42
|
JID_OR_GROUP = 3
|
|
|
43
|
+ VISIBLE = 4
|
|
42
|
44
|
|
|
43
|
45
|
|
|
44
|
46
|
class Roster(Gtk.ScrolledWindow, EventHelper):
|
| ... |
... |
@@ -86,6 +88,11 @@ def __init__(self, account): |
|
86
|
88
|
('roster-push', ged.GUI2, self._on_roster_push),
|
|
87
|
89
|
])
|
|
88
|
90
|
|
|
|
91
|
+ self._modelfilter = self._store.filter_new()
|
|
|
92
|
+ self._modelfilter.set_visible_func(self._visible_func)
|
|
|
93
|
+ self._filter_enabled = False
|
|
|
94
|
+ self._filter_string = ''
|
|
|
95
|
+
|
|
89
|
96
|
self._add_actions()
|
|
90
|
97
|
self._initial_draw()
|
|
91
|
98
|
|
| ... |
... |
@@ -147,8 +154,7 @@ def _on_theme_update(self, _event): |
|
147
|
154
|
def _show_offline(self, action, param):
|
|
148
|
155
|
action.set_state(param)
|
|
149
|
156
|
app.settings.set('showoffline', param.get_boolean())
|
|
150
|
|
- print('_show_offline')
|
|
151
|
|
- print(param.get_boolean())
|
|
|
157
|
+ self._draw_contacts()
|
|
152
|
158
|
|
|
153
|
159
|
def _contact_info(self, _action, param):
|
|
154
|
160
|
app.window.contact_info(self._account, param.get_string())
|
| ... |
... |
@@ -211,12 +217,43 @@ def _show_contact_menu(self, jid, treeview, event): |
|
211
|
217
|
popover.set_pointing_to(rectangle)
|
|
212
|
218
|
popover.popup()
|
|
213
|
219
|
|
|
|
220
|
+ def set_search_string(self, text):
|
|
|
221
|
+ self._filter_string = text
|
|
|
222
|
+ self._filter_enabled = bool(text)
|
|
|
223
|
+ self._draw_contacts()
|
|
|
224
|
+
|
|
|
225
|
+ def _get_contact_visible(self, contact):
|
|
|
226
|
+ if self._filter_enabled:
|
|
|
227
|
+ return self._filter_string in contact.name.lower()
|
|
|
228
|
+
|
|
|
229
|
+ if app.settings.get('showoffline'):
|
|
|
230
|
+ return True
|
|
|
231
|
+
|
|
|
232
|
+ if contact.show is PresenceShowExt.OFFLINE:
|
|
|
233
|
+ return False
|
|
|
234
|
+
|
|
|
235
|
+ return True
|
|
|
236
|
+
|
|
|
237
|
+ def _visible_func(self, model, iter_, _data):
|
|
|
238
|
+ visible = model[iter_][Column.VISIBLE]
|
|
|
239
|
+ is_contact = model[iter_][Column.IS_CONTACT]
|
|
|
240
|
+ name = model[iter_][Column.TEXT]
|
|
|
241
|
+
|
|
|
242
|
+ if not is_contact:
|
|
|
243
|
+ # Always show groups
|
|
|
244
|
+ return True
|
|
|
245
|
+
|
|
|
246
|
+ if self._filter_enabled:
|
|
|
247
|
+ return self._filter_string in name.lower()
|
|
|
248
|
+
|
|
|
249
|
+ return visible
|
|
|
250
|
+
|
|
214
|
251
|
def set_model(self):
|
|
215
|
|
- self._roster.set_model(self._store)
|
|
|
252
|
+ self._roster.set_model(self._modelfilter)
|
|
216
|
253
|
|
|
217
|
254
|
def redraw(self):
|
|
218
|
255
|
self._roster.set_model(None)
|
|
219
|
|
- self._roster.set_model(self._store)
|
|
|
256
|
+ self._roster.set_model(self._modelfilter)
|
|
220
|
257
|
self._roster.expand_all()
|
|
221
|
258
|
|
|
222
|
259
|
def _reset(self):
|
| ... |
... |
@@ -274,7 +311,7 @@ def _add_group(self, group_name): |
|
274
|
311
|
return group_iter
|
|
275
|
312
|
|
|
276
|
313
|
group_iter = self._store.append(
|
|
277
|
|
- None, (None, group_name, False, group_name))
|
|
|
314
|
+ None, (None, group_name, False, group_name, True))
|
|
278
|
315
|
group_path = self._store.get_path(group_iter)
|
|
279
|
316
|
group_ref = Gtk.TreeRowReference(self._store, group_path)
|
|
280
|
317
|
self._group_refs[group_name] = group_ref
|
| ... |
... |
@@ -284,7 +321,7 @@ def _add_contact_to_group(self, contact, group): |
|
284
|
321
|
group_iter = self._add_group(group)
|
|
285
|
322
|
iter_ = self._store.append(
|
|
286
|
323
|
group_iter,
|
|
287
|
|
- (None, contact.name, True, str(contact.jid)))
|
|
|
324
|
+ (None, contact.name, True, str(contact.jid), True))
|
|
288
|
325
|
|
|
289
|
326
|
ref = Gtk.TreeRowReference(self._store, self._store.get_path(iter_))
|
|
290
|
327
|
self._contact_refs[contact.jid].append(ref)
|
| ... |
... |
@@ -357,6 +394,12 @@ def _draw_group(self, group_name): |
|
357
|
394
|
group_name += f' ({group_users}/{total_users})'
|
|
358
|
395
|
|
|
359
|
396
|
self._store[group_iter][Column.TEXT] = group_name
|
|
|
397
|
+ self._store[group_iter][Column.VISIBLE] = True
|
|
|
398
|
+
|
|
|
399
|
+ def _draw_contacts(self):
|
|
|
400
|
+ for jid in self._contact_refs:
|
|
|
401
|
+ self._draw_contact(self._get_contact(jid))
|
|
|
402
|
+ self._roster.expand_all()
|
|
360
|
403
|
|
|
361
|
404
|
def _draw_contact(self, contact):
|
|
362
|
405
|
for ref in self._contact_refs[contact.jid]:
|
| ... |
... |
@@ -369,6 +412,8 @@ def _draw_contact_row(self, ref, contact): |
|
369
|
412
|
if jid_is_blocked(self._account, contact.jid):
|
|
370
|
413
|
name = f'<span strikethrough="true">{name}</span>'
|
|
371
|
414
|
self._store[iter_][Column.TEXT] = name
|
|
|
415
|
+ visible = self._get_contact_visible(contact)
|
|
|
416
|
+ self._store[iter_][Column.VISIBLE] = visible
|
|
372
|
417
|
|
|
373
|
418
|
surface = contact.get_avatar(
|
|
374
|
419
|
AvatarSize.ROSTER, self.get_scale_factor())
|
| ... |
... |
@@ -446,6 +491,7 @@ def clear(self): |
|
446
|
491
|
self._store.clear()
|
|
447
|
492
|
|
|
448
|
493
|
def _on_presence_received(self, event):
|
|
|
494
|
+ # TODO: self.draw_contacts() if contact changes status
|
|
449
|
495
|
pass
|
|
450
|
496
|
|
|
451
|
497
|
def process_event(self, event):
|