CCMain.m 258 KB

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