CCMain.m 261 KB

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