Show warning icon when encryption is disabled

'channel-insecure-symbolic' icon if no encryption is selected

'channel-secure-symbolic' if an encryption is selected
This commit is contained in:
Philipp Hörist 2017-06-12 23:32:59 +02:00
parent f7754487cc
commit 9dc389cc32
4 changed files with 26 additions and 2 deletions

View File

@ -287,6 +287,7 @@ class ChatControl(ChatControlBase):
self.encryption_menu = self.xml.get_object('encryption_menu')
self.encryption_menu.set_menu_model(
gui_menu_builder.get_encryption_menu(self.contact, self.type_id))
self.set_encryption_menu_icon()
# restore previous conversation
self.restore_conversation()
self.msg_textview.grab_focus()

View File

@ -36,6 +36,7 @@ from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gio
import gtkgui_helpers
from gtkgui_helpers import Color
import message_control
import dialogs
import history_window
@ -442,6 +443,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.terminate_esessions()
action.set_state(param)
self.set_encryption_state(encryption)
self.set_encryption_menu_icon()
self.set_lock_image()
def set_encryption_state(self, encryption):
@ -455,6 +457,19 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
state = gajim.config.get_per('encryption', config_key, 'encryption')
return state or None
def set_encryption_menu_icon(self):
for child in self.encryption_menu.get_children():
if isinstance(child, Gtk.Image):
image = child
break
if not self.encryption:
icon = gtkgui_helpers.get_icon_pixmap(
'channel-insecure-symbolic', color=[Color.BLACK])
else:
icon = gtkgui_helpers.get_icon_pixmap('channel-secure-symbolic')
image.set_from_pixbuf(icon)
def set_speller(self):
# now set the one the user selected
per_type = 'contacts'

View File

@ -493,6 +493,7 @@ class GroupchatControl(ChatControlBase):
self.encryption_menu = self.xml.get_object('encryption_menu')
self.encryption_menu.set_menu_model(
gui_menu_builder.get_encryption_menu(self.contact, self.type_id))
self.set_encryption_menu_icon()
gajim.ged.register_event_handler('gc-presence-received', ged.GUI1,
self._nec_gc_presence_received)

View File

@ -53,9 +53,16 @@ from common import configpaths
gtk_icon_theme = Gtk.IconTheme.get_default()
gtk_icon_theme.append_search_path(gajim.ICONS_DIR)
def get_icon_pixmap(icon_name, size=16, quiet=False):
class Color:
BLACK = Gdk.RGBA(red=0, green=0, blue=0, alpha=1)
def get_icon_pixmap(icon_name, size=16, color=None, quiet=False):
try:
return gtk_icon_theme.load_icon(icon_name, size, 0)
iconinfo = gtk_icon_theme.lookup_icon(icon_name, size, 0)
if color:
pixbuf, was_symbolic = iconinfo.load_symbolic(*color)
return pixbuf
return iconinfo.load_icon()
except GLib.GError as e:
if not quiet:
log.error('Unable to load icon %s: %s' % (icon_name, str(e)))