Add mobile phone indicator
Shows a mobile phone icon if the last message was received by a client which identifies as phone
This commit is contained in:
		
							parent
							
								
									c2038b0ffe
								
							
						
					
					
						commit
						1f5be6cb0f
					
				
					 5 changed files with 55 additions and 11 deletions
				
			
		| 
						 | 
					@ -235,6 +235,8 @@ class ChatControl(ChatControlBase):
 | 
				
			||||||
            self._on_tune_received)
 | 
					            self._on_tune_received)
 | 
				
			||||||
        app.ged.register_event_handler('location-received', ged.GUI1,
 | 
					        app.ged.register_event_handler('location-received', ged.GUI1,
 | 
				
			||||||
            self._on_location_received)
 | 
					            self._on_location_received)
 | 
				
			||||||
 | 
					        app.ged.register_event_handler('update-client-info', ged.GUI1,
 | 
				
			||||||
 | 
					            self._on_update_client_info)
 | 
				
			||||||
        if self.TYPE_ID == message_control.TYPE_CHAT:
 | 
					        if self.TYPE_ID == message_control.TYPE_CHAT:
 | 
				
			||||||
            # Dont connect this when PrivateChatControl is used
 | 
					            # Dont connect this when PrivateChatControl is used
 | 
				
			||||||
            app.ged.register_event_handler('update-roster-avatar', ged.GUI1,
 | 
					            app.ged.register_event_handler('update-roster-avatar', ged.GUI1,
 | 
				
			||||||
| 
						 | 
					@ -476,6 +478,14 @@ class ChatControl(ChatControlBase):
 | 
				
			||||||
        self.parent_win.redraw_tab(self)
 | 
					        self.parent_win.redraw_tab(self)
 | 
				
			||||||
        self.parent_win.show_title()
 | 
					        self.parent_win.show_title()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ensure_proper_control
 | 
				
			||||||
 | 
					    def _on_update_client_info(self, event):
 | 
				
			||||||
 | 
					        contact = app.contacts.get_contact(
 | 
				
			||||||
 | 
					            self.account, event.jid, event.resource)
 | 
				
			||||||
 | 
					        if contact is None:
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					        self.xml.get_object('phone_image').set_visible(contact.uses_phone)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _update_jingle(self, jingle_type):
 | 
					    def _update_jingle(self, jingle_type):
 | 
				
			||||||
        if jingle_type not in ('audio', 'video'):
 | 
					        if jingle_type not in ('audio', 'video'):
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
| 
						 | 
					@ -1093,6 +1103,8 @@ class ChatControl(ChatControlBase):
 | 
				
			||||||
            self._on_tune_received)
 | 
					            self._on_tune_received)
 | 
				
			||||||
        app.ged.remove_event_handler('location-received', ged.GUI1,
 | 
					        app.ged.remove_event_handler('location-received', ged.GUI1,
 | 
				
			||||||
            self._on_location_received)
 | 
					            self._on_location_received)
 | 
				
			||||||
 | 
					        app.ged.remove_event_handler('update-client-info', ged.GUI1,
 | 
				
			||||||
 | 
					            self._on_update_client_info)
 | 
				
			||||||
        if self.TYPE_ID == message_control.TYPE_CHAT:
 | 
					        if self.TYPE_ID == message_control.TYPE_CHAT:
 | 
				
			||||||
            app.ged.remove_event_handler('update-roster-avatar', ged.GUI1,
 | 
					            app.ged.remove_event_handler('update-roster-avatar', ged.GUI1,
 | 
				
			||||||
                self._nec_update_avatar)
 | 
					                self._nec_update_avatar)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,6 +78,14 @@ def client_supports(client_caps, requested_feature):
 | 
				
			||||||
        return requested_feature not in FEATURE_BLACKLIST
 | 
					        return requested_feature not in FEATURE_BLACKLIST
 | 
				
			||||||
    return False
 | 
					    return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_client_identity(client_caps):
 | 
				
			||||||
 | 
					    lookup_item = client_caps.get_cache_lookup_strategy()
 | 
				
			||||||
 | 
					    cache_item = lookup_item(capscache)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for identity in cache_item.identities:
 | 
				
			||||||
 | 
					        if identity.get('category') == 'client':
 | 
				
			||||||
 | 
					            return identity.get('type')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def create_suitable_client_caps(node, caps_hash, hash_method, fjid=None):
 | 
					def create_suitable_client_caps(node, caps_hash, hash_method, fjid=None):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Create and return a suitable ClientCaps object for the given node,
 | 
					    Create and return a suitable ClientCaps object for the given node,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -127,6 +127,10 @@ class CommonContact(XMPPEntity):
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
        return caps_cache.client_supports(self.client_caps, requested_feature)
 | 
					        return caps_cache.client_supports(self.client_caps, requested_feature)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @property
 | 
				
			||||||
 | 
					    def uses_phone(self):
 | 
				
			||||||
 | 
					        return caps_cache.get_client_identity(self.client_caps) == 'phone'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Contact(CommonContact):
 | 
					class Contact(CommonContact):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -172,6 +172,11 @@ class Message:
 | 
				
			||||||
            'gc_control': gc_control
 | 
					            'gc_control': gc_control
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        app.nec.push_incoming_event(NetworkEvent('update-client-info',
 | 
				
			||||||
 | 
					                                                 account=self._account,
 | 
				
			||||||
 | 
					                                                 jid=jid,
 | 
				
			||||||
 | 
					                                                 resource=resource))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        event = MessageReceivedEvent(None, **event_attr)
 | 
					        event = MessageReceivedEvent(None, **event_attr)
 | 
				
			||||||
        app.nec.push_incoming_event(event)
 | 
					        app.nec.push_incoming_event(event)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -407,12 +407,13 @@
 | 
				
			||||||
                      </packing>
 | 
					                      </packing>
 | 
				
			||||||
                    </child>
 | 
					                    </child>
 | 
				
			||||||
                    <child>
 | 
					                    <child>
 | 
				
			||||||
                      <object class="GtkBox" id="banner_vbox">
 | 
					                      <object class="GtkGrid">
 | 
				
			||||||
                        <property name="visible">True</property>
 | 
					                        <property name="visible">True</property>
 | 
				
			||||||
                        <property name="can_focus">False</property>
 | 
					                        <property name="can_focus">False</property>
 | 
				
			||||||
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
 | 
					                        <property name="valign">center</property>
 | 
				
			||||||
                        <property name="border_width">5</property>
 | 
					                        <property name="margin_left">5</property>
 | 
				
			||||||
                        <property name="orientation">vertical</property>
 | 
					                        <property name="hexpand">True</property>
 | 
				
			||||||
 | 
					                        <property name="row_spacing">2</property>
 | 
				
			||||||
                        <child>
 | 
					                        <child>
 | 
				
			||||||
                          <object class="GtkLabel" id="banner_name_label">
 | 
					                          <object class="GtkLabel" id="banner_name_label">
 | 
				
			||||||
                            <property name="name">ChatControl-BannerNameLabel</property>
 | 
					                            <property name="name">ChatControl-BannerNameLabel</property>
 | 
				
			||||||
