CCMain.m 263 KB

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