def __fileUploadEnded(self, fileNumber, errorOccured, imageLinks=None,file=""): """if upload was successfull than attaches imageLinks to combobox with given fileNumber and shows it otherwise it sets proggressbar message to indicate upload failure imageLinks and file are ignored if errorOccured is True""" if not errorOccured: self.links[fileNumber] = imageLinks[0] # there is one thread per file so this should be thread safe db.addFile(getUploader(file).NAME, imageLinks[2][0], imageLinks[2][1], imageLinks[2][2], os.path.basename(file), os.path.getsize(file),file.split('.')[-1].lower(), getMimeTypes(file)) if isImage(getMimeTypes(file)): saveThumbnail(createThumbnail(file), file, imageLinks[2][0]) self.__uploadsCompletedLock.acquire() try: #rather not needed self.__uploadsCompleted += 1 if errorOccured: self.__uploadsErrors += 1 finally: self.__uploadsCompletedLock.release() try: gtk.gdk.threads_enter() if errorOccured: self.__pbars[fileNumber].set_text(_("upload failed")) else: self.__pbars[fileNumber].set_text(_("upload completed")) combobox = self.__comboBoxes[fileNumber] linkTypes = imageLinks[1] populateCombobox(combobox, linkTypes) combobox.show() self.__populateStatusIconMenuForFile(fileNumber, linkTypes) if self.__uploadsCompleted > 1: self.__createCopyAllLinks() self.setWindowSize() self.__statusIcon.set_tooltip(_("Uploaded ") + str(self.__uploadsCompleted) + _(" of ") + str(len(self.__comboBoxes)) + _(" files.")) if(self.__uploadsCompleted == len(self.__comboBoxes)): if (set.getBlinkIcon()): self.__statusIcon.set_blinking(True) if set.getShowNotifications(): try: import pynotify if pynotify.init("PyShare"): notification = None if self.__uploadsErrors == 0: notification = pynotify.Notification(_("All files have been uploaded"), _("select link from comboboxes or systray to copy it to clipboard"), "go-up") elif self.__uploadsErrors < self.__uploadsCompleted : notification = pynotify.Notification(_("Some files have not been uploaded"), _("select link from comboboxes or systray to copy it to clipboard. Try sending not-uploaded files again"), "go-up") else: notification = pynotify.Notification(_("Uploads failed"), _("Please try again. If error persist check if file is correct and that you have connection."), "go-up") notification.show() except ImportError: pass finally: gtk.gdk.threads_leave()
def __fileUploadEnded(self, fileNumber, errorOccured, imageLinks=None,file=""): """if upload was successfull than attaches imageLinks to combobox with given fileNumber and shows it otherwise it sets proggressbar message to indicate upload failure imageLinks and file are ignored if errorOccured is True""" if self.__cancelled[fileNumber]: self.__fileUploadCancelled(fileNumber) return # First, hide 'Cancel' button cancelbutton = self.__cancelUploadButton[fileNumber] cancelbutton.hide() if not errorOccured: self.links[fileNumber] = imageLinks[0] # there is one thread per file so this should be thread safe db.addFile(getUploader(file).NAME, imageLinks[2][0], imageLinks[2][1], imageLinks[2][2], os.path.basename(file), os.path.getsize(file),file.split('.')[-1].lower(), getMimeTypes(file)) if isImage(getMimeTypes(file)): saveThumbnail(createThumbnail(file), file, imageLinks[2][0]) self.__uploadsCompletedLock.acquire() try: #rather not needed self.__uploadsCompleted += 1 if errorOccured: self.__uploadsErrors += 1 finally: self.__uploadsCompletedLock.release() try: gtk.gdk.threads_enter() if errorOccured: self.__pbars[fileNumber].set_text(_("upload failed")) else: self.__pbars[fileNumber].set_text(_("upload completed")) # Upload has succeeded, we allow 'Copy Link' button to show copybutton = self.__cplinkButton[fileNumber] copybutton.show() combobox = self.__comboBoxes[fileNumber] linkTypes = imageLinks[1] populateCombobox(combobox, linkTypes) combobox.show() self.__populateStatusIconMenuForFile(fileNumber, linkTypes) if self.__uploadsCompleted > 1: self.__createCopyAllLinks() self.setWindowSize() self.__statusIcon.set_tooltip(_("Uploaded ") + str(self.__uploadsCompleted) + _(" of ") + str(len(self.__comboBoxes)) + _(" files.")) if(self.__uploadsCompleted == len(self.__comboBoxes)): if (set.getBlinkIcon()): self.__statusIcon.set_blinking(True) if set.getShowNotifications(): try: import pynotify if pynotify.init("PyShare"): notification = None if self.__uploadsErrors == 0: notification = pynotify.Notification(_("File(s) uploaded successfully"), _("Click the Copy Link button to copy the file url(s) to your clipboard."), "go-up") elif self.__uploadsErrors < self.__uploadsCompleted : notification = pynotify.Notification(_("Some upload(s) failed"), _("For successfully upload(s), click the Copy Link button to copy the file url(s) to your clipboard. Please try failed upload(s) again."), "go-up") else: notification = pynotify.Notification(_("Upload(s) Failed"), _("Please verify your internet connection and that the file(s) have appropriate permissions then try again."), "go-up") notification.show() except ImportError: pass finally: gtk.gdk.threads_leave()