CCMain.m 270 KB

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