CCMain.m 269 KB

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