Add option to show chatstate in roster

- Preferences: Add options for display in banner, tab, roster
- This makes the chatstate Plugin obsolete
This commit is contained in:
Philipp Hörist 2018-11-20 15:31:45 +01:00
parent b74468b9c3
commit 15c3de2b4d
6 changed files with 137 additions and 69 deletions

View File

@ -669,19 +669,14 @@ class ChatControl(ChatControlBase):
status_reduced = ''
status_escaped = GLib.markup_escape_text(status_reduced)
st = app.config.get('displayed_chat_state_notifications')
if self.TYPE_ID == 'pm':
cs = self.gc_contact.chatstate
else:
cs = app.contacts.get_combined_chatstate(
self.account, self.contact.jid)
if cs and st in ('composing_only', 'all'):
if contact.show == 'offline':
chatstate = ''
elif st == 'all' or cs == 'composing':
chatstate = helpers.get_uf_chatstate(cs)
else:
chatstate = ''
if app.config.get('show_chatstate_in_banner'):
chatstate = helpers.get_uf_chatstate(cs)
label_text = '<span>%s</span><span size="x-small" weight="light">%s %s</span>' \
% (name, acct_info, chatstate)

View File

@ -187,7 +187,6 @@ class Config:
'always_english_wiktionary': [opt_bool, True],
'remote_control': [opt_bool, False, _('If checked, Gajim can be controlled remotely using gajim-remote.'), True],
'outgoing_chat_state_notifications': [opt_str, 'all', _('Sent chat state notifications. Can be one of all, composing_only, disabled.')],
'displayed_chat_state_notifications': [opt_str, 'all', _('Displayed chat state notifications in chat windows. Can be one of all, composing_only, disabled.')],
'autodetect_browser_mailer': [opt_bool, True, '', True],
'print_ichat_every_foo_minutes': [opt_int, 5, _('When not printing time for every message (print_time==sometimes), print it every x minutes.')],
'confirm_close_muc': [opt_bool, True, _('Ask before closing a group chat tab/window.')],
@ -296,6 +295,9 @@ class Config:
'public_room_sync_threshold': [opt_int, 1, _('Maximum history in days we request from a public room archive. 0: As much as possible')],
'private_room_sync_threshold': [opt_int, 0, _('Maximum history in days we request from a private room archive. 0: As much as possible')],
'show_subject_on_join': [opt_bool, True, _('If the room subject is shown in chat on join')],
'show_chatstate_in_roster': [opt_bool, True, _('If the contact row is colored according to the current chatstate of the contact')],
'show_chatstate_in_tabs': [opt_bool, True, _('If the tab is colored according to the current chatstate of the contact')],
'show_chatstate_in_banner': [opt_bool, True, _('Shows a text in the banner that describes the current chatstate of the contact')],
}, {}) # type: Tuple[Dict[str, List[Any]], Dict[Any, Any]]
__options_per_key = {

View File

@ -737,43 +737,6 @@
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Gajim can send and receive meta-information related to a conversation you may have with a contact. Here you can specify which chatstates you want to display in chat windows.</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Display chat state notifications</property>
<property name="use_underline">True</property>
<property name="justify">right</property>
<property name="mnemonic_widget">displayed_chat_states_combobox</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="displayed_chat_states_combobox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="model">display_chat_state_notifications_liststore</property>
<signal name="changed" handler="on_displayed_chat_states_combobox_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -802,6 +765,100 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkCheckButton" id="show_chatstate_in_tabs">
<property name="label" translatable="yes">Show chatstate in tabs</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If checked, the tab will be colored according to the current chatstate of the contact</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_show_chatstate_in_tabs_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="GtkCheckButton" id="show_chatstate_in_roster">
<property name="label" translatable="yes">Show chatstate in roster</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If checked, the contact row will be colored according to the current chatstate of the contact</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_show_chatstate_in_roster_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="show_chatstate_in_banner">
<property name="label" translatable="yes">Show chatstate in banner</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If checked, a desciption of the contacts current chatstate is shown in the banner</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_show_chatstate_in_banner_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Chatstate</property>
<style>
<class name="bold"/>
<class name="margin-top6"/>
</style>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="name">chat</property>

View File

@ -157,13 +157,14 @@ class Preferences(Gtk.ApplicationWindow):
self._ui.print_status_in_muc_combobox.set_active(2)
# Displayed chat state notifications
st = app.config.get('displayed_chat_state_notifications')
if st == 'all':
self._ui.displayed_chat_states_combobox.set_active(0)
elif st == 'composing_only':
self._ui.displayed_chat_states_combobox.set_active(1)
else: # disabled
self._ui.displayed_chat_states_combobox.set_active(2)
st = app.config.get('show_chatstate_in_tabs')
self._ui.show_chatstate_in_tabs.set_active(st)
st = app.config.get('show_chatstate_in_roster')
self._ui.show_chatstate_in_roster.set_active(st)
st = app.config.get('show_chatstate_in_banner')
self._ui.show_chatstate_in_banner.set_active(st)
### Notifications tab ###
## Visual Notifications
@ -612,15 +613,14 @@ class Preferences(Gtk.ApplicationWindow):
else: # in_and_out
app.config.set('print_status_in_muc', 'in_and_out')
def on_displayed_chat_states_combobox_changed(self, widget):
active = widget.get_active()
if active == 0: # all
app.config.set('displayed_chat_state_notifications', 'all')
elif active == 1: # only composing
app.config.set('displayed_chat_state_notifications',
'composing_only')
else: # disabled
app.config.set('displayed_chat_state_notifications', 'disabled')
def on_show_chatstate_in_tabs_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_chatstate_in_tabs')
def on_show_chatstate_in_roster_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_chatstate_in_roster')
def on_show_chatstate_in_banner_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_chatstate_in_banner')
### Notifications tab ###
def on_systray_combobox_changed(self, widget):

View File

@ -652,7 +652,9 @@ class MessageWindow:
if isinstance(ctrl, ChatControl):
tab_label_str = ctrl.get_tab_label()
# Set Label Color
gtkgui_helpers.add_css_class(nick_label, chatstate, 'gajim-state-')
if app.config.get('show_chatstate_in_tabs'):
gtkgui_helpers.add_css_class(
nick_label, chatstate, 'gajim-state-')
else:
tab_label_str, color = ctrl.get_tab_label(chatstate)
# Set Label Color

View File

@ -4639,6 +4639,11 @@ class RosterWindow:
gtkgui_helpers.set_unset_urgency_hint(self.window, nb_unread)
def _nec_chatstate_received(self, event):
if event.contact.is_gc_contact or event.contact.is_pm_contact:
return
self.draw_contact(event.contact.jid, event.account)
def _style_changed(self, *args):
self.change_roster_style(None)
@ -4741,17 +4746,22 @@ class RosterWindow:
return
jid = model[titer][Column.JID]
account = model[titer][Column.ACCOUNT]
color = None
if type_ == 'groupchat':
ctrl = app.interface.minimized_controls[account].get(jid,
None)
ctrl = app.interface.minimized_controls[account].get(jid, None)
if ctrl and ctrl.attention_flag:
color = app.css_config.get_value(
'.state_muc_directed_msg_color', StyleAttr.COLOR)
renderer.set_property('foreground', color)
if not color:
color = app.css_config.get_value('.gajim-contact-row', StyleAttr.COLOR)
renderer.set_property('foreground', color)
elif app.config.get('show_chatstate_in_roster'):
chatstate = app.contacts.get_combined_chatstate(account, jid)
if chatstate not in (None, 'active'):
color = app.css_config.get_value(
'.gajim-state-%s' % chatstate, StyleAttr.COLOR)
else:
color = app.css_config.get_value(
'.gajim-contact-row', StyleAttr.COLOR)
renderer.set_property('foreground', color)
self._set_contact_row_background_color(renderer, jid, account)
desc = app.css_config.get_font('.gajim-contact-row')
@ -5886,3 +5896,5 @@ class RosterWindow:
self._nec_blocking)
app.ged.register_event_handler('style-changed', ged.GUI1,
self._style_changed)
app.ged.register_event_handler('chatstate-received', ged.GUI1,
self._nec_chatstate_received)