CCMain.m 259 KB

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