CCMain.m 262 KB

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