CCMain.m 261 KB

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