CCMain.m 263 KB

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