Example #1
0
 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()
Example #2
0
    def addFiles(self, urls, firstAdding=False):
        """adds progressbar, buttons, thumbnail and status menu entry for each file to GUI.
        calls set windows size
        if there is more than one file in the windows also shows copy all link combobox
        starts uploding given files"""
        files = self.urlsToPaths(urls)
        addedFiles = []
        vbox = self.vboxFiles
        numberOfFilesAddedEarierl = len(self.__comboBoxes)
        totalNumberOfFiles = numberOfFilesAddedEarierl
        for file in files:
            hbox = gtk.HBox(False, 0)
            vbox.pack_start(hbox, False, False, 0)
            hbox.show()

	    from stat import *
	    st = os.stat(file)
	    if (st[ST_SIZE] > 5000000):
		from subprocess import Popen
		proc=Popen("zenity --question --text='File may be to large to transfer. Continue?'", shell=True )
		proc.communicate()
		if proc.returncode:
		    break

            #thumbnail
            image = gtk.Image()
            image.set_from_pixbuf(createThumbnail(file))
            hbox.pack_start(image, False, False, 8)
            image.show()

            vboxSmall = gtk.VBox(False, 5)
            hbox.pack_start(vboxSmall, False, False, 0)
            vboxSmall.show()
            
            #filename
            label = gtk.Label(file.split('/')[-1])
	    label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
            label.set_alignment(0, 0.5)
            vboxSmall.pack_start(label, False, False, 0)
            label.show()
            
            #progress bar
            pbar = gtk.ProgressBar()
            self.__pbars.append(pbar)
            vboxSmall.pack_start(pbar, False, False, 0)
            pbar.show()

            #comboBox = createCombobox(uploader.getReturnedLinkTypes())
            comboBox = createCombobox()
            self.links.append([])
            comboBox.connect("changed", self.copyLink, totalNumberOfFiles)
            comboBox.connect("notify::popup-shown", self.__windowClicked)
            #comboBox.show() # "show" comboboxes to make windows size calculation precise(comboboxes will be hidden again before window will be desplayed)
            self.__comboBoxes.append(comboBox)

	    #Copy Link button - not displayed until upload finished
            copyButton = gtk.Button(label = "Copy Link")
            copyButton.connect("clicked", self.copyLink, totalNumberOfFiles, 0)
	    self.__cplinkButton.append(copyButton)
            vboxSmall.pack_start(copyButton, False, False, 0)
            
	    # Cancel upload button
	    cancelButton = gtk.Button(label = "Cancel")
            cancelButton.connect("clicked", self.cancelUpload, totalNumberOfFiles)
	    self.__cancelUploadButton.append(cancelButton)
	    self.__cancelled.append(0)
	    vboxSmall.pack_start(cancelButton, False, False, 0)
	    cancelButton.show()
	    
	    #cancel label to appear after upload cancelled
	    label = gtk.Label("Cancelled")
	    label.set_size_request(150, 50)
	    label.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white")) 
	    eb = gtk.EventBox()
	    eb.add(label)
	    eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("grey"))
	    self.__cancelledLabel.append(eb)
	    vboxSmall.pack_start(eb, False, False, 0)
	    label.show()

            separator = gtk.HSeparator()
            vbox.pack_start(separator, False, False, 4)
            separator.show()

            uploader = getUploader(file)
            addedFiles.append(file)
            uploadFileWrapper(uploader,self.fileUploadFailed,
                file,self.fileUploaded,self.progress,totalNumberOfFiles, self.__semaphore)
            totalNumberOfFiles += 1
            
        if firstAdding:
            self.__addFooter()
            self.__createStatusIconMenu(addedFiles)
        else:
            self.insertFilesToStatusIconMenu(addedFiles, numberOfFilesAddedEarierl)
            
#        if totalNumberOfFiles > 1:
#            self.__createCopyAllLinks()

        self.setWindowSize()

        while numberOfFilesAddedEarierl < totalNumberOfFiles: # hide comboboxes, they will be displayed when links are ready
            self.__comboBoxes[numberOfFilesAddedEarierl].hide()
            numberOfFilesAddedEarierl += 1
        self.__statusIcon.set_blinking(False)
Example #3
0
    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()
Example #4
0
    def addFiles(self, urls, firstAdding=False):
        """adds progressbar, buttons, thumbnail and status menu entry for each file to GUI.
        calls set windows size
        if there is more than one file in the windows also shows copy all link combobox
        starts uploding given files"""
        files = self.urlsToPaths(urls)
        addedFiles = []
        vbox = self.vboxFiles
        numberOfFilesAddedEarierl = len(self.__comboBoxes)
        totalNumberOfFiles = numberOfFilesAddedEarierl
        for file in files:
            hbox = gtk.HBox(False, 0)
            vbox.pack_start(hbox, False, False, 0)
            hbox.show()

            vboxSmall = gtk.VBox(False, 0)
            hbox.pack_start(vboxSmall, False, False, 0)
            vboxSmall.show()

            label = gtk.Label(file.split('/')[-1])
            vboxSmall.pack_start(label, False, False, 0)
            label.show()

            pbar = gtk.ProgressBar()
            self.__pbars.append(pbar)
            vboxSmall.pack_start(pbar, False, False, 0)
            pbar.show()

            #comboBox = createCombobox(uploader.getReturnedLinkTypes())
            comboBox = createCombobox()
            self.links.append([])
            comboBox.connect("changed", self.copyLink, totalNumberOfFiles)
            comboBox.connect("notify::popup-shown", self.__windowClicked)
            comboBox.show() # "show" comboboxes to make windows size calculation precise(comboboxes will be hidden again before window will be desplayed)
            self.__comboBoxes.append(comboBox)

            vboxSmall.pack_start(comboBox, False, False, 0)

            image = gtk.Image()
            image.set_from_pixbuf(createThumbnail(file))
            hbox.pack_start(image, False, False, 8)
            image.show()

            separator = gtk.HSeparator()
            vbox.pack_start(separator, False, False, 4)
            separator.show()

            uploader = getUploader(file)
            addedFiles.append(file)
            uploadFileWrapper(uploader,self.fileUploadFailed,
                file,self.fileUploaded,self.progress,totalNumberOfFiles, self.__semaphore)
            totalNumberOfFiles += 1
            
        if firstAdding:
            self.__addFooter()
            self.__createStatusIconMenu(addedFiles)
        else:
            self.insertFilesToStatusIconMenu(addedFiles, numberOfFilesAddedEarierl)
            
#        if totalNumberOfFiles > 1:
#            self.__createCopyAllLinks()

        self.setWindowSize()

        while numberOfFilesAddedEarierl < totalNumberOfFiles: # hide comboboxes, they will be displayed when links are ready
            self.__comboBoxes[numberOfFilesAddedEarierl].hide()
            numberOfFilesAddedEarierl += 1
        self.__statusIcon.set_blinking(False)