2006-06-14 21:01:17 +02:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
2006-06-15 03:52:46 +02:00
|
|
|
import pango
|
2006-06-14 21:01:17 +02:00
|
|
|
import dbus
|
2006-06-15 23:03:59 +02:00
|
|
|
import cgi
|
2006-06-16 07:43:42 +02:00
|
|
|
import urllib
|
2006-06-16 08:36:18 +02:00
|
|
|
import re
|
2006-06-14 21:01:17 +02:00
|
|
|
|
|
|
|
import google
|
2006-06-15 23:41:49 +02:00
|
|
|
from sugar.presence.PresenceService import PresenceService
|
|
|
|
from sugar.presence import Service
|
|
|
|
from sugar.browser import BrowserActivity
|
2006-06-14 21:01:17 +02:00
|
|
|
|
|
|
|
class ActivitiesModel(gtk.ListStore):
|
|
|
|
def __init__(self):
|
2006-06-16 07:43:42 +02:00
|
|
|
gtk.ListStore.__init__(self, str, str, str, str)
|
2006-06-14 21:01:17 +02:00
|
|
|
|
|
|
|
def add_web_page(self, title, address):
|
2006-06-16 07:43:42 +02:00
|
|
|
self.append([ title, address, None, None ])
|
|
|
|
|
|
|
|
def add_activity(self, buddy, service):
|
2006-06-16 21:27:50 +02:00
|
|
|
uid = service.get_activity_uid()
|
2006-06-16 08:37:28 +02:00
|
|
|
title = urllib.unquote(service.get_one_property('Title'))
|
2006-06-16 07:43:42 +02:00
|
|
|
address = urllib.unquote(service.get_one_property('URI'))
|
|
|
|
subtitle = 'Shared by %s' % buddy.get_nick_name()
|
|
|
|
self.append([ title, address, subtitle, uid ])
|
2006-06-14 21:01:17 +02:00
|
|
|
|
|
|
|
class ActivitiesView(gtk.TreeView):
|
2006-06-15 03:52:46 +02:00
|
|
|
def __init__(self):
|
2006-06-16 07:43:42 +02:00
|
|
|
gtk.TreeView.__init__(self, model = ActivitiesModel())
|
2006-06-14 21:01:17 +02:00
|
|
|
|
|
|
|
self.set_headers_visible(False)
|
|
|
|
|
|
|
|
column = gtk.TreeViewColumn('')
|
|
|
|
self.append_column(column)
|
|
|
|
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
column.pack_start(cell, True)
|
2006-06-15 03:52:46 +02:00
|
|
|
column.set_cell_data_func(cell, self._cell_data_func)
|
2006-06-14 21:01:17 +02:00
|
|
|
|
|
|
|
self.connect('row-activated', self._row_activated_cb)
|
|
|
|
|
2006-06-15 03:52:46 +02:00
|
|
|
def _cell_data_func(self, column, cell, model, it):
|
|
|
|
title = model.get_value(it, 0)
|
2006-06-16 07:43:42 +02:00
|
|
|
subtitle = model.get_value(it, 2)
|
|
|
|
if subtitle is None:
|
|
|
|
subtitle = model.get_value(it, 1)
|
|
|
|
|
2006-06-16 08:36:18 +02:00
|
|
|
markup = '<big><b>' + cgi.escape(title) + '</b></big>'
|
|
|
|
markup += '\n' + cgi.escape(subtitle)
|
2006-06-15 03:52:46 +02:00
|
|
|
|
|
|
|
cell.set_property('markup', markup)
|
|
|
|
cell.set_property('ellipsize', pango.ELLIPSIZE_END)
|
|
|
|
|
2006-06-16 07:43:42 +02:00
|
|
|
def _row_activated_cb(self, treeview, path, column):
|
2006-06-14 21:01:17 +02:00
|
|
|
bus = dbus.SessionBus()
|
|
|
|
proxy_obj = bus.get_object('com.redhat.Sugar.Browser', '/com/redhat/Sugar/Browser')
|
|
|
|
browser_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.BrowserShell')
|
|
|
|
|
|
|
|
model = self.get_model()
|
|
|
|
address = model.get_value(model.get_iter(path), 1)
|
2006-06-16 07:43:42 +02:00
|
|
|
activity_id = model.get_value(model.get_iter(path), 3)
|
2006-06-14 21:01:17 +02:00
|
|
|
|
2006-06-16 07:43:42 +02:00
|
|
|
print 'Activated row %s %s' % (address, activity_id)
|
|
|
|
|
|
|
|
if activity_id is None:
|
|
|
|
browser_shell.open_browser(address, ignore_reply=True)
|
|
|
|
else:
|
|
|
|
browser_shell.open_browser_with_id(address, activity_id, ignore_reply=True)
|
|
|
|
|
2006-06-14 21:01:17 +02:00
|
|
|
class StartPage(gtk.HBox):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.HBox.__init__(self)
|
|
|
|
|
2006-06-15 23:41:49 +02:00
|
|
|
self._pservice = PresenceService.get_instance()
|
|
|
|
self._pservice.connect("activity-announced", self._on_activity_announced_cb)
|
|
|
|
self._pservice.start()
|
|
|
|
self._pservice.track_service_type(BrowserActivity._BROWSER_ACTIVITY_TYPE)
|
|
|
|
|
2006-06-14 21:01:17 +02:00
|
|
|
vbox = gtk.VBox()
|
|
|
|
|
|
|
|
search_box = gtk.HBox(False, 6)
|
|
|
|
search_box.set_border_width(24)
|
|
|
|
|
|
|
|
self._search_entry = gtk.Entry()
|
2006-06-15 03:52:46 +02:00
|
|
|
self._search_entry.connect('activate', self._search_entry_activate_cb)
|
2006-06-14 21:01:17 +02:00
|
|
|
search_box.pack_start(self._search_entry)
|
|
|
|
self._search_entry.show()
|
|
|
|
|
|
|
|
search_button = gtk.Button("Search")
|
|
|
|
search_button.connect('clicked', self._search_button_clicked_cb)
|
|
|
|
search_box.pack_start(search_button, False)
|
|
|
|
search_button.show()
|
|
|
|
|
|
|
|
vbox.pack_start(search_box, False, True)
|
|
|
|
search_box.show()
|
|
|
|
|
|
|
|
exp_space = gtk.Label('')
|
|
|
|
vbox.pack_start(exp_space)
|
|
|
|
exp_space.show()
|
|
|
|
|
|
|
|
self.pack_start(vbox)
|
|
|
|
vbox.show()
|
|
|
|
|
2006-06-15 03:52:46 +02:00
|
|
|
sw = gtk.ScrolledWindow()
|
|
|
|
sw.set_size_request(320, -1)
|
|
|
|
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
|
2006-06-14 21:01:17 +02:00
|
|
|
|
2006-06-15 03:52:46 +02:00
|
|
|
self._activities = ActivitiesView()
|
|
|
|
sw.add(self._activities)
|
|
|
|
self._activities.show()
|
2006-06-15 23:41:49 +02:00
|
|
|
|
|
|
|
self.pack_start(sw)
|
2006-06-15 03:52:46 +02:00
|
|
|
sw.show()
|
|
|
|
|
2006-06-15 23:41:49 +02:00
|
|
|
def _on_activity_announced_cb(self, pservice, service, buddy):
|
2006-06-16 07:43:42 +02:00
|
|
|
self._activities.get_model().add_activity(buddy, service)
|
2006-06-15 23:41:49 +02:00
|
|
|
|
2006-06-15 03:52:46 +02:00
|
|
|
def _search_entry_activate_cb(self, entry):
|
|
|
|
self._search()
|
2006-06-14 21:01:17 +02:00
|
|
|
|
|
|
|
def _search_button_clicked_cb(self, button):
|
2006-06-15 03:52:46 +02:00
|
|
|
self._search()
|
|
|
|
|
|
|
|
def _search(self):
|
|
|
|
text = self._search_entry.get_text()
|
|
|
|
self._search_entry.set_text('')
|
2006-06-14 21:01:17 +02:00
|
|
|
|
|
|
|
google.LICENSE_KEY = '1As9KaJQFHIJ1L0W5EZPl6vBOFvh/Vaf'
|
|
|
|
data = google.doGoogleSearch(text)
|
2006-06-15 03:52:46 +02:00
|
|
|
|
|
|
|
model = ActivitiesModel()
|
2006-06-14 21:01:17 +02:00
|
|
|
for result in data.results:
|
2006-06-16 08:36:18 +02:00
|
|
|
title = result.title
|
|
|
|
|
|
|
|
# FIXME what tags should we actually strip?
|
|
|
|
title = title.replace('<b>', '')
|
|
|
|
title = title.replace('</b>', '')
|
|
|
|
|
|
|
|
# FIXME I'm sure there is a better way to
|
|
|
|
# unescape these.
|
|
|
|
title = title.replace('"', '"')
|
|
|
|
title = title.replace('&', '&')
|
|
|
|
|
|
|
|
model.add_web_page(title, result.URL)
|
2006-06-15 03:52:46 +02:00
|
|
|
self._activities.set_model(model)
|