| 1 | # -*- coding:utf-8 -*- |
|---|
| 2 | ## src/groups.py |
|---|
| 3 | ## |
|---|
| 4 | ## Copyright (C) 2006 Yann Leboulanger <asterix AT lagaule.org> |
|---|
| 5 | ## Tomasz Melcer <liori AT exroot.org> |
|---|
| 6 | ## |
|---|
| 7 | ## This file is part of Gajim. |
|---|
| 8 | ## |
|---|
| 9 | ## Gajim is free software; you can redistribute it and/or modify |
|---|
| 10 | ## it under the terms of the GNU General Public License as published |
|---|
| 11 | ## by the Free Software Foundation; version 3 only. |
|---|
| 12 | ## |
|---|
| 13 | ## Gajim is distributed in the hope that it will be useful, |
|---|
| 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | ## GNU General Public License for more details. |
|---|
| 17 | ## |
|---|
| 18 | ## You should have received a copy of the GNU General Public License |
|---|
| 19 | ## along with Gajim. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 20 | ## |
|---|
| 21 | |
|---|
| 22 | '''Window to create new post for discussion groups service.''' |
|---|
| 23 | |
|---|
| 24 | import gtk |
|---|
| 25 | |
|---|
| 26 | from common import gajim, xmpp |
|---|
| 27 | import gtkgui_helpers |
|---|
| 28 | |
|---|
| 29 | class GroupsPostWindow: |
|---|
| 30 | def __init__(self, account, servicejid, groupid): |
|---|
| 31 | '''Open new 'create post' window to create message for groupid on servicejid service.''' |
|---|
| 32 | assert isinstance(servicejid, basestring) |
|---|
| 33 | assert isinstance(groupid, basestring) |
|---|
| 34 | |
|---|
| 35 | self.account = account |
|---|
| 36 | self.servicejid = servicejid |
|---|
| 37 | self.groupid = groupid |
|---|
| 38 | |
|---|
| 39 | self.xml = gtkgui_helpers.get_glade('groups_post_window.glade') |
|---|
| 40 | self.window = self.xml.get_widget('groups_post_window') |
|---|
| 41 | for name in ('from_entry', 'subject_entry', 'contents_textview'): |
|---|
| 42 | self.__dict__[name] = self.xml.get_widget(name) |
|---|
| 43 | |
|---|
| 44 | self.xml.signal_autoconnect(self) |
|---|
| 45 | self.window.show_all() |
|---|
| 46 | |
|---|
| 47 | def on_cancel_button_clicked(self, w): |
|---|
| 48 | '''Close window.''' |
|---|
| 49 | self.window.destroy() |
|---|
| 50 | |
|---|
| 51 | def on_send_button_clicked(self, w): |
|---|
| 52 | '''Gather info from widgets and send it as a message.''' |
|---|
| 53 | # constructing item to publish... that's atom:entry element |
|---|
| 54 | item = xmpp.Node('entry', {'xmlns':'http://www.w3.org/2005/Atom'}) |
|---|
| 55 | author = item.addChild('author') |
|---|
| 56 | author.addChild('name', {}, [self.from_entry.get_text()]) |
|---|
| 57 | item.addChild('generator', {}, ['Gajim']) |
|---|
| 58 | item.addChild('title', {}, [self.subject_entry.get_text()]) |
|---|
| 59 | item.addChild('id', {}, ['0']) |
|---|
| 60 | |
|---|
| 61 | buffer = self.contents_textview.get_buffer() |
|---|
| 62 | item.addChild('content', {}, [buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())]) |
|---|
| 63 | |
|---|
| 64 | # publish it to node |
|---|
| 65 | gajim.connections[self.account].send_pb_publish(self.servicejid, self.groupid, item, '0') |
|---|
| 66 | |
|---|
| 67 | # close the window |
|---|
| 68 | self.window.destroy() |
|---|
| 69 | |
|---|
| 70 | # vim: se ts=3: |
|---|