diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2007-06-13 09:27:36 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2007-06-13 09:27:36 (GMT) |
commit | f60c6a236b5662671b64511d2bc4431281547063 (patch) | |
tree | e7543bf2ceedaa824b26a8599e0c169799052bbe /webactivity.py | |
parent | 64282ad52e202f480bbef80bc1505444bffb13f6 (diff) | |
parent | d54dcf3be2eda0eacf88f21a036b7636965dd61b (diff) |
Merge branch 'master' of ssh+git://dev.laptop.org/git/web-activity
Diffstat (limited to 'webactivity.py')
-rwxr-xr-x | webactivity.py | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/webactivity.py b/webactivity.py index c8b2c89..5945353 100755 --- a/webactivity.py +++ b/webactivity.py @@ -74,24 +74,30 @@ class WebActivity(activity.Activity): self.set_title(embed.props.title) def read_file(self, file_path): - f = open(file_path, 'r') - try: - session_data = f.read() - finally: - f.close() - logging.debug('Trying to set session: %s.' % session_data) - self._browser.set_session(session_data) + if self.metadata['mime_type'] == 'text/plain': + f = open(file_path, 'r') + try: + session_data = f.read() + finally: + f.close() + logging.debug('Trying to set session: %s.' % session_data) + self._browser.set_session(session_data) + else: + self._browser.load_uri(file_path) def write_file(self, file_path): - session_data = self._browser.get_session() - if self._browser.props.title: - self.metadata['preview'] = self._browser.props.title - else: - self.metadata['preview'] = '' - self.metadata['icon'] = 'theme:object-link' - f = open(file_path, 'w') - try: - f.write(session_data) - finally: - f.close() + if not self.metadata['mime_type']: + self.metadata['mime_type'] = 'text/plain' + + if self.metadata['mime_type'] == 'text/plain': + session_data = self._browser.get_session() + if self._browser.props.title: + self.metadata['preview'] = self._browser.props.title + else: + self.metadata['preview'] = '' + f = open(file_path, 'w') + try: + f.write(session_data) + finally: + f.close() |