CCMain.m 262 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650
  1. //
  2. // CCMain.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCMain.h"
  24. #import "AppDelegate.h"
  25. #import "CCPhotosCameraUpload.h"
  26. #import "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 addOffline:metadata.fileID 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. if ([selectorPost isEqualToString:selectorReadFolderForced] ) {
  1085. [self readFolderWithForced:YES];
  1086. } else {
  1087. [self getDataSourceWithReloadTableView:[CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount] fileID:nil selector:selector];
  1088. }
  1089. }
  1090. //
  1091. // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
  1092. //
  1093. - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated useSubFolder:(BOOL)useSubFolder session:(NSString *)session
  1094. {
  1095. [_hud visibleHudTitle:nil mode:MBProgressHUDModeIndeterminate color:nil];
  1096. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
  1097. [self performSelectorOnMainThread:@selector(uploadFileAssetBridge:) withObject:@[assets, serverUrl, [NSNumber numberWithBool:cryptated], [NSNumber numberWithBool:useSubFolder], session] waitUntilDone:NO];
  1098. });
  1099. }
  1100. - (void)uploadFileAssetBridge:(NSArray *)arguments
  1101. {
  1102. NSArray *assets = [arguments objectAtIndex:0];
  1103. NSString *serverUrl = [arguments objectAtIndex:1];
  1104. BOOL cryptated = [[arguments objectAtIndex:2] boolValue];
  1105. BOOL useSubFolder = [[arguments objectAtIndex:3] boolValue];
  1106. NSString * session = [arguments objectAtIndex:4];
  1107. // remove title (graphics)
  1108. [self setTitleBackgroundTableView:nil];
  1109. NSString *folderPhotos = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  1110. NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
  1111. // Create if request the folder for Photos
  1112. if ((useSubFolder || [serverUrl isEqualToString:folderPhotos]) && [_localServerUrl isEqualToString:serverUrl] == NO){
  1113. if(![app.activePhotosCameraUpload createFolder:folderPhotos]) {
  1114. [_hud hideHud];
  1115. [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  1116. return;
  1117. }
  1118. }
  1119. // Create if request the subfolders
  1120. if (useSubFolder) {
  1121. for (NSString *dateSubFolder in [CCUtility createNameSubFolder:assets]) {
  1122. if(![app.activePhotosCameraUpload createFolder:[NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder]]) {
  1123. [_hud hideHud];
  1124. [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  1125. return;
  1126. }
  1127. }
  1128. }
  1129. NSLog(@"[LOG] Asset N. %lu", (unsigned long)[assets count]);
  1130. for (PHAsset *asset in assets) {
  1131. NSString *fileName = [CCUtility createFileNameFromAsset:asset key: keyFileNameMask];
  1132. NSDate *assetDate = asset.creationDate;
  1133. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  1134. // Create serverUrl if use sub folder
  1135. if (useSubFolder) {
  1136. [formatter setDateFormat:@"yyyy"];
  1137. NSString *yearString = [formatter stringFromDate:assetDate];
  1138. [formatter setDateFormat:@"MM"];
  1139. NSString *monthString = [formatter stringFromDate:assetDate];
  1140. serverUrl = [NSString stringWithFormat:@"%@/%@/%@", folderPhotos, yearString, monthString];
  1141. }
  1142. // Check if is in upload
  1143. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND (fileName == %@) AND (session != NULL) AND (session != '')", app.activeAccount, directoryID, fileName];
  1144. NSArray *isRecordInSessions = [CCCoreData getTableMetadataWithPredicate:predicate context:nil];
  1145. if ([isRecordInSessions count] > 0) {
  1146. // next upload
  1147. continue;
  1148. } else {
  1149. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1150. if ([app.typeCloud isEqualToString:typeCloudNextcloud] || [app.typeCloud isEqualToString:typeCloudOwnCloud]) {
  1151. metadataNet.action = actionReadFile;
  1152. metadataNet.identifier = asset.localIdentifier;
  1153. metadataNet.cryptated = cryptated;
  1154. metadataNet.fileName = fileName;
  1155. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1156. metadataNet.session = session;
  1157. metadataNet.selector = selectorReadFileUploadFile;
  1158. metadataNet.serverUrl = serverUrl;
  1159. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1160. }
  1161. }
  1162. }
  1163. [_hud hideHud];
  1164. }
  1165. #pragma --------------------------------------------------------------------------------------------
  1166. #pragma mark ==== Read File ====
  1167. #pragma --------------------------------------------------------------------------------------------
  1168. - (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1169. {
  1170. // UploadFile
  1171. if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
  1172. // File not exists
  1173. if (errorCode == 404) {
  1174. metadataNet.action = actionUploadAsset;
  1175. metadataNet.errorCode = 0;
  1176. metadataNet.selector = selectorUploadFile;
  1177. metadataNet.selectorPost = nil;
  1178. metadataNet.taskStatus = taskStatusResume;
  1179. if ([metadataNet.session containsString:@"wwan"])
  1180. [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
  1181. else
  1182. [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
  1183. } else {
  1184. // error ho many retry befor notification and go to on next asses
  1185. if (metadataNet.errorRetry < 3) {
  1186. // Retry read file
  1187. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1188. } else {
  1189. // STOP check file, view message error
  1190. [app messageNotification:@"_upload_file_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1191. }
  1192. }
  1193. }
  1194. }
  1195. - (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(CCMetadata *)metadata
  1196. {
  1197. // ReadFile Folder for change rev
  1198. if ([metadataNet.selector isEqualToString:selectorReadFileFolder]) {
  1199. NSString *rev = [CCCoreData getDirectoryRevFromServerUrl:metadataNet.serverUrl activeAccount:app.activeAccount];
  1200. if (![metadata.rev isEqualToString:rev]) {
  1201. NSLog(@"Change etag, force reload folder %@", metadataNet.serverUrl);
  1202. [CCCoreData setDirectoryRev:metadata.rev serverUrl:metadataNet.serverUrl activeAccount:app.activeAccount];
  1203. [CCCoreData clearDateReadDirectory:metadataNet.serverUrl activeAccount:app.activeAccount];
  1204. CCMain *viewController = [app.listMainVC objectForKey:metadataNet.serverUrl];
  1205. if (viewController)
  1206. [viewController clearDateReadDataSource:nil];
  1207. }
  1208. }
  1209. // UploadFile
  1210. if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
  1211. metadataNet.action = actionUploadAsset;
  1212. metadataNet.errorCode = 403; // File exists 403 Forbidden
  1213. metadataNet.selector = selectorUploadFile;
  1214. metadataNet.selectorPost = nil;
  1215. metadataNet.taskStatus = taskStatusResume;
  1216. if ([metadataNet.session containsString:@"wwan"])
  1217. [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
  1218. else
  1219. [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
  1220. }
  1221. // Quota
  1222. if ([metadataNet.selector isEqualToString:selectorReadFileQuota]) {
  1223. if (app.activeSettings)
  1224. [app.activeSettings reloadForm];
  1225. }
  1226. }
  1227. - (void)readFileSelfFolderRev
  1228. {
  1229. // test
  1230. if ([app.activeAccount length] == 0 || [_localDirectoryID length] == 0)
  1231. return;
  1232. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1233. metadataNet.action = actionReadFile;
  1234. metadataNet.selector = selectorReadFileFolder;
  1235. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:_localDirectoryID activeAccount:app.activeAccount];
  1236. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1237. }
  1238. #pragma --------------------------------------------------------------------------------------------
  1239. #pragma mark ==== Read Folder ====
  1240. #pragma --------------------------------------------------------------------------------------------
  1241. - (void)readFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1242. {
  1243. // verify active user
  1244. TableAccount *record = [CCCoreData getActiveAccount];
  1245. [_hud hideHud];
  1246. [_ccRefreshControl endRefreshing];
  1247. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1248. if (message && [record.account isEqualToString:metadataNet.account])
  1249. [app messageNotification:@"_error_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1250. [self getDataSourceWithReloadTableView:metadataNet.directoryID fileID:nil selector:metadataNet.selector];
  1251. if (errorCode == 401)
  1252. [self changePasswordAccount];
  1253. }
  1254. - (void)readFolderSuccess:(CCMetadataNet *)metadataNet permissions:(NSString *)permissions rev:(NSString *)rev metadatas:(NSArray *)metadatas
  1255. {
  1256. // verify active user
  1257. TableAccount *record = [CCCoreData getActiveAccount];
  1258. if (![record.account isEqualToString:metadataNet.account])
  1259. return;
  1260. // save father e update permission
  1261. _fatherPermission = permissions;
  1262. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND ((session == NULL) OR (session == ''))", app.activeAccount, metadataNet.directoryID]];
  1263. NSArray *recordsInSessions = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, metadataNet.directoryID] context:nil];
  1264. [CCCoreData setDateReadDirectoryID:metadataNet.directoryID activeAccount:app.activeAccount];
  1265. for (CCMetadata *metadata in metadatas) {
  1266. // type of file
  1267. NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
  1268. // if crypto do not insert
  1269. if (typeFilename == metadataTypeFilenameCrypto) continue;
  1270. // verify if the record encrypted has plist + crypto
  1271. if (typeFilename == metadataTypeFilenamePlist && metadata.directory == NO) {
  1272. BOOL isCryptoComplete = NO;
  1273. NSString *fileNameCrypto = [CCUtility trasformedFileNamePlistInCrypto:metadata.fileName];
  1274. for (CCMetadata *completeMetadata in metadatas) {
  1275. if (completeMetadata.cryptated == NO) continue;
  1276. else if ([completeMetadata.fileName isEqualToString:fileNameCrypto]) {
  1277. isCryptoComplete = YES;
  1278. break;
  1279. }
  1280. }
  1281. if (isCryptoComplete == NO) continue;
  1282. }
  1283. // verify if the record is in download/upload progress
  1284. if (metadata.directory == NO && [recordsInSessions count] > 0) {
  1285. CCMetadata *metadataDB = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@) AND (fileName == %@)", app.activeAccount, metadataNet.directoryID, metadata.fileName] context:nil];
  1286. // Upload
  1287. if (metadataDB.session && [metadataDB.session rangeOfString:@"upload"].location != NSNotFound) {
  1288. NSString *sessionID = metadataDB.sessionID;
  1289. // rename SessionID -> fileID
  1290. [CCUtility moveFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, sessionID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]];
  1291. metadataDB.session = @"";
  1292. metadataDB.date = metadata.date;
  1293. metadataDB.fileID = metadata.fileID;
  1294. metadataDB.rev = metadata.fileID;
  1295. metadataDB.sessionError = @"";
  1296. metadataDB.sessionID = @"";
  1297. metadataDB.sessionTaskIdentifier = taskIdentifierDone;
  1298. metadataDB.sessionTaskIdentifierPlist = taskIdentifierDone;
  1299. [CCCoreData updateMetadata:metadataDB predicate:[NSPredicate predicateWithFormat:@"(sessionID == %@) AND (account == %@)", sessionID, app.activeAccount] activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud context:nil];
  1300. [CCCoreData addLocalFile:metadataDB activeAccount:app.activeAccount];
  1301. [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]];
  1302. continue;
  1303. }
  1304. // download in progress
  1305. if (metadataDB.session && [metadataDB.session rangeOfString:@"download"].location != NSNotFound) continue;
  1306. }
  1307. // test rev subdirectory
  1308. /*
  1309. if (metadata.directory) {
  1310. NSString *serverUrlTestRev = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:metadata.fileName];
  1311. NSString *revPrev = [CCCoreData getDirectoryRevFromServerUrl:serverUrlTestRev activeAccount:app.activeAccount];
  1312. if (![metadata.rev isEqualToString:revPrev]) {
  1313. NSLog(@"Change etag, force reload folder");
  1314. [CCCoreData setDirectoryRev:metadata.rev serverUrl:serverUrlTestRev activeAccount:app.activeAccount];
  1315. [CCCoreData clearDateReadDirectory:serverUrlTestRev activeAccount:app.activeAccount];
  1316. CCMain *viewController = [app.listMainVC objectForKey:serverUrlTestRev];
  1317. if (viewController)
  1318. [viewController clearDateReadDataSource:nil];
  1319. }
  1320. }
  1321. */
  1322. // end test, insert in CoreData
  1323. [CCCoreData addMetadata:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud context:nil];
  1324. }
  1325. // read plist
  1326. [self downloadPlist:metadataNet.directoryID serverUrl:metadataNet.serverUrl];
  1327. // Offline Folder
  1328. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  1329. // File is changed ??
  1330. [[CCOfflineFileFolder sharedOfflineFileFolder] verifyChangeMedatas:metadatas serverUrl:metadataNet.serverUrl directoryID:metadataNet.directoryID account:app.activeAccount offline:NO];
  1331. });
  1332. // this is the same directory
  1333. if ([metadataNet.serverUrl isEqualToString:_localServerUrl]) {
  1334. // reload
  1335. [self getDataSourceWithReloadTableView:metadataNet.directoryID fileID:nil selector:metadataNet.selector];
  1336. // stoprefresh
  1337. [_ccRefreshControl endRefreshing];
  1338. // Enable change user
  1339. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  1340. [_hud hideHud];
  1341. }
  1342. }
  1343. - (void)readFolderWithForced:(BOOL)forced
  1344. {
  1345. [self setTitleBackgroundTableView:nil];
  1346. // init control
  1347. if (!_localServerUrl || !app.activeAccount)
  1348. return;
  1349. if (([CCCoreData isDirectoryOutOfDate:dayForceReadFolder directoryID:_localDirectoryID activeAccount:app.activeAccount] || forced) && _localDirectoryID && app.activeAccount) {
  1350. if (_ccRefreshControl.isRefreshing == NO)
  1351. [_hud visibleIndeterminateHud];
  1352. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1353. metadataNet.action = actionReadFolder;
  1354. metadataNet.date = [NSDate date];
  1355. metadataNet.directoryID = _localDirectoryID;
  1356. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1357. metadataNet.selector = selectorReadFolder;
  1358. metadataNet.serverUrl = [CCCoreData getServerUrlFromDirectoryID:_localDirectoryID activeAccount:app.activeAccount];
  1359. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1360. } else {
  1361. if ([_sectionDataSource.allRecordsDataSource count] == 0) [self setTitleBackgroundTableView:NSLocalizedString(@"_no_file_pull_down_",nil)];
  1362. else [self setTitleBackgroundTableView:nil];
  1363. }
  1364. }
  1365. #pragma --------------------------------------------------------------------------------------------
  1366. #pragma mark ===== Delete File or Folder =====
  1367. #pragma --------------------------------------------------------------------------------------------
  1368. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1369. {
  1370. [_hud hideHud];
  1371. if (errorCode == 404)
  1372. [self deleteFileOrFolderSuccess:metadataNet];
  1373. if (message)
  1374. [app messageNotification:@"_delete_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1375. // is detailViewController active ?
  1376. if (_detailViewController) {
  1377. dispatch_async(dispatch_get_main_queue(), ^{
  1378. [_detailViewController deleteFileFailure:errorCode];
  1379. });
  1380. }
  1381. [_selectedMetadatas removeAllObjects];
  1382. [_queueSelector removeAllObjects];
  1383. }
  1384. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  1385. {
  1386. [_queueSelector removeObject:metadataNet.selector];
  1387. if ([_queueSelector count] == 0) {
  1388. [_hud hideHud];
  1389. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  1390. if (metadata) {
  1391. [CCCoreData deleteFile:metadata serverUrl:metadataNet.serverUrl directoryUser:app.directoryUser typeCloud:app.typeCloud activeAccount:app.activeAccount];
  1392. // Carico la Folder o il Datasource
  1393. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
  1394. [self readFolderWithForced:YES];
  1395. } else {
  1396. [self getDataSourceWithReloadTableView:metadata.directoryID fileID:metadata.fileID selector:metadataNet.selector];
  1397. }
  1398. }
  1399. // if detailViewController
  1400. if (_detailViewController) {
  1401. dispatch_async(dispatch_get_main_queue(), ^{
  1402. [_detailViewController deleteFileSuccess:metadata metadataNetVar:metadataNet];
  1403. });
  1404. }
  1405. // next
  1406. if ([_selectedMetadatas count] > 0) {
  1407. [_selectedMetadatas removeObjectAtIndex:0];
  1408. if ([_selectedMetadatas count] > 0)
  1409. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1410. }
  1411. }
  1412. }
  1413. - (void)deleteFileOrFolder:(CCMetadata *)metadata numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
  1414. {
  1415. if (metadata.cryptated == YES) {
  1416. // Cryptated
  1417. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1418. metadataNet.action = actionDeleteFileDirectory;
  1419. metadataNet.fileID = metadata.fileID;
  1420. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1421. metadataNet.serverUrl = _localServerUrl;
  1422. // data crypto
  1423. metadataNet.fileName = metadata.fileNameData;
  1424. metadataNet.selector = selectorDeleteCrypto;
  1425. [_queueSelector addObject:metadataNet.selector];
  1426. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1427. // plist
  1428. metadataNet.fileName = metadata.fileName;
  1429. metadataNet.selector = selectorDeletePlist;
  1430. [_queueSelector addObject:metadataNet.selector];
  1431. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1432. } else {
  1433. // Plain
  1434. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1435. metadataNet.action = actionDeleteFileDirectory;
  1436. metadataNet.fileID = metadata.fileID;
  1437. metadataNet.fileName = metadata.fileName;
  1438. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1439. metadataNet.selector = selectorDelete;
  1440. metadataNet.serverUrl = _localServerUrl;
  1441. [_queueSelector addObject:metadataNet.selector];
  1442. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1443. }
  1444. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_delete_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
  1445. }
  1446. - (void)deleteSelectionFile
  1447. {
  1448. [_selectedMetadatas removeAllObjects];
  1449. [_queueSelector removeAllObjects];
  1450. _selectedMetadatas = [[NSMutableArray alloc] initWithArray: [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]]];
  1451. _numSelectedMetadatas = [_selectedMetadatas count];
  1452. if ([_selectedMetadatas count] > 0)
  1453. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1454. [self tableViewSelect:NO];
  1455. }
  1456. - (void)deleteFile
  1457. {
  1458. [_selectedMetadatas removeAllObjects];
  1459. [_queueSelector removeAllObjects];
  1460. _numSelectedMetadatas = 1;
  1461. [_selectedMetadatas addObject:_metadata];
  1462. if ([_selectedMetadatas count] > 0)
  1463. [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
  1464. [self tableViewSelect:NO];
  1465. }
  1466. #pragma --------------------------------------------------------------------------------------------
  1467. #pragma mark ===== Rename =====
  1468. #pragma --------------------------------------------------------------------------------------------
  1469. - (void)renameSuccess:(CCMetadataNet *)metadataNet revTo:(NSString *)revTo
  1470. {
  1471. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  1472. if (metadata.directory == YES)
  1473. [CCCoreData renameDirectory:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadataNet.fileName] serverUrlTo:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadataNet.fileNameTo] activeAccount:app.activeAccount];
  1474. else
  1475. [CCCoreData renameLocalFileWithFileID:metadata.fileID fileNameTo:metadataNet.fileNameTo fileNamePrintTo:metadataNet.fileNameTo activeAccount:app.activeAccount];
  1476. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced])
  1477. [self readFolderWithForced:YES];
  1478. }
  1479. - (void)renameFile:(CCMetadata *)metadata fileName:(NSString *)fileName
  1480. {
  1481. NSString *fileNameTo, *newTitleTo;
  1482. CCCrypto *crypto = [[CCCrypto alloc] init];
  1483. fileNameTo = [CCUtility removeForbiddenCharacters:fileName];
  1484. if (![fileNameTo length]) return;
  1485. if ([metadata.fileNamePrint isEqualToString:fileNameTo]) return;
  1486. // Plain
  1487. if (metadata.cryptated == NO) {
  1488. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1489. metadataNet.action = actionMoveFileOrFolder;
  1490. metadataNet.fileID = metadata.fileID;
  1491. metadataNet.fileName = metadata.fileName;
  1492. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1493. metadataNet.fileNameTo = fileNameTo;
  1494. metadataNet.selector = selectorRename;
  1495. metadataNet.selectorPost = selectorReadFolderForced;
  1496. metadataNet.serverUrl = _localServerUrl;
  1497. metadataNet.serverUrlTo = _localServerUrl;
  1498. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1499. } else {
  1500. // Change only the contenent of plist, then upload it
  1501. newTitleTo = [AESCrypt encrypt:fileNameTo password:[crypto getKeyPasscode:metadata.uuid]];
  1502. if ([crypto updateTitleFilePlist:metadata.fileName title:newTitleTo directoryUser:app.directoryUser] == NO) {
  1503. NSLog(@"[LOG] Rename cryptated error %@", fileName);
  1504. [app messageNotification:@"_rename_" description:@"_file_not_found_reload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1505. return;
  1506. }
  1507. if (metadata.directory == NO) {
  1508. // cripto il file fileID in temp
  1509. NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]];
  1510. if (data) data = [RNEncryptor encryptData:data withSettings:kRNCryptorAES256Settings password:[crypto getKeyPasscode:metadata.uuid] error:nil];
  1511. if (data) [data writeToFile:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameData] atomically:YES];
  1512. }
  1513. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1514. metadataNet.action = actionUploadOnlyPlist;
  1515. metadataNet.fileName = metadata.fileName;
  1516. metadataNet.selectorPost = selectorReadFolderForced;
  1517. metadataNet.serverUrl = _localServerUrl;
  1518. metadataNet.session = upload_session_foreground;
  1519. metadataNet.taskStatus = taskStatusResume;
  1520. if ([CCCoreData isOffline:metadata.fileID activeAccount:app.activeAccount]) metadataNet.selectorPost = selectorAddOffline;
  1521. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1522. // delete file in filesystem
  1523. [CCCoreData deleteFile:metadata serverUrl:_localServerUrl directoryUser:app.directoryUser typeCloud:app.typeCloud activeAccount:app.activeAccount];
  1524. }
  1525. }
  1526. - (void)renameNote:(CCMetadata *)metadata fileName:(NSString *)fileName
  1527. {
  1528. CCTemplates *templates = [[CCTemplates alloc] init];
  1529. CCCrypto *crypto = [[CCCrypto alloc] init];
  1530. NSMutableDictionary *field = [crypto getDictionaryEncrypted:metadata.fileName uuid:metadata.uuid isLocal:NO directoryUser:app.directoryUser];
  1531. NSString *fileNameModel = [templates salvaNote:[field objectForKey:@"note"] titolo:fileName fileName:metadata.fileName uuid:metadata.uuid];
  1532. if (fileNameModel) {
  1533. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1534. metadataNet.action = actionUploadTemplate;
  1535. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  1536. metadataNet.fileNamePrint = fileName;
  1537. metadataNet.rev = metadata.rev;
  1538. metadataNet.serverUrl = _localServerUrl;
  1539. metadataNet.session = upload_session_foreground;
  1540. metadataNet.taskStatus = taskStatusResume;
  1541. if ([CCCoreData isOffline:metadata.fileID activeAccount:app.activeAccount]) metadataNet.selectorPost = selectorAddOffline;
  1542. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1543. }
  1544. }
  1545. #pragma --------------------------------------------------------------------------------------------
  1546. #pragma mark ===== Move =====
  1547. #pragma --------------------------------------------------------------------------------------------
  1548. - (void)moveFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1549. {
  1550. [_hud hideHud];
  1551. if (message)
  1552. [app messageNotification:@"_move_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1553. [_selectedMetadatas removeAllObjects];
  1554. [_queueSelector removeAllObjects];
  1555. }
  1556. - (void)moveSuccess:(CCMetadataNet *)metadataNet revTo:(NSString *)revTo
  1557. {
  1558. [_queueSelector removeObject:metadataNet.selector];
  1559. if ([_queueSelector count] == 0) {
  1560. [_hud hideHud];
  1561. NSString *fileName = [CCUtility trasformedFileNameCryptoInPlist:metadataNet.fileName];
  1562. NSString *directoryID = metadataNet.directoryID;
  1563. NSString *directoryIDTo = metadataNet.directoryIDTo;
  1564. // FILE -> Metadata
  1565. if (metadataNet.directory == NO) {
  1566. // se esiste l' directoryIDTo destinazione allora cambiamo il file sul nuovo directoryID altrimenti cancelliamo il file
  1567. if (directoryIDTo)
  1568. [CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
  1569. else
  1570. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(directoryID == %@)AND (account == %@)", directoryID, app.activeAccount]];
  1571. }
  1572. // DIRECTORY -> Directory - CCMetadata
  1573. if (metadataNet.directory == YES) {
  1574. // cancelliamo tutte le directory e subdirectory in Directory prelevando i fileID
  1575. NSArray *directoryIDs = [CCCoreData deleteDirectoryAndSubDirectory:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:fileName] activeAccount:app.activeAccount];
  1576. // cancelliamo in metadata tutti i file degli fileID prelevati da directory
  1577. for(NSString *directoryIDDelete in directoryIDs) {
  1578. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(directoryID == %@)AND (account == %@)",directoryIDDelete, app.activeAccount]];
  1579. }
  1580. // rinominiamo ora la directory in CCMetadata
  1581. if (directoryIDTo)
  1582. [CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
  1583. }
  1584. // reload Datasource
  1585. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced])
  1586. [self readFolderWithForced:YES];
  1587. else
  1588. [self getDataSourceWithReloadTableView];
  1589. // Next file
  1590. [_selectedMetadatas removeObjectAtIndex:0];
  1591. [self moveFileOrFolder:metadataNet.serverUrlTo];
  1592. }
  1593. }
  1594. - (void)moveFileOrFolder:(NSString *)serverUrlTo
  1595. {
  1596. if ([_selectedMetadatas count] > 0) {
  1597. CCMetadata *metadata = [_selectedMetadatas objectAtIndex:0];
  1598. // Plain
  1599. if (metadata.cryptated == NO) {
  1600. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1601. metadataNet.action = actionMoveFileOrFolder;
  1602. metadataNet.directory = metadata.directory;
  1603. metadataNet.fileID = metadata.fileID;
  1604. metadataNet.directoryID = _localDirectoryID;
  1605. metadataNet.directoryIDTo = [CCCoreData getDirectoryIDFromServerUrl:serverUrlTo activeAccount:app.activeAccount];
  1606. metadataNet.fileName = metadata.fileName;
  1607. metadataNet.fileNamePrint = metadataNet.fileNamePrint;
  1608. metadataNet.fileNameTo = metadata.fileName;
  1609. metadataNet.rev = metadata.rev;
  1610. metadataNet.selector = selectorMove;
  1611. metadataNet.serverUrl = _localServerUrl;
  1612. metadataNet.serverUrlTo = serverUrlTo;
  1613. [_queueSelector addObject:metadataNet.selector];
  1614. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1615. }
  1616. // cyptated
  1617. if (metadata.cryptated == YES) {
  1618. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1619. metadataNet.action = actionMoveFileOrFolder;
  1620. metadataNet.directory = metadata.directory;
  1621. metadataNet.fileID = metadata.fileID;
  1622. metadataNet.directoryID = _localDirectoryID;
  1623. metadataNet.directoryIDTo = [CCCoreData getDirectoryIDFromServerUrl:serverUrlTo activeAccount:app.activeAccount];
  1624. metadataNet.fileNamePrint = metadata.fileNamePrint;
  1625. metadataNet.rev = metadata.rev;
  1626. metadataNet.serverUrl = _localServerUrl;
  1627. metadataNet.serverUrlTo = serverUrlTo;
  1628. // data
  1629. metadataNet.fileName = metadata.fileNameData;
  1630. metadataNet.fileNameTo = metadata.fileNameData;
  1631. metadataNet.selector = selectorMoveCrypto;
  1632. [_queueSelector addObject:metadataNet.selector];
  1633. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1634. // plist
  1635. metadataNet.fileName = metadata.fileName;
  1636. metadataNet.fileNameTo = metadata.fileName;
  1637. metadataNet.selector = selectorMovePlist;
  1638. [_queueSelector addObject:metadataNet.selector];
  1639. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1640. }
  1641. [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), _numSelectedMetadatas - [_selectedMetadatas count] + 1, _numSelectedMetadatas] mode:MBProgressHUDModeIndeterminate color:nil];
  1642. }
  1643. }
  1644. - (void)move:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
  1645. {
  1646. // Test
  1647. if ([_localServerUrl isEqualToString:serverUrlTo]) {
  1648. [self tableViewSelect:NO];
  1649. return;
  1650. }
  1651. [_selectedMetadatas removeAllObjects];
  1652. [_queueSelector removeAllObjects];
  1653. _selectedMetadatas = [[NSMutableArray alloc] initWithArray:selectedMetadatas];
  1654. _numSelectedMetadatas = [_selectedMetadatas count];
  1655. [self moveFileOrFolder:serverUrlTo];
  1656. [self tableViewSelect:NO];
  1657. }
  1658. - (void)moveOpenWindow:(NSArray *)indexPaths
  1659. {
  1660. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  1661. CCMove *viewController = (CCMove *)navigationController.topViewController;
  1662. viewController.delegate = self;
  1663. viewController.move.title = NSLocalizedString(@"_move_", nil);
  1664. viewController.selectedMetadatas = [self getMetadatasFromSelectedRows:indexPaths];
  1665. viewController.tintColor = COLOR_BRAND;
  1666. viewController.barTintColor = COLOR_BAR;
  1667. viewController.tintColorTitle = COLOR_GRAY;
  1668. viewController.networkingOperationQueue = app.netQueue;
  1669. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  1670. [self presentViewController:navigationController animated:YES completion:nil];
  1671. }
  1672. #pragma --------------------------------------------------------------------------------------------
  1673. #pragma mark ===== Create folder =====
  1674. #pragma --------------------------------------------------------------------------------------------
  1675. - (void)createFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  1676. {
  1677. [_hud hideHud];
  1678. if (message)
  1679. [app messageNotification:@"_create_folder_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1680. }
  1681. - (void)createFolderSuccess:(CCMetadataNet *)metadataNet
  1682. {
  1683. [_hud hideHud];
  1684. [CCCoreData addDirectory:[NSString stringWithFormat:@"%@/%@", metadataNet.serverUrl, metadataNet.fileName] date:[NSDate date] permissions:nil activeAccount:app.activeAccount];
  1685. // Load Folder or the Datasource
  1686. if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
  1687. [self readFolderWithForced:YES];
  1688. } else {
  1689. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:metadataNet.fileID selector:metadataNet.selector];
  1690. }
  1691. }
  1692. - (void)createFolder:(NSString *)fileNameFolder folderCameraUpload:(BOOL)folderCameraUpload
  1693. {
  1694. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1695. fileNameFolder = [CCUtility removeForbiddenCharacters:fileNameFolder];
  1696. if (![fileNameFolder length]) return;
  1697. if (folderCameraUpload) metadataNet.serverUrl = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  1698. else metadataNet.serverUrl = _localServerUrl;
  1699. metadataNet.action = actionCreateFolder;
  1700. if (folderCameraUpload)
  1701. metadataNet.options = @"folderCameraUpload";
  1702. metadataNet.fileName = fileNameFolder;
  1703. metadataNet.selector = selectorCreateFolder;
  1704. metadataNet.selectorPost = selectorReadFolderForced;
  1705. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1706. if (!folderCameraUpload)
  1707. [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1708. }
  1709. - (void)createFolderEncrypted:(NSString *)fileNameFolder
  1710. {
  1711. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1712. CCCrypto *crypto = [[CCCrypto alloc] init];
  1713. NSString *fileNamePlist;
  1714. fileNameFolder = [CCUtility removeForbiddenCharacters:fileNameFolder];
  1715. if (![fileNameFolder length]) return;
  1716. NSString *title = [AESCrypt encrypt:fileNameFolder password:[crypto getKeyPasscode:[CCUtility getUUID]]];
  1717. fileNamePlist = [crypto createFilenameEncryptor:fileNameFolder uuid:[CCUtility getUUID]];
  1718. [crypto createFilePlist:[NSTemporaryDirectory() stringByAppendingString:fileNamePlist] title:title len:0 directory:true uuid:[CCUtility getUUID] nameCurrentDevice:[CCUtility getNameCurrentDevice] icon:@""];
  1719. // Create folder
  1720. metadataNet.action = actionCreateFolder;
  1721. metadataNet.fileName = fileNamePlist;
  1722. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1723. metadataNet.selector = selectorCreateFolder;
  1724. metadataNet.serverUrl = _localServerUrl;
  1725. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1726. // upload plist file
  1727. metadataNet.action = actionUploadOnlyPlist;
  1728. metadataNet.fileName = [fileNamePlist stringByAppendingString:@".plist"];
  1729. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1730. metadataNet.selectorPost = selectorReadFolderForced;
  1731. metadataNet.serverUrl = _localServerUrl;
  1732. metadataNet.session = upload_session_foreground;
  1733. metadataNet.taskStatus = taskStatusResume;
  1734. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1735. [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  1736. }
  1737. - (void)createFolderCameraUpload
  1738. {
  1739. [self createFolder:[CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount] folderCameraUpload:YES];
  1740. }
  1741. #pragma --------------------------------------------------------------------------------------------
  1742. #pragma mark ===== Encrypted / Decrypted Folder =====
  1743. #pragma --------------------------------------------------------------------------------------------
  1744. - (void)encyptedDecryptedFolder
  1745. {
  1746. if (_metadata.cryptated) {
  1747. // DECRYPTED
  1748. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1749. //-------------------------- RENAME -------------------------------------------//
  1750. metadataNet.action = actionMoveFileOrFolder;
  1751. metadataNet.fileID = _metadata.fileID;
  1752. metadataNet.fileName = _metadata.fileNameData;
  1753. metadataNet.fileNameTo = _metadata.fileNamePrint;
  1754. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1755. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1756. metadataNet.selector = selectorRename;
  1757. metadataNet.serverUrl = _localServerUrl;
  1758. metadataNet.serverUrlTo = _localServerUrl;
  1759. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1760. //-------------------------- DELETE -------------------------------------------//
  1761. metadataNet.action = actionDeleteFileDirectory;
  1762. metadataNet.fileID = _metadata.fileID;
  1763. metadataNet.fileName = _metadata.fileName;
  1764. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1765. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1766. metadataNet.selector = selectorDeletePlist;
  1767. metadataNet.selectorPost = selectorReadFolderForced;
  1768. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1769. } else {
  1770. // ENCRYPTED
  1771. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  1772. CCCrypto *crypto = [[CCCrypto alloc] init];
  1773. // Create File Plist
  1774. NSString *fileNameCrypto = [crypto createFileDirectoryPlist:_metadata];
  1775. //-------------------------- RENAME -------------------------------------------//
  1776. metadataNet.action = actionMoveFileOrFolder;
  1777. metadataNet.fileID = _metadata.fileID;
  1778. metadataNet.fileName = _metadata.fileName;
  1779. metadataNet.fileNamePrint = _metadata.fileNamePrint;
  1780. metadataNet.fileNameTo = fileNameCrypto;
  1781. metadataNet.priority = NSOperationQueuePriorityVeryHigh;
  1782. metadataNet.selector = selectorRename;
  1783. metadataNet.serverUrl = _localServerUrl;
  1784. metadataNet.serverUrlTo = _localServerUrl;
  1785. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1786. //-------------------------- UPLOAD -------------------------------------------//
  1787. metadataNet.action = actionUploadOnlyPlist;
  1788. metadataNet.fileName = [fileNameCrypto stringByAppendingString:@".plist"];
  1789. metadataNet.priority = NSOperationQueuePriorityVeryLow;
  1790. metadataNet.selectorPost = selectorReadFolderForced;
  1791. metadataNet.serverUrl = _localServerUrl;
  1792. metadataNet.session = upload_session_foreground;
  1793. metadataNet.taskStatus = taskStatusResume;
  1794. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  1795. }
  1796. }
  1797. #pragma --------------------------------------------------------------------------------------------
  1798. #pragma mark ===== Encrypted/Decrypted File =====
  1799. #pragma --------------------------------------------------------------------------------------------
  1800. - (void)encryptedSelectedFiles
  1801. {
  1802. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1803. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1804. for (CCMetadata *metadata in selectedMetadatas) {
  1805. if (metadata.cryptated == NO && metadata.directory == NO)
  1806. [metadatas addObject:metadata];
  1807. }
  1808. if ([metadatas count] > 0) {
  1809. NSLog(@"[LOG] Start encrypted selected files ...");
  1810. for (CCMetadata* metadata in metadatas)
  1811. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorEncryptFile selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1812. }
  1813. [self tableViewSelect:NO];
  1814. }
  1815. - (void)decryptedSelectedFiles
  1816. {
  1817. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  1818. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  1819. for (CCMetadata *metadata in selectedMetadatas) {
  1820. if (metadata.cryptated == YES && metadata.directory == NO && [metadata.model length] == 0)
  1821. [metadatas addObject:metadata];
  1822. }
  1823. if ([metadatas count] > 0) {
  1824. NSLog(@"[LOG] Start decrypted selected files ...");
  1825. for (CCMetadata* metadata in metadatas)
  1826. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorDecryptFile selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1827. }
  1828. [self tableViewSelect:NO];
  1829. }
  1830. - (void)cmdEncryptedDecryptedFile
  1831. {
  1832. NSString *selector;
  1833. if (_metadata.cryptated == YES) selector = selectorDecryptFile;
  1834. if (_metadata.cryptated == NO) selector = selectorEncryptFile;
  1835. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selector selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  1836. }
  1837. - (void)encryptedFile:(CCMetadata *)metadata
  1838. {
  1839. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1840. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1841. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1842. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
  1843. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  1844. dispatch_async(dispatch_get_main_queue(), ^{
  1845. [[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];
  1846. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.1];
  1847. });
  1848. } else {
  1849. [app messageNotification:@"_encrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1850. }
  1851. }
  1852. - (void)decryptedFile:(CCMetadata *)metadata
  1853. {
  1854. NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  1855. NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  1856. [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
  1857. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
  1858. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  1859. dispatch_async(dispatch_get_main_queue(), ^{
  1860. [[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];
  1861. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil afterDelay:0.1];
  1862. });
  1863. } else {
  1864. [app messageNotification:@"_decrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  1865. }
  1866. }
  1867. #pragma --------------------------------------------------------------------------------------------
  1868. #pragma mark ===== Progress & Task Button =====
  1869. #pragma --------------------------------------------------------------------------------------------
  1870. - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
  1871. {
  1872. // Check
  1873. if (!fileID)
  1874. return;
  1875. [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  1876. if (![serverUrl isEqualToString:_localServerUrl])
  1877. return;
  1878. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  1879. if (indexPath) {
  1880. CCControlCenterCell *cell = (CCControlCenterCell *)[self.tableView cellForRowAtIndexPath:indexPath];
  1881. if (cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  1882. else cell.progressView.progressTintColor = COLOR_CLEAR;
  1883. cell.progressView.hidden = NO;
  1884. [cell.progressView setProgress:progress];
  1885. }
  1886. }
  1887. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  1888. {
  1889. UITouch * touch = [[event allTouches] anyObject];
  1890. CGPoint location = [touch locationInView:self.tableView];
  1891. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1892. if (indexPath) {
  1893. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1894. if (metadata)
  1895. [self reloadTaskButton:metadata];
  1896. }
  1897. }
  1898. - (void)reloadTaskButton:(CCMetadata *)metadata
  1899. {
  1900. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1901. __block NSURLSessionTask *findTask;
  1902. // DOWNLOAD
  1903. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  1904. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1905. for (NSURLSessionUploadTask *task in downloadTasks)
  1906. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1907. findTask = task;
  1908. [app.listChangeTask setObject:@"reloadDownload" forKey:metadata.fileID];
  1909. [task cancel];
  1910. }
  1911. if (!findTask) {
  1912. dispatch_async(dispatch_get_main_queue(), ^{
  1913. [app.listChangeTask setObject:@"reloadDownload" forKey:metadata.fileID];
  1914. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1915. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1916. });
  1917. }
  1918. }];
  1919. }
  1920. // UPLOAD
  1921. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1922. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1923. for (NSURLSessionUploadTask *task in uploadTasks)
  1924. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1925. findTask = task;
  1926. [app.listChangeTask setObject:@"reloadUpload" forKey:metadata.fileID];
  1927. [task cancel];
  1928. }
  1929. if (!findTask) {
  1930. dispatch_async(dispatch_get_main_queue(), ^{
  1931. [app.listChangeTask setObject:@"reloadUpload" forKey:metadata.fileID];
  1932. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1933. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1934. });
  1935. }
  1936. }];
  1937. }
  1938. }
  1939. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  1940. {
  1941. UITouch * touch = [[event allTouches] anyObject];
  1942. CGPoint location = [touch locationInView:self.tableView];
  1943. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1944. if (indexPath) {
  1945. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1946. if (metadata)
  1947. [self cancelTaskButton:metadata reloadTable:YES];
  1948. }
  1949. }
  1950. - (void)cancelTaskButton:(CCMetadata *)metadata reloadTable:(BOOL)reloadTable
  1951. {
  1952. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  1953. __block NSURLSessionTask *findTask;
  1954. // DOWNLOAD
  1955. if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
  1956. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1957. for (NSURLSessionTask *task in downloadTasks)
  1958. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1959. findTask = task;
  1960. [app.listChangeTask setObject:@"cancelDownload" forKey:metadata.fileID];
  1961. [task cancel];
  1962. }
  1963. if (!findTask) {
  1964. [app.listChangeTask setObject:@"cancelDownload" forKey:metadata.fileID];
  1965. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1966. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1967. }
  1968. }];
  1969. }
  1970. // UPLOAD
  1971. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  1972. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  1973. for (NSURLSessionUploadTask *task in uploadTasks)
  1974. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  1975. findTask = task;
  1976. [app.listChangeTask setObject:@"cancelUpload" forKey:metadata.fileID];
  1977. [task cancel];
  1978. }
  1979. if (!findTask) {
  1980. dispatch_async(dispatch_get_main_queue(), ^{
  1981. [app.listChangeTask setObject:@"cancelUpload" forKey:metadata.fileID];
  1982. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  1983. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  1984. });
  1985. }
  1986. }];
  1987. }
  1988. }
  1989. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  1990. {
  1991. UITouch * touch = [[event allTouches] anyObject];
  1992. CGPoint location = [touch locationInView:self.tableView];
  1993. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  1994. if (indexPath) {
  1995. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  1996. if (metadata)
  1997. [self stopTaskButton:metadata];
  1998. }
  1999. }
  2000. - (void)stopTaskButton:(CCMetadata *)metadata
  2001. {
  2002. NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
  2003. __block NSURLSessionTask *findTask;
  2004. // UPLOAD
  2005. if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
  2006. [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
  2007. for (NSURLSessionUploadTask *task in uploadTasks)
  2008. if (task.taskIdentifier == metadata.sessionTaskIdentifier || task.taskIdentifier == metadata.sessionTaskIdentifierPlist) {
  2009. [app.listChangeTask setObject:@"stopUpload" forKey:metadata.fileID];
  2010. findTask = task;
  2011. [task cancel];
  2012. }
  2013. if (!findTask) {
  2014. dispatch_async(dispatch_get_main_queue(), ^{
  2015. [app.listChangeTask setObject:@"stopUpload" forKey:metadata.fileID];
  2016. NSArray *object = [[NSArray alloc] initWithObjects:session, metadata, findTask, nil];
  2017. [[NSNotificationCenter defaultCenter] postNotificationName:networkingSessionNotification object:object];
  2018. });
  2019. }
  2020. }];
  2021. }
  2022. }
  2023. #pragma --------------------------------------------------------------------------------------------
  2024. #pragma mark ===== Shared =====
  2025. #pragma --------------------------------------------------------------------------------------------
  2026. - (void)readSharedSuccess:(CCMetadataNet *)metadataNet items:(NSDictionary *)items openWindow:(BOOL)openWindow
  2027. {
  2028. [_hud hideHud];
  2029. // change account ?
  2030. TableAccount *record = [CCCoreData getActiveAccount];
  2031. if([record.account isEqualToString:metadataNet.account] == NO)
  2032. return;
  2033. [CCCoreData updateShare:items sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup activeAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  2034. if (openWindow && ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud])) {
  2035. if (_shareOC) {
  2036. [_shareOC reloadData];
  2037. } else {
  2038. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadataNet.fileID, app.activeAccount] context:nil];
  2039. // Apriamo la view
  2040. _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
  2041. _shareOC.delegate = self;
  2042. _shareOC.metadata = metadata;
  2043. _shareOC.serverUrl = metadataNet.serverUrl;
  2044. _shareOC.shareLink = [app.sharesLink objectForKey:metadata.fileID];
  2045. _shareOC.shareUserAndGroup = [app.sharesUserAndGroup objectForKey:metadata.fileID];
  2046. [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
  2047. [self presentViewController:_shareOC animated:YES completion:nil];
  2048. }
  2049. }
  2050. [self tableViewReload];
  2051. }
  2052. - (void)requestSharedByServer
  2053. {
  2054. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2055. metadataNet.action = actionReadShareServer;
  2056. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2057. }
  2058. - (void)shareFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2059. {
  2060. [_hud hideHud];
  2061. [app messageNotification:@"_share_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2062. if (_shareOC)
  2063. [_shareOC reloadData];
  2064. [self tableViewReload];
  2065. if (errorCode == 401)
  2066. [self changePasswordAccount];
  2067. }
  2068. - (void)share:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password
  2069. {
  2070. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2071. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2072. metadataNet.action = actionShare;
  2073. metadataNet.fileID = metadata.fileID;
  2074. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl typeCloud:app.typeCloud];
  2075. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2076. metadataNet.password = password;
  2077. metadataNet.selector = selectorShare;
  2078. metadataNet.serverUrl = serverUrl;
  2079. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2080. }
  2081. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2082. }
  2083. - (void)unShareSuccess:(CCMetadataNet *)metadataNet
  2084. {
  2085. [_hud hideHud];
  2086. // rimuoviamo la condivisione da db
  2087. [CCCoreData unShare:metadataNet.share fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl sharesLink:app.sharesLink sharesUserAndGroup:app.sharesUserAndGroup activeAccount:app.activeAccount];
  2088. if ([app.typeCloud isEqualToString:typeCloudNextcloud] && _shareOC)
  2089. [_shareOC reloadData];
  2090. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] && _shareOC)
  2091. [_shareOC reloadData];
  2092. [self tableViewReload];
  2093. }
  2094. - (void)unShare:(NSString *)share metadata:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl
  2095. {
  2096. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2097. metadataNet.action = actionUnShare;
  2098. metadataNet.fileID = metadata.fileID;
  2099. metadataNet.fileName = metadata.fileName;
  2100. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2101. metadataNet.selector = selectorUnshare;
  2102. metadataNet.serverUrl = serverUrl;
  2103. metadataNet.share = share;
  2104. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2105. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2106. }
  2107. - (void)updateShare:(NSString *)share metadata:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission
  2108. {
  2109. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2110. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2111. metadataNet.action = actionUpdateShare;
  2112. metadataNet.fileID = metadata.fileID;
  2113. metadataNet.expirationTime = expirationTime;
  2114. metadataNet.password = password;
  2115. metadataNet.selector = selectorUpdateShare;
  2116. metadataNet.serverUrl = serverUrl;
  2117. metadataNet.share = share;
  2118. metadataNet.sharePermission = permission;
  2119. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2120. }
  2121. [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2122. }
  2123. - (void)getUserAndGroupSuccess:(CCMetadataNet *)metadataNet items:(NSArray *)items
  2124. {
  2125. [_hud hideHud];
  2126. if (_shareOC)
  2127. [_shareOC reloadUserAndGroup:items];
  2128. }
  2129. - (void)getUserAndGroupFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  2130. {
  2131. [_hud hideHud];
  2132. [app messageNotification:@"_error_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2133. }
  2134. - (void)getUserAndGroup:(NSString *)find
  2135. {
  2136. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2137. if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
  2138. metadataNet.action = actionGetUserAndGroup;
  2139. metadataNet.options = find;
  2140. metadataNet.selector = selectorGetUserAndGroup;
  2141. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2142. }
  2143. [_hud visibleIndeterminateHud];
  2144. }
  2145. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(CCMetadata *)metadata directoryID:(NSString *)directoryID serverUrl:(NSString *)serverUrl
  2146. {
  2147. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2148. metadataNet.action = actionShareWith;
  2149. metadataNet.fileID = metadata.fileID;
  2150. metadataNet.directoryID = directoryID;
  2151. metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl typeCloud:app.typeCloud];
  2152. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2153. metadataNet.serverUrl = serverUrl;
  2154. metadataNet.selector = selectorShare;
  2155. metadataNet.share = user;
  2156. metadataNet.shareeType = shareeType;
  2157. metadataNet.sharePermission = permission;
  2158. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2159. [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  2160. }
  2161. - (void)openWindowShare:(CCMetadata *)metadata serverUrl:(NSString *)serverUrl
  2162. {
  2163. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  2164. metadataNet.action = actionReadShareServer;
  2165. metadataNet.fileID = metadata.fileID;
  2166. metadataNet.fileName = metadata.fileName;
  2167. metadataNet.fileNamePrint = metadata.fileNamePrint;
  2168. metadataNet.selector = selectorOpenWindowShare;
  2169. metadataNet.serverUrl = serverUrl;
  2170. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  2171. [_hud visibleIndeterminateHud];
  2172. }
  2173. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  2174. {
  2175. CGPoint location = [tapGesture locationInView:self.tableView];
  2176. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  2177. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2178. if (metadata)
  2179. [self openWindowShare:metadata serverUrl:_localServerUrl];
  2180. }
  2181. - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
  2182. {
  2183. CGPoint location = [tapGesture locationInView:self.tableView];
  2184. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  2185. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  2186. if (metadata) {
  2187. CCShareInfoCMOC *vc = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareInfoCMOC"];
  2188. vc.metadata = metadata;
  2189. [vc setModalPresentationStyle:UIModalPresentationFormSheet];
  2190. [self presentViewController:vc animated:YES completion:nil];
  2191. }
  2192. }
  2193. #pragma --------------------------------------------------------------------------------------------
  2194. #pragma mark ===== Offline =====
  2195. #pragma --------------------------------------------------------------------------------------------
  2196. - (void)addOffline:(CCMetadata *)metadata
  2197. {
  2198. if (metadata.errorPasscode || !metadata.uuid) return;
  2199. if ([metadata.type isEqualToString:metadataType_file])
  2200. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorAddOffline selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2201. if ([metadata.type isEqualToString:metadataType_model])
  2202. [CCCoreData addOffline:metadata.fileID activeAccount:app.activeAccount];
  2203. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2204. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2205. }
  2206. - (void)removeOffline:(CCMetadata *)metadata
  2207. {
  2208. [CCCoreData removeOfflineFileID:metadata.fileID activeAccount:app.activeAccount];
  2209. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2210. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2211. [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableOffline" object:nil];
  2212. }
  2213. #pragma --------------------------------------------------------------------------------------------
  2214. #pragma mark ===== Local =====
  2215. #pragma --------------------------------------------------------------------------------------------
  2216. - (void)addLocal:(CCMetadata *)metadata
  2217. {
  2218. if (metadata.errorPasscode || !metadata.uuid) return;
  2219. if ([metadata.type isEqualToString:metadataType_file])
  2220. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorAddLocal selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2221. if ([metadata.type isEqualToString:metadataType_model]) {
  2222. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileName]];
  2223. [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  2224. [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableOffline" object:nil];
  2225. }
  2226. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2227. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2228. }
  2229. #pragma --------------------------------------------------------------------------------------------
  2230. #pragma mark ===== Reload =====
  2231. #pragma --------------------------------------------------------------------------------------------
  2232. - (void)reloadFile:(CCMetadata *)metadata
  2233. {
  2234. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorReload selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2235. }
  2236. #pragma --------------------------------------------------------------------------------------------
  2237. #pragma mark ===== Open in... =====
  2238. #pragma --------------------------------------------------------------------------------------------
  2239. - (void)openIn:(CCMetadata *)metadata
  2240. {
  2241. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2242. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
  2243. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2244. }
  2245. #pragma --------------------------------------------------------------------------------------------
  2246. #pragma mark ===== Order Table & GroupBy & DirectoryOnTop =====
  2247. #pragma --------------------------------------------------------------------------------------------
  2248. - (void)orderTable:(NSString *)order
  2249. {
  2250. // Clear data-read of DataSource
  2251. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2252. [CCUtility setOrderSettings:order];
  2253. // refresh
  2254. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2255. // new menu
  2256. [self createReMainMenu];
  2257. }
  2258. - (void)ascendingTable:(BOOL)ascending
  2259. {
  2260. // Clear data-read of DataSource
  2261. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2262. [CCUtility setAscendingSettings:ascending];
  2263. // refresh
  2264. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2265. // new menu
  2266. [self createReMainMenu];
  2267. }
  2268. - (void)directoryOnTop:(BOOL)directoryOnTop
  2269. {
  2270. // Clear data-read of DataSource
  2271. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2272. [CCUtility setDirectoryOnTop:directoryOnTop];
  2273. // refresh
  2274. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2275. // new menu
  2276. [self createReMainMenu];
  2277. }
  2278. - (void)tableGroupBy:(NSString *)groupBy
  2279. {
  2280. // Clear data-read of DataSource
  2281. [[NSNotificationCenter defaultCenter] postNotificationName:@"clearDateReadDataSource" object:nil];
  2282. [CCUtility setGroupBySettings:groupBy];
  2283. // refresh
  2284. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  2285. // new menu
  2286. [self createReMainMenu];
  2287. }
  2288. #pragma --------------------------------------------------------------------------------------------
  2289. #pragma mark ==== Menu change User ====
  2290. #pragma --------------------------------------------------------------------------------------------
  2291. - (void)menuChangeUser
  2292. {
  2293. if (app.reSelectMenu.isOpen || app.reMainMenu.isOpen)
  2294. return;
  2295. 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) {
  2296. [app messageNotification:@"_transfers_in_queue_" description:nil visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  2297. return;
  2298. }
  2299. NSArray *listTableAccount = [CCCoreData getAllTableAccount];
  2300. NSMutableArray *menuArray = [[NSMutableArray alloc] init];
  2301. for (TableAccount *record in listTableAccount) {
  2302. if ([record.account isEqualToString:app.activeAccount]) continue;
  2303. CCMenuItem *item = [[CCMenuItem alloc] init];
  2304. item.title = [record.account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
  2305. item.argument = record.account;
  2306. if ([record.typeCloud isEqualToString:typeCloudNextcloud]) item.image = [UIImage imageNamed:image_typeCloudNextcloud];
  2307. if ([record.typeCloud isEqualToString:typeCloudOwnCloud]) item.image = [UIImage imageNamed:image_typeCloudOwnCloud];
  2308. item.target = self;
  2309. item.action = @selector(changeDefaultAccount:);
  2310. [menuArray addObject:item];
  2311. }
  2312. if ([menuArray count] == 0)
  2313. return;
  2314. OptionalConfiguration options;
  2315. Color textColor, backgroundColor;
  2316. textColor.R = 0;
  2317. textColor.G = 0;
  2318. textColor.B = 0;
  2319. backgroundColor.R = 1;
  2320. backgroundColor.G = 1;
  2321. backgroundColor.B = 1;
  2322. options.arrowSize = 9;
  2323. options.marginXSpacing = 7;
  2324. options.marginYSpacing = 10;
  2325. options.intervalSpacing = 20;
  2326. options.menuCornerRadius = 6.5;
  2327. options.maskToBackground = NO;
  2328. options.shadowOfMenu = YES;
  2329. options.hasSeperatorLine = YES;
  2330. options.seperatorLineHasInsets = YES;
  2331. options.textColor = textColor;
  2332. options.menuBackgroundColor = backgroundColor;
  2333. [CCMenu setTitleFont:[UIFont systemFontOfSize:12.0]];
  2334. [CCMenu showMenuInView:self.navigationController.view fromRect:self.view.frame menuItems:menuArray withOptions:options];
  2335. }
  2336. - (void)changeDefaultAccount:(CCMenuItem *)sender
  2337. {
  2338. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
  2339. // STOP, erase all in queue networking
  2340. [app cancelAllOperations];
  2341. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  2342. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  2343. TableAccount *tableAccount = [CCCoreData setActiveAccount:[sender argument]];
  2344. if (tableAccount)
  2345. [app settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activePassword:tableAccount.password activeUID:tableAccount.uid activeAccessToken:tableAccount.token typeCloud:tableAccount.typeCloud];
  2346. // go to home sweet home
  2347. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  2348. [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
  2349. });
  2350. }
  2351. #pragma --------------------------------------------------------------------------------------------
  2352. #pragma mark ==== ReMenu ====
  2353. #pragma --------------------------------------------------------------------------------------------
  2354. - (void)createReMenuBackgroundView:(REMenu *)menu
  2355. {
  2356. __block CGFloat navigationBarH = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
  2357. _reMenuBackgroundView.frame = CGRectMake(0, navigationBarH, self.view.frame.size.width, self.view.frame.size.height);
  2358. [UIView animateWithDuration:0.2 animations:^{
  2359. float height = (self.view.frame.size.height + navigationBarH) - (menu.menuView.frame.size.height - self.navigationController.navigationBar.frame.size.height + 3);
  2360. if (height < self.tabBarController.tabBar.frame.size.height)
  2361. height = self.tabBarController.tabBar.frame.size.height;
  2362. _reMenuBackgroundView.frame = CGRectMake(0, self.view.frame.size.height + navigationBarH, self.view.frame.size.width, - height);
  2363. [self.tabBarController.view addSubview:_reMenuBackgroundView];
  2364. }];
  2365. }
  2366. - (void)createReMainMenu
  2367. {
  2368. NSString *ordinamento;
  2369. NSString *groupBy = _directoryGroupBy;
  2370. __block NSString *nuovoOrdinamento;
  2371. NSString *titoloNuovo, *titoloAttuale;
  2372. BOOL ascendente;
  2373. __block BOOL nuovoAscendente;
  2374. UIImage *image;
  2375. // ITEM SELECT ----------------------------------------------------------------------------------------------------
  2376. if (app.selezionaItem == nil) app.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)
  2377. subtitle:@""
  2378. image:[UIImage imageNamed:image_seleziona]
  2379. highlightedImage:nil
  2380. action:^(REMenuItem *item) {
  2381. if ([_sectionDataSource.allRecordsDataSource count] > 0) {
  2382. [self tableViewSelect:YES];
  2383. }
  2384. }];
  2385. else app.selezionaItem = [app.selezionaItem initWithTitle:NSLocalizedString(@"_select_", nil)
  2386. subtitle:@""
  2387. image:[UIImage imageNamed:image_seleziona]
  2388. highlightedImage:nil
  2389. action:^(REMenuItem *item) {
  2390. if ([_sectionDataSource.allRecordsDataSource count] > 0)
  2391. [self tableViewSelect:YES];
  2392. }];
  2393. // ITEM ORDER ----------------------------------------------------------------------------------------------------
  2394. ordinamento = _directoryOrder;
  2395. if ([ordinamento isEqualToString:@"fileName"]) {
  2396. image = [UIImage imageNamed:image_MenuOrdeyByDate];
  2397. titoloNuovo = NSLocalizedString(@"_order_by_date_", nil);
  2398. titoloAttuale = NSLocalizedString(@"_current_order_name_", nil);
  2399. nuovoOrdinamento = @"fileDate";
  2400. }
  2401. if ([ordinamento isEqualToString:@"fileDate"]) {
  2402. image = [UIImage imageNamed:image_MenuOrderByFileName];
  2403. titoloNuovo = NSLocalizedString(@"_order_by_name_", nil);
  2404. titoloAttuale = NSLocalizedString(@"_current_order_date_", nil);
  2405. nuovoOrdinamento = @"fileName";
  2406. }
  2407. if (app.ordinaItem == nil) app.ordinaItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2408. subtitle:titoloAttuale
  2409. image:image
  2410. highlightedImage:nil
  2411. action:^(REMenuItem *item) {
  2412. [self orderTable:nuovoOrdinamento];
  2413. }];
  2414. else app.ordinaItem = [app.ordinaItem initWithTitle:titoloNuovo
  2415. subtitle:titoloAttuale
  2416. image:image
  2417. highlightedImage:nil
  2418. action:^(REMenuItem *item) {
  2419. [self orderTable:nuovoOrdinamento];
  2420. }];
  2421. // ITEM ASCENDING -----------------------------------------------------------------------------------------------------
  2422. ascendente = [CCUtility getAscendingSettings];
  2423. if (ascendente) {
  2424. image = [UIImage imageNamed:image_MenuOrdinamentoDiscendente];
  2425. titoloNuovo = NSLocalizedString(@"_sort_descending_", nil);
  2426. titoloAttuale = NSLocalizedString(@"_current_sort_ascending_", nil);
  2427. nuovoAscendente = false;
  2428. }
  2429. if (!ascendente) {
  2430. image = [UIImage imageNamed:image_MenuOrdinamentoAscendente];
  2431. titoloNuovo = NSLocalizedString(@"_sort_ascending_", nil);
  2432. titoloAttuale = NSLocalizedString(@"_current_sort_descending_", nil);
  2433. nuovoAscendente = true;
  2434. }
  2435. if (app.ascendenteItem == nil) app.ascendenteItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2436. subtitle:titoloAttuale
  2437. image:image
  2438. highlightedImage:nil
  2439. action:^(REMenuItem *item) {
  2440. [self ascendingTable:nuovoAscendente];
  2441. }];
  2442. else app.ascendenteItem = [app.ascendenteItem initWithTitle:titoloNuovo
  2443. subtitle:titoloAttuale
  2444. image:image
  2445. highlightedImage:nil
  2446. action:^(REMenuItem *item) {
  2447. [self ascendingTable:nuovoAscendente];
  2448. }];
  2449. // ITEM ALPHABETIC -----------------------------------------------------------------------------------------------------
  2450. if ([groupBy isEqualToString:@"alphabetic"]) { titoloNuovo = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
  2451. else { titoloNuovo = NSLocalizedString(@"_group_alphabetic_no_", nil); }
  2452. if (app.alphabeticItem == nil) app.alphabeticItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2453. subtitle:@""
  2454. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2455. highlightedImage:nil
  2456. action:^(REMenuItem *item) {
  2457. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2458. else [self tableGroupBy:@"alphabetic"];
  2459. }];
  2460. else app.alphabeticItem = [app.alphabeticItem initWithTitle:titoloNuovo
  2461. subtitle:@""
  2462. image:[UIImage imageNamed:image_MenuGroupByAlphabetic]
  2463. highlightedImage:nil
  2464. action:^(REMenuItem *item) {
  2465. if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
  2466. else [self tableGroupBy:@"alphabetic"];
  2467. }];
  2468. // ITEM TYPEFILE -------------------------------------------------------------------------------------------------------
  2469. if ([groupBy isEqualToString:@"typefile"]) { titoloNuovo = NSLocalizedString(@"_group_typefile_yes_", nil); }
  2470. else { titoloNuovo = NSLocalizedString(@"_group_typefile_no_", nil); }
  2471. if (app.typefileItem == nil) app.typefileItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2472. subtitle:@""
  2473. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2474. highlightedImage:nil
  2475. action:^(REMenuItem *item) {
  2476. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2477. else [self tableGroupBy:@"typefile"];
  2478. }];
  2479. else app.typefileItem = [app.typefileItem initWithTitle:titoloNuovo
  2480. subtitle:@""
  2481. image:[UIImage imageNamed:image_MenuGroupByTypeFile]
  2482. highlightedImage:nil
  2483. action:^(REMenuItem *item) {
  2484. if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
  2485. else [self tableGroupBy:@"typefile"];
  2486. }];
  2487. // ITEM DATE -------------------------------------------------------------------------------------------------------
  2488. if ([groupBy isEqualToString:@"date"]) { titoloNuovo = NSLocalizedString(@"_group_date_yes_", nil); }
  2489. else { titoloNuovo = NSLocalizedString(@"_group_date_no_", nil); }
  2490. if (app.dateItem == nil) app.dateItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2491. subtitle:@""
  2492. image:[UIImage imageNamed:image_MenuGroupByDate]
  2493. highlightedImage:nil
  2494. action:^(REMenuItem *item) {
  2495. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2496. else [self tableGroupBy:@"date"];
  2497. }];
  2498. else app.dateItem = [app.dateItem initWithTitle:titoloNuovo
  2499. subtitle:@""
  2500. image:[UIImage imageNamed:image_MenuGroupByDate]
  2501. highlightedImage:nil
  2502. action:^(REMenuItem *item) {
  2503. if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
  2504. else [self tableGroupBy:@"date"];
  2505. }];
  2506. // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
  2507. if ([CCUtility getDirectoryOnTop]) { titoloNuovo = NSLocalizedString(@"_directory_on_top_yes_", nil); }
  2508. else { titoloNuovo = NSLocalizedString(@"_directory_on_top_no_", nil); }
  2509. if (app.directoryOnTopItem == nil) app.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:titoloNuovo
  2510. subtitle:@""
  2511. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2512. highlightedImage:nil
  2513. action:^(REMenuItem *item) {
  2514. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2515. else [self directoryOnTop:YES];
  2516. }];
  2517. else app.directoryOnTopItem = [app.directoryOnTopItem initWithTitle:titoloNuovo
  2518. subtitle:@""
  2519. image:[UIImage imageNamed:image_MenuDirectoryOnTop]
  2520. highlightedImage:nil
  2521. action:^(REMenuItem *item) {
  2522. if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
  2523. else [self directoryOnTop:YES];
  2524. }];
  2525. // REMENU --------------------------------------------------------------------------------------------------------------
  2526. if (app.reMainMenu == nil) app.reMainMenu = [[REMenu alloc] initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2527. else app.reMainMenu = [app.reMainMenu initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
  2528. app.reMainMenu.imageOffset = CGSizeMake(5, -1);
  2529. app.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2530. app.reMainMenu.imageOffset = CGSizeMake(0, 0);
  2531. app.reMainMenu.waitUntilAnimationIsComplete = NO;
  2532. app.reMainMenu.separatorHeight = 0.5;
  2533. app.reMainMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2534. app.reMainMenu.backgroundColor = COLOR_BAR;
  2535. app.reMainMenu.textColor = [UIColor blackColor];
  2536. app.reMainMenu.textAlignment = NSTextAlignmentLeft;
  2537. app.reMainMenu.textShadowColor = nil;
  2538. app.reMainMenu.textOffset = CGSizeMake(50, 0.0);
  2539. app.reMainMenu.font = [UIFont systemFontOfSize:14.0];
  2540. app.reMainMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2541. app.reMainMenu.highlightedSeparatorColor = nil;
  2542. app.reMainMenu.highlightedTextColor = [UIColor blackColor];
  2543. app.reMainMenu.highlightedTextShadowColor = nil;
  2544. app.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2545. app.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
  2546. app.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2547. app.reMainMenu.subtitleTextShadowColor = nil;
  2548. app.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2549. app.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2550. app.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2551. app.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2552. app.reMainMenu.subtitleHighlightedTextShadowColor = nil;
  2553. app.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2554. app.reMainMenu.borderWidth = 0.3;
  2555. app.reMainMenu.borderColor = [UIColor lightGrayColor];
  2556. app.reMainMenu.animationDuration = 0.2;
  2557. app.reMainMenu.closeAnimationDuration = 0.2;
  2558. app.reMainMenu.bounce = NO;
  2559. [app.reMainMenu setClosePreparationBlock:^{
  2560. // Backgroun reMenu (Gesture)
  2561. [_reMenuBackgroundView removeFromSuperview];
  2562. [app.controlCenter disableSingleFingerTap];
  2563. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2564. }];
  2565. }
  2566. - (void)toggleReMainMenu
  2567. {
  2568. if (app.reMainMenu.isOpen) {
  2569. [app.reMainMenu close];
  2570. } else {
  2571. [app.reMainMenu showFromNavigationController:self.navigationController];
  2572. // Backgroun reMenu & (Gesture)
  2573. [self createReMenuBackgroundView:app.reMainMenu];
  2574. [app.controlCenter enableSingleFingerTap:@selector(toggleReMainMenu) target:self];
  2575. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
  2576. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2577. }
  2578. }
  2579. - (void)createReSelectMenu
  2580. {
  2581. // ITEM DELETE ------------------------------------------------------------------------------------------------------
  2582. if (app.deleteItem == nil) app.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2583. subtitle:@""
  2584. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2585. highlightedImage:nil
  2586. action:^(REMenuItem *item) {
  2587. [self deleteSelectionFile];
  2588. }];
  2589. else app.deleteItem = [app.deleteItem initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil)
  2590. subtitle:@""
  2591. image:[UIImage imageNamed:image_deleteSelectedFiles]
  2592. highlightedImage:nil
  2593. action:^(REMenuItem *item) {
  2594. [self deleteSelectionFile];
  2595. }];
  2596. // ITEM MOVE ------------------------------------------------------------------------------------------------------
  2597. if (app.moveItem == nil) app.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2598. subtitle:@""
  2599. image:[UIImage imageNamed:image_moveSelectedFiles]
  2600. highlightedImage:nil
  2601. action:^(REMenuItem *item) {
  2602. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2603. }];
  2604. else app.moveItem = [app.moveItem initWithTitle:NSLocalizedString(@"_move_selected_files_", nil)
  2605. subtitle:@""
  2606. image:[UIImage imageNamed:image_moveSelectedFiles]
  2607. highlightedImage:nil
  2608. action:^(REMenuItem *item) {
  2609. [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
  2610. }];
  2611. // ITEM ENCRYPTED ------------------------------------------------------------------------------------------------------
  2612. if (app.encryptItem == nil) app.encryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2613. subtitle:@""
  2614. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2615. highlightedImage:nil
  2616. action:^(REMenuItem *item) {
  2617. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2618. }];
  2619. else app.encryptItem = [app.encryptItem initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil)
  2620. subtitle:@""
  2621. image:[UIImage imageNamed:image_encryptedSelectedFiles]
  2622. highlightedImage:nil
  2623. action:^(REMenuItem *item) {
  2624. [self performSelector:@selector(encryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2625. }];
  2626. // ITEM DECRYPTED ----------------------------------------------------------------------------------------------------
  2627. if (app.decryptItem == nil) app.decryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2628. subtitle:@""
  2629. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2630. highlightedImage:nil
  2631. action:^(REMenuItem *item) {
  2632. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2633. }];
  2634. else app.decryptItem = [app.decryptItem initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil)
  2635. subtitle:@""
  2636. image:[UIImage imageNamed:image_decryptedSelectedFiles]
  2637. highlightedImage:nil
  2638. action:^(REMenuItem *item) {
  2639. [self performSelector:@selector(decryptedSelectedFiles) withObject:nil afterDelay:0.1];
  2640. }];
  2641. // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
  2642. if (app.downloadItem == nil) app.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2643. subtitle:@""
  2644. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2645. highlightedImage:nil
  2646. action:^(REMenuItem *item) {
  2647. [self downloadSelectedFiles];
  2648. }];
  2649. else app.downloadItem = [app.downloadItem initWithTitle:NSLocalizedString(@"_download_selected_files_", nil)
  2650. subtitle:@""
  2651. image:[UIImage imageNamed:image_downloadSelectedFiles]
  2652. highlightedImage:nil
  2653. action:^(REMenuItem *item) {
  2654. [self downloadSelectedFiles];
  2655. }];
  2656. // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
  2657. if (app.saveItem == nil) app.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2658. subtitle:@""
  2659. image:[UIImage imageNamed:image_saveSelectedFiles]
  2660. highlightedImage:nil
  2661. action:^(REMenuItem *item) {
  2662. [self saveSelectedFiles];
  2663. }];
  2664. else app.saveItem = [app.saveItem initWithTitle:NSLocalizedString(@"_save_selected_files_", nil)
  2665. subtitle:@""
  2666. image:[UIImage imageNamed:image_saveSelectedFiles]
  2667. highlightedImage:nil
  2668. action:^(REMenuItem *item) {
  2669. [self saveSelectedFiles];
  2670. }];
  2671. // REMENU --------------------------------------------------------------------------------------------------------------
  2672. if (app.reSelectMenu == nil)
  2673. app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2674. else
  2675. app.reSelectMenu = [app.reSelectMenu initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
  2676. app.reSelectMenu.imageOffset = CGSizeMake(5, -1);
  2677. app.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
  2678. app.reSelectMenu.imageOffset = CGSizeMake(0, 0);
  2679. app.reSelectMenu.waitUntilAnimationIsComplete = NO;
  2680. app.reSelectMenu.separatorHeight = 0.5;
  2681. app.reSelectMenu.separatorColor = COLOR_SEPARATOR_TABLE;
  2682. app.reSelectMenu.backgroundColor = COLOR_BAR;
  2683. app.reSelectMenu.textColor = [UIColor blackColor];
  2684. app.reSelectMenu.textAlignment = NSTextAlignmentLeft;
  2685. app.reSelectMenu.textShadowColor = nil;
  2686. app.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
  2687. app.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
  2688. app.reSelectMenu.highlightedBackgroundColor = COLOR_SELECT_BACKGROUND;
  2689. app.reSelectMenu.highlightedSeparatorColor = nil;
  2690. app.reSelectMenu.highlightedTextColor = [UIColor blackColor];
  2691. app.reSelectMenu.highlightedTextShadowColor = nil;
  2692. app.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
  2693. app.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
  2694. app.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
  2695. app.reSelectMenu.subtitleTextShadowColor = nil;
  2696. app.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
  2697. app.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
  2698. app.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
  2699. app.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
  2700. app.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
  2701. app.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
  2702. app.reSelectMenu.borderWidth = 0.3;
  2703. app.reSelectMenu.borderColor = [UIColor lightGrayColor];
  2704. app.reSelectMenu.closeAnimationDuration = 0.2;
  2705. app.reSelectMenu.animationDuration = 0.2;
  2706. app.reSelectMenu.bounce = NO;
  2707. [app.reSelectMenu setClosePreparationBlock:^{
  2708. // Backgroun reMenu (Gesture)
  2709. [_reMenuBackgroundView removeFromSuperview];
  2710. [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
  2711. }];
  2712. }
  2713. - (void)toggleReSelectMenu
  2714. {
  2715. if (app.reSelectMenu.isOpen) {
  2716. [app.reSelectMenu close];
  2717. } else {
  2718. [app.reSelectMenu showFromNavigationController:self.navigationController];
  2719. // Backgroun reMenu & (Gesture)
  2720. [self createReMenuBackgroundView:app.reSelectMenu];
  2721. _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
  2722. [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
  2723. }
  2724. }
  2725. #pragma --------------------------------------------------------------------------------------------
  2726. #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
  2727. #pragma --------------------------------------------------------------------------------------------
  2728. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  2729. {
  2730. if (recognizer.state == UIGestureRecognizerStateBegan) {
  2731. UITableView *tableView = (UITableView*)self.view;
  2732. CGPoint touchPoint = [recognizer locationInView:self.view];
  2733. NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:touchPoint];
  2734. if (indexPath)
  2735. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  2736. else
  2737. _metadata = nil;
  2738. [self becomeFirstResponder];
  2739. UIMenuController *menuController = [UIMenuController sharedMenuController];
  2740. UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
  2741. UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
  2742. UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
  2743. UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
  2744. UIMenuItem *pasteFileEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_encrypted_", nil) action:@selector(pasteFileEncrypted:)];
  2745. UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
  2746. UIMenuItem *pasteFilesEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_encrypted_", nil) action:@selector(pasteFilesEncrypted:)];
  2747. [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, pasteFileEncryptedItem, pasteFilesEncryptedItem, nil]];
  2748. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:tableView];
  2749. [menuController setMenuVisible:YES animated:YES];
  2750. }
  2751. }
  2752. - (BOOL)canBecomeFirstResponder
  2753. {
  2754. return YES;
  2755. }
  2756. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  2757. {
  2758. // For copy file, copy files, Open in ... :
  2759. //
  2760. // NO Directory
  2761. // NO Error Passcode
  2762. // NO In Session mode (download/upload)
  2763. // NO Template
  2764. if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
  2765. if (_isSelectedMode == NO && _metadata && !_metadata.directory && !_metadata.errorPasscode && [_metadata.session length] == 0 && ![_metadata.typeFile isEqualToString:metadataTypeFile_template]) {
  2766. // NO Cryptated with Title lenght = 0
  2767. if (!_metadata.cryptated || (_metadata.cryptated && _metadata.title.length > 0))
  2768. return YES;
  2769. }
  2770. return NO;
  2771. }
  2772. if (@selector(copyFiles:) == action) {
  2773. if (_isSelectedMode) {
  2774. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2775. for (CCMetadata *metadata in selectedMetadatas) {
  2776. if (!metadata.directory && !metadata.errorPasscode && metadata.session.length == 0 && ![metadata.typeFile isEqualToString:metadataTypeFile_template]) {
  2777. // NO Cryptated with Title lenght = 0
  2778. if (!metadata.cryptated || (metadata.cryptated && metadata.title.length > 0))
  2779. return YES;
  2780. }
  2781. }
  2782. }
  2783. return NO;
  2784. }
  2785. if (@selector(pasteFile:) == action || @selector(pasteFileEncrypted:) == action) {
  2786. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2787. NSArray *items = [pasteboard items];
  2788. if ([items count] == 1) {
  2789. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2790. NSDictionary *dic = [items objectAtIndex:0];
  2791. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2792. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2793. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2794. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2795. if (directoryUser) {
  2796. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2797. return YES;
  2798. }
  2799. return NO;
  2800. } else return NO;
  2801. }
  2802. if (@selector(pasteFiles:) == action || @selector(pasteFilesEncrypted:) == action) {
  2803. BOOL isValid = NO;
  2804. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2805. NSArray *items = [pasteboard items];
  2806. if ([items count] <= 1) return NO;
  2807. for (NSDictionary *dic in items) {
  2808. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2809. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2810. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2811. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2812. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2813. if (directoryUser) {
  2814. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]])
  2815. isValid = YES;
  2816. }
  2817. }
  2818. return isValid;
  2819. }
  2820. return NO;
  2821. }
  2822. /************************************ COPY ************************************/
  2823. - (void)copyFile:(id)sender
  2824. {
  2825. // Remove all item
  2826. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2827. pasteboard.items = [[NSArray alloc] init];
  2828. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser,_metadata.fileID]])
  2829. [self copyFileToPasteboard:_metadata];
  2830. else
  2831. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2832. }
  2833. - (void)copyFiles:(id)sender
  2834. {
  2835. // Remove all item
  2836. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2837. pasteboard.items = [[NSArray alloc] init];
  2838. NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
  2839. for (CCMetadata *metadata in selectedMetadatas) {
  2840. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  2841. [self copyFileToPasteboard:metadata];
  2842. else
  2843. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  2844. }
  2845. [self tableViewSelect:NO];
  2846. }
  2847. - (void)copyFileToPasteboard:(CCMetadata *)metadata
  2848. {
  2849. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2850. NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
  2851. // key : it.twsweb.Crypto-Cloud.CCMetadata Value : (NSData) metadata
  2852. NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata], @"it.twsweb.Crypto-Cloud.CCMetadata",nil];
  2853. [items addObject:item];
  2854. [pasteboard setItems:items];
  2855. }
  2856. /************************************ OPEN IN ... ************************************/
  2857. - (void)openinFile:(id)sender
  2858. {
  2859. [self openIn:_metadata];
  2860. }
  2861. /************************************ PASTE ************************************/
  2862. - (void)pasteFile:(id)sender
  2863. {
  2864. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2865. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2866. }
  2867. - (void)pasteFileEncrypted:(id)sender
  2868. {
  2869. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2870. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2871. }
  2872. - (void)pasteFiles:(id)sender
  2873. {
  2874. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2875. [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
  2876. }
  2877. - (void)pasteFilesEncrypted:(id)sender
  2878. {
  2879. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  2880. [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
  2881. }
  2882. - (void)uploadFilePasteArray:(NSArray *)items cryptated:(BOOL)cryptated
  2883. {
  2884. for (NSDictionary *dic in items) {
  2885. // key : it.twsweb.Crypto-Cloud.CCMetadata
  2886. // Value : (NSData) metadata
  2887. NSData *dataMetadata = [dic objectForKey:@"it.twsweb.Crypto-Cloud.CCMetadata"];
  2888. CCMetadata *metadata = [NSKeyedUnarchiver unarchiveObjectWithData:dataMetadata];
  2889. TableAccount *account = [CCCoreData getTableAccountFromAccount:metadata.account];
  2890. NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
  2891. if (directoryUser) {
  2892. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID]]) {
  2893. [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint]];
  2894. [[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];
  2895. }
  2896. }
  2897. }
  2898. }
  2899. #pragma --------------------------------------------------------------------------------------------
  2900. #pragma mark ===== Lock Passcode =====
  2901. #pragma --------------------------------------------------------------------------------------------
  2902. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  2903. {
  2904. return _failedAttempts;
  2905. }
  2906. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  2907. {
  2908. return _lockUntilDate;
  2909. }
  2910. - (void)passcodeViewCloseButtonPressed:(id)sender
  2911. {
  2912. [self dismissViewControllerAnimated:YES completion:nil];
  2913. }
  2914. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  2915. {
  2916. if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
  2917. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  2918. _lockUntilDate = nil;
  2919. _failedAttempts = 0;
  2920. aResultHandler(YES);
  2921. } else aResultHandler(NO);
  2922. } else aResultHandler(YES);
  2923. }
  2924. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  2925. {
  2926. [aViewController dismissViewControllerAnimated:YES completion:nil];
  2927. switch (aViewController.type) {
  2928. case BKPasscodeViewControllerCheckPasscodeType: {
  2929. if (aViewController.fromType == CCBKPasscodeFromPasscode) {
  2930. CCCrypto *crypto = [[CCCrypto alloc] init];
  2931. // verifichiamo se il passcode è corretto per il seguente file -> UUID
  2932. if ([crypto verifyPasscode:aPasscode uuid:_metadata.uuid text:_metadata.title]) {
  2933. // scriviamo il passcode
  2934. [CCUtility setKeyChainPasscodeForUUID:_metadata.uuid conPasscode:aPasscode];
  2935. [self readFolderWithForced:YES];
  2936. } else {
  2937. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_error_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  2938. [alertView show];
  2939. }
  2940. }
  2941. if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
  2942. // possiamo procedere alla prossima directory
  2943. [self performSegueDirectoryWithControlPasscode:false];
  2944. // avviamo la sessione Passcode Lock con now
  2945. app.sessionePasscodeLock = [NSDate date];
  2946. }
  2947. // disattivazione lock cartella
  2948. if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
  2949. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  2950. if ([CCCoreData setDirectoryUnLock:lockServerUrl activeAccount:app.activeAccount] == NO) {
  2951. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  2952. }
  2953. [self.tableView reloadData];
  2954. }
  2955. }
  2956. break;
  2957. default:
  2958. break;
  2959. }
  2960. }
  2961. - (void)comandoLockPassword
  2962. {
  2963. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  2964. // se non è abilitato il Lock Passcode esci
  2965. if ([[CCUtility getBlockCode] length] == 0) {
  2966. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  2967. [alertView show];
  2968. return;
  2969. }
  2970. // se è richiesta la disattivazione si chiede la password
  2971. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  2972. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  2973. viewController.delegate = self;
  2974. viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
  2975. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  2976. viewController.inputViewTitlePassword = YES;
  2977. if ([CCUtility getSimplyBlockCode]) {
  2978. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  2979. viewController.passcodeInputView.maximumLength = 6;
  2980. } else {
  2981. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  2982. viewController.passcodeInputView.maximumLength = 64;
  2983. }
  2984. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  2985. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  2986. viewController.touchIDManager = touchIDManager;
  2987. viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
  2988. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  2989. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  2990. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  2991. [self presentViewController:navigationController animated:YES completion:nil];
  2992. return;
  2993. }
  2994. // ---------------- ACTIVATE PASSWORD
  2995. if([CCCoreData setDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) {
  2996. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  2997. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  2998. } else {
  2999. [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  3000. }
  3001. }
  3002. #pragma --------------------------------------------------------------------------------------------
  3003. #pragma mark ===== Swipe Tablet -> menu =====
  3004. #pragma --------------------------------------------------------------------------------------------
  3005. // more
  3006. - (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  3007. return NSLocalizedString(@"_more_", nil);
  3008. }
  3009. - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
  3010. {
  3011. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3012. NSString *titoloCriptaDecripta, *titoloOffline, *titoloLock, *titleOfflineFolder;
  3013. BOOL offlineFolder = NO;
  3014. if (_metadata.cryptated) titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_decrypt_", nil)];
  3015. else titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_encrypt_", nil)];
  3016. if ([CCCoreData isOffline:_metadata.fileID activeAccount:app.activeAccount]) titoloOffline = [NSString stringWithFormat:NSLocalizedString(@"_remove_offline_", nil)];
  3017. else titoloOffline = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
  3018. NSString *offlineServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3019. if (_metadata.directory && [CCCoreData isOfflineDirectory:offlineServerUrl activeAccount:app.activeAccount]) {
  3020. titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_remove_offline_", nil)];
  3021. offlineFolder = YES;
  3022. } else titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
  3023. if (_metadata.directory) {
  3024. // calcolo lockServerUrl
  3025. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3026. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount]) titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
  3027. else titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
  3028. }
  3029. /******************************************* AHKActionSheet *******************************************/
  3030. UIImage *iconHeader;
  3031. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  3032. actionSheet.animationDuration = 0.2;
  3033. actionSheet.blurRadius = 0.0f;
  3034. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  3035. actionSheet.buttonHeight = 50.0;
  3036. actionSheet.cancelButtonHeight = 50.0f;
  3037. actionSheet.separatorHeight = 5.0f;
  3038. actionSheet.automaticallyTintButtonImages = @(NO);
  3039. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_ENCRYPTED };
  3040. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_GRAY };
  3041. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  3042. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:COLOR_GRAY };
  3043. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  3044. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  3045. /******************************************* DIRECTORY *******************************************/
  3046. if (_metadata.directory) {
  3047. UIImage *iconHeader;
  3048. BOOL lockDirectory = NO;
  3049. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3050. NSString *upDir = [CCUtility deletingLastPathComponentFromServerUrl:dirServerUrl];
  3051. NSString *homeDir = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud];
  3052. // Directory bloccata ?
  3053. if ([CCCoreData isDirectoryLock:dirServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3054. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3055. NSString *cameraUploadFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  3056. NSString *cameraUploadFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  3057. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3058. image: iconHeader
  3059. backgroundColor: COLOR_NAVBAR_IOS7
  3060. height: 50.0
  3061. type: AHKActionSheetButtonTypeDisabled
  3062. handler: nil
  3063. ];
  3064. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3065. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3066. image:[UIImage imageNamed:image_actionSheetRename]
  3067. backgroundColor:[UIColor whiteColor]
  3068. height: 50.0
  3069. type:AHKActionSheetButtonTypeDefault
  3070. handler:^(AHKActionSheet *as) {
  3071. // close swipe
  3072. [self setEditing:NO animated:YES];
  3073. //chiediamo il nome del file
  3074. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3075. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3076. alertView.tag = alertRename;
  3077. UITextField *textField = [alertView textFieldAtIndex:0];
  3078. textField.text = _metadata.fileNamePrint;
  3079. [alertView show];
  3080. }];
  3081. }
  3082. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3083. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3084. image:[UIImage imageNamed:image_actionSheetMove]
  3085. backgroundColor:[UIColor whiteColor]
  3086. height: 50.0
  3087. type:AHKActionSheetButtonTypeDefault
  3088. handler:^(AHKActionSheet *as) {
  3089. // close swipe
  3090. [self setEditing:NO animated:YES];
  3091. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3092. }];
  3093. }
  3094. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && !lockDirectory) {
  3095. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3096. image:[UIImage imageNamed:image_actionSheetCrypto]
  3097. backgroundColor:[UIColor whiteColor]
  3098. height: 50.0
  3099. type:AHKActionSheetButtonTypeEncrypted
  3100. handler:^(AHKActionSheet *as) {
  3101. // close swipe
  3102. [self setEditing:NO animated:YES];
  3103. [self performSelector:@selector(encyptedDecryptedFolder) withObject:nil afterDelay:0.1];
  3104. }];
  3105. }
  3106. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES)) {
  3107. [actionSheet addButtonWithTitle:titoloLock
  3108. image:[UIImage imageNamed:image_actionSheetLock]
  3109. backgroundColor:[UIColor whiteColor]
  3110. height: 50.0
  3111. type:AHKActionSheetButtonTypeEncrypted
  3112. handler:^(AHKActionSheet *as) {
  3113. // close swipe
  3114. [self setEditing:NO animated:YES];
  3115. [self performSelector:@selector(comandoLockPassword) withObject:nil afterDelay:0.1];
  3116. }];
  3117. }
  3118. if (_metadata.cryptated == NO && app.hasServerShareSupport && !lockDirectory) {
  3119. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3120. image:[UIImage imageNamed:image_actionSheetShare]
  3121. backgroundColor:[UIColor whiteColor]
  3122. height: 50.0
  3123. type:AHKActionSheetButtonTypeDefault
  3124. handler:^(AHKActionSheet *as) {
  3125. // close swipe
  3126. [self setEditing:NO animated:YES];
  3127. [self openWindowShare:_metadata serverUrl:_localServerUrl];
  3128. }];
  3129. }
  3130. if (!([_metadata.fileName isEqualToString:cameraUploadFolderName] == YES && [_localServerUrl isEqualToString:cameraUploadFolderPath] == YES) && _metadata.cryptated == NO) {
  3131. [actionSheet addButtonWithTitle:NSLocalizedString(@"_folder_automatic_upload_", nil)
  3132. image:[UIImage imageNamed:image_folderphotocamera]
  3133. backgroundColor:[UIColor whiteColor]
  3134. height: 50.0
  3135. type:AHKActionSheetButtonTypeDefault
  3136. handler:^(AHKActionSheet *as) {
  3137. // close swipe
  3138. [self setEditing:NO animated:YES];
  3139. // Settings new folder Automatatic upload
  3140. NSString *oldPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  3141. [CCCoreData setCameraUploadFolderName:_metadata.fileName activeAccount:app.activeAccount];
  3142. [CCCoreData setCameraUploadFolderPath:_localServerUrl activeUrl:app.activeUrl typeCloud:app.typeCloud activeAccount:app.activeAccount];
  3143. [CCCoreData clearDateReadDirectory:oldPath activeAccount:app.activeAccount];
  3144. if (app.activeAccount && app.activeUrl && app.activePhotosCameraUpload)
  3145. [app.activePhotosCameraUpload reloadDatasourceForced];
  3146. [self readFolderWithForced:YES];
  3147. }];
  3148. }
  3149. if (!lockDirectory && ([upDir isEqualToString:homeDir] || ![CCCoreData isOfflineDirectory:upDir activeAccount:app.activeAccount])) {
  3150. [actionSheet addButtonWithTitle:titleOfflineFolder
  3151. image:[UIImage imageNamed:image_actionSheetOffline]
  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. if (offlineFolder == NO) {
  3159. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"",nil) message:NSLocalizedString(@"_offline_folder_confirm_",nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3160. alertView.tag = alertOfflineFolder;
  3161. [alertView show];
  3162. } else {
  3163. // remove tag offline for all folder/subfolder/file
  3164. NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
  3165. for (TableDirectory *directory in directories)
  3166. if ([directory.serverUrl containsString:dirServerUrl]) {
  3167. [CCCoreData setOfflineDirectory:directory.serverUrl offline:NO activeAccount:app.activeAccount];
  3168. [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
  3169. }
  3170. [self performSelector:@selector(getDataSourceWithReloadTableView) withObject:nil];
  3171. }
  3172. }];
  3173. }
  3174. [actionSheet show];
  3175. }
  3176. /******************************************* FILE *******************************************/
  3177. if ([_metadata.type isEqualToString:metadataType_file] && !_metadata.directory) {
  3178. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3179. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]])
  3180. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]];
  3181. else
  3182. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3183. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3184. image: iconHeader
  3185. backgroundColor: COLOR_NAVBAR_IOS7
  3186. height: 50.0
  3187. type: AHKActionSheetButtonTypeDisabled
  3188. handler: nil
  3189. ];
  3190. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3191. image:[UIImage imageNamed:image_actionSheetRename]
  3192. backgroundColor:[UIColor whiteColor]
  3193. height: 50.0
  3194. type:AHKActionSheetButtonTypeDefault
  3195. handler:^(AHKActionSheet *as) {
  3196. // close swipe
  3197. [self setEditing:NO animated:YES];
  3198. //chiediamo il nome del file
  3199. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3200. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3201. alertView.tag = alertRename;
  3202. UITextField *textField = [alertView textFieldAtIndex:0];
  3203. textField.text = _metadata.fileNamePrint;
  3204. [alertView show];
  3205. }];
  3206. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3207. image:[UIImage imageNamed:image_actionSheetMove]
  3208. backgroundColor:[UIColor whiteColor]
  3209. height: 50.0
  3210. type:AHKActionSheetButtonTypeDefault
  3211. handler:^(AHKActionSheet *as) {
  3212. // close swipe
  3213. [self setEditing:NO animated:YES];
  3214. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3215. }];
  3216. [actionSheet addButtonWithTitle:NSLocalizedString(@"_reload_", nil)
  3217. image:[UIImage imageNamed:image_actionSheetReload]
  3218. backgroundColor:[UIColor whiteColor]
  3219. height: 50.0
  3220. type:AHKActionSheetButtonTypeDefault
  3221. handler:^(AHKActionSheet *as) {
  3222. // close swipe
  3223. [self setEditing:NO animated:YES];
  3224. [self performSelector:@selector(reloadFile:) withObject:_metadata afterDelay:0.1];
  3225. }];
  3226. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  3227. image:[UIImage imageNamed:image_actionSheetOpenIn]
  3228. backgroundColor:[UIColor whiteColor]
  3229. height: 50.0
  3230. type:AHKActionSheetButtonTypeDefault
  3231. handler:^(AHKActionSheet *as) {
  3232. // close swipe
  3233. [self setEditing:NO animated:YES];
  3234. [self performSelector:@selector(openIn:) withObject:_metadata afterDelay:0.1];
  3235. }];
  3236. if (_metadata.cryptated == NO && app.hasServerShareSupport) {
  3237. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  3238. image:[UIImage imageNamed:image_actionSheetShare]
  3239. backgroundColor:[UIColor whiteColor]
  3240. height: 50.0
  3241. type:AHKActionSheetButtonTypeDefault
  3242. handler:^(AHKActionSheet *as) {
  3243. // close swipe
  3244. [self setEditing:NO animated:YES];
  3245. [self openWindowShare:_metadata serverUrl:_localServerUrl];
  3246. }];
  3247. }
  3248. [actionSheet addButtonWithTitle:titoloCriptaDecripta
  3249. image:[UIImage imageNamed:image_actionSheetCrypto]
  3250. backgroundColor:[UIColor whiteColor]
  3251. height: 50.0
  3252. type:AHKActionSheetButtonTypeEncrypted
  3253. handler:^(AHKActionSheet *as) {
  3254. // close swipe
  3255. [self setEditing:NO animated:YES];
  3256. [self performSelector:@selector(cmdEncryptedDecryptedFile) withObject:nil afterDelay:0.1];
  3257. }];
  3258. if (![CCCoreData isOfflineDirectory:_localServerUrl activeAccount:app.activeAccount]) {
  3259. [actionSheet addButtonWithTitle:titoloOffline
  3260. image:[UIImage imageNamed:image_actionSheetOffline]
  3261. backgroundColor:[UIColor whiteColor]
  3262. height: 50.0
  3263. type:AHKActionSheetButtonTypeDefault
  3264. handler:^(AHKActionSheet *as) {
  3265. // close swipe
  3266. [self setEditing:NO animated:YES];
  3267. if ([CCCoreData isOffline:_metadata.fileID activeAccount:app.activeAccount]) {
  3268. [self removeOffline:_metadata];
  3269. } else {
  3270. [self addOffline:_metadata];
  3271. }
  3272. }];
  3273. }
  3274. [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
  3275. image:[UIImage imageNamed:image_actionSheetLocal]
  3276. backgroundColor:[UIColor whiteColor]
  3277. height: 50.0
  3278. type:AHKActionSheetButtonTypeDefault
  3279. handler:^(AHKActionSheet *as) {
  3280. // close swipe
  3281. [self setEditing:NO animated:YES];
  3282. [self performSelector:@selector(addLocal:) withObject:_metadata afterDelay:0.1];
  3283. }];
  3284. [actionSheet show];
  3285. }
  3286. /******************************************* TEMPLATE *******************************************/
  3287. if ([_metadata.type isEqualToString:metadataType_model]) {
  3288. iconHeader = [UIImage imageNamed:_metadata.iconName];
  3289. [actionSheet addButtonWithTitle: _metadata.fileNamePrint
  3290. image: iconHeader
  3291. backgroundColor: COLOR_NAVBAR_IOS7
  3292. height: 50.0
  3293. type: AHKActionSheetButtonTypeDisabled
  3294. handler: nil
  3295. ];
  3296. if ([_metadata.model isEqualToString:@"note"]) {
  3297. [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
  3298. image:[UIImage imageNamed:image_actionSheetRename]
  3299. backgroundColor:[UIColor whiteColor]
  3300. height: 50.0
  3301. type:AHKActionSheetButtonTypeDefault
  3302. handler:^(AHKActionSheet *as) {
  3303. // close swipe
  3304. [self setEditing:NO animated:YES];
  3305. //chiediamo il nome del file
  3306. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_rename_",nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"_cancel_",nil) otherButtonTitles:NSLocalizedString(@"_save_", nil), nil];
  3307. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  3308. alertView.tag = alertRename;
  3309. UITextField *textField = [alertView textFieldAtIndex:0];
  3310. textField.text = _metadata.fileNamePrint;
  3311. [alertView show];
  3312. }];
  3313. }
  3314. [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
  3315. image:[UIImage imageNamed:image_actionSheetMove]
  3316. backgroundColor:[UIColor whiteColor]
  3317. height: 50.0
  3318. type:AHKActionSheetButtonTypeDefault
  3319. handler:^(AHKActionSheet *as) {
  3320. // close swipe
  3321. [self setEditing:NO animated:YES];
  3322. [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
  3323. }];
  3324. [actionSheet addButtonWithTitle:titoloOffline
  3325. image:[UIImage imageNamed:image_actionSheetOffline]
  3326. backgroundColor:[UIColor whiteColor]
  3327. height: 50.0
  3328. type:AHKActionSheetButtonTypeDefault
  3329. handler:^(AHKActionSheet *as) {
  3330. // close swipe
  3331. [self setEditing:NO animated:YES];
  3332. if ([CCCoreData isOffline:_metadata.fileID activeAccount:app.activeAccount])
  3333. [self removeOffline:_metadata];
  3334. else
  3335. [self addOffline:_metadata];
  3336. }];
  3337. [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
  3338. image:[UIImage imageNamed:image_actionSheetLocal]
  3339. backgroundColor:[UIColor whiteColor]
  3340. height: 50.0
  3341. type:AHKActionSheetButtonTypeDefault
  3342. handler:^(AHKActionSheet *as) {
  3343. // close swipe
  3344. [self setEditing:NO animated:YES];
  3345. [self performSelector:@selector(addLocal:) withObject:_metadata afterDelay:0.1];
  3346. }];
  3347. [actionSheet show];
  3348. }
  3349. }
  3350. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  3351. {
  3352. return NSLocalizedString(@"_delete_", nil);
  3353. }
  3354. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  3355. {
  3356. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3357. if (metadata == nil || metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier >= 0 || metadata.sessionTaskIdentifier >= 0) return NO;
  3358. else return YES;
  3359. }
  3360. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  3361. {
  3362. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3363. if (_metadata.errorPasscode || (_metadata.cryptated && [_metadata.title length] == 0) || _metadata.sessionTaskIdentifier >= 0 || _metadata.sessionTaskIdentifier >= 0) return UITableViewCellEditingStyleNone;
  3364. else return UITableViewCellEditingStyleDelete;
  3365. }
  3366. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  3367. {
  3368. BOOL lockDirectory = NO;
  3369. // Directory locked ?
  3370. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  3371. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
  3372. if (lockDirectory && editingStyle == UITableViewCellEditingStyleDelete) {
  3373. [app messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  3374. return;
  3375. }
  3376. if (editingStyle == UITableViewCellEditingStyleDelete) {
  3377. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3378. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  3379. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  3380. style:UIAlertActionStyleDestructive
  3381. handler:^(UIAlertAction *action) {
  3382. [self performSelector:@selector(deleteFile) withObject:nil afterDelay:0.1];
  3383. }]];
  3384. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  3385. style:UIAlertActionStyleCancel
  3386. handler:^(UIAlertAction *action) {
  3387. [alertController dismissViewControllerAnimated:YES completion:nil];
  3388. }]];
  3389. alertController.popoverPresentationController.sourceView = self.view;
  3390. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  3391. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  3392. [alertController.view layoutIfNeeded];
  3393. [self presentViewController:alertController animated:YES completion:nil];
  3394. }
  3395. }
  3396. #pragma --------------------------------------------------------------------------------------------
  3397. #pragma mark - ==== Datasource ====
  3398. #pragma --------------------------------------------------------------------------------------------
  3399. - (void)clearDateReadDataSource:(NSNotification *)notification
  3400. {
  3401. _dateReadDataSource = Nil;
  3402. }
  3403. - (void)getDataSourceWithReloadTableView
  3404. {
  3405. [self getDataSourceWithReloadTableView:_localDirectoryID fileID:nil selector:nil];
  3406. }
  3407. - (void)getDataSourceWithReloadTableView:(NSString *)directoryID fileID:(NSString *)fileID selector:(NSString *)selector
  3408. {
  3409. if (app.activeAccount == nil || app.activeUrl == nil || directoryID == nil)
  3410. return;
  3411. // Reload -> Offline ?
  3412. if (fileID)
  3413. if ([CCCoreData isOffline:fileID activeAccount:app.activeAccount])
  3414. [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableOffline" object:nil];
  3415. // Reload -> Self se non siamo nella dir appropriata cercala e se è in memoria reindirizza il reload
  3416. if ([directoryID isEqualToString:_localDirectoryID] == NO || _localServerUrl == nil) {
  3417. if ([selector isEqualToString:selectorDownloadOffline]) {
  3418. [app.controlCenter reloadDatasource];
  3419. } else {
  3420. CCMain *main = [app.listMainVC objectForKey:[CCCoreData getServerUrlFromDirectoryID:directoryID activeAccount:app.activeAccount]];
  3421. if (main) {
  3422. [main getDataSourceWithReloadTableView];
  3423. } else {
  3424. [self tableViewReload];
  3425. [app.controlCenter reloadDatasource];
  3426. }
  3427. }
  3428. return;
  3429. }
  3430. [app.controlCenter reloadDatasource];
  3431. // Settaggio variabili per le ottimizzazioni
  3432. _directoryGroupBy = [CCUtility getGroupBySettings];
  3433. _directoryOrder = [CCUtility getOrderSettings];
  3434. // Controllo data lettura Data Source
  3435. NSDate *dateDateRecordDirectory = [CCCoreData getDateReadDirectoryID:_localDirectoryID activeAccount:app.activeAccount];
  3436. if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
  3437. NSLog(@"[LOG] Rebuild Data Source File : %@", _localServerUrl);
  3438. _dateReadDataSource = [NSDate date];
  3439. // Data Source
  3440. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, directoryID] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  3441. _sectionDataSource = [CCSection creataDataSourseSectionTableMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
  3442. } else {
  3443. NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _localServerUrl, _dateReadDataSource);
  3444. }
  3445. [self tableViewReload];
  3446. [self setTitleBackgroundTableView];
  3447. [app updateApplicationIconBadgeNumber];
  3448. }
  3449. - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
  3450. {
  3451. NSMutableArray *metadatas = [[NSMutableArray alloc] init];
  3452. if (selectedRows.count > 0) {
  3453. for (NSIndexPath *selectionIndex in selectedRows) {
  3454. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
  3455. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3456. [metadatas addObject:metadata];
  3457. }
  3458. }
  3459. return metadatas;
  3460. }
  3461. - (CCMetadata *)getMetadataFromSectionDataSource:(NSIndexPath *)indexPath
  3462. {
  3463. NSInteger section = indexPath.section + 1;
  3464. NSInteger row = indexPath.row + 1;
  3465. NSInteger totSections =[_sectionDataSource.sections count] ;
  3466. if ((totSections < section) || (section > totSections)) {
  3467. NSString *message = [NSString stringWithFormat:@"DEBUG [0] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section];
  3468. NSLog(@"[LOG] %@", message);
  3469. #if DEBUG
  3470. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3471. [alertView show];
  3472. #endif
  3473. return nil;
  3474. }
  3475. id valueSection = [_sectionDataSource.sections objectAtIndex:indexPath.section];
  3476. NSArray *fileIDs = [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3477. if (fileIDs) {
  3478. NSInteger totRows =[fileIDs count] ;
  3479. if ((totRows < row) || (row > totRows)) {
  3480. NSString *message = [NSString stringWithFormat:@"DEBUG [1] : error row, totRows = %lu - row = %lu [%@] [%@] [%@]", (long)totRows, (long)row, valueSection, _localDirectoryID, _localServerUrl];
  3481. NSLog(@"[LOG] %@", message);
  3482. #if DEBUG
  3483. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3484. [alertView show];
  3485. #endif
  3486. return nil;
  3487. }
  3488. } else {
  3489. NSLog(@"[LOG] DEBUG [2] : fileIDs is NIL");
  3490. #if DEBUG
  3491. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:@"DEBUG [2] : fileIDs is NIL" delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3492. [alertView show];
  3493. #endif
  3494. return nil;
  3495. }
  3496. NSString *fileID = [fileIDs objectAtIndex:indexPath.row];
  3497. return [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  3498. }
  3499. - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
  3500. {
  3501. NSInteger totSections =[_sectionDataSource.sections count] ;
  3502. if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
  3503. #if DEBUG
  3504. 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];
  3505. [alertView show];
  3506. #endif
  3507. return nil;
  3508. }
  3509. id valueSection = [_sectionDataSource.sections objectAtIndex:section];
  3510. return [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
  3511. }
  3512. #pragma --------------------------------------------------------------------------------------------
  3513. #pragma mark - ==== Table ====
  3514. #pragma --------------------------------------------------------------------------------------------
  3515. - (void)tableViewSelect:(BOOL)edit
  3516. {
  3517. // chiudiamo eventuali swipe aperti
  3518. if (edit) [self.tableView setEditing:NO animated:NO];
  3519. [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
  3520. [self.tableView setEditing:edit animated:YES];
  3521. _isSelectedMode = edit;
  3522. if (edit)
  3523. [self setUINavigationBarSelected];
  3524. else
  3525. [self setUINavigationBarDefault];
  3526. [self setTitleNOAnimation];
  3527. }
  3528. - (void)tableViewReload
  3529. {
  3530. // ricordiamoci le row selezionate
  3531. NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
  3532. [self.tableView reloadData];
  3533. for (NSIndexPath *path in indexPaths)
  3534. [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
  3535. [self setTableViewFooter];
  3536. if (self.tableView.editing)
  3537. [self setTitleNOAnimation];
  3538. }
  3539. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  3540. {
  3541. return 60;
  3542. }
  3543. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  3544. {
  3545. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  3546. }
  3547. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  3548. {
  3549. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  3550. }
  3551. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  3552. {
  3553. NSArray *sections = [_sectionDataSource.sectionArrayRow allKeys];
  3554. NSString *sectionTitle = [sections objectAtIndex:section];
  3555. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
  3556. if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
  3557. if ([_directoryGroupBy isEqualToString:@"none"] && [sections count] <= 1) return 0.f;
  3558. return 20.f;
  3559. }
  3560. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3561. {
  3562. float shift;
  3563. UIVisualEffectView *visualEffectView;
  3564. // Titolo
  3565. NSString *titleSection;
  3566. // Controllo
  3567. if ([_sectionDataSource.sections count] == 0)
  3568. return nil;
  3569. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  3570. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  3571. if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
  3572. else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
  3573. else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  3574. else titleSection = NSLocalizedString(titleSection,nil);
  3575. // Formato titolo
  3576. NSString *currentDevice = [CCUtility currentDevice];
  3577. if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
  3578. visualEffectView = [[UIVisualEffectView alloc] init];
  3579. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR_NO_BLUR;
  3580. } else {
  3581. UIVisualEffect *blurEffect;
  3582. blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  3583. visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  3584. visualEffectView.backgroundColor = COLOR_GROUPBY_BAR;
  3585. }
  3586. if ([_directoryGroupBy isEqualToString:@"alphabetic"]) {
  3587. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) shift = - 35;
  3588. else shift = - 20;
  3589. } else shift = - 10;
  3590. // Title
  3591. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
  3592. titleLabel.backgroundColor=[UIColor clearColor];
  3593. titleLabel.textColor = COLOR_GRAY;
  3594. titleLabel.font = [UIFont systemFontOfSize:12];
  3595. titleLabel.textAlignment = NSTextAlignmentLeft;
  3596. titleLabel.text = titleSection;
  3597. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3598. [visualEffectView addSubview:titleLabel];
  3599. // Elements
  3600. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
  3601. elementLabel.backgroundColor=[UIColor clearColor];
  3602. elementLabel.textColor = COLOR_GRAY;
  3603. elementLabel.font = [UIFont systemFontOfSize:12];
  3604. elementLabel.textAlignment = NSTextAlignmentRight;
  3605. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3606. NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
  3607. NSUInteger rowsCount = [metadatas count];
  3608. if (rowsCount == 0) return nil;
  3609. if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
  3610. if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
  3611. [visualEffectView addSubview:elementLabel];
  3612. return visualEffectView;
  3613. }
  3614. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  3615. {
  3616. return [_sectionDataSource.sections indexOfObject:title];
  3617. }
  3618. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  3619. {
  3620. if ([_directoryGroupBy isEqualToString:@"alphabetic"])
  3621. return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
  3622. else
  3623. return nil;
  3624. }
  3625. /*
  3626. -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  3627. {
  3628. if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
  3629. }
  3630. }
  3631. */
  3632. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  3633. {
  3634. NSString *typeCell;
  3635. NSString *dataFile;
  3636. NSString *lunghezzaFile;
  3637. CCMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
  3638. if ([metadata.session isEqualToString:@""] || metadata.session == nil) typeCell = @"CellMain";
  3639. else typeCell = @"CellMainTransfer";
  3640. if (!metadata)
  3641. return [tableView dequeueReusableCellWithIdentifier:typeCell];
  3642. CCCellMainTransfer *cell = (CCCellMainTransfer *)[tableView dequeueReusableCellWithIdentifier:typeCell forIndexPath:indexPath];
  3643. // separator
  3644. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  3645. // change color selection
  3646. UIView *selectionColor = [[UIView alloc] init];
  3647. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  3648. cell.selectedBackgroundView = selectionColor;
  3649. if ([typeCell isEqualToString:@"CellMain"]) cell.backgroundColor = [UIColor whiteColor];
  3650. if ([typeCell isEqualToString:@"CellMainTransfer"]) cell.backgroundColor = COLOR_TRANSFER_BACKGROUND;
  3651. // ----------------------------------------------------------------------------------------------------------
  3652. // DEFAULT
  3653. // ----------------------------------------------------------------------------------------------------------
  3654. cell.fileImageView.image = nil;
  3655. cell.statusImageView.image = nil;
  3656. cell.offlineImageView.image = nil;
  3657. cell.synchronizedImageView.image = nil;
  3658. cell.sharedImageView.image = nil;
  3659. cell.labelTitle.enabled = YES;
  3660. cell.labelTitle.text = @"";
  3661. cell.labelInfoFile.enabled = YES;
  3662. cell.labelInfoFile.text = @"";
  3663. cell.progressView.progress = 0.0;
  3664. cell.progressView.hidden = YES;
  3665. cell.cancelTaskButton.hidden = YES;
  3666. cell.reloadTaskButton.hidden = YES;
  3667. cell.stopTaskButton.hidden = YES;
  3668. // colori e font
  3669. if (metadata.cryptated) {
  3670. cell.labelTitle.textColor = COLOR_ENCRYPTED;
  3671. //nameLabel.font = RalewayLight(13.0f);
  3672. cell.labelInfoFile.textColor = [UIColor blackColor];
  3673. //detailLabel.font = RalewayLight(9.0f);
  3674. } else {
  3675. cell.labelTitle.textColor = COLOR_CLEAR;
  3676. //nameLabel.font = RalewayLight(13.0f);
  3677. cell.labelInfoFile.textColor = [UIColor blackColor];
  3678. //detailLabel.font = RalewayLight(9.0f);
  3679. }
  3680. // ----------------------------------------------------------------------------------------------------------
  3681. // File Name & Folder
  3682. // ----------------------------------------------------------------------------------------------------------
  3683. // nome del file
  3684. cell.labelTitle.text = metadata.fileNamePrint;
  3685. // è una directory
  3686. if (metadata.directory) {
  3687. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3688. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  3689. lunghezzaFile = @" ";
  3690. // ----------------------------------------------------------------------------------------------------------
  3691. // Offline Folder
  3692. // ----------------------------------------------------------------------------------------------------------
  3693. NSString *offlineServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:metadata.fileNameData];
  3694. if ([CCCoreData isOfflineDirectory:offlineServerUrl activeAccount:app.activeAccount]) {
  3695. // Image Offline
  3696. if (metadata.cryptated) cell.offlineImageView.image = [UIImage imageNamed:image_offlinecrypto];
  3697. else cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  3698. // Animation synchronized gif
  3699. if ([[CCOfflineFileFolder sharedOfflineFileFolder] offlineFolderAnimationDirectory:[[NSArray alloc] initWithObjects:offlineServerUrl, nil] callViewController:NO]) {
  3700. NSURL *myURL;
  3701. if (metadata.cryptated) myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  3702. else myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  3703. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  3704. }
  3705. }
  3706. } else {
  3707. // è un file
  3708. dataFile = [CCUtility dateDiff:metadata.date];
  3709. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  3710. // Plist ancora da scaricare
  3711. if (metadata.cryptated && [metadata.title length] == 0) {
  3712. dataFile = @" ";
  3713. lunghezzaFile = @" ";
  3714. }
  3715. TableLocalFile *recordLocalFile = [CCCoreData getLocalFileWithFileID:metadata.fileID activeAccount:app.activeAccount];
  3716. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3717. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  3718. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  3719. if ([metadata.type isEqualToString:metadataType_model] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO)
  3720. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", dataFile];
  3721. if ([metadata.type isEqualToString:metadataType_file] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO) {
  3722. if (recordLocalFile && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
  3723. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", dataFile, lunghezzaFile];
  3724. else
  3725. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", dataFile, lunghezzaFile];
  3726. }
  3727. // Plist ancora da scaricare
  3728. if ([dataFile isEqualToString:@" "] && [lunghezzaFile isEqualToString:@" "])
  3729. cell.labelInfoFile.text = NSLocalizedString(@"_no_plist_pull_down_",nil);
  3730. cell.accessoryType = UITableViewCellAccessoryNone;
  3731. }
  3732. // ----------------------------------------------------------------------------------------------------------
  3733. // File Image View
  3734. // ----------------------------------------------------------------------------------------------------------
  3735. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  3736. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  3737. cell.fileImageView.image = [app.icoImagesCache objectForKey:metadata.fileID];
  3738. if (cell.fileImageView.image == nil) {
  3739. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  3740. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  3741. [app.icoImagesCache setObject:image forKey:metadata.fileID];
  3742. dispatch_async(dispatch_get_main_queue(), ^{
  3743. CCCellMainTransfer *cell = [tableView cellForRowAtIndexPath:indexPath];
  3744. if (cell)
  3745. cell.fileImageView.image = image;
  3746. });
  3747. });
  3748. }
  3749. } else {
  3750. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  3751. if (metadata.thumbnailExists)
  3752. [self downloadThumbnail:metadata];
  3753. }
  3754. // ----------------------------------------------------------------------------------------------------------
  3755. // Image Status cyptated & Lock Passcode
  3756. // ----------------------------------------------------------------------------------------------------------
  3757. // File Cyptated
  3758. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString:metadataType_model] == NO) {
  3759. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  3760. }
  3761. // Directory con passcode lock attivato
  3762. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:metadata.fileNameData];
  3763. if (metadata.directory && ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length])) cell.statusImageView.image = [UIImage imageNamed:image_passcode];
  3764. // ----------------------------------------------------------------------------------------------------------
  3765. // Offline
  3766. // ----------------------------------------------------------------------------------------------------------
  3767. if ([CCCoreData isOffline:metadata.fileID activeAccount:app.activeAccount]) {
  3768. if (metadata.cryptated) cell.offlineImageView.image = [UIImage imageNamed:image_offlinecrypto];
  3769. else cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  3770. }
  3771. // ----------------------------------------------------------------------------------------------------------
  3772. // Share
  3773. // ----------------------------------------------------------------------------------------------------------
  3774. NSString *shareLink = [app.sharesLink objectForKey:[_localServerUrl stringByAppendingString:metadata.fileName]];
  3775. NSString *shareUserAndGroup = [app.sharesUserAndGroup objectForKey:[_localServerUrl stringByAppendingString:metadata.fileName]];
  3776. BOOL isShare = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_shared].location == NSNotFound);
  3777. BOOL isMounted = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_mounted].location == NSNotFound);
  3778. // Aggiungiamo il Tap per le shared
  3779. if (isShare || [shareLink length] > 0 || [shareUserAndGroup length] > 0 || isMounted) {
  3780. if (isShare) {
  3781. cell.sharedImageView.image = [UIImage imageNamed:image_shareConnect];
  3782. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3783. [tap setNumberOfTapsRequired:1];
  3784. cell.sharedImageView.userInteractionEnabled = YES;
  3785. [cell.sharedImageView addGestureRecognizer:tap];
  3786. }
  3787. if (isMounted) {
  3788. cell.sharedImageView.image = [UIImage imageNamed:image_shareMounted];
  3789. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
  3790. [tap setNumberOfTapsRequired:1];
  3791. cell.sharedImageView.userInteractionEnabled = YES;
  3792. [cell.sharedImageView addGestureRecognizer:tap];
  3793. }
  3794. if ([shareLink length] > 0 || [shareUserAndGroup length] > 0) {
  3795. if ([shareLink length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareLink];
  3796. if ([shareUserAndGroup length] > 0) cell.sharedImageView.image = [UIImage imageNamed:image_shareUser];
  3797. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  3798. [tap setNumberOfTapsRequired:1];
  3799. cell.sharedImageView.userInteractionEnabled = YES;
  3800. [cell.sharedImageView addGestureRecognizer:tap];
  3801. }
  3802. } else {
  3803. cell.sharedImageView.userInteractionEnabled = NO;
  3804. }
  3805. // ----------------------------------------------------------------------------------------------------------
  3806. // downloadFile
  3807. // ----------------------------------------------------------------------------------------------------------
  3808. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  3809. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
  3810. else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
  3811. // sessionTaskIdentifier : RELOAD + STOP
  3812. if (metadata.sessionTaskIdentifier != taskIdentifierDone) {
  3813. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3814. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3815. cell.cancelTaskButton.hidden = NO;
  3816. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3817. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3818. cell.reloadTaskButton.hidden = NO;
  3819. }
  3820. // sessionTaskIdentifierPlist : RELOAD
  3821. if (metadata.sessionTaskIdentifierPlist != taskIdentifierDone) {
  3822. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3823. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3824. cell.reloadTaskButton.hidden = NO;
  3825. }
  3826. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3827. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3828. if (progress > 0) {
  3829. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  3830. else cell.progressView.progressTintColor = COLOR_CLEAR;
  3831. cell.progressView.progress = progress;
  3832. cell.progressView.hidden = NO;
  3833. }
  3834. // ----------------------------------------------------------------------------------------------------------
  3835. // downloadFile Error
  3836. // ----------------------------------------------------------------------------------------------------------
  3837. if (metadata.sessionTaskIdentifier == taskIdentifierError || metadata.sessionTaskIdentifierPlist == taskIdentifierError) {
  3838. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  3839. if ([metadata.sessionError length] == 0)
  3840. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  3841. else
  3842. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3843. }
  3844. }
  3845. // ----------------------------------------------------------------------------------------------------------
  3846. // uploadFile
  3847. // ----------------------------------------------------------------------------------------------------------
  3848. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  3849. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
  3850. else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
  3851. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
  3852. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
  3853. cell.cancelTaskButton.hidden = NO;
  3854. if (metadata.sessionTaskIdentifier == taskIdentifierStop) {
  3855. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  3856. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  3857. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
  3858. else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
  3859. cell.reloadTaskButton.hidden = NO;
  3860. cell.stopTaskButton.hidden = YES;
  3861. } else {
  3862. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  3863. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  3864. cell.stopTaskButton.hidden = NO;
  3865. cell.reloadTaskButton.hidden = YES;
  3866. }
  3867. // se non c'è una preview in bianconero metti l'immagine di default
  3868. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  3869. cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
  3870. cell.labelTitle.enabled = NO;
  3871. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  3872. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  3873. if (progress > 0) {
  3874. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
  3875. else cell.progressView.progressTintColor = COLOR_CLEAR;
  3876. cell.progressView.progress = progress;
  3877. cell.progressView.hidden = NO;
  3878. }
  3879. // ----------------------------------------------------------------------------------------------------------
  3880. // uploadFileError
  3881. // ----------------------------------------------------------------------------------------------------------
  3882. if (metadata.sessionTaskIdentifier == taskIdentifierError || metadata.sessionTaskIdentifierPlist == taskIdentifierError) {
  3883. cell.labelTitle.enabled = NO;
  3884. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  3885. if ([metadata.sessionError length] == 0)
  3886. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  3887. else
  3888. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  3889. }
  3890. }
  3891. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3892. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3893. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  3894. return cell;
  3895. }
  3896. - (void)setTableViewFooter
  3897. {
  3898. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3899. [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3900. UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
  3901. [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  3902. UIFont *appFont = [UIFont systemFontOfSize:12];
  3903. footerLabel.font = appFont;
  3904. footerLabel.textColor = [UIColor grayColor];
  3905. footerLabel.backgroundColor = [UIColor clearColor];
  3906. footerLabel.textAlignment = NSTextAlignmentCenter;
  3907. NSString *folders;
  3908. NSString *files;
  3909. NSString *footerText;
  3910. if (_sectionDataSource.directories > 1) {
  3911. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
  3912. } else if (_sectionDataSource.directories == 1){
  3913. folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
  3914. } else {
  3915. folders = @"";
  3916. }
  3917. if (_sectionDataSource.files > 1) {
  3918. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  3919. } else if (_sectionDataSource.files == 1){
  3920. files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
  3921. } else {
  3922. files = @"";
  3923. }
  3924. if ([folders isEqualToString:@""]) {
  3925. footerText = files;
  3926. } else if ([files isEqualToString:@""]) {
  3927. footerText = folders;
  3928. } else {
  3929. footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
  3930. }
  3931. footerLabel.text = footerText;
  3932. [footerView addSubview:footerLabel];
  3933. [self.tableView setTableFooterView:footerView];
  3934. }
  3935. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3936. {
  3937. NSString *textMessage;
  3938. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  3939. // se non può essere selezionata deseleziona
  3940. if ([cell isEditing] == NO)
  3941. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  3942. // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
  3943. if (self.tableView.editing) {
  3944. [self setTitleNOAnimation];
  3945. return;
  3946. }
  3947. // test crash
  3948. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
  3949. if (indexPath.row >= [metadatas count]) return;
  3950. // settiamo il record file.
  3951. _metadata = [self getMetadataFromSectionDataSource:indexPath];
  3952. // se è in corso una sessione
  3953. if ([_metadata.session length] > 0) return;
  3954. if (_metadata.errorPasscode) {
  3955. // se UUID è nil lo sta ancora caricando quindi esci
  3956. if (!_metadata.uuid) return;
  3957. // esiste un hint ??
  3958. CCCrypto *crypto = [[CCCrypto alloc] init];
  3959. NSString *hint = [crypto getHintFromFile:_metadata.fileName isLocal:NO directoryUser:app.directoryUser];
  3960. // qui !! la richiesta della nuova passcode
  3961. if ([_metadata.uuid isEqualToString:[CCUtility getUUID]]) {
  3962. // stesso UUID ... la password è stata modificata !!!!!!
  3963. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_same_device_different_passcode_hint_",nil), hint];
  3964. else textMessage = NSLocalizedString(@"_same_device_different_passcode_", nil);
  3965. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3966. [alertView show];
  3967. } else {
  3968. // UUID diverso.
  3969. if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_hint_",nil), _metadata.nameCurrentDevice, hint];
  3970. else textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_",nil), _metadata.nameCurrentDevice];
  3971. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  3972. [alertView show];
  3973. }
  3974. // chiediamo la passcode e ricarichiamo tutto.
  3975. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  3976. viewController.delegate = self;
  3977. viewController.fromType = CCBKPasscodeFromPasscode;
  3978. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  3979. viewController.passcodeInputView.maximumLength = 64;
  3980. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  3981. viewController.inputViewTitlePassword = NO;
  3982. viewController.title = _brand_;
  3983. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  3984. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  3985. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  3986. [self presentViewController:navigationController animated:YES completion:nil];
  3987. }
  3988. // modello o plist con il title a 0 allora è andato storto qualcosa ... ricaricalo
  3989. if (_metadata.cryptated && [_metadata.title length] == 0) {
  3990. NSString* selector;
  3991. if ([_metadata.type isEqualToString:metadataType_model]) selector = selectorLoadModelView;
  3992. else selector = selectorLoadPlist;
  3993. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:NO downloadPlist:YES selector:selector selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  3994. return;
  3995. }
  3996. // se il plist è caricato ed è un modello aprilo
  3997. if ([_metadata.type isEqualToString:metadataType_model]) [self openModel:_metadata.model isNew:false];
  3998. // file
  3999. if (_metadata.directory == NO && _metadata.errorPasscode == NO && [_metadata.type isEqualToString:metadataType_file]) {
  4000. // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
  4001. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
  4002. [self downloadFileSuccess:_metadata.fileID serverUrl:_localServerUrl selector:selectorLoadFileView selectorPost:nil];
  4003. } else {
  4004. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_localServerUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self];
  4005. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
  4006. if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  4007. }
  4008. }
  4009. if (_metadata.directory) [self performSegueDirectoryWithControlPasscode:true];
  4010. }
  4011. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  4012. {
  4013. [self setTitleNOAnimation];
  4014. }
  4015. #pragma --------------------------------------------------------------------------------------------
  4016. #pragma mark ===== Offline Folder Cell =====
  4017. #pragma --------------------------------------------------------------------------------------------
  4018. - (void)offlineFolderGraphicsServerUrl:(NSString *)serverUrl animation:(BOOL)animation
  4019. {
  4020. BOOL cryptated = NO;
  4021. CCCellMain *cell;
  4022. for (NSString* fileID in _sectionDataSource.allRecordsDataSource) {
  4023. CCMetadata *recordMetadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4024. if (recordMetadata.directory == NO)
  4025. continue;
  4026. if ([[CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:recordMetadata.fileNameData] isEqualToString:serverUrl]) {
  4027. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:recordMetadata.fileID];
  4028. cell = (CCCellMain *)[self.tableView cellForRowAtIndexPath:indexPath];
  4029. cryptated = recordMetadata.cryptated;
  4030. break;
  4031. }
  4032. }
  4033. if (!cell)
  4034. return;
  4035. if (animation) {
  4036. NSURL *myURL;
  4037. if (cryptated)
  4038. myURL = [[NSBundle mainBundle] URLForResource: @"synchronizedcrypto" withExtension:@"gif"];
  4039. else
  4040. myURL = [[NSBundle mainBundle] URLForResource: @"synchronized" withExtension:@"gif"];
  4041. cell.synchronizedImageView.image = [UIImage animatedImageWithAnimatedGIFURL:myURL];
  4042. } else {
  4043. cell.synchronizedImageView.image = nil;
  4044. }
  4045. }
  4046. #pragma --------------------------------------------------------------------------------------------
  4047. #pragma mark ===== Navigation ====
  4048. #pragma --------------------------------------------------------------------------------------------
  4049. - (BOOL)shouldPerformSegue:(NSString *)serverUrl
  4050. {
  4051. // if background return
  4052. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  4053. // se non siamo in primo piano o se non siamo nella stessa directory esci
  4054. if (self.view.window == NO || ([serverUrl isEqualToString:_localServerUrl] == NO && serverUrl))
  4055. return NO;
  4056. // Collapsed ma siamo già in detail esci
  4057. if (self.splitViewController.isCollapsed)
  4058. if (_detailViewController.isViewLoaded && _detailViewController.view.window) return NO;
  4059. // Video in esecuzione esci
  4060. if (_detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && _detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  4061. return YES;
  4062. }
  4063. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  4064. {
  4065. id viewController = segue.destinationViewController;
  4066. if ([viewController isKindOfClass:[UINavigationController class]]) {
  4067. UINavigationController *nav = viewController;
  4068. _detailViewController = (CCDetail *)nav.topViewController;
  4069. } else {
  4070. _detailViewController = segue.destinationViewController;
  4071. }
  4072. NSMutableArray *allRecordsDataSourceImagesVideos = [[NSMutableArray alloc] init];
  4073. for (NSString *fileID in _sectionDataSource.allFileID) {
  4074. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  4075. if ([metadata.typeFile isEqualToString:metadataTypeFile_image] || [metadata.typeFile isEqualToString:metadataTypeFile_video])
  4076. [allRecordsDataSourceImagesVideos addObject:metadata];
  4077. }
  4078. _detailViewController.delegate = self;
  4079. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  4080. _detailViewController.metadataDetail = _metadataSegue;
  4081. _detailViewController.dateFilterQuery = nil;
  4082. _detailViewController.isCameraUpload = NO;
  4083. _detailViewController.sourceDirectory = sorceDirectoryAccount;
  4084. [_detailViewController setTitle:_metadata.fileNamePrint];
  4085. }
  4086. // can i go to next viewcontroller
  4087. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
  4088. {
  4089. NSString *nomeDir;
  4090. if(self.tableView.editing == NO && _metadata.errorPasscode == NO){
  4091. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:_metadata.fileNameData];
  4092. // 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
  4093. if ([CCCoreData isDirectoryLock:lockServerUrl activeAccount:app.activeAccount] && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil && controlPasscode) {
  4094. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  4095. viewController.delegate = self;
  4096. viewController.fromType = CCBKPasscodeFromLockDirectory;
  4097. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  4098. viewController.inputViewTitlePassword = YES;
  4099. if ([CCUtility getSimplyBlockCode]) {
  4100. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  4101. viewController.passcodeInputView.maximumLength = 6;
  4102. } else {
  4103. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  4104. viewController.passcodeInputView.maximumLength = 64;
  4105. }
  4106. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  4107. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  4108. viewController.touchIDManager = touchIDManager;
  4109. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  4110. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  4111. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  4112. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  4113. [self presentViewController:navController animated:YES completion:nil];
  4114. return;
  4115. }
  4116. if (_metadata.cryptated) nomeDir = [_metadata.fileName substringToIndex:[_metadata.fileName length]-6];
  4117. else nomeDir = _metadata.fileName;
  4118. NSString *serverUrl = [CCUtility stringAppendServerUrl:_localServerUrl addServerUrl:nomeDir];
  4119. CCMain *viewController = [app.listMainVC objectForKey:serverUrl];
  4120. if (viewController.isViewLoaded == false) {
  4121. viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMainVC"];
  4122. viewController.isFolderEncrypted = _metadata.cryptated;
  4123. viewController.localServerUrl = serverUrl;
  4124. viewController.titleMain = _metadata.fileNamePrint;
  4125. viewController.textBackButton = _titleMain;
  4126. // save self
  4127. [app.listMainVC setObject:viewController forKey:serverUrl];
  4128. }
  4129. [self.navigationController pushViewController:viewController animated:YES];
  4130. }
  4131. }
  4132. @end