CCMain.m 259 KB

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