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