Beispiel #1
0
    def set_default_application(mimetype, application):
        '''Set the default application to open a file with a specific
        mimetype. Updates the C{applications/defaults.list} file.
        As a special case when you set the default to C{None} it will
        remove the entry from C{defauts.list} allowing system defaults
        to be used again.
        @param mimetype: the mime-type of the file (e.g. "text/html")
        @param application: an L{Application} object or C{None}
        '''
        ## Based on logic from xdg-mime make_default_generic()
        ## Obtained from http://portland.freedesktop.org/wiki/ (2012-05-31)
        ##
        ## See comment in get_default_application()

        if application is not None:
            if not isinstance(application, basestring):
                application = application.key

            if not application.endswith('.desktop'):
                application += '.desktop'

        default_file = XDG_DATA_HOME.file('applications/defaults.list')
        if default_file.exists():
            lines = default_file.readlines()
            lines = [l for l in lines if not l.startswith(mimetype + '=')]
        else:
            lines = ['[Default Applications]\n']

        if application:
            lines.append('%s=%s\n' % (mimetype, application))
        default_file.writelines(lines)
	def set_default_application(mimetype, application):
		'''Set the default application to open a file with a specific
		mimetype. Updates the C{applications/defaults.list} file.
		As a special case when you set the default to C{None} it will
		remove the entry from C{defauts.list} allowing system defaults
		to be used again.
		@param mimetype: the mime-type of the file (e.g. "text/html")
		@param application: an L{Application} object or C{None}
		'''
		## Based on logic from xdg-mime make_default_generic()
		## Obtained from http://portland.freedesktop.org/wiki/ (2012-05-31)
		##
		## See comment in get_default_application()

		if application is not None:
			if not isinstance(application, basestring):
				application = application.key

			if not application.endswith('.desktop'):
				application += '.desktop'

		default_file = XDG_DATA_HOME.file('applications/defaults.list')
		if default_file.exists():
			lines = default_file.readlines()
			lines = [l for l in lines if not l.startswith(mimetype + '=')]
		else:
			lines = ['[Default Applications]\n']

		if application:
			lines.append('%s=%s\n' % (mimetype, application))
		default_file.writelines(lines)
Beispiel #3
0
	def testRemoveTemplate(self):
		dialog = TemplateEditorDialog(None)
		select_by_name(dialog.view, 'foo_test')
		file = LocalFile(XDG_DATA_HOME.file('zim/templates/html/foo_test.html').path)
		self.assertTrue(file.exists())
		dialog.on_delete()
		self.assertFalse(file.exists())
	def refresh(self):
		model = self.get_model()
		model.clear()
		for category in list_template_categories():
			parent = model.append(None, (category, None, None))
			for name, basename in list_templates(category):
				base = XDG_DATA_HOME.file(('zim', 'templates', category, basename))
				default = data_file(('templates', category, basename)) # None if not existing
				#~ print '>>>', name, base, default
				model.append(parent, (name, base, default))

		self.expand_all()
	def refresh(self):
		model = self.get_model()
		model.clear()
		for category in list_template_categories():
			parent = model.append(None, (category, None, None))
			for name, basename in list_templates(category):
				base = XDG_DATA_HOME.file(('zim', 'templates', category, basename))
				default = data_file(('templates', category, basename)) # None if not existing
				#~ print('>>>', name, base, default)
				model.append(parent, (name, base, default))

		self.expand_all()
Beispiel #6
0
	def testCopyTemplate(self):
		dialog = TemplateEditorDialog(None)
		select_by_name(dialog.view, 'foo_test')

		def do_copy(dialog):
			dialog.set_input(name='new_foo_test')
			dialog.assert_response_ok()

		with tests.DialogContext(do_copy):
			dialog.on_copy()

		file = LocalFile(XDG_DATA_HOME.file('zim/templates/html/new_foo_test.html').path)
		self.assertTrue(file.exists())
Beispiel #7
0
		def open_file(args):
			got = LocalFile(args[-1])
			want = LocalFile(XDG_DATA_HOME.file('zim/templates/html/foo_test.html').path)
			self.assertEqual(got, want)