CCMain.m 260 KB

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