[hack] show a dialog when there's no available network connection, but at least don't traceback

This commit is contained in:
Dan Williams 2006-06-22 12:52:30 -04:00
parent 8797223ccd
commit 89d40971fe

View File

@ -6,6 +6,7 @@ import dbus
import cgi import cgi
import xml.sax.saxutils import xml.sax.saxutils
import gobject import gobject
import socket
from google import google from google import google
from sugar.presence.PresenceService import PresenceService from sugar.presence.PresenceService import PresenceService
@ -26,6 +27,7 @@ class SearchModel(gtk.ListStore):
def __init__(self, activities_model, search_text): def __init__(self, activities_model, search_text):
gtk.ListStore.__init__(self, gobject.TYPE_STRING, gobject.TYPE_STRING, gtk.ListStore.__init__(self, gobject.TYPE_STRING, gobject.TYPE_STRING,
gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
success = False
for row in activities_model: for row in activities_model:
title = row[_COLUMN_TITLE] title = row[_COLUMN_TITLE]
@ -34,21 +36,31 @@ class SearchModel(gtk.ListStore):
self.append([ title, address, row[_COLUMN_SUBTITLE], row[_COLUMN_SERVICE] ]) self.append([ title, address, row[_COLUMN_SUBTITLE], row[_COLUMN_SERVICE] ])
google.LICENSE_KEY = '1As9KaJQFHIJ1L0W5EZPl6vBOFvh/Vaf' google.LICENSE_KEY = '1As9KaJQFHIJ1L0W5EZPl6vBOFvh/Vaf'
data = google.doGoogleSearch(search_text) try:
data = google.doGoogleSearch(search_text)
for result in data.results: success = True
title = result.title except socket.gaierror, exc:
if exc[0] == -3: # Temporary failure in name resolution
# FIXME what tags should we actually strip? errdlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO,
title = title.replace('<b>', '') gtk.BUTTONS_OK, "There appears to be no network connection.")
title = title.replace('</b>', '') errdlg.connect("response", lambda d, e: d.destroy())
errdlg.connect("close", lambda d, e: d.destroy())
errdlg.show()
# FIXME I'm sure there is a better way to if success == True:
# unescape these. for result in data.results:
title = title.replace('&quot;', '"') title = result.title
title = title.replace('&amp;', '&')
# FIXME what tags should we actually strip?
self.append([ title, result.URL, None, None ]) title = title.replace('<b>', '')
title = title.replace('</b>', '')
# FIXME I'm sure there is a better way to
# unescape these.
title = title.replace('&quot;', '"')
title = title.replace('&amp;', '&')
self.append([ title, result.URL, None, None ])
class ActivitiesModel(gtk.ListStore): class ActivitiesModel(gtk.ListStore):
def __init__(self): def __init__(self):