CCMain.m 264 KB

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