CCMain.m 263 KB

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