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