← Back to team overview

openshot.code team mailing list archive

[Branch ~openshot.code/openshot/main] Rev 497: Applied a patch from Emil to fix bug #821102, No feedback when unsupported files are imported. No...

 

------------------------------------------------------------
revno: 497
committer: Andy Finch <we.rocked.in79@xxxxxxxxx>
branch nick: openshot
timestamp: Thu 2011-08-11 20:33:49 +0100
message:
  Applied a patch from Emil to fix bug #821102, No feedback when unsupported files are imported. Now if you try and import an unsupported file type or an empty folder a relevant message is displayed.
modified:
  openshot/classes/files.py
  openshot/windows/AddFiles.py


--
lp:openshot
https://code.launchpad.net/~openshot.code/openshot/main

Your team OpenShot Code is subscribed to branch lp:openshot.
To unsubscribe from this branch go to https://code.launchpad.net/~openshot.code/openshot/main/+edit-subscription
=== modified file 'openshot/classes/files.py'
--- openshot/classes/files.py	2011-07-18 21:18:29 +0000
+++ openshot/classes/files.py	2011-08-11 19:33:49 +0000
@@ -149,23 +149,37 @@
 	#----------------------------------------------------------------------
 	def AddFile(self, file_name, session=None, ignore_image_sequences=False):
 		"""Add a new file to the current folder"""
+		"""
+		Returns a tuple: 
+		(The number of files that could be successfully imported (not including folders),
+		The number of files that could not be imported (wrong format),
+		The number of files already imported to the project,
+		The number of folders selected (0 or 1))
+		"""
 		
 		import urllib
 		
 		# get a reference to the language translate method
 		_ = self.project.translate
 		
-		# clean path to video
+		# clean path to file
 		file_name = urllib.unquote(file_name)
 		newFile = None
 		
-		# don't add a file that is already in this folder (i.e. dupe check)
-		if self.file_exists_in_project(file_name):
-			return
+		# The number of ok files (not counting folders)
+		ok_files = 0
+		# The number of files that couldn't be read (wrong format)
+		broken_files = 0
+		# The number of duplicates in the project
+		duplicate_files = 0
+		# The number of folders submitted (0 or 1)
+		folders = 0
 			
 		# check if the path is a 'folder' and not a file
 		if os.path.isdir(file_name):
 			
+			folders += 1
+			
 			# loop through each sub-file (if any)
 			for sub_file in os.listdir(file_name):
 				sub_file_path = os.path.join(file_name, sub_file)
@@ -173,42 +187,61 @@
 				# only add files
 				if os.path.isfile(sub_file_path):
 					
-					# don't add a file that is alrady in this folder (i.e. dupe check)
+					# don't add a file that is already in the project (i.e. dupe check)
 					if self.file_exists_in_project(sub_file_path) == False:
 
 						# inspect the media file and generate it's thumbnail image (if any)
 						newFile = self.project.thumbnailer.GetFile(sub_file_path)
-						
+					
 						# add to internal item collection
 						if newFile:
+							ok_files += 1
 							self.items.append(newFile)
+						else:
+							broken_files += 1
+					else:
+						duplicate_files += 1
 
 		else:
+		
+			# don't add a file that is already in this folder (i.e. dupe check)
+			if self.file_exists_in_project(file_name):
+				duplicate_files += 1
+				return (ok_files, broken_files, duplicate_files, folders)
+			
 			# should we ignore image sequence check?
 			if ignore_image_sequences:
 				
 				# inspect the media file and generate it's thumbnail image (if any)
 				newFile = self.project.thumbnailer.GetFile(file_name)
-			
+				
 				# add to internal item collection
 				if newFile:
+					ok_files += 1
 					self.items.append(newFile)
+				else:
+					broken_files += 1
 
 			# determine if this is an image sequence
 			elif not self.GetImageSequenceDetails(file_name, session):
-
+			
 				# inspect the media file and generate it's thumbnail image (if any)
 				newFile = self.project.thumbnailer.GetFile(file_name)
 			
 				# add to internal item collection
 				if newFile:
