2006-06-01 00:01:24 +02:00
|
|
|
import dbus
|
|
|
|
import geckoembed
|
2006-06-02 20:52:20 +02:00
|
|
|
import threading
|
2006-06-01 00:01:24 +02:00
|
|
|
|
|
|
|
import sugar.env
|
|
|
|
|
|
|
|
from sugar.p2p.Group import LocalGroup
|
|
|
|
from sugar.browser.WebActivity import WebActivity
|
|
|
|
from sugar.browser.BrowserActivity import BrowserActivity
|
|
|
|
|
|
|
|
class BrowserShell(dbus.service.Object):
|
|
|
|
instance = None
|
2006-06-02 20:52:20 +02:00
|
|
|
_lock = threading.Lock()
|
2006-06-01 00:01:24 +02:00
|
|
|
|
|
|
|
def get_instance():
|
2006-06-02 20:52:20 +02:00
|
|
|
BrowserShell._lock.acquire()
|
2006-06-01 00:01:24 +02:00
|
|
|
if not BrowserShell.instance:
|
|
|
|
BrowserShell.instance = BrowserShell()
|
2006-06-02 20:52:20 +02:00
|
|
|
BrowserShell._lock.release()
|
2006-06-01 00:01:24 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
self.__browsers = []
|
|
|
|
self._group = LocalGroup()
|
|
|
|
|
|
|
|
def open_web_activity(self):
|
|
|
|
web_activity = WebActivity(self)
|
2006-06-02 20:52:20 +02:00
|
|
|
web_activity.connect_to_shell()
|
2006-06-01 00:01:24 +02:00
|
|
|
|
|
|
|
@dbus.service.method('com.redhat.Sugar.BrowserShell')
|
|
|
|
def get_links(self):
|
|
|
|
links = []
|
|
|
|
for browser in self.__browsers:
|
|
|
|
embed = browser.get_embed()
|
|
|
|
link = {}
|
|
|
|
link['title'] = embed.get_title()
|
|
|
|
link['address'] = embed.get_address()
|
|
|
|
links.append(link)
|
|
|
|
return links
|
|
|
|
|
|
|
|
@dbus.service.method('com.redhat.Sugar.BrowserShell')
|
|
|
|
def open_browser(self, uri):
|
|
|
|
browser = BrowserActivity(self._group, uri)
|
|
|
|
self.__browsers.append(browser)
|
2006-06-02 20:52:20 +02:00
|
|
|
browser.connect_to_shell()
|