Пример #1
0
def is_broken_xdg_desktop(pathname):
    """Returns boolean whether the given XDG desktop entry file is broken.
    Reference: http://standards.freedesktop.org/desktop-entry-spec/latest/"""
    config = ConfigParser.RawConfigParser()
    config.read(pathname)
    if not config.has_section('Desktop Entry'):
        print "info: is_broken_xdg_menu: missing required section " \
            "'Desktop Entry': '%s'" % (pathname)
        return True
    if not config.has_option('Desktop Entry', 'Type'):
        print "info: is_broken_xdg_menu: missing required option 'Type': '%s'" % (pathname)
        return True
    file_type = config.get('Desktop Entry', 'Type').strip().lower()
    if 'link' == file_type:
        if not config.has_option('Desktop Entry', 'URL') and \
                not config.has_option('Desktop Entry', 'URL[$e]'):
            print "info: is_broken_xdg_menu: missing required option 'URL': '%s'" % (pathname)
            return True
        return False
    if 'mimetype' == file_type:
        if not config.has_option('Desktop Entry', 'MimeType'):
            print "info: is_broken_xdg_menu: missing required option 'MimeType': '%s'" % (pathname)
            return True
        mimetype = config.get('Desktop Entry', 'MimeType').strip().lower()
        if HAVE_GNOME_VFS and 0 == len(gnomevfs.mime_get_all_applications(mimetype)):
            print "info: is_broken_xdg_menu: MimeType '%s' not " \
                "registered '%s'" % (mimetype, pathname)
            return True
        return False
    if 'application' != file_type:
        print "Warning: unhandled type '%s': file '%s'" % (file_type, pathname)
        return False
    if __is_broken_xdg_desktop_application(config, pathname):
        return True
    return False
Пример #2
0
    def get_file_menuitems(self, file_obj, context=None):
        uri = gnomevfs.get_uri_from_local_path(file_obj.path)
        if file_obj.test_directory(follow_link=True):
            return []

        apps = gnomevfs.mime_get_all_applications(file_obj.mimetype)
        menuitems = []
        pbcache = PixbufCache.getInstance()

        def add_menuitem(app):
            _logger.debug("adding app %r", app)
            if have_gnomedesktop:
                desktop = gnomedesktop.item_new_from_basename(app[0], 0)
                iconpath = desktop.get_icon(self.__itheme)
            else:
                iconpath = None
            menuitem = gtk.ImageMenuItem(_('Open with %s') % (app[1], ))
            if iconpath:
                pbuf = pbcache.get(iconpath,
                                   trystock=True,
                                   stocksize=gtk.ICON_SIZE_MENU)
                img = gtk.image_new_from_pixbuf(pbuf)
                menuitem.set_property('image', img)
            menuitem.connect("activate", self.__on_appmenu_activated, app, uri,
                             context)
            menuitems.append(menuitem)

        for app in apps:
            add_menuitem(app)
        return menuitems
Пример #3
0
 def get_file_menuitems(self, file_obj, context=None):
     uri = gnomevfs.get_uri_from_local_path(file_obj.path)
     if file_obj.test_directory(follow_link=True):
         return []
     
     apps = gnomevfs.mime_get_all_applications(file_obj.mimetype)
     menuitems = []
     pbcache = PixbufCache.getInstance()
     def add_menuitem(app):
         _logger.debug("adding app %r", app)
         if have_gnomedesktop:
             desktop = gnomedesktop.item_new_from_basename(app[0], 0)
             iconpath = desktop.get_icon(self.__itheme)
         else:
             iconpath = None
         menuitem = gtk.ImageMenuItem(_('Open with %s') % (app[1],))
         if iconpath:
             pbuf = pbcache.get(iconpath, trystock=True, stocksize=gtk.ICON_SIZE_MENU)
             img = gtk.image_new_from_pixbuf(pbuf)
             menuitem.set_property('image', img)
         menuitem.connect("activate", self.__on_appmenu_activated, app, uri, context)
         menuitems.append(menuitem) 
     for app in apps:
         add_menuitem(app)
     return menuitems
