CCMain.m 261 KB

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