CCMain.m 261 KB

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