CCMain.m 261 KB

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