CCMain.m 258 KB

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