Commit 6830dec3 authored by Daniel Brötzmann's avatar Daniel Brötzmann
Browse files

StartChat: Use ChatFilter widget

parent 34aa3837
......@@ -176,44 +176,7 @@
<property name="can-focus">False</property>
<property name="transition-duration">100</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<child>
<object class="GtkToggleButton" id="filter_chats">
<property name="label" translatable="yes">Chats</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="active">True</property>
<signal name="toggled" handler="_on_filter_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkToggleButton" id="filter_groupchats">
<property name="label" translatable="yes">Group Chats</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="active">True</property>
<signal name="toggled" handler="_on_filter_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<style>
<class name="linked"/>
</style>
</object>
<placeholder/>
</child>
</object>
<packing>
......
# This file is part of Gajim.
#
# Gajim is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 only.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import GObject
from gi.repository import Gtk
from gajim.common.i18n import _
class ChatFilter(Gtk.Box):
__gsignals__ = {
'filter-changed': (GObject.SignalFlags.RUN_LAST,
None,
(str, )),
}
def __init__(self):
Gtk.Box.__init__(self)
self.set_halign(Gtk.Align.CENTER)
toolbar = Gtk.Toolbar()
all_button = Gtk.RadioToolButton.new_from_widget(None)
all_button.set_label(_('All'))
all_button.set_name('all')
all_button.connect('clicked', self._on_button_clicked)
toolbar.insert(all_button, 1)
chats_button = Gtk.RadioToolButton.new_from_widget(all_button)
chats_button.set_label(_('Chats'))
chats_button.set_name('chats')
chats_button.connect('clicked', self._on_button_clicked)
toolbar.insert(chats_button, 2)
group_chats_button = Gtk.RadioToolButton.new_from_widget(all_button)
group_chats_button.set_label(_('Group Chats'))
group_chats_button.set_name('group_chats')
group_chats_button.connect('clicked', self._on_button_clicked)
toolbar.insert(group_chats_button, 3)
self.add(toolbar)
self.show_all()
def _on_button_clicked(self, button):
if button.get_active():
self.emit('filter-changed', button.get_name())
......@@ -34,6 +34,7 @@
from gajim.common.const import MUC_DISCO_ERRORS
from gajim.common.modules.util import as_task
from .chat_filter import ChatFilter
from .groupchat_info import GroupChatInfoScrolled
from .groupchat_nick import NickChooser
from .util import get_builder
......@@ -103,6 +104,12 @@ def __init__(self):
self._ui.infobar.set_revealed(app.settings.get('show_help_start_chat'))
self._current_filter = 'all'
self._chat_filter = ChatFilter()
self._chat_filter.connect(
'filter-changed', self._on_chat_filter_changed)
self._ui.filter_bar_revealer.add(self._chat_filter)
self.connect('key-press-event', self._on_key_press)
self.connect('destroy', self._destroy)
......@@ -287,7 +294,8 @@ def _on_filter_bar_toggled(self, toggle_button):
active = toggle_button.get_active()
self._ui.filter_bar_revealer.set_reveal_child(active)
def _on_filter_toggled(self, _toggle_button):
def _on_chat_filter_changed(self, _filter, name):
self._current_filter = name
self._ui.listbox.invalidate_filter()
def _start_new_chat(self, row):
......@@ -507,11 +515,10 @@ def _filter_func(self, row, _user_data):
search_text_list = search_text.split()
row_text = row.get_search_text().lower()
show_chats = self._ui.filter_chats.get_active()
show_groupchats = self._ui.filter_groupchats.get_active()
if row.groupchat and not show_groupchats:
if self._current_filter == 'chats' and row.groupchat:
return False
if not row.groupchat and not show_chats:
if self._current_filter == 'group_chats' and not row.groupchat:
return False
for text in search_text_list:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment