CCMain.m 259 KB

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