Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits:
4 changed files:
- gajim/gtk/chat_list.py
- gajim/gtk/chat_list_stack.py
- gajim/gtk/main.py
- gajim/gtk/workspace_side_bar.py
Changes:
| ... | ... | @@ -37,10 +37,19 @@ def __init__(self, workspace_id): |
| 37 | 37 |
|
| 38 | 38 |
self.show_all()
|
| 39 | 39 |
|
| 40 |
+ def get_unread_count(self):
|
|
| 41 |
+ return sum([chats.unread_count for chats in self._chats.values()])
|
|
| 42 |
+ |
|
| 43 |
+ def emit_unread_changed(self):
|
|
| 44 |
+ count = self.get_unread_count()
|
|
| 45 |
+ self.get_parent().emit('unread-count-changed',
|
|
| 46 |
+ self._workspace_id,
|
|
| 47 |
+ count)
|
|
| 48 |
+ |
|
| 40 | 49 |
def is_visible(self):
|
| 41 | 50 |
return self.get_parent().get_property('child-widget') == self
|
| 42 | 51 |
|
| 43 |
- def _on_destroy(self):
|
|
| 52 |
+ def _on_destroy(self, *args):
|
|
| 44 | 53 |
GLib.source_remove(self._timer_id)
|
| 45 | 54 |
|
| 46 | 55 |
def _update_timer(self):
|
| ... | ... | @@ -220,6 +229,16 @@ def __init__(self, workspace_id, account, jid, type_): |
| 220 | 229 |
|
| 221 | 230 |
self.show_all()
|
| 222 | 231 |
|
| 232 |
+ @property
|
|
| 233 |
+ def unread_count(self):
|
|
| 234 |
+ return self._unread_count
|
|
| 235 |
+ |
|
| 236 |
+ @unread_count.setter
|
|
| 237 |
+ def unread_count(self, value):
|
|
| 238 |
+ self._unread_count = value
|
|
| 239 |
+ self._update_unread()
|
|
| 240 |
+ self.get_parent().emit_unread_changed()
|
|
| 241 |
+ |
|
| 223 | 242 |
@property
|
| 224 | 243 |
def is_active(self):
|
| 225 | 244 |
return (self.is_selected() and
|
| ... | ... | @@ -241,23 +260,19 @@ def update_time(self): |
| 241 | 260 |
get_uf_relative_time(self._timestamp))
|
| 242 | 261 |
|
| 243 | 262 |
def _update_unread(self):
|
| 244 |
- print('Update unread', self.account, self.jid, self._unread_count)
|
|
| 245 | 263 |
if self._unread_count < 1000:
|
| 246 | 264 |
self._ui.unread_label.set_text(str(self._unread_count))
|
| 247 | 265 |
else:
|
| 248 | 266 |
self._ui.unread_label.set_text('999+')
|
| 249 |
- self._ui.unread_label.set_text(str(self._unread_count))
|
|
| 250 | 267 |
self._ui.unread_label.set_visible(bool(self._unread_count))
|
| 251 | 268 |
|
| 252 | 269 |
def add_unread(self):
|
| 253 | 270 |
if self.is_active:
|
| 254 | 271 |
return
|
| 255 |
- self._unread_count += 1
|
|
| 256 |
- self._update_unread()
|
|
| 272 |
+ self.unread_count += 1
|
|
| 257 | 273 |
|
| 258 | 274 |
def reset_unread(self):
|
| 259 |
- self._unread_count = 0
|
|
| 260 |
- self._update_unread()
|
|
| 275 |
+ self.unread_count = 0
|
|
| 261 | 276 |
|
| 262 | 277 |
def set_last_message_text(self, nickname, text):
|
| 263 | 278 |
self._ui.message_label.set_text(text)
|
| 1 | 1 |
|
| 2 | 2 |
from gi.repository import Gtk
|
| 3 |
+from gi.repository import GObject
|
|
| 3 | 4 |
|
| 4 | 5 |
from gajim.common import app
|
| 5 | 6 |
|
| ... | ... | @@ -14,6 +15,13 @@ |
| 14 | 15 |
|
| 15 | 16 |
|
| 16 | 17 |
class ChatListStack(Gtk.Stack):
|
| 18 |
+ |
|
| 19 |
+ __gsignals__ = {
|
|
| 20 |
+ 'unread-count-changed': (GObject.SignalFlags.RUN_LAST,
|
|
| 21 |
+ None,
|
|
| 22 |
+ (str, int)),
|
|
| 23 |
+ }
|
|
| 24 |
+ |
|
| 17 | 25 |
def __init__(self, main_window, ui, chat_stack):
|
| 18 | 26 |
Gtk.Stack.__init__(self)
|
| 19 | 27 |
self.set_hexpand(True)
|
| ... | ... | @@ -49,7 +49,7 @@ def __init__(self): |
| 49 | 49 |
self._ui.chat_list_scrolled.add(self._chat_list_stack)
|
| 50 | 50 |
|
| 51 | 51 |
self._account_side_bar = AccountSideBar()
|
| 52 |
- self._workspace_side_bar = WorkspaceSideBar()
|
|
| 52 |
+ self._workspace_side_bar = WorkspaceSideBar(self._chat_list_stack)
|
|
| 53 | 53 |
|
| 54 | 54 |
surface = load_icon('org.gajim.Gajim', self, 40)
|
| 55 | 55 |
self._ui.app_image.set_from_surface(surface)
|
| ... | ... | @@ -107,7 +107,6 @@ def __init__(self): |
| 107 | 107 |
('muc-configuration-finished', ged.GUI1, self._on_event),
|
| 108 | 108 |
('muc-configuration-failed', ged.GUI1, self._on_event),
|
| 109 | 109 |
('update-room-avatar', ged.GUI1, self._on_event),
|
| 110 |
- ('message-sent', ged.OUT_POSTCORE, self._on_event),
|
|
| 111 | 110 |
('message-error', ged.GUI1, self._on_event),
|
| 112 | 111 |
])
|
| 113 | 112 |
|
| ... | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 |
|
| 11 | 11 |
|
| 12 | 12 |
class WorkspaceSideBar(Gtk.ListBox):
|
| 13 |
- def __init__(self):
|
|
| 13 |
+ def __init__(self, chat_list_stack):
|
|
| 14 | 14 |
Gtk.ListBox.__init__(self)
|
| 15 | 15 |
self.set_vexpand(True)
|
| 16 | 16 |
self.set_valign(Gtk.Align.START)
|
| ... | ... | @@ -20,8 +20,14 @@ def __init__(self): |
| 20 | 20 |
self.connect('button-press-event', self._on_button_press)
|
| 21 | 21 |
self.connect('row-activated', self._on_row_activated)
|
| 22 | 22 |
|
| 23 |
+ chat_list_stack.connect('unread-count-changed',
|
|
| 24 |
+ self._on_unread_count_changed)
|
|
| 23 | 25 |
self._workspaces = {}
|
| 24 | 26 |
|
| 27 |
+ def _on_unread_count_changed(self, _chat_list_stack, workspace_id, count):
|
|
| 28 |
+ workspace = self._workspaces[workspace_id]
|
|
| 29 |
+ workspace.set_unread_count(count)
|
|
| 30 |
+ |
|
| 25 | 31 |
@staticmethod
|
| 26 | 32 |
def _sort_func(child1, child2):
|
| 27 | 33 |
if child1.sort_index < child2.sort_index:
|
| ... | ... | @@ -92,7 +98,6 @@ def __init__(self, workspace_id): |
| 92 | 98 |
CommonWorkspace.__init__(self, workspace_id)
|
| 93 | 99 |
|
| 94 | 100 |
self.sort_index = 0
|
| 95 |
- self._unread_count = 0
|
|
| 96 | 101 |
|
| 97 | 102 |
self._unread_label = Gtk.Label()
|
| 98 | 103 |
self._unread_label.get_style_context().add_class(
|
| ... | ... | @@ -111,31 +116,15 @@ def __init__(self, workspace_id): |
| 111 | 116 |
self.add(overlay)
|
| 112 | 117 |
self.show_all()
|
| 113 | 118 |
|
| 114 |
- @property
|
|
| 115 |
- def is_active(self):
|
|
| 116 |
- return (self.is_selected() and
|
|
| 117 |
- self.get_toplevel().get_property('is-active'))
|
|
| 118 |
- |
|
| 119 | 119 |
def update_avatar(self):
|
| 120 | 120 |
self._image.update()
|
| 121 | 121 |
|
| 122 |
- def _update_unread(self):
|
|
| 123 |
- print('Update unread', self.workspace_id, self._unread_count)
|
|
| 124 |
- if self._unread_count < 1000:
|
|
| 125 |
- self._unread_label.set_text(str(self._unread_count))
|
|
| 122 |
+ def set_unread_count(self, count):
|
|
| 123 |
+ if count < 1000:
|
|
| 124 |
+ self._unread_label.set_text(str(count))
|
|
| 126 | 125 |
else:
|
| 127 | 126 |
self._unread_label.set_text('999+')
|
| 128 |
- self._unread_label.set_visible(bool(self._unread_count))
|
|
| 129 |
- |
|
| 130 |
- def add_unread(self):
|
|
| 131 |
- if self.is_active:
|
|
| 132 |
- return
|
|
| 133 |
- self._unread_count += 1
|
|
| 134 |
- self._update_unread()
|
|
| 135 |
- |
|
| 136 |
- def reset_unread(self):
|
|
| 137 |
- self._unread_count = 0
|
|
| 138 |
- self._update_unread()
|
|
| 127 |
+ self._unread_label.set_visible(bool(count))
|
|
| 139 | 128 |
|
| 140 | 129 |
|
| 141 | 130 |
class AddWorkspace(CommonWorkspace):
|