CCMain.m 256 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861
  1. //
  2. // CCMain.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCMain.h"
  24. #import "AppDelegate.h"
  25. #import "CCPhotos.h"
  26. #import "CCSynchronize.h"
  27. #import "CCTransfersCell.h"
  28. #import "OCActivity.h"
  29. #import "OCNotifications.h"
  30. #import "OCNotificationsAction.h"
  31. #import "OCFrameworkConstants.h"
  32. #import "OCCapabilities.h"
  33. #import "CTAssetCheckmark.h"
  34. #import "NCAutoUpload.h"
  35. #import "NCBridgeSwift.h"
  36. @interface CCMain () <CCActionsDeleteDelegate, CCActionsRenameDelegate, CCActionsSearchDelegate, CCActionsDownloadThumbnailDelegate, CCActionsSettingFavoriteDelegate, UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, CCLoginDelegate, CCLoginDelegateWeb>
  37. {
  38. tableMetadata *_metadata;
  39. BOOL _isRoot;
  40. BOOL _isViewDidLoad;
  41. BOOL _isPickerCriptate; // if is cryptated image or video back from picker
  42. BOOL _isSelectedMode;
  43. NSMutableDictionary *_selectedFileIDsMetadatas;
  44. NSUInteger _numSelectedFileIDsMetadatas;
  45. NSMutableArray *_queueSelector;
  46. NSMutableDictionary *_statusSwipeCell;
  47. UIImageView *_ImageTitleHomeCryptoCloud;
  48. UIView *_reMenuBackgroundView;
  49. UITapGestureRecognizer *_singleFingerTap;
  50. NSString *_directoryGroupBy;
  51. NSString *_directoryOrder;
  52. NSUInteger _failedAttempts;
  53. NSDate *_lockUntilDate;
  54. NSString *_fatherPermission;
  55. UIRefreshControl *_refreshControl;
  56. UIDocumentInteractionController *_docController;
  57. CCHud *_hud;
  58. CCHud *_hudDeterminate;
  59. // Datasource
  60. CCSectionDataSourceMetadata *_sectionDataSource;
  61. NSDate *_dateReadDataSource;
  62. // Search
  63. BOOL _isSearchMode;
  64. NSString *_searchFileName;
  65. NSMutableArray *_searchResultMetadatas;
  66. NSString *_depth;
  67. NSString *_noFilesSearchTitle;
  68. NSString *_noFilesSearchDescription;
  69. NSTimer *_timerWaitInput;
  70. // Login
  71. CCLoginWeb *_loginWeb;
  72. CCLogin *_loginVC;
  73. BOOL _loadingFolder;
  74. }
  75. @end
  76. @implementation CCMain
  77. #pragma --------------------------------------------------------------------------------------------
  78. #pragma mark ===== Init =====
  79. #pragma --------------------------------------------------------------------------------------------
  80. - (id)initWithCoder:(NSCoder *)aDecoder
  81. {
  82. if (self = [super initWithCoder:aDecoder]) {
  83. _directoryOrder = [CCUtility getOrderSettings];
  84. _directoryGroupBy = [CCUtility getGroupBySettings];
  85. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:@"initializeMain" object:nil];
  86. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearDateReadDataSource:) name:@"clearDateReadDataSource" object:nil];
  87. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitle) name:@"setTitleMain" object:nil];
  88. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  89. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  90. }
  91. return self;
  92. }
  93. #pragma --------------------------------------------------------------------------------------------
  94. #pragma mark ===== View =====
  95. #pragma --------------------------------------------------------------------------------------------
  96. - (void)viewDidLoad
  97. {
  98. [super viewDidLoad];
  99. // init object
  100. _metadata = [tableMetadata new];
  101. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  102. _hudDeterminate = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  103. _selectedFileIDsMetadatas = [NSMutableDictionary new];
  104. _statusSwipeCell = [NSMutableDictionary new];
  105. _queueSelector = [NSMutableArray new];
  106. _isViewDidLoad = YES;
  107. _fatherPermission = @"";
  108. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  109. _searchResultMetadatas = [NSMutableArray new];
  110. _searchFileName = @"";
  111. _depth = @"infinity";
  112. _noFilesSearchTitle = @"";
  113. _noFilesSearchDescription = @"";
  114. // delegate
  115. self.tableView.delegate = self;
  116. self.tableView.tableFooterView = [UIView new];
  117. self.tableView.separatorColor = [NCBrandColor sharedInstance].seperator;
  118. self.tableView.emptyDataSetDelegate = self;
  119. self.tableView.emptyDataSetSource = self;
  120. self.searchController.delegate = self;
  121. self.searchController.searchBar.delegate = self;
  122. [[CCNetworking sharedNetworking] settingDelegate:self];
  123. // Custom Cell
  124. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
  125. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
  126. // long press recognizer TableView
  127. UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressTableView:)];
  128. [self.tableView addGestureRecognizer:longPressRecognizer];
  129. // Pull-to-Refresh
  130. [self createRefreshControl];
  131. // Register for 3D Touch Previewing if available
  132. if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
  133. {
  134. [self registerForPreviewingWithDelegate:self sourceView:self.view];
  135. }
  136. // Back Button
  137. if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl]])
  138. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationLogo"] style:UIBarButtonItemStylePlain target:nil action:nil];
  139. // reMenu Background
  140. _reMenuBackgroundView = [[UIView alloc] init];
  141. _reMenuBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
  142. // if this is not Main (the Main uses inizializeMain)
  143. if (_isRoot == NO && app.activeAccount.length > 0) {
  144. // Settings this folder & delegate & Loading datasource
  145. app.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  146. // Load Datasource
  147. [self reloadDatasource:_serverUrl];
  148. // Read (File) Folder
  149. [self readFileReloadFolder];
  150. }
  151. // Title
  152. [self setTitle];
  153. // Search
  154. self.definesPresentationContext = YES;
  155. self.searchController.searchResultsUpdater = self;
  156. self.searchController.dimsBackgroundDuringPresentation = NO;
  157. self.searchController.searchBar.barTintColor = [NCBrandColor sharedInstance].seperator;
  158. [self.searchController.searchBar sizeToFit];
  159. self.searchController.searchBar.delegate = self;
  160. // Hide Search Filed on Load
  161. self.tableView.tableHeaderView = self.searchController.searchBar;
  162. [self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height - self.tableView.contentOffset.y)];
  163. }
  164. // Apparirà
  165. - (void)viewWillAppear:(BOOL)animated
  166. {
  167. [super viewWillAppear:animated];
  168. // test
  169. if (app.activeAccount.length == 0)
  170. return;
  171. // Settings this folder & delegate & Loading datasource
  172. app.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  173. [[CCNetworking sharedNetworking] settingDelegate:self];
  174. // Color
  175. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
  176. [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
  177. if (_isSelectedMode)
  178. [self setUINavigationBarSelected];
  179. else
  180. [self setUINavigationBarDefault];
  181. // If not editing mode remove _selectedFileIDs
  182. if (!self.tableView.editing)
  183. [_selectedFileIDsMetadatas removeAllObjects];
  184. // Plus Button
  185. [app plusButtonVisibile:true];
  186. }
  187. // E' arrivato
  188. - (void)viewDidAppear:(BOOL)animated
  189. {
  190. [super viewDidAppear:animated];
  191. // Active Main
  192. app.activeMain = self;
  193. // Test viewDidLoad
  194. if (_isViewDidLoad) {
  195. _isViewDidLoad = NO;
  196. } else {
  197. if (app.activeAccount.length > 0 && [_selectedFileIDsMetadatas count] == 0) {
  198. // Load Datasource
  199. [self reloadDatasource:_serverUrl];
  200. // Read (file) Folder
  201. [self readFileReloadFolder];
  202. }
  203. }
  204. // Title
  205. [self setTitle];
  206. }
  207. - (void)viewWillDisappear:(BOOL)animated
  208. {
  209. [super viewWillDisappear:animated];
  210. [self closeAllMenu];
  211. }
  212. - (void)didReceiveMemoryWarning
  213. {
  214. [super didReceiveMemoryWarning];
  215. // Dispose of any resources that can be recreated.
  216. }
  217. - (BOOL)prefersStatusBarHidden
  218. {
  219. return NO;
  220. }
  221. // detect scroll for remove keyboard in search mode
  222. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  223. {
  224. if (_isSearchMode && scrollView == self.tableView) {
  225. [self.searchController.searchBar endEditing:YES];
  226. }
  227. }
  228. - (void)changeTheming
  229. {
  230. if (self.isViewLoaded && self.view.window)
  231. [app changeTheming:self];
  232. // Refresh control
  233. _refreshControl.tintColor = [NCBrandColor sharedInstance].brand;
  234. // Reload Table View
  235. [self tableViewReloadData];
  236. }
  237. #pragma --------------------------------------------------------------------------------------------
  238. #pragma mark ===== Initizlize Mail =====
  239. #pragma --------------------------------------------------------------------------------------------
  240. - (void)initializeMain:(NSNotification *)notification
  241. {
  242. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  243. _directoryGroupBy = nil;
  244. _directoryOrder = nil;
  245. _dateReadDataSource = nil;
  246. // test
  247. if (app.activeAccount.length == 0)
  248. return;
  249. if ([app.listMainVC count] == 0 || _isRoot) {
  250. // This is Root home main add list
  251. appDelegate.homeMain = self;
  252. _isRoot = YES;
  253. _serverUrl = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
  254. appDelegate.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  255. [appDelegate.listMainVC setObject:self forKey:_serverUrl];
  256. // go Home
  257. [self.navigationController popToRootViewControllerAnimated:NO];
  258. // Crypto Mode
  259. if ([[CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]] length] == 0) {
  260. appDelegate.isCryptoCloudMode = NO;
  261. } else {
  262. appDelegate.isCryptoCloudMode = YES;
  263. }
  264. _isFolderEncrypted = NO;
  265. // setting Networking
  266. [[CCNetworking sharedNetworking] settingDelegate:self];
  267. [[CCNetworking sharedNetworking] settingAccount];
  268. // Remove search mode
  269. [self cancelSearchBar];
  270. // populate shared Link & User
  271. NSArray *results = [[NCManageDatabase sharedInstance] getShares];
  272. if (results) {
  273. appDelegate.sharesLink = results[0];
  274. appDelegate.sharesUserAndGroup = results[1];
  275. }
  276. // Load Datasource
  277. [self reloadDatasource:_serverUrl];
  278. // Read (File) Folder
  279. [self readFileReloadFolder];
  280. // Setting Theming
  281. [app settingThemingColorBrand];
  282. // Load photo datasorce
  283. if (appDelegate.activePhotos)
  284. [appDelegate.activePhotos reloadDatasourceForced];
  285. // remove all of detail
  286. if (appDelegate.activeDetail)
  287. [appDelegate.activeDetail removeAllView];
  288. // remove all Notification Messages
  289. [appDelegate.listOfNotifications removeAllObjects];
  290. // Initializations
  291. [appDelegate applicationInitialized];
  292. } else {
  293. // reload datasource
  294. [self reloadDatasource:_serverUrl];
  295. }
  296. }
  297. #pragma --------------------------------------------------------------------------------------------
  298. #pragma mark ==== DZNEmptyDataSetSource ====
  299. #pragma --------------------------------------------------------------------------------------------
  300. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
  301. {
  302. if (_loadingFolder)
  303. return NO;
  304. else
  305. return YES;
  306. }
  307. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  308. {
  309. return [UIColor whiteColor];
  310. }
  311. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  312. {
  313. if (_isSearchMode)
  314. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"searchBig"] color:[NCBrandColor sharedInstance].brand];
  315. else
  316. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"filesNoFiles"] color:[NCBrandColor sharedInstance].brand];
  317. }
  318. - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
  319. {
  320. if (_loadingFolder && _refreshControl.isRefreshing == NO) {
  321. UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  322. activityView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
  323. activityView.color = [NCBrandColor sharedInstance].brand;
  324. [activityView startAnimating];
  325. return activityView;
  326. }
  327. return nil;
  328. }
  329. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  330. {
  331. NSString *text;
  332. if (_isSearchMode) {
  333. text = _noFilesSearchTitle;
  334. } else {
  335. text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_files_no_files_", nil)];
  336. }
  337. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  338. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  339. }
  340. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  341. {
  342. NSString *text;
  343. if (_isSearchMode) {
  344. text = _noFilesSearchDescription;
  345. } else {
  346. text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_no_file_pull_down_", nil)];
  347. }
  348. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  349. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  350. paragraph.alignment = NSTextAlignmentCenter;
  351. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  352. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  353. }
  354. #pragma --------------------------------------------------------------------------------------------
  355. #pragma mark ===== Text Field =====
  356. #pragma --------------------------------------------------------------------------------------------
  357. - (void)minCharTextFieldDidChange:(UITextField *)sender
  358. {
  359. UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
  360. if (alertController)
  361. {
  362. UITextField *fileName = alertController.textFields.firstObject;
  363. UIAlertAction *okAction = alertController.actions.lastObject;
  364. okAction.enabled = fileName.text.length > 0;
  365. }
  366. }
  367. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  368. [textField selectAll:textField];
  369. }
  370. #pragma --------------------------------------------------------------------------------------------
  371. #pragma mark ===== Graphic Window =====
  372. #pragma --------------------------------------------------------------------------------------------
  373. - (void)createRefreshControl
  374. {
  375. _refreshControl = [UIRefreshControl new];
  376. _refreshControl.tintColor = [NCBrandColor sharedInstance].brand;
  377. _refreshControl.backgroundColor = [UIColor colorWithRed:235.0/255.0 green:235.0/255.0 blue:235.0/255.0 alpha:1.0];
  378. [_refreshControl addTarget:self action:@selector(refreshControlTarget) forControlEvents:UIControlEventValueChanged];
  379. [self setRefreshControl:_refreshControl];
  380. }
  381. - (void)deleteRefreshControl
  382. {
  383. [_refreshControl endRefreshing];
  384. self.refreshControl = nil;
  385. }
  386. - (void)refreshControlTarget
  387. {
  388. [self readFolder:_serverUrl];
  389. // Actuate `Peek` feedback (weak boom)
  390. AudioServicesPlaySystemSound(1519);
  391. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
  392. }
  393. - (void)setTitle
  394. {
  395. // Color text self.navigationItem.title
  396. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
  397. if (_isSelectedMode) {
  398. NSUInteger totali = [_sectionDataSource.allRecordsDataSource count];
  399. NSUInteger selezionati = [[self.tableView indexPathsForSelectedRows] count];
  400. self.navigationItem.titleView = nil;
  401. self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)selezionati, (unsigned long)totali];
  402. } else {
  403. // we are in home : LOGO BRAND
  404. if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl]]) {
  405. self.navigationItem.title = nil;
  406. if ([app.reachability isReachable] == NO)
  407. _ImageTitleHomeCryptoCloud = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigationLogoOffline"]];
  408. else
  409. _ImageTitleHomeCryptoCloud = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigationLogo"]];
  410. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  411. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuLogo)];
  412. [singleTap setNumberOfTapsRequired:1];
  413. [_ImageTitleHomeCryptoCloud addGestureRecognizer:singleTap];
  414. self.navigationItem.titleView = _ImageTitleHomeCryptoCloud;
  415. } else {
  416. self.navigationItem.title = _titleMain;
  417. }
  418. }
  419. }
  420. - (void)setUINavigationBarDefault
  421. {
  422. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
  423. UIBarButtonItem *buttonMore, *buttonNotification;
  424. // =
  425. buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationControllerMenu"] style:UIBarButtonItemStylePlain target:self action:@selector(toggleReMainMenu)];
  426. buttonMore.enabled = true;
  427. // <
  428. self.navigationController.navigationBar.hidden = NO;
  429. // Notification
  430. if ([app.listOfNotifications count] > 0) {
  431. buttonNotification = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"notification"] style:UIBarButtonItemStylePlain target:self action:@selector(viewNotification)];
  432. buttonNotification.tintColor = [NCBrandColor sharedInstance].navigationBarText;
  433. buttonNotification.enabled = true;
  434. }
  435. if (buttonNotification)
  436. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonNotification, nil];
  437. else
  438. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  439. self.navigationItem.leftBarButtonItem = nil;
  440. }
  441. - (void)setUINavigationBarSelected
  442. {
  443. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
  444. UIImage *icon = [UIImage imageNamed:@"navigationControllerMenu"];
  445. UIBarButtonItem *buttonMore = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(toggleReSelectMenu)];
  446. UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelSelect)];
  447. self.navigationItem.leftBarButtonItem = leftButton;
  448. self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
  449. }
  450. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  451. {
  452. [self closeAllMenu];
  453. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  454. }];
  455. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  456. }
  457. - (void)cancelSelect
  458. {
  459. [self tableViewSelect:NO];
  460. [app.reSelectMenu close];
  461. }
  462. - (void)closeAllMenu
  463. {
  464. // close Menu
  465. [app.reSelectMenu close];
  466. [app.reMainMenu close];
  467. // Close Menu Logo
  468. [CCMenuAccount dismissMenu];
  469. }
  470. #pragma --------------------------------------------------------------------------------------------
  471. #pragma mark ===== Document Picker =====
  472. #pragma --------------------------------------------------------------------------------------------
  473. - (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
  474. {
  475. NSLog(@"Cancelled");
  476. }
  477. - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
  478. {
  479. NSLog(@"Cancelled");
  480. }
  481. - (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
  482. {
  483. documentPicker.delegate = self;
  484. [self presentViewController:documentPicker animated:YES completion:nil];
  485. }
  486. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
  487. {
  488. if (controller.documentPickerMode == UIDocumentPickerModeImport) {
  489. NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
  490. __block NSError *error;
  491. [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
  492. NSString *fileName = [url lastPathComponent];
  493. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, fileName];
  494. NSData *data = [NSData dataWithContentsOfURL:newURL];
  495. if (data && error == nil) {
  496. if ([data writeToFile:fileNamePath options:NSDataWritingAtomic error:&error]) {
  497. // Upload File
  498. [[CCNetworking sharedNetworking] uploadFile:fileName serverUrl:_serverUrl cryptated:_isPickerCriptate onlyPlist:NO session:k_upload_session taskStatus: k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  499. } else {
  500. [app messageNotification:@"_error_" description:error.description visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  501. }
  502. } else {
  503. [app messageNotification:@"_error_" description:@"_read_file_error_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  504. }
  505. }];
  506. }
  507. }
  508. - (void)openImportDocumentPicker
  509. {
  510. UIDocumentMenuViewController *documentProviderMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
  511. documentProviderMenu.modalPresentationStyle = UIModalPresentationFormSheet;
  512. documentProviderMenu.popoverPresentationController.sourceView = self.view;
  513. documentProviderMenu.popoverPresentationController.sourceRect = self.view.bounds;
  514. documentProviderMenu.delegate = self;
  515. [self presentViewController:documentProviderMenu animated:YES completion:nil];
  516. }
  517. #pragma --------------------------------------------------------------------------------------------
  518. #pragma mark ===== Assets Picker =====
  519. #pragma --------------------------------------------------------------------------------------------
  520. -(void)dismissFormUploadAssets
  521. {
  522. [self reloadDatasource];
  523. }
  524. - (void)openAssetsPickerController
  525. {
  526. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  527. checkmark.tintColor = [NCBrandColor sharedInstance].brand;
  528. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeTop];
  529. UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:[CTAssetsPickerController class], nil];
  530. [app aspectNavigationControllerBar:navBar encrypted:NO online:YES hidden:NO];
  531. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
  532. dispatch_async(dispatch_get_main_queue(), ^{
  533. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  534. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeBottom];
  535. // init picker
  536. CTAssetsPickerController *picker = [CTAssetsPickerController new];
  537. // set delegate
  538. picker.delegate = self;
  539. // to show selection order
  540. //picker.showsSelectionIndex = YES;
  541. // to present picker as a form sheet in iPad
  542. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  543. picker.modalPresentationStyle = UIModalPresentationFormSheet;
  544. // present picker
  545. [self presentViewController:picker animated:YES completion:nil];
  546. });
  547. }];
  548. }
  549. - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset
  550. {
  551. if (picker.selectedAssets.count > k_pickerControllerMax) {
  552. [app messageNotification:@"_info_" description:@"_limited_dimension_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  553. return NO;
  554. }
  555. return YES;
  556. }
  557. - (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSMutableArray *)assets
  558. {
  559. [picker dismissViewControllerAnimated:YES completion:^{
  560. CreateFormUploadAssets *form = [[CreateFormUploadAssets alloc] init:_titleMain serverUrl:_serverUrl assets:assets cryptated:_isPickerCriptate session:k_upload_session delegate:self];
  561. form.title = NSLocalizedString(@"_upload_photos_videos_", nil);
  562. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:form];
  563. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  564. [self presentViewController:navigationController animated:YES completion:nil];
  565. }];
  566. }
  567. #pragma --------------------------------------------------------------------------------------------
  568. #pragma mark ===== Create New (OpenModel) =====
  569. #pragma --------------------------------------------------------------------------------------------
  570. - (void)openModel:(NSString *)tipo isNew:(BOOL)isnew
  571. {
  572. UIViewController *viewController;
  573. NSString *fileName, *uuid, *fileID, *serverUrl;
  574. NSIndexPath *index = [self.tableView indexPathForSelectedRow];
  575. [self.tableView deselectRowAtIndexPath:index animated:NO];
  576. if (isnew) {
  577. fileName = nil;
  578. uuid = [CCUtility getUUID];
  579. fileID = nil;
  580. serverUrl = _serverUrl;
  581. } else {
  582. fileName = _metadata.fileName;
  583. uuid = _metadata.uuid;
  584. fileID = _metadata.fileID;
  585. serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  586. }
  587. if (serverUrl) {
  588. if ([tipo isEqualToString:@"cartadicredito"])
  589. viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  590. if ([tipo isEqualToString:@"bancomat"])
  591. viewController = [[CCBancomat alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  592. if ([tipo isEqualToString:@"contocorrente"])
  593. viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  594. if ([tipo isEqualToString:@"accountweb"])
  595. viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  596. if ([tipo isEqualToString:@"patenteguida"])
  597. viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  598. if ([tipo isEqualToString:@"cartaidentita"])
  599. viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  600. if ([tipo isEqualToString:@"passaporto"])
  601. viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  602. if ([tipo isEqualToString:@"note"]) {
  603. viewController = [[CCNote alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
  604. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  605. [self presentViewController:navigationController animated:YES completion:nil];
  606. } else {
  607. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  608. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  609. [self presentViewController:navigationController animated:YES completion:nil];
  610. }
  611. }
  612. }
  613. // New folder or new photo or video
  614. - (void)returnCreate:(NSInteger)type
  615. {
  616. switch (type) {
  617. /* PLAIN */
  618. case k_returnCreateFolderPlain: {
  619. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  620. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  621. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  622. textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
  623. }];
  624. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  625. NSLog(@"Cancel action");
  626. }];
  627. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  628. UITextField *fileName = alertController.textFields.firstObject;
  629. [self createFolder:fileName.text autoUploadDirectory:NO];
  630. }];
  631. okAction.enabled = NO;
  632. [alertController addAction:cancelAction];
  633. [alertController addAction:okAction];
  634. [self presentViewController:alertController animated:YES completion:nil];
  635. }
  636. break;
  637. case k_returnCreateFotoVideoPlain: {
  638. _isPickerCriptate = false;
  639. [self openAssetsPickerController];
  640. }
  641. break;
  642. case k_returnCreateFilePlain: {
  643. _isPickerCriptate = false;
  644. [self openImportDocumentPicker];
  645. }
  646. break;
  647. /* ENCRYPTED */
  648. case k_returnCreateFolderEncrypted: {
  649. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  650. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  651. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  652. }];
  653. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  654. NSLog(@"Cancel action");
  655. }];
  656. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  657. UITextField *fileName = alertController.textFields.firstObject;
  658. [self createFolderEncrypted:fileName.text];
  659. }];
  660. okAction.enabled = NO;
  661. [alertController addAction:cancelAction];
  662. [alertController addAction:okAction];
  663. [self presentViewController:alertController animated:YES completion:nil];
  664. }
  665. break;
  666. case k_returnCreateFotoVideoEncrypted: {
  667. _isPickerCriptate = true;
  668. [self openAssetsPickerController];
  669. }
  670. break;
  671. case k_returnCreateFileEncrypted: {
  672. _isPickerCriptate = true;
  673. [self openImportDocumentPicker];
  674. }
  675. break;
  676. /* UTILITY */
  677. case k_returnNote:
  678. [self openModel:@"note" isNew:true];
  679. break;
  680. case k_returnAccountWeb:
  681. [self openModel:@"accountweb" isNew:true];
  682. break;
  683. /* BANK */
  684. case k_returnCartaDiCredito:
  685. [self openModel:@"cartadicredito" isNew:true];
  686. break;
  687. case k_returnBancomat:
  688. [self openModel:@"bancomat" isNew:true];
  689. break;
  690. case k_returnContoCorrente:
  691. [self openModel:@"contocorrente" isNew:true];
  692. break;
  693. /* DOCUMENT */
  694. case k_returnPatenteGuida:
  695. [self openModel:@"patenteguida" isNew:true];
  696. break;
  697. case k_returnCartaIdentita:
  698. [self openModel:@"cartaidentita" isNew:true];
  699. break;
  700. case k_returnPassaporto:
  701. [self openModel:@"passaporto" isNew:true];
  702. break;
  703. }
  704. }
  705. #pragma --------------------------------------------------------------------------------------------
  706. #pragma mark ===== Save selected File =====
  707. #pragma --------------------------------------------------------------------------------------------
  708. -(void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
  709. {
  710. if (error)
  711. [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  712. else
  713. [app messageNotification:@"_save_selected_files_" description:@"_file_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  714. }
  715. - (void)saveSelectedFiles
  716. {
  717. if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
  718. return;
  719. NSLog(@"[LOG] Start download selected files ...");
  720. [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
  721. NSArray *metadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  722. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  723. for (tableMetadata *metadata in metadatas) {
  724. if (metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_file] && ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])) {
  725. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  726. if (serverUrl)
  727. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorSave selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
  728. }
  729. }
  730. [_hud hideHud];
  731. });
  732. [self tableViewSelect:NO];
  733. }
  734. #pragma --------------------------------------------------------------------------------------------
  735. #pragma mark ===== Change Password =====
  736. #pragma --------------------------------------------------------------------------------------------
  737. - (void) loginSuccess:(NSInteger)loginType
  738. {
  739. [self readFolder:_serverUrl];
  740. }
  741. - (void)changePasswordAccount
  742. {
  743. // Brand
  744. if ([NCBrandOptions sharedInstance].use_login_web) {
  745. _loginWeb = [CCLoginWeb new];
  746. _loginWeb.delegate = self;
  747. _loginWeb.loginType = loginModifyPasswordUser;
  748. dispatch_async(dispatch_get_main_queue(), ^ {
  749. [_loginWeb presentModalWithDefaultTheme:self];
  750. });
  751. } else {
  752. _loginVC = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"CCLoginNextcloud"];
  753. _loginVC.delegate = self;
  754. _loginVC.loginType = loginModifyPasswordUser;
  755. [self presentViewController:_loginVC animated:YES completion:nil];
  756. }
  757. }
  758. #pragma mark -
  759. #pragma --------------------------------------------------------------------------------------------
  760. #pragma mark ===== Peek & Pop =====
  761. #pragma --------------------------------------------------------------------------------------------
  762. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
  763. {
  764. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  765. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  766. if (metadata.thumbnailExists && !metadata.cryptated) {
  767. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  768. if (cell) {
  769. previewingContext.sourceRect = cell.frame;
  770. CCPeekPop *vc = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
  771. vc.delegate = self;
  772. vc.metadata = metadata;
  773. return vc;
  774. }
  775. }
  776. return nil;
  777. }
  778. - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
  779. {
  780. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:previewingContext.sourceRect.origin];
  781. [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
  782. }
  783. #pragma mark -
  784. #pragma --------------------------------------------------------------------------------------------
  785. #pragma mark ==== External Sites ====
  786. #pragma --------------------------------------------------------------------------------------------
  787. - (void)getExternalSitesServerSuccess:(NSArray *)listOfExternalSites
  788. {
  789. [[NCManageDatabase sharedInstance] deleteExternalSites];
  790. for (OCExternalSites *tableExternalSites in listOfExternalSites)
  791. [[NCManageDatabase sharedInstance] addExternalSites:tableExternalSites];
  792. }
  793. - (void)getExternalSitesServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  794. {
  795. NSLog(@"[LOG] No External Sites found");
  796. }
  797. #pragma --------------------------------------------------------------------------------------------
  798. #pragma mark ==== Activity ====
  799. #pragma --------------------------------------------------------------------------------------------
  800. - (void)getActivityServerSuccess:(NSArray *)listOfActivity
  801. {
  802. [[NCManageDatabase sharedInstance] addActivityServer:listOfActivity];
  803. // Reload Activity Data Source
  804. [app.activeActivity reloadDatasource];
  805. }
  806. - (void)getActivityServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  807. {
  808. NSLog(@"[LOG] No Activity found");
  809. }
  810. #pragma --------------------------------------------------------------------------------------------
  811. #pragma mark ==== Notification ====
  812. #pragma --------------------------------------------------------------------------------------------
  813. - (void)getNotificationServerSuccess:(NSArray *)listOfNotifications
  814. {
  815. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  816. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  817. // Order by date
  818. NSArray *sortedListOfNotifications = [listOfNotifications sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
  819. OCNotifications *notification1 = obj1, *notification2 = obj2;
  820. return [notification2.date compare: notification1.date];
  821. }];
  822. // verify if listOfNotifications is changed
  823. NSString *old = @"", *new = @"";
  824. for (OCNotifications *notification in listOfNotifications)
  825. new = [new stringByAppendingString:@(notification.idNotification).stringValue];
  826. for (OCNotifications *notification in appDelegate.listOfNotifications)
  827. old = [old stringByAppendingString:@(notification.idNotification).stringValue];
  828. if (![new isEqualToString:old]) {
  829. appDelegate.listOfNotifications = [[NSMutableArray alloc] initWithArray:sortedListOfNotifications];
  830. // reload Notification view
  831. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"notificationReloadData" object:nil];
  832. }
  833. // Update NavigationBar
  834. if (!_isSelectedMode) {
  835. [self performSelectorOnMainThread:@selector(setUINavigationBarDefault) withObject:nil waitUntilDone:NO];
  836. }
  837. });
  838. }
  839. - (void)getNotificationServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  840. {
  841. // Update NavigationBar
  842. if (!_isSelectedMode)
  843. [self setUINavigationBarDefault];
  844. }
  845. - (void)viewNotification
  846. {
  847. if ([app.listOfNotifications count] > 0) {
  848. CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
  849. [notificationVC setModalPresentationStyle:UIModalPresentationFormSheet];
  850. [self presentViewController:notificationVC animated:YES completion:nil];
  851. }
  852. }
  853. #pragma --------------------------------------------------------------------------------------------
  854. #pragma mark ==== User Profile ====
  855. #pragma --------------------------------------------------------------------------------------------
  856. - (void)getUserProfileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  857. {
  858. if (errorCode == 401)
  859. [self changePasswordAccount];
  860. }
  861. - (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile
  862. {
  863. [[NCManageDatabase sharedInstance] setAccountsUserProfile:userProfile];
  864. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  865. NSString *address = [NSString stringWithFormat:@"%@/index.php/avatar/%@/128", app.activeUrl, app.activeUser];
  866. UIImage *avatar = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
  867. if (avatar)
  868. [UIImagePNGRepresentation(avatar) writeToFile:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser] atomically:YES];
  869. else
  870. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser] error:nil];
  871. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"changeUserProfile" object:nil];
  872. });
  873. }
  874. #pragma --------------------------------------------------------------------------------------------
  875. #pragma mark ==== Capabilities ====
  876. #pragma --------------------------------------------------------------------------------------------
  877. - (void)getCapabilitiesOfServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  878. {
  879. // Change Theming color
  880. [app settingThemingColorBrand];
  881. if (errorCode == 401)
  882. [self changePasswordAccount];
  883. }
  884. - (void)getCapabilitiesOfServerSuccess:(OCCapabilities *)capabilities
  885. {
  886. // Update capabilities db
  887. [[NCManageDatabase sharedInstance] addCapabilities:capabilities];
  888. // ------ THEMING -----------------------------------------------------------------------
  889. // Download Theming Background & Change Theming color
  890. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  891. if ([NCBrandOptions sharedInstance].use_themingBackground == YES) {
  892. UIImage *themingBackground = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[capabilities.themingBackground stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
  893. if (themingBackground)
  894. [UIImagePNGRepresentation(themingBackground) writeToFile:[NSString stringWithFormat:@"%@/themingBackground.png", app.directoryUser] atomically:YES];
  895. else
  896. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/themingBackground.png", app.directoryUser] error:nil];
  897. }
  898. dispatch_async(dispatch_get_main_queue(), ^{
  899. [app settingThemingColorBrand];
  900. });
  901. });
  902. // ------ SEARCH ------------------------------------------------------------------------
  903. // Search bar if change version
  904. if ([[NCManageDatabase sharedInstance] getServerVersion] != capabilities.versionMajor) {
  905. [self cancelSearchBar];
  906. }
  907. // ------ GET SERVICE SERVER ------------------------------------------------------------
  908. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  909. // Read External Sites
  910. if (capabilities.isExternalSitesServerEnabled) {
  911. metadataNet.action = actionGetExternalSitesServer;
  912. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  913. }
  914. // Read Share
  915. if (capabilities.isFilesSharingAPIEnabled) {
  916. [app.sharesID removeAllObjects];
  917. metadataNet.action = actionReadShareServer;
  918. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  919. }
  920. // Read Notification
  921. metadataNet.action = actionGetNotificationServer;
  922. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  923. // Read User Profile
  924. metadataNet.action = actionGetUserProfile;
  925. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  926. // Read Activity
  927. metadataNet.action = actionGetActivityServer;
  928. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  929. }
  930. #pragma mark -
  931. #pragma --------------------------------------------------------------------------------------------
  932. #pragma mark ==== Request Server Information ====
  933. #pragma --------------------------------------------------------------------------------------------
  934. - (void)requestServerCapabilities
  935. {
  936. // test
  937. if (app.activeAccount.length == 0)
  938. return;
  939. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  940. metadataNet.action = actionGetCapabilities;
  941. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  942. }
  943. #pragma mark -
  944. #pragma --------------------------------------------------------------------------------------------
  945. #pragma mark ==== Middleware Ping ====
  946. #pragma --------------------------------------------------------------------------------------------
  947. - (void)middlewarePing
  948. {
  949. // test
  950. if (app.activeAccount.length == 0)
  951. return;
  952. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  953. metadataNet.action = actionMiddlewarePing;
  954. metadataNet.serverUrl = [[NCBrandOptions sharedInstance] middlewarePingUrl];
  955. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  956. }
  957. #pragma mark -
  958. #pragma --------------------------------------------------------------------------------------------
  959. #pragma mark ==== Download Thumbnail Delegate ====
  960. #pragma --------------------------------------------------------------------------------------------
  961. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  962. {
  963. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
  964. if ([self indexPathIsValid:indexPath]) {
  965. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]])
  966. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  967. }
  968. }
  969. #pragma --------------------------------------------------------------------------------------------
  970. #pragma mark ==== Download ====
  971. #pragma --------------------------------------------------------------------------------------------
  972. - (void)downloadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  973. {
  974. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  975. // File do not exists on server, remove in local
  976. if (errorCode == kOCErrorServerPathNotFound || errorCode == kCFURLErrorBadServerResponse) {
  977. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, fileID] error:nil];
  978. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, fileID] error:nil];
  979. if (metadata.directory && serverUrl) {
  980. NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
  981. [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete];
  982. }
  983. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID] clearDateReadDirectoryID:nil];
  984. [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  985. }
  986. if ([selector isEqualToString:selectorLoadViewImage]) {
  987. dispatch_async(dispatch_get_main_queue(), ^{
  988. // Updating Detail
  989. if (app.activeDetail)
  990. [app.activeDetail downloadPhotoBrowserFailure:errorCode];
  991. // Updating Photos
  992. if (app.activePhotos)
  993. [app.activePhotos downloadFileFailure:errorCode];
  994. });
  995. } else {
  996. if (errorCode != kCFURLErrorCancelled)
  997. [app messageNotification:@"_download_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  998. }
  999. [self reloadDatasource:serverUrl];
  1000. }
  1001. - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  1002. {
  1003. __block tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  1004. if (metadata == nil)
  1005. return;
  1006. // Download
  1007. if ([selector isEqualToString:selectorDownloadFile]) {
  1008. [self reloadDatasource:serverUrl];
  1009. }
  1010. // Synchronized
  1011. if ([selector isEqualToString:selectorDownloadSynchronize]) {
  1012. [self reloadDatasource:serverUrl];
  1013. }
  1014. // add Favorite
  1015. if ([selector isEqualToString:selectorAddFavorite]) {
  1016. [[CCActions sharedInstance] settingFavorite:metadata favorite:YES delegate:self];
  1017. }
  1018. // encrypted file
  1019. if ([selector isEqualToString:selectorEncryptFile]) {
  1020. [self encryptedFile:metadata];
  1021. }
  1022. // decrypted file
  1023. if ([selector isEqualToString:selectorDecryptFile]) {
  1024. [self decryptedFile:metadata];
  1025. }
  1026. // open View File
  1027. if ([selector isEqualToString:selectorLoadFileView] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  1028. [self reloadDatasource:serverUrl];
  1029. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_compress]) {
  1030. selector = selectorOpenIn;
  1031. //[self performSelector:@selector(unZipFile:) withObject:metadata.fileID];
  1032. } else if ([metadata.typeFile isEqualToString: k_metadataTypeFile_unknown]) {
  1033. selector = selectorOpenIn;
  1034. } else {
  1035. _metadata = metadata;
  1036. if ([self shouldPerformSegue])
  1037. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  1038. }
  1039. }
  1040. // addLocal
  1041. if ([selector isEqualToString:selectorAddLocal]) {
  1042. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileNamePrint]];
  1043. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  1044. [CCGraphics saveIcoWithEtag:metadata.fileNamePrint image:image writeToFile:nil copy:YES move:NO fromPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/.%@.ico", [CCUtility getDirectoryLocal], metadata.fileNamePrint]];
  1045. [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:0];
  1046. [self reloadDatasource:serverUrl];
  1047. }
  1048. // Open with...
  1049. if ([selector isEqualToString:selectorOpenIn] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  1050. [self reloadDatasource:serverUrl];
  1051. [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  1052. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  1053. NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint]];
  1054. _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  1055. _docController.delegate = self;
  1056. [_docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  1057. }
  1058. // Save to Photo Album
  1059. if ([selector isEqualToString:selectorSave] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  1060. NSString *file = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1061. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  1062. UIImage *image = [UIImage imageWithContentsOfFile:file];
  1063. if (image)
  1064. UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  1065. else
  1066. [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  1067. }
  1068. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  1069. [[NSFileManager defaultManager] linkItemAtPath:file toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  1070. if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint])) {
  1071. UISaveVideoAtPathToSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint], self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  1072. } else {
  1073. [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  1074. }
  1075. }
  1076. [self reloadDatasource:serverUrl];
  1077. }
  1078. // Copy File
  1079. if ([selector isEqualToString:selectorLoadCopy]) {
  1080. [self reloadDatasource:serverUrl];
  1081. [self copyFileToPasteboard:metadata];
  1082. }
  1083. // download and view a template
  1084. if ([selector isEqualToString:selectorLoadModelView]) {
  1085. // se è un template aggiorniamo anche nel FileSystem
  1086. if ([metadata.type isEqualToString: k_metadataType_template]) {
  1087. [[NCManageDatabase sharedInstance] setLocalFileWithFileID:metadata.fileID date:metadata.date exifDate:nil exifLatitude:nil exifLongitude:nil fileName:nil fileNamePrint:metadata.fileNamePrint];
  1088. }
  1089. [self openModel:metadata.model isNew:false];
  1090. [self reloadDatasource:serverUrl];
  1091. }
  1092. //download file plist
  1093. if ([selector isEqualToString:selectorLoadPlist]) {
  1094. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  1095. long countSelectorLoadPlist = 0;
  1096. for (NSOperation *operation in [app.netQueue operations]) {
  1097. if ([((OCnetworking *)operation).metadataNet.selector isEqualToString:selectorLoadPlist])
  1098. countSelectorLoadPlist++;
  1099. }
  1100. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
  1101. if ((countSelectorLoadPlist == 0 || countSelectorLoadPlist % k_maxConcurrentOperation == 0) && [metadata.directoryID isEqualToString:directoryID] && directoryID) {
  1102. dispatch_async(dispatch_get_main_queue(), ^{
  1103. [self reloadDatasource:serverUrl];
  1104. });
  1105. }
  1106. });
  1107. }
  1108. //selectorLoadViewImage
  1109. if ([selector isEqualToString:selectorLoadViewImage]) {
  1110. // Detail
  1111. if (app.activeDetail)
  1112. [app.activeDetail downloadPhotoBrowserSuccess:metadata selector:selector];
  1113. // Photos
  1114. if (app.activePhotos)
  1115. [app.activePhotos downloadFileSuccess:metadata];
  1116. [self reloadDatasource:serverUrl];
  1117. }
  1118. // if exists postselector call self with selectorPost
  1119. if ([selectorPost length] > 0)
  1120. [self downloadFileSuccess:fileID serverUrl:serverUrl selector:selectorPost selectorPost:nil];
  1121. }
  1122. - (void)downloadSelectedFilesFolders
  1123. {
  1124. if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
  1125. return;
  1126. NSLog(@"[LOG] Start download selected ...");
  1127. [_hud visibleHudTitle:NSLocalizedString(@"_downloading_progress_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1128. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1129. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  1130. for (tableMetadata *metadata in selectedMetadatas) {
  1131. if ([metadata.type isEqualToString: k_metadataType_file]) {
  1132. if (metadata.directory) {
  1133. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1134. if (serverUrl) {
  1135. serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
  1136. [[CCSynchronize sharedSynchronize] synchronizedFolder:serverUrl selector:selectorReadFolderWithDownload];
  1137. }
  1138. } else {
  1139. [[CCSynchronize sharedSynchronize] synchronizedFile:metadata selector:selectorReadFileWithDownload];
  1140. }
  1141. }
  1142. }
  1143. [_hud hideHud];
  1144. });
  1145. [self tableViewSelect:NO];
  1146. }
  1147. - (void)downloadPlist:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  1148. {
  1149. NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND session = ''", app.activeAccount, directoryID] sorted:nil ascending:NO];
  1150. for (tableMetadata *metadata in metadatas) {
  1151. if ([CCUtility isCryptoPlistString:metadata.fileName] && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName]] == NO && [metadata.session length] == 0) {
  1152. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1153. metadataNet.action = actionDownloadFile;
  1154. metadataNet.downloadData = NO;
  1155. metadataNet.downloadPlist = YES;
  1156. metadataNet.fileID = metadata.fileID;
  1157. metadataNet.selector = selectorLoadPlist;
  1158. metadataNet.serverUrl = serverUrl;
  1159. metadataNet.session = k_download_session_foreground;
  1160. metadataNet.taskStatus = k_taskStatusResume;
  1161. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1162. //[[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:NO downloadPlist:YES selector:selectorLoadPlist selectorPost:nil session:k_download_session_foreground taskStatus:k_taskStatusResume delegate:self];
  1163. }
  1164. }
  1165. }
  1166. #pragma --------------------------------------------------------------------------------------------
  1167. #pragma mark ===== Upload new Photos/Videos =====
  1168. #pragma --------------------------------------------------------------------------------------------
  1169. - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  1170. {
  1171. // Auto Upload
  1172. if([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll]) {
  1173. if ([[NCManageDatabase sharedInstance] getPriorityQueueUploadWithAssetLocalIdentifier:metadataNet.assetLocalIdentifier] > k_priorityAutoUploadStop) {
  1174. // Change priority Auto Upload
  1175. if ([[NCManageDatabase sharedInstance] setPriorityQueueUploadWithAssetLocalIdentifier:metadataNet.assetLocalIdentifier priority:k_priorityAutoUploadError]) {
  1176. // Activity
  1177. [[NCManageDatabase sharedInstance] addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:message type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:app.activeUrl];
  1178. }
  1179. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1180. } else {
  1181. // Delete record on Table Auto Upload
  1182. if ([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll])
  1183. [[NCManageDatabase sharedInstance] deleteQueueUploadWithAssetLocalIdentifier:metadataNet.assetLocalIdentifier selector:selector];
  1184. // Activity
  1185. [[NCManageDatabase sharedInstance] addActivityClient:metadataNet.fileName fileID:metadataNet.assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:@"Too many error, delete file" type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:app.activeUrl];
  1186. [app messageNotification:@"_upload_file_" description:@"Too many error, delete file, see Activity for more info" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1187. }
  1188. } else {
  1189. // Read File test do not exists
  1190. if (errorCode == k_CCErrorFileUploadNotFound && fileID) {
  1191. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  1192. // reUpload
  1193. if (metadata)
  1194. [[CCNetworking sharedNetworking] uploadFileMetadata:metadata taskStatus:k_taskStatusResume];
  1195. }
  1196. // Print error
  1197. else if (errorCode != kCFURLErrorCancelled && errorCode != 403) {
  1198. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1199. }
  1200. }
  1201. [self reloadDatasource:serverUrl];
  1202. }
  1203. - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  1204. {
  1205. // Auto Upload
  1206. if([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll]) {
  1207. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
  1208. // ONLY BACKGROUND
  1209. [[NCAutoUpload sharedInstance] performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUploadBackground] waitUntilDone:NO];
  1210. } else {
  1211. // ONLY FOREFROUND
  1212. [[NCAutoUpload sharedInstance] performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUpload] waitUntilDone:NO];
  1213. }
  1214. }
  1215. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  1216. if ([selectorPost isEqualToString:selectorReadFolderForced] ) {
  1217. [self readFolder:serverUrl];
  1218. } else {
  1219. [self reloadDatasource:serverUrl];
  1220. }
  1221. });
  1222. }
  1223. //
  1224. // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
  1225. //
  1226. - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  1227. {
  1228. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
  1229. [self performSelectorOnMainThread:@selector(uploadFileAssetBridge:) withObject:@[assets, serverUrl, [NSNumber numberWithBool:cryptated], [NSNumber numberWithBool:useSubFolder], session] waitUntilDone:NO];
  1230. });
  1231. }
  1232. - (void)uploadFileAssetBridge:(NSArray *)arguments
  1233. {
  1234. NSArray *assets = [arguments objectAtIndex:0];
  1235. NSString *serverUrl = [arguments objectAtIndex:1];
  1236. BOOL cryptated = [[arguments objectAtIndex:2] boolValue];
  1237. BOOL useSubFolder = [[arguments objectAtIndex:3] boolValue];
  1238. NSString *session = [arguments objectAtIndex:4];
  1239. NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:app.activeUrl];
  1240. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
  1241. if (!directoryID) return;
  1242. // if request create the folder for Photos & the subfolders
  1243. if ([autoUploadPath isEqualToString:serverUrl])
  1244. if (![[NCAutoUpload sharedInstance] createFolderSubFolderAutoUploadFolderPhotos:autoUploadPath useSubFolder:useSubFolder assets:(PHFetchResult *)assets selector:selectorUploadFile])
  1245. return;
  1246. NSLog(@"[LOG] Asset N. %lu", (unsigned long)[assets count]);
  1247. for (PHAsset *asset in assets) {
  1248. NSString *fileName = [CCUtility createFileName:[asset valueForKey:@"filename"] fileDate:asset.creationDate fileType:asset.mediaType keyFileName:k_keyFileNameMask keyFileNameType:k_keyFileNameType];
  1249. NSDate *assetDate = asset.creationDate;
  1250. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  1251. // Create serverUrl if use sub folder
  1252. if (useSubFolder) {
  1253. [formatter setDateFormat:@"yyyy"];
  1254. NSString *yearString = [formatter stringFromDate:assetDate];
  1255. [formatter setDateFormat:@"MM"];
  1256. NSString *monthString = [formatter stringFromDate:assetDate];
  1257. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", autoUploadPath, yearString, monthString];
  1258. }
  1259. // Check if is in upload
  1260. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND fileName = %@ AND session != ''", app.activeAccount, directoryID, fileName];
  1261. NSArray *isRecordInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
  1262. if ([isRecordInSessions count] > 0) {
  1263. // next upload
  1264. continue;
  1265. } else {
  1266. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1267. if (cryptated) {
  1268. metadataNet.action = actionUploadAsset;
  1269. metadataNet.assetLocalIdentifier = asset.localIdentifier;
  1270. metadataNet.cryptated = cryptated;
  1271. metadataNet.fileName = fileName;
  1272. metadataNet.session = session;
  1273. metadataNet.selector = selectorUploadFile;
  1274. metadataNet.selectorPost = nil;
  1275. metadataNet.serverUrl = serverUrl;
  1276. metadataNet.taskStatus = k_taskStatusResume;
  1277. } else {
  1278. metadataNet.action = actionReadFile;
  1279. metadataNet.assetLocalIdentifier = asset.localIdentifier;
  1280. metadataNet.cryptated = cryptated;
  1281. metadataNet.fileName = fileName;
  1282. metadataNet.session = session;
  1283. metadataNet.selector = selectorReadFileUploadFile;
  1284. metadataNet.serverUrl = serverUrl;
  1285. }
  1286. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1287. }
  1288. }
  1289. }
  1290. #pragma --------------------------------------------------------------------------------------------
  1291. #pragma mark ==== Read File ====
  1292. #pragma --------------------------------------------------------------------------------------------
  1293. - (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1294. {
  1295. // Read Folder
  1296. if ([metadataNet.selector isEqualToString:selectorReadFileReloadFolder]) {
  1297. //[self readFolderWithForced:NO serverUrl:metadataNet.serverUrl];
  1298. }
  1299. // UploadFile
  1300. if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
  1301. // File not exists
  1302. if (errorCode == 404) {
  1303. metadataNet.action = actionUploadAsset;
  1304. metadataNet.errorCode = 0;
  1305. metadataNet.selector = selectorUploadFile;
  1306. metadataNet.selectorPost = nil;
  1307. metadataNet.taskStatus = k_taskStatusResume;
  1308. if ([metadataNet.session containsString:@"wwan"])
  1309. [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
  1310. else
  1311. [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
  1312. } else {
  1313. // error ho many retry befor notification and go to on next asses
  1314. if (metadataNet.errorRetry < 3) {
  1315. // Retry read file
  1316. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1317. } else {
  1318. // STOP check file, view message error
  1319. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1320. }
  1321. }
  1322. }
  1323. }
  1324. - (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(tableMetadata *)metadata
  1325. {
  1326. // Read Folder
  1327. if ([metadataNet.selector isEqualToString:selectorReadFileReloadFolder]) {
  1328. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", metadataNet.account, metadataNet.serverUrl]];
  1329. if ([metadata.etag isEqualToString:directory.etag] == NO) {
  1330. [self readFolder:metadataNet.serverUrl];
  1331. }
  1332. }
  1333. // UploadFile
  1334. if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
  1335. metadataNet.action = actionUploadAsset;
  1336. metadataNet.errorCode = 403; // File exists 403 Forbidden
  1337. metadataNet.selector = selectorUploadFile;
  1338. metadataNet.selectorPost = nil;
  1339. metadataNet.taskStatus = k_taskStatusResume;
  1340. if ([metadataNet.session containsString:@"wwan"])
  1341. [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
  1342. else
  1343. [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
  1344. }
  1345. }
  1346. - (void)readFileReloadFolder
  1347. {
  1348. if (!_serverUrl || !app.activeAccount || app.maintenanceMode)
  1349. return;
  1350. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1351. metadataNet.action = actionReadFile;
  1352. metadataNet.priority = NSOperationQueuePriorityHigh;
  1353. metadataNet.selector = selectorReadFileReloadFolder;
  1354. metadataNet.serverUrl = _serverUrl;
  1355. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1356. }
  1357. #pragma --------------------------------------------------------------------------------------------
  1358. #pragma mark ==== Read Folder ====
  1359. #pragma --------------------------------------------------------------------------------------------
  1360. - (void)readFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1361. {
  1362. // verify active user
  1363. tableAccount *record = [[NCManageDatabase sharedInstance] getAccountActive];
  1364. _loadingFolder = NO;
  1365. [self tableViewReloadData];
  1366. [_refreshControl endRefreshing];
  1367. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1368. if (message && [record.account isEqualToString:metadataNet.account])
  1369. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1370. [self reloadDatasource:metadataNet.serverUrl];
  1371. if (errorCode == 401)
  1372. [self changePasswordAccount];
  1373. }
  1374. - (void)readFolderSuccess:(CCMetadataNet *)metadataNet metadataFolder:(tableMetadata *)metadataFolder metadatas:(NSArray *)metadatas
  1375. {
  1376. // verify active user
  1377. tableAccount *record = [[NCManageDatabase sharedInstance] getAccountActive];
  1378. if (![record.account isEqualToString:metadataNet.account])
  1379. return;
  1380. // save father e update permission
  1381. if(!_isSearchMode && metadataFolder)
  1382. _fatherPermission = metadataFolder.permissions;
  1383. NSArray *recordsInSessions;
  1384. NSMutableArray *metadatasToInsertInDB = [NSMutableArray new];
  1385. if (_isSearchMode) {
  1386. recordsInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND session != ''", metadataNet.account] sorted:nil ascending:NO];
  1387. } else {
  1388. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:metadataNet.serverUrl serverUrlTo:nil etag:metadataFolder.etag];
  1389. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND session = ''", metadataNet.account, metadataNet.directoryID] clearDateReadDirectoryID:metadataNet.directoryID];
  1390. recordsInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND session != ''", metadataNet.account, metadataNet.directoryID] sorted:nil ascending:NO];
  1391. [[NCManageDatabase sharedInstance] setDateReadDirectoryWithDirectoryID:metadataNet.directoryID];
  1392. }
  1393. for (tableMetadata *metadata in metadatas) {
  1394. // type of file
  1395. NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
  1396. // if crypto do not insert
  1397. if (typeFilename == k_metadataTypeFilenameCrypto) continue;
  1398. // verify if the record encrypted has plist + crypto
  1399. if (typeFilename == k_metadataTypeFilenamePlist && metadata.directory == NO) {
  1400. BOOL isCryptoComplete = NO;
  1401. NSString *fileNameCrypto = [CCUtility trasformedFileNamePlistInCrypto:metadata.fileName];
  1402. for (tableMetadata *completeMetadata in metadatas) {
  1403. if (completeMetadata.cryptated == NO) continue;
  1404. else if ([completeMetadata.fileName isEqualToString:fileNameCrypto]) {
  1405. isCryptoComplete = YES;
  1406. break;
  1407. }
  1408. }
  1409. if (isCryptoComplete == NO) continue;
  1410. }
  1411. // verify if the record is in download/upload progress
  1412. if (metadata.directory == NO && [recordsInSessions count] > 0) {
  1413. tableMetadata *metadataTransfer = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND fileName = %@", app.activeAccount, metadataNet.directoryID, metadata.fileName]];
  1414. // is in Download or Upload
  1415. if ([metadataTransfer.session containsString:@"upload"] || [metadataTransfer.session containsString:@"download"]) {
  1416. continue;
  1417. }
  1418. }
  1419. // Insert in Array
  1420. [metadatasToInsertInDB addObject:metadata];
  1421. }
  1422. // insert in Database
  1423. metadatasToInsertInDB = (NSMutableArray *)[[NCManageDatabase sharedInstance] addMetadatas:metadatasToInsertInDB serverUrl:metadataNet.serverUrl];
  1424. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  1425. // read plist
  1426. if (!_isSearchMode)
  1427. [self downloadPlist:metadataNet.directoryID serverUrl:metadataNet.serverUrl];
  1428. // File is changed ??
  1429. if (!_isSearchMode && metadatasToInsertInDB)
  1430. [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatasToInsertInDB serverUrl:metadataNet.serverUrl account:app.activeAccount withDownload:NO];
  1431. });
  1432. // Search Mode
  1433. if (_isSearchMode) {
  1434. // Fix managed -> Unmanaged _searchResultMetadatas
  1435. if (metadatasToInsertInDB)
  1436. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatasToInsertInDB];
  1437. [self reloadDatasource:metadataNet.serverUrl];
  1438. }
  1439. // this is the same directory
  1440. if ([metadataNet.serverUrl isEqualToString:_serverUrl] && !_isSearchMode) {
  1441. // reload
  1442. [self reloadDatasource:metadataNet.serverUrl];
  1443. // stoprefresh
  1444. [_refreshControl endRefreshing];
  1445. // Enable change user
  1446. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1447. _loadingFolder = NO;
  1448. [self tableViewReloadData];
  1449. }
  1450. }
  1451. - (void)readFolder:(NSString *)serverUrl
  1452. {
  1453. // init control
  1454. if (!serverUrl || !app.activeAccount || app.maintenanceMode) {
  1455. [_refreshControl endRefreshing];
  1456. return;
  1457. }
  1458. // Search Mode
  1459. if (_isSearchMode) {
  1460. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl directoryID:nil];
  1461. _searchFileName = @""; // forced reload searchg
  1462. [self updateSearchResultsForSearchController:self.searchController];
  1463. return;
  1464. }
  1465. _loadingFolder = YES;
  1466. [self tableViewReloadData];
  1467. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, serverUrl]];
  1468. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1469. metadataNet.action = actionReadFolder;
  1470. metadataNet.date = [NSDate date];
  1471. metadataNet.directoryID = directory.directoryID;
  1472. metadataNet.priority = NSOperationQueuePriorityHigh;
  1473. metadataNet.selector = selectorReadFolder;
  1474. metadataNet.serverUrl = serverUrl;
  1475. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1476. }
  1477. #pragma mark -
  1478. #pragma --------------------------------------------------------------------------------------------
  1479. #pragma mark ===== Search =====
  1480. #pragma --------------------------------------------------------------------------------------------
  1481. -(void)searchStartTimer
  1482. {
  1483. NSString *home = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
  1484. [[CCActions sharedInstance] search:home fileName:_searchFileName depth:_depth date:nil selector:selectorSearch delegate:self];
  1485. _noFilesSearchTitle = @"";
  1486. _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
  1487. [self.tableView reloadEmptyDataSet];
  1488. }
  1489. -(void)updateSearchResultsForSearchController:(UISearchController *)searchController
  1490. {
  1491. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  1492. _isSearchMode = YES;
  1493. [self deleteRefreshControl];
  1494. NSString *fileName = [CCUtility removeForbiddenCharactersServer:searchController.searchBar.text];
  1495. if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
  1496. _searchFileName = fileName;
  1497. // First : filter
  1498. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
  1499. if (!directoryID) return;
  1500. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"directoryID = %@ AND account = %@ AND fileNamePrint CONTAINS[cd] %@", directoryID, app.activeAccount, fileName];
  1501. NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
  1502. [_searchResultMetadatas removeAllObjects];
  1503. for (tableMetadata *record in records)
  1504. [_searchResultMetadatas addObject:record];
  1505. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1506. metadataNet.account = app.activeAccount;
  1507. metadataNet.directoryID = directoryID;
  1508. metadataNet.selector = selectorSearch;
  1509. metadataNet.serverUrl = _serverUrl;
  1510. [self readFolderSuccess:metadataNet metadataFolder:nil metadatas:_searchResultMetadatas];
  1511. // Version >= 12
  1512. if ([[NCManageDatabase sharedInstance] getServerVersion] >= 12) {
  1513. [_timerWaitInput invalidate];
  1514. _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
  1515. }
  1516. }
  1517. if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
  1518. [self reloadDatasource];
  1519. }
  1520. }
  1521. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  1522. {
  1523. [self cancelSearchBar];
  1524. [self readFolder:_serverUrl];
  1525. }
  1526. - (void)searchFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1527. {
  1528. _searchFileName = @"";
  1529. if (message)
  1530. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1531. }
  1532. - (void)searchSuccess:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas
  1533. {
  1534. _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatas];
  1535. [self readFolderSuccess:metadataNet metadataFolder:nil metadatas:metadatas];
  1536. }
  1537. - (void)cancelSearchBar
  1538. {
  1539. if (self.searchController.active) {
  1540. [self.searchController setActive:NO];
  1541. [self createRefreshControl];
  1542. _isSearchMode = NO;
  1543. _searchFileName = @"";
  1544. _dateReadDataSource = nil;
  1545. _searchResultMetadatas = [NSMutableArray new];
  1546. [self reloadDatasource];
  1547. }
  1548. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  1549. }
  1550. #pragma mark -
  1551. #pragma --------------------------------------------------------------------------------------------
  1552. #pragma mark ===== Delete File or Folder =====
  1553. #pragma --------------------------------------------------------------------------------------------
  1554. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1555. {
  1556. [self deleteFileOrFolderSuccess:metadataNet];
  1557. }
  1558. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  1559. {
  1560. [_queueSelector removeObject:metadataNet.selector];
  1561. if ([_queueSelector count] == 0) {
  1562. [_hud hideHud];
  1563. // next
  1564. [_selectedFileIDsMetadatas removeObjectForKey:metadataNet.fileID];
  1565. if ([_selectedFileIDsMetadatas count] > 0) {
  1566. NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
  1567. [self deleteFileOrFolder:[metadatas objectAtIndex:0] numFile:[_selectedFileIDsMetadatas count] ofFile:_numSelectedFileIDsMetadatas];
  1568. } else {
  1569. // End Select Table View
  1570. [self tableViewSelect:NO];
  1571. // Reload
  1572. if (_isSearchMode)
  1573. [self readFolder:metadataNet.serverUrl];
  1574. else
  1575. [self reloadDatasource:metadataNet.serverUrl];
  1576. }
  1577. }
  1578. }
  1579. - (void)deleteFileOrFolder:(tableMetadata *)metadata numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
  1580. {
  1581. if (metadata.cryptated) {
  1582. [_queueSelector addObject:selectorDeleteCrypto];
  1583. [_queueSelector addObject:selectorDeletePlist];
  1584. } else {
  1585. [_queueSelector addObject:selectorDelete];
  1586. }
  1587. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  1588. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_delete_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1589. }
  1590. - (void)deleteFile
  1591. {
  1592. if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
  1593. return;
  1594. [_queueSelector removeAllObjects];
  1595. if ([_selectedFileIDsMetadatas count] > 0) {
  1596. _numSelectedFileIDsMetadatas = [_selectedFileIDsMetadatas count];
  1597. NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
  1598. [self deleteFileOrFolder:[metadatas objectAtIndex:0] numFile:[_selectedFileIDsMetadatas count] ofFile:_numSelectedFileIDsMetadatas];
  1599. } else {
  1600. _numSelectedFileIDsMetadatas = 1;
  1601. [self deleteFileOrFolder:_metadata numFile:1 ofFile:_numSelectedFileIDsMetadatas];
  1602. }
  1603. }
  1604. #pragma --------------------------------------------------------------------------------------------
  1605. #pragma mark ===== Rename / Move =====
  1606. #pragma --------------------------------------------------------------------------------------------
  1607. - (void)renameSuccess:(CCMetadataNet *)metadataNet
  1608. {
  1609. [self readFolder:metadataNet.serverUrl];
  1610. }
  1611. - (void)renameFile:(NSArray *)arguments
  1612. {
  1613. tableMetadata* metadata = [arguments objectAtIndex:0];
  1614. NSString *fileName = [arguments objectAtIndex:1];
  1615. [[CCActions sharedInstance] renameFileOrFolder:metadata fileName:fileName delegate:self];
  1616. }
  1617. - (void)renameNote:(NSArray *)arguments
  1618. {
  1619. tableMetadata* metadata = [arguments objectAtIndex:0];
  1620. NSString *fileName = [arguments objectAtIndex:1];
  1621. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1622. if (!serverUrl) return;
  1623. CCTemplates *templates = [[CCTemplates alloc] init];
  1624. NSMutableDictionary *field = [[CCCrypto sharedManager] getDictionaryEncrypted:metadata.fileName uuid:metadata.uuid isLocal:NO directoryUser:app.directoryUser];
  1625. NSString *fileNameModel = [templates salvaNote:[field objectForKey:@"note"] titolo:fileName fileName:metadata.fileName uuid:metadata.uuid];
  1626. if (fileNameModel) {
  1627. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1628. metadataNet.action = actionUploadTemplate;
  1629. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  1630. metadataNet.fileNamePrint = fileName;
  1631. metadataNet.etag = metadata.etag;
  1632. metadataNet.serverUrl = serverUrl;
  1633. metadataNet.session = k_upload_session_foreground;
  1634. metadataNet.taskStatus = k_taskStatusResume;
  1635. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1636. }
  1637. }
  1638. - (void)renameMoveFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1639. {
  1640. if ([metadataNet.selector isEqualToString:selectorMove]) {
  1641. [_hud hideHud];
  1642. if (message)
  1643. [app messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1644. // End Select Table View
  1645. [self tableViewSelect:NO];
  1646. // reload Datasource
  1647. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced] || _isSearchMode)
  1648. [self readFolder:metadataNet.serverUrl];
  1649. else
  1650. [self reloadDatasource];
  1651. }
  1652. }
  1653. - (void)moveSuccess:(CCMetadataNet *)metadataNet
  1654. {
  1655. [_queueSelector removeObject:metadataNet.selector];
  1656. if ([_queueSelector count] == 0) {
  1657. [_hud hideHud];
  1658. NSString *fileName = [CCUtility trasformedFileNameCryptoInPlist:metadataNet.fileName];
  1659. NSString *directoryID = metadataNet.directoryID;
  1660. NSString *directoryIDTo = metadataNet.directoryIDTo;
  1661. NSString *serverUrlTo = [[NCManageDatabase sharedInstance] getServerUrl:directoryIDTo];
  1662. if (!serverUrlTo) return;
  1663. // FILE -> Metadata
  1664. if (metadataNet.directory == NO)
  1665. [[NCManageDatabase sharedInstance] moveMetadataWithFileName:fileName directoryID:directoryID directoryIDTo:directoryIDTo];
  1666. // DIRECTORY -> Directory - CCMetadata
  1667. if (metadataNet.directory == YES) {
  1668. // delete all dir / subdir
  1669. [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:fileName]];
  1670. // move metadata
  1671. [[NCManageDatabase sharedInstance] moveMetadataWithFileName:fileName directoryID:directoryID directoryIDTo:directoryIDTo];
  1672. // Add new directory
  1673. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrlTo, fileName];
  1674. (void)[[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:newDirectory permissions:@""];
  1675. }
  1676. // next
  1677. [_selectedFileIDsMetadatas removeObjectForKey:metadataNet.fileID];
  1678. if ([_selectedFileIDsMetadatas count] > 0) {
  1679. NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
  1680. [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[[metadatas objectAtIndex:0], serverUrlTo, [NSNumber numberWithInteger:[_selectedFileIDsMetadatas count]], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
  1681. } else {
  1682. // End Select Table View
  1683. [self tableViewSelect:NO];
  1684. // reload Datasource
  1685. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced] || _isSearchMode)
  1686. [self readFolder:metadataNet.serverUrl];
  1687. else
  1688. [self reloadDatasource];
  1689. }
  1690. }
  1691. }
  1692. - (void)moveFileOrFolderMetadata:(NSArray *)arguments
  1693. {
  1694. tableMetadata *metadata = [arguments objectAtIndex:0];
  1695. NSString *serverUrlTo = [arguments objectAtIndex:1];
  1696. NSInteger numFile = [[arguments objectAtIndex:2] integerValue];
  1697. NSInteger ofFile = [[arguments objectAtIndex:3] integerValue];
  1698. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1699. if (!serverUrl) return;
  1700. NSString *directoryIDTo = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlTo];
  1701. if (!directoryIDTo) return;
  1702. // Plain
  1703. if (metadata.cryptated == NO) {
  1704. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:app.activeUser withPassword:app.activePassword withUrl:app.activeUrl isCryptoCloudMode:NO];
  1705. NSError *error = [ocNetworking readFileSync:[NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName]];
  1706. if(!error) {
  1707. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  1708. UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
  1709. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1710. }];
  1711. [alert addAction:ok];
  1712. [self presentViewController:alert animated:YES completion:nil];
  1713. });
  1714. // End Select Table View
  1715. [self tableViewSelect:NO];
  1716. // reload Datasource
  1717. [self readFileReloadFolder];
  1718. return;
  1719. }
  1720. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1721. metadataNet.action = actionMoveFileOrFolder;
  1722. metadataNet.directory = metadata.directory;
  1723. metadataNet.fileID = metadata.fileID;
  1724. metadataNet.directoryID = metadata.directoryID;
  1725. metadataNet.directoryIDTo = directoryIDTo;
  1726. metadataNet.fileName = metadata.fileName;
  1727. metadataNet.fileNamePrint = metadataNet.fileNamePrint;
  1728. metadataNet.fileNameTo = metadata.fileName;
  1729. metadataNet.etag = metadata.etag;
  1730. metadataNet.selector = selectorMove;
  1731. metadataNet.serverUrl = serverUrl;
  1732. metadataNet.serverUrlTo = serverUrlTo;
  1733. [_queueSelector addObject:metadataNet.selector];
  1734. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1735. }
  1736. // cyptated
  1737. if (metadata.cryptated == YES) {
  1738. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1739. metadataNet.action = actionMoveFileOrFolder;
  1740. metadataNet.directory = metadata.directory;
  1741. metadataNet.fileID = metadata.fileID;
  1742. metadataNet.directoryID = metadata.directoryID;
  1743. metadataNet.directoryIDTo = directoryIDTo;
  1744. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1745. metadataNet.etag = metadata.etag;
  1746. metadataNet.serverUrl = serverUrl;
  1747. metadataNet.serverUrlTo = serverUrlTo;
  1748. // data
  1749. metadataNet.fileName = metadata.fileNameData;
  1750. metadataNet.fileNameTo = metadata.fileNameData;
  1751. metadataNet.selector = selectorMoveCrypto;
  1752. [_queueSelector addObject:metadataNet.selector];
  1753. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1754. // plist
  1755. metadataNet.fileName = metadata.fileName;
  1756. metadataNet.fileNameTo = metadata.fileName;
  1757. metadataNet.selector = selectorMovePlist;
  1758. [_queueSelector addObject:metadataNet.selector];
  1759. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1760. }
  1761. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1762. }
  1763. // DELEGATE : Move
  1764. - (void)dismissMove
  1765. {
  1766. [self reloadDatasource];
  1767. }
  1768. // DELEGATE : Move
  1769. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title
  1770. {
  1771. [_queueSelector removeAllObjects];
  1772. if ([_selectedFileIDsMetadatas count] > 0) {
  1773. _numSelectedFileIDsMetadatas = [_selectedFileIDsMetadatas count];
  1774. NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
  1775. [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[[metadatas objectAtIndex:0], serverUrlTo, [NSNumber numberWithInteger:[_selectedFileIDsMetadatas count]], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
  1776. } else {
  1777. _numSelectedFileIDsMetadatas = 1;
  1778. [self performSelectorOnMainThread:@selector(moveFileOrFolderMetadata:) withObject:@[_metadata, serverUrlTo, [NSNumber numberWithInteger:1], [NSNumber numberWithInteger:_numSelectedFileIDsMetadatas]] waitUntilDone:NO];
  1779. }
  1780. }
  1781. - (void)moveOpenWindow:(NSArray *)indexPaths
  1782. {
  1783. if (_isSelectedMode && [_selectedFileIDsMetadatas count] == 0)
  1784. return;
  1785. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  1786. CCMove *viewController = (CCMove *)navigationController.topViewController;
  1787. viewController.delegate = self;
  1788. viewController.move.title = NSLocalizedString(@"_move_", nil);
  1789. viewController.tintColor = [NCBrandColor sharedInstance].navigationBarText;
  1790. viewController.barTintColor = [NCBrandColor sharedInstance].brand;
  1791. viewController.tintColorTitle = [NCBrandColor sharedInstance].navigationBarText;
  1792. viewController.networkingOperationQueue = app.netQueue;
  1793. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  1794. [self presentViewController:navigationController animated:YES completion:nil];
  1795. }
  1796. #pragma --------------------------------------------------------------------------------------------
  1797. #pragma mark ===== Create folder =====
  1798. #pragma --------------------------------------------------------------------------------------------
  1799. - (void)createFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1800. {
  1801. if (metadataNet.cryptated == NO) {
  1802. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataNet.fileID] clearDateReadDirectoryID:nil];
  1803. [self reloadDatasource];
  1804. // We are in directory fail ?
  1805. CCMain *vc = [app.listMainVC objectForKey:[CCUtility stringAppendServerUrl:_serverUrl addFileName:metadataNet.fileName]];
  1806. if (vc)
  1807. [vc.navigationController popViewControllerAnimated:YES];
  1808. }
  1809. if (message)
  1810. [app messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  1811. }
  1812. - (void)createFolderSuccess:(CCMetadataNet *)metadataNet
  1813. {
  1814. NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", metadataNet.serverUrl, metadataNet.fileName];
  1815. (void)[[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:newDirectory permissions:@""];
  1816. if (metadataNet.cryptated == NO) {
  1817. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileName = %@ AND directoryID = %@", metadataNet.fileName, metadataNet.directoryID]];
  1818. [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileName = %@ AND directoryID = %@", metadataNet.fileName, metadataNet.directoryID] clearDateReadDirectoryID:nil];
  1819. metadata.fileID = metadataNet.fileID;
  1820. metadata.date = metadataNet.date;
  1821. metadata.permissions = @"RDNVCK";
  1822. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1823. [self reloadDatasource];
  1824. }
  1825. }
  1826. - (void)createFolder:(NSString *)fileNameFolder autoUploadDirectory:(BOOL)autoUploadDirectory
  1827. {
  1828. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1829. fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
  1830. if (![fileNameFolder length]) return;
  1831. if (autoUploadDirectory) metadataNet.serverUrl = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:app.activeUrl];
  1832. else metadataNet.serverUrl = _serverUrl;
  1833. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
  1834. if (!directoryID) return;
  1835. metadataNet.action = actionCreateFolder;
  1836. metadataNet.directoryID = directoryID;
  1837. if (autoUploadDirectory)
  1838. metadataNet.options = @"folderAutoUpload";
  1839. metadataNet.fileID = [[NSUUID UUID] UUIDString];
  1840. metadataNet.fileName = fileNameFolder;
  1841. metadataNet.selector = selectorCreateFolder;
  1842. metadataNet.serverUrl = _serverUrl;
  1843. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1844. // Create Directory on metadata
  1845. tableMetadata *metadata = [CCUtility createMetadataWithAccount:app.activeAccount date:[NSDate date] directory:YES fileID:metadataNet.fileID directoryID:metadataNet.directoryID fileName:metadataNet.fileName etag:@"" size:0 status:k_metadataStatusNormal];
  1846. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  1847. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:_serverUrl directoryID:nil];
  1848. [self reloadDatasource];
  1849. }
  1850. - (void)createFolderEncrypted:(NSString *)fileNameFolder
  1851. {
  1852. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1853. NSString *fileNamePlist;
  1854. fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
  1855. if (![fileNameFolder length]) return;
  1856. NSString *title = [AESCrypt encrypt:fileNameFolder password:[[CCCrypto sharedManager] getKeyPasscode:[CCUtility getUUID]]];
  1857. fileNamePlist = [[CCCrypto sharedManager] createFilenameEncryptor:fileNameFolder uuid:[CCUtility getUUID]];
  1858. [[CCCrypto sharedManager] createFilePlist:[NSTemporaryDirectory() stringByAppendingString:fileNamePlist] title:title len:0 directory:true uuid:[CCUtility getUUID] nameCurrentDevice:[CCUtility getNameCurrentDevice] icon:@""];
  1859. // Create folder
  1860. metadataNet.action = actionCreateFolder;
  1861. metadataNet.cryptated = YES;
  1862. metadataNet.fileID = [[NSUUID UUID] UUIDString];
  1863. metadataNet.fileName = fileNamePlist;
  1864. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1865. metadataNet.selector = selectorCreateFolder;
  1866. metadataNet.serverUrl = _serverUrl;
  1867. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1868. // upload plist file
  1869. metadataNet.action = actionUploadOnlyPlist;
  1870. metadataNet.cryptated = YES;
  1871. metadataNet.fileID = [[NSUUID UUID] UUIDString];
  1872. metadataNet.fileName = [fileNamePlist stringByAppendingString:@".plist"];
  1873. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1874. metadataNet.selectorPost = selectorReadFolderForced;
  1875. metadataNet.serverUrl = _serverUrl;
  1876. metadataNet.session = k_upload_session_foreground;
  1877. metadataNet.taskStatus = k_taskStatusResume;
  1878. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1879. }
  1880. #pragma --------------------------------------------------------------------------------------------
  1881. #pragma mark ===== Encrypted / Decrypted Folder =====
  1882. #pragma --------------------------------------------------------------------------------------------
  1883. - (void)encyptedDecryptedFolder
  1884. {
  1885. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  1886. if (!serverUrl) return;
  1887. if (_metadata.cryptated) {
  1888. // DECRYPTED
  1889. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1890. //-------------------------- RENAME -------------------------------------------//
  1891. metadataNet.action = actionMoveFileOrFolder;
  1892. metadataNet.fileID = _metadata.fileID;
  1893. metadataNet.fileName = _metadata.fileNameData;
  1894. metadataNet.fileNameTo = _metadata.fileNamePrint;
  1895. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1896. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1897. metadataNet.selector = selectorRename;
  1898. metadataNet.serverUrl = serverUrl;
  1899. metadataNet.serverUrlTo = serverUrl;
  1900. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1901. //-------------------------- DELETE -------------------------------------------//
  1902. metadataNet.action = actionDeleteFileDirectory;
  1903. metadataNet.fileID = _metadata.fileID;
  1904. metadataNet.fileName = _metadata.fileName;
  1905. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1906. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1907. metadataNet.selector = selectorDeletePlist;
  1908. metadataNet.selectorPost = selectorReadFolderForced;
  1909. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1910. } else {
  1911. // ENCRYPTED
  1912. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1913. // Create File Plist
  1914. NSString *fileNameCrypto = [[CCCrypto sharedManager] createFileDirectoryPlist:_metadata];
  1915. //-------------------------- RENAME -------------------------------------------//
  1916. metadataNet.action = actionMoveFileOrFolder;
  1917. metadataNet.fileID = _metadata.fileID;
  1918. metadataNet.fileName = _metadata.fileName;
  1919. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1920. metadataNet.fileNameTo = fileNameCrypto;
  1921. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1922. metadataNet.selector = selectorRename;
  1923. metadataNet.serverUrl = serverUrl;
  1924. metadataNet.serverUrlTo = serverUrl;
  1925. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1926. //-------------------------- UPLOAD -------------------------------------------//
  1927. metadataNet.action = actionUploadOnlyPlist;
  1928. metadataNet.fileName = [fileNameCrypto stringByAppendingString:@".plist"];
  1929. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1930. metadataNet.selectorPost = selectorReadFolderForced;
  1931. metadataNet.serverUrl = serverUrl;
  1932. metadataNet.session = k_upload_session_foreground;
  1933. metadataNet.taskStatus = k_taskStatusResume;
  1934. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1935. }
  1936. }
  1937. #pragma --------------------------------------------------------------------------------------------
  1938. #pragma mark ===== Encrypted/Decrypted File =====
  1939. #pragma --------------------------------------------------------------------------------------------
  1940. - (void)encryptedSelectedFiles
  1941. {
  1942. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1943. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1944. for (tableMetadata *metadata in selectedMetadatas) {
  1945. if (metadata.cryptated == NO && metadata.directory == NO)
  1946. [metadatas addObject:metadata];
  1947. }
  1948. if ([metadatas count] > 0) {
  1949. NSLog(@"[LOG] Start encrypted selected files ...");
  1950. for (tableMetadata* metadata in metadatas) {
  1951. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1952. if(serverUrl)
  1953. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorEncryptFile selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
  1954. }
  1955. }
  1956. [self tableViewSelect:NO];
  1957. }
  1958. - (void)decryptedSelectedFiles
  1959. {
  1960. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1961. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1962. for (tableMetadata *metadata in selectedMetadatas) {
  1963. if (metadata.cryptated == YES && metadata.directory == NO && [metadata.model length] == 0)
  1964. [metadatas addObject:metadata];
  1965. }
  1966. if ([metadatas count] > 0) {
  1967. NSLog(@"[LOG] Start decrypted selected files ...");
  1968. for (tableMetadata* metadata in metadatas) {
  1969. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1970. if (serverUrl)
  1971. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorDecryptFile selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
  1972. }
  1973. }
  1974. [self tableViewSelect:NO];
  1975. }
  1976. - (void)cmdEncryptedDecryptedFile
  1977. {
  1978. NSString *selector;
  1979. if (_metadata.cryptated == YES) selector = selectorDecryptFile;
  1980. if (_metadata.cryptated == NO) selector = selectorEncryptFile;
  1981. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  1982. if (serverUrl)
  1983. [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selector selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  1984. }
  1985. - (void)encryptedFile:(tableMetadata *)metadata
  1986. {
  1987. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1988. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1989. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1990. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  1991. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo] && serverUrl) {
  1992. dispatch_async(dispatch_get_main_queue(), ^{
  1993. [[CCNetworking sharedNetworking] uploadFile:metadata.fileName serverUrl:serverUrl cryptated:YES onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  1994. [self performSelector:@selector(reloadDatasource) withObject:nil];
  1995. });
  1996. } else {
  1997. [app messageNotification:@"_encrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  1998. }
  1999. }
  2000. - (void)decryptedFile:(tableMetadata *)metadata
  2001. {
  2002. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  2003. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  2004. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  2005. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  2006. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo] && serverUrl) {
  2007. dispatch_async(dispatch_get_main_queue(), ^{
  2008. [[CCNetworking sharedNetworking] uploadFile:metadata.fileNamePrint serverUrl:serverUrl cryptated:NO onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  2009. [self performSelector:@selector(reloadDatasource) withObject:nil];
  2010. });
  2011. } else {
  2012. [app messageNotification:@"_decrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  2013. }
  2014. }
  2015. #pragma --------------------------------------------------------------------------------------------
  2016. #pragma mark ===== Progress & Task Button =====
  2017. #pragma --------------------------------------------------------------------------------------------
  2018. - (void)triggerProgressTask:(NSNotification *)notification
  2019. {
  2020. NSDictionary *dict = notification.userInfo;
  2021. NSString *fileID = [dict valueForKey:@"fileID"];
  2022. NSString *serverUrl = [dict valueForKey:@"serverUrl"];
  2023. BOOL cryptated = [[dict valueForKey:@"cryptated"] boolValue];
  2024. float progress = [[dict valueForKey:@"progress"] floatValue];
  2025. // CCProgress
  2026. if (progress == 0)
  2027. [self.navigationController cancelCCProgress];
  2028. else
  2029. [self.navigationController setCCProgressPercentage:progress*100 andTintColor: [NCBrandColor sharedInstance].navigationBarProgress];
  2030. // Check
  2031. if (!fileID || [fileID isEqualToString: @""])
  2032. return;
  2033. [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  2034. if (![serverUrl isEqualToString:_serverUrl])
  2035. return;
  2036. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  2037. if ([self indexPathIsValid:indexPath]) {
  2038. CCTransfersCell *cell = (CCTransfersCell *)[self.tableView cellForRowAtIndexPath:indexPath];
  2039. if (cryptated) cell.progressView.progressTintColor = [NCBrandColor sharedInstance].cryptocloud;
  2040. else cell.progressView.progressTintColor = [UIColor blackColor];
  2041. cell.progressView.hidden = NO;
  2042. [cell.progressView setProgress:progress];
  2043. }
  2044. }
  2045. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  2046. {
  2047. UITouch * touch = [[event allTouches] anyObject];
  2048. CGPoint location = [touch locationInView:self.tableView];
  2049. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  2050. if ([self indexPathIsValid:indexPath]) {
  2051. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2052. if (metadata)
  2053. [self reloadTaskButton:metadata];
  2054. }
  2055. }
  2056. - (void)reloadTaskButton:(tableMetadata *)metadata
  2057. {
  2058. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  2059. __block NSURLSessionTask *findTask;
  2060. NSInteger sessionTaskIdentifier = metadata.sessionTaskIdentifier;
  2061. NSInteger sessionTaskIdentifierPlist = metadata.sessionTaskIdentifierPlist;
  2062. NSString *fileID = metadata.fileID;
  2063. // DOWNLOAD
  2064. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  2065. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  2066. for (NSURLSessionUploadTask *task in downloadTasks)
  2067. if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
  2068. findTask = task;
  2069. [app.listChangeTask setObject:@"reloadDownload" forKey:fileID];
  2070. [task cancel];
  2071. }
  2072. if (!findTask) {
  2073. [app.listChangeTask setObject:@"reloadDownload" forKey:fileID];
  2074. NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
  2075. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
  2076. }
  2077. }];
  2078. }
  2079. // UPLOAD
  2080. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  2081. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  2082. for (NSURLSessionUploadTask *task in uploadTasks)
  2083. if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
  2084. findTask = task;
  2085. [app.listChangeTask setObject:@"reloadUpload" forKey:fileID];
  2086. [task cancel];
  2087. }
  2088. if (!findTask) {
  2089. [app.listChangeTask setObject:@"reloadUpload" forKey:fileID];
  2090. NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
  2091. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
  2092. }
  2093. }];
  2094. }
  2095. }
  2096. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  2097. {
  2098. UITouch * touch = [[event allTouches] anyObject];
  2099. CGPoint location = [touch locationInView:self.tableView];
  2100. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  2101. if ([self indexPathIsValid:indexPath]) {
  2102. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2103. if (metadata)
  2104. [self cancelTaskButton:metadata reloadTable:YES];
  2105. }
  2106. }
  2107. - (void)cancelTaskButton:(tableMetadata *)metadata reloadTable:(BOOL)reloadTable
  2108. {
  2109. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  2110. __block NSURLSessionTask *findTask;
  2111. NSInteger sessionTaskIdentifier = metadata.sessionTaskIdentifier;
  2112. NSInteger sessionTaskIdentifierPlist = metadata.sessionTaskIdentifierPlist;
  2113. NSString *fileID = metadata.fileID;
  2114. // DOWNLOAD
  2115. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  2116. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  2117. for (NSURLSessionTask *task in downloadTasks)
  2118. if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
  2119. findTask = task;
  2120. [app.listChangeTask setObject:@"cancelDownload" forKey:fileID];
  2121. [task cancel];
  2122. }
  2123. if (!findTask) {
  2124. [app.listChangeTask setObject:@"cancelDownload" forKey:fileID];
  2125. NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
  2126. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
  2127. }
  2128. }];
  2129. }
  2130. // UPLOAD
  2131. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  2132. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  2133. for (NSURLSessionUploadTask *task in uploadTasks)
  2134. if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
  2135. findTask = task;
  2136. [app.listChangeTask setObject:@"cancelUpload" forKey:fileID];
  2137. [task cancel];
  2138. }
  2139. if (!findTask) {
  2140. [app.listChangeTask setObject:@"cancelUpload" forKey:fileID];
  2141. NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
  2142. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
  2143. }
  2144. }];
  2145. }
  2146. }
  2147. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  2148. {
  2149. UITouch * touch = [[event allTouches] anyObject];
  2150. CGPoint location = [touch locationInView:self.tableView];
  2151. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  2152. if ([self indexPathIsValid:indexPath]) {
  2153. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2154. if (metadata)
  2155. [self stopTaskButton:metadata];
  2156. }
  2157. }
  2158. - (void)stopTaskButton:(tableMetadata *)metadata
  2159. {
  2160. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  2161. __block NSURLSessionTask *findTask;
  2162. NSInteger sessionTaskIdentifier = metadata.sessionTaskIdentifier;
  2163. NSInteger sessionTaskIdentifierPlist = metadata.sessionTaskIdentifierPlist;
  2164. NSString *fileID = metadata.fileID;
  2165. // UPLOAD
  2166. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  2167. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  2168. for (NSURLSessionUploadTask *task in uploadTasks)
  2169. if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
  2170. [app.listChangeTask setObject:@"stopUpload" forKey:fileID];
  2171. findTask = task;
  2172. [task cancel];
  2173. }
  2174. if (!findTask) {
  2175. [app.listChangeTask setObject:@"stopUpload" forKey:fileID];
  2176. NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
  2177. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
  2178. }
  2179. }];
  2180. }
  2181. }
  2182. #pragma --------------------------------------------------------------------------------------------
  2183. #pragma mark ===== Shared =====
  2184. #pragma --------------------------------------------------------------------------------------------
  2185. - (void)readSharedSuccess:(CCMetadataNet *)metadataNet items:(NSDictionary *)items openWindow:(BOOL)openWindow
  2186. {
  2187. [_hud hideHud];
  2188. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  2189. // change account ?
  2190. tableAccount *record = [[NCManageDatabase sharedInstance] getAccountActive];
  2191. if([record.account isEqualToString:metadataNet.account] == NO)
  2192. return;
  2193. NSArray *result = [[NCManageDatabase sharedInstance] updateShare:items activeUrl:appDelegate.activeUrl];
  2194. if (result) {
  2195. appDelegate.sharesLink = result[0];
  2196. appDelegate.sharesUserAndGroup = result[1];
  2197. }
  2198. // Notify Shares View
  2199. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"SharesReloadDatasource" object:nil userInfo:nil];
  2200. if (openWindow) {
  2201. if (_shareOC) {
  2202. [_shareOC reloadData];
  2203. } else {
  2204. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataNet.fileID]];
  2205. // Apriamo la view
  2206. _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
  2207. _shareOC.delegate = self;
  2208. _shareOC.metadata = metadata;
  2209. _shareOC.serverUrl = metadataNet.serverUrl;
  2210. _shareOC.shareLink = [app.sharesLink objectForKey:metadata.fileID];
  2211. _shareOC.shareUserAndGroup = [app.sharesUserAndGroup objectForKey:metadata.fileID];
  2212. [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
  2213. [self presentViewController:_shareOC animated:YES completion:nil];
  2214. }
  2215. }
  2216. [self tableViewReloadData];
  2217. }
  2218. - (void)shareFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2219. {
  2220. [_hud hideHud];
  2221. [app messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  2222. if (_shareOC)
  2223. [_shareOC reloadData];
  2224. [self tableViewReloadData];
  2225. if (errorCode == 401)
  2226. [self changePasswordAccount];
  2227. }
  2228. - (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password
  2229. {
  2230. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2231. metadataNet.action = actionShare;
  2232. metadataNet.fileID = metadata.fileID;
  2233. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl];
  2234. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2235. metadataNet.password = password;
  2236. metadataNet.selector = selectorShare;
  2237. metadataNet.serverUrl = serverUrl;
  2238. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2239. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2240. }
  2241. - (void)unShareSuccess:(CCMetadataNet *)metadataNet
  2242. {
  2243. [_hud hideHud];
  2244. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  2245. // rimuoviamo la condivisione da db
  2246. NSArray *result = [[NCManageDatabase sharedInstance] unShare:metadataNet.share fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl sharesLink:appDelegate.sharesLink sharesUserAndGroup:appDelegate.sharesUserAndGroup];
  2247. if (result) {
  2248. appDelegate.sharesLink = result[0];
  2249. appDelegate.sharesUserAndGroup = result[1];
  2250. }
  2251. if (_shareOC)
  2252. [_shareOC reloadData];
  2253. [self tableViewReloadData];
  2254. }
  2255. - (void)unShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl
  2256. {
  2257. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2258. metadataNet.action = actionUnShare;
  2259. metadataNet.fileID = metadata.fileID;
  2260. metadataNet.fileName = metadata.fileName;
  2261. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2262. metadataNet.selector = selectorUnshare;
  2263. metadataNet.serverUrl = serverUrl;
  2264. metadataNet.share = share;
  2265. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2266. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2267. }
  2268. - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission
  2269. {
  2270. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2271. metadataNet.action = actionUpdateShare;
  2272. metadataNet.fileID = metadata.fileID;
  2273. metadataNet.expirationTime = expirationTime;
  2274. metadataNet.password = password;
  2275. metadataNet.selector = selectorUpdateShare;
  2276. metadataNet.serverUrl = serverUrl;
  2277. metadataNet.share = share;
  2278. metadataNet.sharePermission = permission;
  2279. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2280. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2281. }
  2282. - (void)getUserAndGroupSuccess:(CCMetadataNet *)metadataNet items:(NSArray *)items
  2283. {
  2284. [_hud hideHud];
  2285. if (_shareOC)
  2286. [_shareOC reloadUserAndGroup:items];
  2287. }
  2288. - (void)getUserAndGroupFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2289. {
  2290. [_hud hideHud];
  2291. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  2292. }
  2293. - (void)getUserAndGroup:(NSString *)find
  2294. {
  2295. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2296. metadataNet.action = actionGetUserAndGroup;
  2297. metadataNet.options = find;
  2298. metadataNet.selector = selectorGetUserAndGroup;
  2299. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2300. [_hud visibleIndeterminateHud];
  2301. }
  2302. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(tableMetadata *)metadata directoryID:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  2303. {
  2304. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2305. metadataNet.action = actionShareWith;
  2306. metadataNet.fileID = metadata.fileID;
  2307. metadataNet.directoryID = directoryID;
  2308. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl];
  2309. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2310. metadataNet.serverUrl = serverUrl;
  2311. metadataNet.selector = selectorShare;
  2312. metadataNet.share = user;
  2313. metadataNet.shareeType = shareeType;
  2314. metadataNet.sharePermission = permission;
  2315. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2316. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2317. }
  2318. - (void)openWindowShare:(tableMetadata *)metadata
  2319. {
  2320. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  2321. if (!serverUrl) return;
  2322. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2323. metadataNet.action = actionReadShareServer;
  2324. metadataNet.fileID = metadata.fileID;
  2325. metadataNet.fileName = metadata.fileName;
  2326. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2327. metadataNet.selector = selectorOpenWindowShare;
  2328. metadataNet.serverUrl = serverUrl;
  2329. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2330. [_hud visibleIndeterminateHud];
  2331. }
  2332. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  2333. {
  2334. CGPoint location = [tapGesture locationInView:self.tableView];
  2335. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  2336. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2337. if (metadata)
  2338. [self openWindowShare:metadata];
  2339. }
  2340. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  2341. {
  2342. CGPoint location = [tapGesture locationInView:self.tableView];
  2343. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  2344. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2345. if (metadata) {
  2346. CCShareInfoCMOC *vc = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareInfoCMOC"];
  2347. vc.metadata = metadata;
  2348. [vc setModalPresentationStyle:UIModalPresentationFormSheet];
  2349. [self presentViewController:vc animated:YES completion:nil];
  2350. }
  2351. }
  2352. #pragma --------------------------------------------------------------------------------------------
  2353. #pragma mark ===== Favorite =====
  2354. #pragma --------------------------------------------------------------------------------------------
  2355. - (void)settingFavoriteSuccess:(CCMetadataNet *)metadataNet
  2356. {
  2357. _dateReadDataSource = nil;
  2358. [[NCManageDatabase sharedInstance] setMetadataFavoriteWithFileID:metadataNet.fileID favorite:[metadataNet.options boolValue]];
  2359. if (_isSearchMode)
  2360. [self readFolder:metadataNet.serverUrl];
  2361. else
  2362. [self reloadDatasource:metadataNet.serverUrl];
  2363. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataNet.fileID]];
  2364. if (metadata.directory && metadata.favorite) {
  2365. NSString *dir = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:metadata.fileNameData];
  2366. [app.activeFavorites addFavoriteFolder:dir];
  2367. }
  2368. }
  2369. - (void)settingFavoriteFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2370. {
  2371. }
  2372. - (void)addFavorite:(tableMetadata *)metadata
  2373. {
  2374. if (metadata.directory) {
  2375. [[CCActions sharedInstance] settingFavorite:metadata favorite:YES delegate:self];
  2376. } else {
  2377. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  2378. if (serverUrl)
  2379. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddFavorite selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2380. }
  2381. }
  2382. - (void)removeFavorite:(tableMetadata *)metadata
  2383. {
  2384. [[CCActions sharedInstance] settingFavorite:metadata favorite:NO delegate:self];
  2385. }
  2386. #pragma --------------------------------------------------------------------------------------------
  2387. #pragma mark ===== Local =====
  2388. #pragma --------------------------------------------------------------------------------------------
  2389. - (void)addLocal:(tableMetadata *)metadata
  2390. {
  2391. if (metadata.errorPasscode || !metadata.uuid) return;
  2392. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  2393. if (!serverUrl) return;
  2394. if ([metadata.type isEqualToString: k_metadataType_file])
  2395. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddLocal selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2396. if ([metadata.type isEqualToString: k_metadataType_template]) {
  2397. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileName]];
  2398. [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:0];
  2399. }
  2400. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2401. if ([self indexPathIsValid:indexPath])
  2402. [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2403. }
  2404. #pragma --------------------------------------------------------------------------------------------
  2405. #pragma mark ===== Open in... =====
  2406. #pragma --------------------------------------------------------------------------------------------
  2407. - (void)openIn:(tableMetadata *)metadata
  2408. {
  2409. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  2410. if (!serverUrl) return;
  2411. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2412. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2413. if ([self indexPathIsValid:indexPath])
  2414. [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2415. }
  2416. #pragma --------------------------------------------------------------------------------------------
  2417. #pragma mark ===== Remove Local File =====
  2418. #pragma --------------------------------------------------------------------------------------------
  2419. - (void)removeLocalFile:(tableMetadata *)metadata
  2420. {
  2421. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  2422. if (!serverUrl) return;
  2423. [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
  2424. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] error:nil];
  2425. [self reloadDatasource:serverUrl];
  2426. }
  2427. #pragma --------------------------------------------------------------------------------------------
  2428. #pragma mark ===== Order Table & GroupBy & DirectoryOnTop =====
  2429. #pragma --------------------------------------------------------------------------------------------
  2430. - (void)orderTable:(NSString *)order
  2431. {
  2432. [CCUtility setOrderSettings:order];
  2433. // Clear data-read of DataSource
  2434. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  2435. }
  2436. - (void)ascendingTable:(BOOL)ascending
  2437. {
  2438. [CCUtility setAscendingSettings:ascending];
  2439. // Clear data-read of DataSource
  2440. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  2441. }
  2442. - (void)directoryOnTop:(BOOL)directoryOnTop
  2443. {
  2444. [CCUtility setDirectoryOnTop:directoryOnTop];
  2445. // Clear data-read of DataSource
  2446. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  2447. }
  2448. - (void)tableGroupBy:(NSString *)groupBy
  2449. {
  2450. [CCUtility setGroupBySettings:groupBy];
  2451. // Clear data-read of DataSource
  2452. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
  2453. }
  2454. #pragma --------------------------------------------------------------------------------------------
  2455. #pragma mark ==== Menu LOGO ====
  2456. #pragma --------------------------------------------------------------------------------------------
  2457. - (void)menuLogo
  2458. {
  2459. if (app.reSelectMenu.isOpen || app.reMainMenu.isOpen)
  2460. return;
  2461. // Brand
  2462. if ([NCBrandOptions sharedInstance].disable_multiaccount)
  2463. return;
  2464. if ([app.netQueue operationCount] > 0 || [app.netQueueDownload operationCount] > 0 || [app.netQueueDownloadWWan operationCount] > 0 || [app.netQueueUpload operationCount] > 0 || [app.netQueueUploadWWan operationCount] > 0 || [[NCManageDatabase sharedInstance] countQueueUploadWithSession:nil] > 0) {
  2465. [app messageNotification:@"_transfers_in_queue_" description:nil visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  2466. return;
  2467. }
  2468. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  2469. NSMutableArray *menuArray = [NSMutableArray new];
  2470. for (NSString *account in listAccount) {
  2471. if ([account isEqualToString:app.activeAccount]) continue;
  2472. CCMenuItem *item = [[CCMenuItem alloc] init];
  2473. item.title = [account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  2474. item.argument = account;
  2475. item.image = [UIImage imageNamed:@"menuLogoUser"];
  2476. item.target = self;
  2477. item.action = @selector(changeDefaultAccount:);
  2478. [menuArray addObject:item];
  2479. }
  2480. if ([menuArray count] == 0)
  2481. return;
  2482. OptionalConfiguration options;
  2483. Color textColor, backgroundColor;
  2484. textColor.R = 0;
  2485. textColor.G = 0;
  2486. textColor.B = 0;
  2487. backgroundColor.R = 1;
  2488. backgroundColor.G = 1;
  2489. backgroundColor.B = 1;
  2490. NSInteger originY = 60;
  2491. options.arrowSize = 9;
  2492. options.marginXSpacing = 7;
  2493. options.marginYSpacing = 10;
  2494. options.intervalSpacing = 20;
  2495. options.menuCornerRadius = 6.5;
  2496. options.maskToBackground = NO;
  2497. options.shadowOfMenu = YES;
  2498. options.hasSeperatorLine = YES;
  2499. options.seperatorLineHasInsets = YES;
  2500. options.textColor = textColor;
  2501. options.menuBackgroundColor = backgroundColor;
  2502. CGRect rect = self.view.frame;
  2503. rect.origin.y = rect.origin.y + originY;
  2504. rect.size.height = rect.size.height - originY;
  2505. [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
  2506. [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
  2507. }
  2508. - (void)changeDefaultAccount:(CCMenuItem *)sender
  2509. {
  2510. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
  2511. // STOP, erase all in queue networking
  2512. [app cancelAllOperations];
  2513. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  2514. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  2515. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
  2516. if (tableAccount)
  2517. [app settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activePassword:tableAccount.password];
  2518. // go to home sweet home
  2519. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
  2520. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  2521. });
  2522. }
  2523. #pragma --------------------------------------------------------------------------------------------
  2524. #pragma mark ==== ReMenu ====
  2525. #pragma --------------------------------------------------------------------------------------------
  2526. - (void)createReMenuBackgroundView:(REMenu *)menu
  2527. {
  2528. __block CGFloat navigationBarH = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
  2529. _reMenuBackgroundView.frame = CGRectMake(0, navigationBarH, self.view.frame.size.width, self.view.frame.size.height);
  2530. [UIView animateWithDuration:0.2 animations:^{
  2531. float height = (self.view.frame.size.height + navigationBarH) - (menu.menuView.frame.size.height - self.navigationController.navigationBar.frame.size.height + 3);
  2532. if (height < self.tabBarController.tabBar.frame.size.height)
  2533. height = self.tabBarController.tabBar.frame.size.height;
  2534. _reMenuBackgroundView.frame = CGRectMake(0, self.view.frame.size.height + navigationBarH, self.view.frame.size.width, - height);
  2535. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  2536. }];
  2537. }
  2538. - (void)createReMainMenu
  2539. {
  2540. NSString *ordinamento;
  2541. NSString *groupBy = _directoryGroupBy;
  2542. __block NSString *nuovoOrdinamento;
  2543. NSString *titoloNuovo, *titoloAttuale;
  2544. BOOL ascendente;
  2545. __block BOOL nuovoAscendente;
  2546. UIImage *image;
  2547. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  2548. app.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"seleziona"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2549. if ([_sectionDataSource.allRecordsDataSource count] > 0) {
  2550. [self tableViewSelect:YES];
  2551. }
  2552. }];
  2553. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  2554. ordinamento = _directoryOrder;
  2555. if ([ordinamento isEqualToString:@"fileName"]) {
  2556. image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuOrdeyByDate"] color:[NCBrandColor sharedInstance].brand];
  2557. titoloNuovo = NSLocalizedString(@"_order_by_date_", nil);
  2558. titoloAttuale = NSLocalizedString(@"_current_order_name_", nil);
  2559. nuovoOrdinamento = @"date";
  2560. }
  2561. if ([ordinamento isEqualToString:@"date"]) {
  2562. image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuOrderByFileName"] color:[NCBrandColor sharedInstance].brand];
  2563. titoloNuovo = NSLocalizedString(@"_order_by_name_", nil);
  2564. titoloAttuale = NSLocalizedString(@"_current_order_date_", nil);
  2565. nuovoOrdinamento = @"fileName";
  2566. }
  2567. app.ordinaItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:titoloAttuale image:image highlightedImage:nil action:^(REMenuItem *item) {
  2568. [self orderTable:nuovoOrdinamento];
  2569. }];
  2570. // ITEM ASCENDING -----------------------------------------------------------------------------------------------------
  2571. ascendente = [CCUtility getAscendingSettings];
  2572. if (ascendente) {
  2573. image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuOrdinamentoDiscendente"] color:[NCBrandColor sharedInstance].brand];
  2574. titoloNuovo = NSLocalizedString(@"_sort_descending_", nil);
  2575. titoloAttuale = NSLocalizedString(@"_current_sort_ascending_", nil);
  2576. nuovoAscendente = false;
  2577. }
  2578. if (!ascendente) {
  2579. image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuOrdinamentoAscendente"] color:[NCBrandColor sharedInstance].brand];
  2580. titoloNuovo = NSLocalizedString(@"_sort_ascending_", nil);
  2581. titoloAttuale = NSLocalizedString(@"_current_sort_descending_", nil);
  2582. nuovoAscendente = true;
  2583. }
  2584. app.ascendenteItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:titoloAttuale image:image highlightedImage:nil action:^(REMenuItem *item) {
  2585. [self ascendingTable:nuovoAscendente];
  2586. }];
  2587. // ITEM ALPHABETIC -----------------------------------------------------------------------------------------------------
  2588. if ([groupBy isEqualToString:@"alphabetic"]) { titoloNuovo = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  2589. else { titoloNuovo = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  2590. app.alphabeticItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByAlphabetic"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2591. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2592. else [self tableGroupBy:@"alphabetic"];
  2593. }];
  2594. // ITEM TYPEFILE -------------------------------------------------------------------------------------------------------
  2595. if ([groupBy isEqualToString:@"typefile"]) { titoloNuovo = NSLocalizedString(@"_group_typefile_yes_", nil); }
  2596. else { titoloNuovo = NSLocalizedString(@"_group_typefile_no_", nil); }
  2597. app.typefileItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByTypeFile"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2598. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2599. else [self tableGroupBy:@"typefile"];
  2600. }];
  2601. // ITEM DATE -------------------------------------------------------------------------------------------------------
  2602. if ([groupBy isEqualToString:@"date"]) { titoloNuovo = NSLocalizedString(@"_group_date_yes_", nil); }
  2603. else { titoloNuovo = NSLocalizedString(@"_group_date_no_", nil); }
  2604. app.dateItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByDate"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2605. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2606. else [self tableGroupBy:@"date"];
  2607. }];
  2608. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  2609. if ([CCUtility getDirectoryOnTop]) { titoloNuovo = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  2610. else { titoloNuovo = NSLocalizedString(@"_directory_on_top_no_", nil); }
  2611. app.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"menuDirectoryOnTop"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2612. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2613. else [self directoryOnTop:YES];
  2614. }];
  2615. // REMENU --------------------------------------------------------------------------------------------------------------
  2616. app.reMainMenu = [[REMenu alloc] initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2617. app.reMainMenu.imageOffset = CGSizeMake(5, -1);
  2618. app.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2619. app.reMainMenu.imageOffset = CGSizeMake(0, 0);
  2620. app.reMainMenu.waitUntilAnimationIsComplete = NO;
  2621. app.reMainMenu.separatorHeight = 0.5;
  2622. app.reMainMenu.separatorColor = [NCBrandColor sharedInstance].seperator;
  2623. app.reMainMenu.backgroundColor = [NCBrandColor sharedInstance].menuBackground;
  2624. app.reMainMenu.textColor = [UIColor blackColor];
  2625. app.reMainMenu.textAlignment = NSTextAlignmentLeft;
  2626. app.reMainMenu.textShadowColor = nil;
  2627. app.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  2628. app.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  2629. app.reMainMenu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
  2630. app.reMainMenu.highlightedSeparatorColor = nil;
  2631. app.reMainMenu.highlightedTextColor = [UIColor blackColor];
  2632. app.reMainMenu.highlightedTextShadowColor = nil;
  2633. app.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2634. app.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  2635. app.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2636. app.reMainMenu.subtitleTextShadowColor = nil;
  2637. app.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2638. app.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2639. app.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2640. app.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2641. app.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  2642. app.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2643. app.reMainMenu.borderWidth = 0.3;
  2644. app.reMainMenu.borderColor = [UIColor lightGrayColor];
  2645. app.reMainMenu.animationDuration = 0.2;
  2646. app.reMainMenu.closeAnimationDuration = 0.2;
  2647. app.reMainMenu.bounce = NO;
  2648. [app.reMainMenu setClosePreparationBlock:^{
  2649. // Backgroun reMenu (Gesture)
  2650. [_reMenuBackgroundView removeFromSuperview];
  2651. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2652. }];
  2653. }
  2654. - (void)toggleReMainMenu
  2655. {
  2656. if (app.reMainMenu.isOpen) {
  2657. [app.reMainMenu close];
  2658. } else {
  2659. [self createReMainMenu];
  2660. [app.reMainMenu showFromNavigationController:self.navigationController];
  2661. // Backgroun reMenu & (Gesture)
  2662. [self createReMenuBackgroundView:app.reMainMenu];
  2663. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  2664. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2665. }
  2666. }
  2667. - (void)createReSelectMenu
  2668. {
  2669. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  2670. app.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"deleteSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2671. [self deleteFile];
  2672. }];
  2673. // ITEM MOVE ------------------------------------------------------------------------------------------------------
  2674. app.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"moveSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2675. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2676. }];
  2677. if (app.isCryptoCloudMode) {
  2678. // ITEM ENCRYPTED ------------------------------------------------------------------------------------------------------
  2679. app.encryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"encryptedSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2680. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil];
  2681. }];
  2682. // ITEM DECRYPTED ----------------------------------------------------------------------------------------------------
  2683. app.decryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"decryptedSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2684. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil];
  2685. }];
  2686. }
  2687. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  2688. app.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_folders_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"downloadSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2689. [self downloadSelectedFilesFolders];
  2690. }];
  2691. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  2692. app.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"saveSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
  2693. [self saveSelectedFiles];
  2694. }];
  2695. // REMENU --------------------------------------------------------------------------------------------------------------
  2696. if (app.isCryptoCloudMode) {
  2697. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2698. } else {
  2699. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.downloadItem, app.saveItem]];
  2700. }
  2701. app.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  2702. app.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2703. app.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  2704. app.reSelectMenu.waitUntilAnimationIsComplete = NO;
  2705. app.reSelectMenu.separatorHeight = 0.5;
  2706. app.reSelectMenu.separatorColor = [NCBrandColor sharedInstance].seperator;
  2707. app.reSelectMenu.backgroundColor = [NCBrandColor sharedInstance].menuBackground;
  2708. app.reSelectMenu.textColor = [UIColor blackColor];
  2709. app.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  2710. app.reSelectMenu.textShadowColor = nil;
  2711. app.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  2712. app.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  2713. app.reSelectMenu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
  2714. app.reSelectMenu.highlightedSeparatorColor = nil;
  2715. app.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  2716. app.reSelectMenu.highlightedTextShadowColor = nil;
  2717. app.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2718. app.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  2719. app.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2720. app.reSelectMenu.subtitleTextShadowColor = nil;
  2721. app.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2722. app.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2723. app.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2724. app.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2725. app.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  2726. app.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2727. app.reSelectMenu.borderWidth = 0.3;
  2728. app.reSelectMenu.borderColor = [UIColor lightGrayColor];
  2729. app.reSelectMenu.closeAnimationDuration = 0.2;
  2730. app.reSelectMenu.animationDuration = 0.2;
  2731. app.reSelectMenu.bounce = NO;
  2732. [app.reSelectMenu setClosePreparationBlock:^{
  2733. // Backgroun reMenu (Gesture)
  2734. [_reMenuBackgroundView removeFromSuperview];
  2735. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2736. }];
  2737. }
  2738. - (void)toggleReSelectMenu
  2739. {
  2740. if (app.reSelectMenu.isOpen) {
  2741. [app.reSelectMenu close];
  2742. } else {
  2743. [self createReSelectMenu];
  2744. [app.reSelectMenu showFromNavigationController:self.navigationController];
  2745. // Backgroun reMenu & (Gesture)
  2746. [self createReMenuBackgroundView:app.reSelectMenu];
  2747. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  2748. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2749. }
  2750. }
  2751. #pragma --------------------------------------------------------------------------------------------
  2752. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  2753. #pragma --------------------------------------------------------------------------------------------
  2754. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  2755. {
  2756. if (recognizer.state == UIGestureRecognizerStateBegan) {
  2757. UITableView *tableView = (UITableView*)self.view;
  2758. CGPoint touchPoint = [recognizer locationInView:self.view];
  2759. NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:touchPoint];
  2760. if ([self indexPathIsValid:indexPath])
  2761. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  2762. else
  2763. _metadata = nil;
  2764. [self becomeFirstResponder];
  2765. UIMenuController *menuController = [UIMenuController sharedMenuController];
  2766. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  2767. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  2768. UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
  2769. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  2770. UIMenuItem *pasteFileEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_encrypted_", nil) action:@selector(pasteFileEncrypted:)];
  2771. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  2772. UIMenuItem *pasteFilesEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_encrypted_", nil) action:@selector(pasteFilesEncrypted:)];
  2773. if (app.isCryptoCloudMode)
  2774. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, pasteFileEncryptedItem, pasteFilesEncryptedItem, nil]];
  2775. else
  2776. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, nil]];
  2777. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:tableView];
  2778. [menuController setMenuVisible:YES animated:YES];
  2779. }
  2780. }
  2781. - (BOOL)canBecomeFirstResponder
  2782. {
  2783. return YES;
  2784. }
  2785. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  2786. {
  2787. // For copy file, copy files, Open in ... :
  2788. //
  2789. // NO Directory
  2790. // NO Error Passcode
  2791. // NO In Session mode (download/upload)
  2792. // NO Template
  2793. if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
  2794. if (_isSelectedMode == NO && _metadata && !_metadata.directory && !_metadata.errorPasscode && [_metadata.session length] == 0 && ![_metadata.typeFile isEqualToString: k_metadataTypeFile_template]) {
  2795. // NO Cryptated with Title lenght = 0
  2796. if (!_metadata.cryptated || (_metadata.cryptated && _metadata.title.length > 0))
  2797. return YES;
  2798. }
  2799. return NO;
  2800. }
  2801. if (@selector(copyFiles:) == action) {
  2802. if (_isSelectedMode) {
  2803. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2804. for (tableMetadata *metadata in selectedMetadatas) {
  2805. if (!metadata.directory && !metadata.errorPasscode && metadata.session.length == 0 && ![metadata.typeFile isEqualToString: k_metadataTypeFile_template]) {
  2806. // NO Cryptated with Title lenght = 0
  2807. if (!metadata.cryptated || (metadata.cryptated && metadata.title.length > 0))
  2808. return YES;
  2809. }
  2810. }
  2811. }
  2812. return NO;
  2813. }
  2814. if (@selector(pasteFile:) == action || @selector(pasteFileEncrypted:) == action) {
  2815. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2816. NSArray *items = [pasteboard items];
  2817. if ([items count] == 1) {
  2818. // Value : (NSData) fileID
  2819. NSDictionary *dic = [items objectAtIndex:0];
  2820. NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
  2821. NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
  2822. if (fileID) {
  2823. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  2824. if (metadata) {
  2825. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account = %@", metadata.account]];
  2826. if (account) {
  2827. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2828. if (directoryUser)
  2829. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]])
  2830. return YES;
  2831. }
  2832. }
  2833. }
  2834. }
  2835. return NO;
  2836. }
  2837. if (@selector(pasteFiles:) == action || @selector(pasteFilesEncrypted:) == action) {
  2838. BOOL isValid = NO;
  2839. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2840. NSArray *items = [pasteboard items];
  2841. if ([items count] <= 1) return NO;
  2842. for (NSDictionary *dic in items) {
  2843. // Value : (NSData) fileID
  2844. NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
  2845. NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
  2846. if (fileID) {
  2847. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  2848. if (metadata) {
  2849. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account = %@", metadata.account]];
  2850. if (account) {
  2851. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2852. if (directoryUser) {
  2853. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]]) {
  2854. isValid = YES;
  2855. } else {
  2856. isValid = NO;
  2857. break;
  2858. }
  2859. } else {
  2860. isValid = NO;
  2861. break;
  2862. }
  2863. } else {
  2864. isValid = NO;
  2865. break;
  2866. }
  2867. } else {
  2868. isValid = NO;
  2869. break;
  2870. }
  2871. } else {
  2872. isValid = NO;
  2873. break;
  2874. }
  2875. }
  2876. return isValid;
  2877. }
  2878. return NO;
  2879. }
  2880. /************************************ COPY ************************************/
  2881. - (void)copyFile:(id)sender
  2882. {
  2883. // Remove all item
  2884. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2885. pasteboard.items = [[NSArray alloc] init];
  2886. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser,_metadata.fileID]]) {
  2887. [self copyFileToPasteboard:_metadata];
  2888. } else {
  2889. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  2890. if (serverUrl)
  2891. [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2892. }
  2893. }
  2894. - (void)copyFiles:(id)sender
  2895. {
  2896. // Remove all item
  2897. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2898. pasteboard.items = [[NSArray alloc] init];
  2899. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2900. for (tableMetadata *metadata in selectedMetadatas) {
  2901. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]]) {
  2902. [self copyFileToPasteboard:metadata];
  2903. } else {
  2904. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  2905. if (serverUrl)
  2906. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  2907. }
  2908. }
  2909. [self tableViewSelect:NO];
  2910. }
  2911. - (void)copyFileToPasteboard:(tableMetadata *)metadata
  2912. {
  2913. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2914. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  2915. // Value : (NSData) fileID
  2916. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata.fileID], k_metadataKeyedUnarchiver,nil];
  2917. [items addObject:item];
  2918. [pasteboard setItems:items];
  2919. }
  2920. /************************************ OPEN IN ... ************************************/
  2921. - (void)openinFile:(id)sender
  2922. {
  2923. [self openIn:_metadata];
  2924. }
  2925. /************************************ PASTE ************************************/
  2926. - (void)pasteFile:(id)sender
  2927. {
  2928. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2929. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2930. }
  2931. - (void)pasteFileEncrypted:(id)sender
  2932. {
  2933. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2934. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2935. }
  2936. - (void)pasteFiles:(id)sender
  2937. {
  2938. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2939. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2940. }
  2941. - (void)pasteFilesEncrypted:(id)sender
  2942. {
  2943. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2944. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2945. }
  2946. - (void)uploadFilePasteArray:(NSArray *)items cryptated:(BOOL)cryptated
  2947. {
  2948. float timer = 0;
  2949. for (NSDictionary *dic in items) {
  2950. // Value : (NSData) fileID
  2951. NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
  2952. NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
  2953. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  2954. if (metadata) {
  2955. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account = %@", metadata.account]];
  2956. if (account) {
  2957. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2958. if (directoryUser) {
  2959. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]]) {
  2960. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint]];
  2961. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timer * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  2962. [[CCNetworking sharedNetworking] uploadFile:metadata.fileNamePrint serverUrl:_serverUrl cryptated:cryptated onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
  2963. });
  2964. timer += 0.1;
  2965. }
  2966. }
  2967. }
  2968. }
  2969. }
  2970. }
  2971. #pragma --------------------------------------------------------------------------------------------
  2972. #pragma mark ===== Lock Passcode =====
  2973. #pragma --------------------------------------------------------------------------------------------
  2974. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  2975. {
  2976. return _failedAttempts;
  2977. }
  2978. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2979. {
  2980. return _lockUntilDate;
  2981. }
  2982. - (void)passcodeViewCloseButtonPressed:(id)sender
  2983. {
  2984. [self dismissViewControllerAnimated:YES completion:nil];
  2985. }
  2986. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2987. {
  2988. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2989. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2990. _lockUntilDate = nil;
  2991. _failedAttempts = 0;
  2992. aResultHandler(YES);
  2993. } else aResultHandler(NO);
  2994. } else aResultHandler(YES);
  2995. }
  2996. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2997. {
  2998. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2999. switch (aViewController.type) {
  3000. case BKPasscodeViewControllerCheckPasscodeType: {
  3001. if (aViewController.fromType == CCBKPasscodeFromPasscode) {
  3002. // verifichiamo se il passcode è corretto per il seguente file -> UUID
  3003. if ([[CCCrypto sharedManager] verifyPasscode:aPasscode uuid:_metadata.uuid text:_metadata.title]) {
  3004. // scriviamo il passcode
  3005. [CCUtility setKeyChainPasscodeForUUID:_metadata.uuid conPasscode:aPasscode];
  3006. [self readFolder:_serverUrl];
  3007. } else {
  3008. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_error_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3009. [alertView show];
  3010. }
  3011. }
  3012. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  3013. // possiamo procedere alla prossima directory
  3014. [self performSegueDirectoryWithControlPasscode:false];
  3015. // avviamo la sessione Passcode Lock con now
  3016. app.sessionePasscodeLock = [NSDate date];
  3017. }
  3018. // disattivazione lock cartella
  3019. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  3020. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  3021. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3022. if (![[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:NO]) {
  3023. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  3024. }
  3025. [self tableViewReloadData];
  3026. }
  3027. }
  3028. break;
  3029. default:
  3030. break;
  3031. }
  3032. }
  3033. - (void)comandoLockPassword
  3034. {
  3035. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  3036. if (!serverUrl) return;
  3037. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3038. // se non è abilitato il Lock Passcode esci
  3039. if ([[CCUtility getBlockCode] length] == 0) {
  3040. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3041. [alertView show];
  3042. return;
  3043. }
  3044. // se è richiesta la disattivazione si chiede la password
  3045. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, lockServerUrl]];
  3046. if (directory.lock) {
  3047. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  3048. viewController.delegate = self;
  3049. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  3050. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  3051. viewController.inputViewTitlePassword = YES;
  3052. if ([CCUtility getSimplyBlockCode]) {
  3053. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  3054. viewController.passcodeInputView.maximumLength = 6;
  3055. } else {
  3056. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  3057. viewController.passcodeInputView.maximumLength = 64;
  3058. }
  3059. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  3060. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  3061. viewController.touchIDManager = touchIDManager;
  3062. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  3063. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3064. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  3065. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3066. [self presentViewController:navigationController animated:YES completion:nil];
  3067. return;
  3068. }
  3069. // ---------------- ACTIVATE PASSWORD
  3070. if ([[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:YES]) {
  3071. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  3072. if ([self indexPathIsValid:indexPath])
  3073. [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  3074. } else {
  3075. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  3076. }
  3077. }
  3078. #pragma mark -
  3079. #pragma --------------------------------------------------------------------------------------------
  3080. #pragma mark ===== Swipe Tablet -> menu =====
  3081. #pragma --------------------------------------------------------------------------------------------
  3082. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
  3083. {
  3084. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  3085. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3086. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
  3087. return NO;
  3088. if (metadata == nil || metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier != k_taskIdentifierDone || metadata.sessionTaskIdentifier != k_taskIdentifierDone)
  3089. return NO;
  3090. else
  3091. return YES;
  3092. }
  3093. -(void)swipeTableCell:(nonnull MGSwipeTableCell *)cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL)gestureIsActive
  3094. {
  3095. }
  3096. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
  3097. {
  3098. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  3099. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3100. if (direction == MGSwipeDirectionRightToLeft) {
  3101. // Delete
  3102. if (index == 0)
  3103. [self swipeDelete:indexPath];
  3104. // More
  3105. if (index == 1) {
  3106. [cell hideSwipeAnimated:NO];
  3107. [self performSelector:@selector(swipeMore:) withObject:indexPath afterDelay:0.1];
  3108. }
  3109. }
  3110. if (direction == MGSwipeDirectionLeftToRight) {
  3111. if (_metadata.favorite)
  3112. [self removeFavorite:_metadata];
  3113. else
  3114. [self addFavorite:_metadata];
  3115. }
  3116. return YES;
  3117. }
  3118. - (void)swipeDelete:(NSIndexPath *)indexPath
  3119. {
  3120. // Directory locked ?
  3121. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:[[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID] addFileName:_metadata.fileNameData];
  3122. if (!lockServerUrl) return;
  3123. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, lockServerUrl]];
  3124. if (directory.lock && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) {
  3125. [app messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
  3126. return;
  3127. }
  3128. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  3129. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  3130. [self performSelector:@selector(deleteFile) withObject:nil];
  3131. }]];
  3132. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  3133. [alertController dismissViewControllerAnimated:YES completion:nil];
  3134. }]];
  3135. alertController.popoverPresentationController.sourceView = self.view;
  3136. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  3137. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  3138. [alertController.view layoutIfNeeded];
  3139. [self presentViewController:alertController animated:YES completion:nil];
  3140. }
  3141. - (void)swipeMore:(NSIndexPath *)indexPath
  3142. {
  3143. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  3144. if (!serverUrl) return;
  3145. NSString *titoloCriptaDecripta, *titoloLock, *titleFavorite;
  3146. if (_metadata.cryptated) titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_decrypt_", nil)];
  3147. else titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_encrypt_", nil)];
  3148. if (_metadata.favorite) {
  3149. titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_remove_favorites_", nil)];
  3150. } else {
  3151. titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_add_favorites_", nil)];
  3152. }
  3153. if (_metadata.directory) {
  3154. // calcolo lockServerUrl
  3155. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3156. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, lockServerUrl]];
  3157. if (directory.lock)
  3158. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  3159. else
  3160. titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  3161. }
  3162. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", _metadata.fileID]];
  3163. // ******************************************* AHKActionSheet *******************************************
  3164. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  3165. actionSheet.animationDuration = 0.2;
  3166. actionSheet.blurRadius = 0.0f;
  3167. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  3168. actionSheet.buttonHeight = 50.0;
  3169. actionSheet.cancelButtonHeight = 50.0f;
  3170. actionSheet.separatorHeight = 5.0f;
  3171. actionSheet.automaticallyTintButtonImages = @(NO);
  3172. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].cryptocloud };
  3173. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
  3174. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].brand };
  3175. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
  3176. actionSheet.separatorColor = [NCBrandColor sharedInstance].seperator;
  3177. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  3178. // ******************************************* DIRECTORY *******************************************
  3179. if (_metadata.directory) {
  3180. BOOL lockDirectory = NO;
  3181. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  3182. // Directory bloccata ?
  3183. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, dirServerUrl]];
  3184. if (directory.lock && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3185. NSString *autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
  3186. NSString *autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:app.activeUrl];
  3187. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3188. image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:_metadata.iconName] color:[NCBrandColor sharedInstance].brand]
  3189. backgroundColor: [NCBrandColor sharedInstance].tabBar
  3190. height: 50.0
  3191. type: AHKActionSheetButtonTypeDisabled
  3192. handler: nil
  3193. ];
  3194. if (_metadata.cryptated == NO && !lockDirectory) {
  3195. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3196. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand]
  3197. backgroundColor:[UIColor whiteColor]
  3198. height: 50.0
  3199. type:AHKActionSheetButtonTypeDefault
  3200. handler:^(AHKActionSheet *as) {
  3201. [self openWindowShare:_metadata];
  3202. }];
  3203. }
  3204. if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && !lockDirectory) {
  3205. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3206. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetRename"] color:[NCBrandColor sharedInstance].brand]
  3207. backgroundColor:[UIColor whiteColor]
  3208. height: 50.0
  3209. type:AHKActionSheetButtonTypeDefault
  3210. handler:^(AHKActionSheet *as) {
  3211. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  3212. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  3213. textField.text = _metadata.fileNamePrint;
  3214. //textField.selectedTextRange = [textField textRangeFromPosition:textField.beginningOfDocument toPosition:textField.endOfDocument];
  3215. //textField.delegate = self;
  3216. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  3217. }];
  3218. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  3219. NSLog(@"Cancel action");
  3220. }];
  3221. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  3222. UITextField *fileName = alertController.textFields.firstObject;
  3223. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:_metadata,fileName.text, nil] waitUntilDone:NO];
  3224. }];
  3225. okAction.enabled = NO;
  3226. [alertController addAction:cancelAction];
  3227. [alertController addAction:okAction];
  3228. [self presentViewController:alertController animated:YES completion:nil];
  3229. }];
  3230. }
  3231. if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && !lockDirectory) {
  3232. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3233. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetMove"] color:[NCBrandColor sharedInstance].brand]
  3234. backgroundColor:[UIColor whiteColor]
  3235. height: 50.0
  3236. type:AHKActionSheetButtonTypeDefault
  3237. handler:^(AHKActionSheet *as) {
  3238. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3239. }];
  3240. }
  3241. if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && _metadata.cryptated == NO) {
  3242. [actionSheet addButtonWithTitle:NSLocalizedString(@"_folder_automatic_upload_", nil)
  3243. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folderphotocamera"] color:[NCBrandColor sharedInstance].brand]
  3244. backgroundColor:[UIColor whiteColor]
  3245. height: 50.0
  3246. type:AHKActionSheetButtonTypeDefault
  3247. handler:^(AHKActionSheet *as) {
  3248. // Settings new folder Automatatic upload
  3249. NSString *oldAutoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:app.activeUrl];
  3250. [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:_metadata.fileName];
  3251. [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:serverUrl activeUrl:app.activeUrl];
  3252. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:oldAutoUploadDirectory directoryID:nil];
  3253. if (app.activeAccount.length > 0 && app.activePhotos)
  3254. [app.activePhotos reloadDatasourceForced];
  3255. [self readFolder:serverUrl];
  3256. NSLog(@"[LOG] Update Folder Photo");
  3257. NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:app.activeUrl];
  3258. if ([autoUploadPath length] > 0)
  3259. [[CCSynchronize sharedSynchronize] synchronizedFolder:autoUploadPath selector:selectorReadFolder];
  3260. }];
  3261. }
  3262. if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES)) {
  3263. [actionSheet addButtonWithTitle:titoloLock
  3264. image:[UIImage imageNamed:@"actionSheetLock"]
  3265. backgroundColor:[UIColor whiteColor]
  3266. height: 50.0
  3267. type:AHKActionSheetButtonTypeEncrypted
  3268. handler:^(AHKActionSheet *as) {
  3269. [self performSelector:@selector(comandoLockPassword) withObject:nil];
  3270. }];
  3271. }
  3272. if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && !lockDirectory && app.isCryptoCloudMode) {
  3273. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3274. image:[UIImage imageNamed:@"actionSheetCrypto"]
  3275. backgroundColor:[UIColor whiteColor]
  3276. height: 50.0
  3277. type:AHKActionSheetButtonTypeEncrypted
  3278. handler:^(AHKActionSheet *as) {
  3279. [self performSelector:@selector(encyptedDecryptedFolder) withObject:nil];
  3280. }];
  3281. }
  3282. [actionSheet show];
  3283. }
  3284. // ******************************************* FILE *******************************************
  3285. if ([_metadata.type isEqualToString: k_metadataType_file] && !_metadata.directory) {
  3286. UIImage *iconHeader;
  3287. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3288. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]])
  3289. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]];
  3290. else
  3291. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3292. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3293. image: iconHeader
  3294. backgroundColor: [NCBrandColor sharedInstance].tabBar
  3295. height: 50.0
  3296. type: AHKActionSheetButtonTypeDisabled
  3297. handler: nil
  3298. ];
  3299. if (_metadata.cryptated == NO) {
  3300. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3301. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand]
  3302. backgroundColor:[UIColor whiteColor]
  3303. height: 50.0
  3304. type:AHKActionSheetButtonTypeDefault
  3305. handler:^(AHKActionSheet *as) {
  3306. [self openWindowShare:_metadata];
  3307. }];
  3308. }
  3309. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  3310. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetOpenIn"] color:[NCBrandColor sharedInstance].brand]
  3311. backgroundColor:[UIColor whiteColor]
  3312. height: 50.0
  3313. type:AHKActionSheetButtonTypeDefault
  3314. handler:^(AHKActionSheet *as) {
  3315. [self performSelector:@selector(openIn:) withObject:_metadata];
  3316. }];
  3317. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3318. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetRename"] color:[NCBrandColor sharedInstance].brand]
  3319. backgroundColor:[UIColor whiteColor]
  3320. height: 50.0
  3321. type:AHKActionSheetButtonTypeDefault
  3322. handler:^(AHKActionSheet *as) {
  3323. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  3324. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  3325. //textField.placeholder = _metadata.fileNamePrint;
  3326. textField.text = _metadata.fileNamePrint;
  3327. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  3328. }];
  3329. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  3330. NSLog(@"Cancel action");
  3331. }];
  3332. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  3333. UITextField *fileName = alertController.textFields.firstObject;
  3334. [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:_metadata,fileName.text, nil] waitUntilDone:NO];
  3335. }];
  3336. okAction.enabled = NO;
  3337. [alertController addAction:cancelAction];
  3338. [alertController addAction:okAction];
  3339. [self presentViewController:alertController animated:YES completion:nil];
  3340. }];
  3341. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3342. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetMove"] color:[NCBrandColor sharedInstance].brand]
  3343. backgroundColor:[UIColor whiteColor]
  3344. height: 50.0
  3345. type:AHKActionSheetButtonTypeDefault
  3346. handler:^(AHKActionSheet *as) {
  3347. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3348. }];
  3349. if (localFile || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
  3350. [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_local_file_", nil)
  3351. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetRemoveLocal"] color:[NCBrandColor sharedInstance].brand]
  3352. backgroundColor:[UIColor whiteColor]
  3353. height: 50.0
  3354. type:AHKActionSheetButtonTypeDefault
  3355. handler:^(AHKActionSheet *as) {
  3356. [self performSelector:@selector(removeLocalFile:) withObject:_metadata];
  3357. }];
  3358. }
  3359. if (app.isCryptoCloudMode) {
  3360. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3361. image:[UIImage imageNamed:@"actionSheetCrypto"]
  3362. backgroundColor:[UIColor whiteColor]
  3363. height: 50.0
  3364. type:AHKActionSheetButtonTypeEncrypted
  3365. handler:^(AHKActionSheet *as) {
  3366. [self performSelector:@selector(cmdEncryptedDecryptedFile) withObject:nil];
  3367. }];
  3368. }
  3369. #ifdef DEBUG
  3370. /*
  3371. [actionSheet addButtonWithTitle:@"Hide file"
  3372. image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"admin"] color:[NCBrandColor sharedInstance].brand]
  3373. backgroundColor:[UIColor whiteColor]
  3374. height: 50.0
  3375. type:AHKActionSheetButtonTypeDefault
  3376. handler:^(AHKActionSheet *as) {
  3377. [[NCManageDatabase sharedInstance] setMetadataStatusWithFileID:_metadata.fileID status:k_metadataStatusHide];
  3378. [self reloadDatasource];
  3379. }];
  3380. */
  3381. #endif
  3382. [actionSheet show];
  3383. }
  3384. // ******************************************* TEMPLATE *******************************************
  3385. if ([_metadata.type isEqualToString: k_metadataType_template]) {
  3386. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3387. image: [UIImage imageNamed:_metadata.iconName]
  3388. backgroundColor: [NCBrandColor sharedInstance].tabBar
  3389. height: 50.0
  3390. type: AHKActionSheetButtonTypeDisabled
  3391. handler: nil
  3392. ];
  3393. if ([_metadata.model isEqualToString:@"note"]) {
  3394. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3395. image:[UIImage imageNamed:@"actionSheetRename"]
  3396. backgroundColor:[UIColor whiteColor]
  3397. height: 50.0
  3398. type:AHKActionSheetButtonTypeDefault
  3399. handler:^(AHKActionSheet *as) {
  3400. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  3401. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  3402. textField.placeholder = _metadata.fileNamePrint;
  3403. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  3404. }];
  3405. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  3406. NSLog(@"Cancel action");
  3407. }];
  3408. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  3409. UITextField *fileName = alertController.textFields.firstObject;
  3410. [self performSelectorOnMainThread:@selector(renameNote:) withObject:[NSMutableArray arrayWithObjects:_metadata,fileName.text, nil] waitUntilDone:NO];
  3411. }];
  3412. okAction.enabled = NO;
  3413. [alertController addAction:cancelAction];
  3414. [alertController addAction:okAction];
  3415. [self presentViewController:alertController animated:YES completion:nil];
  3416. }];
  3417. }
  3418. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3419. image:[UIImage imageNamed:@"actionSheetMove"]
  3420. backgroundColor:[UIColor whiteColor]
  3421. height: 50.0
  3422. type:AHKActionSheetButtonTypeDefault
  3423. handler:^(AHKActionSheet *as) {
  3424. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3425. }];
  3426. [actionSheet show];
  3427. }
  3428. }
  3429. #pragma --------------------------------------------------------------------------------------------
  3430. #pragma mark - ==== Datasource ====
  3431. #pragma --------------------------------------------------------------------------------------------
  3432. - (void)clearDateReadDataSource:(NSNotification *)notification
  3433. {
  3434. _dateReadDataSource = Nil;
  3435. [self reloadDatasource];
  3436. }
  3437. - (void)reloadDatasource
  3438. {
  3439. [self reloadDatasource:_serverUrl];
  3440. }
  3441. - (void)reloadDatasource:(NSString *)serverUrl
  3442. {
  3443. // test
  3444. if (app.activeAccount.length == 0 || serverUrl.length == 0 || serverUrl == nil)
  3445. return;
  3446. // Search Mode
  3447. if(_isSearchMode) {
  3448. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:_searchResultMetadatas listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3449. [self tableViewReloadData];
  3450. if ([_sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] >= k_minCharsSearch) {
  3451. _noFilesSearchTitle = NSLocalizedString(@"_search_no_record_found_", nil);
  3452. _noFilesSearchDescription = @"";
  3453. }
  3454. if ([_sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] < k_minCharsSearch) {
  3455. _noFilesSearchTitle = @"";
  3456. _noFilesSearchDescription = NSLocalizedString(@"_search_instruction_", nil);
  3457. }
  3458. [self.tableView reloadEmptyDataSet];
  3459. return;
  3460. }
  3461. // Reload -> Self se non siamo nella dir appropriata cercala e se è in memoria reindirizza il reload
  3462. if ([serverUrl isEqualToString:_serverUrl] == NO || _serverUrl == nil) {
  3463. CCMain *main = [app.listMainVC objectForKey:serverUrl];
  3464. if (main) {
  3465. [main reloadDatasource];
  3466. } else {
  3467. [self tableViewReloadData];
  3468. [app.activeTransfers reloadDatasource];
  3469. }
  3470. return;
  3471. }
  3472. [app.activeTransfers reloadDatasource];
  3473. // Settaggio variabili per le ottimizzazioni
  3474. _directoryGroupBy = [CCUtility getGroupBySettings];
  3475. _directoryOrder = [CCUtility getOrderSettings];
  3476. // Controllo data lettura Data Source
  3477. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, serverUrl]];
  3478. NSDate *dateDateRecordDirectory = directory.dateReadDirectory;
  3479. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  3480. NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
  3481. _dateReadDataSource = [NSDate date];
  3482. // Data Source
  3483. NSString *sorted = _directoryOrder;
  3484. if ([sorted isEqualToString:@"fileName"])
  3485. sorted = @"fileNamePrint";
  3486. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
  3487. if (directoryID) {
  3488. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND status = %i", app.activeAccount, directoryID, k_metadataStatusNormal] sorted:sorted ascending:[CCUtility getAscendingSettings]];
  3489. _sectionDataSource = [CCSectionDataSourceMetadata new];
  3490. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3491. }
  3492. } else {
  3493. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
  3494. }
  3495. [self tableViewReloadData];
  3496. }
  3497. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  3498. {
  3499. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  3500. if (selectedRows.count > 0) {
  3501. for (NSIndexPath *selectionIndex in selectedRows) {
  3502. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  3503. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3504. [metadatas addObject:metadata];
  3505. }
  3506. }
  3507. return metadatas;
  3508. }
  3509. - (tableMetadata *)getMetadataFromSectionDataSource:(NSIndexPath *)indexPath
  3510. {
  3511. NSInteger section = indexPath.section + 1;
  3512. NSInteger row = indexPath.row + 1;
  3513. NSInteger totSections = [_sectionDataSource.sections count] ;
  3514. if ((totSections < section) || (section > totSections)) {
  3515. NSLog(@"[LOG] %@", [NSString stringWithFormat:@"DEBUG [0] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section]);
  3516. return nil;
  3517. }
  3518. id valueSection = [_sectionDataSource.sections objectAtIndex:indexPath.section];
  3519. NSArray *fileIDs = [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3520. if (fileIDs) {
  3521. NSInteger totRows =[fileIDs count] ;
  3522. if ((totRows < row) || (row > totRows)) {
  3523. NSLog(@"[LOG] %@", [NSString stringWithFormat:@"DEBUG [1] : error row, totRows = %lu - row = %lu", (long)totRows, (long)row]);
  3524. return nil;
  3525. }
  3526. } else {
  3527. NSLog(@"[LOG] DEBUG [2] : fileIDs is NIL");
  3528. return nil;
  3529. }
  3530. NSString *fileID = [fileIDs objectAtIndex:indexPath.row];
  3531. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3532. return metadata;
  3533. }
  3534. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  3535. {
  3536. NSInteger totSections =[_sectionDataSource.sections count] ;
  3537. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  3538. #if DEBUG
  3539. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:[NSString stringWithFormat:@"DEBUG [3] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section] delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3540. [alertView show];
  3541. #endif
  3542. return nil;
  3543. }
  3544. id valueSection = [_sectionDataSource.sections objectAtIndex:section];
  3545. return [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3546. }
  3547. #pragma --------------------------------------------------------------------------------------------
  3548. #pragma mark - ==== Table ====
  3549. #pragma --------------------------------------------------------------------------------------------
  3550. - (void)tableViewSelect:(BOOL)edit
  3551. {
  3552. // chiudiamo eventuali swipe aperti
  3553. if (edit)
  3554. [self.tableView setEditing:NO animated:NO];
  3555. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  3556. [self.tableView setEditing:edit animated:YES];
  3557. _isSelectedMode = edit;
  3558. if (edit)
  3559. [self setUINavigationBarSelected];
  3560. else
  3561. [self setUINavigationBarDefault];
  3562. [_selectedFileIDsMetadatas removeAllObjects];
  3563. [self setTitle];
  3564. }
  3565. - (void)tableViewReloadData
  3566. {
  3567. // store selected cells before relod
  3568. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  3569. //store swipeOffset before relod
  3570. [_statusSwipeCell removeAllObjects];
  3571. for (MGSwipeTableCell *cell in self.tableView.visibleCells) {
  3572. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  3573. [_statusSwipeCell setObject:[NSNumber numberWithDouble:cell.swipeOffset] forKey:indexPath];
  3574. }
  3575. // reload table view
  3576. [self.tableView reloadData];
  3577. // selected cells stored
  3578. for (NSIndexPath *path in indexPaths)
  3579. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  3580. [self setTableViewFooter];
  3581. if (self.tableView.editing)
  3582. [self setTitle];
  3583. }
  3584. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  3585. {
  3586. if (tableView.editing == 1) {
  3587. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3588. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
  3589. return NO;
  3590. if (metadata == nil || metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier != k_taskIdentifierDone || metadata.sessionTaskIdentifier != k_taskIdentifierDone)
  3591. return NO;
  3592. else
  3593. return YES;
  3594. } else {
  3595. [_selectedFileIDsMetadatas removeAllObjects];
  3596. }
  3597. return YES;
  3598. }
  3599. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  3600. {
  3601. return 60;
  3602. }
  3603. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  3604. {
  3605. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  3606. }
  3607. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  3608. {
  3609. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  3610. }
  3611. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  3612. {
  3613. NSArray *sections = [_sectionDataSource.sectionArrayRow allKeys];
  3614. NSString *sectionTitle = [sections objectAtIndex:section];
  3615. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  3616. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  3617. if ([_directoryGroupBy isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
  3618. return 20.f;
  3619. }
  3620. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3621. {
  3622. float shift;
  3623. UIVisualEffectView *visualEffectView;
  3624. NSString *titleSection;
  3625. if (![self indexPathIsValid:[NSIndexPath indexPathForRow:0 inSection:section]])
  3626. return nil;
  3627. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  3628. titleSection = [_sectionDataSource.sections objectAtIndex:section];
  3629. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]])
  3630. titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  3631. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  3632. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  3633. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  3634. else titleSection = NSLocalizedString(titleSection,nil);
  3635. // Format title
  3636. NSString *currentDevice = [CCUtility currentDevice];
  3637. if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
  3638. visualEffectView = [[UIVisualEffectView alloc] init];
  3639. visualEffectView.backgroundColor = [[NCBrandColor sharedInstance].brand colorWithAlphaComponent:0.3];
  3640. } else {
  3641. UIVisualEffect *blurEffect;
  3642. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  3643. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  3644. visualEffectView.backgroundColor = [[NCBrandColor sharedInstance].brand colorWithAlphaComponent:0.2];
  3645. }
  3646. if ([_directoryGroupBy isEqualToString:@"alphabetic"]) {
  3647. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  3648. shift = - 35;
  3649. else
  3650. shift = - 20;
  3651. } else shift = - 10;
  3652. // Title
  3653. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  3654. titleLabel.backgroundColor = [UIColor clearColor];
  3655. titleLabel.textColor = [UIColor blackColor];
  3656. titleLabel.font = [UIFont systemFontOfSize:12];
  3657. titleLabel.textAlignment = NSTextAlignmentLeft;
  3658. titleLabel.text = titleSection;
  3659. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3660. [visualEffectView addSubview:titleLabel];
  3661. // Elements
  3662. UILabel *elementLabel= [[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  3663. elementLabel.backgroundColor = [UIColor clearColor];
  3664. elementLabel.textColor = [UIColor blackColor];;
  3665. elementLabel.font = [UIFont systemFontOfSize:12];
  3666. elementLabel.textAlignment = NSTextAlignmentRight;
  3667. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3668. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  3669. NSUInteger rowsCount = [metadatas count];
  3670. if (rowsCount == 0) return nil;
  3671. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  3672. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  3673. [visualEffectView addSubview:elementLabel];
  3674. return visualEffectView;
  3675. }
  3676. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  3677. {
  3678. return [_sectionDataSource.sections indexOfObject:title];
  3679. }
  3680. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  3681. {
  3682. if ([_directoryGroupBy isEqualToString:@"alphabetic"])
  3683. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  3684. else
  3685. return nil;
  3686. }
  3687. /*
  3688. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  3689. {
  3690. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  3691. }
  3692. }
  3693. */
  3694. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  3695. {
  3696. NSString *typeCell;
  3697. NSString *dataFile;
  3698. NSString *lunghezzaFile;
  3699. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3700. if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
  3701. return [tableView dequeueReusableCellWithIdentifier:@"CellMainTransfer"];
  3702. }
  3703. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  3704. if (!serverUrl)
  3705. return [tableView dequeueReusableCellWithIdentifier:@"CellMainTransfer"];
  3706. if ([metadata.session isEqualToString:@""] || metadata.session == nil) typeCell = @"CellMain";
  3707. else typeCell = @"CellMainTransfer";
  3708. CCCellMainTransfer *cell = (CCCellMainTransfer *)[tableView dequeueReusableCellWithIdentifier:typeCell forIndexPath:indexPath];
  3709. // variable base
  3710. cell.delegate = self;
  3711. cell.indexPath = indexPath;
  3712. // separator
  3713. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  3714. // change color selection
  3715. UIView *selectionColor = [[UIView alloc] init];
  3716. selectionColor.backgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
  3717. cell.selectedBackgroundView = selectionColor;
  3718. if ([typeCell isEqualToString:@"CellMain"]) cell.backgroundColor = [UIColor whiteColor];
  3719. if ([typeCell isEqualToString:@"CellMainTransfer"]) cell.backgroundColor = [NCBrandColor sharedInstance].transferBackground;
  3720. // ----------------------------------------------------------------------------------------------------------
  3721. // DEFAULT
  3722. // ----------------------------------------------------------------------------------------------------------
  3723. cell.file.image = nil;
  3724. cell.status.image = nil;
  3725. cell.favorite.image = nil;
  3726. cell.shared.image = nil;
  3727. cell.local.image = nil;
  3728. cell.labelTitle.enabled = YES;
  3729. cell.labelTitle.text = @"";
  3730. cell.labelInfoFile.enabled = YES;
  3731. cell.labelInfoFile.text = @"";
  3732. cell.progressView.progress = 0.0;
  3733. cell.progressView.hidden = YES;
  3734. cell.cancelTaskButton.hidden = YES;
  3735. cell.reloadTaskButton.hidden = YES;
  3736. cell.stopTaskButton.hidden = YES;
  3737. // Encrypted color
  3738. if (metadata.cryptated) {
  3739. cell.labelTitle.textColor = [NCBrandColor sharedInstance].cryptocloud;
  3740. } else {
  3741. cell.labelTitle.textColor = [UIColor blackColor];
  3742. }
  3743. // ----------------------------------------------------------------------------------------------------------
  3744. // File Name & Folder
  3745. // ----------------------------------------------------------------------------------------------------------
  3746. // nome del file
  3747. cell.labelTitle.text = metadata.fileNamePrint;
  3748. // è una directory
  3749. if (metadata.directory) {
  3750. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3751. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  3752. lunghezzaFile = @" ";
  3753. // ----------------------------------------------------------------------------------------------------------
  3754. // Favorite Folder
  3755. // ----------------------------------------------------------------------------------------------------------
  3756. if (metadata.favorite) {
  3757. cell.favorite.image = [UIImage imageNamed:@"favorite"];
  3758. }
  3759. } else {
  3760. // File
  3761. dataFile = [CCUtility dateDiff:metadata.date];
  3762. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  3763. // Plist ancora da scaricare
  3764. if (metadata.cryptated && [metadata.title length] == 0) {
  3765. dataFile = @" ";
  3766. lunghezzaFile = @" ";
  3767. }
  3768. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
  3769. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3770. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  3771. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  3772. if ([metadata.type isEqualToString: k_metadataType_template] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO)
  3773. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", dataFile];
  3774. if ([metadata.type isEqualToString: k_metadataType_file] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO) {
  3775. if (localFile && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  3776. cell.local.image = [UIImage imageNamed:@"local"];
  3777. else
  3778. cell.local.image = nil;
  3779. //cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", dataFile, lunghezzaFile];
  3780. //cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", dataFile, lunghezzaFile];
  3781. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ %@", dataFile, lunghezzaFile];
  3782. }
  3783. // Plist ancora da scaricare
  3784. if ([dataFile isEqualToString:@" "] && [lunghezzaFile isEqualToString:@" "])
  3785. cell.labelInfoFile.text = NSLocalizedString(@"_no_plist_pull_down_",nil);
  3786. cell.accessoryType = UITableViewCellAccessoryNone;
  3787. }
  3788. // ----------------------------------------------------------------------------------------------------------
  3789. // File Image View
  3790. // ----------------------------------------------------------------------------------------------------------
  3791. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3792. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  3793. cell.file.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  3794. } else {
  3795. if (metadata.directory)
  3796. cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:metadata.iconName] color:[NCBrandColor sharedInstance].brand];
  3797. else
  3798. cell.file.image = [UIImage imageNamed:metadata.iconName];
  3799. if (metadata.thumbnailExists)
  3800. [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
  3801. }
  3802. // ----------------------------------------------------------------------------------------------------------
  3803. // Image Status cyptated & Lock Passcode
  3804. // ----------------------------------------------------------------------------------------------------------
  3805. // File Cyptated
  3806. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_template] == NO) {
  3807. cell.status.image = [UIImage imageNamed:@"lock"];
  3808. }
  3809. // Directory con passcode lock attivato
  3810. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
  3811. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, lockServerUrl]];
  3812. if (metadata.directory && (directory.lock && [[CCUtility getBlockCode] length]))
  3813. cell.status.image = [UIImage imageNamed:@"passcode"];
  3814. // ----------------------------------------------------------------------------------------------------------
  3815. // Favorite
  3816. // ----------------------------------------------------------------------------------------------------------
  3817. if (metadata.favorite) {
  3818. cell.favorite.image = [UIImage imageNamed:@"favorite"];
  3819. }
  3820. // ----------------------------------------------------------------------------------------------------------
  3821. // Share
  3822. // ----------------------------------------------------------------------------------------------------------
  3823. NSString *shareLink = [app.sharesLink objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
  3824. NSString *shareUserAndGroup = [app.sharesUserAndGroup objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
  3825. BOOL isShare = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_shared].location == NSNotFound);
  3826. BOOL isMounted = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_mounted].location == NSNotFound);
  3827. // Aggiungiamo il Tap per le shared
  3828. if (isShare || [shareLink length] > 0 || [shareUserAndGroup length] > 0 || isMounted) {
  3829. if (isShare) {
  3830. if (metadata.directory) {
  3831. cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_shared_with_me"] color:[NCBrandColor sharedInstance].brand];
  3832. cell.shared.userInteractionEnabled = NO;
  3833. } else {
  3834. cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand];
  3835. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3836. [tap setNumberOfTapsRequired:1];
  3837. cell.shared.userInteractionEnabled = YES;
  3838. [cell.shared addGestureRecognizer:tap];
  3839. }
  3840. }
  3841. if (isMounted) {
  3842. if (metadata.directory) {
  3843. cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_external"] color:[NCBrandColor sharedInstance].brand];
  3844. cell.shared.userInteractionEnabled = NO;
  3845. } else {
  3846. cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"shareMounted"] color:[NCBrandColor sharedInstance].brand];
  3847. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3848. [tap setNumberOfTapsRequired:1];
  3849. cell.shared.userInteractionEnabled = YES;
  3850. [cell.shared addGestureRecognizer:tap];
  3851. }
  3852. }
  3853. if ([shareLink length] > 0 || [shareUserAndGroup length] > 0) {
  3854. if (metadata.directory) {
  3855. if ([shareLink length] > 0)
  3856. cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_public"] color:[NCBrandColor sharedInstance].brand];
  3857. if ([shareUserAndGroup length] > 0)
  3858. cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_shared_with_me"] color:[NCBrandColor sharedInstance].brand];
  3859. cell.shared.userInteractionEnabled = NO;
  3860. } else {
  3861. if ([shareLink length] > 0)
  3862. cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"shareLink"] color:[NCBrandColor sharedInstance].brand];
  3863. if ([shareUserAndGroup length] > 0)
  3864. cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand];
  3865. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  3866. [tap setNumberOfTapsRequired:1];
  3867. cell.shared.userInteractionEnabled = YES;
  3868. [cell.shared addGestureRecognizer:tap];
  3869. }
  3870. }
  3871. } else {
  3872. cell.shared.userInteractionEnabled = NO;
  3873. }
  3874. // ----------------------------------------------------------------------------------------------------------
  3875. // downloadFile
  3876. // ----------------------------------------------------------------------------------------------------------
  3877. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  3878. if (metadata.cryptated) cell.status.image = [UIImage imageNamed:@"statusdownloadcrypto"];
  3879. else cell.status.image = [UIImage imageNamed:@"statusdownload"];
  3880. // sessionTaskIdentifier : RELOAD + STOP
  3881. if (metadata.sessionTaskIdentifier != k_taskIdentifierDone) {
  3882. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptaskcrypto"] forState:UIControlStateNormal];
  3883. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
  3884. cell.cancelTaskButton.hidden = NO;
  3885. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtaskcrypto"] forState:UIControlStateNormal];
  3886. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  3887. cell.reloadTaskButton.hidden = NO;
  3888. }
  3889. // sessionTaskIdentifierPlist : RELOAD
  3890. if (metadata.sessionTaskIdentifierPlist != k_taskIdentifierDone) {
  3891. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtaskcrypto"] forState:UIControlStateNormal];
  3892. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  3893. cell.reloadTaskButton.hidden = NO;
  3894. }
  3895. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3896. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3897. if (progress > 0) {
  3898. if (metadata.cryptated) cell.progressView.progressTintColor = [NCBrandColor sharedInstance].cryptocloud;
  3899. else cell.progressView.progressTintColor = [UIColor blackColor];
  3900. cell.progressView.progress = progress;
  3901. cell.progressView.hidden = NO;
  3902. }
  3903. // ----------------------------------------------------------------------------------------------------------
  3904. // downloadFile Error
  3905. // ----------------------------------------------------------------------------------------------------------
  3906. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  3907. cell.status.image = [UIImage imageNamed:@"statuserror"];
  3908. if ([metadata.sessionError length] == 0)
  3909. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  3910. else
  3911. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3912. }
  3913. }
  3914. // ----------------------------------------------------------------------------------------------------------
  3915. // uploadFile
  3916. // ----------------------------------------------------------------------------------------------------------
  3917. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  3918. if (metadata.cryptated) cell.status.image = [UIImage imageNamed:@"statusuploadcrypto"];
  3919. else cell.status.image = [UIImage imageNamed:@"statusupload"];
  3920. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"removetaskcrypto"] forState:UIControlStateNormal];
  3921. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"removetask"] forState:UIControlStateNormal];
  3922. cell.cancelTaskButton.hidden = NO;
  3923. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  3924. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtaskcrypto"] forState:UIControlStateNormal];
  3925. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  3926. if (metadata.cryptated) cell.status.image = [UIImage imageNamed:@"statusstopcrypto"];
  3927. else cell.status.image = [UIImage imageNamed:@"statusstop"];
  3928. cell.reloadTaskButton.hidden = NO;
  3929. cell.stopTaskButton.hidden = YES;
  3930. } else {
  3931. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptaskcrypto"] forState:UIControlStateNormal];
  3932. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
  3933. cell.stopTaskButton.hidden = NO;
  3934. cell.reloadTaskButton.hidden = YES;
  3935. }
  3936. // se non c'è una preview in bianconero metti l'immagine di default
  3937. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  3938. cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"uploaddisable"] color:[NCBrandColor sharedInstance].brand];
  3939. cell.labelTitle.enabled = NO;
  3940. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3941. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3942. if (progress > 0) {
  3943. if (metadata.cryptated) cell.progressView.progressTintColor = [NCBrandColor sharedInstance].cryptocloud;
  3944. else cell.progressView.progressTintColor = [UIColor blackColor];
  3945. cell.progressView.progress = progress;
  3946. cell.progressView.hidden = NO;
  3947. }
  3948. // ----------------------------------------------------------------------------------------------------------
  3949. // uploadFileError
  3950. // ----------------------------------------------------------------------------------------------------------
  3951. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  3952. cell.labelTitle.enabled = NO;
  3953. cell.status.image = [UIImage imageNamed:@"statuserror"];
  3954. if ([metadata.sessionError length] == 0)
  3955. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  3956. else
  3957. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3958. }
  3959. }
  3960. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3961. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3962. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3963. // ======== MGSwipe ========
  3964. //Left only plain
  3965. if (metadata.cryptated == NO) {
  3966. if (metadata.favorite)
  3967. cell.leftButtons = @[[MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_unfavorite_", nil)] icon:[UIImage imageNamed:@"swipeUnfavorite"] backgroundColor:[UIColor colorWithRed:242.0/255.0 green:220.0/255.0 blue:132.0/255.0 alpha:1.000]]];
  3968. else
  3969. cell.leftButtons = @[[MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_favorite_", nil)] icon:[UIImage imageNamed:@"swipeFavorite"] backgroundColor:[UIColor colorWithRed:242.0/255.0 green:220.0/255.0 blue:132.0/255.0 alpha:1.000]]];
  3970. cell.leftExpansion.buttonIndex = 0;
  3971. cell.leftExpansion.fillOnTrigger = NO;
  3972. //centerIconOverText
  3973. MGSwipeButton *favoriteButton = (MGSwipeButton *)[cell.leftButtons objectAtIndex:0];
  3974. [favoriteButton centerIconOverText];
  3975. } else {
  3976. cell.leftButtons = [NSArray new];
  3977. }
  3978. //Right
  3979. cell.rightButtons = @[[MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_delete_", nil)] icon:[UIImage imageNamed:@"swipeDelete"] backgroundColor:[UIColor redColor]], [MGSwipeButton buttonWithTitle:[NSString stringWithFormat:@" %@ ", NSLocalizedString(@"_more_", nil)] icon:[UIImage imageNamed:@"swipeMore"] backgroundColor:[UIColor lightGrayColor]]];
  3980. cell.rightSwipeSettings.transition = MGSwipeTransitionBorder;
  3981. //centerIconOverText
  3982. MGSwipeButton *deleteButton = (MGSwipeButton *)[cell.rightButtons objectAtIndex:0];
  3983. MGSwipeButton *moreButton = (MGSwipeButton *)[cell.rightButtons objectAtIndex:1];
  3984. [deleteButton centerIconOverText];
  3985. [moreButton centerIconOverText];
  3986. //restore swipeOffset after relod
  3987. CGFloat swipeOffset = [[_statusSwipeCell objectForKey:indexPath] doubleValue];
  3988. if (swipeOffset < 0) {
  3989. [cell showSwipe:MGSwipeDirectionRightToLeft animated:NO];
  3990. [_statusSwipeCell removeObjectForKey:indexPath];
  3991. } else if (swipeOffset > 0) {
  3992. [cell showSwipe:MGSwipeDirectionLeftToRight animated:NO];
  3993. [_statusSwipeCell removeObjectForKey:indexPath];
  3994. }
  3995. return cell;
  3996. }
  3997. - (void)setTableViewFooter
  3998. {
  3999. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  4000. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  4001. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  4002. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  4003. UIFont *appFont = [UIFont systemFontOfSize:12];
  4004. footerLabel.font = appFont;
  4005. footerLabel.textColor = [UIColor grayColor];
  4006. footerLabel.backgroundColor = [UIColor clearColor];
  4007. footerLabel.textAlignment = NSTextAlignmentCenter;
  4008. NSString *folders;
  4009. NSString *files;
  4010. NSString *footerText;
  4011. if (_sectionDataSource.directories > 1) {
  4012. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  4013. } else if (_sectionDataSource.directories == 1){
  4014. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  4015. } else {
  4016. folders = @"";
  4017. }
  4018. if (_sectionDataSource.files > 1) {
  4019. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  4020. } else if (_sectionDataSource.files == 1){
  4021. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  4022. } else {
  4023. files = @"";
  4024. }
  4025. if ([folders isEqualToString:@""]) {
  4026. footerText = files;
  4027. } else if ([files isEqualToString:@""]) {
  4028. footerText = folders;
  4029. } else {
  4030. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  4031. }
  4032. footerLabel.text = footerText;
  4033. [footerView addSubview:footerLabel];
  4034. [self.tableView setTableFooterView:footerView];
  4035. }
  4036. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  4037. {
  4038. NSString *textMessage;
  4039. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  4040. // settiamo il record file.
  4041. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  4042. // se non può essere selezionata deseleziona
  4043. if ([cell isEditing] == NO)
  4044. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  4045. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  4046. if (self.tableView.editing) {
  4047. [_selectedFileIDsMetadatas setObject:_metadata forKey:_metadata.fileID];
  4048. [self setTitle];
  4049. return;
  4050. }
  4051. // test crash
  4052. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
  4053. if (indexPath.row >= [metadatas count]) return;
  4054. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  4055. if (!serverUrl) return;
  4056. // se è in corso una sessione
  4057. if ([_metadata.session length] > 0) return;
  4058. if (_metadata.errorPasscode) {
  4059. // se UUID è nil lo sta ancora caricando quindi esci
  4060. if (!_metadata.uuid) return;
  4061. // esiste un hint ??
  4062. NSString *hint = [[CCCrypto sharedManager] getHintFromFile:_metadata.fileName isLocal:NO directoryUser:app.directoryUser];
  4063. // qui !! la richiesta della nuova passcode
  4064. if ([_metadata.uuid isEqualToString:[CCUtility getUUID]]) {
  4065. // stesso UUID ... la password è stata modificata !!!!!!
  4066. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_same_device_different_passcode_hint_",nil), hint];
  4067. else textMessage = NSLocalizedString(@"_same_device_different_passcode_", nil);
  4068. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  4069. [alertView show];
  4070. } else {
  4071. // UUID diverso.
  4072. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_hint_",nil), _metadata.nameCurrentDevice, hint];
  4073. else textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_",nil), _metadata.nameCurrentDevice];
  4074. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  4075. [alertView show];
  4076. }
  4077. // chiediamo la passcode e ricarichiamo tutto.
  4078. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  4079. viewController.delegate = self;
  4080. viewController.fromType = CCBKPasscodeFromPasscode;
  4081. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  4082. viewController.passcodeInputView.maximumLength = 64;
  4083. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  4084. viewController.inputViewTitlePassword = NO;
  4085. viewController.title = [NCBrandOptions sharedInstance].brand;
  4086. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  4087. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  4088. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  4089. [self presentViewController:navigationController animated:YES completion:nil];
  4090. }
  4091. // modello o plist con il title a 0 allora è andato storto qualcosa ... ricaricalo
  4092. if (_metadata.cryptated && [_metadata.title length] == 0) {
  4093. NSString* selector;
  4094. if ([_metadata.type isEqualToString: k_metadataType_template]) selector = selectorLoadModelView;
  4095. else selector = selectorLoadPlist;
  4096. [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:NO downloadPlist:YES selector:selector selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  4097. return;
  4098. }
  4099. // se il plist è caricato ed è un modello aprilo
  4100. if ([_metadata.type isEqualToString:k_metadataType_template]) [self openModel:_metadata.model isNew:false];
  4101. // file
  4102. if (_metadata.directory == NO && _metadata.errorPasscode == NO && [_metadata.type isEqualToString: k_metadataType_file]) {
  4103. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  4104. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
  4105. [self downloadFileSuccess:_metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView selectorPost:nil];
  4106. } else {
  4107. [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  4108. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  4109. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  4110. }
  4111. }
  4112. if (_metadata.directory) [self performSegueDirectoryWithControlPasscode:true];
  4113. }
  4114. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  4115. {
  4116. tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  4117. [_selectedFileIDsMetadatas removeObjectForKey:metadata.fileID];
  4118. [self setTitle];
  4119. }
  4120. - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
  4121. {
  4122. if (!indexPath)
  4123. return NO;
  4124. NSInteger section = indexPath.section;
  4125. NSInteger row = indexPath.row;
  4126. NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.tableView] - 1;
  4127. //Make sure the specified section exists
  4128. if (section > lastSectionIndex)
  4129. return NO;
  4130. NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section] - 1;
  4131. return row <= rowCount;
  4132. }
  4133. #pragma --------------------------------------------------------------------------------------------
  4134. #pragma mark ===== Navigation ====
  4135. #pragma --------------------------------------------------------------------------------------------
  4136. - (BOOL)shouldPerformSegue
  4137. {
  4138. // if background return
  4139. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  4140. if (self.view.window == NO)
  4141. return NO;
  4142. // Collapsed ma siamo già in detail esci
  4143. if (self.splitViewController.isCollapsed)
  4144. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return NO;
  4145. // Video in esecuzione esci
  4146. if (_detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && _detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  4147. return YES;
  4148. }
  4149. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  4150. {
  4151. id viewController = segue.destinationViewController;
  4152. NSMutableArray *allRecordsDataSourceImagesVideos = [NSMutableArray new];
  4153. tableMetadata *metadata;
  4154. if ([viewController isKindOfClass:[UINavigationController class]]) {
  4155. UINavigationController *nav = viewController;
  4156. _detailViewController = (CCDetail *)nav.topViewController;
  4157. } else {
  4158. _detailViewController = segue.destinationViewController;
  4159. }
  4160. if ([sender isKindOfClass:[tableMetadata class]]) {
  4161. metadata = sender;
  4162. [allRecordsDataSourceImagesVideos addObject:sender];
  4163. } else {
  4164. metadata = _metadata;
  4165. for (NSString *fileID in _sectionDataSource.allEtag) {
  4166. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4167. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
  4168. [allRecordsDataSourceImagesVideos addObject:metadata];
  4169. }
  4170. }
  4171. _detailViewController.metadataDetail = metadata;
  4172. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  4173. _detailViewController.dateFilterQuery = nil;
  4174. [_detailViewController setTitle:metadata.fileNamePrint];
  4175. }
  4176. // can i go to next viewcontroller
  4177. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
  4178. {
  4179. NSString *nomeDir;
  4180. if(self.tableView.editing == NO && _metadata.errorPasscode == NO){
  4181. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  4182. if (!serverUrl) return;
  4183. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  4184. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", app.activeAccount, lockServerUrl]];
  4185. // SE siamo in presenza di una directory bloccata E è attivo il block E la sessione password Lock è senza data ALLORA chiediamo la password per procedere
  4186. if (directory.lock && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil && controlPasscode) {
  4187. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  4188. viewController.delegate = self;
  4189. viewController.fromType = CCBKPasscodeFromLockDirectory;
  4190. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  4191. viewController.inputViewTitlePassword = YES;
  4192. if ([CCUtility getSimplyBlockCode]) {
  4193. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  4194. viewController.passcodeInputView.maximumLength = 6;
  4195. } else {
  4196. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  4197. viewController.passcodeInputView.maximumLength = 64;
  4198. }
  4199. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  4200. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  4201. viewController.touchIDManager = touchIDManager;
  4202. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  4203. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  4204. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  4205. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  4206. [self presentViewController:navController animated:YES completion:nil];
  4207. return;
  4208. }
  4209. if (_metadata.cryptated) nomeDir = [_metadata.fileName substringToIndex:[_metadata.fileName length]-6];
  4210. else nomeDir = _metadata.fileName;
  4211. NSString *serverUrlPush = [CCUtility stringAppendServerUrl:serverUrl addFileName:nomeDir];
  4212. CCMain *viewController = [app.listMainVC objectForKey:serverUrlPush];
  4213. if (viewController.isViewLoaded == false || viewController == nil) {
  4214. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMainVC"];
  4215. viewController.isFolderEncrypted = _metadata.cryptated;
  4216. viewController.serverUrl = serverUrlPush;
  4217. viewController.titleMain = _metadata.fileNamePrint;
  4218. viewController.textBackButton = _titleMain;
  4219. // save self
  4220. [app.listMainVC setObject:viewController forKey:serverUrlPush];
  4221. }
  4222. // OFF SearchBar
  4223. [viewController cancelSearchBar];
  4224. [self.navigationController pushViewController:viewController animated:YES];
  4225. }
  4226. }
  4227. @end