CCMain.m 268 KB

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