CCMain.m 269 KB

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