Пример #4
0
def get_applications_for_files(files):
    ids_comuns = None
    for file in files:
        mime = gnomevfs.get_file_mime_type(file)
        if not mime:
          return None

        ids = Set([app[0] for app in gnomevfs.mime_get_all_applications(mime)])
        if ids_comuns == None:
            ids_comuns = ids
        else:
            ids_comuns = ids_comuns.intersection(ids)
    return ids_comuns and [gnomevfs.mime_application_new_from_id(id) for id in ids_comuns]
Пример #5
0
    def getApps(self, filename): # returns a tuple (default app, [list of other apps]) that are registered as able to open this file; 'apps' in this context are App objects; in case of error, returns (None, [])

        defaultApp, otherApps = None, []

        mimeType = self._getMimeType(filename)

        if mimeType:

            if self.DESK_ENV == GNOME:

                # in the future [since gnomevfs is deprecated], this should be done using
                # import gio
                # gio.app_info_get_all_for_type(mimeType)

                # both of these gnomevfs functions return tuples, where the element in [1] is the app name and [2] is the command to execute

                defaultAppInfo = gnomevfs.mime_get_default_application(mimeType)

                if defaultAppInfo: # if we got something

                    defaultApp = App(defaultAppInfo[1], defaultAppInfo[2])

                    otherApps = [App(app[1], app[2]) for app in gnomevfs.mime_get_all_applications(mimeType) ]

            elif self.DESK_ENV == KDE:

                kdeMimeTrader = KMimeTypeTrader.self()

                defaultAppInfo = kdeMimeTrader.preferredService(mimeType)

                if defaultAppInfo:

                    defaultApp = App( unicode(defaultAppInfo.desktopEntryName()) , unicode(defaultAppInfo.exec_()) ) # unicode()s since funky PyQt "QString" strings are returned...

                    otherApps = [ App(unicode(s.desktopEntryName()), unicode(s.exec_()) ) for s in kdeMimeTrader.query(mimeType) ]

            else: # need to use our own file type -> app mapping...

                # XXX code from before

                pass

            otherApps = filter(lambda a: a.cmd != defaultApp.cmd, otherApps) # make sure we don't include the default app into the list of OTHER apps...
            pass

        for app in [defaultApp] + otherApps: # at least KDE sometimes stores the cmd to execute with a placeholder ('%U', '%f') at the end to indicate where the filename should go; we remove that

            if app.cmd.split()[-1].startswith('%'): app.cmd = ' '.join( app.cmd.split()[:-1] ) + ' '
            pass

        return defaultApp, otherApps
Пример #6
0
def get_meta_info(filename):
	try:
		file_mimetype = gnomevfs.get_mime_type(filename)
	except:
		return False
	
	ret = {}
	ret['mime'] = file_mimetype
	ret['default_app'] = gnomevfs.mime_get_default_application(file_mimetype)
	ret['other_apps'] = gnomevfs.mime_get_all_applications(file_mimetype)
	if len(ret['other_apps']) > 0:
		del ret['other_apps'][0]
	ret ['description'] = gnomevfs.mime_get_description(file_mimetype)
	return ret
Пример #7
0
def get_applications_for_files(files):
    ids_comuns = None
    for file in files:
        mime = gnomevfs.get_file_mime_type(file)
        if not mime:
          return None

        ids = set([app[0] for app in gnomevfs.mime_get_all_applications(mime)])
        if ids_comuns == None:
            ids_comuns = ids
        else:
            ids_comuns = ids_comuns & ids
    if ids_comuns:
      return [ApplicationInfo(gnomevfs.mime_application_new_from_id(id)) for id in ids_comuns]
    else:
      return None
