1 # -*- coding: utf-8 -*-
3 ## This file is part of Gajim.
5 ## Gajim is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published
7 ## by the Free Software Foundation; version 3 only.
9 ## Gajim is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
19 Adjustable chat window banner.
21 Includes tweaks to make it compact.
23 Based on patch by pb in ticket #4133:
24 http://trac.gajim.org/attachment/ticket/4133/gajim-chatbanneroptions-svn10008.patch
26 :author: Mateusz Biliński <mateusz@bilinski.it>
28 :copyright: Copyright (2008) Mateusz Biliński <mateusz@bilinski.it>
36 import message_control
37 from common
import i18n
38 from common
import gajim
39 from common
import helpers
41 from plugins
import GajimPlugin
42 from plugins
.helpers
import log
, log_calls
43 from plugins
.gui
import GajimPluginConfigDialog
45 class BannerTweaksPlugin(GajimPlugin
):
47 @log_calls('BannerTweaksPlugin')
49 self
.config_dialog
= BannerTweaksPluginConfigDialog(self
)
51 self
.gui_extension_points
= {
52 'chat_control_base_draw_banner': (self
.chat_control_base_draw_banner_called
,
53 self
.chat_control_base_draw_banner_deactivation
)
56 self
.config_default_values
= {
57 'show_banner_image': (True, _('If True, Gajim will display a status icon in the banner of chat windows.')),
58 'show_banner_online_msg': (True, _('If True, Gajim will display the status message of the contact in the banner of chat windows.')),
59 'show_banner_resource': (False, _('If True, Gajim will display the resource name of the contact in the banner of chat windows.')),
60 'banner_small_fonts': (False, _('If True, Gajim will use small fonts for contact name and resource name in the banner of chat windows.')),
61 'old_chat_avatar_height': (52, _('chat_avatar_height value before plugin was activated')),
64 @log_calls('BannerTweaksPlugin')
66 self
.config
['old_chat_avatar_height'] = gajim
.config
.get('chat_avatar_height')
67 #gajim.config.set('chat_avatar_height', 28)
69 @log_calls('BannerTweaksPlugin')
71 gajim
.config
.set('chat_avatar_height', self
.config
['old_chat_avatar_height'])
73 @log_calls('BannerTweaksPlugin')
74 def chat_control_base_draw_banner_called(self
, chat_control
):
75 if not self
.config
['show_banner_online_msg']:
76 chat_control
.banner_status_label
.hide()
77 chat_control
.banner_status_label
.set_no_show_all(True)
79 chat_control
.banner_status_label
.set_markup(status_text
)
81 if not self
.config
['show_banner_image']:
82 if chat_control
.TYPE_ID
== message_control
.TYPE_GC
:
83 banner_status_img
= chat_control
.xml
.get_object(
84 'gc_banner_status_image')
86 banner_status_img
= chat_control
.xml
.get_object(
87 'banner_status_image')
88 banner_status_img
.clear()
90 # TODO: part below repeats a lot of code from ChatControl.draw_banner_text()
91 # This could be rewritten using re module: getting markup text from
92 # banner_name_label and replacing some elements based on plugin config.
94 if self
.config
['show_banner_resource'] or self
.config
['banner_small_fonts']:
95 banner_name_label
= chat_control
.xml
.get_object('banner_name_label')
96 label_text
= banner_name_label
.get_label()
98 contact
= chat_control
.contact
101 name
= contact
.get_shown_name()
102 if chat_control
.resource
:
103 name
+= '/' + chat_control
.resource
104 elif contact
.resource
and self
.config
['show_banner_resource']:
105 name
+= '/' + contact
.resource
107 if chat_control
.TYPE_ID
== message_control
.TYPE_PM
:
108 name
= _('%(nickname)s from group chat %(room_name)s') %\
109 {'nickname': name
, 'room_name': chat_control
.room_name
}
110 name
= gobject
.markup_escape_text(name
)
112 # We know our contacts nick, but if another contact has the same nick
113 # in another account we need to also display the account.
114 # except if we are talking to two different resources of the same contact
116 for account
in gajim
.contacts
.get_accounts():
117 if account
== chat_control
.account
:
119 if acct_info
: # We already found a contact with same nick
121 for jid
in gajim
.contacts
.get_jid_list(account
):
123 gajim
.contacts
.get_first_contact_from_jid(account
, jid
)
124 if other_contact_
.get_shown_name() == chat_control
.contact
.get_shown_name():
125 acct_info
= ' (%s)' % \
126 gobject
.markup_escape_text(chat_control
.account
)
129 font_attrs
, font_attrs_small
= chat_control
.get_font_attrs()
130 if self
.config
['banner_small_fonts']:
131 font_attrs
= font_attrs_small
133 st
= gajim
.config
.get('displayed_chat_state_notifications')
134 cs
= contact
.chatstate
135 if cs
and st
in ('composing_only', 'all'):
136 if contact
.show
== 'offline':
138 elif contact
.composing_xep
== 'XEP-0085':
139 if st
== 'all' or cs
== 'composing':
140 chatstate
= helpers
.get_uf_chatstate(cs
)
143 elif contact
.composing_xep
== 'XEP-0022':
144 if cs
in ('composing', 'paused'):
145 # only print composing, paused
146 chatstate
= helpers
.get_uf_chatstate(cs
)
150 # When does that happen ? See [7797] and [7804]
151 chatstate
= helpers
.get_uf_chatstate(cs
)
153 label_text
= '<span %s>%s</span><span %s>%s %s</span>' % \
154 (font_attrs
, name
, font_attrs_small
, acct_info
, chatstate
)
156 # weight="heavy" size="x-large"
157 label_text
= '<span %s>%s</span><span %s>%s</span>' % \
158 (font_attrs
, name
, font_attrs_small
, acct_info
)
160 banner_name_label
.set_markup(label_text
)
162 @log_calls('BannerTweaksPlugin')
163 def chat_control_base_draw_banner_deactivation(self
, chat_control
):
165 #chat_control.draw_banner()
167 class BannerTweaksPluginConfigDialog(GajimPluginConfigDialog
):
169 self
.GTK_BUILDER_FILE_PATH
= self
.plugin
.local_file_path(
171 self
.xml
= gtk
.Builder()
172 self
.xml
.set_translation_domain(i18n
.APP
)
173 self
.xml
.add_objects_from_file(self
.GTK_BUILDER_FILE_PATH
,
174 ['banner_tweaks_config_vbox'])
175 self
.config_vbox
= self
.xml
.get_object('banner_tweaks_config_vbox')
176 self
.child
.pack_start(self
.config_vbox
)
178 self
.show_banner_image_checkbutton
= self
.xml
.get_object('show_banner_image_checkbutton')
179 self
.show_banner_online_msg_checkbutton
= self
.xml
.get_object('show_banner_online_msg_checkbutton')
180 self
.show_banner_resource_checkbutton
= self
.xml
.get_object('show_banner_resource_checkbutton')
181 self
.banner_small_fonts_checkbutton
= self
.xml
.get_object('banner_small_fonts_checkbutton')
183 self
.xml
.connect_signals(self
)
186 self
.show_banner_image_checkbutton
.set_active(self
.plugin
.config
['show_banner_image'])
187 self
.show_banner_online_msg_checkbutton
.set_active(self
.plugin
.config
['show_banner_online_msg'])
188 self
.show_banner_resource_checkbutton
.set_active(self
.plugin
.config
['show_banner_resource'])
189 self
.banner_small_fonts_checkbutton
.set_active(self
.plugin
.config
['banner_small_fonts'])
191 def on_show_banner_image_checkbutton_toggled(self
, button
):
192 self
.plugin
.config
['show_banner_image'] = button
.get_active()
194 def on_show_banner_online_msg_checkbutton_toggled(self
, button
):
195 self
.plugin
.config
['show_banner_online_msg'] = button
.get_active()
197 def on_show_banner_resource_checkbutton_toggled(self
, button
):
198 self
.plugin
.config
['show_banner_resource'] = button
.get_active()
200 def on_banner_small_fonts_checkbutton_toggled(self
, button
):
201 self
.plugin
.config
['banner_small_fonts'] = button
.get_active()