CCMain.m 259 KB

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