Get rid of the web search activity, refactor

This commit is contained in:
Marco Pesenti Gritti 2006-06-14 22:04:44 -04:00
parent 3e3c168ab0
commit a4b2e74d25
3 changed files with 10 additions and 85 deletions

View File

@ -5,35 +5,17 @@ import gobject
import sugar.env import sugar.env
from sugar.browser.WebActivity import WebActivity
from sugar.browser.BrowserActivity import BrowserActivity from sugar.browser.BrowserActivity import BrowserActivity
class BrowserShell(dbus.service.Object): class BrowserShell(dbus.service.Object):
instance = None def __init__(self, object_path = '/com/redhat/Sugar/Browser'):
_lock = threading.Lock()
def get_instance():
BrowserShell._lock.acquire()
if not BrowserShell.instance:
BrowserShell.instance = BrowserShell()
BrowserShell._lock.release()
return BrowserShell.instance
get_instance = staticmethod(get_instance)
def __init__(self):
geckoembed.set_profile_path(sugar.env.get_user_dir())
session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName('com.redhat.Sugar.Browser', bus=session_bus)
object_path = '/com/redhat/Sugar/Browser'
dbus.service.Object.__init__(self, bus_name, object_path) dbus.service.Object.__init__(self, bus_name, object_path)
geckoembed.set_profile_path(sugar.env.get_user_dir())
self.__browsers = [] self.__browsers = []
def open_web_activity(self): def start():
web_activity = WebActivity(self) gtk.main()
web_activity.connect_to_shell()
@dbus.service.method('com.redhat.Sugar.BrowserShell') @dbus.service.method('com.redhat.Sugar.BrowserShell')
def get_links(self): def get_links(self):

View File

@ -1,59 +0,0 @@
import pygtk
pygtk.require('2.0')
import gtk
import geckoembed
from sugar.shell import activity
from sugar.browser.AddressItem import AddressItem
class AddressToolbar(gtk.Toolbar):
def __init__(self, shell):
gtk.Toolbar.__init__(self)
self._shell = shell
address_item = AddressItem(self.__open_address_cb)
self.insert(address_item, 0)
address_item.show()
def __open_address_cb(self, address):
self._shell.open_browser(address)
class WebActivity(activity.Activity):
def __init__(self, shell):
activity.Activity.__init__(self)
self._shell = shell
def on_connected_to_shell(self):
self.set_tab_text("Web")
self.set_tab_icon(name="web-browser")
self.set_show_tab_icon(True)
vbox = gtk.VBox()
self.embed = geckoembed.Embed()
self.embed.connect("open-address", self.__open_address);
vbox.pack_start(self.embed)
self.embed.show()
address_toolbar = AddressToolbar(self._shell)
vbox.pack_start(address_toolbar, False)
address_toolbar.show()
plug = self.gtk_plug()
plug.add(vbox)
plug.show()
vbox.show()
self.embed.load_address("http://www.google.com")
def __open_address(self, embed, uri, data=None):
if uri.startswith("http://www.google.com"):
return False
else:
self._shell.open_browser(uri)
return True
def on_disconnected_from_shell(self):
gtk.main_quit()

View File

@ -3,6 +3,7 @@
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk
import dbus
import sugar.env import sugar.env
@ -14,6 +15,7 @@ log_writer.start()
gtk.rc_parse(sugar.env.get_data_file('browser.rc')) gtk.rc_parse(sugar.env.get_data_file('browser.rc'))
BrowserShell.get_instance().open_web_activity() session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName('com.redhat.Sugar.Browser', bus=session_bus)
gtk.main() shell = BrowserShell(bus_name)
shell.start()