2018-09-05 02:59:34 +02:00
|
|
|
# Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
# Copyright (C) 2006 Tomasz Melcer <liori AT exroot.org>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2008-08-15 05:20:23 +02:00
|
|
|
|
2006-08-21 16:14:24 +02:00
|
|
|
'''Window to create new post for discussion groups service.'''
|
|
|
|
|
2019-03-02 10:47:11 +01:00
|
|
|
import uuid
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2012-12-09 21:37:51 +01:00
|
|
|
from nbxmpp import Node
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import gtkgui_helpers
|
2006-08-21 16:14:24 +02:00
|
|
|
|
|
|
|
class GroupsPostWindow:
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, account, servicejid, groupid):
|
|
|
|
"""
|
|
|
|
Open new 'create post' window to create message for groupid on servicejid
|
|
|
|
service
|
|
|
|
"""
|
2016-09-25 23:21:51 +02:00
|
|
|
assert isinstance(servicejid, str)
|
|
|
|
assert isinstance(groupid, str)
|
2006-08-21 16:14:24 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.account = account
|
|
|
|
self.servicejid = servicejid
|
|
|
|
self.groupid = groupid
|
2006-08-21 16:14:24 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('groups_post_window.ui')
|
|
|
|
self.window = self.xml.get_object('groups_post_window')
|
|
|
|
for name in ('from_entry', 'subject_entry', 'contents_textview'):
|
|
|
|
self.__dict__[name] = self.xml.get_object(name)
|
2006-08-21 16:14:24 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.xml.connect_signals(self)
|
|
|
|
self.window.show_all()
|
2006-08-21 16:14:24 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_cancel_button_clicked(self, w):
|
|
|
|
"""
|
|
|
|
Close window
|
|
|
|
"""
|
|
|
|
self.window.destroy()
|
2006-08-21 16:14:24 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_send_button_clicked(self, w):
|
|
|
|
"""
|
|
|
|
Gather info from widgets and send it as a message
|
|
|
|
"""
|
|
|
|
# constructing item to publish... that's atom:entry element
|
2012-12-09 21:37:51 +01:00
|
|
|
item = Node('entry', {'xmlns':'http://www.w3.org/2005/Atom'})
|
2010-02-08 15:08:40 +01:00
|
|
|
author = item.addChild('author')
|
|
|
|
author.addChild('name', {}, [self.from_entry.get_text()])
|
|
|
|
item.addChild('generator', {}, ['Gajim'])
|
|
|
|
item.addChild('title', {}, [self.subject_entry.get_text()])
|
2006-08-21 16:14:24 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
buf = self.contents_textview.get_buffer()
|
2012-12-23 16:23:43 +01:00
|
|
|
item.addChild('content', {}, [buf.get_text(buf.get_start_iter(), buf.get_end_iter(), True)])
|
2006-08-21 16:14:24 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# publish it to node
|
2018-07-01 02:16:33 +02:00
|
|
|
con = app.connections[self.account]
|
|
|
|
con.get_module('PubSub').send_pb_publish(
|
2019-03-02 10:47:11 +01:00
|
|
|
self.servicejid, self.groupid, item, str(uuid.uuid4()))
|
2006-08-21 16:14:24 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# close the window
|
|
|
|
self.window.destroy()
|