CCMain.m 256 KB

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