CCMain.m 262 KB

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