1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728 |
- //
- // CCMain.m
- // Crypto Cloud Technology Nextcloud
- //
- // Created by Marino Faggiana on 04/09/14.
- // Copyright (c) 2017 TWS. All rights reserved.
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- #import "CCMain.h"
- #import "AppDelegate.h"
- #import "CCPhotos.h"
- #import "CCSynchronize.h"
- #import "CCTransfersCell.h"
- #import "OCActivity.h"
- #import "OCNotifications.h"
- #import "OCNotificationsAction.h"
- #import "OCFrameworkConstants.h"
- #import "OCCapabilities.h"
- #import "CTAssetCheckmark.h"
- #import "NCAutoUpload.h"
- #import "NCBridgeSwift.h"
- @interface CCMain () <CCActionsDeleteDelegate, CCActionsRenameDelegate, CCActionsSearchDelegate, CCActionsDownloadThumbnailDelegate, CCActionsSettingFavoriteDelegate, UITextViewDelegate>
- {
- tableMetadata *_metadata;
-
- BOOL _isRoot;
- BOOL _isViewDidLoad;
- BOOL _isOfflineServerUrl;
-
- BOOL _isPickerCriptate; // if is cryptated image or video back from picker
- BOOL _isSelectedMode;
-
- NSMutableArray *_selectedMetadatas;
- NSMutableArray *_queueSelector;
- NSUInteger _numSelectedMetadatas;
- UIImageView *_ImageTitleHomeCryptoCloud;
- UIView *_reMenuBackgroundView;
- UITapGestureRecognizer *_singleFingerTap;
-
- NSString *_directoryGroupBy;
- NSString *_directoryOrder;
-
- NSUInteger _failedAttempts;
- NSDate *_lockUntilDate;
- NSString *_fatherPermission;
- UIRefreshControl *_refreshControl;
- UIDocumentInteractionController *_docController;
- CCHud *_hud;
- CCHud *_hudDeterminate;
-
- // Datasource
- CCSectionDataSourceMetadata *_sectionDataSource;
- NSDate *_dateReadDataSource;
-
- // Search
- BOOL _isSearchMode;
- NSString *_searchFileName;
- NSMutableArray *_searchResultMetadatas;
- NSString *_depth;
- NSString *_noFilesSearchTitle;
- NSString *_noFilesSearchDescription;
- NSTimer *_timerWaitInput;
- // Login
- CCLoginWeb *_loginWeb;
- CCLogin *_loginVC;
-
-
- }
- @end
- @implementation CCMain
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Init =====
- #pragma --------------------------------------------------------------------------------------------
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- if (self = [super initWithCoder:aDecoder]) {
-
- _directoryOrder = [CCUtility getOrderSettings];
- _directoryGroupBy = [CCUtility getGroupBySettings];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:@"initializeMain" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearDateReadDataSource:) name:@"clearDateReadDataSource" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitle) name:@"setTitleMain" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
- }
-
- return self;
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== View =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- // init object
- _metadata = [tableMetadata new];
- _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
- _hudDeterminate = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
- _selectedMetadatas = [NSMutableArray new];
- _queueSelector = [NSMutableArray new];
- _sectionDataSource = [CCSectionDataSourceMetadata new];
- _isViewDidLoad = YES;
- _fatherPermission = @"";
- _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
- _searchResultMetadatas = [NSMutableArray new];
- _searchFileName = @"";
- _depth = @"0";
- _noFilesSearchTitle = @"";
- _noFilesSearchDescription = @"";
-
- // delegate
- self.tableView.delegate = self;
- self.tableView.tableFooterView = [UIView new];
- self.tableView.separatorColor = [NCBrandColor sharedInstance].seperator;
- self.tableView.emptyDataSetDelegate = self;
- self.tableView.emptyDataSetSource = self;
- self.searchController.delegate = self;
- self.searchController.searchBar.delegate = self;
-
- [[CCNetworking sharedNetworking] settingDelegate:self];
-
- // Custom Cell
- [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
- [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
-
- // long press recognizer TableView
- UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressTableView:)];
- [self.tableView addGestureRecognizer:longPressRecognizer];
-
- // Pull-to-Refresh
- [self createRefreshControl];
-
- // Register for 3D Touch Previewing if available
- if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
- {
- [self registerForPreviewingWithDelegate:self sourceView:self.view];
- }
- // Back Button
- if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl]])
- self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationLogo"] style:UIBarButtonItemStylePlain target:nil action:nil];
-
- // reMenu Background
- _reMenuBackgroundView = [[UIView alloc] init];
- _reMenuBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
-
- // if this is not Main (the Main uses inizializeMain)
- if (_isRoot == NO && app.activeAccount.length > 0) {
-
- // Settings this folder & delegate & Loading datasource
- app.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
-
- // Load Datasource
- [self reloadDatasource:_serverUrl fileID:nil selector:nil];
-
- // Read Folder
- [self readFolderWithForced:NO serverUrl:_serverUrl];
- }
-
- // Title
- [self setTitle];
-
- // Search
- self.definesPresentationContext = YES;
- self.searchController.searchResultsUpdater = self;
- self.searchController.dimsBackgroundDuringPresentation = NO;
- self.tableView.tableHeaderView = self.searchController.searchBar;
- self.searchController.searchBar.barTintColor = [NCBrandColor sharedInstance].seperator;
- [self.searchController.searchBar sizeToFit];
- self.searchController.searchBar.delegate = self;
- self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_this_folder_",nil);
- if ([[NCManageDatabase sharedInstance] getServerVersion] >= 12) {
-
- if (_isRoot)
- self.searchController.searchBar.scopeButtonTitles = [NSArray arrayWithObjects:NSLocalizedString(@"_search_this_folder_",nil),NSLocalizedString(@"_search_all_folders_",nil), nil];
- else
- self.searchController.searchBar.scopeButtonTitles = [NSArray arrayWithObjects:NSLocalizedString(@"_search_this_folder_",nil),NSLocalizedString(@"_search_sub_folder_",nil), nil];
- } else {
-
- self.searchController.searchBar.scopeButtonTitles = nil;
- }
-
- // Hide Search Filed on Load
- [self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height - self.tableView.contentOffset.y)];
- }
- // Apparirà
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- // test
- if (app.activeAccount.length == 0)
- return;
-
- // Settings this folder & delegate & Loading datasource
- app.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
-
- [[CCNetworking sharedNetworking] settingDelegate:self];
-
- // Color
- [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
- [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
- if (_isSelectedMode)
- [self setUINavigationBarSelected];
- else
- [self setUINavigationBarDefault];
-
- // Plus Button
- [app plusButtonVisibile:true];
- }
- // E' arrivato
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
-
- // Active Main
- app.activeMain = self;
-
- // Test viewDidLoad
- if (_isViewDidLoad) {
-
- _isViewDidLoad = NO;
-
- } else {
-
- if (app.activeAccount.length > 0) {
-
- // Load Datasource
- [self reloadDatasource:_serverUrl fileID:nil selector:nil];
-
- // Read Folder
- [self readFolderWithForced:NO serverUrl:_serverUrl];
- }
- }
- // Title
- [self setTitle];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
-
- [self closeAllMenu];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (BOOL)prefersStatusBarHidden
- {
- return NO;
- }
- // detect scroll for remove keyboard in search mode
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- if (_isSearchMode && scrollView == self.tableView) {
-
- [self.searchController.searchBar endEditing:YES];
- }
- }
- - (void)changeTheming
- {
- if (self.isViewLoaded && self.view.window)
- [app changeTheming:self];
-
- // Refresh control
- _refreshControl.tintColor = [NCBrandColor sharedInstance].brand;
-
- // Reload Table View
- [self tableViewReload];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Initizlize Mail =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)initializeMain:(NSNotification *)notification
- {
- _directoryGroupBy = nil;
- _directoryOrder = nil;
- _dateReadDataSource = nil;
-
- // test
- if (app.activeAccount.length == 0)
- return;
-
- if ([app.listMainVC count] == 0 || _isRoot) {
-
- // This is Root
- _isRoot = YES;
-
- // Crypto Mode
- if ([[CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]] length] == 0) {
-
- app.isCryptoCloudMode = NO;
-
- } else {
-
- app.isCryptoCloudMode = YES;
- }
-
- // go Home
- [self.navigationController popToRootViewControllerAnimated:NO];
-
- // Remove search mode
- [self cancelSearchBar];
-
- _serverUrl = [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
- _isFolderEncrypted = NO;
-
- app.directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
-
- // add list
- [app.listMainVC setObject:self forKey:_serverUrl];
-
- // setting Networking
- [[CCNetworking sharedNetworking] settingDelegate:self];
- [[CCNetworking sharedNetworking] settingAccount];
-
- // populate shared Link & User variable
-
- NSArray *results = [[NCManageDatabase sharedInstance] getShares];
- if (results) {
- app.sharesLink = results[0];
- app.sharesUserAndGroup = results[1];
- }
-
- // Setting Theming
- [app settingThemingColorBrand];
-
- // Load Datasource
- [self reloadDatasource:_serverUrl fileID:nil selector:nil];
- // Load Folder
- [self readFolderWithForced:NO serverUrl:_serverUrl];
-
- // Load photo datasorce
- if (app.activePhotos)
- [app.activePhotos reloadDatasourceForced];
-
- // remove all of detail
- if (app.activeDetail)
- [app.activeDetail removeAllView];
-
- // remove all Notification Messages
- [app.listOfNotifications removeAllObjects];
-
- // home main
- app.homeMain = self;
-
- // Initializations
- [app applicationInitialized];
-
- } else {
-
- // reload datasource
- [self reloadDatasource:_serverUrl fileID:nil selector:nil];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== DZNEmptyDataSetSource ====
- #pragma --------------------------------------------------------------------------------------------
- /*
- - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
- {
- if(_isSearchMode)
- return NO;
- else
- return YES;
- }
- */
- - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
- {
- return YES;
- }
- - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
- {
- return [UIColor whiteColor];
- }
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
- {
- if (_isSearchMode)
- return [UIImage imageNamed:@"searchBig"];
- else
- return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"filesNoFiles"] color:[NCBrandColor sharedInstance].brand];
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text;
-
- if (_isSearchMode)
- text = _noFilesSearchTitle;
- else
- text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_files_no_files_", nil)];
-
- NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text;
-
- if (_isSearchMode)
- text = _noFilesSearchDescription;
- else
- text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_no_file_pull_down_", nil)];
-
- NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
- paragraph.lineBreakMode = NSLineBreakByWordWrapping;
- paragraph.alignment = NSTextAlignmentCenter;
-
- NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Text Field =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)minCharTextFieldDidChange:(UITextField *)sender
- {
- UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
-
- if (alertController)
- {
- UITextField *fileName = alertController.textFields.firstObject;
- UIAlertAction *okAction = alertController.actions.lastObject;
- okAction.enabled = fileName.text.length > 0;
- }
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField{
- [textField selectAll:textField];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Graphic Window =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)createRefreshControl
- {
- _refreshControl = [UIRefreshControl new];
- _refreshControl.tintColor = [NCBrandColor sharedInstance].brand;
- _refreshControl.backgroundColor = [UIColor colorWithRed:235.0/255.0 green:235.0/255.0 blue:235.0/255.0 alpha:1.0];
- [_refreshControl addTarget:self action:@selector(refreshControlTarget) forControlEvents:UIControlEventValueChanged];
- [self setRefreshControl:_refreshControl];
- }
- - (void)deleteRefreshControl
- {
- [_refreshControl endRefreshing];
- self.refreshControl = nil;
- }
- - (void)refreshControlTarget
- {
- [self readFolderWithForced:YES serverUrl:_serverUrl];
-
- // Actuate `Peek` feedback (weak boom)
- AudioServicesPlaySystemSound(1519);
-
- [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
- }
- - (void)setTitle
- {
- // Color text self.navigationItem.title
- [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
- if (_isSelectedMode) {
-
- NSUInteger totali = [_sectionDataSource.allRecordsDataSource count];
- NSUInteger selezionati = [[self.tableView indexPathsForSelectedRows] count];
-
- self.navigationItem.titleView = nil;
- self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)selezionati, (unsigned long)totali];
- } else {
-
- // we are in home : LOGO BRAND
- if ([_serverUrl isEqualToString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl]]) {
-
- self.navigationItem.title = nil;
-
- if ([app.reachability isReachable] == NO)
- _ImageTitleHomeCryptoCloud = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigationLogoOffline"]];
- else
- _ImageTitleHomeCryptoCloud = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigationLogo"]];
-
- [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
- UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuLogo)];
- [singleTap setNumberOfTapsRequired:1];
- [_ImageTitleHomeCryptoCloud addGestureRecognizer:singleTap];
-
- self.navigationItem.titleView = _ImageTitleHomeCryptoCloud;
-
- } else {
-
- self.navigationItem.title = _titleMain;
- }
- }
- }
- - (void)setUINavigationBarDefault
- {
- [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
-
- UIBarButtonItem *buttonMore, *buttonNotification;
-
- // =
- buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationControllerMenu"] style:UIBarButtonItemStylePlain target:self action:@selector(toggleReMainMenu)];
- buttonMore.enabled = true;
-
- // <
- self.navigationController.navigationBar.hidden = NO;
-
- // Notification
- if ([app.listOfNotifications count] > 0) {
-
- buttonNotification = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"notification"] style:UIBarButtonItemStylePlain target:self action:@selector(viewNotification)];
- buttonNotification.tintColor = [NCBrandColor sharedInstance].navigationBarText;
- buttonNotification.enabled = true;
- }
-
- if (buttonNotification)
- self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonNotification, nil];
- else
- self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
- self.navigationItem.leftBarButtonItem = nil;
- }
- - (void)setUINavigationBarSelected
- {
- [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:_isFolderEncrypted online:[app.reachability isReachable] hidden:NO];
-
- UIImage *icon = [UIImage imageNamed:@"navigationControllerMenu"];
- UIBarButtonItem *buttonMore = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(toggleReSelectMenu)];
- UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(cancelSelect)];
-
- self.navigationItem.leftBarButtonItem = leftButton;
- self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
- }
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
- {
- [self closeAllMenu];
-
- [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
-
- }];
-
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- }
- - (void)cancelSelect
- {
- [self tableViewSelect:NO];
- [app.reSelectMenu close];
- }
- - (void)closeAllMenu
- {
- // close Menu
- [app.reSelectMenu close];
- [app.reMainMenu close];
-
- // Close Menu Logo
- [CCMenuAccount dismissMenu];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Document Picker =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
- {
- NSLog(@"Cancelled");
- }
- - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
- {
- NSLog(@"Cancelled");
- }
- - (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
- {
- documentPicker.delegate = self;
- [self presentViewController:documentPicker animated:YES completion:nil];
- }
- - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
- {
- if (controller.documentPickerMode == UIDocumentPickerModeImport) {
-
- NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
- __block NSError *error;
-
- [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
-
- NSString *fileName = [url lastPathComponent];
- NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, fileName];
- NSData *data = [NSData dataWithContentsOfURL:newURL];
-
- if (data && error == nil) {
-
- if ([data writeToFile:fileNamePath options:NSDataWritingAtomic error:&error]) {
-
- // Upload File
- [[CCNetworking sharedNetworking] uploadFile:fileName serverUrl:_serverUrl cryptated:_isPickerCriptate onlyPlist:NO session:k_upload_session taskStatus: k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
-
- } else {
-
- [app messageNotification:@"_error_" description:error.description visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- }
-
- } else {
-
- [app messageNotification:@"_error_" description:@"_read_file_error_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- }
- }];
- }
- }
- - (void)openImportDocumentPicker
- {
- UIDocumentMenuViewController *documentProviderMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
-
- documentProviderMenu.modalPresentationStyle = UIModalPresentationFormSheet;
- documentProviderMenu.popoverPresentationController.sourceView = self.view;
- documentProviderMenu.popoverPresentationController.sourceRect = self.view.bounds;
- documentProviderMenu.delegate = self;
-
- [self presentViewController:documentProviderMenu animated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Assets Picker =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)openAssetsPickerController
- {
- CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
- checkmark.tintColor = [NCBrandColor sharedInstance].brand;
- [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeTop];
-
- UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:[CTAssetsPickerController class], nil];
- [app aspectNavigationControllerBar:navBar encrypted:NO online:YES hidden:NO];
-
- [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
- dispatch_async(dispatch_get_main_queue(), ^{
-
- // init picker
- CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];
-
- // set delegate
- picker.delegate = self;
-
- // to show selection order
- //picker.showsSelectionIndex = YES;
-
- // to present picker as a form sheet in iPad
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- picker.modalPresentationStyle = UIModalPresentationFormSheet;
-
- // present picker
- [self presentViewController:picker animated:YES completion:nil];
- });
- }];
- }
- - (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSMutableArray *)assets
- {
- [picker dismissViewControllerAnimated:YES completion:^{
-
- CreateFormUploadAssets *form = [[CreateFormUploadAssets alloc] init:_titleMain serverUrl:_serverUrl assets:assets cryptated:_isPickerCriptate session:k_upload_session];
- form.title = NSLocalizedString(@"_upload_photos_videos_", nil);
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:form];
-
- [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
-
- [self presentViewController:navigationController animated:YES completion:nil];
- }];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== UIDocumentInteractionControllerDelegate =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
- {
- // evitiamo il rimando della eventuale photo e/o video
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
- if (tableAccount.autoUpload) {
-
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeImage assetDate:[NSDate date]];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeVideo assetDate:[NSDate date]];
- }
- }
- /*
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== UnZipFile =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)unZipFile:(NSString *)fileID
- {
- [_hudDeterminate visibleHudTitle:NSLocalizedString(@"_unzip_in_progress_", nil) mode:MBProgressHUDModeDeterminate color:nil];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSString *fileZip = [NSString stringWithFormat:@"%@/%@", app.directoryUser, fileID];
-
- [SSZipArchive unzipFileAtPath:fileZip toDestination:[CCUtility getDirectoryLocal] overwrite:YES password:nil progressHandler:^(NSString *entry, unz_file_info zipInfo, long entryNumber, long total) {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- float progress = (float) entryNumber / (float)total;
- [_hudDeterminate progress:progress];
- });
-
- } completionHandler:^(NSString *path, BOOL succeeded, NSError *error) {
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [_hudDeterminate hideHud];
-
- if (succeeded) [app messageNotification:@"_info_" description:@"_file_unpacked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:0];
- else [app messageNotification:@"_error_" description:[NSString stringWithFormat:@"Error %ld", (long)error.code] visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
- });
-
- }];
- });
- }
- */
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Create New (OpenModel) =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)openModel:(NSString *)tipo isNew:(BOOL)isnew
- {
- UIViewController *viewController;
- NSString *fileName, *uuid, *fileID, *serverUrl;
-
- NSIndexPath * index = [self.tableView indexPathForSelectedRow];
- [self.tableView deselectRowAtIndexPath:index animated:NO];
-
- if (isnew) {
-
- fileName = nil;
- uuid = [CCUtility getUUID];
- fileID = nil;
- serverUrl = _serverUrl;
-
- } else {
-
- fileName = _metadata.fileName;
- uuid = _metadata.uuid;
- fileID = _metadata.fileID;
- serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
- }
-
- if ([tipo isEqualToString:@"cartadicredito"])
- viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
-
- if ([tipo isEqualToString:@"bancomat"])
- viewController = [[CCBancomat alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
-
- if ([tipo isEqualToString:@"contocorrente"])
- viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
-
- if ([tipo isEqualToString:@"accountweb"])
- viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
-
- if ([tipo isEqualToString:@"patenteguida"])
- viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
-
- if ([tipo isEqualToString:@"cartaidentita"])
- viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
-
- if ([tipo isEqualToString:@"passaporto"])
- viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
-
- if ([tipo isEqualToString:@"note"]) {
-
- viewController = [[CCNote alloc] initWithDelegate:self fileName:fileName uuid:uuid fileID:fileID isLocal:NO serverUrl:serverUrl];
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
-
- [self presentViewController:navigationController animated:YES completion:nil];
-
- } else {
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
-
- [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
-
- [self presentViewController:navigationController animated:YES completion:nil];
- }
- }
- // New folder or new photo or video
- - (void)returnCreate:(NSInteger)type
- {
- switch (type) {
-
- /* PLAIN */
- case k_returnCreateFolderPlain: {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"Cancel action");
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- UITextField *fileName = alertController.textFields.firstObject;
- [self createFolder:fileName.text autoUploadDirectory:NO];
- }];
-
- okAction.enabled = NO;
-
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- break;
- case k_returnCreateFotoVideoPlain: {
-
- _isPickerCriptate = false;
-
- [self openAssetsPickerController];
- }
- break;
- case k_returnCreateFilePlain: {
-
- _isPickerCriptate = false;
-
- [self openImportDocumentPicker];
- }
- break;
-
-
- /* ENCRYPTED */
- case k_returnCreateFolderEncrypted: {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"Cancel action");
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- UITextField *fileName = alertController.textFields.firstObject;
-
- [self createFolderEncrypted:fileName.text];
- }];
-
- okAction.enabled = NO;
-
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- break;
- case k_returnCreateFotoVideoEncrypted: {
-
- _isPickerCriptate = true;
-
- [self openAssetsPickerController];
- }
- break;
- case k_returnCreateFileEncrypted: {
-
- _isPickerCriptate = true;
-
- [self openImportDocumentPicker];
- }
- break;
-
- /* UTILITY */
- case k_returnNote:
- [self openModel:@"note" isNew:true];
- break;
- case k_returnAccountWeb:
- [self openModel:@"accountweb" isNew:true];
- break;
-
- /* BANK */
- case k_returnCartaDiCredito:
- [self openModel:@"cartadicredito" isNew:true];
- break;
- case k_returnBancomat:
- [self openModel:@"bancomat" isNew:true];
- break;
- case k_returnContoCorrente:
- [self openModel:@"contocorrente" isNew:true];
- break;
-
- /* DOCUMENT */
- case k_returnPatenteGuida:
- [self openModel:@"patenteguida" isNew:true];
- break;
- case k_returnCartaIdentita:
- [self openModel:@"cartaidentita" isNew:true];
- break;
- case k_returnPassaporto:
- [self openModel:@"passaporto" isNew:true];
- break;
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Save selected File =====
- #pragma --------------------------------------------------------------------------------------------
- -(void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
- {
- if (error)
- [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
- else
- [app messageNotification:@"_save_selected_files_" description:@"_file_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
- }
- - (void)saveSelectedFiles
- {
- NSLog(@"[LOG] Start download selected files ...");
-
- [_hud visibleHudTitle:@"" mode:MBProgressHUDModeIndeterminate color:nil];
-
- NSArray *metadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-
- for (tableMetadata *metadata in metadatas) {
-
- if (metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_file] && ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorSave selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
- }
- }
-
- [_hud hideHud];
- });
-
- [self tableViewSelect:NO];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Change Password =====
- #pragma --------------------------------------------------------------------------------------------
- - (void) loginSuccess:(NSInteger)loginType
- {
- [self readFolderWithForced:YES serverUrl:_serverUrl];
- }
- - (void)changePasswordAccount
- {
- // Brand
- if ([NCBrandOptions sharedInstance].use_login_web) {
-
- _loginWeb = [CCLoginWeb new];
- _loginWeb.delegate = self;
- _loginWeb.loginType = loginModifyPasswordUser;
-
- dispatch_async(dispatch_get_main_queue(), ^ {
- [_loginWeb presentModalWithDefaultTheme:self];
- });
-
- } else {
-
- _loginVC = [[UIStoryboard storyboardWithName:@"CCLogin" bundle:nil] instantiateViewControllerWithIdentifier:@"CCLoginNextcloud"];
- _loginVC.delegate = self;
- _loginVC.loginType = loginModifyPasswordUser;
-
- [self presentViewController:_loginVC animated:YES completion:nil];
- }
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Peek & Pop =====
- #pragma --------------------------------------------------------------------------------------------
- - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
- {
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
- tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- if (metadata.thumbnailExists && !metadata.cryptated) {
- CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
-
- if (cell) {
- previewingContext.sourceRect = cell.frame;
- CCPeekPop *vc = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
-
- vc.delegate = self;
- vc.metadata = metadata;
-
- return vc;
- }
- }
-
- return nil;
- }
- - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
- {
- NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:previewingContext.sourceRect.origin];
-
- [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== External Sites ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)getExternalSitesServerSuccess:(NSArray *)listOfExternalSites
- {
- [[NCManageDatabase sharedInstance] deleteExternalSites];
-
- for (OCExternalSites *tableExternalSites in listOfExternalSites)
- [[NCManageDatabase sharedInstance] addExternalSites:tableExternalSites];
- }
- - (void)getExternalSitesServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- NSLog(@"[LOG] No External Sites found");
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Activity ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)getActivityServerSuccess:(NSArray *)listOfActivity
- {
- [[NCManageDatabase sharedInstance] addActivityServer:listOfActivity];
-
- // Reload Activity Data Source
- [app.activeActivity reloadDatasource];
- }
- - (void)getActivityServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- NSLog(@"[LOG] No Activity found");
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Notification ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)getNotificationServerSuccess:(NSArray *)listOfNotifications
- {
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-
- // Order by date
- NSArray *sortedListOfNotifications = [listOfNotifications sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
-
- OCNotifications *notification1 = obj1, *notification2 = obj2;
-
- return [notification2.date compare: notification1.date];
-
- }];
-
- // verify if listOfNotifications is changed
- NSString *old = @"", *new = @"";
- for (OCNotifications *notification in listOfNotifications)
- new = [new stringByAppendingString:@(notification.idNotification).stringValue];
- for (OCNotifications *notification in appDelegate.listOfNotifications)
- old = [old stringByAppendingString:@(notification.idNotification).stringValue];
- if (![new isEqualToString:old]) {
-
- appDelegate.listOfNotifications = [[NSMutableArray alloc] initWithArray:sortedListOfNotifications];
-
- // reload Notification view
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"notificationReloadData" object:nil];
- }
-
- // Update NavigationBar
- if (!_isSelectedMode) {
-
- [self performSelectorOnMainThread:@selector(setUINavigationBarDefault) withObject:nil waitUntilDone:NO];
- }
- });
- }
- - (void)getNotificationServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- // Update NavigationBar
- if (!_isSelectedMode)
- [self setUINavigationBarDefault];
- }
- - (void)viewNotification
- {
- if ([app.listOfNotifications count] > 0) {
-
- CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
-
- [notificationVC setModalPresentationStyle:UIModalPresentationFormSheet];
- [self presentViewController:notificationVC animated:YES completion:nil];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== User Profile ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)getUserProfileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- if (errorCode == 401)
- [self changePasswordAccount];
- }
- - (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile
- {
- [[NCManageDatabase sharedInstance] setAccountsUserProfile:userProfile];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-
- NSString *address = [NSString stringWithFormat:@"%@/index.php/avatar/%@/128", app.activeUrl, app.activeUser];
- UIImage *avatar = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
- if (avatar)
- [UIImagePNGRepresentation(avatar) writeToFile:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser] atomically:YES];
- else
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/avatar.png", app.directoryUser] error:nil];
-
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"changeUserProfile" object:nil];
- });
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Capabilities ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)getCapabilitiesOfServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- // Change Theming color
- [app settingThemingColorBrand];
-
- if (errorCode == 401)
- [self changePasswordAccount];
- }
- - (void)getCapabilitiesOfServerSuccess:(OCCapabilities *)capabilities
- {
- // Update capabilities db
- [[NCManageDatabase sharedInstance] addCapabilities:capabilities];
-
- // ------ THEMING -----------------------------------------------------------------------
-
- // Download Theming Background & Change Theming color
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-
- if ([NCBrandOptions sharedInstance].use_themingBackground == YES) {
-
- UIImage *themingBackground = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[capabilities.themingBackground stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
- if (themingBackground)
- [UIImagePNGRepresentation(themingBackground) writeToFile:[NSString stringWithFormat:@"%@/themingBackground.png", app.directoryUser] atomically:YES];
- else
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/themingBackground.png", app.directoryUser] error:nil];
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [app settingThemingColorBrand];
- });
- });
- // ------ SEARCH ------------------------------------------------------------------------
-
- // Search bar if change version
- if ([[NCManageDatabase sharedInstance] getServerVersion] != capabilities.versionMajor) {
-
- [self cancelSearchBar];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
- if (capabilities.versionMajor >= 12) {
- if (_isRoot)
- self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_all_folders_",nil);
- else
- self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_sub_folder_",nil);
-
- self.searchController.searchBar.scopeButtonTitles = [NSArray arrayWithObjects:NSLocalizedString(@"_search_this_folder_",nil),self.searchController.searchBar.placeholder, nil];
-
- } else {
- self.searchController.searchBar.placeholder = NSLocalizedString(@"_search_this_folder_",nil);
- self.searchController.searchBar.scopeButtonTitles = nil;
- }
- _depth = @"0";
- });
- }
-
- // ------ GET SERVICE SERVER ------------------------------------------------------------
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
- // Read External Sites
- if (capabilities.isExternalSitesServerEnabled) {
-
- metadataNet.action = actionGetExternalSitesServer;
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
-
- // Read Share
- if (capabilities.isFilesSharingAPIEnabled) {
-
- [app.sharesID removeAllObjects];
- metadataNet.action = actionReadShareServer;
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
-
- // Read Notification
- metadataNet.action = actionGetNotificationServer;
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- // Read User Profile
- metadataNet.action = actionGetUserProfile;
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- // Read Activity
- metadataNet.action = actionGetActivityServer;
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Request Server Information ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)requestServerCapabilities
- {
- // test
- if (app.activeAccount.length == 0)
- return;
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionGetCapabilities;
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Middleware Ping ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)middlewarePing
- {
- // test
- if (app.activeAccount.length == 0)
- return;
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionMiddlewarePing;
- metadataNet.serverUrl = [[NCBrandOptions sharedInstance] middlewarePingUrl];
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Download Thumbnail Delegate ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
- {
- __block CCCellMain *cell;
-
- NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
-
- if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]]) {
-
- cell = [self.tableView cellForRowAtIndexPath:indexPath];
-
- cell.file.image = [app.icoImagesCache objectForKey:metadataNet.fileID];
-
- if (cell.file.image == nil) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-
- UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]];
-
- [app.icoImagesCache setObject:image forKey:metadataNet.fileID];
- });
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Download ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)downloadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
-
- // File do not exists on server, remove in local
- if (errorCode == kOCErrorServerPathNotFound || errorCode == kCFURLErrorBadServerResponse) {
-
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, fileID] error:nil];
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, fileID] error:nil];
- if (metadata.directory && serverUrl) {
-
- NSString *dirForDelete = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
-
- [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:dirForDelete];
- }
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID] clearDateReadDirectoryID:nil];
- [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
- }
-
- if ([selector isEqualToString:selectorLoadViewImage]) {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- // Updating Detail
- if (app.activeDetail)
- [app.activeDetail downloadPhotoBrowserFailure:errorCode];
-
- // Updating Photos
- if (app.activePhotos)
- [app.activePhotos downloadFileFailure:errorCode];
- });
-
- } else {
-
- if (errorCode != kCFURLErrorCancelled)
- [app messageNotification:@"_download_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
- [self reloadDatasource:serverUrl fileID:fileID selector:selector];
- }
- - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
- {
- __block tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
-
- if (metadata == nil) return;
-
- // Download
- if ([selector isEqualToString:selectorDownloadFile]) {
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
- }
-
- // Synchronized
- if ([selector isEqualToString:selectorDownloadSynchronize]) {
-
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
- }
-
- // add Favorite
- if ([selector isEqualToString:selectorAddFavorite]) {
-
- [[CCActions sharedInstance] settingFavorite:metadata favorite:YES delegate:self];
- }
-
- // encrypted file
- if ([selector isEqualToString:selectorEncryptFile]) {
- [self encryptedFile:metadata];
- }
-
- // decrypted file
- if ([selector isEqualToString:selectorDecryptFile]) {
- [self decryptedFile:metadata];
- }
-
- // open View File
- if ([selector isEqualToString:selectorLoadFileView] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
-
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
-
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_compress]) {
-
- selector = selectorOpenIn;
- //[self performSelector:@selector(unZipFile:) withObject:metadata.fileID];
-
- } else if ([metadata.typeFile isEqualToString: k_metadataTypeFile_unknown]) {
-
- selector = selectorOpenIn;
-
- } else {
-
- _metadata = metadata;
-
- if ([self shouldPerformSegue])
- [self performSegueWithIdentifier:@"segueDetail" sender:self];
- }
- }
-
- // addLocal
- if ([selector isEqualToString:selectorAddLocal]) {
-
- [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileNamePrint]];
-
- UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
- [CCGraphics saveIcoWithEtag: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]];
-
- [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:0];
-
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
- }
-
- // Open with...
- if ([selector isEqualToString:selectorOpenIn] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
-
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
-
- [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
- [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
- NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint]];
-
- _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
- _docController.delegate = self;
-
- [_docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
- }
-
- // Save to Photo Album
- if ([selector isEqualToString:selectorSave] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
-
- NSString *file = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
-
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
-
- // evitiamo il rimando photo
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeImage assetDate:[NSDate date]];
- UIImage *image = [UIImage imageWithContentsOfFile:file];
-
- if (image)
- UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
- else
- [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
- }
-
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
-
- // we avoid the cross-reference video
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDateAssetType:PHAssetMediaTypeVideo assetDate:[NSDate date]];
-
- [[NSFileManager defaultManager] linkItemAtPath:file toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
-
- if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint])) {
-
- UISaveVideoAtPathToSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint], self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
- } else {
- [app messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
- }
- }
-
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
- }
-
- // Copy File
- if ([selector isEqualToString:selectorLoadCopy]) {
-
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
-
- [self copyFileToPasteboard:metadata];
- }
-
- // download and view a template
- if ([selector isEqualToString:selectorLoadModelView]) {
-
- // se è un template aggiorniamo anche nel FileSystem
- if ([metadata.type isEqualToString: k_metadataType_template]) {
- [[NCManageDatabase sharedInstance] setLocalFileWithFileID:metadata.fileID date:metadata.date exifDate:nil exifLatitude:nil exifLongitude:nil fileName:nil fileNamePrint:metadata.fileNamePrint];
- }
-
- [self openModel:metadata.model isNew:false];
-
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
- }
-
- //download file plist
- if ([selector isEqualToString:selectorLoadPlist]) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-
- long countSelectorLoadPlist = 0;
-
- for (NSOperation *operation in [app.netQueue operations]) {
-
- if ([((OCnetworking *)operation).metadataNet.selector isEqualToString:selectorLoadPlist])
- countSelectorLoadPlist++;
- }
-
- if ((countSelectorLoadPlist == 0 || countSelectorLoadPlist % k_maxConcurrentOperation == 0) && [metadata.directoryID isEqualToString:[[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl]]) {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
- });
- }
- });
- }
-
- //selectorLoadViewImage
- if ([selector isEqualToString:selectorLoadViewImage]) {
-
- // Detail
- if (app.activeDetail)
- [app.activeDetail downloadPhotoBrowserSuccess:metadata selector:selector];
-
- // Photos
- if (app.activePhotos)
- [app.activePhotos downloadFileSuccess:metadata];
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
- }
-
- // if exists postselector call self with selectorPost
- if ([selectorPost length] > 0)
- [self downloadFileSuccess:fileID serverUrl:serverUrl selector:selectorPost selectorPost:nil];
- }
- - (void)downloadSelectedFilesFolders
- {
- NSLog(@"[LOG] Start download selected ...");
-
- [_hud visibleHudTitle:NSLocalizedString(@"_downloading_progress_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
-
- NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-
- for (tableMetadata *metadata in selectedMetadatas) {
-
- if ([metadata.type isEqualToString: k_metadataType_file]) {
-
- if (metadata.directory) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
- [[CCSynchronize sharedSynchronize] synchronizedFolder:serverUrl selector:selectorReadFolderWithDownload];
-
- } else {
-
- [[CCSynchronize sharedSynchronize] synchronizedFile:metadata selector:selectorReadFileWithDownload];
- }
- }
- }
-
- [_hud hideHud];
- });
-
- [self tableViewSelect:NO];
- }
- - (void)downloadPlist:(NSString *)directoryID serverUrl:(NSString *)serverUrl
- {
- NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND session = ''", app.activeAccount, directoryID] sorted:nil ascending:NO];
-
- for (tableMetadata *metadata in metadatas) {
-
- if ([CCUtility isCryptoPlistString:metadata.fileName] && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName]] == NO && [metadata.session length] == 0) {
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionDownloadFile;
- metadataNet.downloadData = NO;
- metadataNet.downloadPlist = YES;
- metadataNet.fileID = metadata.fileID;
- metadataNet.selector = selectorLoadPlist;
- metadataNet.serverUrl = serverUrl;
- metadataNet.session = k_download_session_foreground;
- metadataNet.taskStatus = k_taskStatusResume;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- //[[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:NO downloadPlist:YES selector:selectorLoadPlist selectorPost:nil session:k_download_session_foreground taskStatus:k_taskStatusResume delegate:self];
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Upload new Photos/Videos =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- // Auto Upload
- if([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll]) {
-
- if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
-
- // ONLY BACKGROUND
- [[NCAutoUpload sharedInstance] performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUploadBackground] waitUntilDone:NO];
-
- } else {
-
- // ONLY FOREFROUND
- [[NCAutoUpload sharedInstance] performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUpload] waitUntilDone:NO];
- }
- }
-
- // Read File test do not exists
- if (errorCode == k_CCErrorFileUploadNotFound && fileID) {
-
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
-
- // reUpload
- if (metadata)
- [[CCNetworking sharedNetworking] uploadFileMetadata:metadata taskStatus:k_taskStatusResume];
- }
-
- // Print error
- else if (errorCode != kCFURLErrorCancelled && errorCode != 403) {
-
- [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
-
- [self reloadDatasource:serverUrl fileID:nil selector:selector];
- }
- - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
- {
- // Auto Upload
- if([selector isEqualToString:selectorUploadAutoUpload] || [selector isEqualToString:selectorUploadAutoUploadAll]) {
-
- if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
-
- // ONLY BACKGROUND
- [[NCAutoUpload sharedInstance] performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUploadBackground] waitUntilDone:NO];
-
- } else {
-
- // ONLY FOREFROUND
- [[NCAutoUpload sharedInstance] performSelectorOnMainThread:@selector(loadAutoUpload:) withObject:[NSNumber numberWithInt:k_maxConcurrentOperationDownloadUpload] waitUntilDone:NO];
- }
- }
-
- if ([selectorPost isEqualToString:selectorReadFolderForced] ) {
-
- [self readFolderWithForced:YES serverUrl:serverUrl];
-
- } else {
-
- [self reloadDatasource:serverUrl fileID:nil selector:selector];
- }
- }
- //
- // This procedure with performSelectorOnMainThread it's necessary after (Bridge) for use the function "Sync" in OCNetworking
- //
- - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated useSubFolder:(BOOL)useSubFolder session:(NSString *)session
- {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
- [self performSelectorOnMainThread:@selector(uploadFileAssetBridge:) withObject:@[assets, serverUrl, [NSNumber numberWithBool:cryptated], [NSNumber numberWithBool:useSubFolder], session] waitUntilDone:NO];
- });
- }
- - (void)uploadFileAssetBridge:(NSArray *)arguments
- {
- NSArray *assets = [arguments objectAtIndex:0];
- NSString *serverUrl = [arguments objectAtIndex:1];
- BOOL cryptated = [[arguments objectAtIndex:2] boolValue];
- BOOL useSubFolder = [[arguments objectAtIndex:3] boolValue];
- NSString *session = [arguments objectAtIndex:4];
-
- NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:app.activeUrl];
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
-
- // Create the folder for Photos & if request the subfolders
- if (![[NCAutoUpload sharedInstance] createFolderSubFolderAutoUploadFolderPhotos:autoUploadPath useSubFolder:useSubFolder assets:assets selector:selectorUploadFile])
- return;
-
- NSLog(@"[LOG] Asset N. %lu", (unsigned long)[assets count]);
-
- for (PHAsset *asset in assets) {
-
- NSString *fileName = [CCUtility createFileNameFromAsset:asset key: k_keyFileNameMask];
-
- NSDate *assetDate = asset.creationDate;
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
-
- // Create serverUrl if use sub folder
- if (useSubFolder) {
-
- [formatter setDateFormat:@"yyyy"];
- NSString *yearString = [formatter stringFromDate:assetDate];
-
- [formatter setDateFormat:@"MM"];
- NSString *monthString = [formatter stringFromDate:assetDate];
-
- serverUrl = [NSString stringWithFormat:@"%@/%@/%@", autoUploadPath, yearString, monthString];
- }
-
- // Check if is in upload
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND fileName = %@ AND session != ''", app.activeAccount, directoryID, fileName];
- NSArray *isRecordInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
- if ([isRecordInSessions count] > 0) {
-
- // next upload
- continue;
-
- } else {
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- if (cryptated) {
-
- metadataNet.action = actionUploadAsset;
- metadataNet.assetLocalIdentifier = asset.localIdentifier;
- metadataNet.cryptated = cryptated;
- metadataNet.fileName = fileName;
- metadataNet.priority = NSOperationQueuePriorityNormal;
- metadataNet.session = session;
- metadataNet.selector = selectorUploadFile;
- metadataNet.selectorPost = nil;
- metadataNet.serverUrl = serverUrl;
- metadataNet.taskStatus = k_taskStatusResume;
- } else {
-
- metadataNet.action = actionReadFile;
- metadataNet.assetLocalIdentifier = asset.localIdentifier;
- metadataNet.cryptated = cryptated;
- metadataNet.fileName = fileName;
- metadataNet.priority = NSOperationQueuePriorityNormal;
- metadataNet.session = session;
- metadataNet.selector = selectorReadFileUploadFile;
- metadataNet.serverUrl = serverUrl;
- }
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Read File ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- // UploadFile
- if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
-
- // File not exists
- if (errorCode == 404) {
-
- metadataNet.action = actionUploadAsset;
- metadataNet.errorCode = 0;
- metadataNet.selector = selectorUploadFile;
- metadataNet.selectorPost = nil;
- metadataNet.taskStatus = k_taskStatusResume;
-
- if ([metadataNet.session containsString:@"wwan"])
- [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
- else
- [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
-
- } else {
-
- // error ho many retry befor notification and go to on next asses
- if (metadataNet.errorRetry < 3) {
-
- // Retry read file
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- } else {
-
- // STOP check file, view message error
- [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
- }
- }
- }
- - (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(tableMetadata *)metadata
- {
- // UploadFile
- if ([metadataNet.selector isEqualToString:selectorReadFileUploadFile]) {
-
- metadataNet.action = actionUploadAsset;
- metadataNet.errorCode = 403; // File exists 403 Forbidden
- metadataNet.selector = selectorUploadFile;
- metadataNet.selectorPost = nil;
- metadataNet.taskStatus = k_taskStatusResume;
-
- if ([metadataNet.session containsString:@"wwan"])
- [app addNetworkingOperationQueue:app.netQueueUploadWWan delegate:self metadataNet:metadataNet];
- else
- [app addNetworkingOperationQueue:app.netQueueUpload delegate:self metadataNet:metadataNet];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Read Folder ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)readFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- // verify active user
- tableAccount *record = [[NCManageDatabase sharedInstance] getAccountActive];
-
- [_hud hideHud];
- [_refreshControl endRefreshing];
-
- [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
-
- if (message && [record.account isEqualToString:metadataNet.account])
- [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-
- [self reloadDatasource:metadataNet.serverUrl fileID:nil selector:metadataNet.selector];
-
- if (errorCode == 401)
- [self changePasswordAccount];
- }
- - (void)readFolderSuccess:(CCMetadataNet *)metadataNet permissions:(NSString *)permissions etag:(NSString *)etag metadatas:(NSArray *)metadatas
- {
- // verify active user
- tableAccount *record = [[NCManageDatabase sharedInstance] getAccountActive];
- if (![record.account isEqualToString:metadataNet.account])
- return;
-
- // save father e update permission
- if(!_isSearchMode)
- _fatherPermission = permissions;
-
- NSArray *recordsInSessions;
- NSMutableArray *metadatasToInsertInDB = [NSMutableArray new];
-
- if (_isSearchMode) {
-
- recordsInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND session != ''", metadataNet.account] sorted:nil ascending:NO];
-
- } else {
-
- [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:metadataNet.serverUrl serverUrlTo:nil etag:etag];
-
- [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND session = ''", metadataNet.account, metadataNet.directoryID] clearDateReadDirectoryID:metadataNet.directoryID];
-
- recordsInSessions = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND session != ''", metadataNet.account, metadataNet.directoryID] sorted:nil ascending:NO];
- [[NCManageDatabase sharedInstance] setDateReadDirectoryWithDirectoryID:metadataNet.directoryID];
- }
-
- for (tableMetadata *metadata in metadatas) {
-
- // type of file
- NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
-
- // if crypto do not insert
- if (typeFilename == k_metadataTypeFilenameCrypto) continue;
-
- // verify if the record encrypted has plist + crypto
- if (typeFilename == k_metadataTypeFilenamePlist && metadata.directory == NO) {
-
- BOOL isCryptoComplete = NO;
- NSString *fileNameCrypto = [CCUtility trasformedFileNamePlistInCrypto:metadata.fileName];
-
- for (tableMetadata *completeMetadata in metadatas) {
-
- if (completeMetadata.cryptated == NO) continue;
- else if ([completeMetadata.fileName isEqualToString:fileNameCrypto]) {
- isCryptoComplete = YES;
- break;
- }
- }
- if (isCryptoComplete == NO) continue;
- }
-
- // verify if the record is in download/upload progress
- if (metadata.directory == NO && [recordsInSessions count] > 0) {
-
- tableMetadata *metadataTransfer = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND fileName = %@", app.activeAccount, metadataNet.directoryID, metadata.fileName]];
-
- // is in Download or Upload
- if ([metadataTransfer.session containsString:@"upload"] || [metadataTransfer.session containsString:@"download"]) {
- continue;
- }
- }
-
- // Insert in Array
- [metadatasToInsertInDB addObject:metadata];
- }
-
- // insert in Database
- metadatasToInsertInDB = (NSMutableArray *)[[NCManageDatabase sharedInstance] addMetadatas:metadatasToInsertInDB activeUrl:app.activeUrl serverUrl:metadataNet.serverUrl];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-
- // read plist
- if (!_isSearchMode)
- [self downloadPlist:metadataNet.directoryID serverUrl:metadataNet.serverUrl];
- // File is changed ??
- if (!_isSearchMode && metadatasToInsertInDB)
- [[CCSynchronize sharedSynchronize] verifyChangeMedatas:metadatasToInsertInDB serverUrl:metadataNet.serverUrl account:app.activeAccount withDownload:NO];
- });
-
- // Search Mode
- if (_isSearchMode)
- [self reloadDatasource:metadataNet.serverUrl fileID:nil selector:metadataNet.selector];
- // this is the same directory
- if ([metadataNet.serverUrl isEqualToString:_serverUrl] && !_isSearchMode) {
-
- // reload
- [self reloadDatasource:metadataNet.serverUrl fileID:nil selector:metadataNet.selector];
-
- // stoprefresh
- [_refreshControl endRefreshing];
-
- // Enable change user
- [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
-
- [_hud hideHud];
- }
- }
- - (void)readFolderWithForced:(BOOL)forced serverUrl:(NSString *)serverUrl
- {
- // init control
- if (!serverUrl || !app.activeAccount || app.maintenanceMode) {
-
- [_hud hideHud];
- [_refreshControl endRefreshing];
-
- return;
- }
-
- // Search Mode
- if (_isSearchMode) {
-
- if (forced) {
-
- [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrl directoryID:nil];
-
- _searchFileName = @""; // forced reload searchg
- }
-
- [self updateSearchResultsForSearchController:self.searchController];
-
- return;
- }
-
- BOOL isDirectoryOutOfDate = true;
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl = %@", serverUrl]];
-
- if (directory.dateReadDirectory) {
-
- // Is Directory Out Of Date ?
- NSDateComponents *dateComponents = [NSDateComponents new];
- [dateComponents setWeekday:k_dayForceReadFolder];
- NSCalendar *calendar = [NSCalendar currentCalendar];
-
- NSDate *datePlus = [calendar dateByAddingComponents:dateComponents toDate:directory.dateReadDirectory options:0];
- NSDate *now = [NSDate date];
-
- // usa la Cache se richiesto e se la data è entro X giorni dall'ultima volta che l'hai letta.
- if ([now compare:datePlus] == NSOrderedDescending)
- isDirectoryOutOfDate = true;
- else
- isDirectoryOutOfDate = false;
- }
-
- if (isDirectoryOutOfDate || forced) {
-
- if (_refreshControl.isRefreshing == NO)
- [_hud visibleIndeterminateHud];
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionReadFolder;
- metadataNet.date = [NSDate date];
- metadataNet.directoryID = directory.directoryID;
- metadataNet.priority = NSOperationQueuePriorityHigh;
- metadataNet.selector = selectorReadFolder;
- metadataNet.serverUrl = serverUrl;
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- }
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Search =====
- #pragma --------------------------------------------------------------------------------------------
- -(void)searchStartTimer
- {
- [[CCActions sharedInstance] search:_serverUrl fileName:_searchFileName depth:_depth date:nil selector:selectorSearch delegate:self];
- _noFilesSearchTitle = @"";
- _noFilesSearchDescription = NSLocalizedString(@"_search_in_progress_", nil);
-
- [self.tableView reloadEmptyDataSet];
- }
- -(void)updateSearchResultsForSearchController:(UISearchController *)searchController
- {
- _isSearchMode = YES;
- [self deleteRefreshControl];
-
- NSString *fileName = [CCUtility removeForbiddenCharactersServer:searchController.searchBar.text];
-
- if (fileName.length >= k_minCharsSearch && [fileName isEqualToString:_searchFileName] == NO) {
-
- _searchFileName = fileName;
-
- if ([[NCManageDatabase sharedInstance] getServerVersion] >= 12 && ![_depth isEqualToString:@"0"]) {
-
- [_timerWaitInput invalidate];
- _timerWaitInput = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(searchStartTimer) userInfo:nil repeats:NO];
-
- } else {
-
- NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"directoryID = %@ AND account = %@ AND fileNamePrint CONTAINS[cd] %@", directoryID, app.activeAccount, fileName];
- NSArray *records = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
-
- [_searchResultMetadatas removeAllObjects];
- for (tableMetadata *record in records)
- [_searchResultMetadatas addObject:record];
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.account = app.activeAccount;
- metadataNet.action = actionUploadTemplate;
- metadataNet.directoryID = directoryID;
- metadataNet.selector = selectorSearch;
- metadataNet.serverUrl = _serverUrl;
- [self readFolderSuccess:metadataNet permissions:@"" etag:@"" metadatas:_searchResultMetadatas];
- }
- }
-
- if (_searchResultMetadatas.count == 0 && fileName.length == 0) {
- [self reloadDatasource];
- }
- }
- - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
- {
- [self cancelSearchBar];
-
- [self readFolderWithForced:NO serverUrl:_serverUrl];
- }
- - (void)searchFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- _searchFileName = @"";
- if (message)
- [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
- - (void)searchSuccess:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas
- {
- _searchResultMetadatas = [[NSMutableArray alloc] initWithArray:metadatas];
-
- [self readFolderSuccess:metadataNet permissions:nil etag:nil metadatas:metadatas];
- }
- - (void)cancelSearchBar
- {
- if (self.searchController.active) {
-
- [self.searchController setActive:NO];
- [self createRefreshControl];
-
- _isSearchMode = NO;
- _searchFileName = @"";
- _dateReadDataSource = nil;
- _searchResultMetadatas = [NSMutableArray new];
-
- [self reloadDatasource];
- }
- }
- - (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
- {
- NSString *title = [self.searchController.searchBar.scopeButtonTitles objectAtIndex:selectedScope];
- self.searchController.searchBar.placeholder = title;
- if ([title isEqualToString:NSLocalizedString(@"_search_this_folder_",nil)])
- _depth = @"0";
-
- if ([title isEqualToString:NSLocalizedString(@"_search_sub_folder_",nil)])
- _depth = @"1";
-
- if ([title isEqualToString:NSLocalizedString(@"_search_all_folders_",nil)])
- _depth = @"infinity";
-
- _searchFileName = @"";
- [self updateSearchResultsForSearchController:self.searchController];
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Delete File or Folder =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- [self deleteFileOrFolderSuccess:metadataNet];
- }
- - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
- {
- [_queueSelector removeObject:metadataNet.selector];
-
- if ([_queueSelector count] == 0) {
-
- [_hud hideHud];
-
- if (_isSearchMode)
- [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
- else
- [self reloadDatasource:metadataNet.serverUrl fileID:metadataNet.fileID selector:metadataNet.selector];
-
- // next
- if ([_selectedMetadatas count] > 0) {
-
- [_selectedMetadatas removeObjectAtIndex:0];
-
- if ([_selectedMetadatas count] > 0)
- [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
- }
- }
- }
- - (void)deleteFileOrFolder:(tableMetadata *)metadata numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
- {
- if (metadata.cryptated) {
- [_queueSelector addObject:selectorDeleteCrypto];
- [_queueSelector addObject:selectorDeletePlist];
- } else {
- [_queueSelector addObject:selectorDelete];
- }
-
- [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
-
- [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_delete_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)deleteSelectionFile
- {
- [_selectedMetadatas removeAllObjects];
- [_queueSelector removeAllObjects];
-
- _selectedMetadatas = [[NSMutableArray alloc] initWithArray: [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]]];
- _numSelectedMetadatas = [_selectedMetadatas count];
-
- if ([_selectedMetadatas count] > 0)
- [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
-
- [self tableViewSelect:NO];
- }
- - (void)deleteFile
- {
- [_selectedMetadatas removeAllObjects];
- [_queueSelector removeAllObjects];
- _numSelectedMetadatas = 1;
-
- [_selectedMetadatas addObject:_metadata];
-
- if ([_selectedMetadatas count] > 0)
- [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
-
- [self tableViewSelect:NO];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Rename / Move =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)renameSuccess:(CCMetadataNet *)metadataNet
- {
- [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
- }
- - (void)renameFile:(NSArray *)arguments
- {
- tableMetadata* metadata = [arguments objectAtIndex:0];
- NSString *fileName = [arguments objectAtIndex:1];
-
- [[CCActions sharedInstance] renameFileOrFolder:metadata fileName:fileName delegate:self];
- }
- - (void)renameNote:(NSArray *)arguments
- {
- tableMetadata* metadata = [arguments objectAtIndex:0];
- NSString *fileName = [arguments objectAtIndex:1];
-
- CCTemplates *templates = [[CCTemplates alloc] init];
-
- NSMutableDictionary *field = [[CCCrypto sharedManager] getDictionaryEncrypted:metadata.fileName uuid:metadata.uuid isLocal:NO directoryUser:app.directoryUser];
- NSString *fileNameModel = [templates salvaNote:[field objectForKey:@"note"] titolo:fileName fileName:metadata.fileName uuid:metadata.uuid];
-
- if (fileNameModel) {
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionUploadTemplate;
- metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
- metadataNet.fileNamePrint = fileName;
- metadataNet.etag = metadata.etag;
- metadataNet.serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- metadataNet.session = k_upload_session_foreground;
- metadataNet.taskStatus = k_taskStatusResume;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
- }
- - (void)renameMoveFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- if ([metadataNet.selector isEqualToString:selectorMove]) {
-
- [_hud hideHud];
-
- if (message)
- [app messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-
- [_selectedMetadatas removeAllObjects];
- [_queueSelector removeAllObjects];
- }
- }
- - (void)moveSuccess:(CCMetadataNet *)metadataNet
- {
- [_queueSelector removeObject:metadataNet.selector];
-
- if ([_queueSelector count] == 0) {
-
- [_hud hideHud];
-
- NSString *fileName = [CCUtility trasformedFileNameCryptoInPlist:metadataNet.fileName];
- NSString *directoryID = metadataNet.directoryID;
- NSString *directoryIDTo = metadataNet.directoryIDTo;
- NSString *serverUrlTo = [[NCManageDatabase sharedInstance] getServerUrl:directoryIDTo];
- // FILE -> Metadata
- if (metadataNet.directory == NO) {
-
- // move metadata
- //[CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
-
- [[NCManageDatabase sharedInstance] moveMetadataWithFileName:fileName directoryID:directoryID directoryIDTo:directoryIDTo];
- }
-
- // DIRECTORY -> Directory - CCMetadata
- if (metadataNet.directory == YES) {
-
- // delete all dir / subdir
- [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:fileName]];
-
- // move metadata
- //[CCCoreData moveMetadata:fileName directoryID:directoryID directoryIDTo:directoryIDTo activeAccount:app.activeAccount];
- [[NCManageDatabase sharedInstance] moveMetadataWithFileName:fileName directoryID:directoryID directoryIDTo:directoryIDTo];
-
- // Add new directory
- NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", serverUrlTo, fileName];
- (void)[[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:newDirectory permissions:@""];
- }
-
- // reload Datasource
- if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced] || _isSearchMode)
- [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
- else
- [self reloadDatasource];
- // Next file
- [_selectedMetadatas removeObjectAtIndex:0];
- [self performSelectorOnMainThread:@selector(moveFileOrFolder:) withObject:metadataNet.serverUrlTo waitUntilDone:NO];
- }
- }
- - (void)moveFileOrFolder:(NSString *)serverUrlTo
- {
- if ([_selectedMetadatas count] > 0) {
-
- tableMetadata *metadata = [_selectedMetadatas objectAtIndex:0];
-
- // Plain
- if (metadata.cryptated == NO) {
-
- OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:app.activeUser withPassword:app.activePassword withUrl:app.activeUrl isCryptoCloudMode:NO];
-
- NSError *error = [ocNetworking readFileSync:[NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName]];
-
- if(!error) {
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-
- UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
- }];
- [alert addAction:ok];
- [self presentViewController:alert animated:YES completion:nil];
- });
-
- return;
- }
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionMoveFileOrFolder;
- metadataNet.directory = metadata.directory;
- metadataNet.fileID = metadata.fileID;
- metadataNet.directoryID = metadata.directoryID;
- metadataNet.directoryIDTo = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlTo];
- metadataNet.fileName = metadata.fileName;
- metadataNet.fileNamePrint = metadataNet.fileNamePrint;
- metadataNet.fileNameTo = metadata.fileName;
- metadataNet.etag = metadata.etag;
- metadataNet.selector = selectorMove;
- metadataNet.serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- metadataNet.serverUrlTo = serverUrlTo;
-
- [_queueSelector addObject:metadataNet.selector];
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
-
- // cyptated
- if (metadata.cryptated == YES) {
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionMoveFileOrFolder;
- metadataNet.directory = metadata.directory;
- metadataNet.fileID = metadata.fileID;
- metadataNet.directoryID = metadata.directoryID;
- metadataNet.directoryIDTo = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlTo];
- metadataNet.fileNamePrint = metadata.fileNamePrint;
- metadataNet.etag = metadata.etag;
- metadataNet.serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- metadataNet.serverUrlTo = serverUrlTo;
-
- // data
- metadataNet.fileName = metadata.fileNameData;
- metadataNet.fileNameTo = metadata.fileNameData;
- metadataNet.selector = selectorMoveCrypto;
-
- [_queueSelector addObject:metadataNet.selector];
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- // plist
- metadataNet.fileName = metadata.fileName;
- metadataNet.fileNameTo = metadata.fileName;
- metadataNet.selector = selectorMovePlist;
-
- [_queueSelector addObject:metadataNet.selector];
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
-
- [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), _numSelectedMetadatas - [_selectedMetadatas count] + 1, _numSelectedMetadatas] mode:MBProgressHUDModeIndeterminate color:nil];
- }
- }
- - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
- {
- [_selectedMetadatas removeAllObjects];
- [_queueSelector removeAllObjects];
-
- _selectedMetadatas = [[NSMutableArray alloc] initWithArray:selectedMetadatas];
- _numSelectedMetadatas = [_selectedMetadatas count];
-
- [self performSelectorOnMainThread:@selector(moveFileOrFolder:) withObject:serverUrlTo waitUntilDone:NO];
- [self tableViewSelect:NO];
- }
- - (void)moveOpenWindow:(NSArray *)indexPaths
- {
- UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
-
- CCMove *viewController = (CCMove *)navigationController.topViewController;
- viewController.delegate = self;
- viewController.move.title = NSLocalizedString(@"_move_", nil);
- viewController.selectedMetadatas = [self getMetadatasFromSelectedRows:indexPaths];
- viewController.tintColor = [NCBrandColor sharedInstance].navigationBarText;
- viewController.barTintColor = [NCBrandColor sharedInstance].brand;
- viewController.tintColorTitle = [NCBrandColor sharedInstance].navigationBarText;
- viewController.networkingOperationQueue = app.netQueue;
-
- [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
- [self presentViewController:navigationController animated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Create folder =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)createFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- [_hud hideHud];
-
- if (message)
- [app messageNotification:@"_create_folder_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
- - (void)createFolderSuccess:(CCMetadataNet *)metadataNet
- {
- [_hud hideHud];
-
- NSString *newDirectory = [NSString stringWithFormat:@"%@/%@", metadataNet.serverUrl, metadataNet.fileName];
- (void)[[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:newDirectory permissions:@""];
-
- // Load Folder or the Datasource
- if ([metadataNet.selectorPost isEqualToString:selectorReadFolderForced]) {
- [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
- } else {
- [self reloadDatasource:metadataNet.serverUrl fileID:metadataNet.fileID selector:metadataNet.selector];
- }
- }
- - (void)createFolder:(NSString *)fileNameFolder autoUploadDirectory:(BOOL)autoUploadDirectory
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
- if (![fileNameFolder length]) return;
-
- if (autoUploadDirectory) metadataNet.serverUrl = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:app.activeUrl];
- else metadataNet.serverUrl = _serverUrl;
-
- metadataNet.action = actionCreateFolder;
- if (autoUploadDirectory)
- metadataNet.options = @"folderAutoUpload";
- metadataNet.fileName = fileNameFolder;
- metadataNet.selector = selectorCreateFolder;
- metadataNet.selectorPost = selectorReadFolderForced;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- if (!autoUploadDirectory)
- [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)createFolderEncrypted:(NSString *)fileNameFolder
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
- NSString *fileNamePlist;
-
- fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
- if (![fileNameFolder length]) return;
-
- NSString *title = [AESCrypt encrypt:fileNameFolder password:[[CCCrypto sharedManager] getKeyPasscode:[CCUtility getUUID]]];
- fileNamePlist = [[CCCrypto sharedManager] createFilenameEncryptor:fileNameFolder uuid:[CCUtility getUUID]];
-
- [[CCCrypto sharedManager] createFilePlist:[NSTemporaryDirectory() stringByAppendingString:fileNamePlist] title:title len:0 directory:true uuid:[CCUtility getUUID] nameCurrentDevice:[CCUtility getNameCurrentDevice] icon:@""];
-
- // Create folder
- metadataNet.action = actionCreateFolder;
- metadataNet.fileName = fileNamePlist;
- metadataNet.priority = NSOperationQueuePriorityVeryHigh;
- metadataNet.selector = selectorCreateFolder;
- metadataNet.serverUrl = _serverUrl;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- // upload plist file
- metadataNet.action = actionUploadOnlyPlist;
- metadataNet.fileName = [fileNamePlist stringByAppendingString:@".plist"];
- metadataNet.priority = NSOperationQueuePriorityVeryLow;
- metadataNet.selectorPost = selectorReadFolderForced;
- metadataNet.serverUrl = _serverUrl;
- metadataNet.session = k_upload_session_foreground;
- metadataNet.taskStatus = k_taskStatusResume;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleHudTitle:NSLocalizedString(@"_create_folder_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)createFolderAutoUpload
- {
- NSString *autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
- [self createFolder:autoUploadFileName autoUploadDirectory:YES];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Encrypted / Decrypted Folder =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)encyptedDecryptedFolder
- {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-
- if (_metadata.cryptated) {
-
- // DECRYPTED
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- //-------------------------- RENAME -------------------------------------------//
-
- metadataNet.action = actionMoveFileOrFolder;
- metadataNet.fileID = _metadata.fileID;
- metadataNet.fileName = _metadata.fileNameData;
- metadataNet.fileNameTo = _metadata.fileNamePrint;
- metadataNet.fileNamePrint = _metadata.fileNamePrint;
- metadataNet.priority = NSOperationQueuePriorityVeryHigh;
- metadataNet.selector = selectorRename;
- metadataNet.serverUrl = serverUrl;
- metadataNet.serverUrlTo = serverUrl;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- //-------------------------- DELETE -------------------------------------------//
-
- metadataNet.action = actionDeleteFileDirectory;
- metadataNet.fileID = _metadata.fileID;
- metadataNet.fileName = _metadata.fileName;
- metadataNet.fileNamePrint = _metadata.fileNamePrint;
- metadataNet.priority = NSOperationQueuePriorityVeryLow;
- metadataNet.selector = selectorDeletePlist;
- metadataNet.selectorPost = selectorReadFolderForced;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- } else {
-
- // ENCRYPTED
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- // Create File Plist
- NSString *fileNameCrypto = [[CCCrypto sharedManager] createFileDirectoryPlist:_metadata];
-
- //-------------------------- RENAME -------------------------------------------//
-
- metadataNet.action = actionMoveFileOrFolder;
- metadataNet.fileID = _metadata.fileID;
- metadataNet.fileName = _metadata.fileName;
- metadataNet.fileNamePrint = _metadata.fileNamePrint;
- metadataNet.fileNameTo = fileNameCrypto;
- metadataNet.priority = NSOperationQueuePriorityVeryHigh;
- metadataNet.selector = selectorRename;
- metadataNet.serverUrl = serverUrl;
- metadataNet.serverUrlTo = serverUrl;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- //-------------------------- UPLOAD -------------------------------------------//
-
- metadataNet.action = actionUploadOnlyPlist;
- metadataNet.fileName = [fileNameCrypto stringByAppendingString:@".plist"];
- metadataNet.priority = NSOperationQueuePriorityVeryLow;
- metadataNet.selectorPost = selectorReadFolderForced;
- metadataNet.serverUrl = serverUrl;
- metadataNet.session = k_upload_session_foreground;
- metadataNet.taskStatus = k_taskStatusResume;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Encrypted/Decrypted File =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)encryptedSelectedFiles
- {
- NSMutableArray *metadatas = [[NSMutableArray alloc] init];
-
- NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- for (tableMetadata *metadata in selectedMetadatas) {
- if (metadata.cryptated == NO && metadata.directory == NO)
- [metadatas addObject:metadata];
- }
-
- if ([metadatas count] > 0) {
-
- NSLog(@"[LOG] Start encrypted selected files ...");
-
- for (tableMetadata* metadata in metadatas) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorEncryptFile selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
- }
- }
-
- [self tableViewSelect:NO];
- }
- - (void)decryptedSelectedFiles
- {
- NSMutableArray *metadatas = [[NSMutableArray alloc] init];
-
- NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- for (tableMetadata *metadata in selectedMetadatas) {
- if (metadata.cryptated == YES && metadata.directory == NO && [metadata.model length] == 0)
- [metadatas addObject:metadata];
- }
-
- if ([metadatas count] > 0) {
-
- NSLog(@"[LOG] Start decrypted selected files ...");
-
- for (tableMetadata* metadata in metadatas) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorDecryptFile selectorPost:nil session:k_download_session taskStatus: k_taskStatusResume delegate:self];
- }
- }
-
- [self tableViewSelect:NO];
- }
- - (void)cmdEncryptedDecryptedFile
- {
- NSString *selector;
-
- if (_metadata.cryptated == YES) selector = selectorDecryptFile;
- if (_metadata.cryptated == NO) selector = selectorEncryptFile;
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-
- [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selector selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
- }
- - (void)encryptedFile:(tableMetadata *)metadata
- {
- NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
- NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
- [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [[CCNetworking sharedNetworking] uploadFile:metadata.fileName serverUrl:serverUrl cryptated:YES onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
- [self performSelector:@selector(reloadDatasource) withObject:nil];
- });
-
- } else {
-
- [app messageNotification:@"_encrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
- }
- }
- - (void)decryptedFile:(tableMetadata *)metadata
- {
- NSString *fileNameFrom = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
- NSString *fileNameTo = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
-
- [[NSFileManager defaultManager] copyItemAtPath:fileNameFrom toPath:fileNameTo error:nil];
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:fileNameTo]) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [[CCNetworking sharedNetworking] uploadFile:metadata.fileNamePrint serverUrl:serverUrl cryptated:NO onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
- [self performSelector:@selector(reloadDatasource) withObject:nil];
- });
-
- } else {
-
- [app messageNotification:@"_decrypted_selected_files_" description:@"_file_not_present_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Progress & Task Button =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)triggerProgressTask:(NSNotification *)notification
- {
- NSDictionary *dict = notification.userInfo;
- NSString *fileID = [dict valueForKey:@"fileID"];
- NSString *serverUrl = [dict valueForKey:@"serverUrl"];
- BOOL cryptated = [[dict valueForKey:@"cryptated"] boolValue];
- float progress = [[dict valueForKey:@"progress"] floatValue];
-
- // Check
- if (!fileID)
- return;
-
- [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
-
- if (![serverUrl isEqualToString:_serverUrl])
- return;
-
- NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
-
- if (indexPath) {
-
- CCTransfersCell *cell = (CCTransfersCell *)[self.tableView cellForRowAtIndexPath:indexPath];
-
- if (cryptated) cell.progressView.progressTintColor = [NCBrandColor sharedInstance].cryptocloud;
- else cell.progressView.progressTintColor = [UIColor blackColor];
-
- cell.progressView.hidden = NO;
- [cell.progressView setProgress:progress];
- }
-
- if (progress == 0)
- [self.navigationController cancelCCProgress];
- else
- [self.navigationController setCCProgressPercentage:progress*100 andTintColor: [NCBrandColor sharedInstance].navigationBarProgress];
- }
- - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
- {
- UITouch * touch = [[event allTouches] anyObject];
- CGPoint location = [touch locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- if (indexPath) {
-
- tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- if (metadata)
- [self reloadTaskButton:metadata];
- }
- }
- - (void)reloadTaskButton:(tableMetadata *)metadata
- {
- NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
- __block NSURLSessionTask *findTask;
-
- NSInteger sessionTaskIdentifier = metadata.sessionTaskIdentifier;
- NSInteger sessionTaskIdentifierPlist = metadata.sessionTaskIdentifierPlist;
- NSString *fileID = metadata.fileID;
-
- // DOWNLOAD
- if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
-
- [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
-
- for (NSURLSessionUploadTask *task in downloadTasks)
- if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
- findTask = task;
- [app.listChangeTask setObject:@"reloadDownload" forKey:fileID];
- [task cancel];
- }
-
- if (!findTask) {
-
- [app.listChangeTask setObject:@"reloadDownload" forKey:fileID];
- NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
- }
- }];
- }
- // UPLOAD
- if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
-
- [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
-
- for (NSURLSessionUploadTask *task in uploadTasks)
- if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
- findTask = task;
- [app.listChangeTask setObject:@"reloadUpload" forKey:fileID];
- [task cancel];
- }
-
- if (!findTask) {
-
- [app.listChangeTask setObject:@"reloadUpload" forKey:fileID];
- NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
- }
- }];
- }
- }
- - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
- {
- UITouch * touch = [[event allTouches] anyObject];
- CGPoint location = [touch locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- if (indexPath) {
-
- tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- if (metadata)
- [self cancelTaskButton:metadata reloadTable:YES];
- }
- }
- - (void)cancelTaskButton:(tableMetadata *)metadata reloadTable:(BOOL)reloadTable
- {
- NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
- __block NSURLSessionTask *findTask;
-
- NSInteger sessionTaskIdentifier = metadata.sessionTaskIdentifier;
- NSInteger sessionTaskIdentifierPlist = metadata.sessionTaskIdentifierPlist;
- NSString *fileID = metadata.fileID;
-
- // DOWNLOAD
- if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
-
- [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
-
- for (NSURLSessionTask *task in downloadTasks)
- if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
- findTask = task;
- [app.listChangeTask setObject:@"cancelDownload" forKey:fileID];
- [task cancel];
- }
-
- if (!findTask) {
-
- [app.listChangeTask setObject:@"cancelDownload" forKey:fileID];
- NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
- }
- }];
- }
- // UPLOAD
- if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
-
- [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
-
- for (NSURLSessionUploadTask *task in uploadTasks)
- if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
- findTask = task;
- [app.listChangeTask setObject:@"cancelUpload" forKey:fileID];
- [task cancel];
- }
-
- if (!findTask) {
-
- [app.listChangeTask setObject:@"cancelUpload" forKey:fileID];
- NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
- }
- }];
- }
- }
- - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
- {
- UITouch * touch = [[event allTouches] anyObject];
- CGPoint location = [touch locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- if (indexPath) {
-
- tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- if (metadata)
- [self stopTaskButton:metadata];
- }
- }
- - (void)stopTaskButton:(tableMetadata *)metadata
- {
- NSURLSession *session = [[CCNetworking sharedNetworking] getSessionfromSessionDescription:metadata.session];
- __block NSURLSessionTask *findTask;
- NSInteger sessionTaskIdentifier = metadata.sessionTaskIdentifier;
- NSInteger sessionTaskIdentifierPlist = metadata.sessionTaskIdentifierPlist;
- NSString *fileID = metadata.fileID;
-
- // UPLOAD
- if ([metadata.session length] > 0 && [metadata.session containsString:@"upload"]) {
-
- [session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
-
- for (NSURLSessionUploadTask *task in uploadTasks)
- if (task.taskIdentifier == sessionTaskIdentifier || task.taskIdentifier == sessionTaskIdentifierPlist) {
- [app.listChangeTask setObject:@"stopUpload" forKey:fileID];
- findTask = task;
- [task cancel];
- }
-
- if (!findTask) {
-
- [app.listChangeTask setObject:@"stopUpload" forKey:fileID];
- NSArray *object = [[NSArray alloc] initWithObjects:session, fileID, findTask, nil];
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_networkingSessionNotification object:object];
- }
- }];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Shared =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)readSharedSuccess:(CCMetadataNet *)metadataNet items:(NSDictionary *)items openWindow:(BOOL)openWindow
- {
- [_hud hideHud];
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- // change account ?
- tableAccount *record = [[NCManageDatabase sharedInstance] getAccountActive];
- if([record.account isEqualToString:metadataNet.account] == NO)
- return;
-
- NSArray *result = [[NCManageDatabase sharedInstance] updateShare:items activeUrl:appDelegate.activeUrl];
- if (result) {
- appDelegate.sharesLink = result[0];
- appDelegate.sharesUserAndGroup = result[1];
- }
-
- // Notify Shares View
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"SharesReloadDatasource" object:nil userInfo:nil];
-
- if (openWindow) {
-
- if (_shareOC) {
-
- [_shareOC reloadData];
-
- } else {
-
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataNet.fileID]];
-
- // Apriamo la view
- _shareOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareOC"];
-
- _shareOC.delegate = self;
- _shareOC.metadata = metadata;
- _shareOC.serverUrl = metadataNet.serverUrl;
-
- _shareOC.shareLink = [app.sharesLink objectForKey:metadata.fileID];
- _shareOC.shareUserAndGroup = [app.sharesUserAndGroup objectForKey:metadata.fileID];
-
- [_shareOC setModalPresentationStyle:UIModalPresentationFormSheet];
- [self presentViewController:_shareOC animated:YES completion:nil];
- }
- }
- [self tableViewReload];
- }
- - (void)shareFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- [_hud hideHud];
-
- [app messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- if (_shareOC)
- [_shareOC reloadData];
-
- [self tableViewReload];
-
- if (errorCode == 401)
- [self changePasswordAccount];
- }
- - (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionShare;
- metadataNet.fileID = metadata.fileID;
- metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl];
- metadataNet.fileNamePrint = metadata.fileNamePrint;
- metadataNet.password = password;
- metadataNet.selector = selectorShare;
- metadataNet.serverUrl = serverUrl;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)unShareSuccess:(CCMetadataNet *)metadataNet
- {
- [_hud hideHud];
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- // rimuoviamo la condivisione da db
- NSArray *result = [[NCManageDatabase sharedInstance] unShare:metadataNet.share fileName:metadataNet.fileName serverUrl:metadataNet.serverUrl sharesLink:appDelegate.sharesLink sharesUserAndGroup:appDelegate.sharesUserAndGroup];
-
- if (result) {
- appDelegate.sharesLink = result[0];
- appDelegate.sharesUserAndGroup = result[1];
- }
-
- if (_shareOC)
- [_shareOC reloadData];
-
- [self tableViewReload];
- }
- - (void)unShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionUnShare;
- metadataNet.fileID = metadata.fileID;
- metadataNet.fileName = metadata.fileName;
- metadataNet.fileNamePrint = metadata.fileNamePrint;
- metadataNet.selector = selectorUnshare;
- metadataNet.serverUrl = serverUrl;
- metadataNet.share = share;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionUpdateShare;
- metadataNet.fileID = metadata.fileID;
- metadataNet.expirationTime = expirationTime;
- metadataNet.password = password;
- metadataNet.selector = selectorUpdateShare;
- metadataNet.serverUrl = serverUrl;
- metadataNet.share = share;
- metadataNet.sharePermission = permission;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
- [_hud visibleHudTitle:NSLocalizedString(@"_updating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)getUserAndGroupSuccess:(CCMetadataNet *)metadataNet items:(NSArray *)items
- {
- [_hud hideHud];
-
- if (_shareOC)
- [_shareOC reloadUserAndGroup:items];
- }
- - (void)getUserAndGroupFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- [_hud hideHud];
-
- [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
- }
- - (void)getUserAndGroup:(NSString *)find
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionGetUserAndGroup;
- metadataNet.options = find;
- metadataNet.selector = selectorGetUserAndGroup;
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleIndeterminateHud];
- }
- - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission metadata:(tableMetadata *)metadata directoryID:(NSString *)directoryID serverUrl:(NSString *)serverUrl
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
- metadataNet.action = actionShareWith;
- metadataNet.fileID = metadata.fileID;
- metadataNet.directoryID = directoryID;
- metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:app.activeUrl];
- metadataNet.fileNamePrint = metadata.fileNamePrint;
- metadataNet.serverUrl = serverUrl;
- metadataNet.selector = selectorShare;
- metadataNet.share = user;
- metadataNet.shareeType = shareeType;
- metadataNet.sharePermission = permission;
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleHudTitle:NSLocalizedString(@"_creating_sharing_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)openWindowShare:(tableMetadata *)metadata
- {
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionReadShareServer;
- metadataNet.fileID = metadata.fileID;
- metadataNet.fileName = metadata.fileName;
- metadataNet.fileNamePrint = metadata.fileNamePrint;
- metadataNet.selector = selectorOpenWindowShare;
- metadataNet.serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-
- [_hud visibleIndeterminateHud];
- }
- - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
- {
- CGPoint location = [tapGesture locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- if (metadata)
- [self openWindowShare:metadata];
- }
- - (void)tapActionConnectionMounted:(UITapGestureRecognizer *)tapGesture
- {
- CGPoint location = [tapGesture locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
-
- tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- if (metadata) {
-
- CCShareInfoCMOC *vc = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareInfoCMOC"];
-
- vc.metadata = metadata;
-
- [vc setModalPresentationStyle:UIModalPresentationFormSheet];
- [self presentViewController:vc animated:YES completion:nil];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Favorite =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)settingFavoriteSuccess:(CCMetadataNet *)metadataNet
- {
- _dateReadDataSource = nil;
-
- [[NCManageDatabase sharedInstance] setMetadataFavoriteWithFileID:metadataNet.fileID favorite:[metadataNet.options boolValue]];
-
- if (_isSearchMode)
- [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
- else
- [self reloadDatasource:metadataNet.serverUrl fileID:metadataNet.fileID selector:metadataNet.selector];
-
-
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadataNet.fileID]];
-
- if (metadata.directory && metadata.favorite) {
-
- NSString *dir = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addFileName:metadata.fileNameData];
-
- [app.activeFavorites addFavoriteFolder:dir];
- }
- }
- - (void)settingFavoriteFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- }
- - (void)addFavorite:(tableMetadata *)metadata
- {
- if (metadata.directory) {
-
- [[CCActions sharedInstance] settingFavorite:metadata favorite:YES delegate:self];
-
- } else {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddFavorite selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
- }
- }
- - (void)removeFavorite:(tableMetadata *)metadata
- {
- [[CCActions sharedInstance] settingFavorite:metadata favorite:NO delegate:self];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Local =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)addLocal:(tableMetadata *)metadata
- {
- if (metadata.errorPasscode || !metadata.uuid) return;
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- if ([metadata.type isEqualToString: k_metadataType_file])
- [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddLocal selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
-
- if ([metadata.type isEqualToString: k_metadataType_template]) {
-
- [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName] toPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryLocal], metadata.fileName]];
-
- [app messageNotification:@"_add_local_" description:@"_file_saved_local_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:0];
- }
-
- NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
- if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Open in... =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)openIn:(tableMetadata *)metadata
- {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
- [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
-
- NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
- if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Remove Local File =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)removeLocalFile:(tableMetadata *)metadata
- {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-
- [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
-
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] error:nil];
-
- [self reloadDatasource:serverUrl fileID:metadata.fileID selector:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Order Table & GroupBy & DirectoryOnTop =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)orderTable:(NSString *)order
- {
- [CCUtility setOrderSettings:order];
-
- // Clear data-read of DataSource
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }
- - (void)ascendingTable:(BOOL)ascending
- {
- [CCUtility setAscendingSettings:ascending];
-
- // Clear data-read of DataSource
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }
- - (void)directoryOnTop:(BOOL)directoryOnTop
- {
- [CCUtility setDirectoryOnTop:directoryOnTop];
-
- // Clear data-read of DataSource
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }
- - (void)tableGroupBy:(NSString *)groupBy
- {
- [CCUtility setGroupBySettings:groupBy];
-
- // Clear data-read of DataSource
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"clearDateReadDataSource" object:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Menu LOGO ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)menuLogo
- {
- if (app.reSelectMenu.isOpen || app.reMainMenu.isOpen)
- return;
-
- // Brand
- if ([NCBrandOptions sharedInstance].disable_multiaccount)
- return;
-
- if ([app.netQueue operationCount] > 0 || [app.netQueueDownload operationCount] > 0 || [app.netQueueDownloadWWan operationCount] > 0 || [app.netQueueUpload operationCount] > 0 || [app.netQueueUploadWWan operationCount] > 0 || [[NCManageDatabase sharedInstance] countAutoUploadWithSession:nil] > 0) {
-
- [app messageNotification:@"_transfers_in_queue_" description:nil visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
- return;
- }
-
- NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
-
- NSMutableArray *menuArray = [NSMutableArray new];
-
- for (NSString *account in listAccount) {
-
- if ([account isEqualToString:app.activeAccount]) continue;
-
- CCMenuItem *item = [[CCMenuItem alloc] init];
-
- item.title = [account stringByTruncatingToWidth:self.view.bounds.size.width - 100 withFont:[UIFont systemFontOfSize:12.0] atEnd:YES];
- item.argument = account;
- item.image = [UIImage imageNamed:@"menuLogoUser"];
- item.target = self;
- item.action = @selector(changeDefaultAccount:);
-
- [menuArray addObject:item];
- }
-
- if ([menuArray count] == 0)
- return;
-
- OptionalConfiguration options;
- Color textColor, backgroundColor;
-
- textColor.R = 0;
- textColor.G = 0;
- textColor.B = 0;
-
- backgroundColor.R = 1;
- backgroundColor.G = 1;
- backgroundColor.B = 1;
-
- NSInteger originY = 60;
- options.arrowSize = 9;
- options.marginXSpacing = 7;
- options.marginYSpacing = 10;
- options.intervalSpacing = 20;
- options.menuCornerRadius = 6.5;
- options.maskToBackground = NO;
- options.shadowOfMenu = YES;
- options.hasSeperatorLine = YES;
- options.seperatorLineHasInsets = YES;
- options.textColor = textColor;
- options.menuBackgroundColor = backgroundColor;
-
- CGRect rect = self.view.frame;
- rect.origin.y = rect.origin.y + originY;
- rect.size.height = rect.size.height - originY;
-
- [CCMenuAccount setTitleFont:[UIFont systemFontOfSize:12.0]];
- [CCMenuAccount showMenuInView:self.navigationController.view fromRect:rect menuItems:menuArray withOptions:options];
- }
- - (void)changeDefaultAccount:(CCMenuItem *)sender
- {
- [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:NO];
-
- // STOP, erase all in queue networking
- [app cancelAllOperations];
- [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-
- tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:[sender argument]];
- if (tableAccount)
- [app settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activePassword:tableAccount.password];
-
- // go to home sweet home
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
-
- [_ImageTitleHomeCryptoCloud setUserInteractionEnabled:YES];
- });
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== ReMenu ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)createReMenuBackgroundView:(REMenu *)menu
- {
- __block CGFloat navigationBarH = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
- _reMenuBackgroundView.frame = CGRectMake(0, navigationBarH, self.view.frame.size.width, self.view.frame.size.height);
-
- [UIView animateWithDuration:0.2 animations:^{
-
- float height = (self.view.frame.size.height + navigationBarH) - (menu.menuView.frame.size.height - self.navigationController.navigationBar.frame.size.height + 3);
-
- if (height < self.tabBarController.tabBar.frame.size.height)
- height = self.tabBarController.tabBar.frame.size.height;
-
- _reMenuBackgroundView.frame = CGRectMake(0, self.view.frame.size.height + navigationBarH, self.view.frame.size.width, - height);
-
- [self.tabBarController.view addSubview:_reMenuBackgroundView];
- }];
- }
- - (void)createReMainMenu
- {
- NSString *ordinamento;
- NSString *groupBy = _directoryGroupBy;
- __block NSString *nuovoOrdinamento;
- NSString *titoloNuovo, *titoloAttuale;
- BOOL ascendente;
- __block BOOL nuovoAscendente;
- UIImage *image;
-
- // ITEM SELECT ----------------------------------------------------------------------------------------------------
-
- app.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"seleziona"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- if ([_sectionDataSource.allRecordsDataSource count] > 0) {
- [self tableViewSelect:YES];
- }
- }];
- // ITEM ORDER ----------------------------------------------------------------------------------------------------
-
- ordinamento = _directoryOrder;
- if ([ordinamento isEqualToString:@"fileName"]) {
-
- image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuOrdeyByDate"] color:[NCBrandColor sharedInstance].brand];
- titoloNuovo = NSLocalizedString(@"_order_by_date_", nil);
- titoloAttuale = NSLocalizedString(@"_current_order_name_", nil);
- nuovoOrdinamento = @"date";
- }
-
- if ([ordinamento isEqualToString:@"date"]) {
-
- image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuOrderByFileName"] color:[NCBrandColor sharedInstance].brand];
- titoloNuovo = NSLocalizedString(@"_order_by_name_", nil);
- titoloAttuale = NSLocalizedString(@"_current_order_date_", nil);
- nuovoOrdinamento = @"fileName";
- }
-
- app.ordinaItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:titoloAttuale image:image highlightedImage:nil action:^(REMenuItem *item) {
- [self orderTable:nuovoOrdinamento];
- }];
-
- // ITEM ASCENDING -----------------------------------------------------------------------------------------------------
-
- ascendente = [CCUtility getAscendingSettings];
-
- if (ascendente) {
-
- image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuOrdinamentoDiscendente"] color:[NCBrandColor sharedInstance].brand];
- titoloNuovo = NSLocalizedString(@"_sort_descending_", nil);
- titoloAttuale = NSLocalizedString(@"_current_sort_ascending_", nil);
- nuovoAscendente = false;
- }
-
- if (!ascendente) {
-
- image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuOrdinamentoAscendente"] color:[NCBrandColor sharedInstance].brand];
- titoloNuovo = NSLocalizedString(@"_sort_ascending_", nil);
- titoloAttuale = NSLocalizedString(@"_current_sort_descending_", nil);
- nuovoAscendente = true;
- }
-
- app.ascendenteItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:titoloAttuale image:image highlightedImage:nil action:^(REMenuItem *item) {
- [self ascendingTable:nuovoAscendente];
- }];
-
-
- // ITEM ALPHABETIC -----------------------------------------------------------------------------------------------------
-
- if ([groupBy isEqualToString:@"alphabetic"]) { titoloNuovo = NSLocalizedString(@"_group_alphabetic_yes_", nil); }
- else { titoloNuovo = NSLocalizedString(@"_group_alphabetic_no_", nil); }
-
- app.alphabeticItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByAlphabetic"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- if ([groupBy isEqualToString:@"alphabetic"]) [self tableGroupBy:@"none"];
- else [self tableGroupBy:@"alphabetic"];
- }];
-
- // ITEM TYPEFILE -------------------------------------------------------------------------------------------------------
-
- if ([groupBy isEqualToString:@"typefile"]) { titoloNuovo = NSLocalizedString(@"_group_typefile_yes_", nil); }
- else { titoloNuovo = NSLocalizedString(@"_group_typefile_no_", nil); }
-
- app.typefileItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByTypeFile"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- if ([groupBy isEqualToString:@"typefile"]) [self tableGroupBy:@"none"];
- else [self tableGroupBy:@"typefile"];
- }];
-
- // ITEM DATE -------------------------------------------------------------------------------------------------------
-
- if ([groupBy isEqualToString:@"date"]) { titoloNuovo = NSLocalizedString(@"_group_date_yes_", nil); }
- else { titoloNuovo = NSLocalizedString(@"_group_date_no_", nil); }
-
- app.dateItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"MenuGroupByDate"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- if ([groupBy isEqualToString:@"date"]) [self tableGroupBy:@"none"];
- else [self tableGroupBy:@"date"];
- }];
-
- // ITEM DIRECTORY ON TOP ------------------------------------------------------------------------------------------------
-
- if ([CCUtility getDirectoryOnTop]) { titoloNuovo = NSLocalizedString(@"_directory_on_top_yes_", nil); }
- else { titoloNuovo = NSLocalizedString(@"_directory_on_top_no_", nil); }
-
- app.directoryOnTopItem = [[REMenuItem alloc] initWithTitle:titoloNuovo subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"menuDirectoryOnTop"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- if ([CCUtility getDirectoryOnTop]) [self directoryOnTop:NO];
- else [self directoryOnTop:YES];
- }];
-
- // REMENU --------------------------------------------------------------------------------------------------------------
- app.reMainMenu = [[REMenu alloc] initWithItems:@[app.selezionaItem, app.ordinaItem, app.ascendenteItem, app.alphabeticItem, app.typefileItem, app.dateItem, app.directoryOnTopItem]];
-
- app.reMainMenu.imageOffset = CGSizeMake(5, -1);
-
- app.reMainMenu.separatorOffset = CGSizeMake(50.0, 0.0);
- app.reMainMenu.imageOffset = CGSizeMake(0, 0);
- app.reMainMenu.waitUntilAnimationIsComplete = NO;
-
- app.reMainMenu.separatorHeight = 0.5;
- app.reMainMenu.separatorColor = [NCBrandColor sharedInstance].seperator;
-
- app.reMainMenu.backgroundColor = [NCBrandColor sharedInstance].menuBackground;
- app.reMainMenu.textColor = [UIColor blackColor];
- app.reMainMenu.textAlignment = NSTextAlignmentLeft;
- app.reMainMenu.textShadowColor = nil;
- app.reMainMenu.textOffset = CGSizeMake(50, 0.0);
- app.reMainMenu.font = [UIFont systemFontOfSize:14.0];
-
- app.reMainMenu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
- app.reMainMenu.highlightedSeparatorColor = nil;
- app.reMainMenu.highlightedTextColor = [UIColor blackColor];
- app.reMainMenu.highlightedTextShadowColor = nil;
- app.reMainMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
-
- app.reMainMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1];
- app.reMainMenu.subtitleTextAlignment = NSTextAlignmentLeft;
- app.reMainMenu.subtitleTextShadowColor = nil;
- app.reMainMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
- app.reMainMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
- app.reMainMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
-
- app.reMainMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
- app.reMainMenu.subtitleHighlightedTextShadowColor = nil;
- app.reMainMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
-
- app.reMainMenu.borderWidth = 0.3;
- app.reMainMenu.borderColor = [UIColor lightGrayColor];
-
- app.reMainMenu.animationDuration = 0.2;
- app.reMainMenu.closeAnimationDuration = 0.2;
-
- app.reMainMenu.bounce = NO;
-
- [app.reMainMenu setClosePreparationBlock:^{
-
- // Backgroun reMenu (Gesture)
- [_reMenuBackgroundView removeFromSuperview];
- [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
- }];
- }
- - (void)toggleReMainMenu
- {
- if (app.reMainMenu.isOpen) {
-
- [app.reMainMenu close];
-
- } else {
-
- [self createReMainMenu];
- [app.reMainMenu showFromNavigationController:self.navigationController];
-
- // Backgroun reMenu & (Gesture)
- [self createReMenuBackgroundView:app.reMainMenu];
- _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
- [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
- }
- }
- - (void)createReSelectMenu
- {
- // ITEM DELETE ------------------------------------------------------------------------------------------------------
-
- app.deleteItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_delete_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"deleteSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- [self deleteSelectionFile];
- }];
-
- // ITEM MOVE ------------------------------------------------------------------------------------------------------
-
- app.moveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_move_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"moveSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- [self moveOpenWindow:[self.tableView indexPathsForSelectedRows]];
- }];
-
- if (app.isCryptoCloudMode) {
-
- // ITEM ENCRYPTED ------------------------------------------------------------------------------------------------------
-
- app.encryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_encrypted_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"encryptedSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- [self performSelector:@selector(encryptedSelectedFiles) withObject:nil];
- }];
-
- // ITEM DECRYPTED ----------------------------------------------------------------------------------------------------
-
- app.decryptItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_decrypted_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"decryptedSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- [self performSelector:@selector(decryptedSelectedFiles) withObject:nil];
- }];
- }
-
- // ITEM DOWNLOAD ----------------------------------------------------------------------------------------------------
-
- app.downloadItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_download_selected_files_folders", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"downloadSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- [self downloadSelectedFilesFolders];
- }];
-
- // ITEM SAVE IMAGE & VIDEO -------------------------------------------------------------------------------------------
-
- app.saveItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_save_selected_files_", nil) subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"saveSelectedFiles"] color:[NCBrandColor sharedInstance].brand] highlightedImage:nil action:^(REMenuItem *item) {
- [self saveSelectedFiles];
- }];
- // REMENU --------------------------------------------------------------------------------------------------------------
-
- if (app.isCryptoCloudMode) {
- app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.encryptItem, app.decryptItem, app.downloadItem, app.saveItem]];
- } else {
- app.reSelectMenu = [[REMenu alloc] initWithItems:@[app.deleteItem,app.moveItem, app.downloadItem, app.saveItem]];
- }
-
- app.reSelectMenu.imageOffset = CGSizeMake(5, -1);
-
- app.reSelectMenu.separatorOffset = CGSizeMake(50.0, 0.0);
- app.reSelectMenu.imageOffset = CGSizeMake(0, 0);
- app.reSelectMenu.waitUntilAnimationIsComplete = NO;
-
- app.reSelectMenu.separatorHeight = 0.5;
- app.reSelectMenu.separatorColor = [NCBrandColor sharedInstance].seperator;
-
- app.reSelectMenu.backgroundColor = [NCBrandColor sharedInstance].menuBackground;
- app.reSelectMenu.textColor = [UIColor blackColor];
- app.reSelectMenu.textAlignment = NSTextAlignmentLeft;
- app.reSelectMenu.textShadowColor = nil;
- app.reSelectMenu.textOffset = CGSizeMake(50, 0.0);
- app.reSelectMenu.font = [UIFont systemFontOfSize:14.0];
-
- app.reSelectMenu.highlightedBackgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
- app.reSelectMenu.highlightedSeparatorColor = nil;
- app.reSelectMenu.highlightedTextColor = [UIColor blackColor];
- app.reSelectMenu.highlightedTextShadowColor = nil;
- app.reSelectMenu.highlightedTextShadowOffset = CGSizeMake(0, 0);
-
- app.reSelectMenu.subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000];
- app.reSelectMenu.subtitleTextAlignment = NSTextAlignmentLeft;
- app.reSelectMenu.subtitleTextShadowColor = nil;
- app.reSelectMenu.subtitleTextShadowOffset = CGSizeMake(0, 0.0);
- app.reSelectMenu.subtitleTextOffset = CGSizeMake(50, 0.0);
- app.reSelectMenu.subtitleFont = [UIFont systemFontOfSize:12.0];
-
- app.reSelectMenu.subtitleHighlightedTextColor = [UIColor lightGrayColor];
- app.reSelectMenu.subtitleHighlightedTextShadowColor = nil;
- app.reSelectMenu.subtitleHighlightedTextShadowOffset = CGSizeMake(0, 0);
-
- app.reSelectMenu.borderWidth = 0.3;
- app.reSelectMenu.borderColor = [UIColor lightGrayColor];
-
- app.reSelectMenu.closeAnimationDuration = 0.2;
- app.reSelectMenu.animationDuration = 0.2;
- app.reSelectMenu.bounce = NO;
-
- [app.reSelectMenu setClosePreparationBlock:^{
-
- // Backgroun reMenu (Gesture)
- [_reMenuBackgroundView removeFromSuperview];
- [_reMenuBackgroundView removeGestureRecognizer:_singleFingerTap];
- }];
- }
- - (void)toggleReSelectMenu
- {
- if (app.reSelectMenu.isOpen) {
-
- [app.reSelectMenu close];
-
- } else {
-
- [self createReSelectMenu];
- [app.reSelectMenu showFromNavigationController:self.navigationController];
-
- // Backgroun reMenu & (Gesture)
- [self createReMenuBackgroundView:app.reSelectMenu];
- _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
- [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Long Press Recognized Table View / Menu Controller =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
- {
- if (recognizer.state == UIGestureRecognizerStateBegan) {
-
- UITableView *tableView = (UITableView*)self.view;
- CGPoint touchPoint = [recognizer locationInView:self.view];
- NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:touchPoint];
-
- if (indexPath)
- _metadata = [self getMetadataFromSectionDataSource:indexPath];
- else
- _metadata = nil;
-
- [self becomeFirstResponder];
-
- UIMenuController *menuController = [UIMenuController sharedMenuController];
-
- UIMenuItem *copyFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_file_", nil) action:@selector(copyFile:)];
- UIMenuItem *copyFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_copy_files_", nil) action:@selector(copyFiles:)];
- UIMenuItem *openinFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_open_in_", nil) action:@selector(openinFile:)];
-
- UIMenuItem *pasteFileItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_", nil) action:@selector(pasteFile:)];
- UIMenuItem *pasteFileEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_file_encrypted_", nil) action:@selector(pasteFileEncrypted:)];
-
- UIMenuItem *pasteFilesItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_", nil) action:@selector(pasteFiles:)];
- UIMenuItem *pasteFilesEncryptedItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_paste_files_encrypted_", nil) action:@selector(pasteFilesEncrypted:)];
-
- if (app.isCryptoCloudMode)
- [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, pasteFileEncryptedItem, pasteFilesEncryptedItem, nil]];
- else
- [menuController setMenuItems:[NSArray arrayWithObjects:copyFileItem, copyFilesItem, openinFileItem, pasteFileItem, pasteFilesItem, nil]];
- [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:tableView];
- [menuController setMenuVisible:YES animated:YES];
- }
- }
- - (BOOL)canBecomeFirstResponder
- {
- return YES;
- }
- - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
- {
- // For copy file, copy files, Open in ... :
- //
- // NO Directory
- // NO Error Passcode
- // NO In Session mode (download/upload)
- // NO Template
-
- if (@selector(copyFile:) == action || @selector(openinFile:) == action) {
-
- if (_isSelectedMode == NO && _metadata && !_metadata.directory && !_metadata.errorPasscode && [_metadata.session length] == 0 && ![_metadata.typeFile isEqualToString: k_metadataTypeFile_template]) {
-
- // NO Cryptated with Title lenght = 0
- if (!_metadata.cryptated || (_metadata.cryptated && _metadata.title.length > 0))
- return YES;
- }
- return NO;
- }
-
- if (@selector(copyFiles:) == action) {
-
- if (_isSelectedMode) {
-
- NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- for (tableMetadata *metadata in selectedMetadatas) {
-
- if (!metadata.directory && !metadata.errorPasscode && metadata.session.length == 0 && ![metadata.typeFile isEqualToString: k_metadataTypeFile_template]) {
-
- // NO Cryptated with Title lenght = 0
- if (!metadata.cryptated || (metadata.cryptated && metadata.title.length > 0))
- return YES;
- }
- }
- }
- return NO;
- }
- if (@selector(pasteFile:) == action || @selector(pasteFileEncrypted:) == action) {
-
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- NSArray *items = [pasteboard items];
-
- if ([items count] == 1) {
-
- // Value : (NSData) fileID
-
- NSDictionary *dic = [items objectAtIndex:0];
-
- NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
- NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
-
- tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
- NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
-
- if (directoryUser) {
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]])
- return YES;
- }
-
- return NO;
- } else return NO;
- }
-
- if (@selector(pasteFiles:) == action || @selector(pasteFilesEncrypted:) == action) {
-
- BOOL isValid = NO;
-
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- NSArray *items = [pasteboard items];
-
- if ([items count] <= 1) return NO;
-
- for (NSDictionary *dic in items) {
-
- // Value : (NSData) fileID
-
- NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
- NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
- tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
-
- NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
-
- if (directoryUser) {
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]])
- isValid = YES;
- }
- }
-
- return isValid;
- }
-
- return NO;
- }
- /************************************ COPY ************************************/
- - (void)copyFile:(id)sender
- {
- // Remove all item
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.items = [[NSArray alloc] init];
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser,_metadata.fileID]]) {
-
- [self copyFileToPasteboard:_metadata];
-
- } else {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-
- [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
- }
- }
- - (void)copyFiles:(id)sender
- {
- // Remove all item
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.items = [[NSArray alloc] init];
-
- NSArray *selectedMetadatas = [self getMetadatasFromSelectedRows:[self.tableView indexPathsForSelectedRows]];
-
- for (tableMetadata *metadata in selectedMetadatas) {
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]]) {
-
- [self copyFileToPasteboard:metadata];
-
- } else {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
- [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadCopy selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
- }
- }
-
- [self tableViewSelect:NO];
- }
- - (void)copyFileToPasteboard:(tableMetadata *)metadata
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- NSMutableArray *items = [[NSMutableArray alloc] initWithArray:pasteboard.items];
-
- // Value : (NSData) fileID
-
- NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSKeyedArchiver archivedDataWithRootObject:metadata.fileID], k_metadataKeyedUnarchiver,nil];
- [items addObject:item];
-
- [pasteboard setItems:items];
- }
- /************************************ OPEN IN ... ************************************/
- - (void)openinFile:(id)sender
- {
- [self openIn:_metadata];
- }
- /************************************ PASTE ************************************/
- - (void)pasteFile:(id)sender
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
- }
- - (void)pasteFileEncrypted:(id)sender
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
- }
- - (void)pasteFiles:(id)sender
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- [self uploadFilePasteArray:[pasteboard items] cryptated:NO];
- }
- - (void)pasteFilesEncrypted:(id)sender
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- [self uploadFilePasteArray:[pasteboard items] cryptated:YES];
- }
- - (void)uploadFilePasteArray:(NSArray *)items cryptated:(BOOL)cryptated
- {
- for (NSDictionary *dic in items) {
-
- // Value : (NSData) fileID
-
- NSData *dataFileID = [dic objectForKey: k_metadataKeyedUnarchiver];
- NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
-
- tableAccount *account = [[NCManageDatabase sharedInstance] getAccountActive];
- tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
-
- if (!metadata || !account) return;
-
- NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
-
- if (directoryUser) {
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]]) {
-
- [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint]];
-
- [[CCNetworking sharedNetworking] uploadFile:metadata.fileNamePrint serverUrl:_serverUrl cryptated:cryptated onlyPlist:NO session:k_upload_session taskStatus:k_taskStatusResume selector:nil selectorPost:nil errorCode:0 delegate:nil];
- }
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Lock Passcode =====
- #pragma --------------------------------------------------------------------------------------------
- - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
- {
- return _failedAttempts;
- }
- - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
- {
- return _lockUntilDate;
- }
- - (void)passcodeViewCloseButtonPressed:(id)sender
- {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
- {
- if (aViewController.fromType == CCBKPasscodeFromLockScreen || aViewController.fromType == CCBKPasscodeFromLockDirectory || aViewController.fromType == CCBKPasscodeFromDisactivateDirectory ) {
- if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
- _lockUntilDate = nil;
- _failedAttempts = 0;
- aResultHandler(YES);
- } else aResultHandler(NO);
- } else aResultHandler(YES);
- }
- - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
- {
- [aViewController dismissViewControllerAnimated:YES completion:nil];
-
- switch (aViewController.type) {
-
- case BKPasscodeViewControllerCheckPasscodeType: {
-
- if (aViewController.fromType == CCBKPasscodeFromPasscode) {
-
- // verifichiamo se il passcode è corretto per il seguente file -> UUID
- if ([[CCCrypto sharedManager] verifyPasscode:aPasscode uuid:_metadata.uuid text:_metadata.title]) {
-
- // scriviamo il passcode
- [CCUtility setKeyChainPasscodeForUUID:_metadata.uuid conPasscode:aPasscode];
-
- [self readFolderWithForced:YES serverUrl:_serverUrl];
-
- } else {
-
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_error_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
- }
- }
-
- if (aViewController.fromType == CCBKPasscodeFromLockDirectory) {
-
- // possiamo procedere alla prossima directory
- [self performSegueDirectoryWithControlPasscode:false];
-
- // avviamo la sessione Passcode Lock con now
- app.sessionePasscodeLock = [NSDate date];
- }
-
- // disattivazione lock cartella
- if (aViewController.fromType == CCBKPasscodeFromDisactivateDirectory) {
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
-
- if (![[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:NO]) {
-
- [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
- }
-
- [self tableViewReload];
- }
- }
- break;
- default:
- break;
- }
- }
- - (void)comandoLockPassword
- {
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
- // se non è abilitato il Lock Passcode esci
- if ([[CCUtility getBlockCode] length] == 0) {
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_warning_", nil) message:NSLocalizedString(@"_only_lock_passcode_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
- return;
- }
-
- // se è richiesta la disattivazione si chiede la password
-
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl = %@", lockServerUrl]];
- if (directory.lock) {
-
- CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
- viewController.delegate = self;
- viewController.fromType = CCBKPasscodeFromDisactivateDirectory;
- viewController.type = BKPasscodeViewControllerCheckPasscodeType;
- viewController.inputViewTitlePassword = YES;
-
- if ([CCUtility getSimplyBlockCode]) {
-
- viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 6;
-
- } else {
-
- viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 64;
- }
-
- BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
- touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
- viewController.touchIDManager = touchIDManager;
- viewController.title = NSLocalizedString(@"_passcode_protection_", nil);
- viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
- viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
-
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
- [self presentViewController:navigationController animated:YES completion:nil];
-
- return;
- }
-
- // ---------------- ACTIVATE PASSWORD
-
- if ([[NCManageDatabase sharedInstance] setDirectoryLockWithServerUrl:lockServerUrl lock:YES]) {
-
- NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
- if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
-
- } else {
-
- [app messageNotification:@"_error_" description:@"_error_operation_canc_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
- }
- }
- #pragma mark -
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Swipe Tablet -> menu =====
- #pragma --------------------------------------------------------------------------------------------
- // more
- - (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
- return NSLocalizedString(@"_more_", nil);
- }
- - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- _metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-
- NSString *titoloCriptaDecripta, *titoloLock, *titleFavorite;
-
- if (_metadata.cryptated) titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_decrypt_", nil)];
- else titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_encrypt_", nil)];
-
- if (_metadata.favorite) {
-
- titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_remove_favorites_", nil)];
- } else {
-
- titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_add_favorites_", nil)];
- }
-
- if (_metadata.directory) {
- // calcolo lockServerUrl
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl = %@", lockServerUrl]];
-
- if (directory.lock)
- titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_remove_passcode_", nil)];
- else
- titoloLock = [NSString stringWithFormat:NSLocalizedString(@"_protect_passcode_", nil)];
- }
-
- tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", _metadata.fileID]];
- /******************************************* AHKActionSheet *******************************************/
-
- AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
-
- actionSheet.animationDuration = 0.2;
-
- actionSheet.blurRadius = 0.0f;
- actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
-
- actionSheet.buttonHeight = 50.0;
- actionSheet.cancelButtonHeight = 50.0f;
- actionSheet.separatorHeight = 5.0f;
-
- actionSheet.automaticallyTintButtonImages = @(NO);
-
- actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].cryptocloud };
- actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
- actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].brand };
- actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:[UIColor blackColor] };
-
- actionSheet.separatorColor = [NCBrandColor sharedInstance].seperator;
- actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
-
- /******************************************* DIRECTORY *******************************************/
-
- if (_metadata.directory) {
-
- BOOL lockDirectory = NO;
- NSString *dirServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
- // Directory bloccata ?
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl = %@", dirServerUrl]];
- if (directory.lock && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil) lockDirectory = YES;
-
- NSString *autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
- NSString *autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:app.activeUrl];
-
- [actionSheet addButtonWithTitle: _metadata.fileNamePrint
- image: [CCGraphics changeThemingColorImage:[UIImage imageNamed:_metadata.iconName] color:[NCBrandColor sharedInstance].brand]
- backgroundColor: [NCBrandColor sharedInstance].tabBar
- height: 50.0
- type: AHKActionSheetButtonTypeDisabled
- handler: nil
- ];
- if (!lockDirectory && !_metadata.cryptated) {
-
- [actionSheet addButtonWithTitle:titleFavorite
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetFavorite"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- if (_metadata.favorite)
- [self removeFavorite:_metadata];
- else
- [self addFavorite:_metadata];
- }];
- }
- if (_metadata.cryptated == NO && !lockDirectory) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self openWindowShare:_metadata];
- }];
- }
- if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && !lockDirectory) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetRename"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.text = _metadata.fileNamePrint;
- //textField.selectedTextRange = [textField textRangeFromPosition:textField.beginningOfDocument toPosition:textField.endOfDocument];
- //textField.delegate = self;
- [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"Cancel action");
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- UITextField *fileName = alertController.textFields.firstObject;
-
- [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:_metadata,fileName.text, nil] waitUntilDone:NO];
- }];
-
- okAction.enabled = NO;
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }];
- }
-
- if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && !lockDirectory) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetMove"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
- }];
- }
-
- if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && _metadata.cryptated == NO) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_folder_automatic_upload_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folderphotocamera"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- // Settings new folder Automatatic upload
- NSString *oldAutoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:app.activeUrl];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:_metadata.fileName];
- [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:serverUrl activeUrl:app.activeUrl];
-
- [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:oldAutoUploadDirectory directoryID:nil];
-
- if (app.activeAccount.length > 0 && app.activePhotos)
- [app.activePhotos reloadDatasourceForced];
-
- [self readFolderWithForced:YES serverUrl:serverUrl];
-
- NSLog(@"[LOG] Update Folder Photo");
- NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:app.activeUrl];
- if ([autoUploadPath length] > 0)
- [[CCSynchronize sharedSynchronize] synchronizedFolder:autoUploadPath selector:selectorReadFolder];
- }];
- }
- if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES)) {
-
- [actionSheet addButtonWithTitle:titoloLock
- image:[UIImage imageNamed:@"actionSheetLock"]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeEncrypted
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self performSelector:@selector(comandoLockPassword) withObject:nil];
- }];
- }
- if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && !lockDirectory && app.isCryptoCloudMode) {
-
- [actionSheet addButtonWithTitle:titoloCriptaDecripta
- image:[UIImage imageNamed:@"actionSheetCrypto"]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeEncrypted
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self performSelector:@selector(encyptedDecryptedFolder) withObject:nil];
- }];
- }
- [actionSheet show];
- }
-
- /******************************************* FILE *******************************************/
-
- if ([_metadata.type isEqualToString: k_metadataType_file] && !_metadata.directory) {
-
- UIImage *iconHeader;
-
- // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]])
- iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, _metadata.fileID]];
- else
- iconHeader = [UIImage imageNamed:_metadata.iconName];
-
- [actionSheet addButtonWithTitle: _metadata.fileNamePrint
- image: iconHeader
- backgroundColor: [NCBrandColor sharedInstance].tabBar
- height: 50.0
- type: AHKActionSheetButtonTypeDisabled
- handler: nil
- ];
-
- if (!_metadata.cryptated) {
-
- [actionSheet addButtonWithTitle:titleFavorite
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetFavorite"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- if (_metadata.favorite)
- [self removeFavorite:_metadata];
- else
- [self addFavorite:_metadata];
- }];
- }
- if (_metadata.cryptated == NO) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self openWindowShare:_metadata];
- }];
- }
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetOpenIn"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self performSelector:@selector(openIn:) withObject:_metadata];
- }];
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetRename"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- //textField.placeholder = _metadata.fileNamePrint;
- textField.text = _metadata.fileNamePrint;
- [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"Cancel action");
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- UITextField *fileName = alertController.textFields.firstObject;
-
- [self performSelectorOnMainThread:@selector(renameFile:) withObject:[NSMutableArray arrayWithObjects:_metadata,fileName.text, nil] waitUntilDone:NO];
- }];
-
- okAction.enabled = NO;
-
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }];
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetMove"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
- }];
-
- if (localFile || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_local_file_", nil)
- image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetRemoveLocal"] color:[NCBrandColor sharedInstance].brand]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self performSelector:@selector(removeLocalFile:) withObject:_metadata];
- }];
- }
- if (app.isCryptoCloudMode) {
-
- [actionSheet addButtonWithTitle:titoloCriptaDecripta
- image:[UIImage imageNamed:@"actionSheetCrypto"]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeEncrypted
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self performSelector:@selector(cmdEncryptedDecryptedFile) withObject:nil];
- }];
- }
-
- [actionSheet show];
- }
-
- /******************************************* TEMPLATE *******************************************/
-
- if ([_metadata.type isEqualToString: k_metadataType_template]) {
-
- [actionSheet addButtonWithTitle: _metadata.fileNamePrint
- image: [UIImage imageNamed:_metadata.iconName]
- backgroundColor: [NCBrandColor sharedInstance].tabBar
- height: 50.0
- type: AHKActionSheetButtonTypeDisabled
- handler: nil
- ];
-
- if ([_metadata.model isEqualToString:@"note"]) {
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_rename_", nil)
- image:[UIImage imageNamed:@"actionSheetRename"]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_rename_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.placeholder = _metadata.fileNamePrint;
- [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- NSLog(@"Cancel action");
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- UITextField *fileName = alertController.textFields.firstObject;
-
- [self performSelectorOnMainThread:@selector(renameNote:) withObject:[NSMutableArray arrayWithObjects:_metadata,fileName.text, nil] waitUntilDone:NO];
- }];
-
- okAction.enabled = NO;
-
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }];
- }
-
- [actionSheet addButtonWithTitle:NSLocalizedString(@"_move_", nil)
- image:[UIImage imageNamed:@"actionSheetMove"]
- backgroundColor:[UIColor whiteColor]
- height: 50.0
- type:AHKActionSheetButtonTypeDefault
- handler:^(AHKActionSheet *as) {
-
- // close swipe
- [self setEditing:NO animated:YES];
-
- [self moveOpenWindow:[[NSArray alloc] initWithObjects:indexPath, nil]];
- }];
- [actionSheet show];
- }
- }
- - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return NSLocalizedString(@"_delete_", nil);
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- {
- tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
- if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata])
- return NO;
-
- if (metadata == nil || metadata.errorPasscode || (metadata.cryptated && [metadata.title length] == 0) || metadata.sessionTaskIdentifier >= 0 || metadata.sessionTaskIdentifier >= 0) return NO;
- else return YES;
- }
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- _metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- if (_metadata.errorPasscode || (_metadata.cryptated && [_metadata.title length] == 0) || _metadata.sessionTaskIdentifier >= 0 || _metadata.sessionTaskIdentifier >= 0) return UITableViewCellEditingStyleNone;
- else return UITableViewCellEditingStyleDelete;
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- _metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- BOOL lockDirectory = NO;
-
- // Directory locked ?
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:[[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID] addFileName:_metadata.fileNameData];
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl = %@", lockServerUrl]];
-
- if (directory.lock && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil)
- lockDirectory = YES;
-
- if (lockDirectory && editingStyle == UITableViewCellEditingStyleDelete) {
-
- [app messageNotification:@"_error_" description:@"_folder_blocked_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:0];
-
- return;
- }
- if (editingStyle == UITableViewCellEditingStyleDelete) {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
- style:UIAlertActionStyleDestructive
- handler:^(UIAlertAction *action) {
- [self performSelector:@selector(deleteFile) withObject:nil];
- }]];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
- style:UIAlertActionStyleCancel
- handler:^(UIAlertAction *action) {
- [alertController dismissViewControllerAnimated:YES completion:nil];
- }]];
-
- alertController.popoverPresentationController.sourceView = self.view;
- alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- [alertController.view layoutIfNeeded];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ==== Datasource ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)clearDateReadDataSource:(NSNotification *)notification
- {
- _dateReadDataSource = Nil;
- [self reloadDatasource];
- }
- - (void)reloadDatasource
- {
- [self reloadDatasource:_serverUrl fileID:nil selector:nil];
- }
- - (void)reloadDatasource:(NSString *)serverUrl fileID:(NSString *)fileID selector:(NSString *)selector
- {
- // test
- if (app.activeAccount.length == 0 || serverUrl.length == 0)
- return;
-
- // Search Mode
- if(_isSearchMode) {
-
- if ([selector length] == 0 || [selector isEqualToString:selectorSearch]) {
-
- _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:_searchResultMetadatas listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
-
- } else {
-
- [self readFolderWithForced:NO serverUrl:serverUrl];
- }
-
- [self tableViewReload];
-
- if ([_sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] >= k_minCharsSearch) {
-
- _noFilesSearchTitle = NSLocalizedString(@"_search_no_record_found_", nil);
- _noFilesSearchDescription = @"";
- }
-
- if ([_sectionDataSource.allRecordsDataSource count] == 0 && [_searchFileName length] < k_minCharsSearch) {
-
- _noFilesSearchTitle = @"";
- _noFilesSearchDescription = NSLocalizedString(@"_search_instruction_", nil);
- }
-
- [self.tableView reloadEmptyDataSet];
-
- return;
- }
-
- // Reload -> Self se non siamo nella dir appropriata cercala e se è in memoria reindirizza il reload
- if ([serverUrl isEqualToString:_serverUrl] == NO || _serverUrl == nil) {
-
- if ([selector isEqualToString:selectorDownloadSynchronize]) {
- [app.activeTransfers reloadDatasource];
- } else {
- CCMain *main = [app.listMainVC objectForKey:serverUrl];
- if (main) {
- [main reloadDatasource];
- } else {
- [self tableViewReload];
- [app.activeTransfers reloadDatasource];
- }
- }
-
- return;
- }
-
- [app.activeTransfers reloadDatasource];
-
- // Settaggio variabili per le ottimizzazioni
- _directoryGroupBy = [CCUtility getGroupBySettings];
- _directoryOrder = [CCUtility getOrderSettings];
-
- // Controllo data lettura Data Source
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl == %@", serverUrl]];
- NSDate *dateDateRecordDirectory = directory.dateReadDirectory;
-
- if ([dateDateRecordDirectory compare:_dateReadDataSource] == NSOrderedDescending || dateDateRecordDirectory == nil || _dateReadDataSource == nil) {
-
- NSLog(@"[LOG] Rebuild Data Source File : %@", _serverUrl);
- _dateReadDataSource = [NSDate date];
-
- // Data Source
-
- NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@", app.activeAccount, [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl]] sorted:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
-
- _sectionDataSource = [CCSectionDataSourceMetadata new];
- _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:_directoryGroupBy replaceDateToExifDate:NO activeAccount:app.activeAccount];
-
- } else {
-
- NSLog(@"[LOG] [OPTIMIZATION] Rebuild Data Source File : %@ - %@", _serverUrl, _dateReadDataSource);
- }
-
- [self tableViewReload];
- }
- - (NSArray *)getMetadatasFromSelectedRows:(NSArray *)selectedRows
- {
- NSMutableArray *metadatas = [[NSMutableArray alloc] init];
-
- if (selectedRows.count > 0) {
-
- for (NSIndexPath *selectionIndex in selectedRows) {
-
- NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:selectionIndex.section]] objectAtIndex:selectionIndex.row];
- tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
- [metadatas addObject:metadata];
- }
- }
-
- return metadatas;
- }
- - (tableMetadata *)getMetadataFromSectionDataSource:(NSIndexPath *)indexPath
- {
- NSInteger section = indexPath.section + 1;
- NSInteger row = indexPath.row + 1;
-
- NSInteger totSections =[_sectionDataSource.sections count] ;
-
- if ((totSections < section) || (section > totSections)) {
-
- NSLog(@"[LOG] %@", [NSString stringWithFormat:@"DEBUG [0] : error section, totSections = %lu - section = %lu", (long)totSections, (long)section]);
- return nil;
- }
-
- id valueSection = [_sectionDataSource.sections objectAtIndex:indexPath.section];
-
- NSArray *fileIDs = [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
-
- if (fileIDs) {
-
- NSInteger totRows =[fileIDs count] ;
-
- if ((totRows < row) || (row > totRows)) {
-
- NSLog(@"[LOG] %@", [NSString stringWithFormat:@"DEBUG [1] : error row, totRows = %lu - row = %lu", (long)totRows, (long)row]);
- return nil;
- }
- } else {
-
- NSLog(@"[LOG] DEBUG [2] : fileIDs is NIL");
- return nil;
- }
-
- NSString *fileID = [fileIDs objectAtIndex:indexPath.row];
- tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
-
- return metadata;
- }
- - (NSArray *)getMetadatasFromSectionDataSource:(NSInteger)section
- {
- NSInteger totSections =[_sectionDataSource.sections count] ;
-
- if ((totSections < (section + 1)) || ((section + 1) > totSections)) {
-
- #if DEBUG
- 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];
- [alertView show];
- #endif
- return nil;
- }
-
- id valueSection = [_sectionDataSource.sections objectAtIndex:section];
-
- return [_sectionDataSource.sectionArrayRow objectForKey:valueSection];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ==== Table ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)tableViewSelect:(BOOL)edit
- {
- // chiudiamo eventuali swipe aperti
- if (edit) [self.tableView setEditing:NO animated:NO];
-
- [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
- [self.tableView setEditing:edit animated:YES];
- _isSelectedMode = edit;
-
- if (edit)
- [self setUINavigationBarSelected];
- else
- [self setUINavigationBarDefault];
-
- [self setTitle];
- }
- - (void)tableViewReload
- {
- // ricordiamoci le row selezionate
- NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
- [self.tableView reloadData];
-
- for (NSIndexPath *path in indexPaths)
- [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionNone];
-
- [self setTableViewFooter];
-
- if (self.tableView.editing)
- [self setTitle];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 60;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return [[_sectionDataSource.sectionArrayRow allKeys] count];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- NSArray *sections = [_sectionDataSource.sectionArrayRow allKeys];
- NSString *sectionTitle = [sections objectAtIndex:section];
-
- if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"download"].location != NSNotFound) return 18.f;
- if ([sectionTitle isKindOfClass:[NSString class]] && [sectionTitle rangeOfString:@"upload"].location != NSNotFound) return 18.f;
-
- if ([_directoryGroupBy isEqualToString:@"none"] && [sections count] <= 1) return 0.0f;
-
- return 20.f;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- float shift;
- UIVisualEffectView *visualEffectView;
-
- // Titolo
- NSString *titleSection;
-
- // Controllo
- if ([_sectionDataSource.sections count] == 0)
- return nil;
-
- if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
- if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
-
- if ([titleSection isEqualToString:@"_none_"]) titleSection = @"";
- else if ([titleSection rangeOfString:@"download"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_download_",nil);
- else if ([titleSection rangeOfString:@"upload"].location != NSNotFound) titleSection = NSLocalizedString(@"_title_section_upload_",nil);
- else titleSection = NSLocalizedString(titleSection,nil);
-
- // Formato titolo
- NSString *currentDevice = [CCUtility currentDevice];
- if ([currentDevice rangeOfString:@"iPad3"].location != NSNotFound) {
-
- visualEffectView = [[UIVisualEffectView alloc] init];
- visualEffectView.backgroundColor = [[NCBrandColor sharedInstance].brand colorWithAlphaComponent:0.3];
-
- } else {
-
- UIVisualEffect *blurEffect;
- blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
- visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
- visualEffectView.backgroundColor = [[NCBrandColor sharedInstance].brand colorWithAlphaComponent:0.2];
- }
-
- if ([_directoryGroupBy isEqualToString:@"alphabetic"]) {
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) shift = - 35;
- else shift = - 20;
-
- } else shift = - 10;
-
- // Title
- UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -12, 0, 44)];
- titleLabel.backgroundColor = [UIColor clearColor];
- titleLabel.textColor = [UIColor blackColor];
- titleLabel.font = [UIFont systemFontOfSize:12];
- titleLabel.textAlignment = NSTextAlignmentLeft;
- titleLabel.text = titleSection;
- titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [visualEffectView addSubview:titleLabel];
-
- // Elements
- UILabel *elementLabel= [[UILabel alloc]initWithFrame:CGRectMake(shift, -12, 0, 44)];
- elementLabel.backgroundColor = [UIColor clearColor];
- elementLabel.textColor = [UIColor blackColor];;
- elementLabel.font = [UIFont systemFontOfSize:12];
- elementLabel.textAlignment = NSTextAlignmentRight;
- elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-
- NSArray *metadatas = [self getMetadatasFromSectionDataSource:section];
- NSUInteger rowsCount = [metadatas count];
-
- if (rowsCount == 0) return nil;
- if (rowsCount == 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_element_",nil)];
- if (rowsCount > 1) elementLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)rowsCount, NSLocalizedString(@"_elements_",nil)];
-
- [visualEffectView addSubview:elementLabel];
-
- return visualEffectView;
- }
- - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
- {
- return [_sectionDataSource.sections indexOfObject:title];
- }
- - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
- {
- if ([_directoryGroupBy isEqualToString:@"alphabetic"])
- return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
- else
- return nil;
- }
- /*
- -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
-
- }
- }
- */
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString *typeCell;
- NSString *dataFile;
- NSString *lunghezzaFile;
-
- tableMetadata *metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- if (!metadata || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
- return [tableView dequeueReusableCellWithIdentifier:@"CellMainTransfer"];
- }
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
-
- if ([metadata.session isEqualToString:@""] || metadata.session == nil) typeCell = @"CellMain";
- else typeCell = @"CellMainTransfer";
-
- CCCellMainTransfer *cell = (CCCellMainTransfer *)[tableView dequeueReusableCellWithIdentifier:typeCell forIndexPath:indexPath];
-
- // separator
- cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
-
- // change color selection
- UIView *selectionColor = [[UIView alloc] init];
- selectionColor.backgroundColor = [[NCBrandColor sharedInstance] getColorSelectBackgrond];
- cell.selectedBackgroundView = selectionColor;
-
- if ([typeCell isEqualToString:@"CellMain"]) cell.backgroundColor = [UIColor whiteColor];
- if ([typeCell isEqualToString:@"CellMainTransfer"]) cell.backgroundColor = [NCBrandColor sharedInstance].transferBackground;
-
- // ----------------------------------------------------------------------------------------------------------
- // DEFAULT
- // ----------------------------------------------------------------------------------------------------------
-
- cell.file.image = nil;
- cell.status.image = nil;
- cell.favorite.image = nil;
- cell.shared.image = nil;
- cell.local.image = nil;
-
- cell.labelTitle.enabled = YES;
- cell.labelTitle.text = @"";
- cell.labelInfoFile.enabled = YES;
- cell.labelInfoFile.text = @"";
-
- cell.progressView.progress = 0.0;
- cell.progressView.hidden = YES;
-
- cell.cancelTaskButton.hidden = YES;
- cell.reloadTaskButton.hidden = YES;
- cell.stopTaskButton.hidden = YES;
-
- // Encrypted color
- if (metadata.cryptated) {
- cell.labelTitle.textColor = [NCBrandColor sharedInstance].cryptocloud;
- } else {
- cell.labelTitle.textColor = [UIColor blackColor];
- }
-
- // ----------------------------------------------------------------------------------------------------------
- // File Name & Folder
- // ----------------------------------------------------------------------------------------------------------
-
- // nome del file
- cell.labelTitle.text = metadata.fileNamePrint;
-
- // è una directory
- if (metadata.directory) {
-
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
-
- lunghezzaFile = @" ";
-
- // ----------------------------------------------------------------------------------------------------------
- // Favorite Folder
- // ----------------------------------------------------------------------------------------------------------
-
- if (metadata.favorite) {
-
- cell.favorite.image = [UIImage imageNamed:@"favorite"];
- }
-
- } else {
-
- // File
- dataFile = [CCUtility dateDiff:metadata.date];
- lunghezzaFile = [CCUtility transformedSize:metadata.size];
-
- // Plist ancora da scaricare
- if (metadata.cryptated && [metadata.title length] == 0) {
-
- dataFile = @" ";
- lunghezzaFile = @" ";
- }
-
- tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateStyle:NSDateFormatterShortStyle];
- [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
-
- if ([metadata.type isEqualToString: k_metadataType_template] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO)
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", dataFile];
-
- if ([metadata.type isEqualToString: k_metadataType_file] && [dataFile isEqualToString:@" "] == NO && [lunghezzaFile isEqualToString:@" "] == NO) {
- if (localFile && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]])
- cell.local.image = [UIImage imageNamed:@"local"];
- else
- cell.local.image = nil;
-
- //cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", dataFile, lunghezzaFile];
- //cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", dataFile, lunghezzaFile];
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ %@", dataFile, lunghezzaFile];
- }
- // Plist ancora da scaricare
- if ([dataFile isEqualToString:@" "] && [lunghezzaFile isEqualToString:@" "])
- cell.labelInfoFile.text = NSLocalizedString(@"_no_plist_pull_down_",nil);
-
- cell.accessoryType = UITableViewCellAccessoryNone;
- }
-
- // ----------------------------------------------------------------------------------------------------------
- // File Image View
- // ----------------------------------------------------------------------------------------------------------
- // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
-
- cell.file.image = [app.icoImagesCache objectForKey:metadata.fileID];
-
- if (cell.file.image == nil) {
-
- NSString *fileID = metadata.fileID;
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-
- UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, fileID]];
-
- [app.icoImagesCache setObject:image forKey:fileID];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- CCCellMainTransfer *cell = [tableView cellForRowAtIndexPath:indexPath];
-
- if (cell)
- cell.file.image = image;
- });
- });
- }
- } else {
-
- if (metadata.directory)
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:metadata.iconName] color:[NCBrandColor sharedInstance].brand];
- else
- cell.file.image = [UIImage imageNamed:metadata.iconName];
-
- if (metadata.thumbnailExists)
- [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
- }
-
- // ----------------------------------------------------------------------------------------------------------
- // Image Status cyptated & Lock Passcode
- // ----------------------------------------------------------------------------------------------------------
-
- // File Cyptated
- if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_template] == NO) {
-
- cell.status.image = [UIImage imageNamed:@"lock"];
- }
-
- // Directory con passcode lock attivato
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileNameData];
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl = %@", lockServerUrl]];
-
- if (metadata.directory && (directory.lock && [[CCUtility getBlockCode] length]))
- cell.status.image = [UIImage imageNamed:@"passcode"];
-
- // ----------------------------------------------------------------------------------------------------------
- // Favorite
- // ----------------------------------------------------------------------------------------------------------
-
- if (metadata.favorite) {
-
- cell.favorite.image = [UIImage imageNamed:@"favorite"];
- }
-
- // ----------------------------------------------------------------------------------------------------------
- // Share
- // ----------------------------------------------------------------------------------------------------------
- NSString *shareLink = [app.sharesLink objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
- NSString *shareUserAndGroup = [app.sharesUserAndGroup objectForKey:[serverUrl stringByAppendingString:metadata.fileName]];
- BOOL isShare = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_shared].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_shared].location == NSNotFound);
- BOOL isMounted = ([metadata.permissions length] > 0) && ([metadata.permissions rangeOfString:k_permission_mounted].location != NSNotFound) && ([_fatherPermission rangeOfString:k_permission_mounted].location == NSNotFound);
-
- // Aggiungiamo il Tap per le shared
- if (isShare || [shareLink length] > 0 || [shareUserAndGroup length] > 0 || isMounted) {
-
- if (isShare) {
-
- if (metadata.directory) {
-
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_shared_with_me"] color:[NCBrandColor sharedInstance].brand];
- cell.shared.userInteractionEnabled = NO;
-
- } else {
-
- cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
- [tap setNumberOfTapsRequired:1];
- cell.shared.userInteractionEnabled = YES;
- [cell.shared addGestureRecognizer:tap];
- }
- }
-
- if (isMounted) {
-
- if (metadata.directory) {
-
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_external"] color:[NCBrandColor sharedInstance].brand];
- cell.shared.userInteractionEnabled = NO;
-
- } else {
-
- cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"shareMounted"] color:[NCBrandColor sharedInstance].brand];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionConnectionMounted:)];
- [tap setNumberOfTapsRequired:1];
- cell.shared.userInteractionEnabled = YES;
- [cell.shared addGestureRecognizer:tap];
- }
- }
-
- if ([shareLink length] > 0 || [shareUserAndGroup length] > 0) {
-
- if (metadata.directory) {
-
- if ([shareLink length] > 0)
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_public"] color:[NCBrandColor sharedInstance].brand];
- if ([shareUserAndGroup length] > 0)
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder_shared_with_me"] color:[NCBrandColor sharedInstance].brand];
-
- cell.shared.userInteractionEnabled = NO;
-
- } else {
-
- if ([shareLink length] > 0)
- cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"shareLink"] color:[NCBrandColor sharedInstance].brand];
- if ([shareUserAndGroup length] > 0)
- cell.shared.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"actionSheetShare"] color:[NCBrandColor sharedInstance].brand];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
- [tap setNumberOfTapsRequired:1];
- cell.shared.userInteractionEnabled = YES;
- [cell.shared addGestureRecognizer:tap];
- }
- }
-
- } else {
-
- cell.shared.userInteractionEnabled = NO;
- }
-
- // ----------------------------------------------------------------------------------------------------------
- // downloadFile
- // ----------------------------------------------------------------------------------------------------------
-
- if ([metadata.session length] > 0 && [metadata.session containsString:@"download"]) {
-
- if (metadata.cryptated) cell.status.image = [UIImage imageNamed:@"statusdownloadcrypto"];
- else cell.status.image = [UIImage imageNamed:@"statusdownload"];
- // sessionTaskIdentifier : RELOAD + STOP
- if (metadata.sessionTaskIdentifier != k_taskIdentifierDone) {
-
- if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptaskcrypto"] forState:UIControlStateNormal];
- else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
-
- cell.cancelTaskButton.hidden = NO;
- if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtaskcrypto"] forState:UIControlStateNormal];
- else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
-
- cell.reloadTaskButton.hidden = NO;
-
- }
-
- // sessionTaskIdentifierPlist : RELOAD
- if (metadata.sessionTaskIdentifierPlist != k_taskIdentifierDone) {
-
- if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtaskcrypto"] forState:UIControlStateNormal];
- else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
-
- cell.reloadTaskButton.hidden = NO;
- }
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
-
- float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
- if (progress > 0) {
-
- if (metadata.cryptated) cell.progressView.progressTintColor = [NCBrandColor sharedInstance].cryptocloud;
- else cell.progressView.progressTintColor = [UIColor blackColor];
-
- cell.progressView.progress = progress;
- cell.progressView.hidden = NO;
- }
- // ----------------------------------------------------------------------------------------------------------
- // downloadFile Error
- // ----------------------------------------------------------------------------------------------------------
-
- if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
-
- cell.status.image = [UIImage imageNamed:@"statuserror"];
-
- if ([metadata.sessionError length] == 0)
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
- else
- cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
- }
- }
-
- // ----------------------------------------------------------------------------------------------------------
- // uploadFile
- // ----------------------------------------------------------------------------------------------------------
-
- if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
-
- if (metadata.cryptated) cell.status.image = [UIImage imageNamed:@"statusuploadcrypto"];
- else cell.status.image = [UIImage imageNamed:@"statusupload"];
-
- if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"removetaskcrypto"] forState:UIControlStateNormal];
- else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"removetask"] forState:UIControlStateNormal];
- cell.cancelTaskButton.hidden = NO;
-
- if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
-
- if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtaskcrypto"] forState:UIControlStateNormal];
- else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
-
- if (metadata.cryptated) cell.status.image = [UIImage imageNamed:@"statusstopcrypto"];
- else cell.status.image = [UIImage imageNamed:@"statusstop"];
-
- cell.reloadTaskButton.hidden = NO;
- cell.stopTaskButton.hidden = YES;
-
- } else {
-
- if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptaskcrypto"] forState:UIControlStateNormal];
- else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
-
- cell.stopTaskButton.hidden = NO;
- cell.reloadTaskButton.hidden = YES;
- }
-
- // se non c'è una preview in bianconero metti l'immagine di default
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
- cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"uploaddisable"] color:[NCBrandColor sharedInstance].brand];
-
- cell.labelTitle.enabled = NO;
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
-
- float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
- if (progress > 0) {
-
- if (metadata.cryptated) cell.progressView.progressTintColor = [NCBrandColor sharedInstance].cryptocloud;
- else cell.progressView.progressTintColor = [UIColor blackColor];
-
- cell.progressView.progress = progress;
- cell.progressView.hidden = NO;
- }
-
- // ----------------------------------------------------------------------------------------------------------
- // uploadFileError
- // ----------------------------------------------------------------------------------------------------------
-
- if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
-
- cell.labelTitle.enabled = NO;
- cell.status.image = [UIImage imageNamed:@"statuserror"];
-
- if ([metadata.sessionError length] == 0)
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
- else
- cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
- }
- }
- [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
- [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
- [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
- return cell;
- }
- - (void)setTableViewFooter
- {
- UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
- [footerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
-
- UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 40)];
- [footerLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
-
- UIFont *appFont = [UIFont systemFontOfSize:12];
-
- footerLabel.font = appFont;
- footerLabel.textColor = [UIColor grayColor];
- footerLabel.backgroundColor = [UIColor clearColor];
- footerLabel.textAlignment = NSTextAlignmentCenter;
-
- NSString *folders;
- NSString *files;
- NSString *footerText;
-
- if (_sectionDataSource.directories > 1) {
- folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folders_", nil)];
- } else if (_sectionDataSource.directories == 1){
- folders = [NSString stringWithFormat:@"%ld %@", (long)_sectionDataSource.directories, NSLocalizedString(@"_folder_", nil)];
- } else {
- folders = @"";
- }
-
- if (_sectionDataSource.files > 1) {
- files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_files_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
- } else if (_sectionDataSource.files == 1){
- files = [NSString stringWithFormat:@"%ld %@ %@", (long)_sectionDataSource.files, NSLocalizedString(@"_file_", nil), [CCUtility transformedSize:_sectionDataSource.totalSize]];
- } else {
- files = @"";
- }
-
- if ([folders isEqualToString:@""]) {
- footerText = files;
- } else if ([files isEqualToString:@""]) {
- footerText = folders;
- } else {
- footerText = [NSString stringWithFormat:@"%@, %@", folders, files];
- }
-
- footerLabel.text = footerText;
-
- [footerView addSubview:footerLabel];
- [self.tableView setTableFooterView:footerView];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString *textMessage;
-
- UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
-
- // settiamo il record file.
- _metadata = [self getMetadataFromSectionDataSource:indexPath];
-
- // se non può essere selezionata deseleziona
- if ([cell isEditing] == NO)
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- // se siamo in modalità editing impostiamo il titolo dei selezioati e usciamo subito
- if (self.tableView.editing) {
-
- [self setTitle];
- return;
- }
-
- // test crash
- NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
- if (indexPath.row >= [metadatas count]) return;
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
-
- // se è in corso una sessione
- if ([_metadata.session length] > 0) return;
-
- if (_metadata.errorPasscode) {
-
- // se UUID è nil lo sta ancora caricando quindi esci
- if (!_metadata.uuid) return;
-
- // esiste un hint ??
- NSString *hint = [[CCCrypto sharedManager] getHintFromFile:_metadata.fileName isLocal:NO directoryUser:app.directoryUser];
-
- // qui !! la richiesta della nuova passcode
- if ([_metadata.uuid isEqualToString:[CCUtility getUUID]]) {
-
- // stesso UUID ... la password è stata modificata !!!!!!
-
- if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_same_device_different_passcode_hint_",nil), hint];
- else textMessage = NSLocalizedString(@"_same_device_different_passcode_", nil);
-
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
-
- } else {
-
- // UUID diverso.
-
- if (hint) textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_hint_",nil), _metadata.nameCurrentDevice, hint];
- else textMessage = [NSString stringWithFormat:NSLocalizedString(@"_file_encrypted_another_device_",nil), _metadata.nameCurrentDevice];
-
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:textMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
- [alertView show];
- }
-
- // chiediamo la passcode e ricarichiamo tutto.
- CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
- viewController.delegate = self;
- viewController.fromType = CCBKPasscodeFromPasscode;
- viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 64;
- viewController.type = BKPasscodeViewControllerCheckPasscodeType;
- viewController.inputViewTitlePassword = NO;
-
- viewController.title = [NCBrandOptions sharedInstance].brand;
- viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
- viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
-
- [self presentViewController:navigationController animated:YES completion:nil];
- }
-
- // modello o plist con il title a 0 allora è andato storto qualcosa ... ricaricalo
- if (_metadata.cryptated && [_metadata.title length] == 0) {
-
- NSString* selector;
-
- if ([_metadata.type isEqualToString: k_metadataType_template]) selector = selectorLoadModelView;
- else selector = selectorLoadPlist;
-
- [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:NO downloadPlist:YES selector:selector selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
-
- return;
- }
-
- // se il plist è caricato ed è un modello aprilo
- if ([_metadata.type isEqualToString:k_metadataType_template]) [self openModel:_metadata.model isNew:false];
-
- // file
- if (_metadata.directory == NO && _metadata.errorPasscode == NO && [_metadata.type isEqualToString: k_metadataType_file]) {
-
- // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
-
- [self downloadFileSuccess:_metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView selectorPost:nil];
-
- } else {
-
- [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
-
- NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:_metadata.fileID];
- if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
- }
- }
-
- if (_metadata.directory) [self performSegueDirectoryWithControlPasscode:true];
- }
- - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
- {
- [self setTitle];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Navigation ====
- #pragma --------------------------------------------------------------------------------------------
- - (BOOL)shouldPerformSegue
- {
- // if background return
- if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
-
- if (self.view.window == NO)
- return NO;
-
- // Collapsed ma siamo già in detail esci
- if (self.splitViewController.isCollapsed)
- if (_detailViewController.isViewLoaded && _detailViewController.view.window) return NO;
-
- // Video in esecuzione esci
- if (_detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && _detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
-
- return YES;
- }
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- id viewController = segue.destinationViewController;
- NSMutableArray *allRecordsDataSourceImagesVideos = [NSMutableArray new];
- tableMetadata *metadata;
-
- if ([viewController isKindOfClass:[UINavigationController class]]) {
-
- UINavigationController *nav = viewController;
- _detailViewController = (CCDetail *)nav.topViewController;
-
- } else {
-
- _detailViewController = segue.destinationViewController;
- }
-
- if ([sender isKindOfClass:[tableMetadata class]]) {
-
- metadata = sender;
- [allRecordsDataSourceImagesVideos addObject:sender];
-
- } else {
-
- metadata = _metadata;
-
- for (NSString *fileID in _sectionDataSource.allEtag) {
- tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
- [allRecordsDataSourceImagesVideos addObject:metadata];
- }
- }
-
- _detailViewController.metadataDetail = metadata;
- _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
- _detailViewController.dateFilterQuery = nil;
-
- [_detailViewController setTitle:metadata.fileNamePrint];
- }
- // can i go to next viewcontroller
- - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
- {
- NSString *nomeDir;
- if(self.tableView.editing == NO && _metadata.errorPasscode == NO){
-
- NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
- NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
- tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl = %@", lockServerUrl]];
- // 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
- if (directory.lock && [[CCUtility getBlockCode] length] && app.sessionePasscodeLock == nil && controlPasscode) {
-
- CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
- viewController.delegate = self;
- viewController.fromType = CCBKPasscodeFromLockDirectory;
- viewController.type = BKPasscodeViewControllerCheckPasscodeType;
- viewController.inputViewTitlePassword = YES;
-
- if ([CCUtility getSimplyBlockCode]) {
-
- viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 6;
-
- } else {
-
- viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
- viewController.passcodeInputView.maximumLength = 64;
- }
- BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
- touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
- viewController.touchIDManager = touchIDManager;
-
- viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
- viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
- viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
-
- UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
- [self presentViewController:navController animated:YES completion:nil];
-
- return;
- }
-
- if (_metadata.cryptated) nomeDir = [_metadata.fileName substringToIndex:[_metadata.fileName length]-6];
- else nomeDir = _metadata.fileName;
-
- NSString *serverUrlPush = [CCUtility stringAppendServerUrl:serverUrl addFileName:nomeDir];
-
- CCMain *viewController = [app.listMainVC objectForKey:serverUrlPush];
-
- if (viewController.isViewLoaded == false || viewController == nil) {
-
- viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMainVC"];
-
- viewController.isFolderEncrypted = _metadata.cryptated;
- viewController.serverUrl = serverUrlPush;
- viewController.titleMain = _metadata.fileNamePrint;
- viewController.textBackButton = _titleMain;
-
- // save self
- [app.listMainVC setObject:viewController forKey:serverUrlPush];
- }
-
- // OFF SearchBar
- [viewController cancelSearchBar];
-
- [self.navigationController pushViewController:viewController animated:YES];
- }
- }
- @end
|