CCMain.m 262 KB

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