CCMain.m 268 KB

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