CCMain.m 264 KB

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