CCMain.m 256 KB

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