CCMain.m 266 KB

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