CCMain.m 270 KB

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