~ubuntuone-control-tower/software-center/trunk

« back to all changes in this revision

Viewing changes to softwarecenter/view/widgets/imagedialog.py

  • Committer: Michael Vogt
  • Date: 2010-10-04 16:37:23 UTC
  • mfrom: (1247.1.1 trunk)
  • Revision ID: michael.vogt@ubuntu.com-20101004163723-dxsxmb36f9i5g071
* Screenshots are now stored all in a single software-center
  directory (LP: #648284)
* Thumbnails and screenshots are now reused (LP: #648279, #648278)

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
class Url403Error(IOError):
39
39
    pass
40
40
 
 
41
# FIXME: use the utils.py:ImageDownloader here instead of a thread
41
42
class ShowImageDialog(gtk.Dialog):
42
43
    """A dialog that shows a image """
43
44
 
44
 
    def __init__(self, title, url, missing_img, parent=None):
 
45
    def __init__(self, title, url, missing_img, path=None, parent=None):
45
46
        gtk.Dialog.__init__(self)
46
47
        self.set_has_separator(False)
47
48
        # find parent window for the dialog
90
91
        self.connect("response", self._response)
91
92
        # install urlopener
92
93
        urllib._urlopener = GnomeProxyURLopener()
 
94
        # destination
 
95
        if not path:
 
96
            tmpfile.mkdtemp(prefix="sc-screenshot")
 
97
        self.path = path
93
98
        # data
94
99
        self.url = url
95
100
            
140
145
    def _fetch(self):
141
146
        "fetcher thread"
142
147
        logging.debug("_fetch: %s" % self.url)
143
 
        self.location = tempfile.NamedTemporaryFile()
144
 
        try:
145
 
            (screenshot, info) = urllib.urlretrieve(self.url, 
146
 
                                                    self.location.name, 
147
 
                                                    self._progress)
148
 
            self.image_filename = self.location.name
149
 
        except (Url403Error, Url404Error), e:
150
 
            self.image_filename = self._missing_img
151
 
        except Exception, e:
152
 
            logging.exception("urlopen error")
 
148
        if os.path.exists(self.path):
 
149
            self.image_filename = self.path
 
150
        else:
 
151
            self.location = open(self.path, 'w')
 
152
            try:
 
153
                (screenshot, info) = urllib.urlretrieve(self.url, 
 
154
                                                        self.location.name, 
 
155
                                                        self._progress)
 
156
                self.image_filename = self.location.name
 
157
            except (Url403Error, Url404Error), e:
 
158
                self.image_filename = self._missing_img
 
159
                self.location.close()
 
160
                os.remove(self.location.name)
 
161
            except Exception, e:
 
162
                logging.exception("urlopen error")
153
163
        self._finished = True
154
164
 
155
165
    def _progress(self, count, block, total):