Changeset 9960

Show
Ignore:
Timestamp:
07/19/08 19:36:21 (7 weeks ago)
Author:
steve-e
Message:

Improved groupchat minimization:

  • partly rewrote join_room because it was hard to read
  • Correctly handle invites from anonymous rooms. Fixes #4057
  • Use HIG dialog for invitation requests
  • Fix bug where minimized groupchats where hidden after a reconnect
  • Removed some duplicated code
Location:
trunk
Files:
1 removed
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/dialogs.py

    r9903 r9960  
    22152215 
    22162216        def set_cursor_to_end(self): 
    2217                         end_iter = self.message_tv_buffer.get_end_iter() 
    2218                         self.message_tv_buffer.place_cursor(end_iter) 
     2217                end_iter = self.message_tv_buffer.get_end_iter() 
     2218                self.message_tv_buffer.place_cursor(end_iter) 
    22192219 
    22202220        def save_pos(self): 
     
    29212921                self.password = password 
    29222922                self.is_continued = is_continued 
    2923                 xml = gtkgui_helpers.get_glade('invitation_received_dialog.glade') 
    2924                 self.dialog = xml.get_widget('invitation_received_dialog') 
    2925  
     2923 
     2924                pritext = _('''You are invited to a groupchat''') 
    29262925                #Don't translate $Contact 
    29272926                if is_continued: 
    2928                         pritext = _('$Contact has invited you to join a discussion') 
    2929                 else: 
    2930                         pritext = _('$Contact has invited you to group chat %(room_jid)s')\ 
     2927                        sectext = _('$Contact has invited you to join a discussion') 
     2928                else: 
     2929                        sectext = _('$Contact has invited you to group chat %(room_jid)s')\ 
    29312930                                % {'room_jid': room_jid} 
    29322931                contact = gajim.contacts.get_first_contact_from_jid(account, contact_jid) 
    2933                 if contact and contact.name: 
    2934                         contact_text = '%s (%s)' % (contact.name, contact_jid) 
    2935                 else: 
    2936                         contact_text = contact_jid 
    2937                 pritext = pritext.replace('$Contact', contact_text) 
    2938  
    2939                 label_text = '<big><b>%s</b></big>' % pritext 
     2932                contact_text = contact and contact.name or contact_jid 
     2933                sectext = sectext.replace('$Contact', contact_text) 
    29402934 
    29412935                if comment: # only if not None and not '' 
    29422936                        comment = gobject.markup_escape_text(comment) 
    2943                         sectext = _('Comment: %s') % comment 
    2944                         label_text += '\n\n%s' % sectext 
    2945  
    2946                 xml.get_widget('label').set_markup(label_text) 
    2947  
    2948                 xml.get_widget('deny_button').connect('clicked', 
    2949                         self.on_deny_button_clicked) 
    2950                 xml.get_widget('accept_button').connect('clicked', 
    2951                         self.on_accept_button_clicked) 
    2952                 self.dialog.show_all() 
    2953  
    2954         def on_deny_button_clicked(self, widget): 
    2955                 self.dialog.destroy() 
    2956  
    2957         def on_accept_button_clicked(self, widget): 
    2958                 self.dialog.destroy() 
    2959                 try: 
    2960                         if self.is_continued: 
    2961                                 gajim.interface.join_gc_room(self.account, self.room_jid, 
    2962                                         gajim.nicks[self.account], None, is_continued=True) 
    2963                         else: 
    2964                                 JoinGroupchatWindow(self.account, self.room_jid) 
    2965                 except GajimGeneralException: 
    2966                         pass 
     2937                        comment = _('Comment: %s') % comment 
     2938                        sectext += '\n\n%s' % comment 
     2939                sectext += '\n\n' + _('Do you want to accept the invitation?') 
     2940                 
     2941                dialog = YesNoDialog(pritext, sectext) 
     2942                if dialog.get_response() == gtk.RESPONSE_YES: 
     2943                        try: 
     2944                                if self.is_continued: 
     2945                                        gajim.interface.join_gc_room(self.account, self.room_jid, 
     2946                                                gajim.nicks[self.account], None, is_continued=True) 
     2947                                else: 
     2948                                        JoinGroupchatWindow(self.account, self.room_jid) 
     2949                        except GajimGeneralException: 
     2950                                pass 
    29672951 
    29682952class ProgressDialog: 
  • trunk/src/gajim.py

    r9956 r9960  
    21292129                if type_ in ('printed_gc_msg', 'printed_marked_gc_msg', 'gc_msg'): 
    21302130                        w = self.msg_win_mgr.get_window(jid, account) 
    2131                         if self.minimized_controls[account].has_key(jid): 
    2132                                 if not w: 
    2133                                         ctrl = self.minimized_controls[account][jid] 
    2134                                         w = self.msg_win_mgr.create_window(ctrl.contact, \ 
    2135                                                 ctrl.account, ctrl.type_id) 
     2131                        if jid in self.minimized_controls[account]: 
    21362132                                self.roster.on_groupchat_maximized(None, jid, account) 
    21372133 
     
    24742470 
    24752471        def join_gc_room(self, account, room_jid, nick, password, minimize=False, 
    2476                 is_continued=False): 
     2472        is_continued=False): 
    24772473                '''joins the room immediately''' 
    24782474                if not nick: 
    24792475                        nick = gajim.nicks[account] 
     2476 
    24802477                if self.msg_win_mgr.has_window(room_jid, account) and \ 
    2481                                 gajim.gc_connected[account][room_jid]: 
     2478                gajim.gc_connected[account][room_jid]: 
    24822479                        gc_ctrl = self.msg_win_mgr.get_gc_control(room_jid, account) 
    24832480                        win = gc_ctrl.parent_win 
     
    24852482                        dialogs.ErrorDialog(_('You are already in group chat %s') % room_jid) 
    24862483                        return 
    2487                 minimized_control_exists = False 
    2488                 if room_jid in gajim.interface.minimized_controls[account]: 
    2489                         minimized_control_exists = True 
     2484 
    24902485                invisible_show = gajim.SHOW_LIST.index('invisible') 
    24912486                if gajim.connections[account].connected == invisible_show: 
     
    24932488                                _('You cannot join a group chat while you are invisible')) 
    24942489                        return 
    2495                 if minimize and not minimized_control_exists and \ 
     2490 
     2491                minimized_control_exists = False 
     2492                if room_jid in gajim.interface.minimized_controls[account]: 
     2493                        minimized_control_exists = True 
     2494 
     2495                if not minimized_control_exists and \ 
    24962496                not self.msg_win_mgr.has_window(room_jid, account): 
    2497                         contact = gajim.contacts.create_contact(jid=room_jid, name=nick) 
    2498                         gc_control = GroupchatControl(None, contact, account) 
    2499                         self.minimized_controls[account][room_jid] = gc_control 
    2500                         gajim.connections[account].join_gc(nick, room_jid, password) 
    2501                         if password: 
    2502                                 gajim.gc_passwords[room_jid] = password 
     2497                        # Join new groupchat 
     2498                        if minimize: 
     2499                                contact = gajim.contacts.create_contact(jid=room_jid, name=nick) 
     2500                                gc_control = GroupchatControl(None, contact, account) 
     2501                                gajim.interface.minimized_controls[account][room_jid] = gc_control 
     2502                                self.roster.add_groupchat(room_jid, account) 
     2503                        else: 
     2504                                self.new_room(room_jid, nick, account, is_continued=is_continued) 
     2505                elif not minimized_control_exists: 
     2506                        # We are already in that groupchat 
     2507                        gc_control = self.msg_win_mgr.get_gc_control(room_jid, account) 
     2508                        gc_control.parent_win.set_active_tab(gc_control)         
     2509                else: 
     2510                        # We are already in this groupchat and it is minimized 
    25032511                        self.roster.add_groupchat(room_jid, account) 
    2504                         return 
    2505                 if not minimized_control_exists and \ 
    2506                         not self.msg_win_mgr.has_window(room_jid, account): 
    2507                         self.new_room(room_jid, nick, account, is_continued=is_continued) 
    2508                 if not minimized_control_exists: 
    2509                         gc_control = self.msg_win_mgr.get_gc_control(room_jid, account) 
    2510                         gc_control.parent_win.set_active_tab(gc_control) 
     2512 
     2513                # Connect 
    25112514                gajim.connections[account].join_gc(nick, room_jid, password) 
    25122515                if password: 
    25132516                        gajim.gc_passwords[room_jid] = password 
    2514                 contact = gajim.contacts.get_contact_with_highest_priority(account, \ 
    2515                         room_jid) 
    2516                 if contact or minimized_control_exists: 
    2517                         self.roster.add_groupchat(room_jid, account) 
    25182517 
    25192518        def new_room(self, room_jid, nick, account, is_continued=False): 
     
    28222821                                # Only join non-opened groupchats. Opened one are already 
    28232822                                # auto-joined on re-connection 
    2824                                 if not gajim.gc_connected[account].has_key(jid): 
     2823                                if not jid in gajim.gc_connected[account]: 
    28252824                                        # we are not already connected 
    28262825                                        minimize = bm['minimize'] in ('1', 'true') 
    28272826                                        gajim.interface.join_gc_room(account, jid, bm['nick'], 
    28282827                                        bm['password'], minimize = minimize) 
     2828                                elif jid in self.minimized_controls[account]: 
     2829                                        # more or less a hack: 
     2830                                        # On disconnect the minimized gc contact instances  
     2831                                        # were set to offline. Reconnect them to show up in the roster. 
     2832                                        self.roster.add_groupchat(jid, account) 
    28292833 
    28302834        def add_gc_bookmark(self, account, name, jid, autojoin, minimize, password, 
  • trunk/src/groupchat_control.py

    r9931 r9960  
    16251625                ctrl.parent_win = None 
    16261626 
    1627                 gajim.interface.minimized_controls[self.account][self.contact.jid] = \ 
    1628                         ctrl 
    1629  
    1630                 del win._controls[self.account][self.contact.jid] 
    1631  
    16321627                gajim.interface.roster.add_groupchat(self.contact.jid, self.account, 
    16331628                        status = self.subject) 
     1629 
     1630                del win._controls[self.account][self.contact.jid] 
    16341631 
    16351632        def shutdown(self, status='offline'): 
  • trunk/src/roster_window.py

    r9945 r9960  
    706706                                self._remove_entity(contact, account) 
    707707 
    708  
    709708                        if backend: 
    710709                                # Remove contact before redrawing, otherwise the old 
     
    731730                ''' 
    732731                contact = gajim.contacts.get_contact_with_highest_priority(account, jid) 
     732                # Do not show gc if we are disconnected and minimize it 
     733                if gajim.account_is_connected(account): 
     734                        show = 'online' 
     735                else:  
     736                        show = 'offline' 
     737                        status = '' 
     738 
    733739                if contact is None: 
    734                         # Do not show gc if we are disconnected and minimize it 
    735                         if gajim.account_is_connected(account): 
    736                                 show = 'online' 
    737                         else:  
    738                                 show = 'offline' 
    739                                 status = '' 
     740                        # New groupchat 
    740741                        contact = gajim.contacts.create_contact(jid=jid, name=jid, 
    741742                                groups=[_('Groupchats')], show=show, status=status, sub='none') 
    742743                        gajim.contacts.add_contact(account, contact) 
     744                        gc_control = gajim.interface.msg_win_mgr.get_gc_control(jid, account) 
     745                        if gc_control: 
     746                                # there is a window that we can minimize 
     747                                gajim.interface.minimized_controls[account][jid] = gc_control 
    743748                        self.add_contact(jid, account) 
    744749                else: 
    745                         contact.show = 'online' 
     750                        contact.show = show 
     751                        contact.status = status 
    746752                        self.draw_completely_and_show_if_needed(jid, account) 
     753 
    747754                return contact 
    748755 
     
    752759                contact = gajim.contacts.get_contact_with_highest_priority(account, jid) 
    753760                if contact.is_groupchat(): 
     761                        if jid in gajim.interface.minimized_controls[account]: 
     762                                gajim.interface.minimized_controls[account][jid] 
    754763                        self.remove_contact(jid, account, force=True, backend=True) 
    755764                        return True 
     
    962971 
    963972                # gets number of unread gc marked messages 
    964                 if jid in gajim.interface.minimized_controls[account]: 
     973                if jid in gajim.interface.minimized_controls[account] and \ 
     974                gajim.interface.minimized_controls[account][jid]: 
    965975                        nb_unread = len(gajim.events.get_events(account, jid, 
    966976                                ['printed_marked_gc_msg'])) 
     
    15821592                return False 
    15831593 
    1584         def auto_join_bookmarks(self, account): 
    1585                 '''autojoin bookmarks that have 'auto join' on for this account''' 
    1586                 for bm in gajim.connections[account].bookmarks: 
    1587                         if bm['autojoin'] in ('1', 'true'): 
    1588                                 jid = bm['jid'] 
    1589                                 if not gajim.gc_connected[account].has_key(jid) or\ 
    1590                                         not gajim.gc_connected[account][jid]: 
    1591                                         # we are not already connected 
    1592                                         minimize = bm['minimize'] in ('1', 'true') 
    1593                                         gajim.interface.join_gc_room(account, jid, bm['nick'], 
    1594                                         bm['password'], minimize = minimize) 
    1595  
    15961594        def on_event_removed(self, event_list): 
    15971595                '''Remove contacts on last events removed. 
     
    26522650        def on_disconnect(self, widget, jid, account): 
    26532651                '''When disconnect menuitem is activated: disconect from room''' 
    2654                 ctrl = gajim.interface.minimized_controls[account][jid] 
    2655                 del gajim.interface.minimized_controls[account][jid] 
    2656                 ctrl.shutdown() 
     2652                if jid in gajim.interface.minimized_controls[account]: 
     2653                        ctrl = gajim.interface.minimized_controls[account][jid] 
     2654                        ctrl.shutdown() 
    26572655                self.remove_groupchat(jid, account) 
    26582656 
     
    27232721        def on_groupchat_maximized(self, widget, jid, account): 
    27242722                '''When a groupchat is maximised''' 
     2723                if not jid in gajim.interface.minimized_controls[account]: 
     2724                        return 
    27252725                ctrl = gajim.interface.minimized_controls[account][jid] 
    27262726                mw = gajim.interface.msg_win_mgr.get_window(ctrl.contact.jid, 
     
    27322732                mw.new_tab(ctrl) 
    27332733                mw.set_active_tab(ctrl) 
    2734                 del gajim.interface.minimized_controls[account][jid] 
    2735  
     2734                 
    27362735                self.remove_groupchat(jid, account) 
    27372736 
     
    32413240                jid = model[path][C_JID].decode('utf-8') 
    32423241                resource = None 
    3243                 contact = None 
     3242                contact = gajim.contacts.get_first_contact_from_jid(account, jid) 
    32443243                titer = model.get_iter(path) 
    32453244                if type_ in ('group', 'account'): 
     
    32483247                        else: 
    32493248                                self.tree.expand_row(path, False) 
    3250                 elif jid in gajim.interface.minimized_controls[account]: 
    3251                         self.on_groupchat_maximized(None, jid, account) 
     3249                elif contact.is_groupchat(): 
     3250                        first_ev = gajim.events.get_first_event(account, jid) 
     3251                        if first_ev and self.open_event(account, jid, first_ev): 
     3252                                # We are invited to a GC 
     3253                                # open event cares about connecting to it 
     3254                                self.remove_groupchat(jid, account) 
     3255                        else: 
     3256                                self.on_groupchat_maximized(None, jid, account) 
    32523257                else: 
    32533258                        first_ev = gajim.events.get_first_event(account, jid)