From 94c01aeecccad78c8d471be5f8a3ad72f6e82d84 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Tue, 5 Jul 2005 21:35:37 +0000 Subject: [PATCH] we can now receive normal and chat messages with subject and handle them ok. we can also reply to received normal message with RE: previous message and all the good stuff! hoooray! --- src/chat.py | 7 +- src/common/connection.py | 21 +++- src/dialogs.py | 99 +++++++++++++++---- src/gajim.py | 13 ++- src/gtkgui.glade | 196 ++++++++++++++++++++++++++++++-------- src/roster_window.py | 21 +++- src/tabbed_chat_window.py | 13 ++- 7 files changed, 292 insertions(+), 78 deletions(-) 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. - + 6 GTK_WINDOW_TOPLEVEL @@ -15417,38 +15417,14 @@ the Jabber network. 6 - + True - 2 + 3 3 False 6 12 - - - True - To: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - - - 0 - 1 - 0 - 1 - fill - - - - True @@ -15466,13 +15442,34 @@ the Jabber network. 0 1 - 1 - 2 + 2 + 3 fill + + + True + True + True + True + 0 + + True + * + False + + + 1 + 3 + 0 + 1 + + + + True @@ -15488,8 +15485,8 @@ the Jabber network. 1 2 - 1 - 2 + 2 + 3 @@ -15511,8 +15508,8 @@ the Jabber network. 2 3 - 1 - 2 + 2 + 3 fill @@ -15533,8 +15530,56 @@ the Jabber network. 1 3 + 1 + 2 + + + + + + + True + From: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 0 1 + fill + + + + + + + True + To: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 1 + 1 + 2 + fill @@ -15546,10 +15591,6 @@ the Jabber network. - - - - True @@ -15612,10 +15653,10 @@ the Jabber network. True GTK_RELIEF_NORMAL True - + - + True 0.5 0.5 @@ -15627,13 +15668,13 @@ the Jabber network. 0 - + True False 2 - + True gtk-ok 4 @@ -15650,7 +15691,7 @@ the Jabber network. - + True _Send True @@ -15675,6 +15716,77 @@ the Jabber network. + + + + True + True + True + GTK_RELIEF_NORMAL + True + + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-ok + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Reply + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + 6 diff --git a/src/roster_window.py b/src/roster_window.py index 392050660..2be1de742 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -579,7 +579,7 @@ class RosterWindow: HistoryWindow(self.plugin, user.jid, account) def on_send_single_message_menuitem_activate(self, wiget, account, contact): - dialogs.SendSingleMessageDialog(self, account, contact) + dialogs.SingleMessageWindow(self, account, contact, 'send') def mk_menu_user(self, event, iter): '''Make user's popup menu''' @@ -1147,7 +1147,8 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response() self.plugin.windows[account]['gc'][jid] = \ groupchat_window.GroupchatWindow(jid, nick, self.plugin, account) - def on_message(self, jid, msg, tim, account, encrypted = False): + def on_message(self, jid, msg, tim, account, encrypted = False,\ + msg_type = '', subject = None): '''when we receive a message''' if not self.contacts[account].has_key(jid): keyID = '' @@ -1160,6 +1161,7 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response() status = 'not in the roster', ask = 'none', keyID = keyID) self.contacts[account][jid] = [user1] self.add_user_to_roster(jid, account) + iters = self.get_user_iter(jid, account) if iters: path = self.tree.get_model().get_path(iters[0]) @@ -1167,15 +1169,26 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response() path = None autopopup = gajim.config.get('autopopup') autopopupaway = gajim.config.get('autopopupaway') - # Do we have a queue ? + + + if msg_type == 'normal': # it's single message + #FIXME: take into account autopopup and autopopupaway + # if user doesn't want to be bugged do it as we do the 'chat' + contact = self.contacts[account][jid][0] + dialogs.SingleMessageWindow(self.plugin, account, contact, + action = 'receive', from_whom = jid, subject = subject, message = msg) + return + + # Do we have a queue? qs = self.plugin.queues[account] no_queue = True if qs.has_key(jid): no_queue = False if self.plugin.windows[account]['chats'].has_key(jid): self.plugin.windows[account]['chats'][jid].print_conversation(msg, - jid, tim = tim, encrypted = encrypted) + jid, tim = tim, encrypted = encrypted, subject = subject) return + #We save it in a queue if no_queue: qs[jid] = [] diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index 5089ff037..3c0c5ece8 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -370,7 +370,7 @@ class TabbedChatWindow(chat.Chat): self.plugin.roster.really_remove_user(user, self.account) def print_conversation(self, text, jid, contact = '', tim = None, - encrypted = False): + encrypted = False, subject = None): """Print a line in the conversation: if contact is set to status: it's a status message if contact is set to another value: it's an outgoing message @@ -382,11 +382,15 @@ class TabbedChatWindow(chat.Chat): else: ec = gajim.encrypted_chats[self.account] if encrypted and jid not in ec: - chat.Chat.print_conversation_line(self, 'Encryption enabled', jid, + msg_in_two_langs = _('Encryption enabled')\ + + ' - Encryption enabled' + chat.Chat.print_conversation_line(self, msg_in_two_langs, jid, 'status', '', tim) ec.append(jid) if not encrypted and jid in ec: - chat.Chat.print_conversation_line(self, 'Encryption disabled', jid, + msg_in_two_langs = _('Encryption disabled')\ + + ' - Encryption disabled' + chat.Chat.print_conversation_line(self, msg_in_two_langs, jid, 'status', '', tim) ec.remove(jid) self.xmls[jid].get_widget('gpg_togglebutton').set_active(encrypted) @@ -397,7 +401,8 @@ class TabbedChatWindow(chat.Chat): kind = 'incoming' name = user.name - chat.Chat.print_conversation_line(self, text, jid, kind, name, tim) + chat.Chat.print_conversation_line(self, text, jid, kind, name, tim, + subject = subject) def restore_conversation(self, jid): # don't restore lines if it's a transport