CCMain.m 256 KB

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