/* @@@BUILDINFO@@@ st09GetComp.jsx 466 16-March-2007 */ /************************************************************************* * * ADOBE CONFIDENTIAL * ___________________ * * Copyright 2005 Adobe Systems Incorporated * All Rights Reserved. * * NOTICE: All information contained herein is, and remains * the property of Adobe Systems Incorporated and its suppliers, * if any. The intellectual and technical concepts contained * herein are proprietary to Adobe Systems Incorporated and its * suppliers and may be covered by U.S. and Foreign Patents, * patents in process, and are protected by trade secret or copyright law. * Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained * from Adobe Systems Incorporated. **************************************************************************/ if( ( stockphoto.timeKeeperOn != undefined )&&( stockphoto.timeKeeperOn ) ) { stockphoto.timeKeeper.st09GetComp = {}; stockphoto.timeKeeper.st09GetComp.StTime = new Date(); } // GetComp namespace and zstringCache instance stockphoto.getComp = {}; stockphoto.getComp.zc = new stockphoto.zstringCache("st09GetComp"); stockphoto.getComp.requests = {}; stockphoto.getComp.requestIndex = 0; stockphoto.getComp.CustomName = ""; //stockphoto.getComp.restoreMetadata = function(path, properties) stockphoto.getComp.restoreMetadata = function( doc_id, path, properties ) { properties = eval(properties); var t = undefined; // KR Can't make thumnail if the file doesnt exist.. var dolarLevel = $.level; $.level=0; try { if("undefined" != typeof decodeURI(path)) t = new Thumbnail(decodeURI(path)); } catch(e){} $.level = dolarLevel; if ((t != undefined) && (stockphoto.core.isImageFile(t))) { var m = t.metadata; // No need to fetch synchronousMetadata here... while (properties.length > 0) { var item = properties.pop(); if (item.value.length > 0) { m.namespace = item.namespace; m[item.key] = item.value; } } } if( stockphoto.Burp.doIt ) // in getComp.restoreMetadata { /*B*/ try /*B*/ { // Obtain mediaID /*B*/ stockphoto.Burp.getCompReport( doc_id, path, 0 ); // this path is the "path" /*B*/ } catch(e) { ; } } } stockphoto.getComp.eventHandler = function(event) { var dlCompFolderPath = stockphoto.core.folder.getMyCompFolder(); var dlCompFolder = File(dlCompFolderPath); var thumb; /*B*/ var resultPath=""; stockphoto.core.log.logString(0,event.eventClass + ":" + event.eventName); if (event.eventName == "complete") { var bShowConfDlg = false; stockphoto.core.log.logString(0,event.path); if (event.path != undefined && event.path != "") { /*B*/ resultPath = event.path; var src = new File(event.path); var dst; if (this.destination != undefined) { stockphoto.core.log.logString(0,this.destination.fsName); // KR if (dlCompFolder == this.destination.path) // { //we are copying to the comps folder. Check if copy is already there. this.imgCopied = stockphoto.getComp.OKToCopy(this.destination) if (this.imgCopied) { var pFile1 = File(this.destination); var oCopyCompImages = new stockphoto.core.fileHandle(unescape(src), this.destination.path); // bShowConfDlg = oCopyCompImages.saveFile(pFile1.name, this.customName, this.doNotRenameComp, this.checkBoxState, "comp"); bShowConfDlg = oCopyCompImages.saveFile(pFile1.name, this.customName, this.doNotRenameComp, this.checkBoxState, "comp", this.requestIndex); } /* } else { //save as var pFile1 = File(this.destination); var oCopyCompImages = new stockphoto.core.fileHandle(unescape(src), this.destination.path); // bShowConfDlg = oCopyCompImages.saveFile(pFile1.name, this.customName, this.doNotRenameComp, this.checkBoxState, "comp"); bShowConfDlg = oCopyCompImages.saveFile(pFile1.name, this.customName, this.doNotRenameComp, this.checkBoxState, "comp", this.requestIndex); } */ /*B*/ resultPath = this.destination; if (this.openComp) { // use Thumbnail.open instead of File.execute (Mac bug in ES) if (this.destination.exists) { thumb = new Thumbnail(this.destination); thumb.refresh("metadata"); // Request refresh metadata... if (this.appPath.length > 0) { try { thumb.openWith(this.appPath); } catch( oEx ) { } } else { try { thumb.open(); } catch( oEx ) { } if( stockphoto.gpk3 != undefined ) { stockphoto.gpk3debug.rec = "..openComp[1] "+thumb.path+"\n"; stockphoto.gpk3debug.write2LogFile( stockphoto.gpk3debug.rec ); } } } else { stockphoto.core.log.logString(0, "getComp.eventHandler "+stockphoto.alertBox.localizedStr4ErrMsg.ERROR_CORE_CANT_OPEN_IMAGE_FILE); if (this.reportErr == true) { stockphoto.DL.generalAlertBox(stockphoto.alertBox.localizedStr4ErrMsg.ERROR_CORE_CANT_OPEN_IMAGE_FILE, 2); } } } // if (this.openComp) } // if (this.destination != undefined) var dstFolder = File (this.folderOfThumbToReplace); if (file.exists && dstFolder.exists) //KR - Cannot make Thumbnail of file which doesnt exists { var dstThumbFolder = new Thumbnail(dstFolder); //replace the source thumbnail. if (stockphoto.core.menu.isInFolderHierarchy(dstThumbFolder, stockphoto.places.recentSearches) == true) { var dst = new File(this.folderOfThumbToReplace + "/" + src.name); if (dst.exists) { var dstThumb = new Thumbnail(dst.fsName); var properties = [ ]; var m = dstThumb.metadata; // We don't need synchronous metadata here. if (m != undefined) { var rating; var label; var ns = "http://ns.adobe.com/xap/1.0/"; m.namespace = ns; //m.KindOfImage = "Comp"; // rating = m.Rating; if ((rating != undefined) && (rating.length > 0)) { properties.push({ namespace: ns, key: "Rating", value: rating }); } label = m.Label; if ((label != undefined) && (label.length > 0)) { properties.push({ namespace: ns, key: "Label", value: label }); } delete m; m = undefined; } src.copy(dst); // var refreshed = dstThumb.refresh(); /*B*/ resultPath = dst; var refreshed = dstThumb.refresh(); if (properties.length > 0) { var script = "stockphoto.getComp.restoreMetadata("+(this.doc_id)+",'" + encodeURI(dst.fsName) + "', '" + properties.toSource() + "');"; /*B*/ resultPath = ""; app.scheduleTask(script, 1000, false); } } } // if (stockphoto.core.menu.isInFolderHierarchy(dstThumbFolder, stockphoto.places.recentSearches) == true) } // if (file.exists) if (this.onComplete != undefined) { if (this.fromImgDetail) { this.onComplete.compReceived(event.path, this.imgCopied); var doc_id = app.document.id; stockphoto.getComp.SimpleCopyCompConfirmation(event.path, doc_id, this.onComplete); // wheel off } else { /* if( (stockphoto.core.SaveComp.NONE == stockphoto.core.SaveComp.iDonotSaveTo) || (stockphoto.core.SaveComp.DEFAULT_FOLDER == stockphoto.core.SaveComp.iDonotSaveTo) )// Give This Confirmation only if saving to the UF {*/ this.onComplete.compReceived(event.path, this.imgCopied); /*} else if(stockphoto.core.SaveComp.USER_DEFINED_FOLDER == stockphoto.core.SaveComp.iDonotSaveTo) { var sMsg = "$$$/AlertBox/IMAGES_SAVED_IN_DEFAULT=Some images are saved in the Default Folder."; stockphoto.alertBox.alertBox(zc.get(sMsg)); }*/ } } // if (this.onComplete != undefined) src.remove(); stockphoto.impl.deleteGetComp(this.sourcePath); } // if (event.path != undefined && event.path != "") if( stockphoto.Burp.doIt ) // in getComp.GetAndCopyComp_Body { /*B*/ try /*B*/ { // Obtain mediaID /*B*/ if( resultPath != "" ) /*B*/ stockphoto.Burp.getCompReport( this.doc_id, File( resultPath ).fsName, 0 ) /*B*/ } catch(e) { ; } } return true; } if ((event.eventName == "status") && (event.status == "error")) { var some = stockphoto.impl.deleteGetComp(this.sourcePath) if (this.onComplete != undefined) { this.onComplete.compReceived(event.path, this.imgCopied); } stockphoto.core.log.logString(0, "getComp.eventHandler " + event.message); if ("undefined" != typeof(this.requestIndex) && -1 != this.requestIndex && "undefined" != typeof(stockphoto.getComp.requests) && "undefined" != typeof(stockphoto.getComp.requests[this.requestIndex]) && "undefined" != typeof(stockphoto.getComp.requests[this.requestIndex].ErrorDialogShown) && false == stockphoto.getComp.requests[this.requestIndex].ErrorDialogShown ) { if (this.reportErr == true) { stockphoto.DL.alertBox(event.message ); } if ("undefined" != typeof(this.destination)) { stockphoto.core.checkProxyOnFail(); } stockphoto.getComp.requests[this.requestIndex].ErrorDialogShown = true; stockphoto.DL.NavBar.SpiningWheelOff( app.document.id ); } return false; } return false; } stockphoto.getComp.GetComp_Body = function(thumbPathIn, dest, openIt, onComplete, reportErr, appPath, fromImgDetail, cName, renameFlag, cState, reqIndex) { // Workaround for Bridge 316 -BEGIN- var thumbPath = stockphoto.core.util.fixPathName( thumbPathIn ); // Workaround for Bridge 316 -END- stockphoto.core.log.logString(0,"GetComp_Body"); // Get thumbnail file path // // Get comp base name - same as thumbnail base name var baseCompName = stockphoto.core.util.getBaseName(thumbPath); var thumb, svLevel=$.level; $.level = 0; try { thumb = new Thumbnail(File(thumbPath)); } catch(e) { thumb = undefined; var strMessage = ""; if(stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_AlertBox )) { strMessage = stockphoto.alertBox.zc.get(stockphoto.alertBox.localizedStr4ErrMsg.ERROR_CORE_CANT_OPEN_IMAGE_FILE); } stockphoto.DL.generalAlertBox(strMessage, 2); if (onComplete != undefined) { onComplete.compReceived(undefined, false); } return; } $.level = svLevel; var folderOfThumbToReplace = Folder(thumb.spec.path); var tempFolder = new Folder( stockphoto.core.folder.getTempFolder()+"/"+stockphoto.core.CurrentProcessID ); var file= File(thumbPath); if( stockphoto.gpk3 != undefined ) { stockphoto.gpk3debug.rec = "GetComp_Body: "+baseCompName+" / openComp="+openIt+", fromImageDetail="+fromImgDetail+"\n dest="+dest+"\n"; stockphoto.gpk3debug.write2LogFile( stockphoto.gpk3debug.rec ); } if ( !stockphoto.core.folder.checkAndCreateFolder( tempFolder, false ) ) { stockphoto.core.log.logString( 0, " Can not create temp folder : " + tempFolder.fsName); stockphoto.DL.generalAlertBox(stockphoto.alertBox.localizedStr4ErrMsg.ERROR_CORE_CANT_CREATE_DIR, 2); if (onComplete != undefined) { onComplete.compReceived(undefined, false); } return; } var params = { BillingCountry: "" }; //Compose the Getcomp Argument stockphoto.core.util.addStockPhotoMetadata(thumb, params); var getCompReq = { params: params, sourcePath: file, //full path of img file. appPath: appPath, // path to app that will open comp, "": use default folder: tempFolder, //temp folder of where to initialize D/L comp folderOfThumbToReplace: folderOfThumbToReplace, baseName: baseCompName, eventHandler: stockphoto.getComp.eventHandler, destination: dest, //make a copy to elsewhere like for keep comp. openComp : openIt, onComplete: onComplete, reportErr: reportErr, imgCopied: true, // fromImgDetail: fromImgDetail fromImgDetail: fromImgDetail, doc_id: app.document.id, customName: cName, doNotRenameComp: renameFlag, checkBoxState: cState, requestIndex: reqIndex }; var prev = stockphoto.impl.getComp(getCompReq); if (prev != undefined) { prev.onComplete = onComplete; // getComp() already queued for this image stockphoto.core.log.logString(0,"Duplicate getComp() request: \"" + file.fsName + "\""); } return prev; } stockphoto.getComp.GetMediaTitle = function( thumbPath, tryCnt ) { var xmp = stockphoto.core.util.GetXMPObj(thumbPath); if( (xmp!=undefined)&&(xmp.KindOfImage!=undefined)&&(xmp.KindOfImage != "") ) { var obj = xmp.Media; for( k in obj ) { if( k.indexOf("Media/bmsp:MediaTitle") >= 0 ) { return( File.decode( escape( obj[ k ] ) ) ); } } } // if( (xmp.KindOfImage != "Thumbnail")&&(xmp.KindOfImage != "") ) if( tryCnt > 10 ) { var altNm = stockphoto.core.util.getBaseName( thumbPath ); return( altNm ); } return undefined; } stockphoto.getComp.OKToCopy = function (destFile) { var destPath = destFile.path; var destFolder = Folder(destPath); var dirContents = new Array; var zc = stockphoto.getComp.zc; var messageString; var removeFile; var result = true; var dlCompFolderPath = stockphoto.core.folder.getMyCompFolder(); var destFilename = File.decode(destFile.name); if(stockphoto.core.SaveComp.BOTH_LOCATIONS == stockphoto.core.SaveComp.iDonotSaveTo) { result = false; } // KR - Case user Folde is readonly. if ( (stockphoto.core.SaveComp.USER_DEFINED_FOLDER != stockphoto.core.SaveComp.iDonotSaveTo) && (stockphoto.core.SaveComp.BOTH_LOCATIONS != stockphoto.core.SaveComp.iDonotSaveTo) && (stockphoto.core.folder.isReadOnly(stockphoto.core.GetOrigCurrentCompFolder())) ) { if(stockphoto.core.SaveComp.CheckBoxState) { stockphoto.core.util.alertReadOnlyFolderExtraMsg(stockphoto.core.GetOrigCurrentCompFolder(), "$$$/AlertBox/ERROR_ATTEMPTING_IN_DEFAULT=Attempting download in default folder."); } else { stockphoto.core.util.alertReadOnlyFolderExtraMsg(stockphoto.core.GetOrigCurrentCompFolder()); result = false; } stockphoto.core.SaveComp.iDonotSaveTo = stockphoto.core.SaveComp.USER_DEFINED_FOLDER; // stockphoto.core.util.alertReadOnlyFolder(dlCompFolderPath); // return false; // Kr Attemp save in default folder only. (set a core variable to DEFAULT_ONLY } if( (stockphoto.core.SaveComp.DEFAULT_FOLDER != stockphoto.core.SaveComp.iDonotSaveTo) && (stockphoto.core.SaveComp.BOTH_LOCATIONS != stockphoto.core.SaveComp.iDonotSaveTo) && stockphoto.core.folder.isReadOnly(dlCompFolderPath) && stockphoto.core.SaveComp.CheckBoxState) { stockphoto.core.util.alertReadOnlyFolder(dlCompFolderPath); if(stockphoto.core.SaveComp.USER_DEFINED_FOLDER == stockphoto.core.SaveComp.iDonotSaveTo) { stockphoto.core.SaveComp.iDonotSaveTo = stockphoto.core.SaveComp.BOTH_LOCATIONS; result = false; } else { stockphoto.core.SaveComp.iDonotSaveTo = stockphoto.core.SaveComp.DEFAULT_FOLDER; // KR Do we really need this. } } /* KR TODO Will not give any such pop-up message dirContents = destFolder.getFiles(destFilename); if (dirContents[0] == undefined) { result = true; } else { messageString = zc.get1Arg("$$$/AlertDialog/Dialog/ConfirmFileDelete=Do you want to overwrite %1 in the Downloaded Comps folder? Clicking No will cancel the download.", destFilename); removeFile = stockphoto.DL.alertDialog(undefined, 0, 2, messageString); if (removeFile == 1) { destFile.remove(); result = true; } } */ return (result); } //SA: This would be needed in case of an error scenario, when a comp is getting downloaded. stockphoto.getComp.TurnOffGPK = function(isImageDetails) { if (isImageDetails) { if (( stockphoto.gpk3 != undefined ) && (stockphoto.gpk3.gpk3Sys[ app.document.id ] != undefined)) stockphoto.gpk3.KWSpiningWheel( app.document.id, false /* turmimg OFF */, true /* not to schedule */, stockphoto.gpk3.KWSpiningWheel_unknown /* OFF */ ); } //TODO: Display an appropriate error message. } //Keep comp is only for Search folder. //stockphoto.getComp.GetAndCopyComp_Body = function(thumbPath, onCompleteConfirm, isImageDetails, reportErr) stockphoto.getComp.GetAndCopyComp_Body = function( thumbPathIn, onCompleteConfirm, isImageDetails, reportErr, reqIndex ) { if("undefined" == typeof thumbPathIn) { return false; } if("undefined" != typeof(reqIndex) && reqIndex >=0 && "undefined" != typeof(stockphoto.getComp) && "undefined" != typeof(stockphoto.getComp.requests) && "undefined" != stockphoto.getComp.requests[reqIndex] && "undefined" != stockphoto.getComp.requests[reqIndex].bIsCanceled ) { if(true == stockphoto.getComp.requests[reqIndex].bIsCanceled) { // we just return as its not the first comp in cancel batch return false; } } //GP:let's fire comp download first and let it get saved in the previous searches folder //makes sense to do it for first comp only since it for the rest we don't get the advantage of save as dialog time lag. if(0 == stockphoto.core.SaveComp.MultipleImage ) { stockphoto.core.SendProxyCredentials(); stockphoto.getComp.GetComp_Body( thumbPathIn, undefined, undefined, undefined ,false, "", false, undefined, 0, true, -1); } if (reqIndex < 0) { stockphoto.core.SaveComp.numOfImagesSelected = 1; } // Workaround for Bridge 316 -BEGIN- var thumbPath = stockphoto.core.util.fixPathName( thumbPathIn ); // Workaround for Bridge 316 -END- stockphoto.core.log.logString(0,"GetAndCopyComp_Body"); // Get thumbnail file path var copyDone = true; var file = File(thumbPath); var thumb = undefined; if(file.exists) { thumb = new Thumbnail(file); } var extension = stockphoto.core.util.getExtension(thumbPath); //SA:Change for Save As //TODO: Need to determine why we are using File instead of thumb now. stockphoto.core.SaveComp.MediaType = 0; var oFolderPath; var normalizeName = stockphoto.core.util.normalizeFileName(file.name); normalizeName = stockphoto.core.getKeepCompFilename(normalizeName, extension, file); var dlCompFolderPath = stockphoto.core.GetOrigCurrentCompFolder(); if (extension == "") { normalizeName = normalizeName + ".jpg"; } else if (extension.toLowerCase() != "jpg") //Ensure the file in the comps folder has .jpg as extension no matter what the source is. { var fileBaseNameIdx = normalizeName.lastIndexOf("."); normalizeName = normalizeName.slice(0, fileBaseNameIdx+1) + "jpg"; } //SA: changes for Save As var oTempObject = ""; var oDialogResult = 1; //This could have been a boolean value, but we are taking it as an int considering that in future we might need to send the number of images if(0 == stockphoto.core.SaveComp.MultipleImage ) { if("" == stockphoto.core.SaveComp.AdobeIdList) { stockphoto.core.SaveComp.AdobeIdList = '"' + normalizeName + '"' ; } // KR - If the current comp folder donot have permissions then display default comp folder. // If default comp too donot have permissions then OS will point to desktop be default. if(stockphoto.core.folder.isReadOnly(stockphoto.core.GetCurrentCompFolder())) { stockphoto.core.SetCurrentCompFolder(stockphoto.core.folder.getMyCompFolder()); } var oFolderRequest = { bDoNotRenameFlag : true, bSaveCopyFlag : stockphoto.core.SaveComp.CheckBoxState, bAddToFavoriteFlag : stockphoto.core.SaveComp.AddToFavoriteFolderStateComp, sImageName : unescape(stockphoto.core.SaveComp.AdobeIdList), sImagePath : stockphoto.core.GetCurrentCompFolder(), iImageTypeFlag : stockphoto.core.SaveComp.MediaType, iSingleOrMultipleFlag : stockphoto.core.SaveComp.MultipleImage, sDefaultFolderPath : stockphoto.core.folder.getMyCompFolder() }; stockphoto.core.SaveComp.iDonotSaveTo = stockphoto.core.SaveComp.NONE; stockphoto.core.SaveComp.aImagesSavedComp = []; if( "undefined" != typeof(app.preferences) && undefined != app.preferences.bm_SaveCopyFlag ) { oFolderRequest.bSaveCopyFlag = app.preferences.bm_SaveCopyFlag; } // Watson : 1370007 else { oFolderRequest.bSaveCopyFlag = true; app.preferences.bm_SaveCopyFlag = true; } if (undefined == stockphoto.bIsVCInitialized ) { stockphoto.core.init.loadVC(); } var aFolderArray; if (true == stockphoto.bIsVCInitialized ) { aFolderArray = stockphoto.impl.openSaveAsDialog(oFolderRequest); } else { aFolderArray = []; aFolderArray[0]= "0"; aFolderArray[1] = "1"; aFolderArray[2] = "0"; aFolderArray[3] = ""; aFolderArray[4] = stockphoto.core.GetOrigCurrentCompFolder(); aFolderArray[5] = "0"; } if( ("undefined" != typeof aFolderArray) && ( 6 == aFolderArray.length)) { stockphoto.core.SaveComp.oDialogResult = stockphoto.core.util.convertToInteger(aFolderArray[5]); if(1 == stockphoto.core.SaveComp.oDialogResult) { if(reqIndex >= 0 ) { stockphoto.getComp.requests[reqIndex].bIsCanceled =true; } stockphoto.core.SaveComp.MultipleImage =0 ; stockphoto.core.SaveComp.AdobeIdList =""; stockphoto.getComp.TurnOffGPK(isImageDetails); // Watson: 1362366 return false; } stockphoto.core.SaveComp.DoNotRenameComp = stockphoto.core.util.convertToInteger(aFolderArray[0]); stockphoto.core.SaveComp.CheckBoxState = stockphoto.core.util.convertToBoolean(aFolderArray[1]); app.preferences.bm_SaveCopyFlag = stockphoto.core.SaveComp.CheckBoxState; stockphoto.core.SaveComp.AddToFavoriteFolderStateComp = stockphoto.core.util.convertToBoolean(aFolderArray[2]); stockphoto.getComp.CustomName = aFolderArray[3]; oFolderPath = aFolderArray[4]; if("" != oFolderPath) { dlCompFolderPath=oFolderPath; } if (reqIndex >= 0) { stockphoto.getComp.requests[reqIndex].CustomName = stockphoto.getComp.CustomName; stockphoto.getComp.requests[reqIndex].DoNotRenameComp = stockphoto.core.SaveComp.DoNotRenameComp; stockphoto.getComp.requests[reqIndex].CheckBoxState = stockphoto.core.SaveComp.CheckBoxState; stockphoto.getComp.requests[reqIndex].DownloadFolder = dlCompFolderPath; } } else { stockphoto.core.SaveComp.MultipleImage =0 ; stockphoto.core.SaveComp.AdobeIdList =""; stockphoto.getComp.TurnOffGPK(isImageDetails); // Watson: 1362366 return false; } } else { if( 0 < stockphoto.core.SaveComp.MultipleImage && 1 == stockphoto.core.SaveComp.oDialogResult ) { stockphoto.core.SaveComp.MultipleImage =0 ; //No need of resetting it again as this variable is getting reset when used clicks "cancel" on SaveAs dialog box //stockphoto.core.SaveComp.AdobeIdList =""; stockphoto.getComp.TurnOffGPK(isImageDetails); // Watson: 1362366 return false; } } stockphoto.core.SaveComp.MultipleImage =0 ; stockphoto.core.SetCurrentCompFolder(dlCompFolderPath); stockphoto.core.SaveComp.AdobeIdList =""; //Save As change ends var destFile; if (reqIndex >= 0) { destFile = File(stockphoto.getComp.requests[reqIndex].DownloadFolder + "/" + normalizeName); } else { destFile = File(dlCompFolderPath + "/" + normalizeName); } var aComp = false; var inSrchFldr = false; var inCompFldr = false; if(thumb != undefined) { aComp = stockphoto.core.util.isBMCompImage(thumb); inSrchFldr = stockphoto.core.menu.isInFolderHierarchy(thumb, stockphoto.places.recentSearches); inCompFldr = stockphoto.core.menu.isInFolderHierarchy(thumb, stockphoto.places.comps); } var getNewComp = false; if ( (!file.exists) || //remote version cue file. Always want a new comp. (aComp && (!inSrchFldr && !inCompFldr) ) || //a comp && not in Search folder or Comp folder (!aComp) || //if not a comp (ie thumb or purchase Image). (extension.toLowerCase() != "jpg") //a psd file. ) { getNewComp = true; //will call C code to get a new copy of the comp. } if (!getNewComp) //just use the copy we have and copy to Download comps folder. { var src = file; var imgCopied = true; var isSameFile = false; //make sure we are not overwritting ourselves in the Comps folder. if (src.path == destFile.path) { if (src.name == destFile.name) { isSameFile = true; } } if (! isSameFile) { //SA: Change Save As KR checking for both the folders for confirmation Dlg // if(destFile.path == stockphoto.core.folder.getMyCompFolder()) // { imgCopied = stockphoto.getComp.OKToCopy(destFile); /* } else { imgCopied = true; } */ //Change Ends if (imgCopied) { if (src.exists) { var oCopyCompImages; if (reqIndex >= 0) { oCopyCompImages = new stockphoto.core.fileHandle(src, stockphoto.getComp.requests[reqIndex].DownloadFolder); } else { oCopyCompImages = new stockphoto.core.fileHandle(src, stockphoto.core.GetOrigCurrentCompFolder()); } if (reqIndex >= 0) { copyDone = oCopyCompImages.saveFile(destFile.name, stockphoto.getComp.requests[reqIndex].CustomName, stockphoto.getComp.requests[reqIndex].DoNotRenameComp , stockphoto.getComp.requests[reqIndex].CheckBoxState, "comp", reqIndex); } else { copyDone = oCopyCompImages.saveFile(destFile.name, stockphoto.getComp.CustomName, stockphoto.core.SaveComp.DoNotRenameComp, stockphoto.core.SaveComp.CheckBoxState, "comp", reqIndex); } if (copyDone && isImageDetails) // KR Test { stockphoto.getComp.SimpleCopyCompConfirmation(thumbPath, app.document.id, onCompleteConfirm); // wheel off } } else { imgCopied=false; stockphoto.DL.generalAlertBox(stockphoto.alertBox.localizedStr4ErrMsg.ERROR_CORE_CANT_COPY_MOVE_DELETE_FILE, 2); } } else // Case not copying the Comp. { // Watson 1251473 stockphoto.DL.NavBar.SpiningWheelOff( app.document.id ); // Watson 1251473 copyDone = false; if (isImageDetails) { if (( stockphoto.gpk3 != undefined ) && (stockphoto.gpk3.gpk3Sys[ app.document.id ] != undefined)) stockphoto.gpk3.KWSpiningWheel( app.document.id, false /* turmimg OFF */, true /* not to schedule */, stockphoto.gpk3.KWSpiningWheel_unknown /* OFF */ ); } } } if( stockphoto.Burp.doIt ) // GetAndCopyComp_Body { /*B*/ try /*B*/ { // GetAndCopyComp_Body /*B*/ if( ( stockphoto.Burp.getCompSource[ app.document.id ] == "rtclk" )|| /*B*/ ( stockphoto.Burp.getCompSource[ app.document.id ] == "gpk" )|| /*B*/ ( stockphoto.Burp.getCompSource[ app.document.id ] == "btn" ) ) /*B*/ stockphoto.Burp.getCompReport( app.document.id, File( destFile ).fsName, 0 ); /*B*/ } catch(e) { ; } } if (onCompleteConfirm != undefined) { /* if( (stockphoto.core.SaveComp.NONE == stockphoto.core.SaveComp.iDonotSaveTo) || (stockphoto.core.SaveComp.DEFAULT_FOLDER == stockphoto.core.SaveComp.iDonotSaveTo) )// Give This Confirmation only if saving to the UF {*/ onCompleteConfirm.compReceived(destFile, imgCopied); /*} else if(stockphoto.core.SaveComp.USER_DEFINED_FOLDER == stockphoto.core.SaveComp.iDonotSaveTo) { var sMsg = "$$$/AlertBox/IMAGES_SAVED_IN_DEFAULT=Some images are saved in the Default Folder."; stockphoto.alertBox.alertBox(zc.get(sMsg)); }*/ } } else // { { // GetAndCopyComp_Body - burp done if (stockphoto.getComp.OKToCopy(destFile)) { var prev; if (reqIndex >= 0) { prev = stockphoto.getComp.GetComp_Body(thumbPath, destFile, false, onCompleteConfirm, reportErr, "", isImageDetails, stockphoto.getComp.requests[reqIndex].CustomName, stockphoto.getComp.requests[reqIndex].DoNotRenameComp , stockphoto.getComp.requests[reqIndex].CheckBoxState, reqIndex); } else { prev = stockphoto.getComp.GetComp_Body(thumbPath, destFile, false, onCompleteConfirm, reportErr, "", isImageDetails, stockphoto.getComp.CustomName, stockphoto.core.SaveComp.DoNotRenameComp, stockphoto.core.SaveComp.CheckBoxState, -1); } if (prev != undefined) { prev.destination = destFile; if (reqIndex >= 0) { prev.customName = stockphoto.getComp.requests[reqIndex].CustomName; prev.doNotRenameComp = stockphoto.getComp.requests[reqIndex].DoNotRenameComp; prev.checkBoxState = stockphoto.getComp.requests[reqIndex].CheckBoxState; prev.requestIndex = reqIndex; prev.reportErr = true; } else { prev.customName = stockphoto.getComp.CustomName; prev.doNotRenameComp = stockphoto.core.SaveComp.DoNotRenameComp; prev.checkBoxState = stockphoto.core.SaveComp.CheckBoxState; prev.requestIndex = -1; prev.reportErr = true; } } } else { copyDone = false; } if (( stockphoto.gpk3 != undefined ) && (stockphoto.gpk3.gpk3Sys[ app.document.id ] != undefined)) stockphoto.gpk3.KWSpiningWheel( app.document.id, false /* turmimg OFF */, true /* not to schedule */, stockphoto.gpk3.KWSpiningWheel_unknown /* OFF */ ); } return copyDone; } stockphoto.getComp.GetAndOpenComp_Body = function(thumbPathIn, appPath) { // Workaround for Bridge 316 -BEGIN- var thumbPath = stockphoto.core.util.fixPathName( thumbPathIn ); // Workaround for Bridge 316 -END- stockphoto.core.log.logString(0,"GetAndOpenComp_Body"); // Get thumbnail file path var file = File( thumbPath ); if( ! file.exists ) return; //this is a version cue file. Let Bridge handle it. var normalizeName = stockphoto.core.util.normalizeFileName( file.name ); var dlCompFolderPath = (("" != file.path) && !(stockphoto.core.menu.isInFolderHierarchy(new Thumbnail(file), stockphoto.places.recentSearches))) ? file.path : stockphoto.core.folder.getMyCompFolder(); var extension = stockphoto.core.util.getExtension( thumbPath ); var destFilePath = dlCompFolderPath + "/" + normalizeName; if ("" == extension ) { destFilePath += ".jpg"; } else if ( "jpg" != extension.toLowerCase() ) { return; //if this is a psd file, let Bridge Handle it. } destFile = File( destFilePath ); var thumb = new Thumbnail(File(thumbPath)); var bUseSyncMode = false; // Check if we need to use synchronousMode to get the correct type... if (('file' != thumb.type) && ('alias' != thumb.type)) { thumb.refresh("item"); // Request refresh of 'item' properties like 'type' for future use bUseSyncMode = true; } var aComp, bDoCopy; // Need to use app.synchronousMode = true (See suggestion from Rob - bug# 1469239) var prevAppMode = app.synchronousMode, bNeedToReset = false; if ((true == bUseSyncMode) && (false == prevAppMode)) { app.synchronousMode = true; bNeedToReset = true; } aComp = stockphoto.core.util.isBMCompImage(thumb) if (true == bNeedToReset) { app.synchronousMode = prevAppMode; } if( aComp ) { // Fixing the double byte case var bItIsSameFile=false; if( ( file.exists )&&( destFile.exists ) ) { var thumbnail_1, thumbnail_2; try { thumbnail_1 = new Thumbnail( file ); } catch(e) { thumbnail_1 = undefined; } if( thumbnail_1 != undefined ) { try { thumbnail_2 = new Thumbnail( destFile ); } catch(e) { thumbnail_2 = undefined; } if( thumbnail_2 != undefined ) { // if( thumbnail_1.displayPath == thumbnail_2.displayPath ) var tmpDispPath1 = stockphoto.core.util.getDisplayPath( thumbnail_1, "GetAndOpenComp_Body()-1" ); var tmpDispPath2 = stockphoto.core.util.getDisplayPath( thumbnail_2, "GetAndOpenComp_Body()-2" ); if( stockphoto.core.util.isDisplayPathEqual( tmpDispPath1, tmpDispPath2 ) ) bItIsSameFile = true; delete thumbnail_2; } delete thumbnail_1; } } // make sure user is not opening file from savedComp folder, // then copy file to savedComp folder before opening it. if( ( bItIsSameFile )||( ( file.path == destFile.path )&&( file.name == destFile.name ) ) ) { ; // Same file -> we do not have to copy } else { bDoCopy = true; if( destFile.exists ) { bDoCopy = stockphoto.getComp.OKToCopy(destFile); } if( bDoCopy ) { file.copy( destFilePath ); } } destFile = File( destFilePath ); // re-do // use Thumbnail.open instead of File.execute (Mac bug in ES) if( destFile.exists ) { thumb = new Thumbnail(destFile); if (appPath.length > 0) { try { thumb.openWith(appPath); } catch( oEx ) { } } else { try { thumb.open(); } catch( oEx ) { } if( stockphoto.gpk3 != undefined ) { stockphoto.gpk3debug.rec = "..openComp[2] "+thumb.path+"\n"; stockphoto.gpk3debug.write2LogFile( stockphoto.gpk3debug.rec ); } } } else { stockphoto.DL.generalAlertBox(stockphoto.alertBox.localizedStr4ErrMsg.ERROR_CORE_CANT_OPEN_IMAGE_FILE, 2); } } else { var prev = stockphoto.getComp.GetComp_Body(thumbPath, destFile, true, undefined, false, appPath, false, undefined, 0, true, -1); if (prev != undefined) { prev.appPath = appPath; prev.destination = destFile; prev.openComp = true; prev.doNotRenameComp = 0; prev.checkBoxState = true; prev.requestIndex = -1; prev.reportErr = true; } } } stockphoto.getComp.SimpleCopyCompConfirmation=function(thumbPath, doc_id, onComplete) { var imageCount = 1; var imageName = undefined; if (thumbPath != undefined) { imageName = stockphoto.getComp.GetMediaTitle(thumbPath, 1000); } stockphoto.DL.NavBar.SpiningWheelOff( doc_id ); // KR Changes for proper confirmation if("undefined" != stockphoto.core.SaveComp.aImagesSavedComp && 1 == stockphoto.core.SaveComp.aImagesSavedComp.length) { stockphoto.DL.confirmationBox(1, stockphoto.core.SaveComp.aImagesSavedComp.length, imageName, onComplete, undefined, undefined, doc_id); } else if(stockphoto.core.SaveComp.USER_DEFINED_FOLDER == stockphoto.core.SaveComp.iDonotSaveTo && stockphoto.core.SaveComp.CheckBoxState) { // Case if some images are saved to default folder but none to userfolder. var sMsg = zc.get("$$$/AlertBox/IMAGES_SAVED_IN_DEFAULT=Some images are saved in the Default Folder."); var dlgSaveAsError = new Window('dialog', zc.get("$$$/AlertBox/Dialog/Title=Adobe Stock Photos"), undefined, { resizable: true, orientation: "row" } ); dlgSaveAsError.add('statictext', { x: 100, y: 100, width: 450, height: 43}, sMsg, {multiline:true} ); dlgSaveAsError.okBtn = dlgSaveAsError.add( 'button', undefined, zc.get("$$$/ConfirmationBox/Dialog/Btn/OK/Text=OK")); dlgSaveAsError.okBtn.onClick = function() { this.parent.close(); } dlgSaveAsError.center(); dlgSaveAsError.show(); } //KR Changes End // stockphoto.DL.confirmationBox(1, imageCount, imageName, onComplete, undefined, undefined, doc_id); stockphoto.core.SaveComp.aImagesSavedComp = []; } stockphoto.getComp.CopyCompConfirmation = function(index, reqIndex) { var showAlert = true; var imageName = undefined; var doc_id = stockphoto.getComp.requests[reqIndex].doc_id; var imageCount = stockphoto.getComp.requests[reqIndex].count; var tryCnt=0; if (imageCount == 1) { while (imageName == undefined) { var thumbPath = stockphoto.getComp.requests[reqIndex].list[index].path; if (thumbPath != undefined) { imageName = stockphoto.getComp.GetMediaTitle(thumbPath, (tryCnt++)); } } } else { // only show confirmation alert comp received or comp error occurred var i; for (i = 0; i < imageCount; i++) { if ((stockphoto.getComp.requests[reqIndex].list[i].compRecvSw != true) && (stockphoto.getComp.requests[reqIndex].list[i].error != true)) { showAlert = false; } } } if (showAlert) { // Get the number of comps that are really copied. imageCount = stockphoto.getComp.requests[reqIndex].countCopied; stockphoto.DL.NavBar.SpiningWheelOff( doc_id ); // KR Changes for proper confirmation if("undefined" != stockphoto.core.SaveComp.aImagesSavedComp && stockphoto.core.SaveComp.aImagesSavedComp.length > 0) { stockphoto.DL.confirmationBox(1, imageCount, imageName, undefined, undefined, undefined,doc_id, reqIndex); } else if(stockphoto.core.SaveComp.USER_DEFINED_FOLDER == stockphoto.core.SaveComp.iDonotSaveTo && stockphoto.core.SaveComp.CheckBoxState) { // Case if some images are saved to default folder but none to userfolder. var sMsg = zc.get("$$$/AlertBox/IMAGES_SAVED_IN_DEFAULT=Some images are saved in the Default Folder."); var dlgSaveAsError = new Window('dialog', zc.get("$$$/AlertBox/Dialog/Title=Adobe Stock Photos"), undefined, { resizable: true, orientation: "row" } ); dlgSaveAsError.add('statictext', { x: 100, y: 100, width: 450, height: 43}, sMsg, {multiline:true} ); dlgSaveAsError.okBtn = dlgSaveAsError.add( 'button', undefined, zc.get("$$$/ConfirmationBox/Dialog/Btn/OK/Text=OK")); dlgSaveAsError.okBtn.onClick = function() { this.parent.close(); } dlgSaveAsError.center(); dlgSaveAsError.show(); } // stockphoto.DL.confirmationBox(1,imageCount,imageName, undefined, undefined, undefined,doc_id); stockphoto.core.SaveComp.aImagesSavedComp = []; } } stockphoto.getComp.KeepComp_SaveEach=function( i, reqIndex ) { if( stockphoto.getComp.requests[reqIndex].doc_id == undefined ) { stockphoto.core.log.logString( 0, "[getComp.KeepComp_Body: SaveEach] doc_id undefined." ); stockphoto.getComp.requests[reqIndex].doc_id = app.document.id; } var copyDone = stockphoto.getComp.GetAndCopyComp_Body( stockphoto.getComp.requests[reqIndex].list[i].path , stockphoto.getComp.requests[reqIndex].list[i], false, true, reqIndex); if (!copyDone) { // Watson: 1362366 stockphoto.DL.NavBar.SpiningWheelOff( stockphoto.getComp.requests[reqIndex].doc_id ); stockphoto.getComp.requests[reqIndex].countCopied--; } } stockphoto.getComp.KeepComp_InitRequestListItem=function( i, reqIndex ) { var cmdStr; cmdStr = "stockphoto.getComp.requests["+reqIndex+"].list["+i+"].compRecvSw = false;"; eval( cmdStr ); cmdStr = "stockphoto.getComp.requests["+reqIndex+"].list["+i+"].error = false;"; eval( cmdStr ); cmdStr = "stockphoto.getComp.requests["+reqIndex+"].list["+i; cmdStr += "].compReceived = function(thumb, imgCopied) { if (thumb == undefined || thumb == '')\n"; cmdStr += "stockphoto.getComp.requests["+reqIndex+"].list["+i+"].error = true;\n"; cmdStr += "else { stockphoto.getComp.requests["+reqIndex+"].list["+i+"].compRecvSw = true;\n"; cmdStr += "if (imgCopied) {stockphoto.getComp.CopyCompConfirmation("+i+", "+reqIndex+");}; }; };"; eval( cmdStr ); //SA: Change Save As Multiple Images stockphoto.core.SaveComp.MultipleImage=i; //Change Ends stockphoto.getComp.KeepComp_SaveEach( i, reqIndex ); } stockphoto.getComp.KeepComp_Iterate_Loop=function( doc_id, i, iMax, reqIndex, SelID ) { var i1; if( stockphoto.getComp.requests[ reqIndex ].SelectionID == SelID ) { stockphoto.getComp.KeepComp_InitRequestListItem( i, reqIndex ); i1 = i + 1; if( i1 < iMax ) { app.scheduleTask( "stockphoto.getComp.KeepComp_Iterate_Loop("+doc_id+","+i1+","+iMax+","+reqIndex+","+SelID+");", 100, false ); } } } stockphoto.getComp.KeepComp_Iterate=function( doc_id, i, iMax, reqIndex, SelID ) { if( stockphoto.NavIntDt_t[ doc_id ].SelectionID == SelID ) { var count = 0; var imgCount = 0; for (count = 0; count < iMax; count++) { if (stockphoto.core.util.isBMImageFile(new Thumbnail(stockphoto.NavIntDt_t[ doc_id ].Selections.SelPath[ count ]))) { stockphoto.getComp.requests[ reqIndex ].list[ imgCount ].path = stockphoto.NavIntDt_t[ doc_id ].Selections.SelPath[ count ]; imgCount++; } } stockphoto.getComp.requests[ reqIndex ].SelectionID = SelID; stockphoto.getComp.requests[ reqIndex ].SavedFileNames = []; stockphoto.getComp.requests[ reqIndex ].SavedFileCounter = 0; stockphoto.getComp.requests[ reqIndex ].count = imgCount; stockphoto.getComp.requests[reqIndex].countCopied = imgCount; app.scheduleTask( "stockphoto.getComp.KeepComp_Iterate_Loop("+doc_id+","+i+","+imgCount+","+reqIndex+","+SelID+");", 100, false ); delete stockphoto.NavIntDt_t[ doc_id ].Selections; stockphoto.NavIntDt_t[ doc_id ].Selections = undefined; } } stockphoto.getComp.KeepComp_Body=function( doc_id ) { this.InitRequestItem=function( doc_id, selectionCount ) { var reqIndex = stockphoto.getComp.requestIndex; stockphoto.getComp.requests[reqIndex] = {}; stockphoto.getComp.requests[reqIndex].count = selectionCount; stockphoto.getComp.requests[reqIndex].countCopied = selectionCount; stockphoto.getComp.requests[reqIndex].list = []; stockphoto.getComp.requests[reqIndex].doc_id = doc_id; stockphoto.getComp.requests[reqIndex].ErrorDialogShown = false ; stockphoto.getComp.requests[reqIndex].bIsCanceled = false; stockphoto.getComp.requestIndex++; return reqIndex; } this.InitRequestList=function(reqIndex) { var i, cmdStr; // get the thumbnails. if( stockphoto.getComp.requests[reqIndex].count < 1 ) { /*MESSAGE_ES_WAITING*/ stockphoto.DL.alertBox(stockphoto.alertBox.extendScriptComponentID+9); //*** check that error is correct return( false ); } cmdStr="stockphoto.getComp.requests["+reqIndex+"].list=[ "; for( i=0; i 0 ) cmdStr += ",\n"; cmdStr += ' { path:"", doc_id:' + stockphoto.getComp.requests[reqIndex].doc_id + '}'; } cmdStr += " ];"; eval( cmdStr ); cmdStr = []; return( true ); } this.CopySelections=function( doc_id, iMax ) { var i, doc; this.SelPath = []; if( ( stockphoto.documents[ doc_id ] != undefined )&& ( stockphoto.documents[ doc_id ].document != undefined ) ) { doc= stockphoto.documents[ doc_id ].document; for( i=0; i 1)) { stockphoto.DL.NavBar.SpiningWheelOn(stockphoto.core.multipleCompDown, doc_id ); } else { stockphoto.DL.NavBar.SpiningWheelOn(stockphoto.core.singleCompDown, doc_id ); } //end of added by aman //SA: Getting the list of Adobe Id's for SaveAs Dialog var thumbPath = "" , extension = "", normalizeName = "", fileBaseNameIdx = ""; var file; var iCtr = 0; stockphoto.core.SaveComp.AdobeIdList = ""; for(var iCtr = 0; iCtr < (stockphoto.getComp.requests[reqIndex].count); iCtr++ ) { thumbPath = stockphoto.NavIntDt_t[ doc_id ].Selections.SelPath[ iCtr ]; if ("undefined" == typeof thumbPath) { continue; } file = File(thumbPath); extension = stockphoto.core.util.getExtension(thumbPath); normalizeName = stockphoto.core.util.normalizeFileName(file.name); normalizeName = stockphoto.core.getKeepCompFilename(normalizeName, extension, file); if (extension == "") { normalizeName = normalizeName + ".jpg"; } else { if (extension.toLowerCase() != "jpg") //Ensure the file in the comps folder has .jpg as extension no matter what the source is. { fileBaseNameIdx = normalizeName.lastIndexOf("."); normalizeName = normalizeName.slice(0, fileBaseNameIdx+1) + "jpg"; } } var sAdobeIDFileName = stockphoto.core.getAdobeIDFileNameFromPath(thumbPath); if("" != sAdobeIDFileName) { stockphoto.core.SaveComp.AdobeIdList = stockphoto.core.SaveComp.AdobeIdList+',"' + sAdobeIDFileName + '"'; } } stockphoto.core.SaveComp.AdobeIdList = stockphoto.core.SaveComp.AdobeIdList.slice(1); stockphoto.core.SaveComp.numOfImagesSelected = stockphoto.getComp.requests[reqIndex].count; //SA: Change Ends app.scheduleTask( "stockphoto.getComp.KeepComp_Iterate("+doc_id+",0,"+(stockphoto.getComp.requests[reqIndex].count)+","+reqIndex+","+(stockphoto.NavIntDt_t[ doc_id ].SelectionID)+");", 100, false ); } } } } stockphoto.core.log.logString(0,"getComp installed"); if( ( stockphoto.timeKeeperOn != undefined )&&( stockphoto.timeKeeperOn ) ) { stockphoto.core.util.edTime( stockphoto.DL.jsx_GetComp ); }