CCMain.m 263 KB

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