CCMain.m 268 KB

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