CCMain.m 269 KB

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