CCMain.m 257 KB

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