def testSupportDesktopMimeappsList(self): orig_desktop = os.environ.get('XDG_CURRENT_DESKTOP') def restore_desktop(): os.environ['XDG_CURRENT_DESKTOP'] = orig_desktop self.addCleanup(restore_desktop) os.environ['XDG_CURRENT_DESKTOP'] = 'Test' desktopfile = XDG_CONFIG_HOME.file('Test-mimeapps.list') defaultfile = XDG_CONFIG_HOME.file('mimeapps.list') dir = XDG_DATA_HOME.subdir('applications') for basename in ('desktop-foo.desktop', 'normal-foo.desktop', 'ignore_this.desktop'): _create_application(dir, basename, 'test', 'test') desktopfile.write('[Default Applications]\n' 'text/plain=desktop-foo.desktop\n' '\n' '[Removed Associations]\n' 'text/html=ignore_this.desktop\n') defaultfile.write('[Default Applications]\n' 'text/plain=normal-foo.desktop\n' 'text/html=ignore_this.desktop\n' '\n') manager = ApplicationManager() # Test default picked up from desktop file self.assertEqual( manager.get_default_application('text/plain').key, 'desktop-foo') # Test blacklist in effect self.assertNotIn('ignore_this', manager.list_applications('text/plain'))
def create(self, Name, **properties): '''Create a new custom tool @param Name: the name to show in the Tools menu @param properties: properties for the custom tool, e.g.: - Comment - Icon - X-Zim-ExecTool - X-Zim-ReadOnly - X-Zim-ShowInToolBar @returns: a new L{CustomTool} object. ''' properties['Type'] = 'X-Zim-CustomTool' dir = XDG_CONFIG_HOME.subdir('zim/customtools') tool = _create_application(dir, Name, '', klass=CustomTool, NoDisplay=False, **properties) # XXX - hack to ensure we link to configmanager file = ConfigManager.get_config_file('customtools/' + tool.file.basename) tool.file = file file.connect('changed', partial(self._on_tool_changed, tool)) self._tools[tool.key] = tool self._names.append(tool.key) self._write_list() return tool
def testSupportBackwardDefaultsList(self): defaultfile = XDG_CONFIG_HOME.file('mimeapps.list') backwardfile = XDG_DATA_HOME.file('applications/defaults.list') dir = XDG_DATA_HOME.subdir('applications') for basename in ('foo.desktop', 'bar.desktop', 'ignore_this.desktop'): _create_application(dir, basename, 'test', 'test') defaultfile.write('[Default Applications]\n' 'text/html=bar.desktop\n' '\n') backwardfile.write('[Default Applications]\n' 'text/plain=foo.desktop\n' 'text/html=ignore_this.desktop\n' '\n') manager = ApplicationManager() self.assertEqual( manager.get_default_application('text/plain').key, 'foo') self.assertEqual( manager.get_default_application('text/html').key, 'bar')
def testListApplications(self): defaultfile = XDG_CONFIG_HOME.file('mimeapps.list') cachefile = XDG_DATA_HOME.file('applications/mimeinfo.cache') dir = XDG_DATA_HOME.subdir('applications') for basename in ('aaa.desktop', 'bbb.desktop', 'ccc.desktop', 'ddd.desktop', 'ignore_this.desktop', 'browser.desktop'): _create_application(dir, basename, 'test', 'test', NoDisplay=False) _create_application(dir, 'do_not_list.desktop', 'test', 'test', NoDisplay=True) defaultfile.write( '[Default Applications]\n' 'text/plain=aaa.desktop\n' 'text/html=browser.desktop\n' '\n' '[Added Associations]\n' 'text/plain=bbb.desktop;ccc.desktop;do_not_list.desktop\n' '\n' '[Removed Associations]\n' 'text/plain=ignore_this.desktop\n') cachefile.write('[MIME Cache]\n' 'text/plain=ddd.desktop;ignore_this.desktop\n') manager = ApplicationManager() self.assertEqual( [e.key for e in manager.list_applications('text/plain')], ['aaa', 'bbb', 'ccc', 'ddd']) # Test url scheme also falls back to text/html self.assertEqual( [e.key for e in manager.list_applications('text/html')], ['browser']) self.assertEqual([ e.key for e in manager.list_applications('x-scheme-handler/http') ], ['browser'])