mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-30 19:00:09 +00:00 
			
		
		
		
	some work on exif support...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									d5c63da7db
								
							
						
					
					
						commit
						e9bdde82a6
					
				
							
								
								
									
										94
									
								
								ui (gen4)/features/exif.js
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										94
									
								
								ui (gen4)/features/exif.js
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,94 @@ | |||||||
|  | /********************************************************************** | ||||||
|  | *  | ||||||
|  | * | ||||||
|  | * | ||||||
|  | **********************************************************************/ | ||||||
|  | 
 | ||||||
|  | // XXX this is a hack...
 | ||||||
|  | // 		...need a way to escape these so as not to load them in browser...
 | ||||||
|  | if(typeof(process) != 'undefined'){ | ||||||
|  | 	var fs = require('fs') | ||||||
|  | 	var path = require('path') | ||||||
|  | 	var exiftool = require('exiftool') | ||||||
|  | 	var promise = require('promise') | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | define(function(require){ var module = {} | ||||||
|  | 
 | ||||||
|  | //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||||
|  | 
 | ||||||
|  | var actions = require('lib/actions') | ||||||
|  | var core = require('features/core') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /*********************************************************************/ | ||||||
|  | 
 | ||||||
|  | var EXIFActions = actions.Actions({ | ||||||
|  | 	// XXX cache the result and see if it is cached before running exiftool... 
 | ||||||
|  | 	// XXX also check the metadata/ folder (???)
 | ||||||
|  | 	// XXX this uses .markChanged(..) form filesystem.FileSystemWriter 
 | ||||||
|  | 	// 		feature, but technically does not depend on it...
 | ||||||
|  | 	// XXX should we store metadata in an image (current) or in fs???
 | ||||||
|  | 	getExif: ['Edit/Open with external editor', | ||||||
|  | 		function(image, force){ | ||||||
|  | 			var that = this | ||||||
|  | 
 | ||||||
|  | 			var gid = this.data.getImage(image) | ||||||
|  | 			var img = this.images[gid] | ||||||
|  | 			var full_path = path.normalize(img.base_path +'/'+ img.path) | ||||||
|  | 
 | ||||||
|  | 			return new promise(function(resolve, reject){ | ||||||
|  | 				if(!force && img.metadata){ | ||||||
|  | 					return resolve(img.metadata) | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				fs.readFile(full_path, function(err, file){ | ||||||
|  | 					if(err){ | ||||||
|  | 						return reject(err) | ||||||
|  | 					} | ||||||
|  | 
 | ||||||
|  | 					exiftool.metadata(file, function(err, data){ | ||||||
|  | 						if(err){ | ||||||
|  | 							reject(err) | ||||||
|  | 
 | ||||||
|  | 						} else if(data.error){ | ||||||
|  | 							reject(data) | ||||||
|  | 
 | ||||||
|  | 						} else { | ||||||
|  | 							// store metadata...
 | ||||||
|  | 							// XXX 
 | ||||||
|  | 							that.images[gid].metadata = data | ||||||
|  | 							that.markChanged && that.markChanged(gid) | ||||||
|  | 
 | ||||||
|  | 							resolve(data) | ||||||
|  | 						} | ||||||
|  | 					}) | ||||||
|  | 				}) | ||||||
|  | 			}) | ||||||
|  | 		}], | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | var EXIF =  | ||||||
|  | module.EXIF = core.ImageGridFeatures.Feature({ | ||||||
|  | 	title: '', | ||||||
|  | 	doc: '', | ||||||
|  | 
 | ||||||
|  | 	tag: 'exif', | ||||||
|  | 	depends: [ | ||||||
|  | 		'base', | ||||||
|  | 	], | ||||||
|  | 
 | ||||||
|  | 	isApplicable: function(){  | ||||||
|  | 		return this.runtime == 'nw' || this.runtime == 'node' }, | ||||||
|  | 
 | ||||||
|  | 	actions: EXIFActions, | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /********************************************************************** | ||||||
|  | * vim:set ts=4 sw=4 :                                                */ | ||||||
|  | return module }) | ||||||
| @ -9,7 +9,6 @@ define(function(require){ var module = {} | |||||||
| //var DEBUG = DEBUG != null ? DEBUG : true
 | //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||||
| 
 | 
 | ||||||
| var actions = require('lib/actions') | var actions = require('lib/actions') | ||||||
| 
 |  | ||||||
| var core = require('features/core') | var core = require('features/core') | ||||||
| 
 | 
 | ||||||
| // widgets...
 | // widgets...
 | ||||||
|  | |||||||
| @ -15,11 +15,6 @@ if(typeof(process) != 'undefined'){ | |||||||
| 	var pathlib = requirejs('path') | 	var pathlib = requirejs('path') | ||||||
| 	var glob = requirejs('glob') | 	var glob = requirejs('glob') | ||||||
| 	var file = requirejs('./file') | 	var file = requirejs('./file') | ||||||
| 
 |  | ||||||
| 	// XXX this for some reason does not load in nw while require(..)
 |  | ||||||
| 	// 		for some reason works in browser...
 |  | ||||||
| 	//var browseWalk = requirejs('./lib/widget/browse-walk')
 |  | ||||||
| 	var browseWalk = require('lib/widget/browse-walk') |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var data = require('data') | var data = require('data') | ||||||
| @ -34,6 +29,7 @@ var core = require('features/core') | |||||||
| 
 | 
 | ||||||
| var overlay = require('lib/widget/overlay') | var overlay = require('lib/widget/overlay') | ||||||
| var browse = require('lib/widget/browse') | var browse = require('lib/widget/browse') | ||||||
|  | var browseWalk = requirejs('lib/widget/browse-walk') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -567,6 +563,67 @@ var FileSystemWriterActions = actions.Actions({ | |||||||
| 			} | 			} | ||||||
| 		}], | 		}], | ||||||
| 
 | 
 | ||||||
|  | 	//
 | ||||||
|  | 	//	Mark everything changed...
 | ||||||
|  | 	//	.markChanged('all')
 | ||||||
|  | 	//
 | ||||||
|  | 	//	Mark nothing changed...
 | ||||||
|  | 	//	.markChanged('none')
 | ||||||
|  | 	//
 | ||||||
|  | 	//	Mark a section changed...
 | ||||||
|  | 	//	.markChanged('data')
 | ||||||
|  | 	//	.markChanged('tags')
 | ||||||
|  | 	//	.markChanged('selected')
 | ||||||
|  | 	//	.markChanged('bookmarked')
 | ||||||
|  | 	//
 | ||||||
|  | 	//	Mark image changed...
 | ||||||
|  | 	//	.markChanged(<gid>, ...)
 | ||||||
|  | 	//
 | ||||||
|  | 	markChanged: ['- System/', | ||||||
|  | 		function(){ | ||||||
|  | 			var that = this | ||||||
|  | 			var args = util.args2array(arguments) | ||||||
|  | 			//var changes = this.changes = 
 | ||||||
|  | 			var changes =  | ||||||
|  | 				this.hasOwnProperty('changes') ? | ||||||
|  | 					this.changes || {} | ||||||
|  | 					: {} | ||||||
|  | 
 | ||||||
|  | 			// all...
 | ||||||
|  | 			if(args.length == 1 && args[0] == 'all'){ | ||||||
|  | 				// NOTE: this is better than delete as it will shadow 
 | ||||||
|  | 				// 		the parent's changes in case we got cloned from
 | ||||||
|  | 				// 		a live instance...
 | ||||||
|  | 				//delete this.changes
 | ||||||
|  | 				this.changes = null | ||||||
|  | 
 | ||||||
|  | 			// none...
 | ||||||
|  | 			} else if(args.length == 1 && args[0] == 'none'){ | ||||||
|  | 				this.changes = false  | ||||||
|  | 
 | ||||||
|  | 			} else { | ||||||
|  | 				var images = (changes.images || []) | ||||||
|  | 
 | ||||||
|  | 				args.forEach(function(arg){ | ||||||
|  | 					var gid = that.data.getImage(arg) | ||||||
|  | 
 | ||||||
|  | 					// special case: image gid...
 | ||||||
|  | 					if(gid != -1 && gid != null){ | ||||||
|  | 						images.push(gid) | ||||||
|  | 						images = images.unique() | ||||||
|  | 
 | ||||||
|  | 						changes.images = images | ||||||
|  | 						that.changes = changes | ||||||
|  | 
 | ||||||
|  | 					// all other keywords...
 | ||||||
|  | 					} else { | ||||||
|  | 						changes[arg] = true | ||||||
|  | 						that.changes = changes | ||||||
|  | 					} | ||||||
|  | 				}) | ||||||
|  | 			} | ||||||
|  | 		}], | ||||||
|  | 
 | ||||||
| 	// Convert json index to a format compatible with file.writeIndex(..)
 | 	// Convert json index to a format compatible with file.writeIndex(..)
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// This is here so as other features can participate in index
 | 	// This is here so as other features can participate in index
 | ||||||
| @ -761,7 +818,7 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({ | |||||||
| 		['loadIndex', | 		['loadIndex', | ||||||
| 			function(_, path){ | 			function(_, path){ | ||||||
| 				if(path){ | 				if(path){ | ||||||
| 					this.changes = false  | 					this.markChanged('none') | ||||||
| 				} | 				} | ||||||
| 			}], | 			}], | ||||||
| 		['saveIndex', | 		['saveIndex', | ||||||
| @ -769,7 +826,7 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({ | |||||||
| 				// NOTE: if saving to a different path than loaded do not
 | 				// NOTE: if saving to a different path than loaded do not
 | ||||||
| 				// 		drop the .changes flags...
 | 				// 		drop the .changes flags...
 | ||||||
| 				if(path && path == this.location.path){ | 				if(path && path == this.location.path){ | ||||||
| 					this.changes = false  | 					this.markChanged('none') | ||||||
| 				} | 				} | ||||||
| 			}], | 			}], | ||||||
| 
 | 
 | ||||||
| @ -778,13 +835,7 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({ | |||||||
| 			'loadURLs', | 			'loadURLs', | ||||||
| 			'clear', | 			'clear', | ||||||
| 		],  | 		],  | ||||||
| 			function(){ | 			function(){ this.markChanged('all') }], | ||||||
| 				// NOTE: this is better than delete as it will shadow 
 |  | ||||||
| 				// 		the parent's changes in case we got cloned from
 |  | ||||||
| 				// 		a live instance...
 |  | ||||||
| 				//delete this.changes
 |  | ||||||
| 				this.changes = null |  | ||||||
| 			}], |  | ||||||
| 
 | 
 | ||||||
| 		// data...
 | 		// data...
 | ||||||
| 		[[ | 		[[ | ||||||
| @ -810,14 +861,7 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({ | |||||||
| 			'expandGroup', | 			'expandGroup', | ||||||
| 			'collapseGroup', | 			'collapseGroup', | ||||||
| 		],  | 		],  | ||||||
| 			function(_, target){ | 			function(_, target){ this.markChanged('data') }], | ||||||
| 				var changes = this.changes =  |  | ||||||
| 					this.hasOwnProperty('changes') ? |  | ||||||
| 						this.changes || {} |  | ||||||
| 						: {} |  | ||||||
| 
 |  | ||||||
| 				changes.data = true |  | ||||||
| 			}], |  | ||||||
| 
 | 
 | ||||||
| 		// image specific...
 | 		// image specific...
 | ||||||
| 		[[ | 		[[ | ||||||
| @ -826,26 +870,13 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({ | |||||||
| 			'flipHorizontal', | 			'flipHorizontal', | ||||||
| 			'flipVertical', | 			'flipVertical', | ||||||
| 		],  | 		],  | ||||||
| 			function(_, target){ | 			function(_, target){ this.markChanged(target) }], | ||||||
| 				var changes = this.changes =  |  | ||||||
| 					this.hasOwnProperty('changes') ? |  | ||||||
| 						this.changes || {} |  | ||||||
| 						: {} |  | ||||||
| 				var images = changes.images = changes.images || [] |  | ||||||
| 				target = this.data.getImage(target) |  | ||||||
| 
 |  | ||||||
| 				images.push(target) |  | ||||||
| 			}], |  | ||||||
| 
 | 
 | ||||||
| 		// tags and images...
 | 		// tags and images...
 | ||||||
| 		// NOTE: tags are also stored in images...
 | 		// NOTE: tags are also stored in images...
 | ||||||
| 		['tag untag', | 		['tag untag', | ||||||
| 			function(_, tags, gids){ | 			function(_, tags, gids){ | ||||||
| 				var changes = this.changes =  | 				var changes = [] | ||||||
| 					this.hasOwnProperty('changes') ? |  | ||||||
| 						this.changes || {} |  | ||||||
| 						: {} |  | ||||||
| 				var images = changes.images = changes.images || [] |  | ||||||
| 
 | 
 | ||||||
| 				gids = gids || [this.data.getImage()] | 				gids = gids || [this.data.getImage()] | ||||||
| 				gids = gids.constructor !== Array ? [this.data.getImage(gids)] : gids | 				gids = gids.constructor !== Array ? [this.data.getImage(gids)] : gids | ||||||
| @ -854,22 +885,24 @@ module.FileSystemWriter = core.ImageGridFeatures.Feature({ | |||||||
| 				tags = tags.constructor !== Array ? [tags] : tags | 				tags = tags.constructor !== Array ? [tags] : tags | ||||||
| 
 | 
 | ||||||
| 				// images...
 | 				// images...
 | ||||||
| 				changes.images = images.concat(gids).unique() | 				changes = changes.concat(gids) | ||||||
| 
 | 
 | ||||||
| 				// tags...
 | 				// tags...
 | ||||||
| 				if(tags.length > 0){ | 				if(tags.length > 0){ | ||||||
| 					changes.tags = true | 					changes.push('tags') | ||||||
| 
 | 
 | ||||||
| 					// selected...
 | 					// selected...
 | ||||||
| 					if(tags.indexOf('selected') >= 0){ | 					if(tags.indexOf('selected') >= 0){ | ||||||
| 						changes.selected = true | 						changes.push('selected') | ||||||
| 					} | 					} | ||||||
| 
 | 
 | ||||||
| 					// bookmark...
 | 					// bookmark...
 | ||||||
| 					if(tags.indexOf('bookmark') >= 0){ | 					if(tags.indexOf('bookmark') >= 0){ | ||||||
| 						changes.bookmarked = true | 						changes.push('bookmarked') | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
|  | 
 | ||||||
|  | 				this.markChanged.apply(this, changes) | ||||||
| 			}], | 			}], | ||||||
| 	] | 	] | ||||||
| }) | }) | ||||||
|  | |||||||
| @ -82,6 +82,8 @@ core.ImageGridFeatures.Feature('viewer-testing', [ | |||||||
| 	'ui-fs-url-history', | 	'ui-fs-url-history', | ||||||
| 	'ui-fs-writer', | 	'ui-fs-writer', | ||||||
| 
 | 
 | ||||||
|  | 	'exif', | ||||||
|  | 
 | ||||||
| 	'external-editor', | 	'external-editor', | ||||||
| 	'ui-external-editor', | 	'ui-external-editor', | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,16 +4,25 @@ | |||||||
| * | * | ||||||
| **********************************************************************/ | **********************************************************************/ | ||||||
| 
 | 
 | ||||||
| var os = require('os') | if(typeof(process) != 'undefined'){ | ||||||
| var fs = require('fs') | 	var os = require('os') | ||||||
| var path = require('path') | 	var fs = require('fs') | ||||||
| var promise = require('promise') | 	var path = require('path') | ||||||
| var glob = require('glob') | 	var promise = require('promise') | ||||||
| var guaranteeEvents = require('guarantee-events') | 	var glob = require('glob') | ||||||
|  | 	var guaranteeEvents = require('guarantee-events') | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| define(function(require){ var module = {} | define(function(require){ var module = {} | ||||||
| 
 | 
 | ||||||
|  | // XXX HACK...
 | ||||||
|  | // 		...for some reason this gets loaded in browser...
 | ||||||
|  | if(typeof(process) == 'undefined'){ | ||||||
|  | 	return module | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| //var DEBUG = DEBUG != null ? DEBUG : true
 | //var DEBUG = DEBUG != null ? DEBUG : true
 | ||||||
| 
 | 
 | ||||||
| var object = require('../object') | var object = require('../object') | ||||||
|  | |||||||
| @ -35,6 +35,7 @@ var ui = require('features/ui') | |||||||
| var marks = require('features/ui-marks') | var marks = require('features/ui-marks') | ||||||
| var widgets = require('features/ui-widgets') | var widgets = require('features/ui-widgets') | ||||||
| var exteditor = require('features/external-editor') | var exteditor = require('features/external-editor') | ||||||
|  | var exif = require('features/exif') | ||||||
| var meta = require('features/meta') | var meta = require('features/meta') | ||||||
| var experimental = require('features/experimental') | var experimental = require('features/experimental') | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user