CCMain.m 269 KB

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