1
1
# -*- coding: utf-8 -*-
3
# This file is part of emesene.
5
# emesene is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
10
# emesene is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with emesene; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3
19
'''This module contains the AdiumChatOutput class'''
6
from PyQt4 import QtGui
7
from PyQt4 import QtCore
8
from PyQt4 import QtWebKit
23
from PyQt4 import QtGui
24
from PyQt4 import QtCore
25
from PyQt4 import QtWebKit
28
from gui.qt4ui import Utils
12
29
from gui.base import Plus
13
from gui.qt4ui import Utils
14
from gui.qt4ui.Utils import tr
17
class AdiumChatOutput (QtGui.QScrollArea):
18
'''A widget which displays various messages of a conversation
32
class AdiumChatOutput (QtGui.QScrollArea, gui.base.OutputText):
33
'''A widget which displays various messages of a conversation
19
34
using Adium themes'''
20
# pylint: disable=W0612
21
35
NAME = 'AdiumChatOutput'
22
DESCRIPTION = 'A widget to display conversation messages with Adium' \
23
'themes. Based on Webkit technology.'
36
DESCRIPTION = _('A widget to display conversation messages using adium style')
24
37
AUTHOR = 'Gabriele "Whisky" Visconti'
26
# pylint: enable=W0612
40
search_request = QtCore.pyqtSignal(basestring)
42
#FIXME: implement custom context menu and steal emoticon option
29
44
def __init__(self, config, parent=None):
30
45
QtGui.QScrollArea.__init__(self, parent)
46
gui.base.OutputText.__init__(self, config)
32
47
self.theme = gui.theme.conv_theme
34
48
self._qwebview = QtWebKit.QWebView(self)
36
50
self.setWidget(self._qwebview)
37
51
self.setWidgetResizable(True)
52
settings = self._qwebview.page().settings()
53
settings.setFontSize(QtWebKit.QWebSettings.DefaultFontSize, 12)
38
54
self._qwebview.setRenderHints(QtGui.QPainter.SmoothPixmapTransform)
39
55
self._qwebview.page().setLinkDelegationPolicy(
40
56
QtWebKit.QWebPage.DelegateAllLinks)
42
pic = gui.theme.image_theme.user
43
body = gui.theme.conv_theme.get_body('', '', '', pic, pic)
44
self._qwebview.setHtml(body)
46
self._qwebview.linkClicked.connect(
47
lambda qt_url: gui.base.Desktop.open(qt_url.toString()) )
58
self._qwebview.loadFinished.connect(self._loading_finished_cb)
59
self._qwebview.linkClicked.connect(self.on_link_clicked)
61
def _loading_finished_cb(self, ok):
64
for function in self.pending:
65
self.add_message(function, self.config.b_allow_auto_scroll)
68
def on_link_clicked(self, url):
69
'''callback called when a link is clicked'''
70
href = unicode(url.toString())
71
if href.startswith("search://"):
72
self.search_request.emit(href)
75
if not href.startswith("file://"):
76
gui.base.Desktop.open(href)
49
81
def clear(self, source="", target="", target_display="",
50
82
source_img="", target_img=""):
51
83
'''clear the content'''
52
84
body = self.theme.get_body(source, target, target_display, source_img,
54
self._qwebview.setHtml(body)
86
url = QtCore.QUrl(Utils.path_to_url(self.theme.path))
87
self._qwebview.setHtml(body, url)
88
gui.base.OutputText.clear(self)
56
def _append_message(self, msg, scroll=True):
91
def add_message(self, msg, scroll):
57
92
'''add a message to the conversation'''
93
if msg.type == "status":
94
msg.message = Plus.msnplus_strip(msg.message)
59
95
html = self.theme.format(msg, scroll)
61
96
self._qwebview.page().mainFrame().evaluateJavaScript(html)
63
def send_message(self, formatter, msg):
64
'''add a message to the widget'''
65
self._append_message(msg, self.config.b_allow_auto_scroll)
67
def receive_message(self, formatter, msg):
68
'''add a message to the widget'''
69
self._append_message(msg, self.config.b_allow_auto_scroll)
71
def information(self, formatter, msg):
72
'''add an information message to the widget'''
73
msg.message = Plus.msnplus_strip(msg.message)
74
self._append_message(msg, self.config.b_allow_auto_scroll)
76
98
def update_p2p(self, account, _type, *what):
77
99
''' new p2p data has been received (custom emoticons) '''
78
100
if _type == 'emoticon':
79
101
_creator, _friendly, path = what
80
102
_friendly = xml.sax.saxutils.unescape(_friendly)
81
103
#see gui/base/MarkupParser.py:
82
_id = base64.b64encode(_creator + _friendly)
104
_id = base64.b64encode(_creator + _friendly)
84
106
var now=new Date();
85
107
var x=document.images;