diff options
Diffstat (limited to 'webactivity.py')
-rw-r--r-- | webactivity.py | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/webactivity.py b/webactivity.py index 2e1509d..b444861 100644 --- a/webactivity.py +++ b/webactivity.py @@ -1,5 +1,6 @@ # Copyright (C) 2006, Red Hat, Inc. -# Copyright (C) 2009 Martin Langhoff, Simon Schampijer, Daniel Drake, Tomeu Vizoso +# Copyright (C) 2009 Martin Langhoff, Simon Schampijer, Daniel Drake, +# Tomeu Vizoso # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -114,17 +115,17 @@ def _seed_xs_cookie(): _logger.debug('seed_xs_cookie: Cookie exists already') return - expire = int(time.time()) + 10*365*24*60*60 + expire = int(time.time()) + 10 * 365 * 24 * 60 * 60 c.execute('''INSERT INTO moz_cookies (name, value, host, path, expiry, lastAccessed, isSecure, isHttpOnly) VALUES(?,?,?,?,?,?,?,?)''', ('xoid', cjson.encode(cookie_data), jabber_server, - '/', expire, 0, 0, 0 )) + '/', expire, 0, 0, 0)) cookies_db.commit() cookies_db.close() - except sqlite3.Error, e: - _logger.error('seed_xs_cookie: %s' % e) + except sqlite3.Error: + _logger.exception('seed_xs_cookie: could not write cookie') else: _logger.debug('seed_xs_cookie: Updated cookie successfully') @@ -147,7 +148,7 @@ def _set_accept_languages(): lang = lang.split('_') # e.g. es-uy, es - pref = lang[0] + "-" + lang[1].lower() + ", " + lang[0] + pref = lang[0] + "-" + lang[1].lower() + ", " + lang[0] cls = components.classes["@mozilla.org/preferences-service;1"] prefService = cls.getService(components.interfaces.nsIPrefService) branch = prefService.getBranch('') @@ -200,7 +201,7 @@ class WebActivity(activity.Activity): # isn't exactly known. Thus, disable the multiple tabs feature # if we come across cairo versions >= 1.08.10 # More information can be found here: - # [1] http://lists.sugarlabs.org/archive/sugar-devel/2010-July/025187.html + # http://lists.sugarlabs.org/archive/sugar-devel/2010-July/025187.html self._disable_multiple_tabs = cairo.cairo_version() >= 10810 if self._disable_multiple_tabs: logging.warning('Not enabling the multiple tabs feature due' @@ -265,7 +266,7 @@ class WebActivity(activity.Activity): self.initiating = None if self._shared_activity is not None: - _logger.debug('shared: %s' %self._shared_activity.props.joined) + _logger.debug('shared: %s', self._shared_activity.props.joined) if self._shared_activity is not None: # We are joining the activity @@ -286,7 +287,8 @@ class WebActivity(activity.Activity): self._setup() _logger.debug('This is my activity: making a tube...') - self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(SERVICE, {}) + self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(SERVICE, + {}) def _setup(self): if self._shared_activity is None: @@ -304,15 +306,18 @@ class WebActivity(activity.Activity): channel = telepathy.client.Channel(bus_name, channel_path) htype, handle = channel.GetHandle() if htype == telepathy.HANDLE_TYPE_ROOM: - _logger.debug('Found our room: it has handle#%d "%s"' - %(handle, self.conn.InspectHandles(htype, [handle])[0])) + _logger.debug('Found our room: it has handle#%d "%s"', + handle, + self.conn.InspectHandles(htype, [handle])[0]) room = handle ctype = channel.GetChannelType() if ctype == telepathy.CHANNEL_TYPE_TUBES: - _logger.debug('Found our Tubes channel at %s'%channel_path) + _logger.debug('Found our Tubes channel at %s', + channel_path) tubes_chan = channel elif ctype == telepathy.CHANNEL_TYPE_TEXT: - _logger.debug('Found our Text channel at %s'%channel_path) + _logger.debug('Found our Text channel at %s', + channel_path) text_chan = channel if room is None: @@ -325,9 +330,9 @@ class WebActivity(activity.Activity): # Make sure we have a Tubes channel - PS doesn't yet provide one if tubes_chan is None: _logger.debug("Didn't find our Tubes channel, requesting one...") - tubes_chan = self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES, - telepathy.HANDLE_TYPE_ROOM, - room, True) + tubes_chan = self.conn.request_channel( + telepathy.CHANNEL_TYPE_TUBES, telepathy.HANDLE_TYPE_ROOM, + room, True) self.tubes_chan = tubes_chan self.text_chan = text_chan @@ -340,7 +345,7 @@ class WebActivity(activity.Activity): self._new_tube_cb(*tube_info) def _list_tubes_error_cb(self, e): - _logger.debug('ListTubes() failed: %s'%e) + _logger.debug('ListTubes() failed: %s', e) def _joined_cb(self, activity_): if not self._shared_activity: @@ -356,10 +361,11 @@ class WebActivity(activity.Activity): reply_handler=self._list_tubes_reply_cb, error_handler=self._list_tubes_error_cb) - def _new_tube_cb(self, identifier, initiator, type, service, params, state): + def _new_tube_cb(self, identifier, initiator, type, service, params, + state): _logger.debug('New tube: ID=%d initator=%d type=%d service=%s ' - 'params=%r state=%d' %(identifier, initiator, type, - service, params, state)) + 'params=%r state=%d', identifier, initiator, type, + service, params, state) if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE): @@ -369,7 +375,7 @@ class WebActivity(activity.Activity): self.tube_conn = TubeConnection(self.conn, self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES], - identifier, group_iface = self.text_chan[ + identifier, group_iface=self.text_chan[ telepathy.CHANNEL_INTERFACE_GROUP]) _logger.debug('Tube created') @@ -412,7 +418,7 @@ class WebActivity(activity.Activity): base64.b64decode(link['thumb']), link['color'], link['title'], link['owner'], -1, link['hash']) - logging.debug('########## reading %s' % data) + logging.debug('########## reading %s', data) self._tabbed_view.set_session(self.model.data['history']) self._tabbed_view.set_current_page(self.model.data['current_tab']) elif self.metadata['mime_type'] == 'text/uri-list': @@ -452,18 +458,21 @@ class WebActivity(activity.Activity): self.metadata['title'] = browser.props.title self.model.data['history'] = self._tabbed_view.get_session() - self.model.data['current_tab'] = self._tabbed_view.get_current_page() + current_tab = self._tabbed_view.get_current_page() + self.model.data['current_tab'] = current_tab self.model.data['currents'] = [] for n in range(0, self._tabbed_view.get_n_pages()): n_browser = self._tabbed_view.get_nth_page(n) if n_browser != None: - ui_uri = browser.get_url_from_nsiuri(browser.progress.location) - self.model.data['currents'].append({'title':browser.props.title,'url':ui_uri}) + nsiuri = browser.progress.location + ui_uri = browser.get_url_from_nsiuri(nsiuri) + info = {'title': browser.props.title, 'url': ui_uri} + self.model.data['currents'].append(info) f = open(file_path, 'w') try: - logging.debug('########## writing %s' % self.model.serialize()) + logging.debug('########## writing %s', self.model.serialize()) f.write(self.model.serialize()) finally: f.close() @@ -520,8 +529,8 @@ class WebActivity(activity.Activity): for link in self.model.data['shared_links']: if link['hash'] == sha1(ui_uri).hexdigest(): - _logger.debug('_add_link: link exist already a=%s b=%s' %( - link['hash'], sha1(ui_uri).hexdigest())) + _logger.debug('_add_link: link exist already a=%s b=%s', + link['hash'], sha1(ui_uri).hexdigest()) return buf = self._get_screenshot() timestamp = time.time() @@ -547,7 +556,8 @@ class WebActivity(activity.Activity): item = LinkButton(url, buf, color, title, owner, index, hash) item.connect('clicked', self._link_clicked_cb, url) item.connect('remove_link', self._link_removed_cb) - self._tray.add_item(item, index) # use index to add to the tray + # use index to add to the tray + self._tray.add_item(item, index) item.show() if self._tray.props.visible is False: self._tray.show() @@ -598,9 +608,9 @@ class WebActivity(activity.Activity): alert.props.title = _('Download in progress') alert.props.msg = _('Stopping now will cancel your download') cancel_icon = Icon(icon_name='dialog-cancel') - alert.add_button(gtk.RESPONSE_CANCEL, _('Continue Download'), cancel_icon) + alert.add_button(gtk.RESPONSE_CANCEL, _('Cancel'), cancel_icon) stop_icon = Icon(icon_name='dialog-ok') - alert.add_button(gtk.RESPONSE_OK, _('Cancel Download'), stop_icon) + alert.add_button(gtk.RESPONSE_OK, _('Stop'), stop_icon) stop_icon.show() self.add_alert(alert) alert.connect('response', self.__inprogress_response_cb) |