Logo Search packages:      
Sourcecode: gajim version File versions  Download package

def roster_window::RosterWindow::make_menu (   self  ) 

create the main window's menus

Definition at line 651 of file roster_window.py.

00651                          :
            '''create the main window's menus'''
            if not self.actions_menu_needs_rebuild:
                  return
            new_chat_menuitem = self.xml.get_widget('new_chat_menuitem')
            join_gc_menuitem = self.xml.get_widget('join_gc_menuitem')
            add_new_contact_menuitem = self.xml.get_widget('add_new_contact_menuitem')
            service_disco_menuitem = self.xml.get_widget('service_disco_menuitem')
            advanced_menuitem = self.xml.get_widget('advanced_menuitem')
            show_offline_contacts_menuitem = self.xml.get_widget(
                  'show_offline_contacts_menuitem')
            profile_avatar_menuitem = self.xml.get_widget('profile_avatar_menuitem')      

            # destroy old advanced menus
            for m in self.advanced_menus:
                  m.destroy()

            # make it sensitive. it is insensitive only if no accounts are *available*
            advanced_menuitem.set_sensitive(True)

            if self.add_new_contact_handler_id:
                  add_new_contact_menuitem.handler_disconnect(
                        self.add_new_contact_handler_id)
                  self.add_new_contact_handler_id = None

            if self.service_disco_handler_id:
                  service_disco_menuitem.handler_disconnect(
                        self.service_disco_handler_id)
                  self.service_disco_handler_id = None

            if self.new_chat_menuitem_handler_id:
                  new_chat_menuitem.handler_disconnect(
                        self.new_chat_menuitem_handler_id)
                  self.new_chat_menuitem_handler_id = None

            if self.profile_avatar_menuitem_handler_id:
                  profile_avatar_menuitem.handler_disconnect(
                        self.profile_avatar_menuitem_handler_id)
                  self.profile_avatar_menuitem_handler_id = None


            # remove the existing submenus
            add_new_contact_menuitem.remove_submenu()
            service_disco_menuitem.remove_submenu()
            join_gc_menuitem.remove_submenu()
            new_chat_menuitem.remove_submenu()
            advanced_menuitem.remove_submenu()
            profile_avatar_menuitem.remove_submenu()

            # remove the existing accelerator
            if self.have_new_chat_accel:
                  ag = gtk.accel_groups_from_object(self.window)[0]
                  new_chat_menuitem.remove_accelerator(ag, gtk.keysyms.n,
                        gtk.gdk.CONTROL_MASK)
                  self.have_new_chat_accel = False

            gc_sub_menu = gtk.Menu() # gc is always a submenu
            join_gc_menuitem.set_submenu(gc_sub_menu)
            
            connected_accounts = gajim.get_number_of_connected_accounts()
            if connected_accounts > 1: # 2 or more accounts? make submenus
                  add_sub_menu = gtk.Menu()
                  disco_sub_menu = gtk.Menu()
                  new_chat_sub_menu = gtk.Menu()
                  profile_avatar_sub_menu = gtk.Menu()
                  
                  for account in gajim.connections:
                        if gajim.connections[account].connected <= 1:
                              # if offline or connecting
                              continue
                        
                        # join gc
                        label = gtk.Label()
                        label.set_markup('<u>' + account.upper() +'</u>')
                        label.set_use_underline(False)
                        gc_item = gtk.MenuItem()
                        gc_item.add(label)
                        gc_item.connect('state-changed', self.on_bm_header_changed_state)
                        gc_sub_menu.append(gc_item)
                        
                        self.add_bookmarks_list(gc_sub_menu, account)

                        # the 'manage gc bookmarks' item is showed
                        # below to avoid duplicate code

                        # add
                        add_item = gtk.MenuItem(_('to %s account') % account, False)
                        add_sub_menu.append(add_item)
                        add_item.connect('activate', self.on_add_new_contact, account)
                        add_new_contact_menuitem.set_submenu(add_sub_menu)
                        add_sub_menu.show_all()

                        # disco
                        disco_item = gtk.MenuItem(_('using %s account') % account, False)
                        disco_sub_menu.append(disco_item)
                        disco_item.connect('activate',
                              self.on_service_disco_menuitem_activate, account)
                        service_disco_menuitem.set_submenu(disco_sub_menu)
                        disco_sub_menu.show_all()

                        # new chat
                        new_chat_item = gtk.MenuItem(_('using account %s') % account,
                              False)
                        new_chat_sub_menu.append(new_chat_item)
                        new_chat_item.connect('activate',
                              self.on_new_chat_menuitem_activate, account)
                        new_chat_menuitem.set_submenu(new_chat_sub_menu)
                        new_chat_sub_menu.show_all()
                        
                        # profile, avatar
                        profile_avatar_item = gtk.MenuItem(_('of account %s') % account, 
                               False)
                        profile_avatar_sub_menu.append(profile_avatar_item)
                        profile_avatar_item.connect('activate', 
                              self.on_profile_avatar_menuitem_activate, account)
                        profile_avatar_menuitem.set_submenu(profile_avatar_sub_menu)
                        profile_avatar_sub_menu.show_all()

            elif connected_accounts == 1: # user has only one account
                  for account in gajim.connections:
                        if gajim.connections[account].connected > 1: # THE connected account
                              # gc
                              self.add_bookmarks_list(gc_sub_menu, account)
                              # add
                              if not self.add_new_contact_handler_id:
                                    self.add_new_contact_handler_id =\
                                          add_new_contact_menuitem.connect(
                                          'activate', self.on_add_new_contact, account)
                              # disco
                              if not self.service_disco_handler_id:
                                    self.service_disco_handler_id = service_disco_menuitem.connect(
                                          'activate', self.on_service_disco_menuitem_activate, account)
                              # new chat
                              if not self.new_chat_menuitem_handler_id:
                                    self.new_chat_menuitem_handler_id = new_chat_menuitem.\
                                          connect('activate', self.on_new_chat_menuitem_activate,
                                          account)
                              # new chat accel
                              if not self.have_new_chat_accel:
                                    ag = gtk.accel_groups_from_object(self.window)[0]
                                    new_chat_menuitem.add_accelerator('activate', ag,
                                          gtk.keysyms.n,    gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
                                    self.have_new_chat_accel = True
                              
                              # profile, avatar
                              if not self.profile_avatar_menuitem_handler_id:
                                    self.profile_avatar_menuitem_handler_id = \
                                    profile_avatar_menuitem.connect('activate', self.\
                                    on_profile_avatar_menuitem_activate, account)

                              break # No other account connected
            
            if connected_accounts == 0:
                  # no connected accounts, make the menuitems insensitive
                  new_chat_menuitem.set_sensitive(False)
                  join_gc_menuitem.set_sensitive(False)
                  add_new_contact_menuitem.set_sensitive(False)
                  service_disco_menuitem.set_sensitive(False)
                  profile_avatar_menuitem.set_sensitive(False)
            else: # we have one or more connected accounts
                  new_chat_menuitem.set_sensitive(True)
                  join_gc_menuitem.set_sensitive(True)
                  add_new_contact_menuitem.set_sensitive(True)
                  service_disco_menuitem.set_sensitive(True)
                  profile_avatar_menuitem.set_sensitive(True)
                  # show the 'manage gc bookmarks' item
                  newitem = gtk.SeparatorMenuItem() # separator
                  gc_sub_menu.append(newitem)

                  newitem = gtk.ImageMenuItem(_('Manage Bookmarks...'))
                  img = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES,
                        gtk.ICON_SIZE_MENU)
                  newitem.set_image(img)
                  newitem.connect('activate', self.on_manage_bookmarks_menuitem_activate)
                  gc_sub_menu.append(newitem)
                  gc_sub_menu.show_all()
                  
            # Advanced Actions
            if len(gajim.connections) == 0: # user has no accounts
                  advanced_menuitem.set_sensitive(False)
            elif len(gajim.connections) == 1: # we have one acccount
                  account = gajim.connections.keys()[0]
                  advanced_menuitem_menu = self.get_and_connect_advanced_menuitem_menu(
                        account)
                  self.advanced_menus.append(advanced_menuitem_menu)
            
                  self._add_history_manager_menuitem(advanced_menuitem_menu)

                  advanced_menuitem.set_submenu(advanced_menuitem_menu)
                  advanced_menuitem_menu.show_all()
            else: # user has *more* than one account : build advanced submenus
                  advanced_sub_menu = gtk.Menu()
                  for account in gajim.connections:
                        advanced_item = gtk.MenuItem(_('for account %s') % account, False)
                        advanced_sub_menu.append(advanced_item)
                        advanced_menuitem_menu = self.get_and_connect_advanced_menuitem_menu(
                              account)
                        self.advanced_menus.append(advanced_menuitem_menu)
                        advanced_item.set_submenu(advanced_menuitem_menu)
                  
                  self._add_history_manager_menuitem(advanced_sub_menu)
                  
                  advanced_menuitem.set_submenu(advanced_sub_menu)
                  advanced_sub_menu.show_all()

            self.actions_menu_needs_rebuild = False

      def _add_history_manager_menuitem(self, menu):


Generated by  Doxygen 1.6.0   Back to index