~emesene-team/emesene/master

3 by Riccardo (C10uD)
import2
1
# -*- coding: utf-8 -*-
2
3
'''This module contains the AdiumChatOutput class'''
4
import base64
5
6
from PyQt4      import QtGui
7
from PyQt4      import QtCore
8
from PyQt4      import QtWebKit
9
from PyQt4.QtCore   import Qt
10
11
import e3
12
import gui
13
from gui.base import Plus
14
from gui.qt4ui  import Utils
15
from gui.qt4ui.Utils import tr
16
17
18
class ConversationToolbar (QtGui.QToolBar):
19
    """
20
    A class that represents the toolbar on the conversation window
21
    """
22
    NAME = 'Conversation Toolbar'
23
    DESCRIPTION = 'The toolbar for a conversation'
24
    AUTHOR = 'Mariano Guerra'
25
    WEBSITE = 'www.emesene.org'
26
27
    def __init__(self, handler, session):
28
        """
29
        constructor
30
31
        handler -- an instance of e3common.Handler.ConversationToolbarHandler
32
        """
33
        QtGui.QToolBar.__init__(self)
34
35
        self.handler = handler
36
        self.session = session
37
38
        # an action dict to avoid proliferation of instance variables:
39
        self._action_dict = {}
40
        self.draw()
41
42
    def redraw_ublock_button(self, contact_unblocked):
43
        """
44
        redraws the block button,
45
        setting the appropiated stock_id and tooltip
46
        """
47
        if contact_unblocked:
48
            ublock_icon = self.theme_tool_block
49
            tooltip_text = tr('Block contact')
50
        else:
51
            ublock_icon = self.theme_tool_unblock
52
            tooltip_text = tr('Unblock contact')
53
54
        self._action_dict['ublock'].setToolTip(tooltip_text)
55
        self._action_dict['ublock'].setIcon(ublock_icon)
6 by Sven (Sbte)
emesene 2.12.9
56
57
    def set_ublock_sensitive(self, is_sensitive):
58
        self._action_dict['ublock'].setEnabled(is_sensitive)
59
3 by Riccardo (C10uD)
import2
60
    def set_sensitive(self, is_sensitive, force_sensitive_block_button=False):
61
        self._action_dict['ublock'].setEnabled(force_sensitive_block_button or is_sensitive)
62
        self._action_dict['toggle_avatars'].setEnabled(force_sensitive_block_button or is_sensitive)
63
        self._action_dict['change_font'].setEnabled(is_sensitive)
64
        self._action_dict['send_nudge'].setEnabled(is_sensitive)
65
        self._action_dict['clean'].setEnabled(is_sensitive)
66
        self._action_dict['change_color'].setEnabled(is_sensitive)
67
        self._action_dict['add_smiley'].setEnabled(is_sensitive)
6 by Sven (Sbte)
emesene 2.12.9
68
        self._action_dict['invite'].setEnabled(is_sensitive)
3 by Riccardo (C10uD)
import2
69
70
#        self.invite_av_call.set_sensitive(is_sensitive)
71
#        self.invite_video_call.set_sensitive(is_sensitive)
72
#        self.invite_audio_call.set_sensitive(is_sensitive)
73
#        self.invite_file_transfer.set_sensitive(is_sensitive)
74
75
    def update_toggle_avatar_icon(self, show_avatars):
76
        if show_avatars:
77
            self._action_dict['toggle_avatars'].setIcon(self.theme_tool_hide_avatar)
78
            self._action_dict['toggle_avatars'].setToolTip(tr('Hide avatar'))
79
        else:
80
            self._action_dict['toggle_avatars'].setIcon(self.theme_tool_show_avatar)
81
            self._action_dict['toggle_avatars'].setToolTip(tr('Show avatar'))
82
83
    def draw(self):
84
        '''draw the toolbar'''
85
86
        action_dict = self._action_dict
87
88
        self.setToolButtonStyle(Qt.ToolButtonIconOnly)
89
90
        #FIXME: toolbar size
