CCMain.m 255 KB

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