CCMain.m 257 KB

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