Changeset 9218

Show
Ignore:
Timestamp:
12/30/07 00:52:17 (11 months ago)
Author:
asterix
Message:

add more needed functions to message_control

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/normal_control/src/normal_control.py

    r9177 r9218  
    165165                                self.to_entry.set_text(to) 
    166166 
    167                 if gajim.config.get('use_speller') and HAS_GTK_SPELL and action == 'send': 
    168                         try: 
    169                                 spell1 = gtkspell.Spell(self.conversation_textview.tv) 
    170                                 spell2 = gtkspell.Spell(self.message_textview) 
    171                                 lang = gajim.config.get('speller_language') 
    172                                 if lang: 
    173                                         spell1.set_language(lang) 
    174                                         spell2.set_language(lang) 
    175                         except gobject.GError, msg: 
    176                                 AspellDictError(lang) 
     167#TODO: 
     168#               if gajim.config.get('use_speller') and HAS_GTK_SPELL and action == 'send': 
     169#                       try: 
     170#                               spell1 = gtkspell.Spell(self.conversation_textview.tv) 
     171#                               spell2 = gtkspell.Spell(self.message_textview) 
     172#                               lang = gajim.config.get('speller_language') 
     173#                               if lang: 
     174#                                       spell1.set_language(lang) 
     175#                                       spell2.set_language(lang) 
     176#                       except gobject.GError, msg: 
     177#                               AspellDictError(lang) 
    177178 
    178179                self.prepare_widgets_for(self.action) 
     
    203204                self.xml.signal_autoconnect(self) 
    204205 
    205                 if gajim.config.get('saveposition'): 
    206                         # get window position and size from config 
    207                         # Makes absolutely no sense when dealing with multiple windows 
    208                         # (for example when hitting "reply" the orig window stays) 
    209                         #gtkgui_helpers.move_window(self.window, 
    210                         #       gajim.config.get('single-msg-x-position'), 
    211                         #       gajim.config.get('single-msg-y-position')) 
    212                         gtkgui_helpers.resize_window(self.window, 
    213                                 gajim.config.get('single-msg-width'), 
    214                                 gajim.config.get('single-msg-height')) 
    215206                self.window.show_all() 
     207 
     208        def on_avatar_eventbox_enter_notify_event(self, widget, event): 
     209                # TODO: same code as in chat window 
     210                pass 
     211 
     212        def on_avatar_eventbox_leave_notify_event(self, widget, event): 
     213                # TODO: same code as in chat window 
     214                pass 
     215 
     216        def on_avatar_eventbox_button_press_event(self, widget, event): 
     217                # TODO: same code as in chat window 
     218                pass 
    216219 
    217220        def on_single_message_window_destroy(self, widget): 
    218221                pass 
     222 
     223        def update_ui(self): 
     224                # The name banner is drawn here 
     225                ChatControlBase.update_ui(self) 
     226 
     227        def _update_banner_state_image(self): 
     228                # TODO: same code as in chat window 
     229                pass 
     230 
     231        def draw_banner_text(self): 
     232                '''Draw the text in the fat line at the top of the window that  
     233                houses the name, jid.  
     234                ''' 
     235 
     236                banner_name_label = self.xml.get_widget('banner_name_label') 
     237                banner_eventbox = self.xml.get_widget('banner_eventbox') 
     238 
     239                name = contact.get_shown_name() 
     240                if self.resource: 
     241                        name += '/' + self.resource 
     242                name = gobject.markup_escape_text(name) 
     243 
     244                # We know our contacts nick, but if another contact has the same nick 
     245                # in another account we need to also display the account. 
     246                # except if we are talking to two different resources of the same contact 
     247                acct_info = '' 
     248                for account in gajim.contacts.get_accounts(): 
     249                        if account == self.account: 
     250                                continue 
     251                        if acct_info: # We already found a contact with same nick 
     252                                break 
     253                        for jid in gajim.contacts.get_jid_list(account): 
     254                                contact_ = gajim.contacts.get_first_contact_from_jid(account, jid) 
     255                                if contact_.get_shown_name() == self.contact.get_shown_name(): 
     256                                        acct_info = ' (%s)' % \ 
     257                                                gobject.markup_escape_text(self.account) 
     258                                        break 
     259 
     260                status = contact.status 
     261                if status is not None: 
     262                        banner_name_label.set_ellipsize(pango.ELLIPSIZE_END) 
     263                        self.banner_status_label.set_ellipsize(pango.ELLIPSIZE_END) 
     264                        status_reduced = helpers.reduce_chars_newlines(status, max_lines=1) 
     265                status_escaped = gobject.markup_escape_text(status_reduced) 
     266 
     267                font_attrs, font_attrs_small = self.get_font_attrs() 
     268 
     269                # weight="heavy" size="x-large" 
     270                label_text = '<span %s>%s</span><span %s>%s</span>' % \ 
     271                        (font_attrs, name, font_attrs_small, acct_info) 
     272 
     273                if status_escaped: 
     274                        if gajim.HAVE_PYSEXY: 
     275                                status_text = self.urlfinder.sub(self.make_href, status_escaped) 
     276                                status_text = '<span %s>%s</span>' % (font_attrs_small, status_text) 
     277                        else: 
     278                                status_text = '<span %s>%s</span>' % (font_attrs_small, 
     279                                        status_escaped) 
     280                        self.status_tooltip.set_tip(banner_eventbox, status) 
     281                        self.banner_status_label.show() 
     282                        self.banner_status_label.set_no_show_all(False) 
     283                else: 
     284                        status_text = '' 
     285                        self.status_tooltip.disable() 
     286                        self.banner_status_label.hide() 
     287                        self.banner_status_label.set_no_show_all(True) 
     288 
     289                self.banner_status_label.set_markup(status_text) 
     290                # setup the label that holds name and jid 
     291                banner_name_label.set_markup(label_text) 
     292 
     293        def _update_gpg(self): 
     294                # TODO: same code as in chat window 
     295                pass 
     296 
     297        def get_tab_label(self, chatstate): 
     298                # TODO: same code as in chat window 
     299                unread = '' 
     300                if self.resource: 
     301                        jid = self.contact.get_full_jid() 
     302                else: 
     303                        jid = self.contact.jid 
     304                num_unread = len(gajim.events.get_events(self.account, jid, 
     305                        [self.type_id])) 
     306                if num_unread == 1 and not gajim.config.get('show_unread_tab_icon'): 
     307                        unread = '*' 
     308                elif num_unread > 1: 
     309                        unread = '[' + unicode(num_unread) + ']' 
     310                color = self.parent_win.notebook.style.fg[gtk.STATE_ACTIVE] 
     311 
     312                name = self.contact.get_shown_name() 
     313                if self.resource: 
     314                        name += '/' + self.resource 
     315                label_str = gobject.markup_escape_text(name) 
     316                if num_unread: # if unread, text in the label becomes bold 
     317                        label_str = '<b>' + unread + label_str + '</b>' 
     318                return (label_str, color) 
     319 
     320        def get_tab_image(self): 
     321                # TODO: same code as in chat window 
     322                if self.resource: 
     323                        jid = self.contact.get_full_jid() 
     324                else: 
     325                        jid = self.contact.jid 
     326                num_unread = len(gajim.events.get_events(self.account, jid, 
     327                        ['printed_' + self.type_id, self.type_id])) 
     328                # Set tab image (always 16x16); unread messages show the 'event' image 
     329                tab_img = None 
     330 
     331                if num_unread and gajim.config.get('show_unread_tab_icon'): 
     332                        img_16 = gajim.interface.roster.get_appropriate_state_images( 
     333                                self.contact.jid, icon_name = 'event') 
     334                        tab_img = img_16['event'] 
     335                else: 
     336                        contact = gajim.contacts.get_contact_with_highest_priority( 
     337                                self.account, self.contact.jid) 
     338                        if not contact or self.resource: 
     339                                # For transient contacts 
     340                                contact = self.contact 
     341                        img_16 = gajim.interface.roster.get_appropriate_state_images( 
     342                                self.contact.jid, icon_name = contact.show) 
     343                        tab_img = img_16[contact.show] 
     344 
     345                return tab_img 
    219346 
    220347        def set_cursor_to_end(self): 
     
    714841                self.window.destroy() 
    715842 
    716         def on_single_message_window_key_press_event(self, widget, event): 
    717                 if event.keyval == gtk.keysyms.Escape: # ESCAPE 
    718                         self.save_pos() 
    719                         self.window.destroy() 
     843        def shutdown(self): 
     844                # destroy banner tooltip - bug #pygtk for that! 
     845                self.status_tooltip.destroy() 
     846                # Send 'gone' chatstate 
     847                self.send_chatstate('gone', self.contact) 
     848                self.contact.chatstate = None 
     849                self.contact.our_chatstate = None 
     850                # Disconnect timer callbacks 
     851                gobject.source_remove(self.possible_paused_timeout_id) 
     852                gobject.source_remove(self.possible_inactive_timeout_id) 
     853                # Remove bigger avatar window 
     854                if self.bigger_avatar_window: 
     855                        self.bigger_avatar_window.destroy() 
     856                # Clean events 
     857                gajim.events.remove_events(self.account, self.get_full_jid(), 
     858                types = [self.type_id]) 
     859                # remove all register handlers on wigets, created by self.xml 
     860                # to prevent circular references among objects 
     861                for i in self.handlers.keys(): 
     862                        if self.handlers[i].handler_is_connected(i): 
     863                                self.handlers[i].disconnect(i) 
     864                        del self.handlers[i] 
     865                self.conv_textview.del_handlers() 
     866                self.msg_textview.destroy() 
     867 
     868        def allow_shutdown(self, method): 
     869                if time.time() - gajim.last_message_time[self.account]\ 
     870                [self.get_full_jid()] < 2: 
     871                        # 2 seconds 
     872                        dialog = dialogs.ConfirmationDialog( 
     873                                #%s is being replaced in the code with JID 
     874                                _('You just received a new message from "%s"') % self.contact.jid, 
     875                                _('If you close this tab and you have history disabled, '\ 
     876                                'this message will be lost.')) 
     877                        if dialog.get_response() != gtk.RESPONSE_OK: 
     878                                return 'no' # stop the propagation of the event 
     879                return 'yes' 
     880         
     881        def show_avatar(self, resource = None): 
     882                if not gajim.config.get('show_avatar_in_chat'): 
     883                        return 
     884 
     885                jid_with_resource = self.contact.jid 
     886                if resource: 
     887                        jid_with_resource += '/' + resource 
     888 
     889                # we assume contact has no avatar 
     890                scaled_pixbuf = None 
     891 
     892                pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid_with_resource, 
     893                        False) 
     894                if pixbuf == 'ask': 
     895                        # we don't have the vcard 
     896                        gajim.connections[self.account].request_vcard(jid_with_resource) 
     897                        return 
     898                if pixbuf is not None: 
     899                        scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'chat') 
     900 
     901                image = self.xml.get_widget('avatar_image') 
     902                image.set_from_pixbuf(scaled_pixbuf) 
     903                image.show_all() 
     904 
     905        def show_bigger_avatar(self, small_avatar): 
     906                # TODO: same code as in chat window 
     907                pass 
     908 
     909        def _on_window_avatar_leave_notify_event(self, widget, event): 
     910                # TODO: same code as in chat window 
     911                pass 
     912 
     913        def _on_window_motion_notify_event(self, widget, event): 
     914                # TODO: same code as in chat window 
     915                pass 
     916 
     917        def got_connected(self): 
     918                ChatControlBase.got_connected(self) 
     919                # Refreshing contact 
     920                contact = gajim.contacts.get_contact_with_highest_priority( 
     921                        self.account, self.contact.jid) 
     922                if contact: 
     923                        self.contact = contact 
     924                        self.draw_banner()