[Bugs] #1106 HIGH: Browse: No preview in Journal for downloaded image

Sugar Labs Bugs bugtracker-noreply at sugarlabs.org
Mon Aug 9 10:24:05 EDT 2010


#1106: Browse: No preview in Journal for downloaded image
----------------------------+-----------------------------------------------
    Reporter:  Mokurai      |          Owner:  tomeu      
        Type:  enhancement  |         Status:  new        
    Priority:  High         |      Milestone:  0.90       
   Component:  Browse       |        Version:  Unspecified
    Severity:  Critical     |       Keywords:  GPA r?     
Distribution:  Unspecified  |   Status_field:  Unconfirmed
----------------------------+-----------------------------------------------
Changes (by tomeu):

  * keywords:  GPA => GPA r?
  * component:  journal => Browse


Comment:

 Replying to [comment:5 godiard]:
 > This patch resolves the problem in browser.
 > I don't know if may be a good idea do the preview in the datastore
 instead.

 I think we should try to keep the DS as simple as possible because it's a
 so critical component. Also, the right size and format of previews are
 dependent on the UX and the DS should have no knowledge of it.

 Would be great if you could send commit patches such as those generated
 with git format-patch, more details in
 http://wiki.sugarlabs.org/go/Development_Team/Code_Review#Proposal

 > Gonzalo
 > {{{
 > [gonzalo at aronax Browse.activity]$ diff -u downloadmanager.py.ori
 downloadmanager.py
 > --- downloadmanager.py.ori    2010-07-05 20:27:06.000000000 -0300
 > +++ downloadmanager.py    2010-08-06 02:17:23.095272320 -0300
 > @@ -36,8 +36,10 @@
 >  from sugar import mime
 >  from sugar.graphics.alert import Alert, TimeoutAlert
 >  from sugar.graphics.icon import Icon
 > +from sugar.graphics import style
 >  from sugar.activity import activity
 >
 > +
 >  # #3903 - this constant can be removed and assumed to be 1 when dbus-
 python
 >  # 0.82.3 is the only version used
 >  import dbus
 > @@ -192,12 +194,47 @@
 >                  sniffed_mime_type =
 mime.get_for_file(self._target_file.path)
 >                  self.dl_jobject.metadata['mime_type'] =
 sniffed_mime_type
 >
 > +            if self._mime_type in
 ('image/bmp','image/gif','image/jpeg','image/png','image/tiff'):
 > +
 > +                self.dl_jobject.metadata['preview'] =
 self.__get_preview_image()
 > +            else:
 > +                self.dl_jobject.metadata['preview'] = ''
 > +
 >              datastore.write(self.dl_jobject,
 >                              transfer_ownership=True,
 >                              reply_handler=self._internal_save_cb,
 >                              error_handler=self._internal_save_error_cb,
 >                              timeout=360 *
 DBUS_PYTHON_TIMEOUT_UNITS_PER_SECOND)
 >
 > +    def __get_preview_image(self):
 > +        pixbuf = gtk.gdk.pixbuf_new_from_file(self._target_file.path)
 > +        width, height = pixbuf.get_width(), pixbuf.get_height()
 > +
 > +        preview_width = style.zoom(300)
 > +        preview_height =  style.zoom(225)
 > +
 > +        if (width > preview_width) or (height > preview_height):
 > +            scale_x = float(width) / preview_width
 > +            scale_y = float(height) / preview_height
 > +            scale = max(scale_x,scale_y)
 > +
 > +            pixbuf = pixbuf.scale_simple(float(width) / scale, height /
 scale,
 > +                                     gtk.gdk.INTERP_BILINEAR)
 > +        pixbuf2 =
 gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,pixbuf.get_has_alpha(),8,preview_width,preview_height)
 > +        pixbuf2.fill(0xffffffff)
 > +        margin_x = (preview_width - pixbuf.get_width()) / 2
 > +        margin_y = (preview_height - pixbuf.get_height()) / 2
 > +
 > +
 pixbuf.copy_area(0,0,pixbuf.get_width(),pixbuf.get_height(),pixbuf2,margin_x,margin_y)
 > +
 > +        preview_data = []
 > +        def save_func(buf, data):
 > +            data.append(buf)
 > +
 > +        pixbuf2.save_to_callback(save_func, 'png',
 user_data=preview_data)
 > +        preview_data = ''.join(preview_data)
 > +        return dbus.ByteArray(preview_data)
 > +
 >      def __start_response_cb(self, alert, response_id):
 >          global _active_downloads
 >          if response_id is gtk.RESPONSE_CANCEL:
 > @@ -273,10 +310,10 @@
 >          self.dl_jobject.metadata['progress'] = '0'
 >          self.dl_jobject.metadata['keep'] = '0'
 >          self.dl_jobject.metadata['buddies'] = ''
 > -        self.dl_jobject.metadata['preview'] = ''
 >          self.dl_jobject.metadata['icon-color'] = \
 >                  profile.get_color().to_string()
 >          self.dl_jobject.metadata['mime_type'] = self._mime_type
 > +        self.dl_jobject.metadata['preview'] = ''
 >          self.dl_jobject.file_path = ''
 >          datastore.write(self.dl_jobject)
 > }}}

-- 
Ticket URL: <http://bugs.sugarlabs.org/ticket/1106#comment:6>
Sugar Labs <http://sugarlabs.org/>
Sugar Labs bug tracking system


More information about the Bugs mailing list