CCMain.m 259 KB

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