here is the OLD way to implement MOTD. It's not the JEP-133 way

This commit is contained in:
Yann Leboulanger 2005-08-06 12:33:20 +00:00
parent 252251949f
commit 5177472406
4 changed files with 101 additions and 23 deletions

View File

@ -1206,6 +1206,12 @@ class Connection:
self.connection.send(p) self.connection.send(p)
self.dispatch('STATUS', show) self.dispatch('STATUS', show)
def send_motd(self, jid, subject = '', msg = ''):
if not self.connection:
return
msg_iq = common.xmpp.Message(to = jid, body = msg, subject = subject)
self.to_be_sent.append(msg_iq)
def send_message(self, jid, msg, keyID, type = 'chat', subject='', chatstate = None): def send_message(self, jid, msg, keyID, type = 'chat', subject='', chatstate = None):
if not self.connection: if not self.connection:
return return

View File

@ -1154,7 +1154,7 @@ class PopupNotificationWindow:
if self.msg_type == 'normal': # it's single message if self.msg_type == 'normal': # it's single message
return # FIXME: I think I should not print here but in new_chat? return # FIXME: I think I should not print here but in new_chat?
contact = self.contacts[account][jid][0] contact = self.contacts[account][jid][0]
SingleMessageWindow(self.plugin, self.account, contact, SingleMessageWindow(self.plugin, self.account, contact.jid,
action = 'receive', from_whom = jid, subject = subject, message = msg) action = 'receive', from_whom = jid, subject = subject, message = msg)
elif self.msg_type == 'file': # it's file request elif self.msg_type == 'file': # it's file request
@ -1179,11 +1179,10 @@ class PopupNotificationWindow:
class SingleMessageWindow: class SingleMessageWindow:
'''SingleMessageWindow can send or show a received '''SingleMessageWindow can send or show a received
singled message depending on action argument''' singled message depending on action argument'''
def __init__(self, plugin, account, contact, action='', from_whom='',\ def __init__(self, plugin, account, to='', action='', from_whom='',
subject='', message=''): subject='', message=''):
self.plugin = plugin self.plugin = plugin
self.account = account self.account = account
self.contact = contact
self.action = action self.action = action
self.subject = subject self.subject = subject
@ -1204,7 +1203,7 @@ class SingleMessageWindow:
self.send_and_close_button = self.xml.get_widget('send_and_close_button') self.send_and_close_button = self.xml.get_widget('send_and_close_button')
self.message_tv_buffer.connect('changed', self.update_char_counter) self.message_tv_buffer.connect('changed', self.update_char_counter)
self.to_entry.set_text(self.contact.jid) self.to_entry.set_text(to)
self.send_button.set_no_show_all(True) self.send_button.set_no_show_all(True)
self.reply_button.set_no_show_all(True) self.reply_button.set_no_show_all(True)
@ -1278,13 +1277,18 @@ class SingleMessageWindow:
def send_single_message(self): def send_single_message(self):
to_whom_jid = self.to_entry.get_text() to_whom_jid = self.to_entry.get_text()
subject = self.subject_entry.get_text()
begin, end = self.message_tv_buffer.get_bounds()
message = self.message_tv_buffer.get_text(begin, end)
if to_whom_jid.find('/announce/motd') > -1:
gajim.connections[self.account].send_motd(to_whom_jid, subject,
message)
return
if to_whom_jid.find('@') == -1: # if no @ was given if to_whom_jid.find('@') == -1: # if no @ was given
ErrorDialog(_('Invalid contact ID'), ErrorDialog(_('Invalid contact ID'),
_('Contact ID must be of the form "username@servername".')).get_response() _('Contact ID must be of the form "username@servername".')).get_response()
return return
subject = self.subject_entry.get_text()
begin, end = self.message_tv_buffer.get_bounds()
message = self.message_tv_buffer.get_text(begin, end)
# FIXME: allow GPG message some day # FIXME: allow GPG message some day
gajim.connections[self.account].send_message(to_whom_jid, message, gajim.connections[self.account].send_message(to_whom_jid, message,
@ -1301,7 +1305,7 @@ class SingleMessageWindow:
self.subject = _('RE: %s') % self.subject self.subject = _('RE: %s') % self.subject
self.message = _('\n\n\n== Original Message ==\n%s') % self.message self.message = _('\n\n\n== Original Message ==\n%s') % self.message
self.window.destroy() self.window.destroy()
SingleMessageWindow(self.plugin, self.account, self.contact, SingleMessageWindow(self.plugin, self.account, to = to,
action = 'send', from_whom = self.from_whom, subject = self.subject, action = 'send', from_whom = self.from_whom, subject = self.subject,
message = self.message) message = self.message)

View File

@ -16529,7 +16529,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image841"> <widget class="GtkImage" id="image1098">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-network</property> <property name="stock">gtk-network</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -16555,7 +16555,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image842"> <widget class="GtkImage" id="image1099">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-dialog-warning</property> <property name="stock">gtk-dialog-warning</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -16576,7 +16576,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image843"> <widget class="GtkImage" id="image1100">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-execute</property> <property name="stock">gtk-execute</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -16588,6 +16588,54 @@ Maybe I'll refactor later</property>
</child> </child>
</widget> </widget>
</child> </child>
<child>
<widget class="GtkSeparatorMenuItem" id="separator10">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="set_motd_menuitem">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Set Message of the Day</property>
<property name="label" translatable="yes">Set MOTD</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_set_motd_menuitem_activate" last_modification_time="Sat, 06 Aug 2005 10:28:39 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="update_motd_menuitem">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Update Message of the Day</property>
<property name="label" translatable="yes">Update MOTD</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_update_motd_activate" last_modification_time="Sat, 06 Aug 2005 10:28:39 GMT"/>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="delete_motd_menuitem">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Delete Message of the Day</property>
<property name="label" translatable="yes">Delete MOTD</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_delete_motd_activate" last_modification_time="Sat, 06 Aug 2005 10:28:39 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image1101">
<property name="visible">True</property>
<property name="stock">gtk-clear</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
</widget> </widget>
</child> </child>
</widget> </widget>
@ -16600,7 +16648,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image844"> <widget class="GtkImage" id="image1102">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-preferences</property> <property name="stock">gtk-preferences</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -16620,7 +16668,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image845"> <widget class="GtkImage" id="image1103">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-find</property> <property name="stock">gtk-find</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -16640,7 +16688,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image846"> <widget class="GtkImage" id="image1104">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-add</property> <property name="stock">gtk-add</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -16660,7 +16708,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image847"> <widget class="GtkImage" id="image1105">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-connect</property> <property name="stock">gtk-connect</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -16680,7 +16728,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image848"> <widget class="GtkImage" id="image1106">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-new</property> <property name="stock">gtk-new</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -17056,7 +17104,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image937"> <widget class="GtkImage" id="image1107">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-new</property> <property name="stock">gtk-new</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -17102,7 +17150,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image938"> <widget class="GtkImage" id="image1108">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-new</property> <property name="stock">gtk-new</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -17144,7 +17192,7 @@ Maybe I'll refactor later</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image939"> <widget class="GtkImage" id="image1109">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-clear</property> <property name="stock">gtk-clear</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>

View File

@ -777,7 +777,7 @@ class RosterWindow:
HistoryWindow(self.plugin, contact.jid, account) HistoryWindow(self.plugin, contact.jid, account)
def on_send_single_message_menuitem_activate(self, wiget, account, contact): def on_send_single_message_menuitem_activate(self, wiget, account, contact):
dialogs.SingleMessageWindow(self, account, contact, 'send') dialogs.SingleMessageWindow(self, account, contact.jid, 'send')
def on_send_file_menuitem_activate(self, widget, account, contact): def on_send_file_menuitem_activate(self, widget, account, contact):
self.plugin.windows['file_transfers'].show_file_send_request( self.plugin.windows['file_transfers'].show_file_send_request(
@ -938,6 +938,21 @@ class RosterWindow:
else: else:
self.plugin.windows[account]['xml_console'].window.show_all() self.plugin.windows[account]['xml_console'].window.show_all()
def on_set_motd(self, widget, account):
server = gajim.config.get_per('accounts', account, 'hostname')
server += '/announce/motd'
dialogs.SingleMessageWindow(self.plugin, account, server, 'send')
def on_update_motd(self, widget, account):
server = gajim.config.get_per('accounts', account, 'hostname')
server += '/announce/motd/update'
dialogs.SingleMessageWindow(self.plugin, account, server, 'send')
def on_delete_motd(self, widget, account):
server = gajim.config.get_per('accounts', account, 'hostname')
server += '/announce/motd/delete'
gajim.connections[account].send_motd(server)
def on_edit_account(self, widget, account): def on_edit_account(self, widget, account):
if self.plugin.windows[account].has_key('account_modification'): if self.plugin.windows[account].has_key('account_modification'):
self.plugin.windows[account]['account_modification'].window.present() self.plugin.windows[account]['account_modification'].window.present()
@ -977,8 +992,10 @@ class RosterWindow:
status_menuitem = childs[0] status_menuitem = childs[0]
#sep #sep
advanced_actions_menuitem = childs[2] advanced_actions_menuitem = childs[2]
xml_console_menuitem =\ xml_console_menuitem = xml.get_widget('xml_console_menuitem')
advanced_actions_menuitem.get_submenu().get_children()[0] set_motd_menuitem = xml.get_widget('set_motd_menuitem')
update_motd_menuitem = xml.get_widget('update_motd_menuitem')
delete_motd_menuitem = xml.get_widget('delete_motd_menuitem')
edit_account_menuitem = childs[3] edit_account_menuitem = childs[3]
service_discovery_menuitem = childs[4] service_discovery_menuitem = childs[4]
add_contact_menuitem = childs[5] add_contact_menuitem = childs[5]
@ -1002,6 +1019,9 @@ class RosterWindow:
item.connect('activate', self.change_status, account, show) item.connect('activate', self.change_status, account, show)
xml_console_menuitem.connect('activate', self.on_xml_console, account) xml_console_menuitem.connect('activate', self.on_xml_console, account)
set_motd_menuitem.connect('activate', self.on_set_motd, account)
update_motd_menuitem.connect('activate', self.on_update_motd, account)
delete_motd_menuitem.connect('activate', self.on_delete_motd, account)
edit_account_menuitem.connect('activate', self.on_edit_account, account) edit_account_menuitem.connect('activate', self.on_edit_account, account)
service_discovery_menuitem.connect('activate', service_discovery_menuitem.connect('activate',
self.on_service_disco_menuitem_activate, account) self.on_service_disco_menuitem_activate, account)
@ -1423,7 +1443,7 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
#FIXME: take into account autopopup and autopopupaway #FIXME: take into account autopopup and autopopupaway
# if user doesn't want to be bugged do it as we do the 'chat' # if user doesn't want to be bugged do it as we do the 'chat'
contact = gajim.contacts[account][jid][0] contact = gajim.contacts[account][jid][0]
dialogs.SingleMessageWindow(self.plugin, account, contact, dialogs.SingleMessageWindow(self.plugin, account, contact.jid,
action = 'receive', from_whom = jid, subject = subject, message = msg) action = 'receive', from_whom = jid, subject = subject, message = msg)
return return