CCMain.m 256 KB

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