Ok. I addressed all concerns from the previous mails and the comments in irc.<br>This patch take the supported mime types from the pixbuf library and open the image at the desired size to optimize if possible the io.<br><br>
Gonzalo<br><br><div class="gmail_quote">On Wed, Sep 15, 2010 at 7:58 AM, Simon Schampijer <span dir="ltr">&lt;<a href="mailto:simon@schampijer.de">simon@schampijer.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Gonzalo,<br>
<br>
thanks for the new patch. Would be good to tell in a few words what you<br>
did change to the previous one, like: &quot;I addressed all concerns.&quot; or<br>
&quot;That one I did not address since...&quot;<br>
<br>
Regards,<br>
    Simon<br>
<div><div></div><div class="h5"><br>
On 09/14/2010 08:06 PM, <a href="mailto:godiard@sugarlabs.org">godiard@sugarlabs.org</a> wrote:<br>
&gt; From: Gonzalo Odiard&lt;<a href="mailto:godiard@sugarlabs.org">godiard@sugarlabs.org</a>&gt;<br>
&gt;<br>
&gt; ---<br>
&gt;   downloadmanager.py |   32 ++++++++++++++++++++++++++++++++<br>
&gt;   1 files changed, 32 insertions(+), 0 deletions(-)<br>
&gt;<br>
&gt; diff --git a/downloadmanager.py b/downloadmanager.py<br>
&gt; index 3eec649..24d3911 100644<br>
&gt; --- a/downloadmanager.py<br>
&gt; +++ b/downloadmanager.py<br>
&gt; @@ -36,6 +36,7 @@ from sugar import profile<br>
&gt;   from sugar import mime<br>
&gt;   from sugar.graphics.alert import Alert, TimeoutAlert<br>
&gt;   from sugar.graphics.icon import Icon<br>
&gt; +from sugar.graphics import style<br>
&gt;   from sugar.activity import activity<br>
&gt;<br>
&gt;   # #3903 - this constant can be removed and assumed to be 1 when dbus-python<br>
&gt; @@ -192,12 +193,43 @@ class Download:<br>
&gt;                   sniffed_mime_type = mime.get_for_file(self._target_file.path)<br>
&gt;                   self.dl_jobject.metadata[&#39;mime_type&#39;] = sniffed_mime_type<br>
&gt;<br>
&gt; +            pixbuf_mime_types = []<br>
&gt; +            for pixbuf_format in gtk.gdk.pixbuf_get_formats():<br>
&gt; +                pixbuf_mime_types.extend(pixbuf_format[&#39;mime_types&#39;])<br>
&gt; +<br>
&gt; +            if self._mime_type in pixbuf_mime_types:<br>
&gt; +                self.dl_jobject.metadata[&#39;preview&#39;] = self._get_preview_image()<br>
&gt; +<br>
&gt;               datastore.write(self.dl_jobject,<br>
&gt;                               transfer_ownership=True,<br>
&gt;                               reply_handler=self._internal_save_cb,<br>
&gt;                               error_handler=self._internal_save_error_cb,<br>
&gt;                               timeout=360 * DBUS_PYTHON_TIMEOUT_UNITS_PER_SECOND)<br>
&gt;<br>
&gt; +    def _get_preview_image(self):<br>
&gt; +        preview_width, preview_height = style.zoom(300), style.zoom(225)<br>
&gt; +<br>
&gt; +        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(self._target_file.path, preview_width, preview_height)<br>
&gt; +        width, height = pixbuf.get_width(), pixbuf.get_height()<br>
&gt; +<br>
&gt; +        pixbuf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pixbuf.get_has_alpha(),<br>
&gt; +            pixbuf.get_bits_per_sample(), preview_width, preview_height)<br>
&gt; +<br>
&gt; +        OPAQUE_WHITE = 0xffffffff<br>
&gt; +        pixbuf2.fill(OPAQUE_WHITE)<br>
&gt; +<br>
&gt; +        margin_x, margin_y = (preview_width - width) / 2, (preview_height - height) / 2<br>
&gt; +<br>
&gt; +        pixbuf.copy_area(0, 0, width, height, pixbuf2, margin_x, margin_y)<br>
&gt; +<br>
&gt; +        preview_data = []<br>
&gt; +        def save_func(buf, data):<br>
&gt; +            data.append(buf)<br>
&gt; +<br>
&gt; +        pixbuf2.save_to_callback(save_func, &#39;png&#39;, user_data=preview_data)<br>
&gt; +        preview_data = &#39;&#39;.join(preview_data)<br>
&gt; +        return dbus.ByteArray(preview_data)<br>
&gt; +<br>
&gt;       def __start_response_cb(self, alert, response_id):<br>
&gt;           global _active_downloads<br>
&gt;           if response_id is gtk.RESPONSE_CANCEL:<br>
<br>
</div></div>_______________________________________________<br>
Sugar-devel mailing list<br>
<a href="mailto:Sugar-devel@lists.sugarlabs.org">Sugar-devel@lists.sugarlabs.org</a><br>
<a href="http://lists.sugarlabs.org/listinfo/sugar-devel" target="_blank">http://lists.sugarlabs.org/listinfo/sugar-devel</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Gonzalo Odiard<br>SugarLabs Argentina<br><br>