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