Commit b6c26e57 authored by Philipp Hörist's avatar Philipp Hörist

StartChat: Integrate Groupchat info

parent 5586a209
This diff is collapsed.
......@@ -227,6 +227,7 @@ list.settings > row > box {
/* Padding/Margins */
.margin-top6 { margin-top: 6px; }
.margin-12 { margin: 12px; }
.margin-18 { margin: 18px; }
/* Treeview */
treeview.space { padding: 6px; }
......
......@@ -27,11 +27,6 @@ from gajim.gtk.dialogs import InformationDialog
Message = namedtuple('Message', ['title', 'text', 'dialog'])
messages = {
'start-chat-not-connected': Message(
_('You are not connected to the server'),
_('You can not start a new conversation unless you are connected.'),
ErrorDialog),
'invalid-jid-with-error': Message(
_('Invalid JID'),
'%s',
......
......@@ -93,9 +93,10 @@ MUC_FEATURES = {
class GroupChatInfoScrolled(Gtk.ScrolledWindow):
def __init__(self, account):
def __init__(self, account=None):
Gtk.ScrolledWindow.__init__(self)
self.set_size_request(400, -1)
self.set_vexpand(True)
self.set_min_content_height(400)
self.set_policy(Gtk.PolicyType.NEVER,
Gtk.PolicyType.AUTOMATIC)
......@@ -105,6 +106,9 @@ class GroupChatInfoScrolled(Gtk.ScrolledWindow):
self._ui.connect_signals(self)
self.show_all()
def set_account(self, account):
self._account = account
def set_author(self, author, epoch_timestamp=None):
if not author:
return
......@@ -181,6 +185,11 @@ class GroupChatInfoScrolled(Gtk.ScrolledWindow):
def _add_features(self, features):
grid = self._ui.info_grid
for row in range(30, 9, -1):
# Remove everything from row 30 to 10
# We probably will never have 30 rows and
# there is no method to count grid rows
grid.remove_row(row)
features = list(features)
has_mam = NS_MAM_2 in features or NS_MAM_1 in features
......
......@@ -20,6 +20,8 @@ from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import Pango
from nbxmpp.protocol import InvalidJid
from nbxmpp.protocol import JID
from nbxmpp.util import is_error_result
from nbxmpp.const import AnonymityMode
......@@ -27,7 +29,9 @@ from gajim.common import app
from gajim.common import helpers
from gajim.common.i18n import _
from gajim.common.const import AvatarSize
from gajim.common.const import MUC_DISCO_ERRORS
from gajim.gtk.groupchat_info import GroupChatInfoScrolled
from gajim.gtk.util import get_icon_name
from gajim.gtk.util import get_builder
from gajim.gtk.util import ensure_not_destroyed
......@@ -56,7 +60,7 @@ class StartChatDialog(Gtk.ApplicationWindow):
self._search_stopped = False
self._ui = get_builder('start_chat_dialog.ui')
self.add(self._ui.box)
self.add(self._ui.stack)
self.new_contact_row_visible = False
self.new_contact_rows = {}
......@@ -81,10 +85,14 @@ class StartChatDialog(Gtk.ApplicationWindow):
self._muc_search_listbox = MUCSearch()
self._current_listbox = self._ui.listbox
self._muc_info_box = GroupChatInfoScrolled()
self._ui.info_box.add(self._muc_info_box)
self.connect('key-press-event', self._on_key_press)
self.connect('destroy', self._destroy)
self.select_first_row()
self._ui.connect_signals(self)
self.show_all()
def set_search_text(self, text):
......@@ -131,59 +139,126 @@ class StartChatDialog(Gtk.ApplicationWindow):
self._start_new_chat(row)
def _on_key_press(self, widget, event):
is_search = self._ui.stack.get_visible_child_name() == 'search'
if event.keyval in (Gdk.KEY_Down, Gdk.KEY_Tab):
self._ui.search_entry.emit('next-match')
return True
if is_search:
self._ui.search_entry.emit('next-match')
return Gdk.EVENT_STOP
return Gdk.EVENT_PROPAGATE
if (event.state == Gdk.ModifierType.SHIFT_MASK and
event.keyval == Gdk.KEY_ISO_Left_Tab):
self._ui.search_entry.emit('previous-match')
return True
if is_search:
self._ui.search_entry.emit('previous-match')
return Gdk.EVENT_STOP
return Gdk.EVENT_PROPAGATE
if event.keyval == Gdk.KEY_Up:
self._ui.search_entry.emit('previous-match')
return True
if is_search:
self._ui.search_entry.emit('previous-match')
return Gdk.EVENT_STOP
return Gdk.EVENT_PROPAGATE
if event.keyval == Gdk.KEY_Escape:
if self._ui.stack.get_visible_child_name() == 'progress':
self.destroy()
return Gdk.EVENT_STOP
if self._ui.stack.get_visible_child_name() in ('error', 'info'):
self._ui.stack.set_visible_child_name('search')
return Gdk.EVENT_STOP
self._search_stopped = True
self._muc_search_listbox.remove_all()
if self._ui.search_entry.get_text() != '':
self._ui.search_entry.emit('stop-search')
else:
self.destroy()
return True
return Gdk.EVENT_STOP
if event.keyval == Gdk.KEY_Return:
if self._ui.stack.get_visible_child_name() == 'progress':
return Gdk.EVENT_STOP
if self._ui.stack.get_visible_child_name() == 'error':
self._ui.stack.set_visible_child_name('search')
return Gdk.EVENT_STOP
if self._ui.stack.get_visible_child_name() == 'info':
self._on_join_clicked()
return Gdk.EVENT_STOP
if self._current_listbox_is(Search.MUC):
self._muc_search_listbox.remove_all()
self._start_search()
return True
return Gdk.EVENT_STOP
row = self._ui.listbox.get_selected_row()
if row is not None:
row.emit('activate')
return True
return Gdk.EVENT_STOP
self._ui.search_entry.grab_focus_without_selecting()
if is_search:
self._ui.search_entry.grab_focus_without_selecting()
return Gdk.EVENT_PROPAGATE
def _start_new_chat(self, row):
if row.new:
if not app.account_is_connected(row.account):
app.interface.raise_dialog('start-chat-not-connected')
return
try:
helpers.parse_jid(row.jid)
except helpers.InvalidFormat as e:
app.interface.raise_dialog('invalid-jid-with-error', str(e))
JID(row.jid)
except InvalidJid as error:
self._show_error_page(str(error))
return
if row.groupchat:
app.interface.join_gc_minimal(row.account, row.jid)
if not app.account_is_connected(row.account):
self._show_error_page(_('You can not join a group chat '
'unless you are connected.'))
return
self._disco_muc(row.account, row.jid)
else:
app.interface.new_chat_from_jid(row.account, row.jid)
self.ready_to_destroy = True
def _disco_muc(self, account, jid):
self._ui.stack.set_visible_child_name('progress')
con = app.connections[account]
con.get_module('Discovery').disco_info(
jid, callback=self._disco_info_received, user_data=account)
@ensure_not_destroyed
def _disco_info_received(self, result, account):
if is_error_result(result):
self._set_error(result)
elif result.is_muc:
self._muc_info_box.set_account(account)
self._muc_info_box.set_from_disco_info(result)
self._ui.stack.set_visible_child_name('info')
else:
self._set_error_from_code('not-muc-service')
def _set_error(self, error):
text = MUC_DISCO_ERRORS.get(error.type, str(error))
self._show_error_page(text)
def _set_error_from_code(self, error_code):
self._show_error_page(MUC_DISCO_ERRORS[error_code])
def _show_error_page(self, text):
self._ui.error_label.set_text(text)
self._ui.stack.set_visible_child_name('error')
def _on_join_clicked(self, _button=None):
row = self._ui.listbox.get_selected_row().get_child()
app.interface.join_gc_minimal(row.account, row.jid)
self.ready_to_destroy = True
def _on_back_clicked(self, _button):
self._ui.stack.set_visible_child_name('search')
def _set_listbox(self, listbox):
if self._current_listbox == listbox:
return
......
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