~alexeftimie/software-center/debian-small-fixes

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk/softwarepane.py

  • Committer: Gary Lasker
  • Date: 2011-05-25 20:34:02 UTC
  • mfrom: (1792.1.1 software-center)
  • Revision ID: gary.lasker@canonical.com-20110525203402-l692ovne7areetdh
merged lp:~evfool/software-center/search-suggestions, very nice work, thank you Robert Roth

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import gtk
26
26
import logging
27
27
import xapian
 
28
import copy
28
29
 
29
30
from gettext import gettext as _
30
31
 
33
34
from widgets.searchentry import SearchEntry
34
35
from widgets.actionbar import ActionBar
35
36
from widgets.spinner import SpinnerView
36
 
 
 
37
from softwarecenter.enums import NAV_BUTTON_ID_SUBCAT
37
38
import softwarecenter.utils
38
39
 
39
40
from softwarecenter.backend import get_install_backend
600
601
                self.action_bar.set_label(label, link_result=self._show_nonapp_pkgs)
601
602
 
602
603
    def update_search_help(self):
 
604
        def build_category_path():
 
605
            if not self.apps_category:
 
606
                return None
 
607
            if not self.apps_subcategory:
 
608
                return self.apps_category.name
 
609
            return u"%s \u25b8 %s"%(self.apps_category.name,self.apps_subcategory.name) 
603
610
        search = self.searchentry.get_text()
604
611
        appstore = self.app_view.get_model()
605
612
        if (search and appstore is not None and len(appstore) == 0):
606
613
            category = self.get_current_category()
607
614
            correction = self.db.get_spelling_correction(search)
 
615
            text = "<b>%s</b>\n\n"%(_('No results for "%s"')%search)
 
616
            option_template = "\t - %s\n\n"
 
617
            if not category:
 
618
                text += _('No items match "%s". Suggestions:')%search+"\n\n"
 
619
            else:
 
620
                text += _('No items in %s match "%s". Suggestions:')%("<b>%s</b>"%build_category_path(), search)+"\n\n"
 
621
 
 
622
            if self.apps_subcategory:
 
623
                parent_model = AppStore(self.cache,
 
624
                             self.db,
 
625
                             self.icons,
 
626
                             self.db.get_query_list_from_search_entry(search,
 
627
                                                        self.apps_category.query),
 
628
                             limit=self.get_app_items_limit(),
 
629
                             sortmode=self.get_sort_mode(),
 
630
                             nonapps_visible = self.nonapps_visible,
 
631
                             filter=self.apps_filter,
 
632
                             nonblocking_load=False,
 
633
                             search_term=search)
 
634
                if parent_model.nr_apps>0:
 
635
                    text += option_template%(gettext.ngettext("Try "
 
636
                         "<a href=\"search-parent:\">the item "
 
637
                         "in %(category)s</a> that matches.", "Try "
 
638
                         "<a href=\"search-parent:\">the %(n)d items "
 
639
                         "in %(category)s</a> that match.", n=parent_model.nr_apps)%\
 
640
                         {'category':self.apps_category.name,'n':parent_model.nr_apps})
 
641
            if self.apps_filter.get_supported_only(): 
 
642
                unsupported = copy.copy(self.apps_filter)
 
643
                unsupported.set_supported_only(False)
 
644
                unsupported_model = AppStore(self.cache,
 
645
                             self.db,
 
646
                             self.icons,
 
647
                             self.app_view.get_model().search_query,
 
648
                             limit=self.get_app_items_limit(),
 
649
                             sortmode=self.get_sort_mode(),
 
650
                             nonapps_visible = self.nonapps_visible,
 
651
                             filter=unsupported,
 
652
                             nonblocking_load=False,
 
653
                             search_term=search)
 
654
                if unsupported_model.nr_apps>0:
 
655
                    text += option_template%(gettext.ngettext("Try "
 
656
                         "<a href=\"search-unsupported:\">the %(amount)d item "
 
657
                         "that matches</a> in software not maintained by Canonical.", 
 
658
                         "Try <a href=\"search-unsupported:\">the %(amount)d items "
 
659
                         "that match</a> in software not maintained by Canonical.",unsupported_model.nr_apps)%{'amount':unsupported_model.nr_apps})
608
660
            if category:
609
 
                text = _("Search term not found in current category. "
610
 
                         "Do you want to search "
611
 
                         "<a href=\"search-all:\">all categories</a> instead?")
612
 
                self.label_app_list_header.set_markup(text)
613
 
                self.label_app_list_header.set_visible(True)
614
 
                return
615
 
            elif correction:
 
661
                text += option_template%_("Try searching in "
 
662
                         "<a href=\"search-all:\">all categories</a> instead.")
 
663
            if correction:
616
664
                ref = "<a href=\"search:%s\">%s</a>" % (correction, correction)
617
 
                text = _("Search term not found. Did you mean: %s?") % ref
618
 
                self.label_app_list_header.set_markup(text)
619
 
                self.label_app_list_header.set_visible(True)
620
 
                return
 
665
                text += option_template%_("Check the search is spelled correctly. Did you mean: %s?") % ref
 
666
            text += option_template%gettext.ngettext("Try using a different word.", "Try using fewer words or different words", len(search.split()))
 
667
                
 
668
            self.label_app_list_header.set_markup(text)
 
669
            self.label_app_list_header.set_visible(True)
 
670
            return
621
671
        # catchall, hide if we don't have anything useful to suggest
622
672
        self.label_app_list_header.set_visible(False)
623
673
            
628
678
        elif uri.startswith("search-all:"):
629
679
            self.unset_current_category()
630
680
            self.refresh_apps()
 
681
        elif uri.startswith("search-parent:"):
 
682
            self.apps_subcategory = None;
 
683
            self.navigation_bar.remove_id(NAV_BUTTON_ID_SUBCAT, animate=True)
 
684
            self.refresh_apps()
 
685
        elif uri.startswith("search-unsupported:"):
 
686
            self.apps_filter.set_supported_only(False)
 
687
            self.refresh_apps()
631
688
        # FIXME: add ability to remove categories restriction here
632
689
        # True stops event propergation
633
690
        return True