diff --git a/src/chat.py b/src/chat.py index f429addd5..029da030b 100644 --- a/src/chat.py +++ b/src/chat.py @@ -831,7 +831,7 @@ class Chat: def print_conversation_line(self, text, jid, kind, name, tim, other_tags_for_name = [], other_tags_for_time = [], - other_tags_for_text = [], count_as_new = True): + other_tags_for_text = [], count_as_new = True, subject = None): textview = self.xmls[jid].get_widget('conversation_textview') buffer = textview.get_buffer() buffer.begin_user_action() @@ -889,6 +889,11 @@ class Chat: # add the rest of text located in the index and after end_iter = buffer.get_end_iter() buffer.insert_with_tags_by_name(end_iter, text[index:], *text_tags) + + if subject: # if we have subject, send it too! + subject = '\n' + _('Subject: %s') % subject + end_iter = buffer.get_end_iter() + buffer.insert_with_tags_by_name(end_iter, subject, *text_tags) #scroll to the end of the textview end = False diff --git a/src/common/connection.py b/src/common/connection.py index 2aaf74727..b1b10352e 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -212,6 +212,7 @@ class Connection: """Called when we receive a message""" msgtxt = msg.getBody() mtype = msg.getType() + subject = msg.getSubject() # if note there it's None tim = msg.getTimestamp() tim = time.strptime(tim, '%Y%m%dT%H:%M:%S') tim = time.localtime(timegm(tim)) @@ -237,7 +238,6 @@ class Connection: self.dispatch('MSGERROR', (str(msg.getFrom()), msg.getErrorCode(), msg.getError(), msgtxt, tim)) elif mtype == 'groupchat': - subject = msg.getSubject() if subject: self.dispatch('GC_SUBJECT', (str(msg.getFrom()), subject)) else: @@ -245,11 +245,24 @@ class Connection: return self.dispatch('GC_MSG', (str(msg.getFrom()), msgtxt, tim)) gajim.logger.write('gc', msgtxt, str(msg.getFrom()), tim = tim) - else: + elif mtype == 'normal': # it's single message + log_msgtxt = msgtxt + if subject: + log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt) + gajim.logger.write('incoming', log_msgtxt, str(msg.getFrom()), + tim = tim) + self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted, + mtype, subject)) + else: # it's type 'chat' if not msg.getTag('body'): #no
return - gajim.logger.write('incoming', msgtxt, str(msg.getFrom()), tim = tim) - self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted)) + log_msgtxt = msgtxt + if subject: + log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt) + gajim.logger.write('incoming', log_msgtxt, str(msg.getFrom()), + tim = tim) + self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted, + mtype, subject)) # END messageCB def _presenceCB(self, con, prs): diff --git a/src/dialogs.py b/src/dialogs.py index a8cad7474..041e2f793 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -797,37 +797,92 @@ class PopupNotificationWindow: self.adjust_height_and_move_popup_notification_windows() -class SendSingleMessageDialog: - def __init__(self, plugin, account, contact): +class SingleMessageWindow: + '''SingleMessageWindow can send or show a received + singled message depending on action argument''' + def __init__(self, plugin, account, contact, action='', from_whom='',\ + subject='', message=''): self.plugin = plugin self.account = account + self.contact = contact + self.action = action + + self.subject = subject + self.message = message - self.xml = gtk.glade.XML(GTKGUI_GLADE, 'send_single_message_window', APP) - self.window = self.xml.get_widget('send_single_message_window') + self.xml = gtk.glade.XML(GTKGUI_GLADE, 'single_message_window', APP) + self.window = self.xml.get_widget('single_message_window') self.count_chars_label = self.xml.get_widget('count_chars_label') + self.from_label = self.xml.get_widget('from_label') + self.from_entry = self.xml.get_widget('from_entry') + self.to_label = self.xml.get_widget('to_label') self.to_entry = self.xml.get_widget('to_entry') self.subject_entry = self.xml.get_widget('subject_entry') - self.message_tv_buffer = self.xml.get_widget('message_textview').\ - get_buffer() - + self.message_textview = self.xml.get_widget('message_textview') + self.message_tv_buffer = self.message_textview.get_buffer() + self.send_button = self.xml.get_widget('send_button') + self.reply_button = self.xml.get_widget('reply_button') self.message_tv_buffer.connect('changed', self.update_char_counter) - self.to_entry.set_text(contact.jid) + self.to_entry.set_text(self.contact.jid) - our_jid = gajim.config.get_per('accounts', self.account, 'name') + '@' + \ - gajim.config.get_per('accounts', self.account, 'hostname') - - if len(gajim.connections) > 1: - title = _('Send Single Message as %s') % our_jid - else: - title = _('Send Single Message') - self.window.set_title(title) - - self.subject_entry.grab_focus() + self.send_button.set_no_show_all(True) + self.reply_button.set_no_show_all(True) + self.to_label.set_no_show_all(True) + self.to_entry.set_no_show_all(True) + self.from_label.set_no_show_all(True) + self.from_entry.set_no_show_all(True) + self.prepare_widgets_for(self.action) + + if self.action == 'send': + if self.message: # we come from a reply? + self.message_textview.grab_focus() + else: # we write a new message + self.subject_entry.grab_focus() + elif self.action == 'receive': + self.from_whom = from_whom + self.from_entry.set_text(self.from_whom) + self.from_entry.set_property('editable', False) + self.subject_entry.set_property('editable', False) + self.message_textview.set_editable(False) + self.reply_button.grab_focus() + + self.subject_entry.set_text(self.subject) + self.message_tv_buffer.set_text(self.message) + begin_iter = self.message_tv_buffer.get_start_iter() + self.message_tv_buffer.place_cursor(begin_iter) + self.xml.signal_autoconnect(self) self.window.show_all() + def prepare_widgets_for(self, action): + our_jid = gajim.config.get_per('accounts', self.account, 'name') + '@' + \ + gajim.config.get_per('accounts', self.account, 'hostname') + if len(gajim.connections) > 1: + title = _('Single Message as %s') % our_jid + else: + title = _('Single Message') + + if action == 'send': + title = _('Send %s') % title + self.send_button.show() + self.to_label.show() + self.to_entry.show() + self.reply_button.hide() + self.from_label.hide() + self.from_entry.hide() + elif action == 'receive': + title = _('%s Received') % title + self.reply_button.show() + self.from_label.show() + self.from_entry.show() + self.send_button.hide() + self.to_label.hide() + self.to_entry.hide() + + self.window.set_title(title) + def on_cancel_button_clicked(self, widget): self.window.destroy() @@ -851,6 +906,14 @@ class SendSingleMessageDialog: self.message_tv_buffer.set_text('') # we sent ok, clear the textview + def on_reply_button_clicked(self, widget): + # we create a new blank window to send and we preset RE: and to jid + self.subject = _('RE: %s') % self.subject + self.message = _('\n-< Original Message >-\n%s') % self.message + SingleMessageWindow(self.plugin, self.account, self.contact, + action = 'send', from_whom = self.from_whom, subject = self.subject, + message = self.message) + class XMLConsoleWindow: def __init__(self, plugin, account): self.plugin = plugin diff --git a/src/gajim.py b/src/gajim.py index da98e36be..575076680 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -334,7 +334,7 @@ class Interface: array[10], array[11], array[12], account) def handle_event_msg(self, account, array): - #('MSG', account, (user, msg, time, encrypted)) + #('MSG', account, (contact, msg, time, encrypted, mtype, subject)) jid = array[0].split('/')[0] if jid.find('@') <= 0: jid = jid.replace('@', '') @@ -353,9 +353,9 @@ class Interface: self.roster.nb_unread += 1 gc = self.windows[account]['gc'][jid] show = gc.contacts[jid][nick].show - u = Contact(jid = fjid, name = nick, groups = ['none'], show = show, + c = Contact(jid = fjid, name = nick, groups = ['none'], show = show, ask = 'none') - self.roster.new_chat(u, account) + self.roster.new_chat(c, account) return @@ -376,9 +376,12 @@ class Interface: show_notification = True if show_notification: instance = dialogs.PopupNotificationWindow(self, - _('New Message'), jid, account) + _('New Message'), jid, account) self.roster.popup_notification_windows.append(instance) - self.roster.on_message(jid, array[1], array[2], account, array[3]) + + # array : (contact, msg, time, encrypted, mtype, subject) + self.roster.on_message(jid, array[1], array[2], account, array[3], + array[4], array[5]) if gajim.config.get_per('soundevents', 'first_message_received', 'enabled') and first: self.play_sound('first_message_received') diff --git a/src/gtkgui.glade b/src/gtkgui.glade index 997a88d92..cb9e30c3b 100644 --- a/src/gtkgui.glade +++ b/src/gtkgui.glade @@ -15394,7 +15394,7 @@ the Jabber network. -