CCMain.m 254 KB

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