CCMain.m 267 KB

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