CCMain.m 261 KB

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