CCMain.m 261 KB

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