CCMain.m 262 KB

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