CCMain.m 269 KB

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