CCMain.m 264 KB

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