Welcome to mirror list, hosted at ThFree Co, Russian Federation.

groups.py « src - dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a86a4dc1d02f50dd9f3aab6afffdb5e73e3cfd57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
## src/groups.py
##
## Copyright (C) 2006 Yann Leboulanger <asterix AT lagaule.org>
##                    Tomasz Melcer <liori AT exroot.org>
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.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/>.
##

'''Window to create new post for discussion groups service.'''

import gtk

from common import gajim, xmpp
import gtkgui_helpers

class GroupsPostWindow:
	def __init__(self, account, servicejid, groupid):
		'''Open new 'create post' window to create message for groupid on servicejid service.'''
		assert isinstance(servicejid, basestring)
		assert isinstance(groupid, basestring)

		self.account = account
		self.servicejid = servicejid
		self.groupid = groupid

		self.xml = gtkgui_helpers.get_glade('groups_post_window.glade')
		self.window = self.xml.get_widget('groups_post_window')
		for name in ('from_entry', 'subject_entry', 'contents_textview'):
			self.__dict__[name] = self.xml.get_widget(name)

		self.xml.signal_autoconnect(self)
		self.window.show_all()

	def on_cancel_button_clicked(self, w):
		'''Close window.'''
		self.window.destroy()

	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
		item = xmpp.Node('entry', {'xmlns':'http://www.w3.org/2005/Atom'})
		author = item.addChild('author')
		author.addChild('name', {}, [self.from_entry.get_text()])
		item.addChild('generator', {}, ['Gajim'])
		item.addChild('title', {}, [self.subject_entry.get_text()])
		item.addChild('id', {}, ['0'])

		buffer = self.contents_textview.get_buffer()
		item.addChild('content', {}, [buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())])

		# publish it to node
		gajim.connections[self.account].send_pb_publish(self.servicejid, self.groupid, item, '0')

		# close the window
		self.window.destroy()

# vim: se ts=3: