CCMain.m 264 KB

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