CCMain.m 270 KB

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