Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Quiñones <manuq@laptop.org>2011-11-11 02:27:04 (GMT)
committer Manuel Quiñones <manuq@laptop.org>2011-11-17 01:43:25 (GMT)
commit8dc7c44df2ece1729abd53aeb082daa67ae83281 (patch)
treece03a6a76259a19dfe105156ae29ebcb7b336d51
parent6c33d7db7f85de12ad84cb583e1b030ad674b69d (diff)
Restore storing links functionality
The screenshots now are made with Cairo. For now it grabs all the activity window, it needs to grab only the WebKit WebView widget. Signed-off-by: Manuel Quiñones <manuq@laptop.org>
-rw-r--r--linkbutton.py47
-rw-r--r--webactivity.py47
2 files changed, 48 insertions, 46 deletions
diff --git a/linkbutton.py b/linkbutton.py
index b43374c..afc3b60 100644
--- a/linkbutton.py
+++ b/linkbutton.py
@@ -18,6 +18,9 @@
from gi.repository import Gtk
import os
from gi.repository import GObject
+from gi.repository import Gdk
+import StringIO
+import cairo
from gettext import gettext as _
import rsvg
import re
@@ -45,32 +48,26 @@ class LinkButton(TrayButton, GObject.GObject):
def set_image(self, buf, fill='#0000ff', stroke='#4d4c4f'):
img = Gtk.Image()
- loader = GdkPixbuf.PixbufLoader()
- loader.write(buf)
- loader.close()
- pixbuf = loader.get_pixbuf()
- del loader
+ str_buf = StringIO.StringIO(buf)
+ thumb_surface = cairo.ImageSurface.create_from_png(str_buf)
xo_buddy = os.path.join(os.path.dirname(__file__), "icons/link.svg")
- pixbuf_bg = self._read_link_background(xo_buddy, fill, stroke)
- pixbuf_bg = pixbuf_bg.scale_simple(style.zoom(120),
- style.zoom(110),
- GdkPixbuf.InterpType.BILINEAR)
+ bg_surface = self._read_link_background(xo_buddy, fill, stroke)
+
+ cairo_context = cairo.Context(bg_surface)
dest_x = style.zoom(10)
dest_y = style.zoom(20)
- w = pixbuf.get_width()
- h = pixbuf.get_height()
- scale_x = 1
- scale_y = 1
-
- pixbuf.composite(pixbuf_bg, dest_x, dest_y, w, h, dest_x, dest_y,
- scale_x, scale_y, GdkPixbuf.InterpType.BILINEAR, 255)
+ cairo_context.set_source_surface(thumb_surface, dest_x, dest_y)
+ thumb_width, thumb_height = style.zoom(100), style.zoom(80)
+ cairo_context.rectangle(dest_x, dest_y, thumb_width, thumb_height)
+ cairo_context.fill()
+
+ bg_width, bg_height = style.zoom(120), style.zoom(110)
+ pixbuf_bg = Gdk.pixbuf_get_from_surface(bg_surface, 0, 0,
+ bg_width, bg_height)
img.set_from_pixbuf(pixbuf_bg)
self.set_icon_widget(img)
img.show()
- del pixbuf
- del pixbuf_bg
- gc.collect()
def _read_link_background(self, filename, fill_color, stroke_color):
icon_file = open(filename, 'r')
@@ -85,8 +82,16 @@ class LinkButton(TrayButton, GObject.GObject):
entity = '<!ENTITY stroke_color "%s">' % stroke_color
data = re.sub('<!ENTITY stroke_color .*>', entity, data)
- data_size = len(data)
- return rsvg.Handle(data=data).get_pixbuf()
+ link_width, link_height = style.zoom(120), style.zoom(110)
+ link_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
+ link_width, link_height)
+ link_context = cairo.Context(link_surface)
+ link_scale_w = link_width * 1.0 / 120
+ link_scale_h = link_height * 1.0 / 110
+ link_context.scale(link_scale_w, link_scale_h)
+ handler = rsvg.Handle(data=data)
+ handler.render_cairo(link_context)
+ return link_surface
def setup_rollover_options(self, info):
palette = Palette(info, text_maxlen=50)
diff --git a/webactivity.py b/webactivity.py
index 95ee269..4e70e85 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -34,6 +34,7 @@ import cjson
from gi.repository import GConf
import locale
import cairo
+import StringIO
from hashlib import sha1
# HACK: Needed by http://dev.sugarlabs.org/ticket/456
@@ -504,7 +505,7 @@ class WebActivity(activity.Activity):
''' take screenshot and add link info to the model '''
browser = self._tabbed_view.props.current_browser
- ui_uri = browser.get_url_from_nsiuri(browser.progress.location)
+ ui_uri = browser.get_uri()
for link in self.model.data['shared_links']:
if link['hash'] == sha1(ui_uri).hexdigest():
@@ -553,31 +554,27 @@ class WebActivity(activity.Activity):
''' an item of the link tray has been clicked '''
self._tabbed_view.props.current_browser.load_uri(url)
- def _pixbuf_save_cb(self, buf, data):
- data[0] += buf
- return True
-
- def get_buffer(self, pixbuf):
- data = [""]
- pixbuf.save_to_callback(self._pixbuf_save_cb, "png", {}, data)
- return str(data[0])
-
def _get_screenshot(self):
- window = self._tabbed_view.props.current_browser.window
- width, height = window.get_size()
-
- screenshot = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, has_alpha=False,
- bits_per_sample=8, width=width,
- height=height)
- screenshot.get_from_drawable(window, window.get_colormap(), 0, 0, 0, 0,
- width, height)
-
- screenshot = screenshot.scale_simple(style.zoom(100),
- style.zoom(80),
- GdkPixbuf.InterpType.BILINEAR)
-
- buf = self.get_buffer(screenshot)
- return buf
+ # FIXME need to make the screenshot only for the page area,
+ # maybe using Gtk.OffscreenWindow
+ window = self._tabbed_view.get_window()
+ width, height = window.get_width(), window.get_height()
+
+ thumb_surface = Gdk.Window.create_similar_surface(window,
+ cairo.CONTENT_COLOR,
+ width, height)
+
+ thumb_width, thumb_height = style.zoom(100), style.zoom(80)
+ cairo_context = cairo.Context(thumb_surface)
+ thumb_scale_w = thumb_width * 1.0 / width
+ thumb_scale_h = thumb_height * 1.0 / height
+ cairo_context.scale(thumb_scale_w, thumb_scale_h)
+ Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
+ cairo_context.paint()
+
+ thumb_str = StringIO.StringIO()
+ thumb_surface.write_to_png(thumb_str)
+ return thumb_str.getvalue()
def can_close(self):
# FIXME temporarily skipping downloadmanager so the activity