CCMain.m 259 KB

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