From 8945173e51ac5638c76f7c798f81324bec231592 Mon Sep 17 00:00:00 2001
From: Dimitur Kirov <dkirov@gmail.com>
Date: Wed, 1 Mar 2006 11:03:56 +0000
Subject: [PATCH] update banner font with theme font

---
 src/chat_control.py        | 39 +++++++++++++++++++++++++++++++-------
 src/common/config.py       |  4 +++-
 src/common/optparser.py    |  3 ++-
 src/config.py              |  7 ++++++-
 src/gajim_themes_window.py |  9 +++++++--
 5 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/src/chat_control.py b/src/chat_control.py
index 3cfa7231bc..6d27e6b5bd 100644
--- a/src/chat_control.py
+++ b/src/chat_control.py
@@ -747,7 +747,7 @@ class ChatControl(ChatControlBase):
 
 	def notify_on_new_messages(self):
 		return gajim.config.get('trayicon_notification_on_new_messages')
-
+	
 	def on_avatar_eventbox_enter_notify_event(self, widget, event):
 		'''we enter the eventbox area so we under conditions add a timeout
 		to show a bigger avatar after 0.5 sec'''
@@ -833,7 +833,7 @@ class ChatControl(ChatControlBase):
 
 	def draw_banner(self, chatstate = None):
 		'''Draw the fat line at the top of the window that 
-		houses the status icon, name, jid, and avatar.  The chatstate arg should
+		houses the status icon, name, jid.  The chatstate arg should
 		only be used if the control's chatstate member is NOT to be use, such as
 		composing, paused, etc.
 		'''
@@ -870,6 +870,30 @@ class ChatControl(ChatControlBase):
 		#label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
 		#	% (name, fulljid)
 		
+		# get banner font settings
+		theme = gajim.config.get('roster_theme')
+		bannerfont = gajim.config.get_per('themes', theme, 'bannerfont')
+		bannerfontattrs = gajim.config.get_per('themes', theme, 'bannerfontattrs')
+		
+		if bannerfont:
+			font = pango.FontDescription(bannerfont)
+		else:
+			font = pango.FontDescription('Normal')
+		if bannerfontattrs:
+			# B is attribute set by default
+			if 'B' in bannerfontattrs:
+				font.set_weight(pango.WEIGHT_HEAVY)
+			if 'I' in bannerfontattrs:
+				font.set_style(pango.STYLE_ITALIC)
+		
+		font_attrs = 'font_desc="%s"' % font.to_string()
+		font_size = font.get_size()
+		
+		# in case there is no font specified we use x-large font size
+		if font_size == 0:
+			font_size = 'x-large'
+			font_attrs = '%s size="%s"' % (font_attrs, font_size)
+		
 		st = gajim.config.get('chat_state_notifications')
 		cs = contact.chatstate
 		if cs and st in ('composing_only', 'all'):
@@ -884,18 +908,19 @@ class ChatControl(ChatControlBase):
 				else:
 					chatstate = ''
 			label_text = \
-			'<span weight="heavy" size="x-large">%s</span>%s %s' % \
-				(name, acct_info, chatstate)
+			'<span %s>%s</span>%s %s' % \
+				(font_attrs, name, acct_info, chatstate)
 		else:
-			label_text = '<span weight="heavy" size="x-large">%s</span>%s' % \
-					(name, acct_info)
+			# weight="heavy" size="x-large"
+			label_text = '<span %s>%s</span>%s' % \
+					(font_attrs, name, acct_info)
 		
 		if status is not None:
 			label_text += '\n%s' % status
 
 		# setup the label that holds name and jid
 		banner_name_label.set_markup(label_text)
-
+	
 	def _update_gpg(self):
 		tb = self.xml.get_widget('gpg_togglebutton')
 		if self.contact.keyID: # we can do gpg
diff --git a/src/common/config.py b/src/common/config.py
index 195b305b2c..f9026774e0 100644
--- a/src/common/config.py
+++ b/src/common/config.py
@@ -260,7 +260,9 @@ class Config:
 			'contactfontattrs': [ opt_str, '' ],
 			'bannertextcolor': [ opt_color, 'black' ],
 			'bannerbgcolor': [ opt_color, '' ],
-
+			'bannerfont': [ opt_str, '' ],
+			'bannerfontattrs': [ opt_str, 'B' ],
+				
 			# http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html
 			# FIXME: not black but the default color from gtk+ theme
 			'state_active_color': [ opt_color, 'black' ],
diff --git a/src/common/optparser.py b/src/common/optparser.py
index 5b5c40579d..f4e010471c 100644
--- a/src/common/optparser.py
+++ b/src/common/optparser.py
@@ -162,7 +162,8 @@ class OptionsParser:
 		d = ['accounttextcolor', 'accountbgcolor', 'accountfont',
 			'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont',
 			'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont',
-			'contactfontattrs', 'bannertextcolor', 'bannerbgcolor']
+			'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont', 
+			'bannerfontattrs']
 		for theme_name in (_('grocery'), _('plain')):
 			if theme_name not in gajim.config.get_per('themes'):
 				gajim.config.add_per('themes', theme_name)
diff --git a/src/config.py b/src/config.py
index 4cac5ae36b..5fc7fff630 100644
--- a/src/config.py
+++ b/src/config.py
@@ -417,6 +417,8 @@ class PreferencesWindow:
 					self.on_msg_treemodel_row_changed)
 		self.msg_tree.get_model().connect('row-deleted',
 					self.on_msg_treemodel_row_deleted)
+		
+		self.theme_preferences = None
 
 	def on_preferences_window_show(self, widget):
 		self.update_preferences_window()
@@ -532,7 +534,10 @@ class PreferencesWindow:
 		gajim.interface.roster.reload_jabber_state_images()
 
 	def on_manage_theme_button_clicked(self, widget):
-		dialogs.GajimThemesWindow()
+		if self.theme_preferences is None:
+			self.theme_preferences = dialogs.GajimThemesWindow()
+		else:
+			self.theme_preferences.window.present()
 
 	def on_theme_combobox_changed(self, widget):
 		model = widget.get_model()
diff --git a/src/gajim_themes_window.py b/src/gajim_themes_window.py
index 800d68c5d1..38cae49669 100644
--- a/src/gajim_themes_window.py
+++ b/src/gajim_themes_window.py
@@ -74,12 +74,17 @@ class GajimThemesWindow:
 		self.set_theme_options(self.current_theme, self.current_option)
 		
 		self.xml.signal_autoconnect(self)
+		self.window.connect('delete-event', self.on_themese_window_delete_event)
 		self.themes_tree.get_selection().connect('changed', 
 				self.selection_changed)
 		self.window.show_all()
-
+	
+	def on_themese_window_delete_event(self, widget, event):
+		self.window.hide()
+		return True # do NOT destroy the window
+	
 	def on_close_button_clicked(self, widget):
-		self.window.destroy()
+		self.window.hide()
 
 	def on_theme_cell_edited(self, cell, row, new_name):
 		model = self.themes_tree.get_model()
-- 
GitLab