[whiteboard] Adapt to new ChatControl design
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
[info]
|
[info]
|
||||||
name: Whiteboard
|
name: Whiteboard
|
||||||
short_name: whiteboard
|
short_name: whiteboard
|
||||||
version: 0.5
|
version: 0.6
|
||||||
description: Shows a whiteboard in chat. python-pygoocanvas is required.
|
description: Shows a whiteboard in chat. python-pygoocanvas is required.
|
||||||
authors = Yann Leboulanger <asterix@lagaule.org>
|
authors = Yann Leboulanger <asterix@lagaule.org>
|
||||||
homepage = https://dev.gajim.org/gajim/gajim-plugins/wikis/WhiteboardPlugin
|
homepage = https://dev.gajim.org/gajim/gajim-plugins/wikis/WhiteboardPlugin
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ from gajim.plugins.gajimplugin import GajimPluginException
|
|||||||
from gajim.plugins.helpers import log_calls, log
|
from gajim.plugins.helpers import log_calls, log
|
||||||
from nbxmpp import Message
|
from nbxmpp import Message
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import GdkPixbuf
|
from gi.repository import Gio
|
||||||
|
from gi.repository import GLib
|
||||||
from gajim import chat_control
|
from gajim import chat_control
|
||||||
from gajim.common import ged
|
from gajim.common import ged
|
||||||
from gajim.common.jingle_session import JingleSession
|
from gajim.common.jingle_session import JingleSession
|
||||||
@@ -61,7 +62,7 @@ class WhiteboardPlugin(GajimPlugin):
|
|||||||
'raw-message-received': (ged.GUI1, self._nec_raw_message),
|
'raw-message-received': (ged.GUI1, self._nec_raw_message),
|
||||||
}
|
}
|
||||||
self.gui_extension_points = {
|
self.gui_extension_points = {
|
||||||
'chat_control_base' : (self.connect_with_chat_control,
|
'chat_control' : (self.connect_with_chat_control,
|
||||||
self.disconnect_from_chat_control),
|
self.disconnect_from_chat_control),
|
||||||
'chat_control_base_update_toolbar': (self.update_button_state,
|
'chat_control_base_update_toolbar': (self.update_button_state,
|
||||||
None),
|
None),
|
||||||
@@ -111,20 +112,15 @@ class WhiteboardPlugin(GajimPlugin):
|
|||||||
if base.chat_control == control:
|
if base.chat_control == control:
|
||||||
if control.contact.supports(NS_JINGLE_SXE) and \
|
if control.contact.supports(NS_JINGLE_SXE) and \
|
||||||
control.contact.supports(NS_SXE):
|
control.contact.supports(NS_SXE):
|
||||||
base.button.set_sensitive(True)
|
base.enable_action(True)
|
||||||
tooltip_text = _('Show whiteboard')
|
|
||||||
else:
|
else:
|
||||||
base.button.set_sensitive(False)
|
base.enable_action(False)
|
||||||
tooltip_text = _('Client on the other side '
|
|
||||||
'does not support the whiteboard')
|
|
||||||
base.button.set_tooltip_text(tooltip_text)
|
|
||||||
|
|
||||||
@log_calls('WhiteboardPlugin')
|
@log_calls('WhiteboardPlugin')
|
||||||
def show_request_dialog(self, account, fjid, jid, sid, content_types):
|
def show_request_dialog(self, account, fjid, jid, sid, content_types):
|
||||||
def on_ok():
|
def on_ok():
|
||||||
session = app.connections[account].get_jingle_session(fjid, sid)
|
session = app.connections[account].get_jingle_session(fjid, sid)
|
||||||
self.sid = session.sid
|
self.sid = session.sid
|
||||||
print(session.accepted)
|
|
||||||
if not session.accepted:
|
if not session.accepted:
|
||||||
session.approve_session()
|
session.approve_session()
|
||||||
for content in content_types:
|
for content in content_types:
|
||||||
@@ -259,41 +255,24 @@ class Base(object):
|
|||||||
self.contact = self.chat_control.contact
|
self.contact = self.chat_control.contact
|
||||||
self.account = self.chat_control.account
|
self.account = self.chat_control.account
|
||||||
self.jid = self.contact.get_full_jid()
|
self.jid = self.contact.get_full_jid()
|
||||||
self.create_buttons()
|
self.add_action()
|
||||||
self.whiteboard = None
|
self.whiteboard = None
|
||||||
self.sid = None
|
self.sid = None
|
||||||
|
|
||||||
def create_buttons(self):
|
def add_action(self):
|
||||||
# create whiteboard button
|
action_name = 'toggle-whiteboard-' + self.chat_control.control_id
|
||||||
actions_hbox = self.chat_control.xml.get_object('actions_hbox')
|
act = Gio.SimpleAction.new_stateful(
|
||||||
self.button = Gtk.ToggleButton()
|
action_name, None, GLib.Variant.new_boolean(False))
|
||||||
self.button.set_property('relief', Gtk.ReliefStyle.NONE)
|
act.connect('change-state', self.on_whiteboard_button_toggled)
|
||||||
self.button.set_property('can-focus', False)
|
self.chat_control.parent_win.window.add_action(act)
|
||||||
img = Gtk.Image()
|
|
||||||
img_path = self.plugin.local_file_path('whiteboard.png')
|
self.chat_control.control_menu.append(
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(img_path)
|
'WhiteBoard', 'win.' + action_name)
|
||||||
iconset = Gtk.IconSet(pixbuf=pixbuf)
|
|
||||||
factory = Gtk.IconFactory()
|
def enable_action(self, state):
|
||||||
factory.add('whiteboard', iconset)
|
win = self.chat_control.parent_win.window
|
||||||
img_path = self.plugin.local_file_path('brush_tool.png')
|
action_name = 'toggle-whiteboard-' + self.chat_control.control_id
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(img_path)
|
win.lookup_action(action_name).set_enabled(state)
|
||||||
iconset = Gtk.IconSet(pixbuf=pixbuf)
|
|
||||||
factory.add('brush_tool', iconset)
|
|
||||||
img_path = self.plugin.local_file_path('line_tool.png')
|
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(img_path)
|
|
||||||
iconset = Gtk.IconSet(pixbuf=pixbuf)
|
|
||||||
factory.add('line_tool', iconset)
|
|
||||||
img_path = self.plugin.local_file_path('oval_tool.png')
|
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(img_path)
|
|
||||||
iconset = Gtk.IconSet(pixbuf=pixbuf)
|
|
||||||
factory.add('oval_tool', iconset)
|
|
||||||
factory.add_default()
|
|
||||||
img.set_from_stock('whiteboard', Gtk.IconSize.MENU)
|
|
||||||
self.button.set_image(img)
|
|
||||||
actions_hbox.pack_start(self.button, False, False, 0)
|
|
||||||
id_ = self.button.connect('toggled', self.on_whiteboard_button_toggled)
|
|
||||||
self.chat_control.handlers[id_] = self.button
|
|
||||||
self.button.show()
|
|
||||||
|
|
||||||
def draw_whiteboard(self, content):
|
def draw_whiteboard(self, content):
|
||||||
hbox = self.chat_control.xml.get_object('chat_control_hbox')
|
hbox = self.chat_control.xml.get_object('chat_control_hbox')
|
||||||
@@ -304,15 +283,17 @@ class Base(object):
|
|||||||
self.whiteboard.hbox.set_size_request(300, 0)
|
self.whiteboard.hbox.set_size_request(300, 0)
|
||||||
hbox.pack_start(self.whiteboard.hbox, False, False, 0)
|
hbox.pack_start(self.whiteboard.hbox, False, False, 0)
|
||||||
self.whiteboard.hbox.show_all()
|
self.whiteboard.hbox.show_all()
|
||||||
self.button.set_active(True)
|
self.enable_action(True)
|
||||||
content.control = self
|
content.control = self
|
||||||
self.sid = content.session.sid
|
self.sid = content.session.sid
|
||||||
|
|
||||||
def on_whiteboard_button_toggled(self, widget):
|
def on_whiteboard_button_toggled(self, action, param):
|
||||||
"""
|
"""
|
||||||
Popup whiteboard
|
Popup whiteboard
|
||||||
"""
|
"""
|
||||||
if widget.get_active():
|
action.set_state(param)
|
||||||
|
state = param.get_boolean()
|
||||||
|
if state:
|
||||||
if not self.whiteboard:
|
if not self.whiteboard:
|
||||||
self.start_whiteboard()
|
self.start_whiteboard()
|
||||||
else:
|
else:
|
||||||
@@ -334,7 +315,7 @@ class Base(object):
|
|||||||
session = conn.get_jingle_session(self.jid, media='xhtml')
|
session = conn.get_jingle_session(self.jid, media='xhtml')
|
||||||
if session:
|
if session:
|
||||||
session.end_session()
|
session.end_session()
|
||||||
self.button.set_active(False)
|
self.enable_action(False)
|
||||||
if reason:
|
if reason:
|
||||||
txt = _('Whiteboard stopped: %(reason)s') % {'reason': reason}
|
txt = _('Whiteboard stopped: %(reason)s') % {'reason': reason}
|
||||||
self.chat_control.print_conversation(txt, 'info')
|
self.chat_control.print_conversation(txt, 'info')
|
||||||
@@ -347,8 +328,12 @@ class Base(object):
|
|||||||
self.whiteboard = None
|
self.whiteboard = None
|
||||||
|
|
||||||
def disconnect_from_chat_control(self):
|
def disconnect_from_chat_control(self):
|
||||||
actions_hbox = self.chat_control.xml.get_object('actions_hbox')
|
menu = self.chat_control.control_menu
|
||||||
actions_hbox.remove(self.button)
|
for i in range(menu.get_n_items()):
|
||||||
|
label = menu.get_item_attribute_value(i, 'label')
|
||||||
|
if label.get_string() == 'WhiteBoard':
|
||||||
|
menu.remove(i)
|
||||||
|
break
|
||||||
|
|
||||||
class JingleWhiteboard(JingleContent):
|
class JingleWhiteboard(JingleContent):
|
||||||
''' Jingle Whiteboard sessions consist of xhtml content'''
|
''' Jingle Whiteboard sessions consist of xhtml content'''
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<object class="GtkImage" id="image5">
|
<object class="GtkImage" id="image5">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="stock">brush_tool</property>
|
<property name="pixbuf">brush_tool.png</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
<object class="GtkImage" id="image6">
|
<object class="GtkImage" id="image6">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="stock">oval_tool</property>
|
<property name="pixbuf">oval_tool.png</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
<object class="GtkImage" id="image7">
|
<object class="GtkImage" id="image7">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="stock">line_tool</property>
|
<property name="pixbuf">line_tool.png</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
@@ -193,9 +193,4 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkImage" id="image1">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="stock">gtk-delete</property>
|
|
||||||
</object>
|
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
Reference in New Issue
Block a user