CCMain.m 255 KB

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