CCMain.m 265 KB

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