+					ok_files += 1
 					self.items.append(newFile)
+				else:
+					broken_files += 1
+			else:
+				ok_files += 1
 
 		# mark project as modified
 		if newFile:
 			self.project.set_project_modified(is_modified=True, refresh_xml=False, type=_("Added file"))
 		
-		return newFile
+		return (ok_files, broken_files, duplicate_files, folders)
 	
 	
 	def GetImageSequenceDetails(self, file_path, session=None):

=== modified file 'openshot/windows/AddFiles.py'
--- openshot/windows/AddFiles.py	2011-01-29 06:32:37 +0000
+++ openshot/windows/AddFiles.py	2011-08-11 19:33:49 +0000
@@ -55,27 +55,70 @@
 	def on_btnAdd_clicked(self, widget, *args):
 		files_to_add = self.frmAddFiles.get_filenames()
 		
+		# get a reference to the language translate method
+		_ = self.project.translate
+		
 		# create a unique session id, to prevent duplicate prompts
 		session = str(time.time())
 		
+		# The total number of ok files selected (not folders)
+		total_ok_files = 0
+		# The total number of broken files selected (could not be imported)
+		total_broken_files = 0
+		# The total number of files already imported selected
+		total_duplicate_files = 0
+		# The total number of folders selected
+		total_folders = 0
+		
 		try:
 			for file in files_to_add:
 				# add each file
-				self.project.project_folder.AddFile(file, session=session)
-			
-			#set the project as modified
+				result = self.project.project_folder.AddFile(file, session=session)
+				# parse the results and add to the total
+				total_ok_files += result[0]
+				total_broken_files += result[1]
+				total_duplicate_files += result[2]
+				total_folders += result[3]
+		
+			# The number of total selected files, not including folders
+			total_files = total_ok_files + total_broken_files + total_duplicate_files
+		
+			# print error messages (if needed)
+		
+			if total_files == 0:
+				if total_folders == 1:
+					messagebox.show(_("Empty Folder "), _("The selected folder was empty."))
+				else:
+					messagebox.show(_("Empty Folders"), _("The selected folders were empty."))
+			else:
+				if total_files == total_broken_files:
+					if total_files == 1:
+						messagebox.show(_("Unsupported File Type"), _("OpenShot does not support this file type."))
+					else:
+						messagebox.show(_("Unsupported File Types"), _("OpenShot supports none of the file types of the selected files."))
+			
+				elif total_files == total_duplicate_files:
+					if total_files == 1:
+						messagebox.show(_("Already Imported File"), _("The selected file has already been imported to the project."))
+					else:
+						messagebox.show(_("Already Imported Files"), _("All of the selected files have already been imported to the project."))
+			
+				elif total_ok_files == 0:
+					messagebox.show(_("File Import Error"), _("The selected files either have an unsupported file type or have already been imported to the project."))
+					
+			# set the project as modified
 			self.project.set_project_modified(is_modified=True, refresh_xml=False)
-				
+			
 			# refresh the main form
 			self.form.refresh_files()
 			
 		except:
-			messagebox.show(_("Error"), _("There was an error importing the selected files"))
+			messagebox.show(_("Error"), _("There was an error importing the selected file(s)."))
 
 		#set the last used folder
 		preferences.Settings.app_state["import_folder"] = self.frmAddFiles.get_current_folder()
 		
-		# clear and destory this dialog
+		# clear and destroy this dialog
 		self.form.import_files_dialog = None	
 		self.frmAddFiles.destroy()
 		
@@ -117,7 +160,7 @@
 			self.form.replace_clip(self.clip,replace_clip_with)
 			
 		except:
-			messagebox.show(_("Error"), _("There was an error importing the selected files"))
+			messagebox.show(_("Error"), _("There was an error importing the selected file(s)."))
 
 		#set the last used folder
 		preferences.Settings.app_state["import_folder"] = self.frmAddFiles.get_current_folder()