91
        #toolbar_small = self.handler.session.config.get_or_set('b_toolbar_small', False)
92
        # check if we have theme-specific toolbar-icons
93
94
        image_theme = gui.theme.image_theme
95
        if image_theme.has_custom_toolbar_icons():
96
            theme_tool_font = QtGui.QIcon(image_theme.tool_font)
97
            theme_tool_font_color = QtGui.QIcon(image_theme.tool_font_color)
98
            theme_tool_emotes = QtGui.QIcon(image_theme.tool_emotes)
99
            theme_tool_nudge = QtGui.QIcon(image_theme.tool_nudge)
100
            theme_tool_invite = QtGui.QIcon(image_theme.tool_invite)
101
            theme_tool_clean = QtGui.QIcon(image_theme.tool_clean)
102
            theme_tool_file_transfer = QtGui.QIcon(image_theme.tool_file_transfer)
103
            self.theme_tool_block = QtGui.QIcon(image_theme.tool_block)
104
            self.theme_tool_unblock = QtGui.QIcon(image_theme.tool_unblock)
105
        else:
106
            theme_tool_font = QtGui.QIcon.fromTheme("preferences-desktop-font")
6 by Sven (Sbte)
emesene 2.12.9
107
            theme_tool_font_color = QtGui.QIcon.fromTheme("preferences-desktop-theme")
3 by Riccardo (C10uD)
import2
108
109
            emote_theme = gui.theme.emote_theme
110
111
            theme_tool_emotes = QtGui.QIcon(emote_theme.emote_to_path(':D', True))
112
            theme_tool_nudge = QtGui.QIcon(emote_theme.emote_to_path(':S', True))
113
            theme_tool_invite = QtGui.QIcon.fromTheme("list-add")
114
            theme_tool_clean = QtGui.QIcon.fromTheme("edit-clear")
115
            theme_tool_file_transfer = QtGui.QIcon.fromTheme("go-up")
116
            self.theme_tool_block = QtGui.QIcon.fromTheme("list-remove")
117
            self.theme_tool_unblock = QtGui.QIcon.fromTheme("list-add")
118
119
        if self.session.config.b_avatar_on_left:
120
            self.theme_tool_hide_avatar = QtGui.QIcon.fromTheme("go-previous")
121
            self.theme_tool_show_avatar = QtGui.QIcon.fromTheme("go-next")
122
        else:
123
            self.theme_tool_hide_avatar = QtGui.QIcon.fromTheme("go-next")
124
            self.theme_tool_show_avatar = QtGui.QIcon.fromTheme("go-previous")
125
126
#FIXME: add icons
127
#        theme_tool_call = QtGui.QIcon(image_theme.call)
128
#        theme_tool_video = QtGui.QIcon(image_theme.video)
129
#        theme_tool_av = QtGui.QIcon(image_theme.av)
130
131
        action_dict['change_font']  = QtGui.QAction(theme_tool_font,  tr('Select font'), self)
132
        action_dict['change_font'].triggered.connect(self.handler.on_font_selected)
133
134
        action_dict['change_color'] = QtGui.QAction(theme_tool_font_color, tr('Select font color'), self)
135
        action_dict['change_color'].triggered.connect(
136
                            self.handler.on_color_selected)
137
138
        action_dict['add_smiley'] = QtGui.QAction(theme_tool_emotes, tr('Send an emoticon'), self)
139
        #FIXME: this should use self.handler.on_emotes_selected but that isn't working
140
        action_dict['add_smiley'].triggered.connect(
141
                            self.handler.conversation._on_show_smiley_chooser)
142
143
        action_dict['send_nudge'] = QtGui.QAction(theme_tool_nudge, tr('Request attention'), self)
144
        action_dict['send_nudge'].triggered.connect(
145
                            self.handler.on_notify_attention_selected)
146
6 by Sven (Sbte)
emesene 2.12.9
147
        action_dict['invite'] = QtGui.QAction(theme_tool_invite, tr('Invite a buddy'), self)
