ignore this patch.<br>I am doing anything wrong with git<br><br>Gonzalo<br><br><div class="gmail_quote">On Fri, Sep 24, 2010 at 10:44 AM,  <span dir="ltr">&lt;<a href="mailto:godiard@sugarlabs.org">godiard@sugarlabs.org</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;">From: Gonzalo Odiard &lt;<a href="mailto:godiard@sugarlabs.org">godiard@sugarlabs.org</a>&gt;<br>

<br>
generates a preview image with a fixed size and proportions.<br>
if the original image is bigger scale down and center the image, if is smaller center the image<br>
the supported format files are checked with pixbuf_get_formats<br>
<br>
this patch adressed comments from silbe about segregate the check of a image mime type and use of sugar.style constant colors<br>
now opens the image in the original size because we don&#39;t want scale up small images<br>
---<br>
 downloadmanager.py |   46 ++++++++++++++++++++++++++++++++++++++++++++++<br>
 1 files changed, 46 insertions(+), 0 deletions(-)<br>
<br>
diff --git a/downloadmanager.py b/downloadmanager.py<br>
index 3eec649..ed68d82 100644<br>
--- a/downloadmanager.py<br>
+++ b/downloadmanager.py<br>
@@ -35,6 +35,7 @@ from sugar.datastore import datastore<br>
 from sugar import profile<br>
 from sugar import mime<br>
 from sugar.graphics.alert import Alert, TimeoutAlert<br>
+from sugar.graphics import style<br>
 from sugar.graphics.icon import Icon<br>
 from sugar.activity import activity<br>
<br>
@@ -192,12 +193,57 @@ class Download:<br>
                 sniffed_mime_type = mime.get_for_file(self._target_file.path)<br>
                 self.dl_jobject.metadata[&#39;mime_type&#39;] = sniffed_mime_type<br>
<br>
+            if self._check_image_mime_type():<br>
+                self.dl_jobject.metadata[&#39;preview&#39;] = self._get_preview_image()<br>
+<br>
             datastore.write(self.dl_jobject,<br>
                             transfer_ownership=True,<br>
                             reply_handler=self._internal_save_cb,<br>
                             error_handler=self._internal_save_error_cb,<br>
                             timeout=360 * DBUS_PYTHON_TIMEOUT_UNITS_PER_SECOND)<br>
<br>
+<br>
+    def _check_image_mime_type(self):<br>
+        pixbuf_mime_types = []<br>
+        for pixbuf_format in gtk.gdk.pixbuf_get_formats():<br>
+            pixbuf_mime_types.extend(pixbuf_format[&#39;mime_types&#39;])<br>
+<br>
+        return self._mime_type in pixbuf_mime_types<br>
+<br>
+    def _get_preview_image(self):<br>
+        preview_width, preview_height = style.zoom(300), style.zoom(225)<br>
+<br>
+        pixbuf = gtk.gdk.pixbuf_new_from_file(self._target_file.path)<br>
+        width, height = pixbuf.get_width(), pixbuf.get_height()<br>
+<br>
+<br>
+        if (width &gt; preview_width) or (height &gt; preview_height):<br>
+            scale_x = float(width) / preview_width<br>
+            scale_y = float(height) / preview_height<br>
+            scale = max(scale_x,scale_y)<br>
+<br>
+            pixbuf = pixbuf.scale_simple(float(width) / scale, height / scale,<br>
+                                     gtk.gdk.INTERP_BILINEAR)<br>
+<br>
+        width, height = pixbuf.get_width(), pixbuf.get_height()<br>
+<br>
+        pixbuf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pixbuf.get_has_alpha(),<br>
+            pixbuf.get_bits_per_sample(), preview_width, preview_height)<br>
+<br>
+        pixbuf2.fill(style.COLOR_WHITE.get_int())<br>
+<br>
+        margin_x, margin_y = (preview_width - width) / 2, (preview_height - height) / 2<br>
+<br>
+        pixbuf.copy_area(0, 0, width, height, pixbuf2, margin_x, margin_y)<br>
+<br>
+        preview_data = []<br>
+        def save_func(buf, data):<br>
+            data.append(buf)<br>
+<br>
+        pixbuf2.save_to_callback(save_func, &#39;png&#39;, user_data=preview_data)<br>
+        preview_data = &#39;&#39;.join(preview_data)<br>
+        return dbus.ByteArray(preview_data)<br>
+<br>
     def __start_response_cb(self, alert, response_id):<br>
         global _active_downloads<br>
         if response_id is gtk.RESPONSE_CANCEL:<br>
<font color="#888888">--<br>
1.7.2.3<br>
<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Gonzalo Odiard<br>SugarLabs Argentina<br><br>