CCMain.m 265 KB

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