CCMain.m 260 KB

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