148
        action_dict['invite'].triggered.connect(
149
                            self.handler.on_invite_selected)
3 by Riccardo (C10uD)
import2
150
151
        action_dict['clean'] = QtGui.QAction(theme_tool_clean, tr('Clean the conversation'), self)
152
        action_dict['clean'].triggered.connect(
153
                            self.handler.on_clean_selected)
154
155
#        self.invite_file_transfer = gtk.ToolButton(theme_tool_file_transfer)
156
#        self.invite_file_transfer.set_label(_('Send a file'))
157
#        self.invite_file_transfer.set_tooltip_text(_('Send a file'))
158
#        self.invite_file_transfer.connect('clicked',
159
#            lambda *args: self.handler.on_invite_file_transfer_selected())
160
161
        action_dict['ublock'] = QtGui.QAction(
6 by Sven (Sbte)
emesene 2.12.9
162
                            self.theme_tool_show_avatar, tr('Block/Unblock contact'), self)
3 by Riccardo (C10uD)
import2
163
        action_dict['ublock'].triggered.connect(
164
                            self.handler.on_ublock_selected)
165
166
        action_dict['toggle_avatars'] = QtGui.QAction(
6 by Sven (Sbte)
emesene 2.12.9
167
                            self.theme_tool_block, tr('Hide/Show avatar'), self)
3 by Riccardo (C10uD)
import2
168
        action_dict['toggle_avatars'].triggered.connect(
169
                            self.handler.on_toggle_avatar_selected)
170
        self.update_toggle_avatar_icon(self.session.config.b_show_info)
171
172
#        self.invite_video_call = gtk.ToolButton(theme_tool_video)
173
#        self.invite_video_call.set_label(_('Video Call'))
174
#        self.invite_video_call.set_tooltip_text(_('Video Call'))
175
#        self.invite_video_call.connect('clicked',
176
#            lambda *args: self.handler.on_invite_video_call_selected())
177
178
#        self.invite_audio_call = gtk.ToolButton(theme_tool_call)
179
#        self.invite_audio_call.set_label(_('Voice Call'))
180
#        self.invite_audio_call.set_tooltip_text(_('Voice Call'))
181
#        self.invite_audio_call.connect('clicked',
182
#            lambda *args: self.handler.on_invite_voice_call_selected())
183
184
#        self.invite_av_call = gtk.ToolButton(theme_tool_av)
185
#        self.invite_av_call.set_label(_('Audio/Video Call'))
186
#        self.invite_av_call.set_tooltip_text(_('Audio/Video Call'))
187
#        self.invite_av_call.connect('clicked',
188
#            lambda *args: self.handler.on_invite_av_call_selected())
189
190
        self.addAction(action_dict['change_font'])
191
        self.addAction(action_dict['change_color'])
192
        self.addSeparator()
193
194
        self.addAction(action_dict['add_smiley'])
195
        self.addAction(action_dict['send_nudge'])
196
6 by Sven (Sbte)
emesene 2.12.9
197
        if self.handler.session_service_supported(e3.Session.SERVICE_CONTACT_INVITE):
198
            self.addSeparator()
199
            self.addAction(action_dict['invite'])
3 by Riccardo (C10uD)
import2
200
#FIXME: implement this actions
201
#        if self.handler.session_service_supported(e3.Session.SERVICE_FILETRANSFER):
202
#            self.add(self.invite_file_transfer)
203
        self.addSeparator()
204
205
#        if self.handler.session_service_supported(e3.Session.SERVICE_CALLS):
206
#            self.add(self.invite_video_call)
207
#            self.add(self.invite_audio_call)
208
#            self.add(self.invite_av_call)
209
#            self.addSeparator()
210
211
        self.addAction(action_dict['clean'])
212
        if self.handler.session_service_supported(e3.Session.SERVICE_CONTACT_BLOCK):
213
            self.addAction(action_dict['ublock'])
214
215
        self.addSeparator()
216
        self.addAction(action_dict['toggle_avatars'])