CCMain.m 259 KB

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