CCMain.m 262 KB

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