Пример #8
0
def is_broken_xdg_desktop(pathname):
    """Returns boolean whether the given XDG desktop entry file is broken.
    Reference: http://standards.freedesktop.org/desktop-entry-spec/latest/"""
    config = ConfigParser.RawConfigParser()
    config.read(pathname)
    if not config.has_section('Desktop Entry'):
        print "info: is_broken_xdg_menu: missing required section " \
            "'Desktop Entry': '%s'" % (pathname)
        return True
    if not config.has_option('Desktop Entry', 'Type'):
        print "info: is_broken_xdg_menu: missing required option 'Type': '%s'" % (
            pathname)
        return True
    file_type = config.get('Desktop Entry', 'Type').strip().lower()
    if 'link' == file_type:
        if not config.has_option('Desktop Entry', 'URL') and \
                not config.has_option('Desktop Entry', 'URL[$e]'):
            print "info: is_broken_xdg_menu: missing required option 'URL': '%s'" % (
                pathname)
            return True
        return False
    if 'mimetype' == file_type:
        if not config.has_option('Desktop Entry', 'MimeType'):
            print "info: is_broken_xdg_menu: missing required option 'MimeType': '%s'" % (
                pathname)
            return True
        mimetype = config.get('Desktop Entry', 'MimeType').strip().lower()
        if HAVE_GNOME_VFS and 0 == len(
                gnomevfs.mime_get_all_applications(mimetype)):
            print "info: is_broken_xdg_menu: MimeType '%s' not " \
                "registered '%s'" % (mimetype, pathname)
            return True
        return False
    if 'application' != file_type:
        print "Warning: unhandled type '%s': file '%s'" % (file_type, pathname)
        return False
    if __is_broken_xdg_desktop_application(config, pathname):
        return True
    return False
Пример #9
0
    def __init__(self, fobj):
        super(FileSlideout, self).__init__()
        vbox = CanvasVBox(border_color=0x0000000ff, spacing=4)
        self.get_root().append(vbox)
        self.__header = Header(topborder=False)
        text = ThemedText(theme_hints=['header'], text=fobj.get_name(), font="14px Bold", xalign=hippo.ALIGNMENT_START)
        self.__header.append(text, hippo.PACK_EXPAND)        
        vbox.append(self.__header)
        
        hbox = CanvasHBox(spacing=4, padding=4)
        img = hippo.CanvasImage(scale_width=60, scale_height=60, xalign=hippo.ALIGNMENT_START, yalign=hippo.ALIGNMENT_START)
        img.set_property('image-name', fobj.get_image_name())
        hbox.append(img)
        vbox.append(hbox)
        
        detailvbox = CanvasVBox(spacing=3)
        hbox.append(detailvbox) 
        mime = fobj.get_mimetype()
        if mime:
            mimename = gnomevfs.mime_get_description(mime)
            text = ThemedText(theme_hints=['subforeground'], text=mimename, font='12px', xalign=hippo.ALIGNMENT_START)                  
            detailvbox.append(text)
        size = fobj.get_size()            
        if size is not None:
            sizestr = format_file_size(size)
            text = ThemedText(theme_hints=['subforeground'], text=sizestr, font='12px', xalign=hippo.ALIGNMENT_START)             
            detailvbox.append(text)
        fname = os.path.dirname(fobj.get_full_name())
        if fname.startswith('file://'):
            fname = fname[7:]
        home = os.path.expanduser('~')
        if fname.startswith(home):
            fname = fname[:len(home)]
        fname = urllib.unquote(fname)            
        text = ThemedText(theme_hints=['subforeground'], text=fname, font='12px', xalign=hippo.ALIGNMENT_START)          
        detailvbox.append(text)
        apps = gnomevfs.mime_get_all_applications(mime)
        if apps:
            text = ThemedText(text='Open With: ', font='14px')
            detailvbox.append(text)
            def on_app_clicked(button, app):
                self.emit('close', True)
                _logger.debug("launching app %s", app)
                _launch_vfsmimeapp(app, fobj.get_url())      
            directory = apps_directory.get_app_directory()
            for app in apps:
                _logger.debug("mime type: %s got app %s", mime, app)
                button = hippo.CanvasButton()
                labelhbox = gtk.HBox()
                labelhbox.set_border_width(1)
                labelhbox.set_spacing(2)
                
                try:
                    menu = directory.lookup(app[0])
                except KeyError, e:
                    _logger.debug("failed to find desktop file %s", app[0])
                    menu = None

                img = gtk.Image()
                    
                if menu:
                    pixbuf = get_menu_pixbuf(menu, size=16)
                    img.set_from_pixbuf(pixbuf)
                else:
                    img.set_size_request(16, 16)

                labelhbox.pack_start(img, False, False)
                
                textlabel = gtk.Label(app[1])
                labelhbox.pack_start(textlabel, False)
                labelhbox.show_all()

                button.get_property('widget').add(labelhbox)
                button.get_property('widget').connect('clicked', on_app_clicked, app)
                button.get_property('widget').set_name('bigboard-nopad-button')
                detailvbox.append(button)
