CCMain.m 266 KB

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