CCMain.m 268 KB

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