CCMain.m 268 KB

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