CCMain.m 258 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554
  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:NSFileCoordinatorReadingForUploading 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. CreateFormUploadAssets *form = [[CreateFormUploadAssets 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. metadataNet.action = actionReadFile;
  779. metadataNet.selector = selectorReadFileQuota;
  780. metadataNet.serverUrl = _localServerUrl;
  781. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  782. }
  783. }
  784. #pragma --------------------------------------------------------------------------------------------
  785. #pragma mark ==== Download Thumbnail ====
  786. #pragma --------------------------------------------------------------------------------------------
  787. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  788. {
  789. __block CCCellMain *cell;
  790. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
  791. if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]]) {
  792. cell = [self.tableView cellForRowAtIndexPath:indexPath];
  793. cell.fileImageView.image = [app.icoImagesCache objectForKey:metadataNet.fileID];
  794. if (cell.fileImageView.image == nil) {
  795. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  796. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]];
  797. [app.icoImagesCache setObject:image forKey:metadataNet.fileID];
  798. });
  799. }
  800. }
  801. }
  802. - (void)downloadThumbnailFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  803. {
  804. NSLog(@"[LOG] Thumbnail Error %@ %@ (error %ld)", metadataNet.fileName , message, (long)errorCode);
  805. }
  806. - (void)downloadThumbnail:(CCMetadata *)metadata
  807. {
  808. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  809. metadataNet.action = actionDownloadThumbnail;
  810. metadataNet.fileID = metadata.fileID;
  811. if ([metadata.typeCloud isEqualToString:typeCloudOwnCloud] || [metadata.typeCloud isEqualToString:typeCloudNextcloud])
  812. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:_localServerUrl activeUrl:app.activeUrl typeCloud:app.typeCloud];
  813. metadataNet.fileNameLocal = metadata.fileID;
  814. metadataNet.fileNamePrint = metadata.fileNamePrint;
  815. metadataNet.options = @"m";
  816. metadataNet.priority = NSOperationQueuePriorityLow;
  817. metadataNet.selector = selectorDownloadThumbnail;
  818. metadataNet.serverUrl = _localServerUrl;
  819. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  820. }
  821. #pragma --------------------------------------------------------------------------------------------
  822. #pragma mark ==== Download ====
  823. #pragma --------------------------------------------------------------------------------------------
  824. - (void)downloadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  825. {
  826. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  827. // File do not exists on server, remove in local
  828. if (errorCode == kOCErrorServerPathNotFound || errorCode == kCFURLErrorBadServerResponse) {
  829. [CCCoreData deleteFile:metadata serverUrl:serverUrl directoryUser:app.directoryUser typeCloud:app.typeCloud activeAccount:app.activeAccount];
  830. }
  831. if ([selector isEqualToString:selectorLoadViewImage] || [selector isEqualToString:selectorBrowseImages]) {
  832. dispatch_async(dispatch_get_main_queue(), ^{
  833. // Updating Detail
  834. if (app.activeDetail)
  835. [app.activeDetail downloadPhotoBrowserFailure:errorCode];
  836. // Updating Photos
  837. if (app.activePhotosCameraUpload)
  838. [app.activePhotosCameraUpload downloadFileFailure:errorCode];
  839. });
  840. } else {
  841. if (errorCode != kCFURLErrorCancelled)
  842. [app messageNotification:@"_download_file_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  843. }
  844. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  845. }
  846. - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  847. {
  848. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  849. if (metadata == nil) return;
  850. // reload
  851. if ([selector isEqualToString:selectorReload]) {
  852. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  853. }
  854. // Synchronize
  855. if ([selector isEqualToString:selectorDownloadSynchronized]) {
  856. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  857. }
  858. // add Favorite
  859. if ([selector isEqualToString:selectorAddFavorite]) {
  860. [CCCoreData addFavorite:metadata.fileID activeAccount:app.activeAccount];
  861. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  862. }
  863. // encrypted file
  864. if ([selector isEqualToString:selectorEncryptFile]) {
  865. [self encryptedFile:metadata];
  866. }
  867. // decrypted file
  868. if ([selector isEqualToString:selectorDecryptFile]) {
  869. [self decryptedFile:metadata];
  870. }
  871. // open View File
  872. if ([selector isEqualToString:selectorLoadFileView] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  873. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  874. if ([metadata.typeFile isEqualToString:metadataTypeFile_compress]) {
  875. [self performSelector:@selector(unZipFile:) withObject:metadata.fileID afterDelay:0.1];
  876. } else if ([metadata.typeFile isEqualToString:metadataTypeFile_unknown]) {
  877. selector = selectorOpenIn;
  878. } else {
  879. _metadataSegue = metadata;
  880. _metadataSegue.sessionSelector = selector;
  881. if ([self shouldPerformSegue:serverUrl])
  882. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  883. }
  884. }
  885. // addLocal
  886. if ([selector isEqualToString:selectorAddLocal]) {
  887. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileNamePrint]];
  888. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  889. [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]];
  890. [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  891. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  892. }
  893. // Open with...
  894. if ([selector isEqualToString:selectorOpenIn] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  895. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  896. [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  897. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  898. NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint]];
  899. _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  900. _docController.delegate = self;
  901. [_docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  902. }
  903. // Save to Photo Album
  904. if ([selector isEqualToString:selectorSave] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
  905. NSString *file = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  906. if ([metadata.typeFile isEqualToString:metadataTypeFile_image]) {
  907. // evitiamo il rimando photo
  908. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  909. UIImage *image = [UIImage imageWithContentsOfFile:file];
  910. if (image)
  911. UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  912. else
  913. [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  914. }
  915. if ([metadata.typeFile isEqualToString:metadataTypeFile_video]) {
  916. // we avoid the cross-reference video
  917. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  918. [[NSFileManager defaultManager] linkItemAtPath:file toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  919. if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint])) {
  920. UISaveVideoAtPathToSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint], self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
  921. } else {
  922. [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  923. }
  924. }
  925. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  926. }
  927. // download and view a template
  928. if ([selector isEqualToString:selectorLoadModelView]) {
  929. [CCCoreData downloadFilePlist:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud directoryUser:app.directoryUser];
  930. [self openModel:metadata.model isNew:false];
  931. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  932. }
  933. //download file plist
  934. if ([selector isEqualToString:selectorLoadPlist]) {
  935. [CCCoreData downloadFilePlist:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud directoryUser:app.directoryUser];
  936. long countSelectorLoadPlist = 0;
  937. for (NSOperation *operation in [app.netQueue operations]) {
  938. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  939. if ([((OCnetworking *)operation).metadataNet.selector isEqualToString:selectorLoadPlist])
  940. countSelectorLoadPlist++;
  941. }
  942. }
  943. if ((countSelectorLoadPlist == 0 || countSelectorLoadPlist % maxConcurrentOperation == 0) && [metadata.directoryID isEqualToString:_localDirectoryID]) {
  944. dispatch_async(dispatch_get_main_queue(), ^{
  945. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  946. });
  947. }
  948. }
  949. //selectorLoadViewImage & selectorBrowseImages
  950. if ([selector isEqualToString:selectorLoadViewImage] || [selector isEqualToString:selectorBrowseImages]) {
  951. dispatch_async(dispatch_get_main_queue(), ^{
  952. // Detail
  953. if (app.activeDetail)
  954. [app.activeDetail downloadPhotoBrowserSuccess:metadata selector:selector];
  955. // Photos
  956. if (app.activePhotosCameraUpload)
  957. [app.activePhotosCameraUpload downloadFileSuccess:metadata];
  958. });
  959. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:selector];
  960. }
  961. // if exists postselector call self with selectorPost
  962. if ([selectorPost length] > 0)
  963. [self downloadFileSuccess:fileID serverUrl:serverUrl selector:selectorPost selectorPost:nil];
  964. }
  965. - (void)downloadSelectedFiles
  966. {
  967. NSLog(@"[LOG] Start download selected files ...");
  968. [_hud visibleHudTitle:NSLocalizedString(@"_downloading_progress_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  969. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  970. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  971. for (CCMetadata *metadata in selectedMetadatas) {
  972. if (metadata.directory == NO && [metadata.type isEqualToString:metadataType_file])
  973. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorReload selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  974. }
  975. [_hud hideHud];
  976. });
  977. [self tableViewSelect:NO];
  978. }
  979. - (void)downloadPlist:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  980. {
  981. NSArray *records = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND ((session == NULL) OR (session == ''))", app.activeAccount, directoryID] context:nil];
  982. for (TableMetadata *recordMetadata in records) {
  983. if ([CCUtility isCryptoPlistString:recordMetadata.fileName] && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, recordMetadata.fileName]] == NO && [recordMetadata.session length] == 0) {
  984. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  985. metadataNet.action = actionDownloadFile;
  986. metadataNet.metadata = [CCCoreData insertEntityInMetadata:recordMetadata];
  987. metadataNet.downloadData = NO;
  988. metadataNet.downloadPlist = YES;
  989. metadataNet.selector = selectorLoadPlist;
  990. metadataNet.serverUrl = serverUrl;
  991. metadataNet.session = download_session_foreground;
  992. metadataNet.taskStatus = taskStatusResume;
  993. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  994. }
  995. }
  996. }
  997. #pragma --------------------------------------------------------------------------------------------
  998. #pragma mark ===== Upload new Photos/Videos =====
  999. #pragma --------------------------------------------------------------------------------------------
  1000. - (void)uploadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  1001. {
  1002. // Automatic upload
  1003. if([selector isEqualToString:selectorUploadAutomatic] || [selector isEqualToString:selectorUploadAutomaticAll])
  1004. [app loadTableAutomaticUploadForSelector:selector];
  1005. // Read File test do not exists
  1006. if (errorCode == CCErrorFileUploadNotFound) {
  1007. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  1008. // reUpload
  1009. if (metadata)
  1010. [[CCNetworking sharedNetworking] uploadFileMetadata:metadata taskStatus:taskStatusResume];
  1011. }
  1012. // Print error
  1013. else if (errorCode != kCFURLErrorCancelled && errorCode != 403) {
  1014. [app messageNotification:@"_upload_file_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1015. }
  1016. [self getDataSourceWithReloadTableView:[CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount] fileID:nil selector:selector];
  1017. }
  1018. - (void)uploadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  1019. {
  1020. // Automatic upload
  1021. if([selector isEqualToString:selectorUploadAutomatic] || [selector isEqualToString:selectorUploadAutomaticAll])
  1022. [app loadTableAutomaticUploadForSelector:selector];
  1023. if ([selectorPost isEqualToString:selectorReadFolderForced] ) {
  1024. [self readFolderWithForced:YES];
  1025. } else {
  1026. [self getDataSourceWithReloadTableView:[CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount] fileID:nil selector:selector];
  1027. }
  1028. }
  1029. //
  1030. // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
  1031. //
  1032. - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  1033. {
  1034. [_hud visibleHudTitle:nil mode:MBProgressHUDModeIndeterminate color:nil];
  1035. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
  1036. [self performSelectorOnMainThread:@selector(uploadFileAssetBridge:) withObject:@[assets, serverUrl, [NSNumber numberWithBool:cryptated], [NSNumber numberWithBool:useSubFolder], session] waitUntilDone:NO];
  1037. });
  1038. }
  1039. - (void)uploadFileAssetBridge:(NSArray *)arguments
  1040. {
  1041. NSArray *assets = [arguments objectAtIndex:0];
  1042. NSString *serverUrl = [arguments objectAtIndex:1];
  1043. BOOL cryptated = [[arguments objectAtIndex:2] boolValue];
  1044. BOOL useSubFolder = [[arguments objectAtIndex:3] boolValue];
  1045. NSString * session = [arguments objectAtIndex:4];
  1046. // remove title (graphics)
  1047. [self setTitleBackgroundTableView:nil];
  1048. NSString *folderPhotos = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  1049. NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
  1050. // Create if request the folder for Photos
  1051. if ((useSubFolder || [serverUrl isEqualToString:folderPhotos]) && [_localServerUrl isEqualToString:serverUrl] == NO){
  1052. if(![app.activePhotosCameraUpload createFolder:folderPhotos]) {
  1053. [_hud hideHud];
  1054. [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  1055. return;
  1056. }
  1057. }
  1058. // Create if request the subfolders
  1059. if (useSubFolder) {
  1060. for (NSString *dateSubFolder in [CCUtility createNameSubFolder:assets]) {
  1061. if(![app.activePhotosCameraUpload createFolder:[NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder]]) {
  1062. [_hud hideHud];
  1063. [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  1064. return;
  1065. }
  1066. }
  1067. }
  1068. NSLog(@"[LOG] Asset N. %lu", (unsigned long)[assets count]);
  1069. for (PHAsset *asset in assets) {
  1070. NSString *fileName = [CCUtility createFileNameFromAsset:asset key: keyFileNameMask];
  1071. NSDate *assetDate = asset.creationDate;
  1072. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  1073. // Create serverUrl if use sub folder
  1074. if (useSubFolder) {
  1075. [formatter setDateFormat:@"yyyy"];
  1076. NSString *yearString = [formatter stringFromDate:assetDate];
  1077. [formatter setDateFormat:@"MM"];
  1078. NSString *monthString = [formatter stringFromDate:assetDate];
  1079. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", folderPhotos, yearString, monthString];
  1080. }
  1081. // Check if is in upload
  1082. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND (fileName == %@) AND (session != NULL) AND (session != '')", app.activeAccount, directoryID, fileName];
  1083. NSArray *isRecordInSessions = [CCCoreData getTableMetadataWithPredicate:predicate context:nil];
  1084. if ([isRecordInSessions count] > 0) {
  1085. // next upload
  1086. continue;
  1087. } else {
  1088. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1089. if ([app.typeCloud isEqualToString:typeCloudNextcloud] || [app.typeCloud isEqualToString:typeCloudOwnCloud]) {
  1090. metadataNet.action = actionReadFile;
  1091. metadataNet.assetLocalItentifier = asset.localIdentifier;
  1092. metadataNet.cryptated = cryptated;
  1093. metadataNet.fileName = fileName;
  1094. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1095. metadataNet.session = session;
  1096. metadataNet.selector = selectorReadFileUploadFile;
  1097. metadataNet.serverUrl = serverUrl;
  1098. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1099. }
  1100. }
  1101. }
  1102. [_hud hideHud];
  1103. }
  1104. #pragma --------------------------------------------------------------------------------------------
  1105. #pragma mark ==== Read File ====
  1106. #pragma --------------------------------------------------------------------------------------------
  1107. - (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1108. {
  1109. // UploadFile
  1110. if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
  1111. // File not exists
  1112. if (errorCode == 404) {
  1113. metadataNet.action = actionUploadAsset;
  1114. metadataNet.errorCode = 0;
  1115. metadataNet.selector = selectorUploadFile;
  1116. metadataNet.selectorPost = nil;
  1117. metadataNet.taskStatus = taskStatusResume;
  1118. if ([metadataNet.session containsString:@"wwan"])
  1119. [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
  1120. else
  1121. [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
  1122. } else {
  1123. // error ho many retry befor notification and go to on next asses
  1124. if (metadataNet.errorRetry < 3) {
  1125. // Retry read file
  1126. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1127. } else {
  1128. // STOP check file, view message error
  1129. [app messageNotification:@"_upload_file_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1130. }
  1131. }
  1132. }
  1133. }
  1134. - (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(CCMetadata *)metadata
  1135. {
  1136. // ReadFile Folder for change rev
  1137. if ([metadataNet.selector isEqualToString:selectorReadFileFolder]) {
  1138. NSString *rev = [CCCoreData getDirectoryRevFromServerUrl:metadataNet.serverUrl activeAccount:app.activeAccount];
  1139. if (![metadata.rev isEqualToString:rev]) {
  1140. NSLog(@"Change etag, force reload folder %@", metadataNet.serverUrl);
  1141. [CCCoreData setDirectoryRev:metadata.rev serverUrl:metadataNet.serverUrl activeAccount:app.activeAccount];
  1142. [CCCoreData clearDateReadDirectory:metadataNet.serverUrl activeAccount:app.activeAccount];
  1143. CCMain *viewController = [app.listMainVC objectForKey:metadataNet.serverUrl];
  1144. if (viewController)
  1145. [viewController clearDateReadDataSource:nil];
  1146. }
  1147. }
  1148. // UploadFile
  1149. if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
  1150. metadataNet.action = actionUploadAsset;
  1151. metadataNet.errorCode = 403; // File exists 403 Forbidden
  1152. metadataNet.selector = selectorUploadFile;
  1153. metadataNet.selectorPost = nil;
  1154. metadataNet.taskStatus = taskStatusResume;
  1155. if ([metadataNet.session containsString:@"wwan"])
  1156. [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
  1157. else
  1158. [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
  1159. }
  1160. // Quota
  1161. if ([metadataNet.selector isEqualToString:selectorReadFileQuota]) {
  1162. if (app.activeSettings)
  1163. [app.activeSettings reloadForm];
  1164. }
  1165. }
  1166. - (void)readFileSelfFolderRev
  1167. {
  1168. // test
  1169. if ([app.activeAccount length] == 0 || [_localDirectoryID length] == 0)
  1170. return;
  1171. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1172. metadataNet.action = actionReadFile;
  1173. metadataNet.selector = selectorReadFileFolder;
  1174. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:_localDirectoryID activeAccount:app.activeAccount];
  1175. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1176. }
  1177. #pragma --------------------------------------------------------------------------------------------
  1178. #pragma mark ==== Read Folder ====
  1179. #pragma --------------------------------------------------------------------------------------------
  1180. - (void)readFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1181. {
  1182. // verify active user
  1183. TableAccount *record = [CCCoreData getActiveAccount];
  1184. [_hud hideHud];
  1185. [_ccRefreshControl endRefreshing];
  1186. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1187. if (message && [record.account isEqualToString:metadataNet.account])
  1188. [app messageNotification:@"_error_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1189. [self getDataSourceWithReloadTableView:metadataNet.directoryID fileID:nil selector:metadataNet.selector];
  1190. if (errorCode == 401)
  1191. [self changePasswordAccount];
  1192. }
  1193. - (void)readFolderSuccess:(CCMetadataNet *)metadataNet permissions:(NSString *)permissions rev:(NSString *)rev metadatas:(NSArray *)metadatas
  1194. {
  1195. // verify active user
  1196. TableAccount *record = [CCCoreData getActiveAccount];
  1197. if (![record.account isEqualToString:metadataNet.account])
  1198. return;
  1199. // save father e update permission
  1200. _fatherPermission = permissions;
  1201. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND ((session == NULL) OR (session == ''))", app.activeAccount, metadataNet.directoryID]];
  1202. NSArray *recordsInSessions = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, metadataNet.directoryID] context:nil];
  1203. [CCCoreData setDateReadDirectoryID:metadataNet.directoryID activeAccount:app.activeAccount];
  1204. for (CCMetadata *metadata in metadatas) {
  1205. // type of file
  1206. NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
  1207. // if crypto do not insert
  1208. if (typeFilename == metadataTypeFilenameCrypto) continue;
  1209. // verify if the record encrypted has plist + crypto
  1210. if (typeFilename == metadataTypeFilenamePlist && metadata.directory == NO) {
  1211. BOOL isCryptoComplete = NO;
  1212. NSString *fileNameCrypto = [CCUtility trasformedFileNamePlistInCrypto:metadata.fileName];
  1213. for (CCMetadata *completeMetadata in metadatas) {
  1214. if (completeMetadata.cryptated == NO) continue;
  1215. else if ([completeMetadata.fileName isEqualToString:fileNameCrypto]) {
  1216. isCryptoComplete = YES;
  1217. break;
  1218. }
  1219. }
  1220. if (isCryptoComplete == NO) continue;
  1221. }
  1222. // verify if the record is in download/upload progress
  1223. if (metadata.directory == NO && [recordsInSessions count] > 0) {
  1224. CCMetadata *metadataDB = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND (fileName == %@)", app.activeAccount, metadataNet.directoryID, metadata.fileName] context:nil];
  1225. // Upload
  1226. if (metadataDB.session && [metadataDB.session rangeOfString:@"upload"].location != NSNotFound) {
  1227. NSString *sessionID = metadataDB.sessionID;
  1228. // rename SessionID -> fileID
  1229. [CCUtility moveFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, sessionID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]];
  1230. metadataDB.session = @"";
  1231. metadataDB.date = metadata.date;
  1232. metadataDB.fileID = metadata.fileID;
  1233. metadataDB.rev = metadata.fileID;
  1234. metadataDB.sessionError = @"";
  1235. metadataDB.sessionID = @"";
  1236. metadataDB.sessionTaskIdentifier = taskIdentifierDone;
  1237. metadataDB.sessionTaskIdentifierPlist = taskIdentifierDone;
  1238. [CCCoreData updateMetadata:metadataDB predicate:[NSPredicate predicateWithFormat:@"(sessionID == %@) AND (account == %@)", sessionID, app.activeAccount] activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud context:nil];
  1239. [CCCoreData addLocalFile:metadataDB activeAccount:app.activeAccount];
  1240. [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]];
  1241. continue;
  1242. }
  1243. // download in progress
  1244. if (metadataDB.session && [metadataDB.session rangeOfString:@"download"].location != NSNotFound) continue;
  1245. }
  1246. // test rev subdirectory
  1247. /*
  1248. if (metadata.directory) {
  1249. NSString *serverUrlTestRev = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:metadata.fileName];
  1250. NSString *revPrev = [CCCoreData getDirectoryRevFromServerUrl:serverUrlTestRev activeAccount:app.activeAccount];
  1251. if (![metadata.rev isEqualToString:revPrev]) {
  1252. NSLog(@"Change etag, force reload folder");
  1253. [CCCoreData setDirectoryRev:metadata.rev serverUrl:serverUrlTestRev activeAccount:app.activeAccount];
  1254. [CCCoreData clearDateReadDirectory:serverUrlTestRev activeAccount:app.activeAccount];
  1255. CCMain *viewController = [app.listMainVC objectForKey:serverUrlTestRev];
  1256. if (viewController)
  1257. [viewController clearDateReadDataSource:nil];
  1258. }
  1259. }
  1260. */
  1261. // end test, insert in CoreData
  1262. [CCCoreData addMetadata:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud context:nil];
  1263. }
  1264. // read plist
  1265. [self downloadPlist:metadataNet.directoryID serverUrl:metadataNet.serverUrl];
  1266. // Synchronization directory
  1267. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  1268. [[CCSynchronization sharedSynchronization] verifyChangeMedatas:metadatas serverUrl:metadataNet.serverUrl directoryID:metadataNet.directoryID account:app.activeAccount synchronization:NO];
  1269. });
  1270. // this is the same directory
  1271. if ([metadataNet.serverUrl isEqualToString:_localServerUrl]) {
  1272. // reload
  1273. [self getDataSourceWithReloadTableView:metadataNet.directoryID fileID:nil selector:metadataNet.selector];
  1274. // stoprefresh
  1275. [_ccRefreshControl endRefreshing];
  1276. // Enable change user
  1277. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1278. [_hud hideHud];
  1279. }
  1280. }
  1281. - (void)readFolderWithForced:(BOOL)forced
  1282. {
  1283. [self setTitleBackgroundTableView:nil];
  1284. // init control
  1285. if (!_localServerUrl || !app.activeAccount)
  1286. return;
  1287. if (([CCCoreData isDirectoryOutOfDate:dayForceReadFolder directoryID:_localDirectoryID activeAccount:app.activeAccount] || forced) && _localDirectoryID && app.activeAccount) {
  1288. if (_ccRefreshControl.isRefreshing == NO)
  1289. [_hud visibleIndeterminateHud];
  1290. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1291. metadataNet.action = actionReadFolder;
  1292. metadataNet.date = [NSDate date];
  1293. metadataNet.directoryID = _localDirectoryID;
  1294. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1295. metadataNet.selector = selectorReadFolder;
  1296. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:_localDirectoryID activeAccount:app.activeAccount];
  1297. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1298. } else {
  1299. if ([_sectionDataSource.allRecordsDataSource count] == 0) [self setTitleBackgroundTableView:NSLocalizedString(@"_no_file_pull_down_",nil)];
  1300. else [self setTitleBackgroundTableView:nil];
  1301. }
  1302. }
  1303. #pragma --------------------------------------------------------------------------------------------
  1304. #pragma mark ===== Delete File or Folder =====
  1305. #pragma --------------------------------------------------------------------------------------------
  1306. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1307. {
  1308. [_hud hideHud];
  1309. if (errorCode == 404)
  1310. [self deleteFileOrFolderSuccess:metadataNet];
  1311. if (message)
  1312. [app messageNotification:@"_delete_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1313. // is detailViewController active ?
  1314. if (_detailViewController) {
  1315. dispatch_async(dispatch_get_main_queue(), ^{
  1316. [_detailViewController deleteFileFailure:errorCode];
  1317. });
  1318. }
  1319. [_selectedMetadatas removeAllObjects];
  1320. [_queueSelector removeAllObjects];
  1321. }
  1322. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  1323. {
  1324. [_queueSelector removeObject:metadataNet.selector];
  1325. if ([_queueSelector count] == 0) {
  1326. [_hud hideHud];
  1327. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  1328. if (metadata) {
  1329. [CCCoreData deleteFile:metadata serverUrl:metadataNet.serverUrl directoryUser:app.directoryUser typeCloud:app.typeCloud activeAccount:app.activeAccount];
  1330. // Carico la Folder o il Datasource
  1331. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
  1332. [self readFolderWithForced:YES];
  1333. } else {
  1334. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:metadataNet.selector];
  1335. }
  1336. }
  1337. // if detailViewController
  1338. if (_detailViewController) {
  1339. dispatch_async(dispatch_get_main_queue(), ^{
  1340. [_detailViewController deleteFileSuccess:metadata metadataNetVar:metadataNet];
  1341. });
  1342. }
  1343. // next
  1344. if ([_selectedMetadatas count] > 0) {
  1345. [_selectedMetadatas removeObjectAtIndex:0];
  1346. if ([_selectedMetadatas count] > 0)
  1347. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1348. }
  1349. }
  1350. }
  1351. - (void)deleteFileOrFolder:(CCMetadata *)metadata numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
  1352. {
  1353. if (metadata.cryptated == YES) {
  1354. // Cryptated
  1355. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1356. metadataNet.action = actionDeleteFileDirectory;
  1357. metadataNet.fileID = metadata.fileID;
  1358. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1359. metadataNet.serverUrl = _localServerUrl;
  1360. // data crypto
  1361. metadataNet.fileName = metadata.fileNameData;
  1362. metadataNet.selector = selectorDeleteCrypto;
  1363. [_queueSelector addObject:metadataNet.selector];
  1364. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1365. // plist
  1366. metadataNet.fileName = metadata.fileName;
  1367. metadataNet.selector = selectorDeletePlist;
  1368. [_queueSelector addObject:metadataNet.selector];
  1369. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1370. } else {
  1371. // Plain
  1372. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1373. metadataNet.action = actionDeleteFileDirectory;
  1374. metadataNet.fileID = metadata.fileID;
  1375. metadataNet.fileName = metadata.fileName;
  1376. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1377. metadataNet.selector = selectorDelete;
  1378. metadataNet.serverUrl = _localServerUrl;
  1379. [_queueSelector addObject:metadataNet.selector];
  1380. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1381. }
  1382. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_delete_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1383. }
  1384. - (void)deleteSelectionFile
  1385. {
  1386. [_selectedMetadatas removeAllObjects];
  1387. [_queueSelector removeAllObjects];
  1388. _selectedMetadatas = [[NSMutableArray alloc] initWithArray: [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]]];
  1389. _numSelectedMetadatas = [_selectedMetadatas count];
  1390. if ([_selectedMetadatas count] > 0)
  1391. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1392. [self tableViewSelect:NO];
  1393. }
  1394. - (void)deleteFile
  1395. {
  1396. [_selectedMetadatas removeAllObjects];
  1397. [_queueSelector removeAllObjects];
  1398. _numSelectedMetadatas = 1;
  1399. [_selectedMetadatas addObject:_metadata];
  1400. if ([_selectedMetadatas count] > 0)
  1401. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1402. [self tableViewSelect:NO];
  1403. }
  1404. #pragma --------------------------------------------------------------------------------------------
  1405. #pragma mark ===== Rename =====
  1406. #pragma --------------------------------------------------------------------------------------------
  1407. - (void)renameSuccess:(CCMetadataNet *)metadataNet revTo:(NSString *)revTo
  1408. {
  1409. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  1410. if (metadata.directory == YES)
  1411. [CCCoreData renameDirectory:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadataNet.fileName] serverUrlTo:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadataNet.fileNameTo] activeAccount:app.activeAccount];
  1412. else
  1413. [CCCoreData renameLocalFileWithFileID:metadata.fileID fileNameTo:metadataNet.fileNameTo fileNamePrintTo:metadataNet.fileNameTo activeAccount:app.activeAccount];
  1414. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced])
  1415. [self readFolderWithForced:YES];
  1416. }
  1417. - (void)renameFile:(CCMetadata *)metadata fileName:(NSString *)fileName
  1418. {
  1419. NSString *fileNameTo, *newTitleTo;
  1420. CCCrypto *crypto = [[CCCrypto alloc] init];
  1421. fileNameTo = [CCUtility removeForbiddenCharacters:fileName];
  1422. if (![fileNameTo length]) return;
  1423. if ([metadata.fileNamePrint isEqualToString:fileNameTo]) return;
  1424. // Plain
  1425. if (metadata.cryptated == NO) {
  1426. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1427. metadataNet.action = actionMoveFileOrFolder;
  1428. metadataNet.fileID = metadata.fileID;
  1429. metadataNet.fileName = metadata.fileName;
  1430. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1431. metadataNet.fileNameTo = fileNameTo;
  1432. metadataNet.selector = selectorRename;
  1433. metadataNet.selectorPost = selectorReadFolderForced;
  1434. metadataNet.serverUrl = _localServerUrl;
  1435. metadataNet.serverUrlTo = _localServerUrl;
  1436. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1437. } else {
  1438. // Change only the contenent of plist, then upload it
  1439. newTitleTo = [AESCrypt encrypt:fileNameTo password:[crypto getKeyPasscode:metadata.uuid]];
  1440. if ([crypto updateTitleFilePlist:metadata.fileName title:newTitleTo directoryUser:app.directoryUser] == NO) {
  1441. NSLog(@"[LOG] Rename cryptated error %@", fileName);
  1442. [app messageNotification:@"_rename_" description:@"_file_not_found_reload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1443. return;
  1444. }
  1445. if (metadata.directory == NO) {
  1446. // cripto il file fileID in temp
  1447. NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]];
  1448. if (data) data = [RNEncryptor encryptData:data withSettings:kRNCryptorAES256Settings password:[crypto getKeyPasscode:metadata.uuid] error:nil];
  1449. if (data) [data writeToFile:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameData] atomically:YES];
  1450. }
  1451. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1452. metadataNet.action = actionUploadOnlyPlist;
  1453. metadataNet.fileName = metadata.fileName;
  1454. metadataNet.selectorPost = selectorReadFolderForced;
  1455. metadataNet.serverUrl = _localServerUrl;
  1456. metadataNet.session = upload_session_foreground;
  1457. metadataNet.taskStatus = taskStatusResume;
  1458. if ([CCCoreData isFavorite:metadata.fileID activeAccount:app.activeAccount]) metadataNet.selectorPost = selectorAddFavorite;
  1459. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1460. // delete file in filesystem
  1461. [CCCoreData deleteFile:metadata serverUrl:_localServerUrl directoryUser:app.directoryUser typeCloud:app.typeCloud activeAccount:app.activeAccount];
  1462. }
  1463. }
  1464. - (void)renameNote:(CCMetadata *)metadata fileName:(NSString *)fileName
  1465. {
  1466. CCTemplates *templates = [[CCTemplates alloc] init];
  1467. CCCrypto *crypto = [[CCCrypto alloc] init];
  1468. NSMutableDictionary *field = [crypto getDictionaryEncrypted:metadata.fileName uuid:metadata.uuid isLocal:NO directoryUser:app.directoryUser];
  1469. NSString *fileNameModel = [templates salvaNote:[field objectForKey:@"note"] titolo:fileName fileName:metadata.fileName uuid:metadata.uuid];
  1470. if (fileNameModel) {
  1471. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1472. metadataNet.action = actionUploadTemplate;
  1473. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  1474. metadataNet.fileNamePrint = fileName;
  1475. metadataNet.rev = metadata.rev;
  1476. metadataNet.serverUrl = _localServerUrl;
  1477. metadataNet.session = upload_session_foreground;
  1478. metadataNet.taskStatus = taskStatusResume;
  1479. if ([CCCoreData isFavorite:metadata.fileID activeAccount:app.activeAccount]) metadataNet.selectorPost = selectorAddFavorite;
  1480. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1481. }
  1482. }
  1483. #pragma --------------------------------------------------------------------------------------------
  1484. #pragma mark ===== Move =====
  1485. #pragma --------------------------------------------------------------------------------------------
  1486. - (void)moveFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1487. {
  1488. [_hud hideHud];
  1489. if (message)
  1490. [app messageNotification:@"_move_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1491. [_selectedMetadatas removeAllObjects];
  1492. [_queueSelector removeAllObjects];
  1493. }
  1494. - (void)moveSuccess:(CCMetadataNet *)metadataNet revTo:(NSString *)revTo
  1495. {
  1496. [_queueSelector removeObject:metadataNet.selector];
  1497. if ([_queueSelector count] == 0) {
  1498. [_hud hideHud];
  1499. NSString *fileName = [CCUtility trasformedFileNameCryptoInPlist:metadataNet.fileName];
  1500. NSString *directoryID = metadataNet.directoryID;
  1501. NSString *directoryIDTo = metadataNet.directoryIDTo;
  1502. // FILE -> Metadata
  1503. if (metadataNet.directory == NO) {
  1504. // se esiste l' directoryIDTo destinazione allora cambiamo il file sul nuovo directoryID altrimenti cancelliamo il file
  1505. if (directoryIDTo)
  1506. [CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
  1507. else
  1508. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(directoryID == %@)AND (account == %@)", directoryID, app.activeAccount]];
  1509. }
  1510. // DIRECTORY -> Directory - CCMetadata
  1511. if (metadataNet.directory == YES) {
  1512. // cancelliamo tutte le directory e subdirectory in Directory prelevando i fileID
  1513. NSArray *directoryIDs = [CCCoreData deleteDirectoryAndSubDirectory:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:fileName] activeAccount:app.activeAccount];
  1514. // cancelliamo in metadata tutti i file degli fileID prelevati da directory
  1515. for(NSString *directoryIDDelete in directoryIDs) {
  1516. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(directoryID == %@)AND (account == %@)",directoryIDDelete, app.activeAccount]];
  1517. }
  1518. // rinominiamo ora la directory in CCMetadata
  1519. if (directoryIDTo)
  1520. [CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
  1521. }
  1522. // reload Datasource
  1523. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced])
  1524. [self readFolderWithForced:YES];
  1525. else
  1526. [self getDataSourceWithReloadTableView];
  1527. // Next file
  1528. [_selectedMetadatas removeObjectAtIndex:0];
  1529. [self moveFileOrFolder:metadataNet.serverUrlTo];
  1530. }
  1531. }
  1532. - (void)moveFileOrFolder:(NSString *)serverUrlTo
  1533. {
  1534. if ([_selectedMetadatas count] > 0) {
  1535. CCMetadata *metadata = [_selectedMetadatas objectAtIndex:0];
  1536. // Plain
  1537. if (metadata.cryptated == NO) {
  1538. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1539. metadataNet.action = actionMoveFileOrFolder;
  1540. metadataNet.directory = metadata.directory;
  1541. metadataNet.fileID = metadata.fileID;
  1542. metadataNet.directoryID = _localDirectoryID;
  1543. metadataNet.directoryIDTo = [CCCoreData getDirectoryIDFromServerUrl:serverUrlTo activeAccount:app.activeAccount];
  1544. metadataNet.fileName = metadata.fileName;
  1545. metadataNet.fileNamePrint = metadataNet.fileNamePrint;
  1546. metadataNet.fileNameTo = metadata.fileName;
  1547. metadataNet.rev = metadata.rev;
  1548. metadataNet.selector = selectorMove;
  1549. metadataNet.serverUrl = _localServerUrl;
  1550. metadataNet.serverUrlTo = serverUrlTo;
  1551. [_queueSelector addObject:metadataNet.selector];
  1552. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1553. }
  1554. // cyptated
  1555. if (metadata.cryptated == YES) {
  1556. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1557. metadataNet.action = actionMoveFileOrFolder;
  1558. metadataNet.directory = metadata.directory;
  1559. metadataNet.fileID = metadata.fileID;
  1560. metadataNet.directoryID = _localDirectoryID;
  1561. metadataNet.directoryIDTo = [CCCoreData getDirectoryIDFromServerUrl:serverUrlTo activeAccount:app.activeAccount];
  1562. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1563. metadataNet.rev = metadata.rev;
  1564. metadataNet.serverUrl = _localServerUrl;
  1565. metadataNet.serverUrlTo = serverUrlTo;
  1566. // data
  1567. metadataNet.fileName = metadata.fileNameData;
  1568. metadataNet.fileNameTo = metadata.fileNameData;
  1569. metadataNet.selector = selectorMoveCrypto;
  1570. [_queueSelector addObject:metadataNet.selector];
  1571. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1572. // plist
  1573. metadataNet.fileName = metadata.fileName;
  1574. metadataNet.fileNameTo = metadata.fileName;
  1575. metadataNet.selector = selectorMovePlist;
  1576. [_queueSelector addObject:metadataNet.selector];
  1577. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1578. }
  1579. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), _numSelectedMetadatas - [_selectedMetadatas count] + 1, _numSelectedMetadatas] mode:MBProgressHUDModeIndeterminate color:nil];
  1580. }
  1581. }
  1582. - (void)move:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
  1583. {
  1584. // Test
  1585. if ([_localServerUrl isEqualToString:serverUrlTo]) {
  1586. [self tableViewSelect:NO];
  1587. return;
  1588. }
  1589. [_selectedMetadatas removeAllObjects];
  1590. [_queueSelector removeAllObjects];
  1591. _selectedMetadatas = [[NSMutableArray alloc] initWithArray:selectedMetadatas];
  1592. _numSelectedMetadatas = [_selectedMetadatas count];
  1593. [self moveFileOrFolder:serverUrlTo];
  1594. [self tableViewSelect:NO];
  1595. }
  1596. - (void)moveOpenWindow:(NSArray *)indexPaths
  1597. {
  1598. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  1599. CCMove *viewController = (CCMove *)navigationController.topViewController;
  1600. viewController.delegate = self;
  1601. viewController.move.title = NSLocalizedString(@"_move_", nil);
  1602. viewController.selectedMetadatas = [self getMetadatasFromSelectedRows:indexPaths];
  1603. viewController.tintColor = COLOR_BRAND;
  1604. viewController.barTintColor = COLOR_BAR;
  1605. viewController.tintColorTitle = COLOR_GRAY;
  1606. viewController.networkingOperationQueue = app.netQueue;
  1607. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  1608. [self presentViewController:navigationController animated:YES completion:nil];
  1609. }
  1610. #pragma --------------------------------------------------------------------------------------------
  1611. #pragma mark ===== Create folder =====
  1612. #pragma --------------------------------------------------------------------------------------------
  1613. - (void)createFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1614. {
  1615. [_hud hideHud];
  1616. if (message)
  1617. [app messageNotification:@"_create_folder_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1618. }
  1619. - (void)createFolderSuccess:(CCMetadataNet *)metadataNet
  1620. {
  1621. [_hud hideHud];
  1622. [CCCoreData addDirectory:[NSString stringWithFormat:@"%@/%@", metadataNet.serverUrl, metadataNet.fileName] date:[NSDate date] permissions:nil activeAccount:app.activeAccount];
  1623. // Load Folder or the Datasource
  1624. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
  1625. [self readFolderWithForced:YES];
  1626. } else {
  1627. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:metadataNet.fileID selector:metadataNet.selector];
  1628. }
  1629. }
  1630. - (void)createFolder:(NSString *)fileNameFolder folderCameraUpload:(BOOL)folderCameraUpload
  1631. {
  1632. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1633. fileNameFolder = [CCUtility removeForbiddenCharacters:fileNameFolder];
  1634. if (![fileNameFolder length]) return;
  1635. if (folderCameraUpload) metadataNet.serverUrl = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  1636. else metadataNet.serverUrl = _localServerUrl;
  1637. metadataNet.action = actionCreateFolder;
  1638. if (folderCameraUpload)
  1639. metadataNet.options = @"folderCameraUpload";
  1640. metadataNet.fileName = fileNameFolder;
  1641. metadataNet.selector = selectorCreateFolder;
  1642. metadataNet.selectorPost = selectorReadFolderForced;
  1643. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1644. if (!folderCameraUpload)
  1645. [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1646. }
  1647. - (void)createFolderEncrypted:(NSString *)fileNameFolder
  1648. {
  1649. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1650. CCCrypto *crypto = [[CCCrypto alloc] init];
  1651. NSString *fileNamePlist;
  1652. fileNameFolder = [CCUtility removeForbiddenCharacters:fileNameFolder];
  1653. if (![fileNameFolder length]) return;
  1654. NSString *title = [AESCrypt encrypt:fileNameFolder password:[crypto getKeyPasscode:[CCUtility getUUID]]];
  1655. fileNamePlist = [crypto createFilenameEncryptor:fileNameFolder uuid:[CCUtility getUUID]];
  1656. [crypto createFilePlist:[NSTemporaryDirectory() stringByAppendingString:fileNamePlist] title:title len:0 directory:true uuid:[CCUtility getUUID] nameCurrentDevice:[CCUtility getNameCurrentDevice] icon:@""];
  1657. // Create folder
  1658. metadataNet.action = actionCreateFolder;
  1659. metadataNet.fileName = fileNamePlist;
  1660. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1661. metadataNet.selector = selectorCreateFolder;
  1662. metadataNet.serverUrl = _localServerUrl;
  1663. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1664. // upload plist file
  1665. metadataNet.action = actionUploadOnlyPlist;
  1666. metadataNet.fileName = [fileNamePlist stringByAppendingString:@".plist"];
  1667. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1668. metadataNet.selectorPost = selectorReadFolderForced;
  1669. metadataNet.serverUrl = _localServerUrl;
  1670. metadataNet.session = upload_session_foreground;
  1671. metadataNet.taskStatus = taskStatusResume;
  1672. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1673. [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1674. }
  1675. - (void)createFolderCameraUpload
  1676. {
  1677. [self createFolder:[CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount] folderCameraUpload:YES];
  1678. }
  1679. #pragma --------------------------------------------------------------------------------------------
  1680. #pragma mark ===== Encrypted / Decrypted Folder =====
  1681. #pragma --------------------------------------------------------------------------------------------
  1682. - (void)encyptedDecryptedFolder
  1683. {
  1684. if (_metadata.cryptated) {
  1685. // DECRYPTED
  1686. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1687. //-------------------------- RENAME -------------------------------------------//
  1688. metadataNet.action = actionMoveFileOrFolder;
  1689. metadataNet.fileID = _metadata.fileID;
  1690. metadataNet.fileName = _metadata.fileNameData;
  1691. metadataNet.fileNameTo = _metadata.fileNamePrint;
  1692. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1693. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1694. metadataNet.selector = selectorRename;
  1695. metadataNet.serverUrl = _localServerUrl;
  1696. metadataNet.serverUrlTo = _localServerUrl;
  1697. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1698. //-------------------------- DELETE -------------------------------------------//
  1699. metadataNet.action = actionDeleteFileDirectory;
  1700. metadataNet.fileID = _metadata.fileID;
  1701. metadataNet.fileName = _metadata.fileName;
  1702. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1703. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1704. metadataNet.selector = selectorDeletePlist;
  1705. metadataNet.selectorPost = selectorReadFolderForced;
  1706. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1707. } else {
  1708. // ENCRYPTED
  1709. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1710. CCCrypto *crypto = [[CCCrypto alloc] init];
  1711. // Create File Plist
  1712. NSString *fileNameCrypto = [crypto createFileDirectoryPlist:_metadata];
  1713. //-------------------------- RENAME -------------------------------------------//
  1714. metadataNet.action = actionMoveFileOrFolder;
  1715. metadataNet.fileID = _metadata.fileID;
  1716. metadataNet.fileName = _metadata.fileName;
  1717. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1718. metadataNet.fileNameTo = fileNameCrypto;
  1719. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1720. metadataNet.selector = selectorRename;
  1721. metadataNet.serverUrl = _localServerUrl;
  1722. metadataNet.serverUrlTo = _localServerUrl;
  1723. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1724. //-------------------------- UPLOAD -------------------------------------------//
  1725. metadataNet.action = actionUploadOnlyPlist;
  1726. metadataNet.fileName = [fileNameCrypto stringByAppendingString:@".plist"];
  1727. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1728. metadataNet.selectorPost = selectorReadFolderForced;
  1729. metadataNet.serverUrl = _localServerUrl;
  1730. metadataNet.session = upload_session_foreground;
  1731. metadataNet.taskStatus = taskStatusResume;
  1732. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1733. }
  1734. }
  1735. #pragma --------------------------------------------------------------------------------------------
  1736. #pragma mark ===== Encrypted/Decrypted File =====
  1737. #pragma --------------------------------------------------------------------------------------------
  1738. - (void)encryptedSelectedFiles
  1739. {
  1740. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1741. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1742. for (CCMetadata *metadata in selectedMetadatas) {
  1743. if (metadata.cryptated == NO && metadata.directory == NO)
  1744. [metadatas addObject:metadata];
  1745. }
  1746. if ([metadatas count] > 0) {
  1747. NSLog(@"[LOG] Start encrypted selected files ...");
  1748. for (CCMetadata* metadata in metadatas)
  1749. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorEncryptFile selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1750. }
  1751. [self tableViewSelect:NO];
  1752. }
  1753. - (void)decryptedSelectedFiles
  1754. {
  1755. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1756. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1757. for (CCMetadata *metadata in selectedMetadatas) {
  1758. if (metadata.cryptated == YES && metadata.directory == NO && [metadata.model length] == 0)
  1759. [metadatas addObject:metadata];
  1760. }
  1761. if ([metadatas count] > 0) {
  1762. NSLog(@"[LOG] Start decrypted selected files ...");
  1763. for (CCMetadata* metadata in metadatas)
  1764. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorDecryptFile selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1765. }
  1766. [self tableViewSelect:NO];
  1767. }
  1768. - (void)cmdEncryptedDecryptedFile
  1769. {
  1770. NSString *selector;
  1771. if (_metadata.cryptated == YES) selector = selectorDecryptFile;
  1772. if (_metadata.cryptated == NO) selector = selectorEncryptFile;
  1773. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selector selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1774. }
  1775. - (void)encryptedFile:(CCMetadata *)metadata
  1776. {
  1777. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1778. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1779. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1780. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
  1781. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  1782. dispatch_async(dispatch_get_main_queue(), ^{
  1783. [[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];
  1784. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.1];
  1785. });
  1786. } else {
  1787. [app messageNotification:@"_encrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1788. }
  1789. }
  1790. - (void)decryptedFile:(CCMetadata *)metadata
  1791. {
  1792. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1793. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1794. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1795. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
  1796. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  1797. dispatch_async(dispatch_get_main_queue(), ^{
  1798. [[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];
  1799. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.1];
  1800. });
  1801. } else {
  1802. [app messageNotification:@"_decrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1803. }
  1804. }
  1805. #pragma --------------------------------------------------------------------------------------------
  1806. #pragma mark ===== Progress & Task Button =====
  1807. #pragma --------------------------------------------------------------------------------------------
  1808. - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
  1809. {
  1810. // Check
  1811. if (!fileID)
  1812. return;
  1813. [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  1814. if (![serverUrl isEqualToString:_localServerUrl])
  1815. return;
  1816. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  1817. if (indexPath) {
  1818. CCControlCenterCell *cell = (CCControlCenterCell *)[self.tableView cellForRowAtIndexPath:indexPath];
  1819. if (cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  1820. else cell.progressView.progressTintColor = COLOR_CLEAR;
  1821. cell.progressView.hidden = NO;
  1822. [cell.progressView setProgress:progress];
  1823. }
  1824. }
  1825. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  1826. {
  1827. UITouch * touch = [[event allTouches] anyObject];
  1828. CGPoint location = [touch locationInView:self.tableView];
  1829. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1830. if (indexPath) {
  1831. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1832. if (metadata)
  1833. [self reloadTaskButton:metadata];
  1834. }
  1835. }
  1836. - (void)reloadTaskButton:(CCMetadata *)metadata
  1837. {
  1838. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1839. __block NSURLSessionTask *findTask;
  1840. // DOWNLOAD
  1841. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  1842. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1843. for (NSURLSessionUploadTask *task in downloadTasks)
  1844. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1845. findTask = task;
  1846. [app.listChangeTask setObject:@"reloadDownload" forKey:metadata.fileID];
  1847. [task cancel];
  1848. }
  1849. if (!findTask) {
  1850. dispatch_async(dispatch_get_main_queue(), ^{
  1851. [app.listChangeTask setObject:@"reloadDownload" forKey:metadata.fileID];
  1852. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1853. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1854. });
  1855. }
  1856. }];
  1857. }
  1858. // UPLOAD
  1859. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1860. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1861. for (NSURLSessionUploadTask *task in uploadTasks)
  1862. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1863. findTask = task;
  1864. [app.listChangeTask setObject:@"reloadUpload" forKey:metadata.fileID];
  1865. [task cancel];
  1866. }
  1867. if (!findTask) {
  1868. dispatch_async(dispatch_get_main_queue(), ^{
  1869. [app.listChangeTask setObject:@"reloadUpload" forKey:metadata.fileID];
  1870. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1871. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1872. });
  1873. }
  1874. }];
  1875. }
  1876. }
  1877. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1878. {
  1879. UITouch * touch = [[event allTouches] anyObject];
  1880. CGPoint location = [touch locationInView:self.tableView];
  1881. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1882. if (indexPath) {
  1883. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1884. if (metadata)
  1885. [self cancelTaskButton:metadata reloadTable:YES];
  1886. }
  1887. }
  1888. - (void)cancelTaskButton:(CCMetadata *)metadata reloadTable:(BOOL)reloadTable
  1889. {
  1890. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1891. __block NSURLSessionTask *findTask;
  1892. // DOWNLOAD
  1893. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  1894. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1895. for (NSURLSessionTask *task in downloadTasks)
  1896. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1897. findTask = task;
  1898. [app.listChangeTask setObject:@"cancelDownload" forKey:metadata.fileID];
  1899. [task cancel];
  1900. }
  1901. if (!findTask) {
  1902. [app.listChangeTask setObject:@"cancelDownload" forKey:metadata.fileID];
  1903. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1904. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1905. }
  1906. }];
  1907. }
  1908. // UPLOAD
  1909. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1910. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1911. for (NSURLSessionUploadTask *task in uploadTasks)
  1912. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1913. findTask = task;
  1914. [app.listChangeTask setObject:@"cancelUpload" forKey:metadata.fileID];
  1915. [task cancel];
  1916. }
  1917. if (!findTask) {
  1918. dispatch_async(dispatch_get_main_queue(), ^{
  1919. [app.listChangeTask setObject:@"cancelUpload" forKey:metadata.fileID];
  1920. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1921. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1922. });
  1923. }
  1924. }];
  1925. }
  1926. }
  1927. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  1928. {
  1929. UITouch * touch = [[event allTouches] anyObject];
  1930. CGPoint location = [touch locationInView:self.tableView];
  1931. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1932. if (indexPath) {
  1933. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1934. if (metadata)
  1935. [self stopTaskButton:metadata];
  1936. }
  1937. }
  1938. - (void)stopTaskButton:(CCMetadata *)metadata
  1939. {
  1940. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1941. __block NSURLSessionTask *findTask;
  1942. // UPLOAD
  1943. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1944. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1945. for (NSURLSessionUploadTask *task in uploadTasks)
  1946. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1947. [app.listChangeTask setObject:@"stopUpload" forKey:metadata.fileID];
  1948. findTask = task;
  1949. [task cancel];
  1950. }
  1951. if (!findTask) {
  1952. dispatch_async(dispatch_get_main_queue(), ^{
  1953. [app.listChangeTask setObject:@"stopUpload" forKey:metadata.fileID];
  1954. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1955. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1956. });
  1957. }
  1958. }];
  1959. }
  1960. }
  1961. #pragma --------------------------------------------------------------------------------------------
  1962. #pragma mark ===== Shared =====
  1963. #pragma --------------------------------------------------------------------------------------------
  1964. - (void)readSharedSuccess:(CCMetadataNet *)metadataNet items:(NSDictionary *)items openWindow:(BOOL)openWindow
  1965. {
  1966. [_hud hideHud];
  1967. // change account ?
  1968. TableAccount *record = [CCCoreData getActiveAccount];
  1969. if([record.account isEqualToString:metadataNet.account] == NO)
  1970. return;
  1971. [CCCoreData updateShare:items sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  1972. if (openWindow && ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])) {
  1973. if (_shareOC) {
  1974. [_shareOC reloadData];
  1975. } else {
  1976. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  1977. // Apriamo la view
  1978. _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
  1979. _shareOC.delegate = self;
  1980. _shareOC.metadata = metadata;
  1981. _shareOC.serverUrl = metadataNet.serverUrl;
  1982. _shareOC.shareLink = [app.sharesLink objectForKey:metadata.fileID];
  1983. _shareOC.shareUserAndGroup = [app.sharesUserAndGroup objectForKey:metadata.fileID];
  1984. [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
  1985. [self presentViewController:_shareOC animated:YES completion:nil];
  1986. }
  1987. }
  1988. [self tableViewReload];
  1989. }
  1990. - (void)requestSharedByServer
  1991. {
  1992. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1993. metadataNet.action = actionReadShareServer;
  1994. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1995. }
  1996. - (void)shareFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1997. {
  1998. [_hud hideHud];
  1999. [app messageNotification:@"_share_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2000. if (_shareOC)
  2001. [_shareOC reloadData];
  2002. [self tableViewReload];
  2003. if (errorCode == 401)
  2004. [self changePasswordAccount];
  2005. }
  2006. - (void)share:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password
  2007. {
  2008. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2009. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2010. metadataNet.action = actionShare;
  2011. metadataNet.fileID = metadata.fileID;
  2012. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl typeCloud:app.typeCloud];
  2013. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2014. metadataNet.password = password;
  2015. metadataNet.selector = selectorShare;
  2016. metadataNet.serverUrl = serverUrl;
  2017. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2018. }
  2019. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2020. }
  2021. - (void)unShareSuccess:(CCMetadataNet *)metadataNet
  2022. {
  2023. [_hud hideHud];
  2024. // rimuoviamo la condivisione da db
  2025. [CCCoreData unShare:metadataNet.share fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup activeAccount:app.activeAccount];
  2026. if ([app.typeCloud isEqualToString:typeCloudNextcloud] && _shareOC)
  2027. [_shareOC reloadData];
  2028. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] && _shareOC)
  2029. [_shareOC reloadData];
  2030. [self tableViewReload];
  2031. }
  2032. - (void)unShare:(NSString *)share metadata:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl
  2033. {
  2034. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2035. metadataNet.action = actionUnShare;
  2036. metadataNet.fileID = metadata.fileID;
  2037. metadataNet.fileName = metadata.fileName;
  2038. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2039. metadataNet.selector = selectorUnshare;
  2040. metadataNet.serverUrl = serverUrl;
  2041. metadataNet.share = share;
  2042. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2043. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2044. }
  2045. - (void)updateShare:(NSString *)share metadata:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission
  2046. {
  2047. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2048. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2049. metadataNet.action = actionUpdateShare;
  2050. metadataNet.fileID = metadata.fileID;
  2051. metadataNet.expirationTime = expirationTime;
  2052. metadataNet.password = password;
  2053. metadataNet.selector = selectorUpdateShare;
  2054. metadataNet.serverUrl = serverUrl;
  2055. metadataNet.share = share;
  2056. metadataNet.sharePermission = permission;
  2057. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2058. }
  2059. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2060. }
  2061. - (void)getUserAndGroupSuccess:(CCMetadataNet *)metadataNet items:(NSArray *)items
  2062. {
  2063. [_hud hideHud];
  2064. if (_shareOC)
  2065. [_shareOC reloadUserAndGroup:items];
  2066. }
  2067. - (void)getUserAndGroupFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2068. {
  2069. [_hud hideHud];
  2070. [app messageNotification:@"_error_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2071. }
  2072. - (void)getUserAndGroup:(NSString *)find
  2073. {
  2074. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2075. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2076. metadataNet.action = actionGetUserAndGroup;
  2077. metadataNet.options = find;
  2078. metadataNet.selector = selectorGetUserAndGroup;
  2079. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2080. }
  2081. [_hud visibleIndeterminateHud];
  2082. }
  2083. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(CCMetadata *)metadata directoryID:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  2084. {
  2085. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2086. metadataNet.action = actionShareWith;
  2087. metadataNet.fileID = metadata.fileID;
  2088. metadataNet.directoryID = directoryID;
  2089. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl typeCloud:app.typeCloud];
  2090. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2091. metadataNet.serverUrl = serverUrl;
  2092. metadataNet.selector = selectorShare;
  2093. metadataNet.share = user;
  2094. metadataNet.shareeType = shareeType;
  2095. metadataNet.sharePermission = permission;
  2096. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2097. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2098. }
  2099. - (void)openWindowShare:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl
  2100. {
  2101. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2102. metadataNet.action = actionReadShareServer;
  2103. metadataNet.fileID = metadata.fileID;
  2104. metadataNet.fileName = metadata.fileName;
  2105. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2106. metadataNet.selector = selectorOpenWindowShare;
  2107. metadataNet.serverUrl = serverUrl;
  2108. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2109. [_hud visibleIndeterminateHud];
  2110. }
  2111. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  2112. {
  2113. CGPoint location = [tapGesture locationInView:self.tableView];
  2114. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  2115. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2116. if (metadata)
  2117. [self openWindowShare:metadata serverUrl:_localServerUrl];
  2118. }
  2119. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  2120. {
  2121. CGPoint location = [tapGesture locationInView:self.tableView];
  2122. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  2123. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2124. if (metadata) {
  2125. CCShareInfoCMOC *vc = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareInfoCMOC"];
  2126. vc.metadata = metadata;
  2127. [vc setModalPresentationStyle:UIModalPresentationFormSheet];
  2128. [self presentViewController:vc animated:YES completion:nil];
  2129. }
  2130. }
  2131. #pragma --------------------------------------------------------------------------------------------
  2132. #pragma mark ===== Favorite =====
  2133. #pragma --------------------------------------------------------------------------------------------
  2134. - (void)addFavorite:(CCMetadata *)metadata
  2135. {
  2136. if (metadata.errorPasscode || !metadata.uuid) return;
  2137. if ([metadata.type isEqualToString:metadataType_file])
  2138. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorAddFavorite selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2139. if ([metadata.type isEqualToString:metadataType_model])
  2140. [CCCoreData addFavorite:metadata.fileID activeAccount:app.activeAccount];
  2141. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2142. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2143. }
  2144. - (void)removeFavorite:(CCMetadata *)metadata
  2145. {
  2146. [CCCoreData removeFavoriteFromFileID:metadata.fileID activeAccount:app.activeAccount];
  2147. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2148. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2149. [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableFavorite" object:nil];
  2150. }
  2151. #pragma --------------------------------------------------------------------------------------------
  2152. #pragma mark ===== Local =====
  2153. #pragma --------------------------------------------------------------------------------------------
  2154. - (void)addLocal:(CCMetadata *)metadata
  2155. {
  2156. if (metadata.errorPasscode || !metadata.uuid) return;
  2157. if ([metadata.type isEqualToString:metadataType_file])
  2158. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorAddLocal selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2159. if ([metadata.type isEqualToString:metadataType_model]) {
  2160. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileName]];
  2161. [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  2162. [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableFavorite" object:nil];
  2163. }
  2164. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2165. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2166. }
  2167. #pragma --------------------------------------------------------------------------------------------
  2168. #pragma mark ===== Reload =====
  2169. #pragma --------------------------------------------------------------------------------------------
  2170. - (void)reloadFile:(CCMetadata *)metadata
  2171. {
  2172. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorReload selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2173. }
  2174. #pragma --------------------------------------------------------------------------------------------
  2175. #pragma mark ===== Open in... =====
  2176. #pragma --------------------------------------------------------------------------------------------
  2177. - (void)openIn:(CCMetadata *)metadata
  2178. {
  2179. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2180. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2181. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2182. }
  2183. #pragma --------------------------------------------------------------------------------------------
  2184. #pragma mark ===== Browse Images =====
  2185. #pragma --------------------------------------------------------------------------------------------
  2186. - (void)browseImages
  2187. {
  2188. NSArray *records = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND ((typeFile == %@) OR (typeFile == %@))", app.activeAccount, _localDirectoryID, metadataTypeFile_image, metadataTypeFile_video] context:nil];
  2189. if ([records count] == 0 || [self shouldPerformSegue:_localServerUrl] == NO) {
  2190. [app messageNotification:@"_info_" description:@"_no_photo_load_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  2191. return;
  2192. }
  2193. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.4 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  2194. _metadataSegue.fileID = nil;
  2195. _metadataSegue.directoryID = _localDirectoryID;
  2196. _metadataSegue.sessionSelector = selectorBrowseImages;
  2197. _metadataSegue.typeFile = metadataTypeFile_image;
  2198. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  2199. });
  2200. }
  2201. #pragma --------------------------------------------------------------------------------------------
  2202. #pragma mark ===== Order Table & GroupBy & DirectoryOnTop =====
  2203. #pragma --------------------------------------------------------------------------------------------
  2204. - (void)orderTable:(NSString *)order
  2205. {
  2206. // Clear data-read of DataSource
  2207. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2208. [CCUtility setOrderSettings:order];
  2209. // refresh
  2210. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2211. // new menu
  2212. [self createReMainMenu];
  2213. }
  2214. - (void)ascendingTable:(BOOL)ascending
  2215. {
  2216. // Clear data-read of DataSource
  2217. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2218. [CCUtility setAscendingSettings:ascending];
  2219. // refresh
  2220. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2221. // new menu
  2222. [self createReMainMenu];
  2223. }
  2224. - (void)directoryOnTop:(BOOL)directoryOnTop
  2225. {
  2226. // Clear data-read of DataSource
  2227. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2228. [CCUtility setDirectoryOnTop:directoryOnTop];
  2229. // refresh
  2230. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2231. // new menu
  2232. [self createReMainMenu];
  2233. }
  2234. - (void)tableGroupBy:(NSString *)groupBy
  2235. {
  2236. // Clear data-read of DataSource
  2237. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2238. [CCUtility setGroupBySettings:groupBy];
  2239. // refresh
  2240. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2241. // new menu
  2242. [self createReMainMenu];
  2243. }
  2244. #pragma --------------------------------------------------------------------------------------------
  2245. #pragma mark ==== Menu change User ====
  2246. #pragma --------------------------------------------------------------------------------------------
  2247. - (void)menuChangeUser
  2248. {
  2249. if (app.reSelectMenu.isOpen || app.reMainMenu.isOpen)
  2250. return;
  2251. 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) {
  2252. [app messageNotification:@"_transfers_in_queue_" description:nil visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  2253. return;
  2254. }
  2255. NSArray *listTableAccount = [CCCoreData getAllTableAccount];
  2256. NSMutableArray *menuArray = [[NSMutableArray alloc] init];
  2257. for (TableAccount *record in listTableAccount) {
  2258. if ([record.account isEqualToString:app.activeAccount]) continue;
  2259. CCMenuItem *item = [[CCMenuItem alloc] init];
  2260. item.title = [record.account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  2261. item.argument = record.account;
  2262. if ([record.typeCloud isEqualToString:typeCloudNextcloud]) item.image = [UIImage imageNamed:image_typeCloudNextcloud];
  2263. if ([record.typeCloud isEqualToString:typeCloudOwnCloud]) item.image = [UIImage imageNamed:image_typeCloudOwnCloud];
  2264. item.target = self;
  2265. item.action = @selector(changeDefaultAccount:);
  2266. [menuArray addObject:item];
  2267. }
  2268. if ([menuArray count] == 0)
  2269. return;
  2270. OptionalConfiguration options;
  2271. Color textColor, backgroundColor;
  2272. textColor.R = 0;
  2273. textColor.G = 0;
  2274. textColor.B = 0;
  2275. backgroundColor.R = 1;
  2276. backgroundColor.G = 1;
  2277. backgroundColor.B = 1;
  2278. options.arrowSize = 9;
  2279. options.marginXSpacing = 7;
  2280. options.marginYSpacing = 10;
  2281. options.intervalSpacing = 20;
  2282. options.menuCornerRadius = 6.5;
  2283. options.maskToBackground = NO;
  2284. options.shadowOfMenu = YES;
  2285. options.hasSeperatorLine = YES;
  2286. options.seperatorLineHasInsets = YES;
  2287. options.textColor = textColor;
  2288. options.menuBackgroundColor = backgroundColor;
  2289. [CCMenu setTitleFont:[UIFont systemFontOfSize:12.0]];
  2290. [CCMenu showMenuInView:self.navigationController.view fromRect:self.view.frame menuItems:menuArray withOptions:options];
  2291. }
  2292. - (void)changeDefaultAccount:(CCMenuItem *)sender
  2293. {
  2294. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
  2295. // STOP, erase all in queue networking
  2296. [app cancelAllOperations];
  2297. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  2298. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  2299. TableAccount *tableAccount = [CCCoreData setActiveAccount:[sender argument]];
  2300. if (tableAccount)
  2301. [app settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activePassword:tableAccount.password activeUID:tableAccount.uid activeAccessToken:tableAccount.token typeCloud:tableAccount.typeCloud];
  2302. // go to home sweet home
  2303. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  2304. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  2305. });
  2306. }
  2307. #pragma --------------------------------------------------------------------------------------------
  2308. #pragma mark ==== ReMenu ====
  2309. #pragma --------------------------------------------------------------------------------------------
  2310. - (void)createReMenuBackgroundView:(REMenu *)menu
  2311. {
  2312. __block CGFloat navigationBarH = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
  2313. _reMenuBackgroundView.frame = CGRectMake(0, navigationBarH, self.view.frame.size.width, self.view.frame.size.height);
  2314. [UIView animateWithDuration:0.2 animations:^{
  2315. float height = (self.view.frame.size.height + navigationBarH) - (menu.menuView.frame.size.height - self.navigationController.navigationBar.frame.size.height + 3);
  2316. if (height < self.tabBarController.tabBar.frame.size.height)
  2317. height = self.tabBarController.tabBar.frame.size.height;
  2318. _reMenuBackgroundView.frame = CGRectMake(0, self.view.frame.size.height + navigationBarH, self.view.frame.size.width, - height);
  2319. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  2320. }];
  2321. }
  2322. - (void)createReMainMenu
  2323. {
  2324. NSString *ordinamento;
  2325. NSString *groupBy = _directoryGroupBy;
  2326. __block NSString *nuovoOrdinamento;
  2327. NSString *titoloNuovo, *titoloAttuale;
  2328. BOOL ascendente;
  2329. __block BOOL nuovoAscendente;
  2330. UIImage *image;
  2331. // ITEM THUMBS ------------------------------------------------------------------------------------------------------
  2332. if (app.browseItem == nil) app.browseItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_browse_images_", nil)
  2333. subtitle:@""
  2334. image:[UIImage imageNamed:image_thumbs]
  2335. highlightedImage:nil
  2336. action:^(REMenuItem *item) {
  2337. [self browseImages];
  2338. }];
  2339. else app.browseItem = [app.browseItem initWithTitle:NSLocalizedString(@"_browse_images_", nil)
  2340. subtitle:@""
  2341. image:[UIImage imageNamed:image_thumbs]
  2342. highlightedImage:nil
  2343. action:^(REMenuItem *item) {
  2344. [self browseImages];
  2345. }];
  2346. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  2347. if (app.selezionaItem == nil) app.selezionaItem = [[REMenuItem alloc] 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. }];
  2356. else app.selezionaItem = [app.selezionaItem initWithTitle:NSLocalizedString(@"_select_", nil)
  2357. subtitle:@""
  2358. image:[UIImage imageNamed:image_seleziona]
  2359. highlightedImage:nil
  2360. action:^(REMenuItem *item) {
  2361. if ([_sectionDataSource.allRecordsDataSource count] > 0)
  2362. [self tableViewSelect:YES];
  2363. }];
  2364. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  2365. ordinamento = _directoryOrder;
  2366. if ([ordinamento isEqualToString:@"fileName"]) {
  2367. image = [UIImage imageNamed:image_MenuOrdeyByDate];
  2368. titoloNuovo = NSLocalizedString(@"_order_by_date_", nil);
  2369. titoloAttuale = NSLocalizedString(@"_current_order_name_", nil);
  2370. nuovoOrdinamento = @"fileDate";
  2371. }
  2372. if ([ordinamento isEqualToString:@"fileDate"]) {
  2373. image = [UIImage imageNamed:image_MenuOrderByFileName];
  2374. titoloNuovo = NSLocalizedString(@"_order_by_name_", nil);
  2375. titoloAttuale = NSLocalizedString(@"_current_order_date_", nil);
  2376. nuovoOrdinamento = @"fileName";
  2377. }
  2378. if (app.ordinaItem == nil) app.ordinaItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2379. subtitle:titoloAttuale
  2380. image:image
  2381. highlightedImage:nil
  2382. action:^(REMenuItem *item) {
  2383. [self orderTable:nuovoOrdinamento];
  2384. }];
  2385. else app.ordinaItem = [app.ordinaItem initWithTitle:titoloNuovo
  2386. subtitle:titoloAttuale
  2387. image:image
  2388. highlightedImage:nil
  2389. action:^(REMenuItem *item) {
  2390. [self orderTable:nuovoOrdinamento];
  2391. }];
  2392. // ITEM ASCENDING -----------------------------------------------------------------------------------------------------
  2393. ascendente = [CCUtility getAscendingSettings];
  2394. if (ascendente) {
  2395. image = [UIImage imageNamed:image_MenuOrdinamentoDiscendente];
  2396. titoloNuovo = NSLocalizedString(@"_sort_descending_", nil);
  2397. titoloAttuale = NSLocalizedString(@"_current_sort_ascending_", nil);
  2398. nuovoAscendente = false;
  2399. }
  2400. if (!ascendente) {
  2401. image = [UIImage imageNamed:image_MenuOrdinamentoAscendente];
  2402. titoloNuovo = NSLocalizedString(@"_sort_ascending_", nil);
  2403. titoloAttuale = NSLocalizedString(@"_current_sort_descending_", nil);
  2404. nuovoAscendente = true;
  2405. }
  2406. if (app.ascendenteItem == nil) app.ascendenteItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2407. subtitle:titoloAttuale
  2408. image:image
  2409. highlightedImage:nil
  2410. action:^(REMenuItem *item) {
  2411. [self ascendingTable:nuovoAscendente];
  2412. }];
  2413. else app.ascendenteItem = [app.ascendenteItem initWithTitle:titoloNuovo
  2414. subtitle:titoloAttuale
  2415. image:image
  2416. highlightedImage:nil
  2417. action:^(REMenuItem *item) {
  2418. [self ascendingTable:nuovoAscendente];
  2419. }];
  2420. // ITEM ALPHABETIC -----------------------------------------------------------------------------------------------------
  2421. if ([groupBy isEqualToString:@"alphabetic"]) { titoloNuovo = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  2422. else { titoloNuovo = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  2423. if (app.alphabeticItem == nil) app.alphabeticItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2424. subtitle:@""
  2425. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2426. highlightedImage:nil
  2427. action:^(REMenuItem *item) {
  2428. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2429. else [self tableGroupBy:@"alphabetic"];
  2430. }];
  2431. else app.alphabeticItem = [app.alphabeticItem initWithTitle:titoloNuovo
  2432. subtitle:@""
  2433. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2434. highlightedImage:nil
  2435. action:^(REMenuItem *item) {
  2436. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2437. else [self tableGroupBy:@"alphabetic"];
  2438. }];
  2439. // ITEM TYPEFILE -------------------------------------------------------------------------------------------------------
  2440. if ([groupBy isEqualToString:@"typefile"]) { titoloNuovo = NSLocalizedString(@"_group_typefile_yes_", nil); }
  2441. else { titoloNuovo = NSLocalizedString(@"_group_typefile_no_", nil); }
  2442. if (app.typefileItem == nil) app.typefileItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2443. subtitle:@""
  2444. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2445. highlightedImage:nil
  2446. action:^(REMenuItem *item) {
  2447. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2448. else [self tableGroupBy:@"typefile"];
  2449. }];
  2450. else app.typefileItem = [app.typefileItem initWithTitle:titoloNuovo
  2451. subtitle:@""
  2452. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2453. highlightedImage:nil
  2454. action:^(REMenuItem *item) {
  2455. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2456. else [self tableGroupBy:@"typefile"];
  2457. }];
  2458. // ITEM DATE -------------------------------------------------------------------------------------------------------
  2459. if ([groupBy isEqualToString:@"date"]) { titoloNuovo = NSLocalizedString(@"_group_date_yes_", nil); }
  2460. else { titoloNuovo = NSLocalizedString(@"_group_date_no_", nil); }
  2461. if (app.dateItem == nil) app.dateItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2462. subtitle:@""
  2463. image:[UIImage imageNamed:image_MenuGroupByDate]
  2464. highlightedImage:nil
  2465. action:^(REMenuItem *item) {
  2466. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2467. else [self tableGroupBy:@"date"];
  2468. }];
  2469. else app.dateItem = [app.dateItem initWithTitle:titoloNuovo
  2470. subtitle:@""
  2471. image:[UIImage imageNamed:image_MenuGroupByDate]
  2472. highlightedImage:nil
  2473. action:^(REMenuItem *item) {
  2474. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2475. else [self tableGroupBy:@"date"];
  2476. }];
  2477. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  2478. if ([CCUtility getDirectoryOnTop]) { titoloNuovo = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  2479. else { titoloNuovo = NSLocalizedString(@"_directory_on_top_no_", nil); }
  2480. if (app.directoryOnTopItem == nil) app.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2481. subtitle:@""
  2482. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2483. highlightedImage:nil
  2484. action:^(REMenuItem *item) {
  2485. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2486. else [self directoryOnTop:YES];
  2487. }];
  2488. else app.directoryOnTopItem = [app.directoryOnTopItem initWithTitle:titoloNuovo
  2489. subtitle:@""
  2490. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2491. highlightedImage:nil
  2492. action:^(REMenuItem *item) {
  2493. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2494. else [self directoryOnTop:YES];
  2495. }];
  2496. // REMENU --------------------------------------------------------------------------------------------------------------
  2497. 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]];
  2498. else app.reMainMenu = [app.reMainMenu initWithItems:@[app.browseItem, app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2499. app.reMainMenu.imageOffset = CGSizeMake(5, -1);
  2500. app.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2501. app.reMainMenu.imageOffset = CGSizeMake(0, 0);
  2502. app.reMainMenu.waitUntilAnimationIsComplete = NO;
  2503. app.reMainMenu.separatorHeight = 0.5;
  2504. app.reMainMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2505. app.reMainMenu.backgroundColor = COLOR_BAR;
  2506. app.reMainMenu.textColor = [UIColor blackColor];
  2507. app.reMainMenu.textAlignment = NSTextAlignmentLeft;
  2508. app.reMainMenu.textShadowColor = nil;
  2509. app.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  2510. app.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  2511. app.reMainMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2512. app.reMainMenu.highlightedSeparatorColor = nil;
  2513. app.reMainMenu.highlightedTextColor = [UIColor blackColor];
  2514. app.reMainMenu.highlightedTextShadowColor = nil;
  2515. app.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2516. app.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  2517. app.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2518. app.reMainMenu.subtitleTextShadowColor = nil;
  2519. app.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2520. app.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2521. app.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2522. app.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2523. app.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  2524. app.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2525. app.reMainMenu.borderWidth = 0.3;
  2526. app.reMainMenu.borderColor = [UIColor lightGrayColor];
  2527. app.reMainMenu.animationDuration = 0.2;
  2528. app.reMainMenu.closeAnimationDuration = 0.2;
  2529. app.reMainMenu.bounce = NO;
  2530. [app.reMainMenu setClosePreparationBlock:^{
  2531. // Backgroun reMenu (Gesture)
  2532. [_reMenuBackgroundView removeFromSuperview];
  2533. [app.controlCenter disableSingleFingerTap];
  2534. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2535. }];
  2536. }
  2537. - (void)toggleReMainMenu
  2538. {
  2539. if (app.reMainMenu.isOpen) {
  2540. [app.reMainMenu close];
  2541. } else {
  2542. [app.reMainMenu showFromNavigationController:self.navigationController];
  2543. // Backgroun reMenu & (Gesture)
  2544. [self createReMenuBackgroundView:app.reMainMenu];
  2545. [app.controlCenter enableSingleFingerTap:@selector(toggleReMainMenu) target:self];
  2546. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  2547. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2548. }
  2549. }
  2550. - (void)createReSelectMenu
  2551. {
  2552. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  2553. if (app.deleteItem == nil) app.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2554. subtitle:@""
  2555. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2556. highlightedImage:nil
  2557. action:^(REMenuItem *item) {
  2558. [self deleteSelectionFile];
  2559. }];
  2560. else app.deleteItem = [app.deleteItem initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2561. subtitle:@""
  2562. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2563. highlightedImage:nil
  2564. action:^(REMenuItem *item) {
  2565. [self deleteSelectionFile];
  2566. }];
  2567. // ITEM MOVE ------------------------------------------------------------------------------------------------------
  2568. if (app.moveItem == nil) app.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2569. subtitle:@""
  2570. image:[UIImage imageNamed:image_moveSelectedFiles]
  2571. highlightedImage:nil
  2572. action:^(REMenuItem *item) {
  2573. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2574. }];
  2575. else app.moveItem = [app.moveItem initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2576. subtitle:@""
  2577. image:[UIImage imageNamed:image_moveSelectedFiles]
  2578. highlightedImage:nil
  2579. action:^(REMenuItem *item) {
  2580. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2581. }];
  2582. // ITEM ENCRYPTED ------------------------------------------------------------------------------------------------------
  2583. if (app.encryptItem == nil) app.encryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2584. subtitle:@""
  2585. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2586. highlightedImage:nil
  2587. action:^(REMenuItem *item) {
  2588. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2589. }];
  2590. else app.encryptItem = [app.encryptItem initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2591. subtitle:@""
  2592. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2593. highlightedImage:nil
  2594. action:^(REMenuItem *item) {
  2595. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2596. }];
  2597. // ITEM DECRYPTED ----------------------------------------------------------------------------------------------------
  2598. if (app.decryptItem == nil) app.decryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2599. subtitle:@""
  2600. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2601. highlightedImage:nil
  2602. action:^(REMenuItem *item) {
  2603. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2604. }];
  2605. else app.decryptItem = [app.decryptItem initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2606. subtitle:@""
  2607. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2608. highlightedImage:nil
  2609. action:^(REMenuItem *item) {
  2610. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2611. }];
  2612. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  2613. if (app.downloadItem == nil) app.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2614. subtitle:@""
  2615. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2616. highlightedImage:nil
  2617. action:^(REMenuItem *item) {
  2618. [self downloadSelectedFiles];
  2619. }];
  2620. else app.downloadItem = [app.downloadItem initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2621. subtitle:@""
  2622. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2623. highlightedImage:nil
  2624. action:^(REMenuItem *item) {
  2625. [self downloadSelectedFiles];
  2626. }];
  2627. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  2628. if (app.saveItem == nil) app.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2629. subtitle:@""
  2630. image:[UIImage imageNamed:image_saveSelectedFiles]
  2631. highlightedImage:nil
  2632. action:^(REMenuItem *item) {
  2633. [self saveSelectedFiles];
  2634. }];
  2635. else app.saveItem = [app.saveItem initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2636. subtitle:@""
  2637. image:[UIImage imageNamed:image_saveSelectedFiles]
  2638. highlightedImage:nil
  2639. action:^(REMenuItem *item) {
  2640. [self saveSelectedFiles];
  2641. }];
  2642. // REMENU --------------------------------------------------------------------------------------------------------------
  2643. if (app.reSelectMenu == nil)
  2644. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2645. else
  2646. app.reSelectMenu = [app.reSelectMenu initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2647. app.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  2648. app.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2649. app.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  2650. app.reSelectMenu.waitUntilAnimationIsComplete = NO;
  2651. app.reSelectMenu.separatorHeight = 0.5;
  2652. app.reSelectMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2653. app.reSelectMenu.backgroundColor = COLOR_BAR;
  2654. app.reSelectMenu.textColor = [UIColor blackColor];
  2655. app.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  2656. app.reSelectMenu.textShadowColor = nil;
  2657. app.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  2658. app.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  2659. app.reSelectMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2660. app.reSelectMenu.highlightedSeparatorColor = nil;
  2661. app.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  2662. app.reSelectMenu.highlightedTextShadowColor = nil;
  2663. app.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2664. app.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  2665. app.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2666. app.reSelectMenu.subtitleTextShadowColor = nil;
  2667. app.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2668. app.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2669. app.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2670. app.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2671. app.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  2672. app.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2673. app.reSelectMenu.borderWidth = 0.3;
  2674. app.reSelectMenu.borderColor = [UIColor lightGrayColor];
  2675. app.reSelectMenu.closeAnimationDuration = 0.2;
  2676. app.reSelectMenu.animationDuration = 0.2;
  2677. app.reSelectMenu.bounce = NO;
  2678. [app.reSelectMenu setClosePreparationBlock:^{
  2679. // Backgroun reMenu (Gesture)
  2680. [_reMenuBackgroundView removeFromSuperview];
  2681. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2682. }];
  2683. }
  2684. - (void)toggleReSelectMenu
  2685. {
  2686. if (app.reSelectMenu.isOpen) {
  2687. [app.reSelectMenu close];
  2688. } else {
  2689. [app.reSelectMenu showFromNavigationController:self.navigationController];
  2690. // Backgroun reMenu & (Gesture)
  2691. [self createReMenuBackgroundView:app.reSelectMenu];
  2692. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  2693. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2694. }
  2695. }
  2696. #pragma --------------------------------------------------------------------------------------------
  2697. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  2698. #pragma --------------------------------------------------------------------------------------------
  2699. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  2700. {
  2701. if (recognizer.state == UIGestureRecognizerStateBegan) {
  2702. UITableView *tableView = (UITableView*)self.view;
  2703. CGPoint touchPoint = [recognizer locationInView:self.view];
  2704. NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:touchPoint];
  2705. if (indexPath)
  2706. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  2707. else
  2708. _metadata = nil;
  2709. [self becomeFirstResponder];
  2710. UIMenuController *menuController = [UIMenuController sharedMenuController];
  2711. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  2712. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  2713. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  2714. UIMenuItem *pasteFileEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_encrypted_", nil) action:@selector(pasteFileEncrypted:)];
  2715. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  2716. UIMenuItem *pasteFilesEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_encrypted_", nil) action:@selector(pasteFilesEncrypted:)];
  2717. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, pasteFileItem, pasteFilesItem, pasteFileEncryptedItem, pasteFilesEncryptedItem, nil]];
  2718. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:tableView];
  2719. [menuController setMenuVisible:YES animated:YES];
  2720. }
  2721. }
  2722. - (BOOL)canBecomeFirstResponder
  2723. {
  2724. return YES;
  2725. }
  2726. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  2727. {
  2728. if (@selector(copyFile:) == action) {
  2729. if (_isSelectedMode == NO && _metadata) {
  2730. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) return YES;
  2731. else return NO;
  2732. } else return NO;
  2733. }
  2734. if (@selector(copyFiles:) == action) {
  2735. if (_isSelectedMode) {
  2736. BOOL isValid = NO;
  2737. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2738. for (CCMetadata *metadata in selectedMetadatas) {
  2739. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  2740. isValid = YES;
  2741. }
  2742. return isValid;
  2743. } else return NO;
  2744. }
  2745. if (@selector(pasteFile:) == action || @selector(pasteFileEncrypted:) == action) {
  2746. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2747. NSArray *items = [pasteboard items];
  2748. if ([items count] == 1) {
  2749. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2750. NSDictionary *dic = [items objectAtIndex:0];
  2751. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2752. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2753. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2754. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2755. if (directoryUser) {
  2756. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2757. return YES;
  2758. }
  2759. return NO;
  2760. } else return NO;
  2761. }
  2762. if (@selector(pasteFiles:) == action || @selector(pasteFilesEncrypted:) == action) {
  2763. BOOL isValid = NO;
  2764. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2765. NSArray *items = [pasteboard items];
  2766. if ([items count] <= 1) return NO;
  2767. for (NSDictionary *dic in items) {
  2768. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2769. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2770. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2771. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2772. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2773. if (directoryUser) {
  2774. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2775. isValid = YES;
  2776. }
  2777. }
  2778. return isValid;
  2779. }
  2780. return NO;
  2781. }
  2782. /************************************ COPY ************************************/
  2783. - (void)copyFile:(id)sender
  2784. {
  2785. [self copyFileFiles];
  2786. }
  2787. - (void)copyFiles:(id)sender
  2788. {
  2789. [self copyFileFiles];
  2790. }
  2791. - (void)copyFileFiles
  2792. {
  2793. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2794. NSMutableArray *items = [[NSMutableArray alloc] init];
  2795. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2796. if (_isSelectedMode) {
  2797. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2798. for (CCMetadata *metadata in selectedMetadatas) {
  2799. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]]) {
  2800. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata], @"it.twsweb.Crypto-Cloud.CCMetadata",nil];
  2801. [items addObject:item];
  2802. }
  2803. }
  2804. [self tableViewSelect:NO];
  2805. } else {
  2806. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser,_metadata.fileID]]) {
  2807. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:_metadata], @"it.twsweb.Crypto-Cloud.CCMetadata", nil];
  2808. [items addObject:item];
  2809. }
  2810. }
  2811. pasteboard.items = items;
  2812. }
  2813. /************************************ PASTE ************************************/
  2814. - (void)pasteFile:(id)sender
  2815. {
  2816. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2817. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2818. }
  2819. - (void)pasteFileEncrypted:(id)sender
  2820. {
  2821. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2822. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2823. }
  2824. - (void)pasteFiles:(id)sender
  2825. {
  2826. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2827. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2828. }
  2829. - (void)pasteFilesEncrypted:(id)sender
  2830. {
  2831. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2832. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2833. }
  2834. - (void)uploadFilePasteArray:(NSArray *)items cryptated:(BOOL)cryptated
  2835. {
  2836. for (NSDictionary *dic in items) {
  2837. // key : it.twsweb.Crypto-Cloud.CCMetadata
  2838. // Value : (NSData) metadata
  2839. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2840. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2841. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2842. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2843. if (directoryUser) {
  2844. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]]) {
  2845. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint]];
  2846. [[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];
  2847. }
  2848. }
  2849. }
  2850. }
  2851. #pragma --------------------------------------------------------------------------------------------
  2852. #pragma mark ===== Lock Passcode =====
  2853. #pragma --------------------------------------------------------------------------------------------
  2854. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  2855. {
  2856. return _failedAttempts;
  2857. }
  2858. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2859. {
  2860. return _lockUntilDate;
  2861. }
  2862. - (void)passcodeViewCloseButtonPressed:(id)sender
  2863. {
  2864. [self dismissViewControllerAnimated:YES completion:nil];
  2865. }
  2866. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2867. {
  2868. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2869. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2870. _lockUntilDate = nil;
  2871. _failedAttempts = 0;
  2872. aResultHandler(YES);
  2873. } else aResultHandler(NO);
  2874. } else aResultHandler(YES);
  2875. }
  2876. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2877. {
  2878. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2879. switch (aViewController.type) {
  2880. case BKPasscodeViewControllerCheckPasscodeType: {
  2881. if (aViewController.fromType == CCBKPasscodeFromPasscode) {
  2882. CCCrypto *crypto = [[CCCrypto alloc] init];
  2883. // verifichiamo se il passcode è corretto per il seguente file -> UUID
  2884. if ([crypto verifyPasscode:aPasscode uuid:_metadata.uuid text:_metadata.title]) {
  2885. // scriviamo il passcode
  2886. [CCUtility setKeyChainPasscodeForUUID:_metadata.uuid conPasscode:aPasscode];
  2887. [self readFolderWithForced:YES];
  2888. } else {
  2889. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_error_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  2890. [alertView show];
  2891. }
  2892. }
  2893. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  2894. // possiamo procedere alla prossima directory
  2895. [self performSegueDirectoryWithControlPasscode:false];
  2896. // avviamo la sessione Passcode Lock con now
  2897. app.sessionePasscodeLock = [NSDate date];
  2898. }
  2899. // disattivazione lock cartella
  2900. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  2901. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  2902. if ([CCCoreData setDirectoryUnLock:lockServerUrl activeAccount:app.activeAccount] == NO) {
  2903. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2904. }
  2905. [self.tableView reloadData];
  2906. }
  2907. }
  2908. break;
  2909. default:
  2910. break;
  2911. }
  2912. }
  2913. - (void)comandoLockPassword
  2914. {
  2915. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  2916. // se non è abilitato il Lock Passcode esci
  2917. if ([[CCUtility getBlockCode] length] == 0) {
  2918. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  2919. [alertView show];
  2920. return;
  2921. }
  2922. // se è richiesta la disattivazione si chiede la password
  2923. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  2924. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2925. viewController.delegate = self;
  2926. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  2927. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2928. viewController.inputViewTitlePassword = YES;
  2929. if ([CCUtility getSimplyBlockCode]) {
  2930. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2931. viewController.passcodeInputView.maximumLength = 6;
  2932. } else {
  2933. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2934. viewController.passcodeInputView.maximumLength = 64;
  2935. }
  2936. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  2937. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2938. viewController.touchIDManager = touchIDManager;
  2939. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  2940. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  2941. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  2942. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  2943. [self presentViewController:navigationController animated:YES completion:nil];
  2944. return;
  2945. }
  2946. // ---------------- ACTIVATE PASSWORD
  2947. if([CCCoreData setDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  2948. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  2949. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2950. } else {
  2951. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2952. }
  2953. }
  2954. #pragma --------------------------------------------------------------------------------------------
  2955. #pragma mark ===== Swipe Tablet -> menu =====
  2956. #pragma --------------------------------------------------------------------------------------------
  2957. // more
  2958. - (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  2959. return NSLocalizedString(@"_more_", nil);
  2960. }
  2961. - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
  2962. {
  2963. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  2964. NSString *titoloCriptaDecripta, *titoloPreferiti, *titoloLock, *titoloSynchronized;
  2965. BOOL synchronized = NO;
  2966. if (_metadata.cryptated) titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_decrypt_", nil)];
  2967. else titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_encrypt_", nil)];
  2968. if ([CCCoreData isFavorite:_metadata.fileID activeAccount:app.activeAccount]) titoloPreferiti = [NSString stringWithFormat:NSLocalizedString(@"_remove_favorites_", nil)];
  2969. else titoloPreferiti = [NSString stringWithFormat:NSLocalizedString(@"_add_favorites_", nil)];
  2970. NSString *synchronizedServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  2971. if (_metadata.directory && [CCCoreData isSynchronizedDirectory:synchronizedServerUrl activeAccount:app.activeAccount]) {
  2972. titoloSynchronized = [NSString stringWithFormat:NSLocalizedString(@"_remove_synchronized_folder_", nil)];
  2973. synchronized = YES;
  2974. } else titoloSynchronized = [NSString stringWithFormat:NSLocalizedString(@"_synchronized_folder_", nil)];
  2975. if (_metadata.directory) {
  2976. // calcolo lockServerUrl
  2977. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  2978. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  2979. else titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  2980. }
  2981. /******************************************* AHKActionSheet *******************************************/
  2982. UIImage *iconHeader;
  2983. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  2984. actionSheet.animationDuration = 0.2;
  2985. actionSheet.blurRadius = 0.0f;
  2986. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  2987. actionSheet.buttonHeight = 50.0;
  2988. actionSheet.cancelButtonHeight = 50.0f;
  2989. actionSheet.separatorHeight = 5.0f;
  2990. actionSheet.automaticallyTintButtonImages = @(NO);
  2991. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_ENCRYPTED };
  2992. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_GRAY };
  2993. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  2994. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:COLOR_GRAY };
  2995. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  2996. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  2997. /******************************************* DIRECTORY *******************************************/
  2998. if (_metadata.directory) {
  2999. UIImage *iconHeader;
  3000. BOOL lockDirectory = NO;
  3001. // calcolo lockServerUrl
  3002. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3003. // Directory bloccata ?
  3004. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3005. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3006. NSString *cameraUploadFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  3007. NSString *cameraUploadFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  3008. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3009. image: iconHeader
  3010. backgroundColor: COLOR_NAVBAR_IOS7
  3011. height: 50.0
  3012. type: AHKActionSheetButtonTypeDisabled
  3013. handler: nil
  3014. ];
  3015. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3016. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3017. image:[UIImage imageNamed:image_actionSheetRename]
  3018. backgroundColor:[UIColor whiteColor]
  3019. height: 50.0
  3020. type:AHKActionSheetButtonTypeDefault
  3021. handler:^(AHKActionSheet *as) {
  3022. // close swipe
  3023. [self setEditing:NO animated:YES];
  3024. //chiediamo il nome del file
  3025. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3026. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3027. alertView.tag = alertRename;
  3028. UITextField *textField = [alertView textFieldAtIndex:0];
  3029. textField.text = _metadata.fileNamePrint;
  3030. [alertView show];
  3031. }];
  3032. }
  3033. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3034. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3035. image:[UIImage imageNamed:image_actionSheetMove]
  3036. backgroundColor:[UIColor whiteColor]
  3037. height: 50.0
  3038. type:AHKActionSheetButtonTypeDefault
  3039. handler:^(AHKActionSheet *as) {
  3040. // close swipe
  3041. [self setEditing:NO animated:YES];
  3042. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3043. }];
  3044. }
  3045. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3046. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3047. image:[UIImage imageNamed:image_actionSheetCrypto]
  3048. backgroundColor:[UIColor whiteColor]
  3049. height: 50.0
  3050. type:AHKActionSheetButtonTypeEncrypted
  3051. handler:^(AHKActionSheet *as) {
  3052. // close swipe
  3053. [self setEditing:NO animated:YES];
  3054. [self performSelector:@selector(encyptedDecryptedFolder) withObject:nil afterDelay:0.1];
  3055. }];
  3056. }
  3057. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES)) {
  3058. [actionSheet addButtonWithTitle:titoloLock
  3059. image:[UIImage imageNamed:image_actionSheetLock]
  3060. backgroundColor:[UIColor whiteColor]
  3061. height: 50.0
  3062. type:AHKActionSheetButtonTypeEncrypted
  3063. handler:^(AHKActionSheet *as) {
  3064. // close swipe
  3065. [self setEditing:NO animated:YES];
  3066. [self performSelector:@selector(comandoLockPassword) withObject:nil afterDelay:0.1];
  3067. }];
  3068. }
  3069. if (_metadata.cryptated == NO && app.hasServerShareSupport && !lockDirectory) {
  3070. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3071. image:[UIImage imageNamed:image_actionSheetShare]
  3072. backgroundColor:[UIColor whiteColor]
  3073. height: 50.0
  3074. type:AHKActionSheetButtonTypeDefault
  3075. handler:^(AHKActionSheet *as) {
  3076. // close swipe
  3077. [self setEditing:NO animated:YES];
  3078. [self openWindowShare:_metadata serverUrl:_localServerUrl];
  3079. }];
  3080. }
  3081. if (!lockDirectory) {
  3082. [actionSheet addButtonWithTitle:titoloSynchronized
  3083. image:[UIImage imageNamed:image_actionSheetSynchronized]
  3084. backgroundColor:[UIColor whiteColor]
  3085. height: 50.0
  3086. type:AHKActionSheetButtonTypeDefault
  3087. handler:^(AHKActionSheet *as) {
  3088. // close swipe
  3089. [self setEditing:NO animated:YES];
  3090. if (synchronized == NO) {
  3091. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"",nil) message:NSLocalizedString(@"_synchronized_confirm_",nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3092. alertView.tag = alertSynchronization;
  3093. [alertView show];
  3094. } else {
  3095. [[CCSynchronization sharedSynchronization] synchronizationFolder:[CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData]];
  3096. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.5];
  3097. }
  3098. }];
  3099. }
  3100. [actionSheet show];
  3101. }
  3102. /******************************************* FILE *******************************************/
  3103. if ([_metadata.type isEqualToString:metadataType_file] && !_metadata.directory) {
  3104. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3105. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]])
  3106. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]];
  3107. else
  3108. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3109. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3110. image: iconHeader
  3111. backgroundColor: COLOR_NAVBAR_IOS7
  3112. height: 50.0
  3113. type: AHKActionSheetButtonTypeDisabled
  3114. handler: nil
  3115. ];
  3116. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3117. image:[UIImage imageNamed:image_actionSheetRename]
  3118. backgroundColor:[UIColor whiteColor]
  3119. height: 50.0
  3120. type:AHKActionSheetButtonTypeDefault
  3121. handler:^(AHKActionSheet *as) {
  3122. // close swipe
  3123. [self setEditing:NO animated:YES];
  3124. //chiediamo il nome del file
  3125. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3126. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3127. alertView.tag = alertRename;
  3128. UITextField *textField = [alertView textFieldAtIndex:0];
  3129. textField.text = _metadata.fileNamePrint;
  3130. [alertView show];
  3131. }];
  3132. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3133. image:[UIImage imageNamed:image_actionSheetMove]
  3134. backgroundColor:[UIColor whiteColor]
  3135. height: 50.0
  3136. type:AHKActionSheetButtonTypeDefault
  3137. handler:^(AHKActionSheet *as) {
  3138. // close swipe
  3139. [self setEditing:NO animated:YES];
  3140. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3141. }];
  3142. [actionSheet addButtonWithTitle:NSLocalizedString(@"_reload_", nil)
  3143. image:[UIImage imageNamed:image_actionSheetReload]
  3144. backgroundColor:[UIColor whiteColor]
  3145. height: 50.0
  3146. type:AHKActionSheetButtonTypeDefault
  3147. handler:^(AHKActionSheet *as) {
  3148. // close swipe
  3149. [self setEditing:NO animated:YES];
  3150. [self performSelector:@selector(reloadFile:) withObject:_metadata afterDelay:0.1];
  3151. }];
  3152. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  3153. image:[UIImage imageNamed:image_actionSheetOpenIn]
  3154. backgroundColor:[UIColor whiteColor]
  3155. height: 50.0
  3156. type:AHKActionSheetButtonTypeDefault
  3157. handler:^(AHKActionSheet *as) {
  3158. // close swipe
  3159. [self setEditing:NO animated:YES];
  3160. [self performSelector:@selector(openIn:) withObject:_metadata afterDelay:0.1];
  3161. }];
  3162. if (_metadata.cryptated == NO && app.hasServerShareSupport) {
  3163. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3164. image:[UIImage imageNamed:image_actionSheetShare]
  3165. backgroundColor:[UIColor whiteColor]
  3166. height: 50.0
  3167. type:AHKActionSheetButtonTypeDefault
  3168. handler:^(AHKActionSheet *as) {
  3169. // close swipe
  3170. [self setEditing:NO animated:YES];
  3171. [self openWindowShare:_metadata serverUrl:_localServerUrl];
  3172. }];
  3173. }
  3174. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3175. image:[UIImage imageNamed:image_actionSheetCrypto]
  3176. backgroundColor:[UIColor whiteColor]
  3177. height: 50.0
  3178. type:AHKActionSheetButtonTypeEncrypted
  3179. handler:^(AHKActionSheet *as) {
  3180. // close swipe
  3181. [self setEditing:NO animated:YES];
  3182. [self performSelector:@selector(cmdEncryptedDecryptedFile) withObject:nil afterDelay:0.1];
  3183. }];
  3184. [actionSheet addButtonWithTitle:titoloPreferiti
  3185. image:[UIImage imageNamed:image_actionSheetFavorite]
  3186. backgroundColor:[UIColor whiteColor]
  3187. height: 50.0
  3188. type:AHKActionSheetButtonTypeDefault
  3189. handler:^(AHKActionSheet *as) {
  3190. // close swipe
  3191. [self setEditing:NO animated:YES];
  3192. if ([CCCoreData isFavorite:_metadata.fileID activeAccount:app.activeAccount])
  3193. [self removeFavorite:_metadata];
  3194. else
  3195. [self addFavorite:_metadata];
  3196. }];
  3197. [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
  3198. image:[UIImage imageNamed:image_actionSheetLocal]
  3199. backgroundColor:[UIColor whiteColor]
  3200. height: 50.0
  3201. type:AHKActionSheetButtonTypeDefault
  3202. handler:^(AHKActionSheet *as) {
  3203. // close swipe
  3204. [self setEditing:NO animated:YES];
  3205. [self performSelector:@selector(addLocal:) withObject:_metadata afterDelay:0.1];
  3206. }];
  3207. [actionSheet show];
  3208. }
  3209. /******************************************* TEMPLATE *******************************************/
  3210. if ([_metadata.type isEqualToString:metadataType_model]) {
  3211. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3212. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3213. image: iconHeader
  3214. backgroundColor: COLOR_NAVBAR_IOS7
  3215. height: 50.0
  3216. type: AHKActionSheetButtonTypeDisabled
  3217. handler: nil
  3218. ];
  3219. if ([_metadata.model isEqualToString:@"note"]) {
  3220. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3221. image:[UIImage imageNamed:image_actionSheetRename]
  3222. backgroundColor:[UIColor whiteColor]
  3223. height: 50.0
  3224. type:AHKActionSheetButtonTypeDefault
  3225. handler:^(AHKActionSheet *as) {
  3226. // close swipe
  3227. [self setEditing:NO animated:YES];
  3228. //chiediamo il nome del file
  3229. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3230. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3231. alertView.tag = alertRename;
  3232. UITextField *textField = [alertView textFieldAtIndex:0];
  3233. textField.text = _metadata.fileNamePrint;
  3234. [alertView show];
  3235. }];
  3236. }
  3237. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3238. image:[UIImage imageNamed:image_actionSheetMove]
  3239. backgroundColor:[UIColor whiteColor]
  3240. height: 50.0
  3241. type:AHKActionSheetButtonTypeDefault
  3242. handler:^(AHKActionSheet *as) {
  3243. // close swipe
  3244. [self setEditing:NO animated:YES];
  3245. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3246. }];
  3247. [actionSheet addButtonWithTitle:titoloPreferiti
  3248. image:[UIImage imageNamed:image_actionSheetFavorite]
  3249. backgroundColor:[UIColor whiteColor]
  3250. height: 50.0
  3251. type:AHKActionSheetButtonTypeDefault
  3252. handler:^(AHKActionSheet *as) {
  3253. // close swipe
  3254. [self setEditing:NO animated:YES];
  3255. if ([CCCoreData isFavorite:_metadata.fileID activeAccount:app.activeAccount])
  3256. [self removeFavorite:_metadata];
  3257. else
  3258. [self addFavorite:_metadata];
  3259. }];
  3260. [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
  3261. image:[UIImage imageNamed:image_actionSheetLocal]
  3262. backgroundColor:[UIColor whiteColor]
  3263. height: 50.0
  3264. type:AHKActionSheetButtonTypeDefault
  3265. handler:^(AHKActionSheet *as) {
  3266. // close swipe
  3267. [self setEditing:NO animated:YES];
  3268. [self performSelector:@selector(addLocal:) withObject:_metadata afterDelay:0.1];
  3269. }];
  3270. [actionSheet show];
  3271. }
  3272. }
  3273. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  3274. {
  3275. return NSLocalizedString(@"_delete_", nil);
  3276. }
  3277. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  3278. {
  3279. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3280. if (metadata == nil || metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier >= 0 || metadata.sessionTaskIdentifier >= 0) return NO;
  3281. else return YES;
  3282. }
  3283. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  3284. {
  3285. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3286. if (_metadata.errorPasscode || (_metadata.cryptated && [_metadata.title length] == 0) || _metadata.sessionTaskIdentifier >= 0 || _metadata.sessionTaskIdentifier >= 0) return UITableViewCellEditingStyleNone;
  3287. else return UITableViewCellEditingStyleDelete;
  3288. }
  3289. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  3290. {
  3291. BOOL lockDirectory = NO;
  3292. // Directory locked ?
  3293. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3294. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3295. if (lockDirectory && editingStyle == UITableViewCellEditingStyleDelete) {
  3296. [app messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  3297. return;
  3298. }
  3299. if (editingStyle == UITableViewCellEditingStyleDelete) {
  3300. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3301. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  3302. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  3303. style:UIAlertActionStyleDestructive
  3304. handler:^(UIAlertAction *action) {
  3305. [self performSelector:@selector(deleteFile) withObject:nil afterDelay:0.1];
  3306. }]];
  3307. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  3308. style:UIAlertActionStyleCancel
  3309. handler:^(UIAlertAction *action) {
  3310. [alertController dismissViewControllerAnimated:YES completion:nil];
  3311. }]];
  3312. alertController.popoverPresentationController.sourceView = self.view;
  3313. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  3314. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  3315. [alertController.view layoutIfNeeded];
  3316. [self presentViewController:alertController animated:YES completion:nil];
  3317. }
  3318. }
  3319. #pragma --------------------------------------------------------------------------------------------
  3320. #pragma mark - ==== Datasource ====
  3321. #pragma --------------------------------------------------------------------------------------------
  3322. - (void)clearDateReadDataSource:(NSNotification *)notification
  3323. {
  3324. _dateReadDataSource = Nil;
  3325. }
  3326. - (void)getDataSourceWithReloadTableView
  3327. {
  3328. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  3329. }
  3330. - (void)getDataSourceWithReloadTableView:(NSString *)directoryID fileID:(NSString *)fileID selector:(NSString *)selector
  3331. {
  3332. if (app.activeAccount == nil || app.activeUrl == nil || directoryID == nil)
  3333. return;
  3334. // Reload -> Favorite ?
  3335. if (fileID)
  3336. if ([CCCoreData isFavorite:fileID activeAccount:app.activeAccount])
  3337. [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableFavorite" object:nil];
  3338. // Reload -> Self se non siamo nella dir appropriata cercala e se è in memoria reindirizza il reload
  3339. if ([directoryID isEqualToString:_localDirectoryID] == NO || _localServerUrl == nil) {
  3340. if ([selector isEqualToString:selectorDownloadSynchronized]) {
  3341. [app.controlCenter reloadDatasource];
  3342. } else {
  3343. CCMain *main = [app.listMainVC objectForKey:[CCCoreData getServerUrlFromDirectoryID:directoryID activeAccount:app.activeAccount]];
  3344. if (main) {
  3345. [main getDataSourceWithReloadTableView];
  3346. } else {
  3347. [self tableViewReload];
  3348. [app.controlCenter reloadDatasource];
  3349. }
  3350. }
  3351. return;
  3352. }
  3353. [app.controlCenter reloadDatasource];
  3354. // Settaggio variabili per le ottimizzazioni
  3355. _directoryGroupBy = [CCUtility getGroupBySettings];
  3356. _directoryOrder = [CCUtility getOrderSettings];
  3357. // Controllo data lettura Data Source
  3358. NSDate *dateDateRecordDirectory = [CCCoreData getDateReadDirectoryID:_localDirectoryID activeAccount:app.activeAccount];
  3359. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  3360. NSLog(@"[LOG] Rebuild Data Source File : %@", _localServerUrl);
  3361. _dateReadDataSource = [NSDate date];
  3362. // Data Source
  3363. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, directoryID] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  3364. _sectionDataSource = [CCSection creataDataSourseSectionTableMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3365. // if DataSource has no records, Data Nil
  3366. //if ([_sectionDataSource.allRecordsDataSource count] == 0)
  3367. // _dateReadDataSource = nil;
  3368. } else {
  3369. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _localServerUrl, _dateReadDataSource);
  3370. }
  3371. [self tableViewReload];
  3372. [self setTitleBackgroundTableView];
  3373. [app updateApplicationIconBadgeNumber];
  3374. }
  3375. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  3376. {
  3377. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  3378. if (selectedRows.count > 0) {
  3379. for (NSIndexPath *selectionIndex in selectedRows) {
  3380. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  3381. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3382. [metadatas addObject:metadata];
  3383. }
  3384. }
  3385. return metadatas;
  3386. }
  3387. - (CCMetadata *)getMetadataFromSectionDataSource:(NSIndexPath *)indexPath
  3388. {
  3389. NSInteger section = indexPath.section + 1;
  3390. NSInteger row = indexPath.row + 1;
  3391. NSInteger totSections =[_sectionDataSource.sections count] ;
  3392. if ((totSections < section) || (section > totSections)) {
  3393. NSString *message = [NSString stringWithFormat:@"DEBUG [0] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section];
  3394. NSLog(@"[LOG] %@", message);
  3395. #if DEBUG
  3396. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3397. [alertView show];
  3398. #endif
  3399. return nil;
  3400. }
  3401. id valueSection = [_sectionDataSource.sections objectAtIndex:indexPath.section];
  3402. NSArray *fileIDs = [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3403. if (fileIDs) {
  3404. NSInteger totRows =[fileIDs count] ;
  3405. if ((totRows < row) || (row > totRows)) {
  3406. NSString *message = [NSString stringWithFormat:@"DEBUG [1] : error row, totRows = %lu - row = %lu [%@] [%@] [%@]", (long)totRows, (long)row, valueSection, _localDirectoryID, _localServerUrl];
  3407. NSLog(@"[LOG] %@", message);
  3408. #if DEBUG
  3409. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3410. [alertView show];
  3411. #endif
  3412. return nil;
  3413. }
  3414. } else {
  3415. NSLog(@"[LOG] DEBUG [2] : fileIDs is NIL");
  3416. #if DEBUG
  3417. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:@"DEBUG [2] : fileIDs is NIL" delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3418. [alertView show];
  3419. #endif
  3420. return nil;
  3421. }
  3422. NSString *fileID = [fileIDs objectAtIndex:indexPath.row];
  3423. return [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3424. }
  3425. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  3426. {
  3427. NSInteger totSections =[_sectionDataSource.sections count] ;
  3428. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  3429. #if DEBUG
  3430. 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];
  3431. [alertView show];
  3432. #endif
  3433. return nil;
  3434. }
  3435. id valueSection = [_sectionDataSource.sections objectAtIndex:section];
  3436. return [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3437. }
  3438. #pragma --------------------------------------------------------------------------------------------
  3439. #pragma mark - ==== Table ====
  3440. #pragma --------------------------------------------------------------------------------------------
  3441. - (void)tableViewSelect:(BOOL)edit
  3442. {
  3443. // chiudiamo eventuali swipe aperti
  3444. if (edit) [self.tableView setEditing:NO animated:NO];
  3445. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  3446. [self.tableView setEditing:edit animated:YES];
  3447. _isSelectedMode = edit;
  3448. if (edit)
  3449. [self setUINavigationBarSeleziona];
  3450. else
  3451. [self setUINavigationBarDefault];
  3452. [self setTitleNOAnimation];
  3453. }
  3454. - (void)tableViewReload
  3455. {
  3456. // ricordiamoci le row selezionate
  3457. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  3458. [self.tableView reloadData];
  3459. for (NSIndexPath *path in indexPaths)
  3460. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  3461. [self setTableViewFooter];
  3462. if (self.tableView.editing)
  3463. [self setTitleNOAnimation];
  3464. }
  3465. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  3466. {
  3467. return 60;
  3468. }
  3469. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  3470. {
  3471. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  3472. }
  3473. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  3474. {
  3475. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  3476. }
  3477. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  3478. {
  3479. NSArray *sections = [_sectionDataSource.sectionArrayRow allKeys];
  3480. NSString *sectionTitle = [sections objectAtIndex:section];
  3481. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  3482. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  3483. if ([_directoryGroupBy isEqualToString:@"none"] && [sections count] <= 1) return 0.f;
  3484. return 20.f;
  3485. }
  3486. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3487. {
  3488. float shift;
  3489. UIVisualEffectView *visualEffectView;
  3490. // Titolo
  3491. NSString *titleSection;
  3492. // Controllo
  3493. if ([_sectionDataSource.sections count] == 0)
  3494. return nil;
  3495. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  3496. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  3497. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  3498. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  3499. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  3500. else titleSection = NSLocalizedString(titleSection,nil);
  3501. // Formato titolo
  3502. NSString *currentDevice = [CCUtility currentDevice];
  3503. if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
  3504. visualEffectView = [[UIVisualEffectView alloc] init];
  3505. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR_NO_BLUR;
  3506. } else {
  3507. UIVisualEffect *blurEffect;
  3508. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  3509. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  3510. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR;
  3511. }
  3512. if ([_directoryGroupBy isEqualToString:@"alphabetic"]) {
  3513. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) shift = - 35;
  3514. else shift = - 20;
  3515. } else shift = - 10;
  3516. // Title
  3517. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  3518. titleLabel.backgroundColor=[UIColor clearColor];
  3519. titleLabel.textColor = COLOR_GRAY;
  3520. titleLabel.font = [UIFont systemFontOfSize:12];
  3521. titleLabel.textAlignment = NSTextAlignmentLeft;
  3522. titleLabel.text = titleSection;
  3523. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3524. [visualEffectView addSubview:titleLabel];
  3525. // Elements
  3526. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  3527. elementLabel.backgroundColor=[UIColor clearColor];
  3528. elementLabel.textColor = COLOR_GRAY;
  3529. elementLabel.font = [UIFont systemFontOfSize:12];
  3530. elementLabel.textAlignment = NSTextAlignmentRight;
  3531. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3532. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  3533. NSUInteger rowsCount = [metadatas count];
  3534. if (rowsCount == 0) return nil;
  3535. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  3536. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  3537. [visualEffectView addSubview:elementLabel];
  3538. return visualEffectView;
  3539. }
  3540. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  3541. {
  3542. return [_sectionDataSource.sections indexOfObject:title];
  3543. }
  3544. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  3545. {
  3546. if ([_directoryGroupBy isEqualToString:@"alphabetic"])
  3547. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  3548. else
  3549. return nil;
  3550. }
  3551. /*
  3552. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  3553. {
  3554. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  3555. }
  3556. }
  3557. */
  3558. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  3559. {
  3560. NSString *typeCell;
  3561. NSString *dataFile;
  3562. NSString *lunghezzaFile;
  3563. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3564. if ([metadata.session isEqualToString:@""] || metadata.session == nil) typeCell = @"CellMain";
  3565. else typeCell = @"CellMainTransfer";
  3566. if (!metadata)
  3567. return [tableView dequeueReusableCellWithIdentifier:typeCell];
  3568. CCCellMainTransfer *cell = (CCCellMainTransfer *)[tableView dequeueReusableCellWithIdentifier:typeCell forIndexPath:indexPath];
  3569. // separator
  3570. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  3571. // change color selection
  3572. UIView *selectionColor = [[UIView alloc] init];
  3573. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  3574. cell.selectedBackgroundView = selectionColor;
  3575. if ([typeCell isEqualToString:@"CellMain"]) cell.backgroundColor = [UIColor whiteColor];
  3576. if ([typeCell isEqualToString:@"CellMainTransfer"]) cell.backgroundColor = COLOR_TRANSFER_BACKGROUND;
  3577. // ----------------------------------------------------------------------------------------------------------
  3578. // DEFAULT
  3579. // ----------------------------------------------------------------------------------------------------------
  3580. cell.fileImageView.image = nil;
  3581. cell.statusImageView.image = nil;
  3582. cell.favoriteImageView.image = nil;
  3583. cell.synchronizedImageView.image = nil;
  3584. cell.sharedImageView.image = nil;
  3585. cell.labelTitle.enabled = YES;
  3586. cell.labelTitle.text = @"";
  3587. cell.labelInfoFile.enabled = YES;
  3588. cell.labelInfoFile.text = @"";
  3589. cell.progressView.progress = 0.0;
  3590. cell.progressView.hidden = YES;
  3591. cell.cancelTaskButton.hidden = YES;
  3592. cell.reloadTaskButton.hidden = YES;
  3593. cell.stopTaskButton.hidden = YES;
  3594. // colori e font
  3595. if (metadata.cryptated) {
  3596. cell.labelTitle.textColor = COLOR_ENCRYPTED;
  3597. //nameLabel.font = RalewayLight(13.0f);
  3598. cell.labelInfoFile.textColor = [UIColor blackColor];
  3599. //detailLabel.font = RalewayLight(9.0f);
  3600. } else {
  3601. cell.labelTitle.textColor = COLOR_CLEAR;
  3602. //nameLabel.font = RalewayLight(13.0f);
  3603. cell.labelInfoFile.textColor = [UIColor blackColor];
  3604. //detailLabel.font = RalewayLight(9.0f);
  3605. }
  3606. // ----------------------------------------------------------------------------------------------------------
  3607. // File Name & Folder
  3608. // ----------------------------------------------------------------------------------------------------------
  3609. // nome del file
  3610. cell.labelTitle.text = metadata.fileNamePrint;
  3611. // è una directory
  3612. if (metadata.directory) {
  3613. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3614. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  3615. lunghezzaFile = @" ";
  3616. // ----------------------------------------------------------------------------------------------------------
  3617. // Synchronize
  3618. // ----------------------------------------------------------------------------------------------------------
  3619. NSString *synchronizedServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:metadata.fileNameData];
  3620. if ([CCCoreData isSynchronizedDirectory:synchronizedServerUrl activeAccount:app.activeAccount]) {
  3621. if ([[CCSynchronization sharedSynchronization] synchronizationAnimationDirectory:[[NSArray alloc] initWithObjects:synchronizedServerUrl, nil] callViewController:NO]) {
  3622. NSURL *myURL;
  3623. if (metadata.cryptated) myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  3624. else myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  3625. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  3626. } else {
  3627. if (metadata.cryptated) cell.synchronizedImageView.image = [UIImage imageNamed:image_synchronizedcrypto];
  3628. else cell.synchronizedImageView.image = [UIImage imageNamed:image_synchronized];
  3629. }
  3630. }
  3631. } else {
  3632. // è un file
  3633. dataFile = [CCUtility dateDiff:metadata.date];
  3634. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  3635. // Plist ancora da scaricare
  3636. if (metadata.cryptated && [metadata.title length] == 0) {
  3637. dataFile = @" ";
  3638. lunghezzaFile = @" ";
  3639. }
  3640. TableLocalFile *recordLocalFile = [CCCoreData getLocalFileWithFileID:metadata.fileID activeAccount:app.activeAccount];
  3641. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3642. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  3643. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  3644. if ([metadata.type isEqualToString:metadataType_model] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO)
  3645. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", dataFile];
  3646. if ([metadata.type isEqualToString:metadataType_file] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO) {
  3647. if (recordLocalFile && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  3648. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", dataFile, lunghezzaFile];
  3649. else
  3650. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", dataFile, lunghezzaFile];
  3651. }
  3652. // Plist ancora da scaricare
  3653. if ([dataFile isEqualToString:@" "] && [lunghezzaFile isEqualToString:@" "])
  3654. cell.labelInfoFile.text = NSLocalizedString(@"_no_plist_pull_down_",nil);
  3655. cell.accessoryType = UITableViewCellAccessoryNone;
  3656. }
  3657. // ----------------------------------------------------------------------------------------------------------
  3658. // File Image View
  3659. // ----------------------------------------------------------------------------------------------------------
  3660. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3661. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  3662. cell.fileImageView.image = [app.icoImagesCache objectForKey:metadata.fileID];
  3663. if (cell.fileImageView.image == nil) {
  3664. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  3665. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  3666. [app.icoImagesCache setObject:image forKey:metadata.fileID];
  3667. dispatch_async(dispatch_get_main_queue(), ^{
  3668. CCCellMainTransfer *cell = [tableView cellForRowAtIndexPath:indexPath];
  3669. if (cell)
  3670. cell.fileImageView.image = image;
  3671. });
  3672. });
  3673. }
  3674. } else {
  3675. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  3676. if (metadata.thumbnailExists)
  3677. [self downloadThumbnail:metadata];
  3678. }
  3679. // ----------------------------------------------------------------------------------------------------------
  3680. // Image Status cyptated & Lock Passcode
  3681. // ----------------------------------------------------------------------------------------------------------
  3682. // File Cyptated
  3683. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString:metadataType_model] == NO) {
  3684. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  3685. }
  3686. // Directory con passcode lock attivato
  3687. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:metadata.fileNameData];
  3688. if (metadata.directory && ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length])) cell.statusImageView.image = [UIImage imageNamed:image_passcode];
  3689. // ----------------------------------------------------------------------------------------------------------
  3690. // Favorite
  3691. // ----------------------------------------------------------------------------------------------------------
  3692. if ([CCCoreData isFavorite:metadata.fileID activeAccount:app.activeAccount]) {
  3693. if (metadata.cryptated) cell.favoriteImageView.image = [UIImage imageNamed:image_favoritecrypto];
  3694. else cell.favoriteImageView.image = [UIImage imageNamed:image_favorite];
  3695. }
  3696. // ----------------------------------------------------------------------------------------------------------
  3697. // Share
  3698. // ----------------------------------------------------------------------------------------------------------
  3699. NSString *shareLink = [app.sharesLink objectForKey:[_localServerUrl stringByAppendingString:metadata.fileName]];
  3700. NSString *shareUserAndGroup = [app.sharesUserAndGroup objectForKey:[_localServerUrl stringByAppendingString:metadata.fileName]];
  3701. BOOL isShare = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_shared].location == NSNotFound);
  3702. BOOL isMounted = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_mounted].location == NSNotFound);
  3703. // Aggiungiamo il Tap per le shared
  3704. if (isShare || [shareLink length] > 0 || [shareUserAndGroup length] > 0 || isMounted) {
  3705. if (isShare) {
  3706. cell.sharedImageView.image = [UIImage imageNamed:image_shareConnect];
  3707. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3708. [tap setNumberOfTapsRequired:1];
  3709. cell.sharedImageView.userInteractionEnabled = YES;
  3710. [cell.sharedImageView addGestureRecognizer:tap];
  3711. }
  3712. if (isMounted) {
  3713. cell.sharedImageView.image = [UIImage imageNamed:image_shareMounted];
  3714. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3715. [tap setNumberOfTapsRequired:1];
  3716. cell.sharedImageView.userInteractionEnabled = YES;
  3717. [cell.sharedImageView addGestureRecognizer:tap];
  3718. }
  3719. if ([shareLink length] > 0 || [shareUserAndGroup length] > 0) {
  3720. if ([shareLink length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareLink];
  3721. if ([shareUserAndGroup length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareUser];
  3722. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  3723. [tap setNumberOfTapsRequired:1];
  3724. cell.sharedImageView.userInteractionEnabled = YES;
  3725. [cell.sharedImageView addGestureRecognizer:tap];
  3726. }
  3727. } else {
  3728. cell.sharedImageView.userInteractionEnabled = NO;
  3729. }
  3730. // ----------------------------------------------------------------------------------------------------------
  3731. // downloadFile
  3732. // ----------------------------------------------------------------------------------------------------------
  3733. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  3734. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
  3735. else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
  3736. // sessionTaskIdentifier : RELOAD + STOP
  3737. if (metadata.sessionTaskIdentifier != taskIdentifierDone) {
  3738. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3739. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3740. cell.cancelTaskButton.hidden = NO;
  3741. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3742. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3743. cell.reloadTaskButton.hidden = NO;
  3744. }
  3745. // sessionTaskIdentifierPlist : RELOAD
  3746. if (metadata.sessionTaskIdentifierPlist != taskIdentifierDone) {
  3747. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3748. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3749. cell.reloadTaskButton.hidden = NO;
  3750. }
  3751. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3752. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3753. if (progress > 0) {
  3754. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  3755. else cell.progressView.progressTintColor = COLOR_CLEAR;
  3756. cell.progressView.progress = progress;
  3757. cell.progressView.hidden = NO;
  3758. }
  3759. // ----------------------------------------------------------------------------------------------------------
  3760. // downloadFile Error
  3761. // ----------------------------------------------------------------------------------------------------------
  3762. if (metadata.sessionTaskIdentifier == taskIdentifierError || metadata.sessionTaskIdentifierPlist == taskIdentifierError) {
  3763. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  3764. if ([metadata.sessionError length] == 0)
  3765. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  3766. else
  3767. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3768. }
  3769. }
  3770. // ----------------------------------------------------------------------------------------------------------
  3771. // uploadFile
  3772. // ----------------------------------------------------------------------------------------------------------
  3773. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  3774. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
  3775. else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
  3776. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
  3777. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
  3778. cell.cancelTaskButton.hidden = NO;
  3779. if (metadata.sessionTaskIdentifier == taskIdentifierStop) {
  3780. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3781. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3782. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
  3783. else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
  3784. cell.reloadTaskButton.hidden = NO;
  3785. cell.stopTaskButton.hidden = YES;
  3786. } else {
  3787. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3788. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3789. cell.stopTaskButton.hidden = NO;
  3790. cell.reloadTaskButton.hidden = YES;
  3791. }
  3792. // se non c'è una preview in bianconero metti l'immagine di default
  3793. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  3794. cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
  3795. cell.labelTitle.enabled = NO;
  3796. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3797. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3798. if (progress > 0) {
  3799. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  3800. else cell.progressView.progressTintColor = COLOR_CLEAR;
  3801. cell.progressView.progress = progress;
  3802. cell.progressView.hidden = NO;
  3803. }
  3804. // ----------------------------------------------------------------------------------------------------------
  3805. // uploadFileError
  3806. // ----------------------------------------------------------------------------------------------------------
  3807. if (metadata.sessionTaskIdentifier == taskIdentifierError || metadata.sessionTaskIdentifierPlist == taskIdentifierError) {
  3808. cell.labelTitle.enabled = NO;
  3809. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  3810. if ([metadata.sessionError length] == 0)
  3811. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  3812. else
  3813. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3814. }
  3815. }
  3816. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3817. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3818. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3819. return cell;
  3820. }
  3821. - (void)setTableViewFooter
  3822. {
  3823. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3824. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3825. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3826. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3827. UIFont *appFont = [UIFont systemFontOfSize:12];
  3828. footerLabel.font = appFont;
  3829. footerLabel.textColor = [UIColor grayColor];
  3830. footerLabel.backgroundColor = [UIColor clearColor];
  3831. footerLabel.textAlignment = NSTextAlignmentCenter;
  3832. NSString *folders;
  3833. NSString *files;
  3834. NSString *footerText;
  3835. if (_sectionDataSource.directories > 1) {
  3836. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  3837. } else if (_sectionDataSource.directories == 1){
  3838. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  3839. } else {
  3840. folders = @"";
  3841. }
  3842. if (_sectionDataSource.files > 1) {
  3843. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  3844. } else if (_sectionDataSource.files == 1){
  3845. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  3846. } else {
  3847. files = @"";
  3848. }
  3849. if ([folders isEqualToString:@""]) {
  3850. footerText = files;
  3851. } else if ([files isEqualToString:@""]) {
  3852. footerText = folders;
  3853. } else {
  3854. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  3855. }
  3856. footerLabel.text = footerText;
  3857. [footerView addSubview:footerLabel];
  3858. [self.tableView setTableFooterView:footerView];
  3859. }
  3860. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3861. {
  3862. NSString *textMessage;
  3863. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  3864. // se non può essere selezionata deseleziona
  3865. if ([cell isEditing] == NO)
  3866. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  3867. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  3868. if (self.tableView.editing) {
  3869. [self setTitleNOAnimation];
  3870. return;
  3871. }
  3872. // test crash
  3873. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
  3874. if (indexPath.row >= [metadatas count]) return;
  3875. // settiamo il record file.
  3876. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3877. // se è in corso una sessione
  3878. if ([_metadata.session length] > 0) return;
  3879. if (_metadata.errorPasscode) {
  3880. // se UUID è nil lo sta ancora caricando quindi esci
  3881. if (!_metadata.uuid) return;
  3882. // esiste un hint ??
  3883. CCCrypto *crypto = [[CCCrypto alloc] init];
  3884. NSString *hint = [crypto getHintFromFile:_metadata.fileName isLocal:NO directoryUser:app.directoryUser];
  3885. // qui !! la richiesta della nuova passcode
  3886. if ([_metadata.uuid isEqualToString:[CCUtility getUUID]]) {
  3887. // stesso UUID ... la password è stata modificata !!!!!!
  3888. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_same_device_different_passcode_hint_",nil), hint];
  3889. else textMessage = NSLocalizedString(@"_same_device_different_passcode_", nil);
  3890. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3891. [alertView show];
  3892. } else {
  3893. // UUID diverso.
  3894. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_hint_",nil), _metadata.nameCurrentDevice, hint];
  3895. else textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_",nil), _metadata.nameCurrentDevice];
  3896. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3897. [alertView show];
  3898. }
  3899. // chiediamo la passcode e ricarichiamo tutto.
  3900. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  3901. viewController.delegate = self;
  3902. viewController.fromType = CCBKPasscodeFromPasscode;
  3903. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  3904. viewController.passcodeInputView.maximumLength = 64;
  3905. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  3906. viewController.inputViewTitlePassword = NO;
  3907. viewController.title = _brand_;
  3908. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3909. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  3910. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3911. [self presentViewController:navigationController animated:YES completion:nil];
  3912. }
  3913. // modello o plist con il title a 0 allora è andato storto qualcosa ... ricaricalo
  3914. if (_metadata.cryptated && [_metadata.title length] == 0) {
  3915. NSString* selector;
  3916. if ([_metadata.type isEqualToString:metadataType_model]) selector = selectorLoadModelView;
  3917. else selector = selectorLoadPlist;
  3918. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:NO downloadPlist:YES selector:selector selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  3919. return;
  3920. }
  3921. // se il plist è caricato ed è un modello aprilo
  3922. if ([_metadata.type isEqualToString:metadataType_model]) [self openModel:_metadata.model isNew:false];
  3923. // file
  3924. if (_metadata.directory == NO && _metadata.errorPasscode == NO && [_metadata.type isEqualToString:metadataType_file]) {
  3925. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  3926. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
  3927. [self downloadFileSuccess:_metadata.fileID serverUrl:_localServerUrl selector:selectorLoadFileView selectorPost:nil];
  3928. } else {
  3929. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  3930. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  3931. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  3932. }
  3933. }
  3934. if (_metadata.directory) [self performSegueDirectoryWithControlPasscode:true];
  3935. }
  3936. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  3937. {
  3938. [self setTitleNOAnimation];
  3939. }
  3940. #pragma --------------------------------------------------------------------------------------------
  3941. #pragma mark ===== Synchronize Cell =====
  3942. #pragma --------------------------------------------------------------------------------------------
  3943. - (void)synchronizedFolderGraphicsServerUrl:(NSString *)serverUrl animation:(BOOL)animation
  3944. {
  3945. BOOL cryptated = NO;
  3946. CCCellMain *cell;
  3947. for (NSString* fileID in _sectionDataSource.allRecordsDataSource) {
  3948. CCMetadata *recordMetadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3949. if (recordMetadata.directory == NO)
  3950. continue;
  3951. if ([[CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:recordMetadata.fileNameData] isEqualToString:serverUrl]) {
  3952. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:recordMetadata.fileID];
  3953. cell = (CCCellMain *)[self.tableView cellForRowAtIndexPath:indexPath];
  3954. cryptated = recordMetadata.cryptated;
  3955. break;
  3956. }
  3957. }
  3958. if (!cell)
  3959. return;
  3960. if (animation) {
  3961. NSURL *myURL;
  3962. if (cryptated)
  3963. myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  3964. else
  3965. myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  3966. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  3967. } else {
  3968. if (cryptated)
  3969. cell.synchronizedImageView.image = [UIImage imageNamed:image_synchronizedcrypto];
  3970. else
  3971. cell.synchronizedImageView.image = [UIImage imageNamed:image_synchronized];
  3972. }
  3973. }
  3974. #pragma --------------------------------------------------------------------------------------------
  3975. #pragma mark ===== Navigation ====
  3976. #pragma --------------------------------------------------------------------------------------------
  3977. - (BOOL)shouldPerformSegue:(NSString *)serverUrl
  3978. {
  3979. // if background return
  3980. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  3981. // se non siamo in primo piano o se non siamo nella stessa directory esci
  3982. if (self.view.window == NO || ([serverUrl isEqualToString:_localServerUrl] == NO && serverUrl))
  3983. return NO;
  3984. // Collapsed ma siamo già in detail esci
  3985. if (self.splitViewController.isCollapsed)
  3986. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return NO;
  3987. // Video in esecuzione esci
  3988. if (_detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && _detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  3989. return YES;
  3990. }
  3991. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  3992. {
  3993. id viewController = segue.destinationViewController;
  3994. if ([viewController isKindOfClass:[UINavigationController class]]) {
  3995. UINavigationController *nav = viewController;
  3996. _detailViewController = (CCDetail *)nav.topViewController;
  3997. } else {
  3998. _detailViewController = segue.destinationViewController;
  3999. }
  4000. NSMutableArray *allRecordsDataSourceImagesVideos = [[NSMutableArray alloc] init];
  4001. for (NSString *fileID in _sectionDataSource.allFileID) {
  4002. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4003. if ([metadata.typeFile isEqualToString:metadataTypeFile_image] || [metadata.typeFile isEqualToString:metadataTypeFile_video])
  4004. [allRecordsDataSourceImagesVideos addObject:metadata];
  4005. }
  4006. _detailViewController.delegate = self;
  4007. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  4008. _detailViewController.metadataDetail = _metadataSegue;
  4009. _detailViewController.dateFilterQuery = nil;
  4010. _detailViewController.isCameraUpload = NO;
  4011. _detailViewController.sourceDirectory = sorceDirectoryAccount;
  4012. [_detailViewController setTitle:_metadata.fileNamePrint];
  4013. }
  4014. // can i go to next viewcontroller
  4015. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
  4016. {
  4017. NSString *nomeDir;
  4018. if(self.tableView.editing == NO && _metadata.errorPasscode == NO){
  4019. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  4020. // 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
  4021. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil && controlPasscode) {
  4022. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  4023. viewController.delegate = self;
  4024. viewController.fromType = CCBKPasscodeFromLockDirectory;
  4025. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  4026. viewController.inputViewTitlePassword = YES;
  4027. if ([CCUtility getSimplyBlockCode]) {
  4028. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  4029. viewController.passcodeInputView.maximumLength = 6;
  4030. } else {
  4031. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  4032. viewController.passcodeInputView.maximumLength = 64;
  4033. }
  4034. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  4035. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  4036. viewController.touchIDManager = touchIDManager;
  4037. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  4038. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  4039. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  4040. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  4041. [self presentViewController:navController animated:YES completion:nil];
  4042. return;
  4043. }
  4044. if (_metadata.cryptated) nomeDir = [_metadata.fileName substringToIndex:[_metadata.fileName length]-6];
  4045. else nomeDir = _metadata.fileName;
  4046. NSString *serverUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:nomeDir];
  4047. CCMain *viewController = [app.listMainVC objectForKey:serverUrl];
  4048. if (viewController.isViewLoaded == false) {
  4049. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMainVC"];
  4050. viewController.isFolderEncrypted = _metadata.cryptated;
  4051. viewController.localServerUrl = serverUrl;
  4052. viewController.titleMain = _metadata.fileNamePrint;
  4053. viewController.textBackButton = _titleMain;
  4054. // save self
  4055. [app.listMainVC setObject:viewController forKey:serverUrl];
  4056. }
  4057. [self.navigationController pushViewController:viewController animated:YES];
  4058. }
  4059. }
  4060. @end