CCMain.m 260 KB

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