Пример #10
0
	def get_apps(self, filename):
		mime_type = gnomevfs.get_mime_type(filename)
		application_list = gnomevfs.mime_get_all_applications(mime_type)
		return application_list   
Пример #11
0
 def app_info_get_all_for_type(mime):
     return [
         AppInfo(app_data)
         for app_data in gnomevfs.mime_get_all_applications(mime)
     ]
Пример #12
0
 def app_info_get_all_for_type(mime):
     return [AppInfo(app_data) for app_data in gnomevfs.mime_get_all_applications(mime)]
Пример #13
0
    def getApps(
        self, filename
    ):  # returns a tuple (default app, [list of other apps]) that are registered as able to open this file; 'apps' in this context are App objects; in case of error, returns (None, [])

        defaultApp, otherApps = None, []

        mimeType = self._getMimeType(filename)

        if mimeType:

            if self.DESK_ENV == GNOME:

                # in the future [since gnomevfs is deprecated], this should be done using
                # import gio
                # gio.app_info_get_all_for_type(mimeType)

                # both of these gnomevfs functions return tuples, where the element in [1] is the app name and [2] is the command to execute

                defaultAppInfo = gnomevfs.mime_get_default_application(
                    mimeType)

                if defaultAppInfo:  # if we got something

                    defaultApp = App(defaultAppInfo[1], defaultAppInfo[2])

                    otherApps = [
                        App(app[1], app[2])
                        for app in gnomevfs.mime_get_all_applications(mimeType)
                    ]

            elif self.DESK_ENV == KDE:

                kdeMimeTrader = KMimeTypeTrader.self()

                defaultAppInfo = kdeMimeTrader.preferredService(mimeType)

                if defaultAppInfo:

                    defaultApp = App(
                        unicode(defaultAppInfo.desktopEntryName()),
                        unicode(defaultAppInfo.exec_())
                    )  # unicode()s since funky PyQt "QString" strings are returned...

                    otherApps = [
                        App(unicode(s.desktopEntryName()), unicode(s.exec_()))
                        for s in kdeMimeTrader.query(mimeType)
                    ]

            else:  # need to use our own file type -> app mapping...

                # XXX code from before

                pass

            otherApps = filter(
                lambda a: a.cmd != defaultApp.cmd, otherApps
            )  # make sure we don't include the default app into the list of OTHER apps...
            pass

        for app in [
                defaultApp
        ] + otherApps:  # at least KDE sometimes stores the cmd to execute with a placeholder ('%U', '%f') at the end to indicate where the filename should go; we remove that

            if app.cmd.split()[-1].startswith('%'):
                app.cmd = ' '.join(app.cmd.split()[:-1]) + ' '
            pass

        return defaultApp, otherApps