| 
						 | 
					@ -423,9 +424,9 @@
 | 
				
			||||||
                            <property name="xalign">0</property>
 | 
					                            <property name="xalign">0</property>
 | 
				
			||||||
                          </object>
 | 
					                          </object>
 | 
				
			||||||
                          <packing>
 | 
					                          <packing>
 | 
				
			||||||
                            <property name="expand">True</property>
 | 
					                            <property name="left_attach">0</property>
 | 
				
			||||||
                            <property name="fill">True</property>
 | 
					                            <property name="top_attach">0</property>
 | 
				
			||||||
                            <property name="position">0</property>
 | 
					                            <property name="width">2</property>
 | 
				
			||||||
                          </packing>
 | 
					                          </packing>
 | 
				
			||||||
                        </child>
 | 
					                        </child>
 | 
				
			||||||
                        <child>
 | 
					                        <child>
 | 
				
			||||||
| 
						 | 
					@ -433,6 +434,7 @@
 | 
				
			||||||
                            <property name="name">ChatControl-BannerLabel</property>
 | 
					                            <property name="name">ChatControl-BannerLabel</property>
 | 
				
			||||||
                            <property name="visible">True</property>
 | 
					                            <property name="visible">True</property>
 | 
				
			||||||
                            <property name="can_focus">False</property>
 | 
					                            <property name="can_focus">False</property>
 | 
				
			||||||
 | 
					                            <property name="hexpand">True</property>
 | 
				
			||||||
                            <property name="label">label</property>
 | 
					                            <property name="label">label</property>
 | 
				
			||||||
                            <property name="use_markup">True</property>
 | 
					                            <property name="use_markup">True</property>
 | 
				
			||||||
                            <property name="selectable">True</property>
 | 
					                            <property name="selectable">True</property>
 | 
				
			||||||
| 
						 | 
					@ -440,14 +442,27 @@
 | 
				
			||||||
                            <signal name="populate-popup" handler="on_banner_label_populate_popup" swapped="no"/>
 | 
					                            <signal name="populate-popup" handler="on_banner_label_populate_popup" swapped="no"/>
 | 
				
			||||||
                          </object>
 | 
					                          </object>
 | 
				
			||||||
                          <packing>
 | 
					                          <packing>
 | 
				
			||||||
                            <property name="expand">True</property>
 | 
					                            <property name="left_attach">1</property>
 | 
				
			||||||
                            <property name="fill">True</property>
 | 
					                            <property name="top_attach">1</property>
 | 
				
			||||||
                            <property name="position">1</property>
 | 
					                          </packing>
 | 
				
			||||||
 | 
					                        </child>
 | 
				
			||||||
 | 
					                        <child>
 | 
				
			||||||
 | 
					                          <object class="GtkImage" id="phone_image">
 | 
				
			||||||
 | 
					                            <property name="can_focus">False</property>
 | 
				
			||||||
 | 
					                            <property name="no_show_all">True</property>
 | 
				
			||||||
 | 
					                            <property name="tooltip_text" translatable="yes">The last message was written on a mobile client</property>
 | 
				
			||||||
 | 
					                            <property name="halign">start</property>
 | 
				
			||||||
 | 
					                            <property name="margin_right">4</property>
 | 
				
			||||||
 | 
					                            <property name="icon_name">phone-apple-iphone-symbolic</property>
 | 
				
			||||||
 | 
					                          </object>
 | 
				
			||||||
 | 
					                          <packing>
 | 
				
			||||||
 | 
					                            <property name="left_attach">0</property>
 | 
				
			||||||
 | 
					                            <property name="top_attach">1</property>
 | 
				
			||||||
                          </packing>
 | 
					                          </packing>
 | 
				
			||||||
                        </child>
 | 
					                        </child>
 | 
				
			||||||
                      </object>
 | 
					                      </object>
 | 
				
			||||||
                      <packing>
 | 
					                      <packing>
 | 
				
			||||||
                        <property name="expand">True</property>
 | 
					                        <property name="expand">False</property>
 | 
				
			||||||
                        <property name="fill">True</property>
 | 
					                        <property name="fill">True</property>
 | 
				
			||||||
                        <property name="position">1</property>
 | 
					                        <property name="position">1</property>
 | 
				
			||||||
                      </packing>
 | 
					                      </packing>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue