home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.5)
-
- import os
- import urllib
- import sys
- import cgi
- import ConfigParser
- from os.path import join, basename, normpath, abspath, dirname
- from os.path import split, expanduser, exists, isfile, isdir
- from gettext import gettext as _
- import gobject
- import gtk
- import gnome
- import gnome.ui as gnome
- import gnomevfs
- import deskbar
- import deskbar.Indexer as deskbar
- import deskbar.Handler as deskbar
- import deskbar.Match as deskbar
- from deskbar.defs import VERSION
- from deskbar.Watcher import FileWatcher
- from deskbar.Utils import spawn_async, url_show_file
- HANDLERS = {
- 'FileFolderHandler': {
- 'name': _('Files, Folders and Places'),
- 'description': _('View your files, folders, bookmarks, drives, network places by name'),
- 'version': VERSION } }
- NETWORK_URIS = [
- 'http',
- 'ftp',
- 'smb',
- 'sftp']
- AUDIO_URIS = [
- 'cdda']
- MONITOR = gnomevfs.VolumeMonitor()
- GTK_BOOKMARKS_FILE = expanduser('~/.gtk-bookmarks')
-
- class FileMatch(deskbar.Match.Match):
-
- def __init__(self, backend, name = None, absname = None, **args):
- deskbar.Match.Match.__init__(self, backend, name = name, **args)
- self._icon = deskbar.Utils.load_icon_for_file(absname)
- self.absname = absname
-
-
- def action(self, text = None):
- url_show_file(self.absname)
-
-
- def is_valid(self, text = None):
- return exists(self.absname)
-
-
- def get_category(self):
- return 'files'
-
-
- def get_verb(self):
- return _('Open %s') % '<b>%(name)s</b>'
-
-
- def get_hash(self, text = None):
- return self.absname
-
-
-
- class FolderMatch(deskbar.Match.Match):
-
- def __init__(self, backend, name = None, absname = None, **args):
- deskbar.Match.Match.__init__(self, backend, name = name, **args)
- self._icon = deskbar.Utils.load_icon_for_file(absname)
- self.absname = absname
-
-
- def action(self, text = None):
- url_show_file(self.absname)
-
-
- def is_valid(self, text = None):
- return exists(self.absname)
-
-
- def get_category(self):
- return 'places'
-
-
- def get_verb(self):
- return _('Open folder %s') % '<b>%(name)s</b>'
-
-
- def get_hash(self, text = None):
- return self.absname
-
-
-
- class GtkBookmarkMatch(deskbar.Match.Match):
-
- def __init__(self, backend, name = None, path = None, **args):
- deskbar.Match.Match.__init__(self, backend, name = name, **args)
- self.path = path
-
-
- def action(self, text = None):
- spawn_async([
- 'nautilus',
- self.path])
-
-
- def is_valid(self, text = None):
- return exists(self.path)
-
-
- def get_category(self):
- return 'places'
-
-
- def get_verb(self):
- return _('Open location %s') % '<b>%(name)s</b>'
-
-
- def get_hash(self, text = None):
- return self.path
-
-
-
- class VolumeMatch(deskbar.Match.Match):
-
- def __init__(self, backend, name = None, drive = None, icon = None):
- deskbar.Match.Match.__init__(self, backend, name = name, icon = icon)
- self.drive = drive
-
-
- def action(self, text = None):
- if self.drive == None:
- spawn_async([
- 'nautilus'])
- else:
- spawn_async([
- 'nautilus',
- self.drive])
-
-
- def is_valid(self, text = None):
- return exists(self.drive)
-
-
- def get_category(self):
- return 'places'
-
-
- def get_verb(self):
- if self.drive == None:
- uri_scheme = None
- else:
- uri_scheme = gnomevfs.get_uri_scheme(self.drive)
- if uri_scheme in NETWORK_URIS:
- return _('Open network place %s') % '<b>%(name)s</b>'
- elif uri_scheme in AUDIO_URIS:
- return _('Open audio disc %s') % '<b>%(name)s</b>'
- else:
- return _('Open location %s') % '<b>%(name)s</b>'
-
-
- def get_hash(self, text = None):
- return self.drive
-
-
-
- class FileFolderHandler(deskbar.Handler.Handler):
-
- def __init__(self):
- deskbar.Handler.Handler.__init__(self, gtk.STOCK_OPEN)
- self._locations = { }
-
-
- def initialize(self):
- if not hasattr(self, 'watcher'):
- self.watcher = FileWatcher()
- self.watcher.connect(('changed',), (lambda watcher, f: self._scan_bookmarks_files()))
-
- self.watcher.add(GTK_BOOKMARKS_FILE)
- self._scan_bookmarks_files()
-
-
- def stop(self):
- self.watcher.remove(GTK_BOOKMARKS_FILE)
-
-
- def query(self, query):
- result = []
- result += self.query_filefolder(query, False)
- result += self.query_filefolder(query, True)
- query = query.lower()
- for name, loc in self._locations.items():
- if bmk.startswith(query):
- result.append(GtkBookmarkMatch(self, name, loc))
- continue
-
- for drive in MONITOR.get_mounted_volumes() + MONITOR.get_connected_drives():
- if not drive.is_user_visible():
- continue
-
- if not drive.is_mounted():
- continue
-
- if not drive.get_display_name().lower().startswith(query):
- continue
-
- result.append(VolumeMatch(self, drive.get_display_name(), drive.get_activation_uri(), drive.get_icon()))
-
- return result
-
-
- def query_filefolder(self, query, is_file):
- (completions, prefix, relative) = filesystem_possible_completions(query, is_file)
-
-
- def _scan_bookmarks_files(self):
- if not isfile(GTK_BOOKMARKS_FILE):
- return None
-
- for line in file(GTK_BOOKMARKS_FILE):
- line = line.strip()
-
- try:
- if gnomevfs.exists(line):
- uri = urllib.unquote(line)
- (head, tail) = split(uri)
- if tail == '':
- i = head.rfind('/')
- tail = head[i + 1:]
-
- self._locations[tail.lower()] = (tail, line)
- continue
- except Exception:
- msg = None
- print 'Error:_scan_bookmarks_files:', msg
- continue
-
-
-
-
-
-
- def filesystem_possible_completions(prefix, is_file = False):
- '''
- \tGiven an path prefix, retreive the file/folders in it.
- \tIf files is False return only the folder, else return only the files.
- \tReturn a tuple (list, prefix, relative)
- \t list is a list of files whose name starts with prefix
- \t prefix is the prefix effectively used, and is always a directory
- \t relative is a flag indicating wether the given prefix was given without ~ or /
- \t'''
- relative = False
- if not prefix.startswith('~') and not prefix.startswith('/'):
- relative = True
- prefix = join('~/', prefix)
-
- if prefix.startswith('~') and not prefix.startswith('~/') and len(prefix) > 1:
- prefix = join('~/', prefix[1:])
-
- if prefix.endswith('/'):
- prefix = prefix[:-1]
-
- if prefix == '~':
- return ([
- expanduser(prefix)], dirname(expanduser(prefix)), relative)
-
- start = None
- path = normpath(abspath(expanduser(prefix)))
- (prefix, start) = split(prefix)
- path = normpath(abspath(expanduser(prefix)))
- if not exists(path):
- return ([], prefix, relative)
-
- if my_isfile(path):
- print 'Myisfile:', is_file
- if is_file:
- return ([
- path], dirname(prefix), relative)
- else:
- return ([], prefix, relative)
-
- return (_[1], prefix, relative)
-
-
- def my_isfile(path):
- if isfile(path):
- pass
- return not path.endswith('.savedSearch')
-
-