CCMain.m 258 KB

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