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

def catfish::catfish::find (   self )
Do the actual search.

Definition at line 574 of file catfish.py.

                  :
        """Do the actual search."""

        self.button_find.set_label(gtk.STOCK_CANCEL)
        self.window_search.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
        self.window_search.set_title(_('Searching for "%s"') % self.entry_find_text.get_text())
        self.statusbar.push(self.statusbar.get_context_id('results'), _('Searching...'))
        while gtk.events_pending(): gtk.main_iteration()

        # Reset treeview
        listmodel = gtk.ListStore(gtk.gdk.Pixbuf, str, int, str, str)
        self.treeview_files.set_model(listmodel)
        self.treeview_files.columns_autosize()

        # Retrieve search parameters
        keywords = self.entry_find_text.get_text()
        method = self.get_selected_find_method()
        folder = self.button_find_folder.get_filename()
        exact = self.checkbox_find_exact.get_active()
        hidden = self.checkbox_find_hidden.get_active()
        fulltext = self.checkbox_find_fulltext.get_active()
        if self.checkbox_find_limit.get_active():
            limit = self.spin_find_limit.get_value()
        else:
            limit = -1

        if keywords != '':
            # Generate search command
            options = self.get_find_options(method, folder, limit)
            (a, daemon, default, a, a, a, wildcards, file_manual, path_manual
                , exact_manual, errors_ignore) = options

            # Set display options
            if not self.options.icons_large and not self.options.thumbnails:
                icon_size = gtk.ICON_SIZE_SMALL_TOOLBAR
            else:
                icon_size = gtk.ICON_SIZE_DIALOG
            if not self.options.time_iso:
                time_format = '%x %X'
            else:
                time_format = '%Y-%m-%d %H:%M'

            # Run search command and capture the results
            messages = []
            if ('*' in keywords or '?' in keywords) and not wildcards:
                status_icon = gtk.STOCK_CANCEL
                messages.append([_('The search backend doesn\'t support wildcards.'), None])
                status = _('No files found for "%s".') % keywords
            else:
                try:
                    if default[:7] == 'dbus://':
                        query = dbus_query(options)
                    else:
                        query = shell_query(options)
                except Exception, msg:
                    if self.options.debug: print 'Debug:', msg
                    query = generic_query()
                for filename in query.run(keywords, folder, exact, hidden, limit):
                    if self.abort_find or len(listmodel) == limit: break
                    filename = filename.split(os.linesep)[0]
                    # Convert uris to filenames
                    if filename[:7] == 'file://':
                        filename = filename[7:]
                    # Handle mailbox uris like filenames as well
                    if filename[:10] == 'mailbox://':
                        filename = filename[10:]
                        filename = filename[:filename.index('?')]
                    path, name = os.path.split(filename)
                    if (path_manual or exact_manual) and not fulltext:
                        if not self.string_wild_match(name, keywords, exact):
                            yield True
                            continue
                    if path_manual and not folder in path:
                        yield True
                        continue
                    if not hidden and self.file_is_hidden(filename, folder):
                        yield True
                        continue
                    mime_type = self.get_mime_type(os.path.join(path, filename))
                    if not self.file_is_wanted(filename, mime_type):
                        yield True
                        continue
                    if self.options.thumbnails:
                        icon = self.get_thumbnail(filename, icon_size, mime_type)
                    else:
                        icon = self.get_file_icon(filename, icon_size, mime_type)
                    try:
                        filestat = os.stat(filename)
                        size = filestat.st_size
                        modified = time.strftime(time_format, time.gmtime(filestat.st_mtime))
                        name = name.replace('&', '&')
                        if not self.options.icons_large and not self.options.thumbnails:
                            listmodel.append([icon, name, size, path, modified])
                        else:
                            path = path.replace('&', '&')
                            if modified <> '':
                                modified = os.linesep + modified
                            listmodel.append([icon, '%s %s%s%s%s' % (name
                            , self.format_size(size), os.linesep, path
                            , modified), -1, name, path])
                    except Exception, msg:
                        if self.options.debug: print 'Debug:', msg
                        pass # Ignore inaccessible files
                    self.treeview_files.set_model(listmodel)
                    yield True
                if len(listmodel) == 0:
                    if not errors_ignore and query.status():
                        status_icon = gtk.STOCK_CANCEL
                        messages.append([_('Fatal error, search was aborted.'), None])
                        if daemon <> '':
                            link_format = '<u><span foreground="%s">%s</span></u>'
                            messages.append([link_format % (self.link_color,
                                _('Click here to start the search daemon.')),
                                '<span size="0">daemon:' + daemon + '</span>'])
                    else:
                        status_icon = gtk.STOCK_INFO
                        messages.append([_('No files were found.'), None])
                    status = _('No files found for "%s".') % keywords
                else:
                    status = _('%s files found for "%s".') % (len(listmodel), keywords)
            for message, action in messages:
                icon = [None, self.get_icon_pixbuf(status_icon)][message == messages[0][0]]
                listmodel.append([icon, message, -1, None, action])
            self.statusbar.push(self.statusbar.get_context_id('results'), status)
        self.treeview_files.set_model(listmodel)

        self.window_search.window.set_cursor(None)
        self.button_find.set_label(gtk.STOCK_FIND)
        yield False


Generated by  Doxygen 1.6.0   Back to index