CCMain.m 255 KB

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