CCMain.m 261 KB

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